Skip to content

Commit a6c39a1

Browse files
committed
adapt to pr review
Signed-off-by: Florian Bacher <[email protected]>
1 parent 721c537 commit a6c39a1

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

pkg/ottl/e2e/e2e_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ func Test_e2e_editors(t *testing.T) {
5454
tCtx.GetLogRecord().Attributes().Remove("flags")
5555
tCtx.GetLogRecord().Attributes().Remove("total.string")
5656
tCtx.GetLogRecord().Attributes().Remove("foo")
57-
tCtx.GetLogRecord().Attributes().Remove("double_value")
5857
},
5958
},
6059
{
@@ -82,7 +81,6 @@ func Test_e2e_editors(t *testing.T) {
8281
m.PutStr("test.foo.flags", "pass")
8382
m.PutStr("test.foo.slice.0", "val")
8483
m.PutStr("test.foo.nested.test", "pass")
85-
m.PutDouble("test.double_value", 10.5)
8684
m.CopyTo(tCtx.GetLogRecord().Attributes())
8785
},
8886
},
@@ -104,7 +102,6 @@ func Test_e2e_editors(t *testing.T) {
104102
m.PutStr("foo.bar", "pass")
105103
m.PutStr("foo.flags", "pass")
106104
m.PutStr("foo.slice.0", "val")
107-
m.PutDouble("double_value", 10.5)
108105
m2 := m.PutEmptyMap("foo.nested")
109106
m2.PutStr("test", "pass")
110107
m.CopyTo(tCtx.GetLogRecord().Attributes())
@@ -117,7 +114,6 @@ func Test_e2e_editors(t *testing.T) {
117114
tCtx.GetLogRecord().Attributes().Remove("http.path")
118115
tCtx.GetLogRecord().Attributes().Remove("http.url")
119116
tCtx.GetLogRecord().Attributes().Remove("foo")
120-
tCtx.GetLogRecord().Attributes().Remove("double_value")
121117
},
122118
},
123119
{
@@ -132,7 +128,6 @@ func Test_e2e_editors(t *testing.T) {
132128
tCtx.GetLogRecord().Attributes().Remove("http.url")
133129
tCtx.GetLogRecord().Attributes().Remove("flags")
134130
tCtx.GetLogRecord().Attributes().Remove("foo")
135-
tCtx.GetLogRecord().Attributes().Remove("double_value")
136131
},
137132
},
138133
{
@@ -842,7 +837,6 @@ func constructLogTransformContext() ottllog.TransformContext {
842837
logRecord.Attributes().PutStr("http.url", "http://localhost/health")
843838
logRecord.Attributes().PutStr("flags", "A|B|C")
844839
logRecord.Attributes().PutStr("total.string", "123456789")
845-
logRecord.Attributes().PutDouble("double_value", 10.5)
846840
m := logRecord.Attributes().PutEmptyMap("foo")
847841
m.PutStr("bar", "pass")
848842
m.PutStr("flags", "pass")

processor/transformprocessor/internal/metrics/func_scale.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ func Scale(args ScaleArguments) (ottl.ExprFunc[ottlmetric.TransformContext], err
3737
return func(ctx context.Context, tCtx ottlmetric.TransformContext) (any, error) {
3838
metric := tCtx.GetMetric()
3939

40+
var unit string
41+
var err error
42+
if !args.Unit.IsEmpty() {
43+
unit, err = args.Unit.Get().Get(ctx, tCtx)
44+
if err != nil {
45+
return nil, fmt.Errorf("could not get unit from ScaleArguments: %w", err)
46+
}
47+
}
48+
4049
switch metric.Type() {
4150
case pmetric.MetricTypeGauge:
4251
scaleMetric(metric.Gauge().DataPoints(), args.Multiplier)
@@ -51,14 +60,10 @@ func Scale(args ScaleArguments) (ottl.ExprFunc[ottlmetric.TransformContext], err
5160
default:
5261
return nil, fmt.Errorf("unsupported metric type: '%v'", metric.Type())
5362
}
54-
5563
if !args.Unit.IsEmpty() {
56-
unit, err := args.Unit.Get().Get(ctx, tCtx)
57-
if err != nil {
58-
return nil, fmt.Errorf("could not get unit from ScaleArguments: %w", err)
59-
}
6064
metric.SetUnit(unit)
6165
}
66+
6267
return nil, nil
6368
}, nil
6469
}

processor/transformprocessor/internal/metrics/func_scale_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,31 @@ func TestScale(t *testing.T) {
114114
},
115115
wantErr: false,
116116
},
117+
{
118+
name: "scale summary metric",
119+
valueFunc: func() pmetric.Metric {
120+
metric := pmetric.NewMetric()
121+
dp := metric.SetEmptySummary().DataPoints().AppendEmpty()
122+
dp.SetSum(10.0)
123+
qv := dp.QuantileValues().AppendEmpty()
124+
qv.SetValue(10.0)
125+
126+
return metric
127+
},
128+
args: ScaleArguments{
129+
Multiplier: 10.0,
130+
},
131+
wantFunc: func() pmetric.Metric {
132+
metric := pmetric.NewMetric()
133+
dp := metric.SetEmptySummary().DataPoints().AppendEmpty()
134+
dp.SetSum(100.0)
135+
qv := dp.QuantileValues().AppendEmpty()
136+
qv.SetValue(100.0)
137+
138+
return metric
139+
},
140+
wantErr: false,
141+
},
117142
{
118143
name: "unsupported: exponential histogram metric",
119144
valueFunc: func() pmetric.Metric {

0 commit comments

Comments
 (0)