API Stability Long-Term

The testParserV2() GraphQL mutation is used to test a parser on some test events in LogScale. If the parser fails to run, an error is returned. Otherwise, a list of results, one for each test event, is returned.

For more information on parsers, see the Parsing Data documentation page.

Syntax

Below is the syntax for the testParserV2() mutation field:

graphql
testParserV2(
      input: ParserTestRunInput!
   ): ParserTestRunOutput!

Below is an example of how this mutation field might be used:

Show:
graphql
mutation {
  testParserV2(input: 
    { repositoryName: "humio",
      parserName: "my-parser",
      script: "kvParse()",
      testCases: [{
        event: {rawString: "key=value"}, 
        outputAssertions: [{outputEventIndex: 0, 
                            assertions: { fieldsHaveValues: 
                                   [{fieldName: "key", expectedValue: "value"}]
                            } } ],
        }],
      fieldsToTag: [],
      fieldsToBeRemovedBeforeParsing: []
    } )
  { ... on ParserTestRunCompleted {
              results {
                outputEvents { fields { fieldName, value } },
                outputFailures {
                  outputEventIndex,
                  failures {
                    parsingErrors,
                    assertionFailuresOnFields {
                      ... on FieldUnexpectedlyPresent { fieldName, actualValue }
                      ... on Field adUnexpectedValue { fieldName, expectedValue, actualValue }
                      ... on FieldHadConflictingAssertions { fieldName }
                      ... on AssertionOnFieldWasOrphaned { fieldName }
}
                } } } }
    ... on ParserTestRunAborted { errorMessage }
}

Given Datatypes

For ParserTestRunInput, there are a few parameters that may be given. Below is a list of them along with a description of each:

Table: ParserTestRunInput

ParameterTypeRequiredDefaultStabilityDescription
Some arguments may be required, as indicated in the Required column. For some fields, this column indicates that a result will always be returned for this column.
Table last updated: Mar 28, 2025
fieldsToBeRemovedBeforeParsing[string]yes  A list of fields that will be removed from the event before it's parsed. These fields will not be included when calculating usage.
fieldsToTag[string]yes  The fields that are used as tags.
languageVersionLanguageVersionInputTypeyes{name: ”legacy“} A specific language version. See LanguageVersionInputType.
parserNamestringyes  The name of the parser. This is part of the test output in the #type field in each parsed event.
repositoryNameRepoOrViewNameyes  The name of the repository in which the parser is located. This is part of the test output in the #repo field in each parsed event. The RepoOrViewName is a scalar.
schemayaml   The YAML specification of schema by which to validate parser output.
scriptstringyes  The parser script that is executed for every incoming event.
testCases[ParserTestCaseInput]yes  The test cases to run the parsing script against. See ParserTestCaseInput.

Returned Datatypes

The returned datatype, ParserTestRunOutput is the output of running all the parser test cases, and a union of two other datatypes: ParserTestRunCompleted and ParserTestRunAborted. The parameters for those are listed in the tables below. See the example given above for a better understanding on how to enter these parameters.

Table: ParserTestRunCompleted

ParameterTypeRequiredDefaultStabilityDescription
Some arguments may be required, as indicated in the Required column. For some fields, this column indicates that a result will always be returned for this column.
Table last updated: Sep 27, 2024
results[ParserTestCaseResult]yes Long-TermThe results from running each test case. See ParserTestCaseResult.

Table: ParserTestRunAborted

ParameterTypeRequiredDefaultStabilityDescription
Some arguments may be required, as indicated in the Required column. For some fields, this column indicates that a result will always be returned for this column.
Table last updated: Sep 27, 2024
errorMessagestringyes Long-TermThe error message returned when a parser test is run aborted.