From 1ff724b9fc1915438ec3dfebfc50ed17afc7ad5c Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Wed, 15 Jan 2025 11:40:31 -0800 Subject: [PATCH] remove resource_metrics, fully move to upstream testing --- tests/README.md | 51 +------------ tests/general/container_test.go | 2 - .../k8s-observer-smart-agent-redis.yaml | 17 ----- tests/general/dry_run_test.go | 1 - tests/go.mod | 18 ++--- tests/go.sum | 24 ------- tests/receivers/scriptedinputs/script_test.go | 12 ---- .../testdata/resource_metrics/all_broker.yaml | 66 ----------------- .../resource_metrics/all_consumer.yaml | 29 -------- .../resource_metrics/all_producer.yaml | 39 ---------- .../jmx/testdata/resource_metrics/all.yaml | 11 --- tests/testutils/README.md | 72 ++++--------------- .../collector_process_integration_test.go | 5 +- tests/testutils/otlp_receiver_sink.go | 1 + tests/testutils/otlp_receiver_sink_test.go | 70 ------------------ tests/testutils/testcase.go | 23 ++---- 16 files changed, 28 insertions(+), 413 deletions(-) delete mode 100644 tests/general/discoverymode/testdata/resource_metrics/k8s-observer-smart-agent-redis.yaml delete mode 100644 tests/receivers/smartagent/collectd-kafka/testdata/resource_metrics/all_broker.yaml delete mode 100644 tests/receivers/smartagent/collectd-kafka/testdata/resource_metrics/all_consumer.yaml delete mode 100644 tests/receivers/smartagent/collectd-kafka/testdata/resource_metrics/all_producer.yaml delete mode 100644 tests/receivers/smartagent/jmx/testdata/resource_metrics/all.yaml diff --git a/tests/README.md b/tests/README.md index b7203a9cf2..9571b05878 100644 --- a/tests/README.md +++ b/tests/README.md @@ -5,8 +5,7 @@ provides a set of integration tests and associated utilities. The general testi is: 1. Building the Collector (`make otelcol` or `make all`) -1. Defining your expected [resource metric content](./testutils/README.md#resource-metrics) as a yaml file -([see example](testutils/telemetry/testdata/metrics/resource-metrics.yaml)) +1. Defining [your expected golden file content as a yaml file](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/golden) 1. Spin up your target resources as [docker containers](./testutils/README.md#test-containers). 1. Stand up an in-memory [OTLP metrics receiver and sink](./testutils/README.md#otlp-metrics-receiver-sink) capable of detecting if/when desired data are received. 1. Spin up your Collector [as a subprocess](./testutils/README.md#collector-process) or [as a container](./testutils/README.md#collector-container) configured to report to this OTLP receiver. @@ -17,51 +16,3 @@ is more useful overall. **NOTE** At this time, integration tests generally target collector containers (`SPLUNK_OTEL_COLLECTOR_IMAGE` env var), and test coverage for the subprocess is best effort only, unless the test cases explicitly maintain one. The collector process targets are generally for test development without requiring frequent rebuilds of a local docker image. - -```go -package example_test - -import ( - "context" - "path/filepath" - "testing" - "time" - - "github.com/stretchr/testify/require" - - "github.com/signalfx/splunk-otel-collector/tests/testutils" - "github.com/signalfx/splunk-otel-collector/tests/testutils/telemetry" -) - -func TestMyExampleComponent(t *testing.T) { - expectedResourceMetrics, err := telemetry.LoadResourceMetrics( - filepath.Join(".", "testdata", "metrics", "my_resource_metrics.yaml"), - ) - require.NoError(t, err) - require.NotNil(t, expectedResourceMetrics) - - // combination OTLP Receiver, consumertests.MetricsSink, and consumertests.LogsSink - otlp, err := testutils.NewOTLPReceiverSink().WithEndpoint("localhost:23456").Build() - require.NoError(t, err) - require.NoError(t, otlp.Start()) - - defer func() { - require.NoError(t, otlp.Shutdown()) - }() - - myContainer := testutils.NewContainer().WithImage("someTarget").Build() - err = myContainer.Start(context.Background()) - require.NoError(t, err) - - // running collector subprocess that uses the provided config set to export OTLP to our test receiver - myCollector, err := testutils.NewCollectorProcess().WithConfigPath(filepath.Join(".", "testdata", "config.yaml")).Build() - require.NoError(t, err) - err = myCollector.Start() - require.NoError(t, err) - defer func() { - require.NoError(t, myCollector.Shutdown() ) - }() - - require.NoError(t, otlp.AssertAllMetricsReceived(t, *expectedResourceMetrics, 30*time.Second)) -} -``` diff --git a/tests/general/container_test.go b/tests/general/container_test.go index b43836effb..18806e370a 100644 --- a/tests/general/container_test.go +++ b/tests/general/container_test.go @@ -111,7 +111,6 @@ func TestSpecifiedContainerConfigDefaultsToCmdLineArgIfEnvVarConflict(t *testing return false } receivedOTLPMetrics := tc.OTLPReceiverSink.AllMetrics() - tc.OTLPReceiverSink.Reset() for _, rom := range receivedOTLPMetrics { for i := 0; i < rom.ResourceMetrics().Len(); i++ { @@ -189,7 +188,6 @@ service: return false } receivedOTLPMetrics := tc.OTLPReceiverSink.AllMetrics() - tc.OTLPReceiverSink.Reset() for _, rom := range receivedOTLPMetrics { for i := 0; i < rom.ResourceMetrics().Len(); i++ { diff --git a/tests/general/discoverymode/testdata/resource_metrics/k8s-observer-smart-agent-redis.yaml b/tests/general/discoverymode/testdata/resource_metrics/k8s-observer-smart-agent-redis.yaml deleted file mode 100644 index de19286be7..0000000000 --- a/tests/general/discoverymode/testdata/resource_metrics/k8s-observer-smart-agent-redis.yaml +++ /dev/null @@ -1,17 +0,0 @@ -resource_metrics: - - attributes: - k8s.namespace.name: test-namespace - k8s.pod.name: target.redis - k8s.pod.uid: - one.key: one.value - two.key: two.value - scope_metrics: - - metrics: - - name: gauge.connected_clients - type: IntGauge - attributes: - dsname: value - plugin: redis_info - plugin_instance: - system.type: redis - three.key: three.value.from.cmdline.property diff --git a/tests/general/dry_run_test.go b/tests/general/dry_run_test.go index 3c448d7058..1142c03869 100644 --- a/tests/general/dry_run_test.go +++ b/tests/general/dry_run_test.go @@ -90,7 +90,6 @@ service: return false } receivedOTLPMetrics := tc.OTLPReceiverSink.AllMetrics() - tc.OTLPReceiverSink.Reset() for _, rom := range receivedOTLPMetrics { for i := 0; i < rom.ResourceMetrics().Len(); i++ { diff --git a/tests/go.mod b/tests/go.mod index 1fa852e4b9..ce1c32d655 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -9,7 +9,6 @@ require ( github.com/docker/go-connections v0.5.0 github.com/go-sql-driver/mysql v1.8.1 github.com/google/uuid v1.6.0 - github.com/knadh/koanf v1.5.0 github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden v0.117.0 github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest v0.117.0 github.com/shirou/gopsutil/v3 v3.24.5 @@ -17,13 +16,9 @@ require ( github.com/testcontainers/testcontainers-go v0.35.0 go.opentelemetry.io/collector/component v0.117.0 go.opentelemetry.io/collector/component/componenttest v0.117.0 - go.opentelemetry.io/collector/config/configgrpc v0.117.0 go.opentelemetry.io/collector/config/confignet v1.23.0 - go.opentelemetry.io/collector/config/configtls v1.23.0 go.opentelemetry.io/collector/confmap v1.23.0 go.opentelemetry.io/collector/consumer/consumertest v0.117.0 - go.opentelemetry.io/collector/exporter v0.117.0 - go.opentelemetry.io/collector/exporter/otlpexporter v0.117.0 go.opentelemetry.io/collector/pdata v1.23.0 go.opentelemetry.io/collector/receiver v0.117.0 go.opentelemetry.io/collector/receiver/otlpreceiver v0.117.0 @@ -35,7 +30,6 @@ require ( golang.org/x/exp v0.0.0-20230711023510-fffb14384f22 golang.org/x/sys v0.29.0 gopkg.in/yaml.v2 v2.4.0 - gopkg.in/yaml.v3 v3.0.1 ) require ( @@ -60,9 +54,9 @@ require ( github.com/go-viper/mapstructure/v2 v2.2.1 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/snappy v0.0.4 // indirect - github.com/hashicorp/go-version v1.7.0 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/compress v1.17.11 // indirect + github.com/knadh/koanf v1.5.0 // indirect github.com/knadh/koanf/v2 v2.1.2 // indirect github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect github.com/magiconair/properties v1.8.7 // indirect @@ -96,24 +90,19 @@ require ( go.opentelemetry.io/collector/component/componentstatus v0.117.0 // indirect go.opentelemetry.io/collector/config/configauth v0.117.0 // indirect go.opentelemetry.io/collector/config/configcompression v1.23.0 // indirect + go.opentelemetry.io/collector/config/configgrpc v0.117.0 // indirect go.opentelemetry.io/collector/config/confighttp v0.117.0 // indirect go.opentelemetry.io/collector/config/configopaque v1.23.0 // indirect - go.opentelemetry.io/collector/config/configretry v1.23.0 // indirect go.opentelemetry.io/collector/config/configtelemetry v0.117.0 // indirect + go.opentelemetry.io/collector/config/configtls v1.23.0 // indirect go.opentelemetry.io/collector/consumer v1.23.0 // indirect go.opentelemetry.io/collector/consumer/consumererror v0.117.0 // indirect - go.opentelemetry.io/collector/consumer/consumererror/xconsumererror v0.117.0 // indirect go.opentelemetry.io/collector/consumer/xconsumer v0.117.0 // indirect - go.opentelemetry.io/collector/exporter/exporterhelper/xexporterhelper v0.117.0 // indirect - go.opentelemetry.io/collector/exporter/xexporter v0.117.0 // indirect go.opentelemetry.io/collector/extension v0.117.0 // indirect go.opentelemetry.io/collector/extension/auth v0.117.0 // indirect - go.opentelemetry.io/collector/extension/xextension v0.117.0 // indirect - go.opentelemetry.io/collector/featuregate v1.23.0 // indirect go.opentelemetry.io/collector/internal/sharedcomponent v0.117.0 // indirect go.opentelemetry.io/collector/pdata/pprofile v0.117.0 // indirect go.opentelemetry.io/collector/pipeline v0.117.0 // indirect - go.opentelemetry.io/collector/pipeline/xpipeline v0.117.0 // indirect go.opentelemetry.io/collector/receiver/xreceiver v0.117.0 // indirect go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.56.0 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 // indirect @@ -130,4 +119,5 @@ require ( google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28 // indirect google.golang.org/grpc v1.69.2 // indirect google.golang.org/protobuf v1.36.2 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/tests/go.sum b/tests/go.sum index 6e44ccc7f2..efea1f9394 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -168,8 +168,6 @@ github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdv github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= -github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY= -github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= @@ -379,8 +377,6 @@ go.opentelemetry.io/collector/config/confignet v1.23.0 h1:gq90GDgQFSjAeFkDeIkstk go.opentelemetry.io/collector/config/confignet v1.23.0/go.mod h1:ZppUH1hgUJOubawEsxsQ9MzEYFytqo2GnVSS7d4CVxc= go.opentelemetry.io/collector/config/configopaque v1.23.0 h1:SEnEzOHufGc4KGOjQq8zKIQuDBmRFl9ncZ3qs1SRpJk= go.opentelemetry.io/collector/config/configopaque v1.23.0/go.mod h1:sW0t0iI/VfRL9VYX7Ik6XzVgPcR+Y5kejTLsYcMyDWs= -go.opentelemetry.io/collector/config/configretry v1.23.0 h1:0Ox2KvTZyNdgureAs3kJzsNIa6ttrx9bwlKjj/p4fGU= -go.opentelemetry.io/collector/config/configretry v1.23.0/go.mod h1:cleBc9I0DIWpTiiHfu9v83FUaCTqcPXmebpLxjEIqro= go.opentelemetry.io/collector/config/configtelemetry v0.117.0 h1:xsMfc89VByIF2fJzWuxs/2eqy44DWfNBAysReG4TAr8= go.opentelemetry.io/collector/config/configtelemetry v0.117.0/go.mod h1:SlBEwQg0qly75rXZ6W1Ig8jN25KBVBkFIIAUI1GiAAE= go.opentelemetry.io/collector/config/configtls v1.23.0 h1:52q9dAV923hHn1aoYQyKGnrRXCPvTTT3DXurtxcpZaQ= @@ -391,34 +387,16 @@ go.opentelemetry.io/collector/consumer v1.23.0 h1:JT0nE1vikL5yIk97IHBGzwx8co3w1W go.opentelemetry.io/collector/consumer v1.23.0/go.mod h1:8d0uQ6gq64LbPktV4sc888lRj1cQCmrdl13hRIEURgA= go.opentelemetry.io/collector/consumer/consumererror v0.117.0 h1:PPIZCcYZcENnyIrpRV4ERvMUoPSTV0zIP0QPzJvz80g= go.opentelemetry.io/collector/consumer/consumererror v0.117.0/go.mod h1:L47xOVC+Vzos8350j3SWtU43w7rzms6UDhb6IrFxymY= -go.opentelemetry.io/collector/consumer/consumererror/xconsumererror v0.117.0 h1:gT9VUzerc4rSRUDMEBQdrgBxbrpjinoa4Oxo5qlj6gw= -go.opentelemetry.io/collector/consumer/consumererror/xconsumererror v0.117.0/go.mod h1:AzJIPm65RpEeoQk8OuQ4HLT6QQPDNrWWKk8IEaNBiIQ= go.opentelemetry.io/collector/consumer/consumertest v0.117.0 h1:9WFyyjLudvfJDEuUaGsQyNRd1m6D1iRg8Iyg3xliFko= go.opentelemetry.io/collector/consumer/consumertest v0.117.0/go.mod h1:B7A+OS76QKAzM8W7cmvlfVynFELj9Sa444hSm1SILFw= go.opentelemetry.io/collector/consumer/xconsumer v0.117.0 h1:vsBNJGaEbYqgMU3PEsOcqjMxX5ul++Cxda44sttoi8c= go.opentelemetry.io/collector/consumer/xconsumer v0.117.0/go.mod h1:dTr+Tms53lRLvR3OAzYic0yhcwldhTUdVIwJNSDmBmw= -go.opentelemetry.io/collector/exporter v0.117.0 h1:A9kVXzdb8i1eFELImuaSPyijAfg4qMIpM/4y/98mlxk= -go.opentelemetry.io/collector/exporter v0.117.0/go.mod h1:Cbrorch2s18w1X7+A+zXQtAffbInnIOP7Su26gbRG+k= -go.opentelemetry.io/collector/exporter/exporterhelper/xexporterhelper v0.117.0 h1:1e991aHPgSvWFMOFFir40HANg2SkXcrkG4AlRvK2+KI= -go.opentelemetry.io/collector/exporter/exporterhelper/xexporterhelper v0.117.0/go.mod h1:TkPEGX28zDvGAqlJRZQhKohG+82iN2lWPjF+dTuzS9Q= -go.opentelemetry.io/collector/exporter/exportertest v0.117.0 h1:u+loeqxpniMiJL1iqc/lCCcfniWrqHBgJTAjXfqVBqQ= -go.opentelemetry.io/collector/exporter/exportertest v0.117.0/go.mod h1:GyHwJLsOPPau0m+TYrIA7jWD9/GU+ID+l/9sL0cAqhE= -go.opentelemetry.io/collector/exporter/otlpexporter v0.117.0 h1:A/qDjii7WN2Wdx+gtdLvSVpPu8to6ogVutxIggNBEio= -go.opentelemetry.io/collector/exporter/otlpexporter v0.117.0/go.mod h1:rW4Re7GGCPB4JwZoZjXaPqJ77GEIr8OjTz5YK59avJM= -go.opentelemetry.io/collector/exporter/xexporter v0.117.0 h1:BB8D0Dvb46CVAZrnPEg5nYgXO7LzONmXeGKEfzSIOZs= -go.opentelemetry.io/collector/exporter/xexporter v0.117.0/go.mod h1:yo0T8WkvLCJ7NOqIquHGFe4Xpuc4CbDb8a06T2G5De4= go.opentelemetry.io/collector/extension v0.117.0 h1:B3cG7g+wbhmpMFugaDxOcyiPKeulaW8+EQdJbZxDfho= go.opentelemetry.io/collector/extension v0.117.0/go.mod h1:WjyD5h9N5Y0SF8azB2rulvHJieJoWqroGO5hi3ax5+8= go.opentelemetry.io/collector/extension/auth v0.117.0 h1:tXQdYIdcABXalWyFZP22pREY7+nWUNurx8Y6FseWs7w= go.opentelemetry.io/collector/extension/auth v0.117.0/go.mod h1:ofrV2BuE46+k7Su/h0ccrMl5Zk5Y7NVlzOb3AwU7Dzw= go.opentelemetry.io/collector/extension/auth/authtest v0.117.0 h1:wV4OIiWrt7gteQrxL8MCmGvjGhMiu5TplKJHOfVZO6Y= go.opentelemetry.io/collector/extension/auth/authtest v0.117.0/go.mod h1:nHxcAOyo26JnuYwKIoQM9mDlSXpERQrbjIw3Dtp9hug= -go.opentelemetry.io/collector/extension/extensiontest v0.117.0 h1:XH+tkHdATylYZtASZKK3rCoN/xlaFi8MXLh07ZlQQWw= -go.opentelemetry.io/collector/extension/extensiontest v0.117.0/go.mod h1:ABqB9D41p4MCeGVmABOgJi7i7roWZlFbqeFJDy7lskQ= -go.opentelemetry.io/collector/extension/xextension v0.117.0 h1:ADUKWHGaVvvmebJHiNRuX6YAfQXFDW/UaXK9W1hCo1k= -go.opentelemetry.io/collector/extension/xextension v0.117.0/go.mod h1:BmR8xN7Ja+El4IJ9aVmtON2miudjsbq2COZ9azVXsNg= -go.opentelemetry.io/collector/featuregate v1.23.0 h1:N033ROo85qKrsK16QzR6RV+3UWOWF7kpOO8FSnX99s0= -go.opentelemetry.io/collector/featuregate v1.23.0/go.mod h1:3GaXqflNDVwWndNGBJ1+XJFy3Fv/XrFgjMN60N3z7yg= go.opentelemetry.io/collector/internal/sharedcomponent v0.117.0 h1:mk+qZO2HpNny3FuYeb4mjL4mbrEfkJN5untocHA8AqM= go.opentelemetry.io/collector/internal/sharedcomponent v0.117.0/go.mod h1:Hlzn5+54tgYchP3OJz/YMnrbMNHX8PggDpZFlDTB2kQ= go.opentelemetry.io/collector/pdata v1.23.0 h1:tEk0dkfB8RdSukoOMfEa8duB938gfZowdfRkrJxGDrw= @@ -429,8 +407,6 @@ go.opentelemetry.io/collector/pdata/testdata v0.117.0 h1:ainpacShKHaDkPK6lcvgJ0a go.opentelemetry.io/collector/pdata/testdata v0.117.0/go.mod h1:LZAymmRKHQEqJqJUSO15rej3+V1rNRyBMF5mWCKCMBY= go.opentelemetry.io/collector/pipeline v0.117.0 h1:CSv0Dd3n9AQNQ73e7PdEkgexkSMRZliKATxkoZKUFcY= go.opentelemetry.io/collector/pipeline v0.117.0/go.mod h1:qE3DmoB05AW0C3lmPvdxZqd/H4po84NPzd5MrqgtL74= -go.opentelemetry.io/collector/pipeline/xpipeline v0.117.0 h1:jnHQNaNfVRIdrtOPCORUy8s1cEJyxql3uv/WQ1ve1Js= -go.opentelemetry.io/collector/pipeline/xpipeline v0.117.0/go.mod h1:lNY3uQjRcb3f7CW1JQMXJcWzCJp5122LOKrKs5eito8= go.opentelemetry.io/collector/receiver v0.117.0 h1:jm+b2G2IKKwGE213lB9cviKEdeATvYtNSY1kO0XdpMM= go.opentelemetry.io/collector/receiver v0.117.0/go.mod h1:fZXigB3afp54OE+ogPcup/RPwI7j+CwZh9Mz6ObB/Cg= go.opentelemetry.io/collector/receiver/otlpreceiver v0.117.0 h1:Ezv4K3TGcQ5sd6lj0QsemjUeO+5RTnSsfodfPyjHo2o= diff --git a/tests/receivers/scriptedinputs/script_test.go b/tests/receivers/scriptedinputs/script_test.go index 20a2a901c4..0dbd11a1e2 100644 --- a/tests/receivers/scriptedinputs/script_test.go +++ b/tests/receivers/scriptedinputs/script_test.go @@ -41,7 +41,6 @@ func TestScriptReceiverCpu(t *testing.T) { return } receivedOTLPLogs := tc.OTLPReceiverSink.AllLogs() - tc.OTLPReceiverSink.Reset() lr := receivedOTLPLogs[0].ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0) assert.Regexp(tt, regexp.MustCompile("CPU\\s+pctUser\\s+pctNice\\s+pctSystem\\s+pctIowait\\s+pctIdle\\nall(\\s*\\d{1,3}.\\d{1,3}){5}\\n0(\\s*\\d{1,3}.\\d{1,3}){5}"), lr.Body().Str()) @@ -62,7 +61,6 @@ func TestScriptReceiverDf(t *testing.T) { return } receivedOTLPLogs := tc.OTLPReceiverSink.AllLogs() - tc.OTLPReceiverSink.Reset() lr := receivedOTLPLogs[0].ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0) fmt.Printf("Received log entry - \n%s", lr.Body().Str()) @@ -84,7 +82,6 @@ func TestScriptReceiverHardware(t *testing.T) { return } receivedOTLPLogs := tc.OTLPReceiverSink.AllLogs() - tc.OTLPReceiverSink.Reset() lr := receivedOTLPLogs[0].ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0) assert.Regexp(tt, regexp.MustCompile("KEY\\s+VALUE"), lr.Body().Str()) @@ -105,7 +102,6 @@ func TestScriptReceiverInterfaces(t *testing.T) { return } receivedOTLPLogs := tc.OTLPReceiverSink.AllLogs() - tc.OTLPReceiverSink.Reset() lr := receivedOTLPLogs[0].ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0) assert.Regexp(tt, regexp.MustCompile("Name\\s+MAC\\s+inetAddr\\s+inet6Addr\\s+Collisions\\s+RXbytes\\s+RXerrors\\s+RXdropped\\s+TXbytes\\s+TXerrors\\s+TXdropped\\s+Speed\\s+Duplex"), lr.Body().Str()) @@ -126,7 +122,6 @@ func TestScriptReceiverIostat(t *testing.T) { return } receivedOTLPLogs := tc.OTLPReceiverSink.AllLogs() - tc.OTLPReceiverSink.Reset() lr := receivedOTLPLogs[0].ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0) assert.Regexp(tt, regexp.MustCompile("Device\\s+r/s\\s+rkB/s\\s+rrqm/s\\s+%rrqm\\s+r_await\\s+rareq-sz\\s+w/s\\s+wkB/s\\s+wrqm/s\\s+%wrqm\\s+w_await\\s+wareq-sz\\s+d/s\\s+dkB/s\\s+drqm/s\\s+%drqm\\s+d_await\\s+dareq-sz\\s+(f/s\\s+)?(f_await\\s+)?aqu-sz\\s+%util"), lr.Body().Str()) @@ -147,7 +142,6 @@ func TestScriptReceiverLsof(t *testing.T) { return } receivedOTLPLogs := tc.OTLPReceiverSink.AllLogs() - tc.OTLPReceiverSink.Reset() lr := receivedOTLPLogs[0].ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0) assert.Regexp(tt, regexp.MustCompile("COMMAND\\s+PID\\s+USER\\s+FD\\s+TYPE\\s+DEVICE\\s+SIZE\\s+NODE\\s+NAME"), lr.Body().Str()) @@ -168,7 +162,6 @@ func TestScriptReceiverNetstat(t *testing.T) { return } receivedOTLPLogs := tc.OTLPReceiverSink.AllLogs() - tc.OTLPReceiverSink.Reset() lr := receivedOTLPLogs[0].ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0) assert.Regexp(tt, regexp.MustCompile("Proto\\s+Recv-Q\\s+Send-Q\\s+LocalAddress\\s+ForeignAddress\\s+State"), lr.Body().Str()) @@ -189,7 +182,6 @@ func TestScriptReceiverOpenPorts(t *testing.T) { return } receivedOTLPLogs := tc.OTLPReceiverSink.AllLogs() - tc.OTLPReceiverSink.Reset() lr := receivedOTLPLogs[0].ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0) assert.Regexp(tt, regexp.MustCompile("Proto\\s+Port"), lr.Body().Str()) @@ -210,7 +202,6 @@ func TestScriptReceiverPackage(t *testing.T) { return } receivedOTLPLogs := tc.OTLPReceiverSink.AllLogs() - tc.OTLPReceiverSink.Reset() lr := receivedOTLPLogs[0].ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0) assert.Regexp(tt, regexp.MustCompile("NAME\\s+VERSION\\s+RELEASE\\s+ARCH\\s+VENDOR\\s+GROUP"), lr.Body().Str()) @@ -231,7 +222,6 @@ func TestScriptReceiverProtocol(t *testing.T) { return } receivedOTLPLogs := tc.OTLPReceiverSink.AllLogs() - tc.OTLPReceiverSink.Reset() lr := receivedOTLPLogs[0].ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0) assert.Regexp(tt, regexp.MustCompile("IPdropped\\s+TCPrexmits\\s+TCPreorder\\s+TCPpktRecv\\s+TCPpktSent\\s+UDPpktLost\\s+UDPunkPort\\s+UDPpktRecv\\s+UDPpktSent"), lr.Body().Str()) @@ -252,7 +242,6 @@ func TestScriptReceiverPs(t *testing.T) { return } receivedOTLPLogs := tc.OTLPReceiverSink.AllLogs() - tc.OTLPReceiverSink.Reset() lr := receivedOTLPLogs[0].ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0) assert.Regexp(tt, regexp.MustCompile("USER\\s+PID\\s+%CPU\\s+%MEM\\s+VSZ\\s+RSS\\s+TTY\\s+STAT\\s+START\\s+TIME\\s+COMMAND\\s+ARGS"), lr.Body().Str()) @@ -273,7 +262,6 @@ func TestScriptReceiverTop(t *testing.T) { return } receivedOTLPLogs := tc.OTLPReceiverSink.AllLogs() - tc.OTLPReceiverSink.Reset() lr := receivedOTLPLogs[0].ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0) assert.Regexp(tt, regexp.MustCompile("PID\\s+USER\\s+PR\\s+NI\\s+VIRT\\s+RES\\s+SHR\\s+S\\s+pctCPU\\s+pctMEM\\s+cpuTIME\\s+COMMAND"), lr.Body().Str()) diff --git a/tests/receivers/smartagent/collectd-kafka/testdata/resource_metrics/all_broker.yaml b/tests/receivers/smartagent/collectd-kafka/testdata/resource_metrics/all_broker.yaml deleted file mode 100644 index 761cb3a72f..0000000000 --- a/tests/receivers/smartagent/collectd-kafka/testdata/resource_metrics/all_broker.yaml +++ /dev/null @@ -1,66 +0,0 @@ -resource_metrics: - - scope_metrics: - - metrics: - - name: counter.kafka-bytes-in - type: IntMonotonicCumulativeSum - - name: counter.kafka-bytes-out - type: IntMonotonicCumulativeSum - - name: counter.kafka-isr-expands - type: IntMonotonicCumulativeSum - - name: counter.kafka-isr-shrinks - type: IntMonotonicCumulativeSum - - name: counter.kafka-leader-election-rate - type: IntMonotonicCumulativeSum - - name: counter.kafka-messages-in - type: IntMonotonicCumulativeSum - - name: counter.kafka-unclean-elections-rate - type: IntMonotonicCumulativeSum - - name: counter.kafka.fetch-consumer.total-time.count - type: IntMonotonicCumulativeSum - - name: counter.kafka.fetch-follower.total-time.count - type: IntMonotonicCumulativeSum - - name: counter.kafka.produce.total-time.count - type: IntMonotonicCumulativeSum - - name: gauge.jvm.threads.count - type: IntGauge - - name: gauge.kafka-active-controllers - type: IntGauge - - name: gauge.kafka-max-lag - type: IntGauge - - name: gauge.kafka-offline-partitions-count - type: IntGauge - - name: gauge.kafka-request-queue - type: IntGauge - - name: gauge.kafka-underreplicated-partitions - type: IntGauge - - name: gauge.kafka.fetch-consumer.total-time.99th - type: IntGauge - - name: gauge.kafka.fetch-consumer.total-time.median - type: IntGauge - - name: gauge.kafka.fetch-follower.total-time.99th - type: IntGauge - - name: gauge.kafka.fetch-follower.total-time.median - type: IntGauge - - name: gauge.kafka.produce.total-time.99th - type: IntGauge - - name: counter.kafka.logs.flush-time.count - type: IntMonotonicCumulativeSum - - name: gauge.kafka.logs.flush-time.median - type: DoubleGauge - - name: gauge.kafka.logs.flush-time.99th - type: DoubleGauge - - name: gauge.kafka.produce.total-time.median - - name: gauge.loaded_classes - type: IntGauge - - name: invocations - type: IntMonotonicCumulativeSum - - name: jmx_memory.committed - type: IntGauge - - name: jmx_memory.init - type: IntGauge - - name: jmx_memory.max - type: IntGauge - - name: jmx_memory.used - type: IntGauge - - name: total_time_in_ms.collection_time - type: IntMonotonicCumulativeSum diff --git a/tests/receivers/smartagent/collectd-kafka/testdata/resource_metrics/all_consumer.yaml b/tests/receivers/smartagent/collectd-kafka/testdata/resource_metrics/all_consumer.yaml deleted file mode 100644 index a053c40b7f..0000000000 --- a/tests/receivers/smartagent/collectd-kafka/testdata/resource_metrics/all_consumer.yaml +++ /dev/null @@ -1,29 +0,0 @@ -resource_metrics: - - scope_metrics: - - metrics: - - name: gauge.jvm.threads.count - type: IntGauge - - name: gauge.kafka.consumer.bytes-consumed-rate - type: DoubleGauge - - name: gauge.kafka.consumer.fetch-rate - type: DoubleGauge - - name: gauge.kafka.consumer.fetch-size-avg - type: DoubleGauge - - name: gauge.kafka.consumer.records-consumed-rate - type: DoubleGauge - - name: gauge.kafka.consumer.records-lag-max - type: IntGauge - - name: gauge.loaded_classes - type: IntGauge - - name: invocations - type: IntMonotonicCumulativeSum - - name: jmx_memory.committed - type: IntGauge - - name: jmx_memory.init - type: IntGauge - - name: jmx_memory.max - type: IntGauge - - name: jmx_memory.used - type: IntGauge - - name: total_time_in_ms.collection_time - type: IntMonotonicCumulativeSum diff --git a/tests/receivers/smartagent/collectd-kafka/testdata/resource_metrics/all_producer.yaml b/tests/receivers/smartagent/collectd-kafka/testdata/resource_metrics/all_producer.yaml deleted file mode 100644 index 58ea294da0..0000000000 --- a/tests/receivers/smartagent/collectd-kafka/testdata/resource_metrics/all_producer.yaml +++ /dev/null @@ -1,39 +0,0 @@ -resource_metrics: - - scope_metrics: - - metrics: - - name: gauge.jvm.threads.count - type: IntGauge - - name: gauge.kafka.producer.byte-rate - type: DoubleGauge - - name: gauge.kafka.producer.compression-rate - type: IntGauge - - name: gauge.kafka.producer.io-wait-time-ns-avg - type: DoubleGauge - - name: gauge.kafka.producer.outgoing-byte-rate - type: DoubleGauge - - name: gauge.kafka.producer.record-error-rate - type: IntGauge - - name: gauge.kafka.producer.record-retry-rate - type: IntGauge - - name: gauge.kafka.producer.record-send-rate - type: DoubleGauge - - name: gauge.kafka.producer.request-latency-avg - type: DoubleGauge - - name: gauge.kafka.producer.request-rate - type: DoubleGauge - - name: gauge.kafka.producer.response-rate - type: DoubleGauge - - name: gauge.loaded_classes - type: IntGauge - - name: invocations - type: IntMonotonicCumulativeSum - - name: jmx_memory.committed - type: IntGauge - - name: jmx_memory.init - type: IntGauge - - name: jmx_memory.max - type: IntGauge - - name: jmx_memory.used - type: IntGauge - - name: total_time_in_ms.collection_time - type: IntMonotonicCumulativeSum diff --git a/tests/receivers/smartagent/jmx/testdata/resource_metrics/all.yaml b/tests/receivers/smartagent/jmx/testdata/resource_metrics/all.yaml deleted file mode 100644 index e34f0f458d..0000000000 --- a/tests/receivers/smartagent/jmx/testdata/resource_metrics/all.yaml +++ /dev/null @@ -1,11 +0,0 @@ -resource_metrics: - - scope_metrics: - - metrics: - - name: cassandra.status - type: DoubleGauge - - name: cassandra.state - type: DoubleGauge - - name: cassandra.load - type: DoubleGauge - - name: cassandra.ownership - type: DoubleGauge diff --git a/tests/testutils/README.md b/tests/testutils/README.md index 9f616b7cd6..8067d36a19 100644 --- a/tests/testutils/README.md +++ b/tests/testutils/README.md @@ -3,62 +3,6 @@ The `testutils` package provides an internal test format for Collector data, and helpers to help assert its integrity from arbitrary components. -### Resource Metrics - -`ResourceMetrics` are at the core of the internal metric data format for these tests and are intended to be defined -in yaml files or by converting from obtained `pdata.Metrics` items. They provide a strict `Equals()` helper method as -well as `RelaxedEquals()` to help in verifying desired field and values, ignoring those not specified. - -```yaml -resource_metrics: - - attributes: - a_resource_attribute: a_value - another_resource_attribute: another_value - scope_metrics: - - instrumentation_scope: - name: a library - version: some version - - metrics: - - name: my.int.gauge - type: IntGauge - description: my.int.gauge description - unit: ms - attributes: - my_attribute: my_attribute_value - my_other_attribute: my_other_attribute_value - value: 123 - - name: my.double.sum - type: DoubleNonmonotonicDeltaSum - attributes: {} # enforced empty attribute map in RelaxedEquals() (only point with no attributes matches) - value: -123.456 - - scope_metrics: - - instrumentation_scope: - name: an instrumentation library from a different resource without attributes - metrics: - - name: my.double.gauge - type: DoubleGauge - # missing attributes field, so values are not compared in RelaxedEquals() (any attribute values are accepted) - value: 456.789 - - name: my.double.gauge - type: DoubleGauge - attributes: - another: attribute - value: 567.890 - - instrumentation_scope: - name: another instrumentation library - version: this_library_version - metrics: - - name: another_int_gauge - type: IntGauge - value: 456 -``` - -Using `telemetry.LoadResourceMetrics("my_yaml.path")` you can create an equivalent `ResourceMetrics` instance to what your yaml file specifies. -Using `telemetry.PDataToResourceMetrics(myReceivedPDataMetrics)` you can use the assertion helpers to determine if your expected -`ResourceMetrics` are the same as those received in your test case. `telemetry.FlattenResourceMetrics()` is a good way to "normalize" -metrics received over time to ensure that only unique datapoints are represented, and that all unique Resources and -Instrumentation Libraries have a single item. - ### Test Containers The Testcontainers project is a popular testing resource for easy container creation and usage for a number of languages @@ -178,9 +122,19 @@ func MyTest(t *testing.T) { } // will implicitly create a Testcase with OTLPReceiverSink listening at $OTLP_ENDPOINT, - // ./testdata/resource_metrics/my_resource_metrics.yaml ResourceMetrics instance, CollectorProcess with + // ./testdata/expected.yaml golden file, CollectorProcess with // ./testdata/my_collector_config.yaml config, and build and start all specified containers before calling - // OTLPReceiverSink.AssertAllMetricsReceived() with a 30s wait duration. - testutils.AssertAllMetricsReceived(t, "my_resource_metrics.yaml", "my_collector_config.yaml", containers, nil) + testutils.RunMetricsCollectionTest(t, "my_collector_config.yaml", "expected.yaml", + testutils.WithCompareMetricsOptions( + pmetrictest.IgnoreScopeVersion(), + pmetrictest.IgnoreMetricDataPointsOrder(), + pmetrictest.IgnoreResourceMetricsOrder(), + pmetrictest.IgnoreScopeMetricsOrder(), + pmetrictest.IgnoreMetricsOrder(), + pmetrictest.IgnoreMetricValues(), + pmetrictest.IgnoreTimestamp(), + pmetrictest.IgnoreStartTimestamp(), + ), + ) } ``` diff --git a/tests/testutils/collector_process_integration_test.go b/tests/testutils/collector_process_integration_test.go index 767d0033b6..6122e50e33 100644 --- a/tests/testutils/collector_process_integration_test.go +++ b/tests/testutils/collector_process_integration_test.go @@ -16,10 +16,11 @@ package testutils import ( - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "strings" "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestCollectorPath(t *testing.T) { diff --git a/tests/testutils/otlp_receiver_sink.go b/tests/testutils/otlp_receiver_sink.go index 0d46c8f214..cbc76196d5 100644 --- a/tests/testutils/otlp_receiver_sink.go +++ b/tests/testutils/otlp_receiver_sink.go @@ -17,6 +17,7 @@ package testutils import ( "context" "fmt" + "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/config/confignet" diff --git a/tests/testutils/otlp_receiver_sink_test.go b/tests/testutils/otlp_receiver_sink_test.go index 9168e42cb4..f737301666 100644 --- a/tests/testutils/otlp_receiver_sink_test.go +++ b/tests/testutils/otlp_receiver_sink_test.go @@ -17,23 +17,10 @@ package testutils import ( - "context" "testing" - "time" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/component/componenttest" - "go.opentelemetry.io/collector/config/configgrpc" - "go.opentelemetry.io/collector/config/configtls" - otelcolexporter "go.opentelemetry.io/collector/exporter" - "go.opentelemetry.io/collector/exporter/otlpexporter" - noopmetric "go.opentelemetry.io/otel/metric/noop" - nooptrace "go.opentelemetry.io/otel/trace/noop" - "go.uber.org/zap" - - "github.com/signalfx/splunk-otel-collector/tests/testutils/telemetry" ) func TestNewOTLPReceiverSink(t *testing.T) { @@ -77,60 +64,3 @@ func TestBuildDefaults(t *testing.T) { assert.NotNil(t, otlp.tracesReceiver) assert.NotNil(t, otlp.tracesSink) } - -func createOTLPFactoryParameters() (otlpexporter.Config, otelcolexporter.Settings) { - exporterCfg := otlpexporter.Config{ - ClientConfig: configgrpc.ClientConfig{ - Endpoint: "localhost:4317", - TLSSetting: configtls.ClientConfig{ - Insecure: true, - }, - }, - } - createParams := otelcolexporter.Settings{ - TelemetrySettings: component.TelemetrySettings{ - Logger: zap.NewNop(), - TracerProvider: nooptrace.NewTracerProvider(), - MeterProvider: noopmetric.NewMeterProvider(), - }, - } - - return exporterCfg, createParams -} - -func otlpMetricsExporter(t *testing.T) otelcolexporter.Metrics { - exporterCfg, createParams := createOTLPFactoryParameters() - otlpExporterFactory := otlpexporter.NewFactory() - ctx := context.Background() - - exporter, err := otlpExporterFactory.CreateMetrics(ctx, createParams, &exporterCfg) - - require.NoError(t, err) - require.NotNil(t, exporter) - err = exporter.Start(ctx, componenttest.NewNopHost()) - require.NoError(t, err) - return exporter -} - -func TestOTLPReceiverMetricsAvailableToSink(t *testing.T) { - otlp, err := NewOTLPReceiverSink().WithEndpoint("localhost:4317").Build() - require.NoError(t, err) - - err = otlp.Start() - defer func() { - require.NoError(t, otlp.Shutdown()) - }() - require.NoError(t, err) - - exporter := otlpMetricsExporter(t) - defer func() { require.NoError(t, exporter.Shutdown(context.Background())) }() - - metrics := telemetry.PDataMetrics() - expectedCount := metrics.DataPointCount() - err = exporter.ConsumeMetrics(context.Background(), metrics) - require.NoError(t, err) - - assert.Eventually(t, func() bool { - return otlp.DataPointCount() == expectedCount - }, 5*time.Second, 1*time.Millisecond) -} diff --git a/tests/testutils/testcase.go b/tests/testutils/testcase.go index 91e0a740c3..d51fcf7a5d 100644 --- a/tests/testutils/testcase.go +++ b/tests/testutils/testcase.go @@ -17,19 +17,18 @@ package testutils import ( "context" "fmt" - "github.com/google/uuid" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "go.uber.org/zap" - "go.uber.org/zap/zapcore" - "go.uber.org/zap/zaptest/observer" "os" "path" "runtime" "strings" "testing" - "github.com/signalfx/splunk-otel-collector/tests/testutils/telemetry" + "github.com/google/uuid" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "go.uber.org/zap" + "go.uber.org/zap/zapcore" + "go.uber.org/zap/zaptest/observer" ) type CollectorBuilder func(Collector) Collector @@ -75,16 +74,6 @@ func (t *Testcase) setOTLPEndpoint() { t.OTLPEndpointForCollector = t.OTLPEndpoint } -// Loads and validates a ResourceMetrics instance, assuming it's located in ./testdata/resource_metrics -func (t *Testcase) ResourceMetrics(filename string) *telemetry.ResourceMetrics { - expectedResourceMetrics, err := telemetry.LoadResourceMetrics( - path.Join(".", "testdata", "resource_metrics", filename), - ) - require.NoError(t, err) - require.NotNil(t, expectedResourceMetrics) - return expectedResourceMetrics -} - // Builds and starts all provided Container builder instances, returning them and a validating stop function. func (t *Testcase) Containers(builders ...Container) (containers []*Container, stop func()) { for _, builder := range builders {