-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid duplication/triplication/n-plication of traces for the same pro…
…cess (#371) * Failint tests for multi-process * Avoid multi-instrumentation of the same process
- Loading branch information
Showing
7 changed files
with
185 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
test/integration/components/testserver/Dockerfile_duplicate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Build the testserver binary | ||
# Docker command must be invoked from the projec root directory | ||
FROM golang:1.21 as builder | ||
|
||
ARG TARGETARCH | ||
|
||
ENV GOARCH=$TARGETARCH | ||
|
||
WORKDIR /src | ||
|
||
# Copy the go manifests and source | ||
COPY vendor/ vendor/ | ||
COPY test/ test/ | ||
COPY go.mod go.mod | ||
COPY go.sum go.sum | ||
|
||
# Build | ||
RUN go build -o testserver ./test/integration/components/testserver/testserver.go | ||
|
||
# Create final image from minimal + built binary | ||
FROM debian:bookworm-slim | ||
|
||
WORKDIR / | ||
COPY --from=builder /src/test/integration/components/testserver/duplicate_testserver.sh . | ||
COPY --from=builder /src/testserver dupe_testserver | ||
USER 0:0 | ||
|
||
CMD [ "sh", "/duplicate_testserver.sh" ] |
12 changes: 12 additions & 0 deletions
12
test/integration/components/testserver/duplicate_testserver.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env sh | ||
|
||
run_testserver() | ||
{ | ||
# prefix for start ports. E.g. 808 | ||
sp=$1 | ||
STD_PORT=${1}0 GIN_PORT=${1}1 GORILLA_PORT=${1}2 GORILLA_MID_PORT=${1}3 ./dupe_testserver -port ${1}4 | ||
} | ||
|
||
# runs testserver twice | ||
run_testserver 1808 & | ||
run_testserver 1809 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
//go:build integration | ||
|
||
package integration | ||
|
||
import ( | ||
"net/http" | ||
"path" | ||
"testing" | ||
"time" | ||
|
||
"github.com/mariomac/guara/pkg/test" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/grafana/beyla/test/integration/components/docker" | ||
"github.com/grafana/beyla/test/integration/components/prom" | ||
) | ||
|
||
func TestMultiProcess(t *testing.T) { | ||
compose, err := docker.ComposeSuite("docker-compose-multiexec.yml", path.Join(pathOutput, "test-suite-multiexec.log")) | ||
// we are going to setup discovery directly in the configuration file | ||
compose.Env = append(compose.Env, `EXECUTABLE_NAME=`, `OPEN_PORT=`) | ||
require.NoError(t, err) | ||
require.NoError(t, compose.Up()) | ||
t.Run("Go RED metrics: usual service", func(t *testing.T) { | ||
waitForTestComponents(t, instrumentedServiceStdURL) | ||
testREDMetricsForHTTPLibrary(t, instrumentedServiceStdURL, "testserver", "initial-set") | ||
// checks that, instrumenting the process from this container, | ||
// it doesn't instrument too the process from the other container | ||
checkReportedOnlyOnce(t, instrumentedServiceStdURL, "testserver") | ||
}) | ||
t.Run("Go RED metrics: service 1", func(t *testing.T) { | ||
waitForTestComponents(t, "http://localhost:8900") | ||
testREDMetricsForHTTPLibrary(t, "http://localhost:8900", "rename1", "initial-set") | ||
// checks that, instrumenting the process from this container, | ||
// it doesn't instrument too the process from the other container | ||
checkReportedOnlyOnce(t, "http://localhost:8900", "rename1") | ||
}) | ||
t.Run("Processes in the same host are instrumented once and only once", func(t *testing.T) { | ||
waitForTestComponents(t, "http://localhost:18080") | ||
checkReportedOnlyOnce(t, "http://localhost:18080", "dupe_testserver") | ||
}) | ||
|
||
t.Run("BPF pinning folders mounted", func(t *testing.T) { | ||
// 1 pinned map for testserver and testserver-unused containers | ||
// 1 pinned map for testserver1 container | ||
// 1 pinned map for all the processes in testserver-duplicate container | ||
testBPFPinningMountedWithCount(t, 3) | ||
}) | ||
|
||
require.NoError(t, compose.Close()) | ||
t.Run("BPF pinning folder unmounted", testBPFPinningUnmounted) | ||
} | ||
|
||
// Addresses bug https://github.com/grafana/beyla/issues/370 for Go executables | ||
// Prevents that two instances of the same process report traces or metrics by duplicate | ||
func checkReportedOnlyOnce(t *testing.T, baseURL, serviceName string) { | ||
const path = "/check-only-once" | ||
for i := 0; i < 3; i++ { | ||
resp, err := http.Get(baseURL + path) | ||
require.NoError(t, err) | ||
require.Equal(t, http.StatusOK, resp.StatusCode) | ||
} | ||
pq := prom.Client{HostPort: prometheusHostPort} | ||
var results []prom.Result | ||
test.Eventually(t, testTimeout, func(t require.TestingT) { | ||
var err error | ||
results, err = pq.Query(`http_server_duration_seconds_count{` + | ||
`http_method="GET",` + | ||
`http_status_code="200",` + | ||
`service_name="` + serviceName + `",` + | ||
`http_target="` + path + `"}`) | ||
require.NoError(t, err) | ||
// check duration_count has 3 calls and all the arguments | ||
require.Len(t, results, 1) | ||
assert.Equal(t, 3, totalPromCount(t, results)) | ||
}, test.Interval(1000*time.Millisecond)) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters