Skip to content

Commit

Permalink
#84: add '| teragrep set config key value' with tests (#86)
Browse files Browse the repository at this point in the history
* add '| teragrep set config key value' with tests

* add '| teragrep get config' with tests
  • Loading branch information
eemhu authored Oct 25, 2024
1 parent 42ae75f commit 8699341
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/main/antlr4/imports/COMMAND_TERAGREP_MODE.g4
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ COMMAND_TERAGREP_MODE_DOT: '.';
COMMAND_TERAGREP_MODE_TOKENIZER: 'tokenizer';
COMMAND_TERAGREP_MODE_REGEXEXTRACT: 'regexextract';
COMMAND_TERAGREP_MODE_FOREACHBATCH: 'foreachbatch';
COMMAND_TERAGREP_MODE_CONFIG: 'config';
COMMAND_TERAGREP_MODE_SYSLOG: 'syslog';
COMMAND_TERAGREP_MODE_STREAM: 'stream';
COMMAND_TERAGREP_MODE_LOAD: 'load';
Expand Down
20 changes: 18 additions & 2 deletions src/main/antlr4/imports/DPLParserTransform_teragrep.g4
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
parser grammar DPLParserTransform_teragrep;

teragrepTransformation
: COMMAND_MODE_TERAGREP ( t_execParameter | t_getParameter)
: COMMAND_MODE_TERAGREP ( t_execParameter | t_getParameter | t_setParameter )
;

t_execParameter
Expand Down Expand Up @@ -133,7 +133,23 @@ t_listModeParameter
;

t_getParameter
: (COMMAND_TERAGREP_MODE_GET | COMMAND_TERAGREP_MODE_SET) (t_getTeragrepVersionParameter | t_getArchiveSummaryParameter) numberType?
: COMMAND_TERAGREP_MODE_GET (t_getTeragrepVersionParameter | t_getArchiveSummaryParameter | COMMAND_TERAGREP_MODE_CONFIG)
;

t_setParameter
: COMMAND_TERAGREP_MODE_SET t_setConfigParameter
;

t_setConfigParameter
: COMMAND_TERAGREP_MODE_CONFIG t_configKeyParameter t_configValueParameter
;

t_configKeyParameter
: stringType
;

t_configValueParameter
: stringType
;

t_getTeragrepVersionParameter
Expand Down
41 changes: 38 additions & 3 deletions src/test/java/com/teragrep/pth_03/tests/TeragrepSyntaxTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ public class TeragrepSyntaxTests {
"teragrep_syslog_stream",
"teragrep_syslog_stream_host_port",
"teragrep_foreachbatch",
"teragrep_foreachbatch_transformStatement"
"teragrep_foreachbatch_transformStatement",
"teragrep_config_set",
"teragrep_config_get"
})
public void teragrepSyntaxParseTest(String arg) {
String fileName = "src/test/resources/antlr4/commands/teragrep/" + arg + ".txt";
Expand Down Expand Up @@ -277,7 +279,7 @@ void syslogStreamTest(String arg) { // includes an eval command in the end of th
String syslogPath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_syslogModeParameter";
String evalPath = "/root/transformStatement/transformStatement/evalTransformation";

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

// Check that 1 found
Expand Down Expand Up @@ -384,7 +386,7 @@ void testRegexExtractWithParams(String arg) {
String regexPath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_regexextractParameter/t_regexParameter";
String inputPath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_regexextractParameter/t_inputParameter";
String outputPath = "/root/transformStatement/teragrepTransformation/t_execParameter/t_regexextractParameter/t_outputParameter";
NodeList regexextractNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, regexextractPath, true));
NodeList regexextractNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, regexextractPath, false));
NodeList regexNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, regexPath, false));
NodeList inputNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, inputPath, false));
NodeList outputNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, outputPath, false));
Expand Down Expand Up @@ -427,4 +429,37 @@ void testTeragrepForEachBatchWithTransformStatement(String arg) {
assertEquals(1, febParamNodes.getLength());
assertEquals(1, transformStmtNodes.getLength());
}

@ParameterizedTest
@ValueSource(strings = {
"teragrep_config_set",
})
void testTeragrepSetConfig(String arg) {
ParserStructureTestingUtility pstu = new ParserStructureTestingUtility();
String fileName = "src/test/resources/antlr4/commands/teragrep/" + arg + ".txt";

String configKeyPath = "/root/transformStatement/teragrepTransformation/t_setParameter/t_setConfigParameter/t_configKeyParameter";
String configValuePath = "/root/transformStatement/teragrepTransformation/t_setParameter/t_setConfigParameter/t_configValueParameter";
NodeList configKeyNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, configKeyPath, false));
NodeList configValueNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, configValuePath, false));

assertEquals(1, configKeyNodes.getLength());
assertEquals(1, configValueNodes.getLength());
}

@ParameterizedTest
@ValueSource(strings = {
"teragrep_config_get",
})
void testTeragrepGetConfig(String arg) {
ParserStructureTestingUtility pstu = new ParserStructureTestingUtility();
String fileName = "src/test/resources/antlr4/commands/teragrep/" + arg + ".txt";

String configGetPath = "/root/transformStatement/teragrepTransformation/t_getParameter/value";
NodeList configGetNodes = Assertions.assertDoesNotThrow(() -> (NodeList) pstu.xpathQueryFile(fileName, configGetPath, false));

Assertions.assertEquals(2, configGetNodes.getLength());
Assertions.assertEquals("get", configGetNodes.item(0).getTextContent());
Assertions.assertEquals("config", configGetNodes.item(1).getTextContent());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!-- /*
* Teragrep Data Processing Language Parser Library PTH-03
* Copyright (C) 2019, 2020, 2021, 2022 Suomen Kanuuna Oy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://github.com/teragrep/teragrep/blob/main/LICENSE>.
*
*
* Additional permission under GNU Affero General Public License version 3
* section 7
*
* If you modify this Program, or any covered work, by linking or combining it
* with other code, such other code is not for that reason alone subject to any
* of the requirements of the GNU Affero GPL version 3 as long as this Program
* is the same Program as licensed from Suomen Kanuuna Oy without any additional
* modifications.
*
* Supplemented terms under GNU Affero General Public License version 3
* section 7
*
* Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified
* versions must be marked as "Modified version of" The Program.
*
* Names of the licensors and authors may not be used for publicity purposes.
*
* No rights are granted for use of trade names, trademarks, or service marks
* which are in The Program if any.
*
* Licensee must indemnify licensors and authors for any liability that these
* contractual assumptions impose on licensors and authors.
*
* To the extent this program is licensed as part of the Commercial versions of
* Teragrep, the applicable Commercial License may apply to this file if you as
* a licensee so wish it.
*/ -->
| teragrep get config
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!-- /*
* Teragrep Data Processing Language Parser Library PTH-03
* Copyright (C) 2019, 2020, 2021, 2022 Suomen Kanuuna Oy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://github.com/teragrep/teragrep/blob/main/LICENSE>.
*
*
* Additional permission under GNU Affero General Public License version 3
* section 7
*
* If you modify this Program, or any covered work, by linking or combining it
* with other code, such other code is not for that reason alone subject to any
* of the requirements of the GNU Affero GPL version 3 as long as this Program
* is the same Program as licensed from Suomen Kanuuna Oy without any additional
* modifications.
*
* Supplemented terms under GNU Affero General Public License version 3
* section 7
*
* Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified
* versions must be marked as "Modified version of" The Program.
*
* Names of the licensors and authors may not be used for publicity purposes.
*
* No rights are granted for use of trade names, trademarks, or service marks
* which are in The Program if any.
*
* Licensee must indemnify licensors and authors for any liability that these
* contractual assumptions impose on licensors and authors.
*
* To the extent this program is licensed as part of the Commercial versions of
* Teragrep, the applicable Commercial License may apply to this file if you as
* a licensee so wish it.
*/ -->
| teragrep set config dpl.pth_xx.one.two.three "value.foo.bar"

0 comments on commit 8699341

Please sign in to comment.