Skip to content

Commit

Permalink
Swith telegraf/exec test to golden (#5795)
Browse files Browse the repository at this point in the history
  • Loading branch information
atoulme authored Jan 13, 2025
1 parent 766da2b commit 0412d0b
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 14 deletions.
63 changes: 58 additions & 5 deletions tests/receivers/smartagent/telegraf-exec/telegraf_exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@ package tests

import (
"path"
"path/filepath"
"testing"
"time"

"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/pmetrictest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/pdata/pmetric"

"github.com/signalfx/splunk-otel-collector/tests/testutils"
)
Expand All @@ -29,9 +37,13 @@ func TestTelegrafExecWithGoScript(t *testing.T) {
if testutils.CollectorImageIsForArm(t) {
platform = "arm64"
}
testutils.AssertAllMetricsReceived(
t, "all.yaml", "", nil,
[]testutils.CollectorBuilder{func(collector testutils.Collector) testutils.Collector {

tc := testutils.NewTestcase(t)
defer tc.PrintLogsOnFailure()
defer tc.ShutdownOTLPReceiverSink()

_, shutdown := tc.SplunkOtelCollectorContainer("",
func(collector testutils.Collector) testutils.Collector {
cc := collector.(*testutils.CollectorContainer)
cc.Container = cc.Container.WithContext(
path.Join(".", "testdata", "exec"),
Expand All @@ -40,6 +52,47 @@ func TestTelegrafExecWithGoScript(t *testing.T) {
"SPLUNK_OTEL_COLLECTOR_IMAGE": &collectorImage,
})
return cc.WithArgs("--config", "/etc/config.yaml")
}},
)
})
defer shutdown()

expected, err := golden.ReadMetrics(filepath.Join("testdata", "all_expected.yaml"))
require.NoError(t, err)
assert.EventuallyWithT(t, func(tt *assert.CollectT) {
if len(tc.OTLPReceiverSink.AllMetrics()) == 0 {
assert.Fail(tt, "No metrics collected")
return
}
var selected *pmetric.Metrics
for i := len(tc.OTLPReceiverSink.AllMetrics()) - 1; i >= 0; i-- {
m := tc.OTLPReceiverSink.AllMetrics()[i]
if m.MetricCount() == expected.MetricCount() {
selected = &m
break
}
}

require.NotNil(tt, selected)

err := pmetrictest.CompareMetrics(expected, *selected,
pmetrictest.IgnoreResourceAttributeValue("service.instance.id"),
pmetrictest.IgnoreResourceAttributeValue("net.host.port"),
pmetrictest.IgnoreResourceAttributeValue("server.port"),
pmetrictest.IgnoreResourceAttributeValue("service.name"),
pmetrictest.IgnoreResourceAttributeValue("service_instance_id"),
pmetrictest.IgnoreResourceAttributeValue("service_version"),
pmetrictest.IgnoreMetricAttributeValue("service_version"),
pmetrictest.IgnoreMetricAttributeValue("service_instance_id"),
pmetrictest.IgnoreSubsequentDataPoints(),
pmetrictest.IgnoreTimestamp(),
pmetrictest.IgnoreStartTimestamp(),
pmetrictest.IgnoreMetricDataPointsOrder(),
pmetrictest.IgnoreScopeMetricsOrder(),
pmetrictest.IgnoreMetricsOrder(),
pmetrictest.IgnoreScopeVersion(),
pmetrictest.IgnoreResourceMetricsOrder(),
pmetrictest.IgnoreMetricValues(),
)
assert.NoError(tt, err)
}, 60*time.Second, 1*time.Second)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
resourceMetrics:
- resource: {}
scopeMetrics:
- metrics:
- gauge:
dataPoints:
- asInt: "4284667555770276808"
attributes:
- key: system.type
value:
stringValue: exec
- key: tag.one
value:
stringValue: one
- key: tag.two
value:
stringValue: two
timeUnixNano: "1000000"
name: some.metric
scope: {}

This file was deleted.

0 comments on commit 0412d0b

Please sign in to comment.