Summary

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.

API Stability Long-Term

Syntax

graphql
testParserV2(
      input: ParserTestRunInput!
   ): ParserTestRunOutput!

For the input, you'll have to give the name of the repository associated with the parser to test, some events to use for testing, a list of fields to be removed, etc. See the Input Parameters for more details.

For the results, you can get confirmation the test was succesful, and a message explaining the test results. See the Returned Values section for more.

Example

Raw
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 }
}
Mac OS or Linux (curl)
shell
curl -v -X POST $YOUR_LOGSCALE_URL/graphql \
    -H "Authorization: Bearer $TOKEN" \
    -H "Content-Type: application/json" \
    -d @- << EOF
{"query" : "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 }
}"
}
EOF
Mac OS or Linux (curl) One-line
shell
curl -v -X POST $YOUR_LOGSCALE_URL/graphql \
    -H "Authorization: Bearer $TOKEN" \
    -H "Content-Type: application/json" \
    -d @- << EOF
{"query" : "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 }
}"
}
EOF
Windows Cmd and curl
shell
curl -v -X POST $YOUR_LOGSCALE_URL/graphql ^
    -H "Authorization: Bearer $TOKEN" ^
    -H "Content-Type: application/json" ^
    -d @'{"query" : "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 } ^
}" ^
} '
Windows Powershell and curl
powershell
curl.exe -X POST 
    -H "Authorization: Bearer $TOKEN"
    -H "Content-Type: application/json"
    -d '{"query" : "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 }
}"
}'
    "$YOUR_LOGSCALE_URL/graphql"
Perl
perl
#!/usr/bin/perl

use HTTP::Request;
use LWP;

my $TOKEN = "TOKEN";

my $uri = '$YOUR_LOGSCALE_URL/graphql';

my $query = "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 }
}";
$query =~ s/\n/ /g;
my $json = sprintf('{"query" : "%s"}',$query);
my $req = HTTP::Request->new("POST", $uri );

$req->header("Authorization" => "Bearer $TOKEN");
$req->header("Content-Type" => "application/json");

$req->content( $json );

my $lwp = LWP::UserAgent->new;

my $result = $lwp->request( $req );

print $result->{"_content"},"\n";
Python
python
#! /usr/local/bin/python3

import requests

url = '$YOUR_LOGSCALE_URL/graphql'
mydata = r'''{"query" : "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 }
}"
}'''

resp = requests.post(url,
                     data = mydata,
                     headers = {
   "Authorization" : "Bearer $TOKEN",
   "Content-Type" : "application/json"
}
)

print(resp.text)
Node.js
javascript
const https = require('https');

const data = JSON.stringify(
    {"query" : "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 }
}"
}
);


const options = {
  hostname: '$YOUR_LOGSCALE_URL',
  path: 'graphql',
  port: 443,
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Content-Length': data.length,
    Authorization: 'BEARER ' + process.env.TOKEN,
    'User-Agent': 'Node',
  },
};

const req = https.request(options, (res) => {
  let data = '';
  console.log(`statusCode: ${res.statusCode}`);

  res.on('data', (d) => {
    data += d;
  });
  res.on('end', () => {
    console.log(JSON.parse(data).data);
  });
});

req.on('error', (error) => {
  console.error(error);
});

req.write(data);
req.end();

Input Parameters

For the input, you would provide the name of the repository associated with the parser to test, some events to use for testing, a list of fields to be removed, and other parameters. These are listed and explained in the table below, along with links to other datatypes with sub-parameters:

Table: ParserTestRunInput Input Datatype

ParameterTypeRequiredDefaultStabilityDescription
Some input parameters may be required, as indicated in the Required column. For return values, this indicates that you are assured a value if the field is requested for the results.
Table last updated: Oct 29, 2025
fieldsToBeRemovedBeforeParsing[string]yes Long-TermA 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 Long-TermThe fields that are used as tags.
languageVersionLanguageVersionInputType {name: ”legacy“}Long-TermA specific language version. See LanguageVersionInputType.
parserNamestringyes Long-TermThe name of the parser. This is part of the test output in the #type field in each parsed event.
repositoryNameRepoOrViewNameyes Long-TermThe 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  Long-TermThe yaml specification of schema by which to validate parser output. YAML is a scalar.
schemaNameSchema {name: ”legacy“}Long-TermThe name of the used schema. See Schema.
scriptstringyes Long-TermThe parser script that is executed for every incoming event.
testCases[ParserTestCaseInput]yes Long-TermThe test cases to run the parsing script against. See ParserTestCaseInput.

Returned Values

The results are the output of running all parser test cases. However, it's a union datatype. Use either ParserTestRunCompleted or the ParserTestRunAborted datatypes and their choices — or both. See the example given above for a better understanding on how to enter these. Below are the tables for each datatype:

Table: ParserTestRunCompleted Datatype

ParameterTypeRequiredDefaultStabilityDescription
Some input parameters may be required, as indicated in the Required column. For return values, this indicates that you are assured a value if the field is requested for the results.
Table last updated: Sep 27, 2024
results[ParserTestCaseResult]yes Long-TermThe results from running each test case. See ParserTestCaseResult.

Table: ParserTestRunAborted Datatype

ParameterTypeRequiredDefaultStabilityDescription
Some input parameters may be required, as indicated in the Required column. For return values, this indicates that you are assured a value if the field is requested for the results.
Table last updated: Sep 27, 2024
errorMessagestringyes Long-TermThe error message returned when a parser test is run aborted.