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

Add orchestrator for supporting multiple processes #208

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
2c71b87
Add orchestrator for supporting multiple processes
dineshg13 Jun 25, 2023
bab5d8f
remove gops & use disover process
dineshg13 Jun 26, 2023
ad0ae97
Merge branch 'main' into dinesh.gurumurthy/multiprocess
dineshg13 Jun 26, 2023
6e6181a
Merge branch 'main' into dinesh.gurumurthy/multiprocess
dineshg13 Jun 27, 2023
24ccbd1
revert un-needed changes
dineshg13 Jun 28, 2023
b6386d4
Merge branch 'dinesh.gurumurthy/multiprocess' of github.com:dineshg13…
dineshg13 Jun 28, 2023
d196e4f
add changelog
dineshg13 Jun 28, 2023
729cf8d
Merge branch 'main' into dinesh.gurumurthy/multiprocess
dineshg13 Jul 3, 2023
d5c54a1
PR comments - add controllersettings
dineshg13 Jul 3, 2023
d4c3931
fix lint issues
dineshg13 Jul 3, 2023
72f4fda
Merge branch 'main' into dinesh.gurumurthy/multiprocess
dineshg13 Jul 8, 2023
cc9ef9a
add deployment yaml
dineshg13 Jul 8, 2023
4022e04
add chmod
dineshg13 Jul 10, 2023
05e27fe
Add tests for k8s deployment
damemi Jul 10, 2023
0bf47c0
read env vars from /proc
dineshg13 Jul 12, 2023
aed3934
remove ignore process + read service name from env var
dineshg13 Jul 13, 2023
8f06d0f
merge main
dineshg13 Jul 13, 2023
50b5c4e
Update generated offsets (#224)
github-actions[bot] Jul 15, 2023
1e2c979
Bump go.opentelemetry.io/build-tools/multimod in /internal/tools (#225)
dependabot[bot] Jul 16, 2023
f9f6572
Bump helm/kind-action from 1.7.0 to 1.8.0 (#226)
dependabot[bot] Jul 16, 2023
9874331
BPF FS: add support for multiple processes (#211)
edeNFed Jul 23, 2023
f5c4c06
Commit message
dineshg13 Jul 31, 2023
f79b635
Merge branch 'main' into dinesh.gurumurthy/multiprocess
dineshg13 Jul 31, 2023
61b620d
Merge branch 'main' into dinesh.gurumurthy/multiprocess
dineshg13 Aug 4, 2023
725e58b
merge main
dineshg13 Aug 8, 2023
7685fa1
merge main
dineshg13 Aug 8, 2023
a35693f
Address PR comments
dineshg13 Aug 16, 2023
db9989f
Merge main
dineshg13 Aug 21, 2023
4a42cc5
Update CHANGELOG.md
dineshg13 Aug 21, 2023
ed03b50
Update CHANGELOG.md
dineshg13 Aug 21, 2023
0340fdc
Update CHANGELOG.md
dineshg13 Sep 5, 2023
1cedbe6
merge main
dineshg13 Sep 5, 2023
a69ff54
non-compiling changes
dineshg13 Oct 4, 2023
5b1693e
local changes - non compiling
dineshg13 Oct 10, 2023
de6e29a
Add withPID
dineshg13 Oct 14, 2023
e3aaff3
remove un-needed tests
dineshg13 Oct 15, 2023
1183064
Merge main
dineshg13 Oct 15, 2023
ed52f93
remove gin from tests
dineshg13 Oct 15, 2023
39cc03a
Merge branch 'main' into dinesh.gurumurthy/multiprocess
dineshg13 Oct 15, 2023
ef606ef
fix license
dineshg13 Oct 15, 2023
6137c90
Update changelog
dineshg13 Oct 15, 2023
89d30e4
fix version
dineshg13 Oct 15, 2023
fc13d3d
fix path
dineshg13 Oct 15, 2023
937cb8b
remove gorillamux
dineshg13 Oct 15, 2023
2931fdf
fix test
dineshg13 Oct 15, 2023
2f206d9
Merge branch 'main' into dinesh.gurumurthy/multiprocess
dineshg13 Oct 15, 2023
09049d7
Add OTel go sql statement
dineshg13 Oct 15, 2023
6b1ae19
Merge branch 'main' into dinesh.gurumurthy/multiprocess
pdelewski Oct 17, 2023
67867d4
Merge branch 'main' into dinesh.gurumurthy/multiprocess
dineshg13 Oct 19, 2023
e598e1d
Update cli/main.go
dineshg13 Oct 19, 2023
11cb8d1
Update Makefile
dineshg13 Oct 19, 2023
92dd99a
PR feedback - move context to Run method
dineshg13 Oct 19, 2023
1bf77a5
Merge remote-tracking branch 'origin/main' into dinesh.gurumurthy/mul…
dineshg13 Oct 19, 2023
e778cfb
PR feedback - move changelog to un-released
dineshg13 Oct 19, 2023
4bcce14
Merge main
dineshg13 Oct 22, 2023
fa996bd
PR feedback - comments + remove monitor All
dineshg13 Oct 22, 2023
74ecf77
PR feedback - change name + add ticker stop method
dineshg13 Oct 22, 2023
c6ccf5a
Fix tests
dineshg13 Oct 22, 2023
715c21d
Merge branch 'main' into dinesh.gurumurthy/multiprocess
dineshg13 Oct 22, 2023
26748f8
Merge main + PR feedback on ctx
dineshg13 Oct 23, 2023
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
50 changes: 50 additions & 0 deletions .github/workflows/bare-metal.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: e2e-tests-bare-metal
on:
push:
branches:
- main
tags:
- 'v[0-9]+.[0-9]+.[0-9]+*'
pull_request:
jobs:
bare-metal-test:
strategy:
matrix:
k8s-version: ["v1.26.0"]
library: ["nethttp", "gin", "databasesql"]
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: "1.20"
- name: Setup BATS
uses: mig4/setup-bats@v1
- name: run collector
run: |
docker run -d -v ${PWD}/.github/workflows/e2e/bare-metal/collector-config.yml:/etc/config.yaml -v /tmp:/tmp -p 4317:4317 otel/opentelemetry-collector-contrib --config /etc/config.yaml
- name: Build auto-instrumentation
run: |
IMG=otel-go-instrumentation:latest make docker-build
- name: run auto-instrumentation
run: |
docker run -d -e OTEL_EXPORTER_OTLP_ENDPOINT="http://172.17.0.1:4317" -e OTEL_GO_AUTO_INCLUDE_DB_STATEMENT=true --privileged --pid=host otel-go-instrumentation
- name: Build sample app
run: |
cd internal/test/e2e/${{ matrix.library }}
go build .
cd ../../..
- name: run app
run: |
export OTEL_SERVICE_NAME=sample-app
./internal/test/e2e/${{matrix.library}}/${{matrix.library}}
- name: copy traces
run: |
sudo chmod 666 /tmp/trace.json
cp /tmp/trace.json ./internal/test/e2e/${{ matrix.library }}/traces-orig.json
rm -f ./test/e2e/${{ matrix.library }}/traces.json
- name: verify output and redact to traces.json
run: |
bats ./internal/test/e2e/${{ matrix.library }}/verify.bats
21 changes: 21 additions & 0 deletions .github/workflows/e2e/bare-metal/collector-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
receivers:
otlp:
protocols:
grpc:
http:
exporters:
logging: {}
file/trace:
path: /tmp/trace.json
rotation:
service:
telemetry:
logs:
level: "debug"
pipelines:
traces:
receivers:
- otlp
exporters:
- file/trace
- logging
65 changes: 65 additions & 0 deletions .github/workflows/e2e/k8s/deployment/sample-job.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
apiVersion: batch/v1
kind: Job
metadata:
name: sample-job
namespace: default
spec:
template:
metadata:
annotations:
workload: job
labels:
app: sample
spec:
hostPID: true
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
containers:
- name: sample-app
image: sample-app
imagePullPolicy: IfNotPresent
env:
- name: OTEL_SERVICE_NAME
value: "sample-app"
command: ["/bin/sh", "-c"]
args: ["/sample-app/main"]
---
apiVersion: v1
kind: Pod
metadata:
name: "auto-instrumentation"
namespace: default
labels:
app: "auto-instrumentation"
spec:
hostPID: true
containers:
- name: auto-instrumentation
image: otel-go-instrumentation
imagePullPolicy: IfNotPresent
env:
- name: OTEL_EXPORTER_OTLP_ENDPOINT
value: "http://test-opentelemetry-collector:4317"
- name: OTEL_PROPAGATORS
value: "tracecontext,baggage"
- name: OTEL_GO_AUTO_INCLUDE_DB_STATEMENT
value: "true"
resources: {}
securityContext:
runAsUser: 0
runAsGroup: 0
capabilities:
add:
- SYS_PTRACE
privileged: true
volumeMounts:
- mountPath: /sys/kernel/debug
name: kernel-debug
volumes:
- name: kernel-debug
hostPath:
path: /sys/kernel/debug
restartPolicy: Always
---
43 changes: 43 additions & 0 deletions .github/workflows/e2e/k8s/sidecar/collector-helm-values.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
mode: "statefulset"

config:
exporters:
logging: {}
file/trace:
path: /tmp/trace.json
rotation:

service:
telemetry:
logs:
level: "debug"
pipelines:
traces:
receivers:
- otlp
exporters:
- file/trace
- logging


image:
repository: otel/opentelemetry-collector-contrib
tag: "latest"

command:
name: otelcol-contrib

extraVolumes:
- name: filevolume
emptyDir: {}
extraVolumeMounts:
- mountPath: /tmp
name: filevolume

extraContainers:
- name: filecp
image: busybox
command: ["sh", "-c", "sleep 36000"]
volumeMounts:
- name: filevolume
mountPath: /tmp
9 changes: 4 additions & 5 deletions .github/workflows/kind.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
name: e2e-tests

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

jobs:
kubernetes-test:
strategy:
matrix:
k8s-version: ["v1.26.0"]
library: ["nethttp", "gin", "databasesql"]
mode: ["sidecar", "deployment"]
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
Expand Down Expand Up @@ -53,19 +52,19 @@ jobs:
- name: Add Dependencies
shell: bash
run: |
helm repo add open-telemetry https://open-telemetry.github.io/opentelemetry-helm-charts
helm repo add open-telemetry https://open-telemetry.github.io/opentelemetry-helm-charts
- uses: actions/checkout@v4
with:
repository: 'open-telemetry/opentelemetry-helm-charts'
path: opentelemetry-helm-charts
- name: Helm install collector
run: helm install test -f .github/workflows/e2e/k8s/collector-helm-values.yml opentelemetry-helm-charts/charts/opentelemetry-collector
run: helm install test -f .github/workflows/e2e/k8s/${{ matrix.mode }}/collector-helm-values.yml opentelemetry-helm-charts/charts/opentelemetry-collector
- name: check collector status
run: |
kubectl wait --for=condition=Ready --timeout=60s pod/test-opentelemetry-collector-0
- name: start sample job
run: |
kubectl -n default create -f .github/workflows/e2e/k8s/sample-job.yml
kubectl -n default create -f .github/workflows/e2e/k8s/${{ matrix.mode }}/sample-job.yml
- name: check job status
run: |
kubectl wait --for=condition=Complete --timeout=60s job/sample-job
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ OpenTelemetry Go Automatic Instrumentation adheres to [Semantic Versioning](http

## [Unreleased]

- Add ability to monitor multiple processes. ([#197](https://github.com/open-telemetry/opentelemetry-go-instrumentation/issues/197))
dineshg13 marked this conversation as resolved.
Show resolved Hide resolved

### Changed

- Documentation no longer says that `SYS_PTRACE` capabilty is needed. ([#388](https://github.com/open-telemetry/opentelemetry-go-instrumentation/pull/388))
Expand Down
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ CGO_ENABLED=1

.DEFAULT_GOAL := precommit

# Generate fixtures using "sidecar" or "deployment" method
FIXTURE_MODE ?= "sidecar"

.PHONY: precommit
precommit: license-header-check dependabot-generate go-mod-tidy golangci-lint-fix

Expand Down Expand Up @@ -157,9 +160,11 @@ fixtures/%:
if [ ! -d "opentelemetry-helm-charts" ]; then \
git clone https://github.com/open-telemetry/opentelemetry-helm-charts.git; \
fi
helm install test -f .github/workflows/e2e/k8s/collector-helm-values.yml opentelemetry-helm-charts/charts/opentelemetry-collector
helm install test -f .github/workflows/e2e/k8s/$(FIXTURE_MODE)/collector-helm-values.yml opentelemetry-helm-charts/charts/opentelemetry-collector
until kubectl get pods test-opentelemetry-collector-0 > /dev/null 2>&1; do sleep 1; done
echo "Pod test-opentelemetry-collector-0 been created!"
kubectl wait --for=condition=Ready --timeout=60s pod/test-opentelemetry-collector-0
kubectl -n default create -f .github/workflows/e2e/k8s/sample-job.yml
kubectl -n default create -f .github/workflows/e2e/k8s/$(FIXTURE_MODE)/sample-job.yml
kubectl wait --for=condition=Complete --timeout=60s job/sample-job
kubectl cp -c filecp default/test-opentelemetry-collector-0:tmp/trace.json ./internal/test/e2e/$(LIBRARY)/traces-orig.json
rm -f ./internal/test/e2e/$(LIBRARY)/traces.json
Expand Down
35 changes: 20 additions & 15 deletions cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ package main

import (
"context"
"errors"
"fmt"
"os"
"os/signal"
"syscall"

"go.opentelemetry.io/auto"
"go.opentelemetry.io/auto/internal/pkg/log"
"go.opentelemetry.io/auto/internal/pkg/process"
)

func main() {
Expand All @@ -35,30 +33,37 @@ func main() {
}

log.Logger.V(0).Info("building OpenTelemetry Go instrumentation ...")
inst, err := auto.NewInstrumentation()

ctx := contextWithSigterm(context.Background())
r, err := auto.NewInstrumentation(ctx)
if err != nil {
log.Logger.Error(err, "failed to create instrumentation")
return
}

// Trap Ctrl+C and SIGTERM and call cancel on the context.
ctx, cancel := context.WithCancel(context.Background())
log.Logger.V(0).Info("starting OpenTelemetry Go Agent ...")
if err = r.Run(ctx); err != nil {
log.Logger.Error(err, "running orchestrator")
}
}

func contextWithSigterm(parent context.Context) context.Context {
ctx, cancel := context.WithCancel(parent)

ch := make(chan os.Signal, 1)
signal.Notify(ch, os.Interrupt, syscall.SIGTERM)
defer func() {
signal.Stop(ch)
cancel()
}()

go func() {
defer close(ch)
defer signal.Stop(ch)

select {
case <-ch:
case <-parent.Done(): // if parent is cancelled, return
return
case <-ch: // if SIGTERM is received, cancel this context
cancel()
case <-ctx.Done():
}
}()

log.Logger.V(0).Info("starting instrumentors...")
if err = inst.Run(ctx); err != nil && !errors.Is(err, process.ErrInterrupted) {
log.Logger.Error(err, "instrumentation crashed")
}
return ctx
}
Loading
Loading