Skip to content

Commit

Permalink
Fix eBPF director cleanups (#1523)
Browse files Browse the repository at this point in the history
Fixed cleanup in eBPF director:
* Delete `instrumentationInstance` correctly (passing the correct
instrumentation instance name which includes the pod name and the PID).
* Add a periodic cleanup routine to detect processes that do not exist
and clear all the instrumentation resources associated with them.

Refine the director data structures by introducing
`InstrumentedProcess`:
* make sure we only try to instrument a given PID in a given pod once
with `sync.Once`.
* Once an instrumented process is closed use an atomic flag to mark it
as closed.
* Refactor the cleanup of an instrumented process to a common function.
* Move the go instrumentation to an `sdks` folder which allows
separating the generic director to its package and testing it without
having dependencies on the go instrumentation repo.
* Add unit testing for the director.
  • Loading branch information
RonFed authored Sep 22, 2024
1 parent e504bc4 commit 75cc5df
Show file tree
Hide file tree
Showing 6 changed files with 554 additions and 138 deletions.
6 changes: 3 additions & 3 deletions k8sutils/pkg/instrumentation_instance/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ func updateInstrumentationInstanceStatus(status odigosv1.InstrumentationInstance
return status
}

func InstrumentationInstanceName(owner client.Object, pid int) string {
return fmt.Sprintf("%s-%d", owner.GetName(), pid)
func InstrumentationInstanceName(ownerName string, pid int) string {
return fmt.Sprintf("%s-%d", ownerName, pid)
}

func UpdateInstrumentationInstanceStatus(ctx context.Context, owner client.Object, containerName string, kubeClient client.Client, instrumentedAppName string, pid int, scheme *runtime.Scheme, options ...InstrumentationInstanceOption) error {
instrumentationInstanceName := InstrumentationInstanceName(owner, pid)
instrumentationInstanceName := InstrumentationInstanceName(owner.GetName(), pid)
updatedInstance := &odigosv1.InstrumentationInstance{
TypeMeta: metav1.TypeMeta{
APIVersion: "odigos.io/v1alpha1",
Expand Down
3 changes: 2 additions & 1 deletion odiglet/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"os"

"github.com/odigos-io/odigos/odiglet/pkg/ebpf/sdks"
"github.com/odigos-io/odigos/odiglet/pkg/instrumentation/fs"

"github.com/kubevirt/device-plugin-manager/pkg/dpm"
Expand Down Expand Up @@ -143,7 +144,7 @@ func startDeviceManager(clientset *kubernetes.Clientset) {
}

func initEbpf(ctx context.Context, client client.Client, scheme *runtime.Scheme) (ebpf.DirectorsMap, error) {
goInstrumentationFactory := ebpf.NewGoInstrumentationFactory(client)
goInstrumentationFactory := sdks.NewGoInstrumentationFactory(client)
goDirector := ebpf.NewEbpfDirector(ctx, client, scheme, common.GoProgrammingLanguage, goInstrumentationFactory)
goDirectorKey := ebpf.DirectorKey{
Language: common.GoProgrammingLanguage,
Expand Down
3 changes: 3 additions & 0 deletions odiglet/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
github.com/odigos-io/odigos/opampserver v0.0.0
github.com/odigos-io/odigos/procdiscovery v0.0.0
github.com/odigos-io/opentelemetry-zap-bridge v0.0.5
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/auto v0.14.0-alpha.0.20240825151512-46ef49139923
go.opentelemetry.io/otel v1.29.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.29.0
Expand Down Expand Up @@ -63,6 +64,7 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.20.1 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
Expand Down Expand Up @@ -101,6 +103,7 @@ require (
google.golang.org/genproto/googleapis/api v0.0.0-20240822170219-fc7c04adadcd // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240822170219-fc7c04adadcd // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading

0 comments on commit 75cc5df

Please sign in to comment.