Skip to content

Commit

Permalink
reenable redis discovery by running the redis server in a dedicated t…
Browse files Browse the repository at this point in the history
…est (#5782)

* reenable redis discovery by running the redis server in a bridge network

* update discovery

* fix docker host

* run the test in its own test run

* simplify by running the test in isolation
  • Loading branch information
atoulme authored Jan 13, 2025
1 parent e402969 commit ab498e0
Show file tree
Hide file tree
Showing 6 changed files with 365 additions and 102 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ jobs:
id: get-matrix
run: |
includes=""
for service in "apache" "jmx/cassandra" "kafkametrics" "mongodb" "nginx" "envoy" "oracledb" "mysql"; do
for service in "apache" "jmx/cassandra" "kafkametrics" "mongodb" "nginx" "envoy" "oracledb" "mysql" "redis"; do
for arch in "amd64" "arm64"; do
if [ "$service" = "mongodb" ]; then
# tests for mongo "6.0" and "7.0" are flaky, skipping for now
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,14 @@ integration-test-envoy-discovery:
integration-test-nginx-discovery:
@set -e; cd tests && $(GOTEST_SERIAL) $(BUILD_INFO_TESTS) --tags=discovery_integration_nginx -v -timeout 5m -count 1 ./...

.PHONY: integration-test-redis-discovery
integration-test-redis-discovery:
@set -e; cd tests && $(GOTEST_SERIAL) $(BUILD_INFO_TESTS) --tags=discovery_integration_redis -v -timeout 5m -count 1 ./...

.PHONY: integration-test-oracledb-discovery
integration-test-oracledb-discovery:
@set -e; cd tests && $(GOTEST_SERIAL) $(BUILD_INFO_TESTS) --tags=discovery_integration_oracledb -v -timeout 5m -count 1 ./...


.PHONY: smartagent-integration-test
smartagent-integration-test:
@set -e; cd tests && $(GOTEST_SERIAL) $(BUILD_INFO_TESTS) --tags=smartagent_integration -v -timeout 5m -count 1 ./...
Expand Down
1 change: 1 addition & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ services:
image: quay.io/splunko11ytest/redis_server:latest
profiles:
- integration
- integration-test-redis-discovery
build: ./redis_server
ports:
- "6379:6379"
Expand Down
101 changes: 69 additions & 32 deletions tests/receivers/redis/bundled_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,48 +12,85 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build integration
//go:build discovery_integration_redis

package tests

import (
"fmt"
"runtime"
"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"

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

func TestRedisDockerObserver(t *testing.T) {
t.Skip("Discovery mode picks up other Docker containers running, making the test fail.")
testutils.SkipIfNotContainerTest(t)
if runtime.GOOS == "darwin" {
t.Skip("unable to share sockets between mac and d4m vm: https://github.com/docker/for-mac/issues/483#issuecomment-758836836")
}

testutils.AssertAllMetricsReceived(t, "all_server_bundled.yaml", "otlp_exporter.yaml",
nil, []testutils.CollectorBuilder{
func(c testutils.Collector) testutils.Collector {
cc := c.(*testutils.CollectorContainer)
cc.Container = cc.Container.WithBinds("/var/run/docker.sock:/var/run/docker.sock:ro")
cc.Container = cc.Container.WillWaitForLogs("Discovering for next")
cc.Container = cc.Container.WithUser(fmt.Sprintf("999:%d", testutils.GetDockerGID(t)))
return cc
},
func(collector testutils.Collector) testutils.Collector {
return collector.WithEnv(map[string]string{
"REDIS_PASSWORD": "securepassword",
"REDIS_USERNAME": "otel",
// confirm that debug logging doesn't affect runtime
"SPLUNK_DISCOVERY_LOG_LEVEL": "debug",
}).WithArgs(
"--discovery",
"--set", "splunk.discovery.receivers.redis.config.password=${REDIS_PASSWORD}",
"--set", "splunk.discovery.receivers.redis.config.username=${REDIS_USERNAME}",
"--set", `splunk.discovery.extensions.k8s_observer.enabled=false`,
"--set", `splunk.discovery.extensions.host_observer.enabled=false`,
)
},
},
)
dockerSocket := testutils.CreateDockerSocketProxy(t)
require.NoError(t, dockerSocket.Start())
t.Cleanup(func() {
dockerSocket.Stop()
})

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

_, shutdown := tc.SplunkOtelCollectorContainer("otlp_exporter.yaml", func(c testutils.Collector) testutils.Collector {
cc := c.(*testutils.CollectorContainer)
cc.Container = cc.Container.WillWaitForLogs("Discovering for next")
return cc
},
func(collector testutils.Collector) testutils.Collector {
return collector.WithEnv(map[string]string{
"REDIS_PASSWORD": "securepassword",
"REDIS_USERNAME": "otel",
// confirm that debug logging doesn't affect runtime
"SPLUNK_DISCOVERY_LOG_LEVEL": "debug",
"SPLUNK_DISCOVERY_DURATION": "20s",
}).WithArgs(
"--discovery",
"--set", "splunk.discovery.receivers.redis.config.password=${REDIS_PASSWORD}",
"--set", "splunk.discovery.receivers.redis.config.username=${REDIS_USERNAME}",
"--set", `splunk.discovery.extensions.k8s_observer.enabled=false`,
"--set", `splunk.discovery.extensions.host_observer.enabled=false`,
"--set", fmt.Sprintf("splunk.discovery.extensions.docker_observer.config.endpoint=tcp://%s", dockerSocket.ContainerEndpoint),
)
})
defer shutdown()
expected, err := golden.ReadMetrics(filepath.Join("testdata", "expected.yaml"))
require.NoError(t, err)
require.EventuallyWithT(t, func(tt *assert.CollectT) {
if len(tc.OTLPReceiverSink.AllMetrics()) == 0 {
assert.Fail(tt, "No metrics collected")
return
}
err := pmetrictest.CompareMetrics(expected, tc.OTLPReceiverSink.AllMetrics()[len(tc.OTLPReceiverSink.AllMetrics())-1],
pmetrictest.IgnoreResourceAttributeValue("service.instance.id"),
pmetrictest.IgnoreResourceAttributeValue("net.host.port"),
pmetrictest.IgnoreResourceAttributeValue("net.host.name"),
pmetrictest.IgnoreResourceAttributeValue("server.address"),
pmetrictest.IgnoreResourceAttributeValue("container.name"),
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.IgnoreTimestamp(),
pmetrictest.IgnoreStartTimestamp(),
pmetrictest.IgnoreMetricDataPointsOrder(),
pmetrictest.IgnoreScopeMetricsOrder(),
pmetrictest.IgnoreScopeVersion(),
pmetrictest.IgnoreResourceMetricsOrder(),
pmetrictest.IgnoreMetricValues(),
)
assert.NoError(tt, err)
}, 60*time.Second, 1*time.Second)
}
Loading

0 comments on commit ab498e0

Please sign in to comment.