Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do not use resource_metrics for configproviders tests #5796

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 38 additions & 10 deletions tests/general/configproviders/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
package tests

import (
"fmt"
"testing"
"time"

"github.com/stretchr/testify/assert"

"github.com/signalfx/splunk-otel-collector/tests/testutils"
)
Expand All @@ -41,14 +45,38 @@ service:
receivers: [hostmetrics]
exporters: [otlp]
`
testutils.AssertAllMetricsReceived(
t, "memory.yaml", "", nil,
[]testutils.CollectorBuilder{
func(collector testutils.Collector) testutils.Collector {
return collector.WithEnv(
map[string]string{"SOME_ENV_VAR": config},
).WithArgs("--config", "env:SOME_ENV_VAR")
},
},
)
tc := testutils.NewTestcase(t)
defer tc.PrintLogsOnFailure()
defer tc.ShutdownOTLPReceiverSink()

_, shutdown := tc.SplunkOtelCollector("", func(collector testutils.Collector) testutils.Collector {
return collector.WithEnv(
map[string]string{"SOME_ENV_VAR": config},
).WithArgs("--config", "env:SOME_ENV_VAR")
})
defer shutdown()

missingMetrics := map[string]struct{}{
"system.memory.usage": {},
}

assert.EventuallyWithT(t, func(tt *assert.CollectT) {
for i := 0; i < len(tc.OTLPReceiverSink.AllMetrics()); i++ {
m := tc.OTLPReceiverSink.AllMetrics()[i]
for j := 0; j < m.ResourceMetrics().Len(); j++ {
rm := m.ResourceMetrics().At(j)
for k := 0; k < rm.ScopeMetrics().Len(); k++ {
sm := rm.ScopeMetrics().At(k)
for l := 0; l < sm.Metrics().Len(); l++ {
delete(missingMetrics, sm.Metrics().At(l).Name())
atoulme marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}
msg := "Missing metrics:\n"
for k := range missingMetrics {
msg += fmt.Sprintf("- %q\n", k)
}
assert.Len(tt, missingMetrics, 0, msg)
}, 30*time.Second, 1*time.Second)
}
50 changes: 34 additions & 16 deletions tests/general/configproviders/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,46 @@
package tests

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

"github.com/stretchr/testify/require"
"github.com/stretchr/testify/assert"

"github.com/signalfx/splunk-otel-collector/tests/testutils"
)

func TestFileProvider(t *testing.T) {
t.Skip("Issues with test-containers networking, need to wait for -contrib to update the docker api version for us to update testcontainers-go locally")
testdataPath, err := filepath.Abs(path.Join(".", "testdata"))
require.NoError(t, err)
testutils.AssertAllMetricsReceived(
t, "memory.yaml", "", nil,
[]testutils.CollectorBuilder{
func(collector testutils.Collector) testutils.Collector {
if cc, ok := collector.(*testutils.CollectorContainer); ok {
collector = cc.WithMount(testdataPath, "/testdata")
tc := testutils.NewTestcase(t)
defer tc.PrintLogsOnFailure()
defer tc.ShutdownOTLPReceiverSink()

_, shutdown := tc.SplunkOtelCollectorProcess("", func(collector testutils.Collector) testutils.Collector {
return collector.WithArgs("--config", "file:./testdata/file_config.yaml")
})
defer shutdown()

missingMetrics := map[string]struct{}{
"system.memory.usage": {},
}

assert.EventuallyWithT(t, func(tt *assert.CollectT) {
for i := 0; i < len(tc.OTLPReceiverSink.AllMetrics()); i++ {
m := tc.OTLPReceiverSink.AllMetrics()[i]
for j := 0; j < m.ResourceMetrics().Len(); j++ {
rm := m.ResourceMetrics().At(j)
for k := 0; k < rm.ScopeMetrics().Len(); k++ {
sm := rm.ScopeMetrics().At(k)
for l := 0; l < sm.Metrics().Len(); l++ {
delete(missingMetrics, sm.Metrics().At(l).Name())
}
}
return collector.WithArgs("--config", "file:./testdata/file_config.yaml")
},
},
)
}
}
msg := "Missing metrics:\n"
for k := range missingMetrics {
msg += fmt.Sprintf("- %q\n", k)
}
assert.Len(tt, missingMetrics, 0, msg)
}, 30*time.Second, 1*time.Second)
}

This file was deleted.

Loading