Skip to content

Commit 8699341

Browse files
authored
#84: add '| teragrep set config key value' with tests (#86)
* add '| teragrep set config key value' with tests * add '| teragrep get config' with tests
1 parent 42ae75f commit 8699341

5 files changed

Lines changed: 149 additions & 5 deletions

File tree

src/main/antlr4/imports/COMMAND_TERAGREP_MODE.g4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ COMMAND_TERAGREP_MODE_DOT: '.';
8181
COMMAND_TERAGREP_MODE_TOKENIZER: 'tokenizer';
8282
COMMAND_TERAGREP_MODE_REGEXEXTRACT: 'regexextract';
8383
COMMAND_TERAGREP_MODE_FOREACHBATCH: 'foreachbatch';
84+
COMMAND_TERAGREP_MODE_CONFIG: 'config';
8485
COMMAND_TERAGREP_MODE_SYSLOG: 'syslog';
8586
COMMAND_TERAGREP_MODE_STREAM: 'stream';
8687
COMMAND_TERAGREP_MODE_LOAD: 'load';

src/main/antlr4/imports/DPLParserTransform_teragrep.g4

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
parser grammar DPLParserTransform_teragrep;
4747

4848
teragrepTransformation
49-
: COMMAND_MODE_TERAGREP ( t_execParameter | t_getParameter)
49+
: COMMAND_MODE_TERAGREP ( t_execParameter | t_getParameter | t_setParameter )
5050
;
5151

5252
t_execParameter
@@ -133,7 +133,23 @@ t_listModeParameter
133133
;
134134

135135
t_getParameter
136-
: (COMMAND_TERAGREP_MODE_GET | COMMAND_TERAGREP_MODE_SET) (t_getTeragrepVersionParameter | t_getArchiveSummaryParameter) numberType?
136+
: COMMAND_TERAGREP_MODE_GET (t_getTeragrepVersionParameter | t_getArchiveSummaryParameter | COMMAND_TERAGREP_MODE_CONFIG)
137+
;
138+
139+
t_setParameter
140+
: COMMAND_TERAGREP_MODE_SET t_setConfigParameter
141+
;
142+
143+
t_setConfigParameter
144+
: COMMAND_TERAGREP_MODE_CONFIG t_configKeyParameter t_configValueParameter
145+
;
146+
147+
t_configKeyParameter
148+
: stringType
149+
;
150+
151+
t_configValueParameter
152+
: stringType
137153
;
138154

139155
t_getTeragrepVersionParameter

src/test/java/com/teragrep/pth_03/tests/TeragrepSyntaxTests.java

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ public class TeragrepSyntaxTests {
7777
"teragrep_syslog_stream",
7878
"teragrep_syslog_stream_host_port",
7979
"teragrep_foreachbatch",
80-
"teragrep_foreachbatch_transformStatement"
80+
"teragrep_foreachbatch_transformStatement",
81+
"teragrep_config_set",
82+
"teragrep_config_get"
8183
})
8284
public void teragrepSyntaxParseTest(String arg) {
8385
String fileName = "src/test/resources/antlr4/commands/teragrep/" + arg + ".txt";
@@ -277,7 +279,7 @@ void syslogStreamTest(String arg) { // includes an eval command in the end of th
277279
String syslogPath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_syslogModeParameter";
278280
String evalPath = "/root/transformStatement/transformStatement/evalTransformation";
279281

280-
NodeList syslogNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, syslogPath, true));
282+
NodeList syslogNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, syslogPath, false));
281283
NodeList evalNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, evalPath, false));
282284

283285
// Check that 1 found
@@ -384,7 +386,7 @@ void testRegexExtractWithParams(String arg) {
384386
String regexPath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_regexextractParameter/t_regexParameter";
385387
String inputPath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_regexextractParameter/t_inputParameter";
386388
String outputPath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_regexextractParameter/t_outputParameter";
387-
NodeList regexextractNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, regexextractPath, true));
389+
NodeList regexextractNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, regexextractPath, false));
388390
NodeList regexNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, regexPath, false));
389391
NodeList inputNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, inputPath, false));
390392
NodeList outputNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, outputPath, false));
@@ -427,4 +429,37 @@ void testTeragrepForEachBatchWithTransformStatement(String arg) {
427429
assertEquals(1, febParamNodes.getLength());
428430
assertEquals(1, transformStmtNodes.getLength());
429431
}
432+
433+
@ParameterizedTest
434+
@ValueSource(strings = {
435+
"teragrep_config_set",
436+
})
437+
void testTeragrepSetConfig(String arg) {
438+
ParserStructureTestingUtility pstu = new ParserStructureTestingUtility();
439+
String fileName = "src/test/resources/antlr4/commands/teragrep/" + arg + ".txt";
440+
441+
String configKeyPath = "/root/transformStatement/teragrepTransformation/t_setParameter/t_setConfigParameter/t_configKeyParameter";
442+
String configValuePath = "/root/transformStatement/teragrepTransformation/t_setParameter/t_setConfigParameter/t_configValueParameter";
443+
NodeList configKeyNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, configKeyPath, false));
444+
NodeList configValueNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, configValuePath, false));
445+
446+
assertEquals(1, configKeyNodes.getLength());
447+
assertEquals(1, configValueNodes.getLength());
448+
}
449+
450+
@ParameterizedTest
451+
@ValueSource(strings = {
452+
"teragrep_config_get",
453+
})
454+
void testTeragrepGetConfig(String arg) {
455+
ParserStructureTestingUtility pstu = new ParserStructureTestingUtility();
456+
String fileName = "src/test/resources/antlr4/commands/teragrep/" + arg + ".txt";
457+
458+
String configGetPath = "/root/transformStatement/teragrepTransformation/t_getParameter/value";
459+
NodeList configGetNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, configGetPath, false));
460+
461+
Assertions.assertEquals(2, configGetNodes.getLength());
462+
Assertions.assertEquals("get", configGetNodes.item(0).getTextContent());
463+
Assertions.assertEquals("config", configGetNodes.item(1).getTextContent());
464+
}
430465
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<!-- /*
2+
* Teragrep Data Processing Language Parser Library PTH-03
3+
* Copyright (C) 2019, 2020, 2021, 2022 Suomen Kanuuna Oy
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Affero General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Affero General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Affero General Public License
16+
* along with this program. If not, see <https://github.com/teragrep/teragrep/blob/main/LICENSE>.
17+
*
18+
*
19+
* Additional permission under GNU Affero General Public License version 3
20+
* section 7
21+
*
22+
* If you modify this Program, or any covered work, by linking or combining it
23+
* with other code, such other code is not for that reason alone subject to any
24+
* of the requirements of the GNU Affero GPL version 3 as long as this Program
25+
* is the same Program as licensed from Suomen Kanuuna Oy without any additional
26+
* modifications.
27+
*
28+
* Supplemented terms under GNU Affero General Public License version 3
29+
* section 7
30+
*
31+
* Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified
32+
* versions must be marked as "Modified version of" The Program.
33+
*
34+
* Names of the licensors and authors may not be used for publicity purposes.
35+
*
36+
* No rights are granted for use of trade names, trademarks, or service marks
37+
* which are in The Program if any.
38+
*
39+
* Licensee must indemnify licensors and authors for any liability that these
40+
* contractual assumptions impose on licensors and authors.
41+
*
42+
* To the extent this program is licensed as part of the Commercial versions of
43+
* Teragrep, the applicable Commercial License may apply to this file if you as
44+
* a licensee so wish it.
45+
*/ -->
46+
| teragrep get config
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<!-- /*
2+
* Teragrep Data Processing Language Parser Library PTH-03
3+
* Copyright (C) 2019, 2020, 2021, 2022 Suomen Kanuuna Oy
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Affero General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Affero General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Affero General Public License
16+
* along with this program. If not, see <https://github.com/teragrep/teragrep/blob/main/LICENSE>.
17+
*
18+
*
19+
* Additional permission under GNU Affero General Public License version 3
20+
* section 7
21+
*
22+
* If you modify this Program, or any covered work, by linking or combining it
23+
* with other code, such other code is not for that reason alone subject to any
24+
* of the requirements of the GNU Affero GPL version 3 as long as this Program
25+
* is the same Program as licensed from Suomen Kanuuna Oy without any additional
26+
* modifications.
27+
*
28+
* Supplemented terms under GNU Affero General Public License version 3
29+
* section 7
30+
*
31+
* Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified
32+
* versions must be marked as "Modified version of" The Program.
33+
*
34+
* Names of the licensors and authors may not be used for publicity purposes.
35+
*
36+
* No rights are granted for use of trade names, trademarks, or service marks
37+
* which are in The Program if any.
38+
*
39+
* Licensee must indemnify licensors and authors for any liability that these
40+
* contractual assumptions impose on licensors and authors.
41+
*
42+
* To the extent this program is licensed as part of the Commercial versions of
43+
* Teragrep, the applicable Commercial License may apply to this file if you as
44+
* a licensee so wish it.
45+
*/ -->
46+
| teragrep set config dpl.pth_xx.one.two.three "value.foo.bar"

0 commit comments

Comments
 (0)