Starlark script for renaming prometheus remote write metrics #9074
Starlark script for renaming prometheus remote write metrics #9074helenosheaa merged 8 commits intomasterfrom
Conversation
| for k, v in metric.fields.items(): | ||
| metric.name = k | ||
| metric.fields["value"] = v | ||
| metric.fields.pop(k) | ||
| return metric No newline at end of file |
There was a problem hiding this comment.
if we're going to recommend this to everyone, we should include a metric.name guard in this function to look for the metric name, and either handle the case where there are multiple fields (they can't all be the metric name), or specify in the description and file name that this is specifically for prometheus.
There was a problem hiding this comment.
Added a guard to check it's promtheus_remote_write. I'd put in the other example a namepass but probably makes more sense to have it in there. I've added in to the name and description that it's for promtheus remote write where there is only one field as that is the use case.
| - [multiple metrics from json array](/plugins/processors/starlark/testdata/multiple_metrics_with_json.star) - Builds a new metric from each element of a json array then returns all the created metrics. | ||
| - [custom error](/plugins/processors/starlark/testdata/fail.star) - Return a custom error with [fail](https://docs.bazel.build/versions/master/skylark/lib/globals.html#fail). | ||
| - [compare with previous metric](/plugins/processors/starlark/testdata/compare_metrics.star) - Compare the current metric with the previous one using the shared state. | ||
| - [rename measurement](/plugins/processors/starlark/testdata/rename.star) - Rename measurement name with fieldname and rename fieldname to value. |
There was a problem hiding this comment.
there is already a rename.star, double check file name
There was a problem hiding this comment.
updated to rename_prometheus_remote_write
|
|
||
| - Use the [Starlark processor](https://github.com/influxdata/telegraf/blob/master/plugins/processors/starlark/README.md) to rename the measurement name to the fieldname and rename the fieldname to value. Use namepass to only apply the script to prometheus_remote_write metrics | ||
|
|
||
| - Example script: |
There was a problem hiding this comment.
maybe just link to the script so we don't have to keep the two docs in sync.
There was a problem hiding this comment.
yeah i suggested otherwise so people could just copy and paste from the readme but one extra click isn't a big deal
|
@helenosheaa - Thanks so much for adding this in! |
|
@disfluxly no problem! I hope this helps for your use case. I'll close the related issue but if there are any issues feel free to reopen. |
Adds script to Starlark examples and to the readme of the prometheus remote write parser.
Enables alignment with InfluxDB v1.8 prometheus remote write spec outlined here
The provided Starlark script renames the measurement name using the fieldname (which holds the Prometheus metric name), and renames the fieldname to value.
Relates to #9038