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

[PoC] Run integration tests using docker-compose #1140

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft
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
59 changes: 59 additions & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: e2e

on:
push:
branches:
- main
tags:
- 'v[0-9]+.[0-9]+.[0-9]+*'
pull_request:

jobs:
setup:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Install build dependencies
run: sudo apt-get install -y clang llvm libbpf-dev
- name: Install Go
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5
with:
go-version: "~1.23.1"
check-latest: true
- name: Run generate
run: make generate
- uses: actions/upload-artifact@v4
with:
name: repo
path: ./
test:
needs: setup
strategy:
matrix:
library:
- autosdk
- databasesql
- gin
- grpc
- kafka-go
- nethttp
- nethttp_custom
- otelglobal
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
name: repo
- name: Clean
run: |
rm -f ./internal/test/e2e/${{ matrix.library }}/traces{,-orig}.json
touch ./internal/test/e2e/${{ matrix.library }}/traces-orig.json
- name: Run docker-compose
uses: hoverkraft-tech/[email protected]
with:
compose-file: "./internal/test/e2e/${{ matrix.library }}/compose.yaml"
- name: Setup BATS
uses: mig4/setup-bats@af9a00deb21b5d795cabfeaa8d9060410377686d # v1
- name: Verify with BATS
run: bats ./internal/test/e2e/${{ matrix.library }}/verify.bats
7 changes: 1 addition & 6 deletions .github/workflows/kind.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,8 @@ jobs:
steps:
- name: Checkout Repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Build sample app from script
if: ${{ hashFiles(format('internal/test/e2e/{0}/build.sh', matrix.library)) != '' }}
run: ./internal/test/e2e/${{ matrix.library }}/build.sh -t sample-app:latest
- name: Build sample app
if: ${{ hashFiles(format('internal/test/e2e/{0}/build.sh', matrix.library)) == '' }}
working-directory: ./internal/test/e2e/${{ matrix.library }}
run: docker build -t sample-app:latest .
run: docker build -f ./internal/test/e2e/${{ matrix.library }}/Dockerfile -t sample-app:latest .
- name: Set up Helm
uses: azure/setup-helm@fe7b79cd5ee1e45176fcad797de68ecaf3ca4814 # v4
with:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ examples/kafka-go/producer/producer
examples/kafka-go/consumer/consumer

go.work*

internal/test/e2e/autosdk/autosdk
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,21 @@ license-header-check:
exit 1; \
fi

.PHONY: e2e-autosdk e2e-databasesql e2e-gin e2e-grpc e2e-kafka-go e2e-nethttp e2e-nethttp-custom e2e-otelglobal
e2e-autosdk: e2e/internal/test/e2e/autosdk
e2e-databasesql: e2e/internal/test/e2e/databasesql
e2e-gin: e2e/internal/test/e2e/gin
e2e-grpc: e2e/internal/test/e2e/grpc
e2e-kafka-go: e2e/internal/test/e2e/kafka-go
e2e-nethttp: e2e/internal/test/e2e/nethttp
e2e-nethttp-custom: e2e/internal/test/e2e/nethttp_custom
e2e-otelglobal: e2e/internal/test/e2e/otelglobal
e2e/%: DIR=$*
e2e/%: generate
@: > $(DIR)/traces-orig.json # Truncate or ensure ownership.
@(cd $(DIR) && docker-compose up && docker-compose down)
@bats $(DIR)/verify.bats

.PHONY: fixture-nethttp fixture-gin fixture-databasesql fixture-nethttp-custom fixture-otelglobal fixture-autosdk fixture-kafka-go
fixture-nethttp-custom: fixtures/nethttp_custom
fixture-nethttp: fixtures/nethttp
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
Expand All @@ -50,7 +50,7 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.20.5 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.61.0 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL
github.com/cilium/ebpf v0.17.1 h1:G8mzU81R2JA1nE5/8SRubzqvBMmAmri2VL8BIZPWvV0=
github.com/cilium/ebpf v0.17.1/go.mod h1:vay2FaYSmIlv3r8dNACd4mW/OCaZLJKJOo+IHBvCIO8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
Expand Down Expand Up @@ -58,8 +59,9 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+bR9r+8l63Y=
github.com/prometheus/client_golang v1.20.5/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE=
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
Expand Down
15 changes: 9 additions & 6 deletions internal/test/e2e/autosdk/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
FROM golang:1.23.4@sha256:70031844b8c225351d0bb63e2c383f80db85d92ba894e3da7e13bcf80efa9a37
# Make sure this dir exists.
WORKDIR /usr/src/go.opentelemetry.io/auto/internal/test/e2e/autosdk
ARG BASE_IMAGE=golang:1.23.4@sha256:70031844b8c225351d0bb63e2c383f80db85d92ba894e3da7e13bcf80efa9a37
FROM ${BASE_IMAGE}

COPY sdk/ /usr/src/go.opentelemetry.io/auto/sdk/
COPY sdk/ /usr/src/go.opentelemetry.io/auto/sdk

# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading
# them in subsequent builds if they change
COPY internal/test/e2e/autosdk/go.mod internal/test/e2e/autosdk/go.sum ./
RUN go mod download && go mod verify
WORKDIR /usr/src/go.opentelemetry.io/auto/internal/test
COPY internal/test/go.mod internal/test/go.sum ./
RUN --mount=type=cache,target=/go/pkg go mod download && go mod verify

COPY internal/test/trigger/ ./trigger

WORKDIR /usr/src/go.opentelemetry.io/auto/internal/test/e2e/autosdk
COPY internal/test/e2e/autosdk/*.go .
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
Expand Down
59 changes: 59 additions & 0 deletions internal/test/e2e/autosdk/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0
services:
collector:
build:
context: ../../../tools/collector/
container_name: collector
ports:
- "4318:4318" # OTLP HTTP receiver
- "8888:8888" # Internal telemetry.
- "8080:8080" # Shutdown server
- "13133:13133" # Health check endpoint
command: -out=/target/traces-orig.json
volumes:
- .:/target
healthcheck:
test: ["CMD", "curl", "--silent", "--fail", "http://collector:13133/health"]
interval: 50ms
timeout: 40ms
runner:
build:
context: ../../../../
dockerfile: internal/tools/runner/Dockerfile
image: test-runner:latest
pull_policy: build
entrypoint: ["true"] # service is just used to build image.
e2e:
build:
context: ../../../../
dockerfile: internal/test/e2e/autosdk/Dockerfile
args:
BASE_IMAGE: "test-runner:latest"
TRIGGER: "signal:SIGCONT"
image: e2e-autosdk:latest
pull_policy: build
privileged: true
environment:
- OTEL_EXPORTER_OTLP_ENDPOINT=http://collector:4318
- OTEL_SERVICE_NAME=sample-app
- OTEL_BSP_SCHEDULE_DELAY=60000
depends_on:
runner:
condition: service_started
collector:
condition: service_healthy
entrypoint: ["/usr/local/bin/runner"]
command: -bin=/usr/local/bin/app
executioner:
build:
context: ../../../../
dockerfile: internal/tools/executioner/Dockerfile
image: test-executioner:latest
pull_policy: build
depends_on:
e2e:
condition: service_completed_successfully
command:
- -collector-address=http://collector
- -span-count=3
11 changes: 0 additions & 11 deletions internal/test/e2e/autosdk/go.mod

This file was deleted.

14 changes: 0 additions & 14 deletions internal/test/e2e/autosdk/go.sum

This file was deleted.

26 changes: 17 additions & 9 deletions internal/test/e2e/autosdk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package main
import (
"context"
"errors"
"flag"
"fmt"
"os"
"os/signal"
"time"
Expand All @@ -14,6 +16,7 @@ import (
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/trace"

"go.opentelemetry.io/auto/internal/test/trigger"
"go.opentelemetry.io/auto/sdk"
)

Expand Down Expand Up @@ -76,8 +79,19 @@ func sig(ctx context.Context) <-chan msg {
}

func main() {
// give time for auto-instrumentation to start up
time.Sleep(5 * time.Second)
var trig trigger.Flag
flag.Var(&trig, "trigger", trig.Docs())
flag.Parse()

ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
defer stop()

// Wait for auto-instrumentation.
err := trig.Wait(ctx)
if err != nil {
fmt.Println(err)
os.Exit(1)
}

provider := sdk.TracerProvider()
tracer := provider.Tracer(
Expand All @@ -87,12 +101,9 @@ func main() {
)
app := app{tracer: tracer}

ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
defer stop()

ctx, span := tracer.Start(ctx, "main", trace.WithTimestamp(y2k))

err := app.Run(ctx, "Alice", true, sig(ctx))
err = app.Run(ctx, "Alice", true, sig(ctx))
if err != nil {
span.SetStatus(codes.Error, "application error")
span.RecordError(
Expand All @@ -104,7 +115,4 @@ func main() {
}

span.End(trace.WithTimestamp(y2k.Add(5 * time.Second)))

// give time for auto-instrumentation to report signal
time.Sleep(5 * time.Second)
}
14 changes: 10 additions & 4 deletions internal/test/e2e/databasesql/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
FROM golang:1.23.4@sha256:70031844b8c225351d0bb63e2c383f80db85d92ba894e3da7e13bcf80efa9a37
ARG BASE_IMAGE=golang:1.23.4@sha256:70031844b8c225351d0bb63e2c383f80db85d92ba894e3da7e13bcf80efa9a37
FROM ${BASE_IMAGE}

COPY sdk/ /usr/src/go.opentelemetry.io/auto/sdk

# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading
# them in subsequent builds if they change
WORKDIR /usr/src/go.opentelemetry.io/auto/internal/test/e2e/databasesql
COPY go.mod go.sum ./
WORKDIR /usr/src/go.opentelemetry.io/auto/internal/test
COPY internal/test/go.mod internal/test/go.sum ./
RUN --mount=type=cache,target=/go/pkg go mod download && go mod verify

COPY *.go .
COPY internal/test/trigger/ ./trigger

WORKDIR /usr/src/go.opentelemetry.io/auto/internal/test/e2e/databasesql
COPY internal/test/e2e/databasesql/*.go .
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
go build -v -o /usr/local/bin/app .
Expand Down
60 changes: 60 additions & 0 deletions internal/test/e2e/databasesql/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0
services:
collector:
build:
context: ../../../tools/collector/
container_name: collector
ports:
- "4318:4318" # OTLP HTTP receiver
- "8080:8080" # Shutdown server
- "13133:13133" # Health check endpoint
command: -out=/target/traces-orig.json
volumes:
- .:/target
healthcheck:
test: ["CMD", "curl", "--silent", "--fail", "http://collector:13133/health"]
interval: 50ms
timeout: 40ms
runner:
build:
context: ../../../../
dockerfile: internal/tools/runner/Dockerfile
image: test-runner:latest
pull_policy: build
entrypoint: ["true"] # service is just used to build image.
e2e:
build:
context: ../../../../
dockerfile: internal/test/e2e/databasesql/Dockerfile
args:
BASE_IMAGE: "test-runner:latest"
TRIGGER: "signal:SIGCONT"
image: e2e-databasesql:latest
pull_policy: build
privileged: true
environment:
- OTEL_EXPORTER_OTLP_ENDPOINT=http://collector:4318
- OTEL_SERVICE_NAME=sample-app
- OTEL_BSP_SCHEDULE_DELAY=60000
- OTEL_GO_AUTO_INCLUDE_DB_STATEMENT=true
- OTEL_GO_AUTO_PARSE_DB_STATEMENT=true
depends_on:
runner:
condition: service_started
collector:
condition: service_healthy
entrypoint: ["/usr/local/bin/runner"]
command: -bin=/usr/local/bin/app
executioner:
build:
context: ../../../../
dockerfile: internal/tools/executioner/Dockerfile
image: test-executioner:latest
pull_policy: build
depends_on:
e2e:
condition: service_completed_successfully
command:
- -collector-address=http://collector
- -span-count=12
Loading