Skip to content

Commit

Permalink
[processor/transform] Added Int function to the transform processor (#…
Browse files Browse the repository at this point in the history
…14338)

[processor/transform] Added the Int function to the transform processor (#11810)
  • Loading branch information
mcdoker18 authored Sep 28, 2022
1 parent d3cc2dd commit 4b4688f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions processor/transformprocessor/internal/common/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 15 additions & 0 deletions processor/transformprocessor/internal/metrics/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 4 additions & 0 deletions unreleased/feat-int-func.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
change_type: enhancement
component: pkg/telemetryquerylanguage
note: Add the Int factory function to the transform processor
issues: [11810]

0 comments on commit 4b4688f

Please sign in to comment.