Skip to content

Problems with $lookup function in Telegraf json_transformation derived from jsonata-go #23

@iserranoe

Description

@iserranoe

I recently had a problem with a json transformation using jsonata in Telegraf. The transformation is the following:

$each($merge([metrics.fields]), function($value, $key) {{
    "key": $key,
    "value": $value
  }}) ~> $reduce(function($acc, $entry) {(
    $contains($entry.key, "__")
      ? (
        $outerLevelKey := $split($entry.key, "__")[0];
        $innerLevelKey := $split($entry.key, "__")[1];        
        $merge([$acc, { 
          $outerLevelKey: $merge([
            $lookup($acc, $outerLevelKey), 
            { $innerLevelKey:$entry.value } 
          ])
        }])
      )
      : $merge([$acc, { $entry.key: $entry.value }])
  )}, {})

That works perfectly in the simulator https://try.jsonata.org/5aN2vrMY3, but when used in Telegraf it doesn't work and I found the problematic function is $lookup($acc, $outerLevelKey), since using $acc.PressSPM instead doesn't cause any problem.

I first asked in Telegraf but they say the issue seems to be in the upstream library they are using, i.e. jsonata-go.

influxdata/telegraf#14069

Also, if anyone knows an alternative way to do the transformation, I'd really appreciate it.

Thanks a lot

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions