influxdata / telegraf

Agent for collecting, processing, aggregating, and writing metrics, logs, and other arbitrary data.
https://influxdata.com/telegraf
MIT License
14.51k stars 5.56k forks source link

JSON_v2 parser enhancement: zip values from two different arrays #9328

Open samhld opened 3 years ago

samhld commented 3 years ago

There is a JSON style (albeit probably not an optimal one) that splits keys and values into separate arrays. A real world example is needing to pair keys in "keys" and values in "values" in the below JSON, such that the Line Protocol output gets pairs like shortterm=0.83:

Note: it can be assumed that these will be ordered appropriately

    {
        "keys": [
            "shortterm",
            "midterm",
            "longterm"
        ],
        "values": [
            0.83,
            1.76,
            2.27
        ]
    }

This is done in Starlark with zip() (snippet):

pairs = zip(dsnames, values)
for key,val in pairs:
    if val == None:
        val = float()
    new_metric.fields[key] = val
samhld commented 3 years ago

@sjwang90 I can't assign or label this so, FYI, the Starlark label was added automatically and it shouldn't have been.

ssoroka commented 3 years ago

Probably a better use case for Starlark than the JSON parser for now.