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 24 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: ["gorillamux", "nethttp", "gin"]
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" --privileged --pid=host otel-go-instrumentation
- name: Build sample app
run: |
cd test/e2e/${{ matrix.library }}
go build .
cd ../../..
- name: run app
run: |
export OTEL_SERVICE_NAME=sample-app
./test/e2e/${{matrix.library}}/${{matrix.library}}
- name: copy traces
run: |
sudo chmod 666 /tmp/trace.json
cp /tmp/trace.json ./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 ./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
63 changes: 63 additions & 0 deletions .github/workflows/e2e/k8s/deployment/sample-job.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
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"
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: ["gorillamux", "nethttp", "gin"]
mode: ["sidecar", "deployment"]
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
Expand Down Expand Up @@ -52,19 +51,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@v3
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
dineshg13 marked this conversation as resolved.
Show resolved Hide resolved

## [v0.2.2-alpha] - 2023-07-12

### Added
Expand Down
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ BPF_INCLUDE += -I${REPODIR}/include

.DEFAULT_GOAL := precommit

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

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

Expand Down Expand Up @@ -132,9 +135,10 @@ 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
sleep 5
dineshg13 marked this conversation as resolved.
Show resolved Hide resolved
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 ./test/e2e/$(LIBRARY)/traces-orig.json
rm -f ./test/e2e/$(LIBRARY)/traces.json
Expand Down
106 changes: 61 additions & 45 deletions cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,41 @@
package main

import (
"context"
"fmt"
"os"
"os/signal"
"runtime"
"strings"
"syscall"

"go.opentelemetry.io/auto/pkg/errors"
"go.opentelemetry.io/auto/pkg/instrumentors"
"google.golang.org/grpc"

"go.opentelemetry.io/otel/exporters/otlp/otlptrace"
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"

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

var (
// Controller-local reference to the auto-instrumentation release version.
releaseVersion = auto.Version()
MrAlias marked this conversation as resolved.
Show resolved Hide resolved
// Start of this auto-instrumentation's exporter User-Agent header, e.g. ""OTel-Go-Auto-Instrumentation/1.2.3".
baseUserAgent = fmt.Sprintf("OTel-Go-Auto-Instrumentation/%s", releaseVersion)
// Information about the runtime environment for inclusion in User-Agent, e.g. "go/1.18.2 (linux/amd64)".
runtimeInfo = fmt.Sprintf(
"%s (%s/%s)",
strings.Replace(runtime.Version(), "go", "go/", 1),
runtime.GOOS,
runtime.GOARCH,
)
// Combined User-Agent identifying this auto-instrumentation and its runtime environment, see RFC7231 for format considerations.
autoinstUserAgent = fmt.Sprintf("%s %s", baseUserAgent, runtimeInfo)
)

func main() {
err := log.Init()
if err != nil {
Expand All @@ -35,56 +58,49 @@ func main() {
}

log.Logger.V(0).Info("starting Go OpenTelemetry Agent ...")
target := process.ParseTargetArgs()
if err = target.Validate(); err != nil {
log.Logger.Error(err, "invalid target args")
return
}

processAnalyzer := process.NewAnalyzer()
otelController, err := opentelemetry.NewController()
ctx := contextWithSigterm(context.Background())
log.Logger.V(0).Info("Establishing connection to OTLP receiver ...")
otlpTraceClient := otlptracegrpc.NewClient(
otlptracegrpc.WithDialOption(grpc.WithUserAgent(autoinstUserAgent)),
)
traceExporter, err := otlptrace.New(ctx, otlpTraceClient)
if err != nil {
log.Logger.Error(err, "unable to create OpenTelemetry controller")
log.Logger.Error(err, "unable to connect to OTLP endpoint")
return
}

instManager, err := instrumentors.NewManager(otelController)
targetArgs := process.ParseTargetArgs()
if targetArgs != nil {
dineshg13 marked this conversation as resolved.
Show resolved Hide resolved
if err := targetArgs.Validate(); err != nil {
log.Logger.Error(err, "invalid target args")
return
}
}
r, err := orchestrator.New(ctx, targetArgs, traceExporter)
dineshg13 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
log.Logger.Error(err, "error creating instrumetors manager")
return
log.Logger.V(0).Error(err, "creating orchestrator")
}
if err = r.Run(); err != nil {
log.Logger.Error(err, "running orchestrator")
}
}

stopper := make(chan os.Signal, 1)
signal.Notify(stopper, os.Interrupt, syscall.SIGTERM)
go func() {
<-stopper
log.Logger.V(0).Info("Got SIGTERM, cleaning up..")
processAnalyzer.Close()
instManager.Close()
}()
func contextWithSigterm(parent context.Context) context.Context {
ctx, cancel := context.WithCancel(parent)

pid, err := processAnalyzer.DiscoverProcessID(target)
if err != nil {
if err != errors.ErrInterrupted {
log.Logger.Error(err, "error while discovering process id")
}
return
}
ch := make(chan os.Signal, 1)
signal.Notify(ch, os.Interrupt, syscall.SIGTERM)

targetDetails, err := processAnalyzer.Analyze(pid, instManager.GetRelevantFuncs())
if err != nil {
log.Logger.Error(err, "error while analyzing target process")
return
}
log.Logger.V(0).Info("target process analysis completed", "pid", targetDetails.PID,
"go_version", targetDetails.GoVersion, "dependencies", targetDetails.Libraries,
"total_functions_found", len(targetDetails.Functions))
go func() {
defer close(ch)
defer signal.Stop(ch)

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

log.Logger.V(0).Info("invoking instrumentors")
err = instManager.Run(targetDetails)
if err != nil && err != errors.ErrInterrupted {
log.Logger.Error(err, "error while running instrumentors")
}
return ctx
}
Loading
Loading