Skip to content

Commit

Permalink
fix failing checks
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Bacher <florian.bacher@dynatrace.com>
  • Loading branch information
bacherfl committed Jun 20, 2024
1 parent d398d64 commit e495e03
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 50 deletions.
46 changes: 0 additions & 46 deletions pkg/ottl/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlmetric"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/ottlfuncs"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/plogtest"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/pmetrictest"
)

var (
Expand Down Expand Up @@ -305,38 +304,6 @@ func Test_e2e_editors(t *testing.T) {
}
}

func Test_e2e_metricEditors(t *testing.T) {
tests := []struct {
statement string
want func(tCtx ottlmetric.TransformContext)
}{
{
statement: `scale_metric(data_points,0.1)`,
want: func(tCtx ottlmetric.TransformContext) {
tCtx.GetMetric().Gauge().DataPoints().At(0).SetDoubleValue(1.0)
},
},
}

for _, tt := range tests {
t.Run(tt.statement, func(t *testing.T) {
settings := componenttest.NewNopTelemetrySettings()
metricParser, err := ottlmetric.NewParser(ottlfuncs.StandardFuncs[ottlmetric.TransformContext](), settings)
assert.NoError(t, err)
logStatements, err := metricParser.ParseStatement(tt.statement)
assert.NoError(t, err)

tCtx := constructMetricTransformContext()
_, _, _ = logStatements.Execute(context.Background(), tCtx)

exTCtx := constructMetricTransformContext()
tt.want(exTCtx)

assert.NoError(t, pmetrictest.CompareResourceMetrics(newResourceMetrics(exTCtx), newResourceMetrics(tCtx)))
})
}
}

func Test_e2e_converters(t *testing.T) {
tests := []struct {
statement string
Expand Down Expand Up @@ -856,19 +823,6 @@ func Test_e2e_ottl_features(t *testing.T) {
}
}

func constructMetricTransformContext() ottlmetric.TransformContext {
resource := pcommon.NewResource()
resource.Attributes().PutStr("host.name", "localhost")

scope := pcommon.NewInstrumentationScope()
scope.SetName("scope")

metric := pmetric.NewMetric()
metric.SetEmptyGauge().DataPoints().AppendEmpty().SetDoubleValue(10.0)

return ottlmetric.NewTransformContext(metric, pmetric.NewMetricSlice(), scope, resource)
}

func constructLogTransformContext() ottllog.TransformContext {
resource := pcommon.NewResource()
resource.Attributes().PutStr("host.name", "localhost")
Expand Down
4 changes: 2 additions & 2 deletions processor/transformprocessor/internal/metrics/func_scale.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package metrics // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/ottlfuncs"
package metrics // import "github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor/internal/metrics"

import (
"context"
Expand Down Expand Up @@ -34,7 +34,7 @@ func createScaleFunction(_ ottl.FunctionContext, oArgs ottl.Arguments) (ottl.Exp
}

func Scale(args ScaleArguments) (ottl.ExprFunc[ottlmetric.TransformContext], error) {
return func(ctx context.Context, tCtx ottlmetric.TransformContext) (any, error) {
return func(_ context.Context, tCtx ottlmetric.TransformContext) (any, error) {
metric := tCtx.GetMetric()

switch metric.Type() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func Test_MetricFunctions(t *testing.T) {
expected["extract_sum_metric"] = newExtractSumMetricFactory()
expected["extract_count_metric"] = newExtractCountMetricFactory()
expected["copy_metric"] = newCopyMetricFactory()
expected["scale_metric"] = newScaleMetricFactory()

defer testutil.SetFeatureGateForTest(t, useConvertBetweenSumAndGaugeMetricContext, true)()
actual := MetricFunctions()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,11 @@ func Test_ProcessMetrics_MetricContext(t *testing.T) {
},
},
{
statements: []string{`scale_metric(0.1,"") where name == "operationA"`},
statements: []string{`scale_metric(10.0,"s") where name == "operationA"`},
want: func(td pmetric.Metrics) {
td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Sum().DataPoints().At(0).SetDoubleValue(0.1)
td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Sum().DataPoints().At(0).SetDoubleValue(10.0)
td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Sum().DataPoints().At(1).SetDoubleValue(37.0)
td.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).SetUnit("s")
},
},
}
Expand Down

0 comments on commit e495e03

Please sign in to comment.