Skip to content

Commit

Permalink
move telegraf sqlserver to use golden files (#5786)
Browse files Browse the repository at this point in the history
  • Loading branch information
atoulme authored Jan 13, 2025
1 parent 0412d0b commit 606ea55
Show file tree
Hide file tree
Showing 4 changed files with 4,708 additions and 245 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,21 @@ 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"
)

func TestTelegrafSQLServerReceiverProvidesAllMetrics(t *testing.T) {
testutils.SkipIfNotContainerTest(t)
server := testutils.NewContainer().WithContext(
path.Join(".", "testdata", "server"),
).WithExposedPorts("1433:1433").WithName("sql-server").WithNetworks(
Expand All @@ -34,7 +43,59 @@ func TestTelegrafSQLServerReceiverProvidesAllMetrics(t *testing.T) {
client := testutils.NewContainer().WithContext(
path.Join(".", "testdata", "client"),
).WithName("sql-client").WithNetworks("mssql").WillWaitForLogs("name", "signalfxagent")
containers := []testutils.Container{server, client}

testutils.AssertAllMetricsReceived(t, "all.yaml", "all_metrics_config.yaml", containers, nil)
tc := testutils.NewTestcase(t)
defer tc.PrintLogsOnFailure()
defer tc.ShutdownOTLPReceiverSink()

_, stop := tc.Containers(server, client)
defer stop()

_, shutdown := tc.SplunkOtelCollectorContainer("all_metrics_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.IgnoreMetricAttributeValue("sql_instance"),
pmetrictest.IgnoreMetricAttributeValue("instance"),
pmetrictest.IgnoreMetricAttributeValue("wait_type"),
pmetrictest.IgnoreMetricAttributeValue("wait_category"),
pmetrictest.IgnoreMetricAttributeValue("hardware_type"),
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)
}
Loading

0 comments on commit 606ea55

Please sign in to comment.