Skip to content

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

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

Closed
wants to merge 18 commits into from
Closed
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@b9e51907a09c216f16ebe8536097933489208112 # v4
with:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,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 @@ -194,6 +194,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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,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/gogo/protobuf v1.3.2 // indirect
github.com/google/uuid v1.6.0 // indirect
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL
github.com/cilium/ebpf v0.17.3 h1:FnP4r16PWYSE4ux6zN+//jMcW4nMVRvuTLVTvCjyyjg=
github.com/cilium/ebpf v0.17.3/go.mod h1:G5EDHij8yiLzaqn0WjyfJHvRa+3aDlReIaLVRMvOyJk=
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
13 changes: 9 additions & 4 deletions internal/test/e2e/autosdk/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
FROM golang:1.24.1@sha256:c5adecdb7b3f8c5ca3c88648a861882849cc8b02fed68ece31e25de88ad13418
ARG BASE_IMAGE=golang:1.24.1@sha256:c5adecdb7b3f8c5ca3c88648a861882849cc8b02fed68ece31e25de88ad13418
FROM ${BASE_IMAGE}
# Make sure this dir exists.
WORKDIR /usr/src/go.opentelemetry.io/auto/internal/test/e2e/autosdk

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.24.1@sha256:c5adecdb7b3f8c5ca3c88648a861882849cc8b02fed68ece31e25de88ad13418
ARG BASE_IMAGE=golang:1.24.1@sha256:c5adecdb7b3f8c5ca3c88648a861882849cc8b02fed68ece31e25de88ad13418
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
5 changes: 0 additions & 5 deletions internal/test/e2e/databasesql/go.mod

This file was deleted.

2 changes: 0 additions & 2 deletions internal/test/e2e/databasesql/go.sum

This file was deleted.

Loading