Skip to content

processors.parser doesn't seem to work with json_v2 data_format #10365

Description

@siehar

Relevent telegraf.conf

[agent]
  interval = "1s"
  flush_interval = "1s"

[[inputs.file]]
  files = ["./foo.json"]
  data_format = "value"
  data_type = "string"

[[processors.parser]]
  parse_fields = ["value"]
  data_format = "json_v2"

  [[processors.parser.json_v2]]
    [[processors.parser.json_v2.object]]
      path = "@this"
      timestamp_key = "time"
      timestamp_format = "2006-01-02T15:04:05"
      timestamp_timezone = "Local"
      disable_prepend_keys = true

      [[processors.parser.json_v2.object.field]]
        path = "test"
        type = "uint"

[[outputs.file]]
  files = ["stdout"]
  data_format = "influx"

Logs from Telegraf

2022-01-02T22:08:47Z I! Starting Telegraf 1.21.1
2022-01-02T22:08:47Z E! [telegraf] Error running agent: Error loading config file telegraf.conf: plugin processors.parser: line 14: configuration specified the fields ["object"], but they weren't used

System info

Telegraf 1.21.1 (git: HEAD 7c9a9c1) (both on Debian 11 and Ubuntu 20.04, amd64); installed via Debian package downloaded from Github Releases page

Docker

not applicable

Steps to reproduce

  1. Place a file foo.json into working directory with content e.g. {"time": "2022-01-01T21:57:10", "test": 123}
  2. Start telegraf with telegraf --config telegraf.conf with the config from above
  3. Error message is shown

Expected behavior

Telegraf should print the one metric from the JSON file to stdout in influx format every second.

Actual behavior

Telegraf exits with an error because of invalid config.
It seems it doesn't recognize that the object section must be handed to the json_v2 parser or something.

Additional info

  • When I use data_format = "json_v2" in the input.file section and place the same config there, data is parsed correctly, so I think the json_v2 config should be OK
  • If I replace the data_format in the processors.parser section with influx, remove the additional json_v2 config and place an influx-formatted metric into the input file, then it also works
  • I'm not 100% sure if the way I specified the config for the json_v2 parser is correct for processors.parser. I didn't find any example. If this is a user error on my part it would at least be good to add a correct example to the processors.parser Readme

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/configurationarea/jsonjson and json_v2 parser/serialiser relatedbugunexpected problem or unintended behaviorplugin/parser1. Request for new parser plugins 2. Issues/PRs that are related to parser pluginsplugin/processor

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions