From 4b4688f83dd482e36ff1dbe67ef0d76e54eb48e4 Mon Sep 17 00:00:00 2001 From: Vitalii Solodilov Date: Wed, 28 Sep 2022 23:53:27 +0300 Subject: [PATCH] [processor/transform] Added Int function to the transform processor (#14338) [processor/transform] Added the Int function to the transform processor (#11810) --- .../internal/common/functions.go | 1 + .../internal/metrics/processor_test.go | 15 +++++++++++++++ unreleased/feat-int-func.yaml | 4 ++++ 3 files changed, 20 insertions(+) create mode 100644 unreleased/feat-int-func.yaml diff --git a/processor/transformprocessor/internal/common/functions.go b/processor/transformprocessor/internal/common/functions.go index 18aebb67a042..37b12c1c881f 100644 --- a/processor/transformprocessor/internal/common/functions.go +++ b/processor/transformprocessor/internal/common/functions.go @@ -24,6 +24,7 @@ var registry = map[string]interface{}{ "IsMatch": ottlfuncs.IsMatch, "Concat": ottlfuncs.Concat, "Split": ottlfuncs.Split, + "Int": ottlfuncs.Int, "keep_keys": ottlfuncs.KeepKeys, "set": ottlfuncs.Set, "truncate_all": ottlfuncs.TruncateAll, diff --git a/processor/transformprocessor/internal/metrics/processor_test.go b/processor/transformprocessor/internal/metrics/processor_test.go index 9f72fb4120eb..c7c51e4842f3 100644 --- a/processor/transformprocessor/internal/metrics/processor_test.go +++ b/processor/transformprocessor/internal/metrics/processor_test.go @@ -57,6 +57,20 @@ func TestProcess(t *testing.T) { td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(3).Summary().DataPoints().At(0).Attributes().PutString("test", "pass") }, }, + { + statements: []string{`set(attributes["int_value"], Int("2")) where metric.name == "operationA"`}, + want: func(td pmetric.Metrics) { + td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Sum().DataPoints().At(0).Attributes().PutInt("int_value", 2) + td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Sum().DataPoints().At(1).Attributes().PutInt("int_value", 2) + }, + }, + { + statements: []string{`set(attributes["int_value"], Int(value_double)) where metric.name == "operationA"`}, + want: func(td pmetric.Metrics) { + td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Sum().DataPoints().At(0).Attributes().PutInt("int_value", 1) + td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Sum().DataPoints().At(1).Attributes().PutInt("int_value", 3) + }, + }, { statements: []string{`keep_keys(attributes, "attr2") where metric.name == "operationA"`}, want: func(td pmetric.Metrics) { @@ -355,6 +369,7 @@ func fillMetricOne(m pmetric.Metric) { dataPoint1 := m.Sum().DataPoints().AppendEmpty() dataPoint1.SetStartTimestamp(StartTimestamp) + dataPoint1.SetDoubleValue(3.7) dataPoint1.Attributes().PutString("attr1", "test1") dataPoint1.Attributes().PutString("attr2", "test2") dataPoint1.Attributes().PutString("attr3", "test3") diff --git a/unreleased/feat-int-func.yaml b/unreleased/feat-int-func.yaml new file mode 100644 index 000000000000..e48bcb2a5695 --- /dev/null +++ b/unreleased/feat-int-func.yaml @@ -0,0 +1,4 @@ +change_type: enhancement +component: pkg/telemetryquerylanguage +note: Add the Int factory function to the transform processor +issues: [11810]