Skip to content

Commit 4b4688f

Browse files
authored
[processor/transform] Added Int function to the transform processor (#14338)
[processor/transform] Added the Int function to the transform processor (#11810)
1 parent d3cc2dd commit 4b4688f

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

processor/transformprocessor/internal/common/functions.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var registry = map[string]interface{}{
2424
"IsMatch": ottlfuncs.IsMatch,
2525
"Concat": ottlfuncs.Concat,
2626
"Split": ottlfuncs.Split,
27+
"Int": ottlfuncs.Int,
2728
"keep_keys": ottlfuncs.KeepKeys,
2829
"set": ottlfuncs.Set,
2930
"truncate_all": ottlfuncs.TruncateAll,

processor/transformprocessor/internal/metrics/processor_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,20 @@ func TestProcess(t *testing.T) {
5757
td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(3).Summary().DataPoints().At(0).Attributes().PutString("test", "pass")
5858
},
5959
},
60+
{
61+
statements: []string{`set(attributes["int_value"], Int("2")) where metric.name == "operationA"`},
62+
want: func(td pmetric.Metrics) {
63+
td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Sum().DataPoints().At(0).Attributes().PutInt("int_value", 2)
64+
td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Sum().DataPoints().At(1).Attributes().PutInt("int_value", 2)
65+
},
66+
},
67+
{
68+
statements: []string{`set(attributes["int_value"], Int(value_double)) where metric.name == "operationA"`},
69+
want: func(td pmetric.Metrics) {
70+
td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Sum().DataPoints().At(0).Attributes().PutInt("int_value", 1)
71+
td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Sum().DataPoints().At(1).Attributes().PutInt("int_value", 3)
72+
},
73+
},
6074
{
6175
statements: []string{`keep_keys(attributes, "attr2") where metric.name == "operationA"`},
6276
want: func(td pmetric.Metrics) {
@@ -355,6 +369,7 @@ func fillMetricOne(m pmetric.Metric) {
355369

356370
dataPoint1 := m.Sum().DataPoints().AppendEmpty()
357371
dataPoint1.SetStartTimestamp(StartTimestamp)
372+
dataPoint1.SetDoubleValue(3.7)
358373
dataPoint1.Attributes().PutString("attr1", "test1")
359374
dataPoint1.Attributes().PutString("attr2", "test2")
360375
dataPoint1.Attributes().PutString("attr3", "test3")

unreleased/feat-int-func.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
change_type: enhancement
2+
component: pkg/telemetryquerylanguage
3+
note: Add the Int factory function to the transform processor
4+
issues: [11810]

0 commit comments

Comments
 (0)