Skip to content

Commit

Permalink
fix: Sampling Processor not removing higher level objs (#1879)
Browse files Browse the repository at this point in the history
* test fix for logs

* add log msg

* remove resource logs too

* remove scope and resource level objs for traces & metrics

* add test for verifying behavior
  • Loading branch information
dpaasman00 authored Sep 26, 2024
1 parent 9548eb9 commit a022fea
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 18 deletions.
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ require (
github.com/open-telemetry/opentelemetry-collector-contrib/extension/pprofextension v0.109.0
github.com/open-telemetry/opentelemetry-collector-contrib/extension/sigv4authextension v0.109.0
github.com/open-telemetry/opentelemetry-collector-contrib/extension/storage/filestorage v0.109.0
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden v0.109.0
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest v0.109.0
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden v0.110.0
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest v0.110.0
github.com/open-telemetry/opentelemetry-collector-contrib/processor/attributesprocessor v0.109.0
github.com/open-telemetry/opentelemetry-collector-contrib/processor/cumulativetodeltaprocessor v0.109.0
github.com/open-telemetry/opentelemetry-collector-contrib/processor/deltatorateprocessor v0.109.0
Expand Down Expand Up @@ -184,7 +184,7 @@ require (
go.opentelemetry.io/collector/extension/zpagesextension v0.109.0
go.opentelemetry.io/collector/featuregate v1.15.0
go.opentelemetry.io/collector/otelcol v0.109.0
go.opentelemetry.io/collector/pdata v1.15.0
go.opentelemetry.io/collector/pdata v1.16.0
go.opentelemetry.io/collector/processor v0.109.0
go.opentelemetry.io/collector/processor/batchprocessor v0.109.0
go.opentelemetry.io/collector/processor/memorylimiterprocessor v0.109.0
Expand Down Expand Up @@ -438,7 +438,7 @@ require (
github.com/Azure/azure-amqp-common-go/v4 v4.2.0 // indirect
github.com/bmatcuk/doublestar/v4 v4.6.1 // indirect
github.com/hooklift/gowsdl v0.5.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil v0.109.0 // indirect; indir2ct
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil v0.110.0 // indirect; indir2ct
github.com/ovh/go-ovh v1.6.0 // indirect
github.com/relvacode/iso8601 v1.4.0 // indirect
)
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2052,14 +2052,14 @@ github.com/open-telemetry/opentelemetry-collector-contrib/pkg/batchpersignal v0.
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/batchpersignal v0.109.0/go.mod h1:1aJ+q3jFR+UVsitJF03xKrJ/+N8QyHIs9yWoRS85498=
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/experimentalmetricmetadata v0.109.0 h1:T6rvvaY1PW5Oqwb3fhFy89UARRoveqtSLh6t5uvktes=
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/experimentalmetricmetadata v0.109.0/go.mod h1:EWEI4jcMr9jXlBWTG77rqknzc3K+QObImve7y5vdnjs=
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden v0.109.0 h1:9mStsYv/9nnav/mftmHxEA6fp7c7mfd5CgU2802frjE=
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden v0.109.0/go.mod h1:P7e6ch+uoSfxK+lMwfcndkHE6gWUqvWKpr7mD04KIAA=
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden v0.110.0 h1:07mGeb5o9W6DcT1xlXBX5pHamVO9bcro0pFct/z0Ivs=
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden v0.110.0/go.mod h1:eazQnU3D7Xwyctq8Yfig4ws5HcnD3G+ygWrG9H03JjE=
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl v0.109.0 h1:k7uHhrznH4dYvzbaCRz5VgFyHzhd1NGow1s6504r6tA=
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl v0.109.0/go.mod h1:LfwqmbImTBZW5psp7tCyZPHIPy3Imwexq+K/A1NAhEY=
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest v0.109.0 h1:Mi0qKcH4VjyyZsbaWYG038drk5FCFL7igVM8abEL4ZY=
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest v0.109.0/go.mod h1:KvJWxR0bDk9Qh0ktw4gOFsd/ZrJ7p5KTAQueEJsaK9Q=
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil v0.109.0 h1:3kXFgdEEKw37ftdRC7SmXAiZuLahVavqOYRhlJVMLc8=
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil v0.109.0/go.mod h1:HtaWI5WJKJkBhHz2R7Xb2n7R3fdBPhfKieYcQajNCTo=
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest v0.110.0 h1:/kMxDplBmo99UQwkpnCkHO3mwBD6/YcX/ldwlZSURFw=
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest v0.110.0/go.mod h1:nn/ktwLdZ6O9mtnRuak8NQEfGRow3VI3l+YqAroJX7g=
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil v0.110.0 h1:KYBzbgQyCz4i5zjzs0iBOFuNh2vagaw2seqvZ7Lftxk=
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil v0.110.0/go.mod h1:zLtbGLswPAKzTHM4C1Pcxb+PgNHgo6aGVZQtQaeBtec=
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/resourcetotelemetry v0.109.0 h1:q3rHsRNnB97Xw2rjTBW1qpw6y+LP2xWSRbmTJtPIyQM=
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/resourcetotelemetry v0.109.0/go.mod h1:vo39/3CexkMcF+T0T8Ic/Oer/ErrSMiD+MWNBYo9VYE=
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/sampling v0.109.0 h1:YQB8+grNfmaLqiavbv4VKhBw1NF8O6pSmbLC+FjMrKM=
Expand Down Expand Up @@ -2681,8 +2681,8 @@ go.opentelemetry.io/collector/otelcol v0.109.0 h1:x7hcrV3lnCg7Ub0Q5haLRFWmqS3mPi
go.opentelemetry.io/collector/otelcol v0.109.0/go.mod h1:LR2qca0GFWd2yZFBaSTpTIPqnAXJM3gmes++nZNx4ms=
go.opentelemetry.io/collector/otelcol/otelcoltest v0.109.0 h1:j1jEq+iBfzc2XrFZphQOz2VoYlsOLqZFnBTWZfTq+yU=
go.opentelemetry.io/collector/otelcol/otelcoltest v0.109.0/go.mod h1:Fcacbap4v39ymbW6AlgZQUqcQm+YMo2rO9izv66IpwQ=
go.opentelemetry.io/collector/pdata v1.15.0 h1:q/T1sFpRKJnjDrUsHdJ6mq4uSqViR/f92yvGwDby/gY=
go.opentelemetry.io/collector/pdata v1.15.0/go.mod h1:2wcsTIiLAJSbqBq/XUUYbi+cP+N87d0jEJzmb9nT19U=
go.opentelemetry.io/collector/pdata v1.16.0 h1:g02K8jlRnmQ7TQDuXpdgVL6vIxIVqr5Gbb1qIR27rto=
go.opentelemetry.io/collector/pdata v1.16.0/go.mod h1:YZZJIt2ehxosYf/Y1pbvexjNWsIGNNrzzlCTO9jC1F4=
go.opentelemetry.io/collector/pdata/pprofile v0.109.0 h1:5lobQKeHk8p4WC7KYbzL6ZqqX3eSizsdmp5vM8pQFBs=
go.opentelemetry.io/collector/pdata/pprofile v0.109.0/go.mod h1:lXIifCdtR5ewO17JAYTUsclMqRp6h6dCowoXHhGyw8Y=
go.opentelemetry.io/collector/pdata/testdata v0.109.0 h1:gvIqy6juvqFET/6zi+zUOH1KZY/vtEDZW55u7gJ/hEo=
Expand Down
10 changes: 8 additions & 2 deletions processor/samplingprocessor/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ require (
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/collector/component v0.109.0
go.opentelemetry.io/collector/consumer v0.109.0
go.opentelemetry.io/collector/pdata v1.15.0
go.opentelemetry.io/collector/pdata v1.16.0
go.opentelemetry.io/collector/processor v0.109.0
go.uber.org/zap v1.27.0
)

require (
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil v0.110.0 // indirect
)

require (
github.com/alecthomas/participle/v2 v2.1.1 // indirect
github.com/antonmedv/expr v1.15.5 // indirect
Expand All @@ -29,6 +34,7 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.109.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest v0.110.0
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/ua-parser/uap-go v0.0.0-20240611065828-3a4781585db6 // indirect
go.opentelemetry.io/collector v0.109.0 // indirect
Expand All @@ -45,7 +51,7 @@ require (
golang.org/x/sys v0.24.0 // indirect
golang.org/x/text v0.17.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240822170219-fc7c04adadcd // indirect
google.golang.org/grpc v1.66.0 // indirect
google.golang.org/grpc v1.66.2 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
14 changes: 10 additions & 4 deletions processor/samplingprocessor/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,14 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.109.0 h1:4VBRgtyh3hHSgAVGgs4bvNwJd0oUGyxVA3eQO2ujNsA=
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.109.0/go.mod h1:9MGQCqxdCNBhdD+7QBZ6hH9HipXe5CajMafVKglD5f0=
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden v0.110.0 h1:07mGeb5o9W6DcT1xlXBX5pHamVO9bcro0pFct/z0Ivs=
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden v0.110.0/go.mod h1:eazQnU3D7Xwyctq8Yfig4ws5HcnD3G+ygWrG9H03JjE=
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl v0.109.0 h1:k7uHhrznH4dYvzbaCRz5VgFyHzhd1NGow1s6504r6tA=
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl v0.109.0/go.mod h1:LfwqmbImTBZW5psp7tCyZPHIPy3Imwexq+K/A1NAhEY=
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest v0.110.0 h1:/kMxDplBmo99UQwkpnCkHO3mwBD6/YcX/ldwlZSURFw=
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest v0.110.0/go.mod h1:nn/ktwLdZ6O9mtnRuak8NQEfGRow3VI3l+YqAroJX7g=
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil v0.110.0 h1:KYBzbgQyCz4i5zjzs0iBOFuNh2vagaw2seqvZ7Lftxk=
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil v0.110.0/go.mod h1:zLtbGLswPAKzTHM4C1Pcxb+PgNHgo6aGVZQtQaeBtec=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v1.20.2 h1:5ctymQzZlyOON1666svgwn3s6IKWgfbjsejTMiXIyjg=
Expand Down Expand Up @@ -93,8 +99,8 @@ go.opentelemetry.io/collector/consumer/consumerprofiles v0.109.0 h1:+WZ6MEWQRC6s
go.opentelemetry.io/collector/consumer/consumerprofiles v0.109.0/go.mod h1:spZ9Dn1MRMPDHHThdXZA5TrFhdOL1wsl0Dw45EBVoVo=
go.opentelemetry.io/collector/consumer/consumertest v0.109.0 h1:v4w9G2MXGJ/eabCmX1DvQYmxzdysC8UqIxa/BWz7ACo=
go.opentelemetry.io/collector/consumer/consumertest v0.109.0/go.mod h1:lECt0qOrx118wLJbGijtqNz855XfvJv0xx9GSoJ8qSE=
go.opentelemetry.io/collector/pdata v1.15.0 h1:q/T1sFpRKJnjDrUsHdJ6mq4uSqViR/f92yvGwDby/gY=
go.opentelemetry.io/collector/pdata v1.15.0/go.mod h1:2wcsTIiLAJSbqBq/XUUYbi+cP+N87d0jEJzmb9nT19U=
go.opentelemetry.io/collector/pdata v1.16.0 h1:g02K8jlRnmQ7TQDuXpdgVL6vIxIVqr5Gbb1qIR27rto=
go.opentelemetry.io/collector/pdata v1.16.0/go.mod h1:YZZJIt2ehxosYf/Y1pbvexjNWsIGNNrzzlCTO9jC1F4=
go.opentelemetry.io/collector/pdata/pprofile v0.109.0 h1:5lobQKeHk8p4WC7KYbzL6ZqqX3eSizsdmp5vM8pQFBs=
go.opentelemetry.io/collector/pdata/pprofile v0.109.0/go.mod h1:lXIifCdtR5ewO17JAYTUsclMqRp6h6dCowoXHhGyw8Y=
go.opentelemetry.io/collector/pdata/testdata v0.109.0 h1:gvIqy6juvqFET/6zi+zUOH1KZY/vtEDZW55u7gJ/hEo=
Expand Down Expand Up @@ -158,8 +164,8 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240822170219-fc7c04adadcd h1:6TEm2ZxXoQmFWFlt1vNxvVOa1Q0dXFQD1m/rYjXmS0E=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240822170219-fc7c04adadcd/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU=
google.golang.org/grpc v1.66.0 h1:DibZuoBznOxbDQxRINckZcUvnCEvrW9pcWIE2yF9r1c=
google.golang.org/grpc v1.66.0/go.mod h1:s3/l6xSSCURdVfAnL+TqCNMyTDAGN6+lZeVxnZR128Y=
google.golang.org/grpc v1.66.2 h1:3QdXkuq3Bkh7w+ywLdLvM56cmGvQHUMZpiCzt6Rqaoo=
google.golang.org/grpc v1.66.2/go.mod h1:s3/l6xSSCURdVfAnL+TqCNMyTDAGN6+lZeVxnZR128Y=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
18 changes: 18 additions & 0 deletions processor/samplingprocessor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,13 @@ func (sp *tracesSamplingProcessor) processTraces(ctx context.Context, td ptrace.
return err == nil && match && sampleFunc(sp.dropCutOffRatio)
})
}
td.ResourceSpans().At(i).ScopeSpans().RemoveIf(func(ss ptrace.ScopeSpans) bool {
return ss.Spans().Len() == 0
})
}
td.ResourceSpans().RemoveIf(func(rs ptrace.ResourceSpans) bool {
return rs.ScopeSpans().Len() == 0
})
return td, nil
}

Expand Down Expand Up @@ -145,7 +151,13 @@ func (sp *logsSamplingProcessor) processLogs(ctx context.Context, ld plog.Logs)
return err == nil && match && sampleFunc(sp.dropCutOffRatio)
})
}
ld.ResourceLogs().At(i).ScopeLogs().RemoveIf(func(sl plog.ScopeLogs) bool {
return sl.LogRecords().Len() == 0
})
}
ld.ResourceLogs().RemoveIf(func(rl plog.ResourceLogs) bool {
return rl.ScopeLogs().Len() == 0
})
return ld, nil
}

Expand Down Expand Up @@ -180,6 +192,12 @@ func (sp *metricsSamplingProcessor) processMetrics(ctx context.Context, md pmetr
return err == nil && match && sampleFunc(sp.dropCutOffRatio)
})
}
md.ResourceMetrics().At(i).ScopeMetrics().RemoveIf(func(sm pmetric.ScopeMetrics) bool {
return sm.Metrics().Len() == 0
})
}
md.ResourceMetrics().RemoveIf(func(rm pmetric.ResourceMetrics) bool {
return rm.ScopeMetrics().Len() == 0
})
return md, nil
}
113 changes: 113 additions & 0 deletions processor/samplingprocessor/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ package samplingprocessor

import (
"context"
"fmt"
"testing"

"github.com/observiq/bindplane-agent/expr"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/plogtest"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/pmetrictest"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/ptracetest"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/pdata/plog"
Expand Down Expand Up @@ -259,3 +263,112 @@ func Test_processMetrics(t *testing.T) {
})
}
}

func Test_completeResourceDropping(t *testing.T) {
cfg := &Config{
DropRatio: 0.5,
Condition: "true",
}

t.Run("verify no empty logs", func(t *testing.T) {
ld := plog.NewLogs()
for i := 0; i < 2; i++ {
rl := ld.ResourceLogs().AppendEmpty()
for j := 0; j < 3; j++ {
sl := rl.ScopeLogs().AppendEmpty()

lr := sl.LogRecords().AppendEmpty()
lr.Body().SetEmptyMap()
lr.Body().Map().PutStr("id", fmt.Sprintf("rl-%d/sl-%d/lr", i, j))
}
}

ottlCondition, err := expr.NewOTTLLogRecordCondition(cfg.Condition, component.TelemetrySettings{Logger: zap.NewNop()})
require.NoError(t, err)
processor := newLogsSamplingProcessor(zap.NewNop(), cfg, ottlCondition)

actual, err := processor.processLogs(context.Background(), ld)
require.NoError(t, err)

// can't know for sure how many logs are removed, but at 50% we can safely assume not all logs are removed
err = plogtest.CompareLogs(plog.NewLogs(), actual)
require.Error(t, err)

for i := 0; i < actual.ResourceLogs().Len(); i++ {
rl := actual.ResourceLogs().At(i)
require.NotEqual(t, 0, rl.ScopeLogs().Len())
for j := 0; j < rl.ScopeLogs().Len(); j++ {
sl := rl.ScopeLogs().At(j)
require.NotEqual(t, 0, sl.LogRecords().Len())
}
}
})

t.Run("verify no empty traces", func(t *testing.T) {
td := ptrace.NewTraces()
for i := 0; i < 2; i++ {
rt := td.ResourceSpans().AppendEmpty()
for j := 0; j < 3; j++ {
st := rt.ScopeSpans().AppendEmpty()

sd := st.Spans().AppendEmpty()
m := sd.Attributes().PutEmptyMap("test")
m.PutStr("id", fmt.Sprintf("rt-%d/st-%d/s", i, j))
}
}

ottlCondition, err := expr.NewOTTLSpanCondition(cfg.Condition, component.TelemetrySettings{Logger: zap.NewNop()})
require.NoError(t, err)
processor := newTracesSamplingProcessor(zap.NewNop(), cfg, ottlCondition)

actual, err := processor.processTraces(context.Background(), td)
require.NoError(t, err)

// can't know for sure how many traces are removed, but at 50% we can safely assume not all traces are removed
err = ptracetest.CompareTraces(ptrace.NewTraces(), actual)
require.Error(t, err)

for i := 0; i < actual.ResourceSpans().Len(); i++ {
rt := actual.ResourceSpans().At(i)
require.NotEqual(t, 0, rt.ScopeSpans().Len())
for j := 0; j < rt.ScopeSpans().Len(); j++ {
st := rt.ScopeSpans().At(j)
require.NotEqual(t, 0, st.Spans().Len())
}
}
})

t.Run("verify no empty metrics", func(t *testing.T) {
md := pmetric.NewMetrics()
for i := 0; i < 2; i++ {
rm := md.ResourceMetrics().AppendEmpty()
for j := 0; j < 3; j++ {
sm := rm.ScopeMetrics().AppendEmpty()

m := sm.Metrics().AppendEmpty()
m.SetName(fmt.Sprintf("rm-%d/sm-%d/m", i, j))
}
}

ottlCondition, err := expr.NewOTTLMetricCondition(cfg.Condition, component.TelemetrySettings{Logger: zap.NewNop()})
require.NoError(t, err)
processor := newMetricsSamplingProcessor(zap.NewNop(), cfg, ottlCondition)

actual, err := processor.processMetrics(context.Background(), md)
require.NoError(t, err)

// can't know for sure how many traces are removed, but at 50% we can safely assume not all traces are removed
err = pmetrictest.CompareMetrics(pmetric.NewMetrics(), actual)
require.Error(t, err)

for i := 0; i < actual.ResourceMetrics().Len(); i++ {
rm := actual.ResourceMetrics().At(i)
require.NotEqual(t, 0, rm.ScopeMetrics().Len())
for j := 0; j < rm.ScopeMetrics().Len(); j++ {
sm := rm.ScopeMetrics().At(j)
require.NotEqual(t, 0, sm.Metrics().Len())
}
}

})
}

0 comments on commit a022fea

Please sign in to comment.