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

Docker socket adoption for installation test #5776

Merged
merged 4 commits into from
Jan 10, 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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,7 @@ deployments/heroku/test/node_modules
/instrumentation/so/
/instrumentation/tests/dotnet/libsplunk.so
/instrumentation/tests/java/libsplunk.so
/instrumentation/tests/nodejs/libsplunk.so
/instrumentation/tests/nodejs/libsplunk.so

# temp file created during testing
tests/installation/testdata/systemd/splunk-otel-collector.conf
26 changes: 13 additions & 13 deletions tests/installation/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"path/filepath"
"sort"
"strings"
"syscall"
"testing"
"time"

Expand Down Expand Up @@ -63,12 +62,11 @@ func TestDefaultConfigDDiscoversPostgres(t *testing.T) {
defer tc.PrintLogsOnFailure()
defer tc.ShutdownOTLPReceiverSink()

finfo, err := os.Stat("/var/run/docker.sock")
require.NoError(t, err)
fsys := finfo.Sys()
stat, ok := fsys.(*syscall.Stat_t)
require.True(t, ok)
dockerGID := fmt.Sprintf("%d", stat.Gid)
dockerSocket := testutils.CreateDockerSocketProxy(t)
require.NoError(t, dockerSocket.Start())
t.Cleanup(func() {
dockerSocket.Stop()
})

treeBytes, err := os.ReadFile(filepath.Join(".", "testdata", "tree"))
require.NoError(t, err)
Expand Down Expand Up @@ -99,6 +97,10 @@ func TestDefaultConfigDDiscoversPostgres(t *testing.T) {
for _, packageType := range []string{"deb", "rpm"} {
t.Run(packageType, func(t *testing.T) {
defer tc.OTLPReceiverSink.Reset()
tmpl, err := os.ReadFile(filepath.Join(".", "testdata", "systemd", "splunk-otel-collector.conf.tmpl"))
require.NoError(t, err)
newTmpl := strings.Replace(string(tmpl), "<DOCKER_SOCKET>", fmt.Sprintf("tcp://%s", dockerSocket.ContainerEndpoint), 1)
require.NoError(t, os.WriteFile(filepath.Join(".", "testdata", "systemd", "splunk-otel-collector.conf"), []byte(newTmpl), 0644))
packagePath := getPackagePath(t, packageType)
cc, shutdown := tc.SplunkOtelCollectorContainer(
"", func(c testutils.Collector) testutils.Collector {
Expand All @@ -110,14 +112,12 @@ func TestDefaultConfigDDiscoversPostgres(t *testing.T) {
fmt.Sprintf("Dockerfile.%s", packageType),
).WithHostConfigModifier(func(config *dockerContainer.HostConfig) {
config.CgroupnsMode = dockerContainer.CgroupnsModeHost
config.CapAdd = append(config.CapAdd, "NET_RAW")
config.GroupAdd = []string{dockerGID}
config.Mounts = []dockerMount.Mount{
{Source: "/sys/fs/cgroup", Target: "/sys/fs/cgroup", Type: dockerMount.TypeBind},
{Source: packagePath, Target: fmt.Sprintf("/opt/otel/splunk-otel-collector.%s", packageType), Type: dockerMount.TypeBind},
{Source: "/var/run/docker.sock", Target: "/opt/docker/docker.sock", ReadOnly: true, Type: dockerMount.TypeBind},
}
}).WithBuildArgs(map[string]*string{"DOCKER_GID": &dockerGID}).WithNetworks("postgres")

}).WithNetworks("postgres").WithNetworkMode("bridge")
cc.Container.WillWaitForLogs()
cc.Container.WaitingFor = append(cc.Container.WaitingFor, waitForSystemd)
return cc.WithArgs("")
Expand Down Expand Up @@ -213,7 +213,7 @@ func TestDefaultConfigDDiscoversPostgres(t *testing.T) {
"splunk.discovery": map[string]any{
"extensions": map[string]any{
"docker_observer": map[string]any{
"endpoint": "unix:///opt/docker/docker.sock",
"endpoint": fmt.Sprintf("tcp://%s", dockerSocket.ContainerEndpoint),
},
},
"receivers": map[string]any{
Expand Down Expand Up @@ -253,7 +253,7 @@ func TestDefaultConfigDDiscoversPostgres(t *testing.T) {
},
"extensions": map[string]any{
"docker_observer": map[string]any{
"endpoint": "unix:///opt/docker/docker.sock",
"endpoint": fmt.Sprintf("tcp://%s", dockerSocket.ContainerEndpoint),
},
},
"processors": map[string]any{},
Expand Down
3 changes: 0 additions & 3 deletions tests/installation/testdata/systemd/Dockerfile.deb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# A debian image with systemd enabled. Must be run with:
# `-d --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro` flags
FROM debian:bullseye
ARG DOCKER_GID=998

ENV DEBIAN_FRONTEND noninteractive

Expand All @@ -20,8 +19,6 @@ RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i = \
RUN systemctl set-default multi-user.target
ENV init /lib/systemd/systemd

RUN groupadd -g ${DOCKER_GID} docker

COPY --chown=999 service.yaml /etc/otel/collector/config.d/service.yaml
COPY --chown=999 otlp-exporter.yaml /etc/otel/collector/config.d/exporters/otlp-exporter.yaml
COPY --chown=999 prometheus-internal.yaml /etc/otel/collector/config.d/receivers/prometheus-internal.yaml
Expand Down
3 changes: 0 additions & 3 deletions tests/installation/testdata/systemd/Dockerfile.rpm
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
# A centos9 image with systemd enabled. Must be run with:
# `-d --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro` flags
FROM quay.io/centos/centos:stream9
ARG DOCKER_GID=998

ENV container docker

RUN groupadd -g ${DOCKER_GID} docker

RUN rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
RUN echo 'fastestmirror=1' >> /etc/yum.conf
RUN dnf install -y procps initscripts systemd tree
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
OTELCOL_OPTIONS="--configd --discovery"
SPLUNK_DISCOVERY_LOG_LEVEL=debug
SPLUNK_DISCOVERY_EXTENSIONS_docker_observer_CONFIG_endpoint="unix:///opt/docker/docker.sock"
SPLUNK_DISCOVERY_EXTENSIONS_docker_observer_CONFIG_endpoint="<DOCKER_SOCKET>"
SPLUNK_CONFIG=/dev/null
Loading