From 901e63e37d10bfcbe221321ec3111260a9cb8748 Mon Sep 17 00:00:00 2001 From: Samantha Wang <32681364+sjwang90@users.noreply.github.com> Date: Wed, 19 Aug 2020 16:26:35 -0700 Subject: [PATCH] add example input/outputs to starlark examples (#7980) * add sample input/outputs to starlark examples * update ratio.star with example input/outputs * Update rename.star * update scale.star with input/output examples * fix spacing * fix spacing --- plugins/processors/starlark/testdata/number_logic.star | 9 ++++++++- plugins/processors/starlark/testdata/ratio.star | 7 +++++++ plugins/processors/starlark/testdata/rename.star | 5 +++++ plugins/processors/starlark/testdata/scale.star | 5 +++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/plugins/processors/starlark/testdata/number_logic.star b/plugins/processors/starlark/testdata/number_logic.star index 4ecd56890..719b61a9f 100644 --- a/plugins/processors/starlark/testdata/number_logic.star +++ b/plugins/processors/starlark/testdata/number_logic.star @@ -1,4 +1,11 @@ -# Set any 'status' field between 1 and 6 to a value of 0 +# Set a logic function to transform a numerical value to another numerical value +# Example: Set any 'status' field between 1 and 6 to a value of 0 +# +# Example Input: +# lb, http_method=GET status=5 1465839830100400201 +# Example Output: +# lb, http_method=GET status=0 1465839830100400201 + def apply(metric): v = metric.fields.get('status') diff --git a/plugins/processors/starlark/testdata/ratio.star b/plugins/processors/starlark/testdata/ratio.star index 086cd2e69..ee4f5b20a 100644 --- a/plugins/processors/starlark/testdata/ratio.star +++ b/plugins/processors/starlark/testdata/ratio.star @@ -1,4 +1,11 @@ # Compute the ratio of two integer fields. +# +# Example: A new field 'usage' from an existing fields 'used' and 'total' +# +# Example Input: +# memory, host=hostname used=11038756864.4948,total=17179869184.1221 1597255082000000000 +# Example Output: +# memory, host=hostname used=11038756864.4948,total=17179869184.1221,usage=64.254021647 1597255082000000000 def apply(metric): used = float(metric.fields['used']) diff --git a/plugins/processors/starlark/testdata/rename.star b/plugins/processors/starlark/testdata/rename.star index 51a372911..5c5be1120 100644 --- a/plugins/processors/starlark/testdata/rename.star +++ b/plugins/processors/starlark/testdata/rename.star @@ -1,4 +1,9 @@ # Rename any tags using the mapping in the renames dict. +# +# Example Input: +# measurement, host=hostname lower=0,upper=100 1597255410000000000 +# Example Output: +# measurement, host=hostname min=0,max=100 1597255410000000000 renames = { 'lower': 'min', diff --git a/plugins/processors/starlark/testdata/scale.star b/plugins/processors/starlark/testdata/scale.star index 502a13146..a71c5a9aa 100644 --- a/plugins/processors/starlark/testdata/scale.star +++ b/plugins/processors/starlark/testdata/scale.star @@ -1,4 +1,9 @@ # Multiply any float fields by 10 +# +# Example Input: +# modbus,host=hostname Current=1.22,Energy=0,Frequency=60i,Power=0,Voltage=123.9000015258789 1554079521000000000 +# Example Output: +# modbus,host=hostname Current=12.2,Energy=0,Frequency=60i,Power=0,Voltage=1239.000015258789 1554079521000000000 def apply(metric): for k, v in metric.fields.items():