API Stability Deprecated

The testParser() 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.

This is deprecated and will be removed in version 1.142. Use instead testParserV2().

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

Syntax

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

graphql
testParser(
     input: TestParserInputV2!
   ): TestParserResultV2!

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

Raw
graphql
mutation {
  testParser(input: 
    { repositoryName: "humio",
      parserId: "123abc",
      parserName: "my-parser",
      parserScript: "kvParse()",
      testData: [{
        event: {rawString: "key=value"}, 
        outputAssertions: [{outputEventIndex: 0, 
                            assertions: { fieldsHaveValues: 
                                   [{fieldName: "key", expectedValue: "value"}]
                            } } ],
        }],
    } )
  { ... 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 {
  testParser(input: 
    { repositoryName: \"humio\",
      parserId: \"123abc\",
      parserName: \"my-parser\",
      parserScript: \"kvParse()\",
      testData: [{
        event: {rawString: \"key=value\"}, 
        outputAssertions: [{outputEventIndex: 0, 
                            assertions: { fieldsHaveValues: 
                                   [{fieldName: \"key\", expectedValue: \"value\"}]
                            } } ],
        }],
    } )
  { ... 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 {
  testParser(input: 
    { repositoryName: \"humio\",
      parserId: \"123abc\",
      parserName: \"my-parser\",
      parserScript: \"kvParse()\",
      testData: [{
        event: {rawString: \"key=value\"}, 
        outputAssertions: [{outputEventIndex: 0, 
                            assertions: { fieldsHaveValues: 
                                   [{fieldName: \"key\", expectedValue: \"value\"}]
                            } } ],
        }],
    } )
  { ... 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 { ^
  testParser(input:  ^
    { repositoryName: \"humio\", ^
      parserId: \"123abc\", ^
      parserName: \"my-parser\", ^
      parserScript: \"kvParse()\", ^
      testData: [{ ^
        event: {rawString: \"key=value\"},  ^
        outputAssertions: [{outputEventIndex: 0,  ^
                            assertions: { fieldsHaveValues:  ^
                                   [{fieldName: \"key\", expectedValue: \"value\"}] ^
                            } } ], ^
        }], ^
    } ) ^
  { ... 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 {
  testParser(input: 
    { repositoryName: \"humio\",
      parserId: \"123abc\",
      parserName: \"my-parser\",
      parserScript: \"kvParse()\",
      testData: [{
        event: {rawString: \"key=value\"}, 
        outputAssertions: [{outputEventIndex: 0, 
                            assertions: { fieldsHaveValues: 
                                   [{fieldName: \"key\", expectedValue: \"value\"}]
                            } } ],
        }],
    } )
  { ... 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 $INGEST_TOKEN = "TOKEN";

my $uri = '$YOUR_LOGSCALE_URL/graphql';

my $json = '{"query" : "mutation {
  testParser(input: 
    { repositoryName: \"humio\",
      parserId: \"123abc\",
      parserName: \"my-parser\",
      parserScript: \"kvParse()\",
      testData: [{
        event: {rawString: \"key=value\"}, 
        outputAssertions: [{outputEventIndex: 0, 
                            assertions: { fieldsHaveValues: 
                                   [{fieldName: \"key\", expectedValue: \"value\"}]
                            } } ],
        }],
    } )
  { ... 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 }
}"
}';
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 {
  testParser(input: 
    { repositoryName: \"humio\",
      parserId: \"123abc\",
      parserName: \"my-parser\",
      parserScript: \"kvParse()\",
      testData: [{
        event: {rawString: \"key=value\"}, 
        outputAssertions: [{outputEventIndex: 0, 
                            assertions: { fieldsHaveValues: 
                                   [{fieldName: \"key\", expectedValue: \"value\"}]
                            } } ],
        }],
    } )
  { ... 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 {
  testParser(input: 
    { repositoryName: \"humio\",
      parserId: \"123abc\",
      parserName: \"my-parser\",
      parserScript: \"kvParse()\",
      testData: [{
        event: {rawString: \"key=value\"}, 
        outputAssertions: [{outputEventIndex: 0, 
                            assertions: { fieldsHaveValues: 
                                   [{fieldName: \"key\", expectedValue: \"value\"}]
                            } } ],
        }],
    } )
  { ... 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/graphql',
  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();

Given Datatypes

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

Table: TestParserInputV2

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 20, 2024
parserIdstringyes DeprecatedThe unique identifier of the parser.
parserNamestringyes DeprecatedThe name of the parser.
parserScriptstringyes DeprecatedThe parser script to be tested.
repositoryNamestringyes DeprecatedThe name of the repository in which the parser is located.
testData[string]yes DeprecatedThe events on which to test the parser.

Returned Datatypes

The returned datatype, TestParserResultV2 is a union between two other datatypes: TestParserSuccessResultV2 and TestParserErrorResult. 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: TestParserSuccessResultV2

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 27, 2025
results[ParseEventResult]yes DeprecatedThe results of parsing test events. See ParseEventResult. This datatype and field are deprecated. They will be removed at the earliest in version 1.183.

Table: TestParserErrorResult

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: Oct 3, 2024
errorMessagestringyes DeprecatedAn error message while running a parser. No events were parsed. This datatype and field are deprecated. They will be removed at the earliest in version 1.183.