Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add pivot example for starlark processor #7976

Merged
merged 6 commits into from
Aug 12, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions plugins/processors/starlark/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ Attempting to modify the global scope will fail with an error.
- [rename](/plugins/processors/starlark/testdata/rename.star)
- [scale](/plugins/processors/starlark/testdata/scale.star)
- [number logic](/plugins/processors/starlark/testdata/number_logic.star)
- [pivot](/plugins/processors/starlark/testdata/pivot.star)

Open a [PR](https://github.com/influxdata/telegraf/compare) to add any other useful Starlark examples.

Expand Down
14 changes: 14 additions & 0 deletions plugins/processors/starlark/testdata/pivot.star
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'''
Pivots a key's value to be the key for another key.
In this example it pivots the value of key `sensor`
to be the key of the value in key `value`

Input: temperature sensor=001A0,value=111.48
Output: temperature 001A0=111.48
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Input: temperature sensor=001A0,value=111.48
Output: temperature 001A0=111.48
Input:
temperature sensor=001A0,value=111.48
Output:
temperature 001A0=111.48

'''

def apply(metric):
metric.fields[str(metric.fields['sensor'])] = metric.fields['value']
metric.fields.pop('value',None)
metric.fields.pop('sensor',None)
return metric