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

Read initial config of go auto instrumentation from instrumentationconfig CR #1486

Merged
merged 1 commit into from
Sep 2, 2024
Merged
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
2 changes: 1 addition & 1 deletion odiglet/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func startDeviceManager(clientset *kubernetes.Clientset) {
}

func initEbpf(ctx context.Context, client client.Client, scheme *runtime.Scheme) (ebpf.DirectorsMap, error) {
goInstrumentationFactory := ebpf.NewGoInstrumentationFactory()
goInstrumentationFactory := ebpf.NewGoInstrumentationFactory(client)
goDirector := ebpf.NewEbpfDirector(ctx, client, scheme, common.GoProgrammingLanguage, goInstrumentationFactory)
goDirectorKey := ebpf.DirectorKey{
Language: common.GoProgrammingLanguage,
Expand Down
30 changes: 23 additions & 7 deletions odiglet/pkg/ebpf/go.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"context"
"fmt"

"github.com/odigos-io/odigos/api/odigos/v1alpha1"
odigosv1 "github.com/odigos-io/odigos/api/odigos/v1alpha1"
"github.com/odigos-io/odigos/common"
"github.com/odigos-io/odigos/k8sutils/pkg/workload"
"github.com/odigos-io/odigos/odiglet/pkg/kube/utils"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/odigos-io/odigos/odiglet/pkg/env"
"github.com/odigos-io/odigos/odiglet/pkg/instrumentation/consts"
Expand All @@ -28,10 +29,14 @@ var _ goAutoConfig.Provider = (*ConfigProvider[goAutoConfig.InstrumentationConfi
// compile-time check that GoOtelEbpfSdk implements ConfigurableOtelEbpfSdk
var _ ConfigurableOtelEbpfSdk = (*GoOtelEbpfSdk)(nil)

type GoInstrumentationFactory struct{}
type GoInstrumentationFactory struct{
kubeclient client.Client
}

func NewGoInstrumentationFactory() InstrumentationFactory[*GoOtelEbpfSdk] {
return &GoInstrumentationFactory{}
func NewGoInstrumentationFactory(kubeclient client.Client) InstrumentationFactory[*GoOtelEbpfSdk] {
return &GoInstrumentationFactory{
kubeclient: kubeclient,
}
}

func (g *GoInstrumentationFactory) CreateEbpfInstrumentation(ctx context.Context, pid int, serviceName string, podWorkload *workload.PodWorkload, containerName string, podName string, loadedIndicator chan struct{}) (*GoOtelEbpfSdk, error) {
Expand All @@ -45,7 +50,18 @@ func (g *GoInstrumentationFactory) CreateEbpfInstrumentation(ctx context.Context
return nil, err
}

cp := NewConfigProvider(goAutoConfig.InstrumentationConfig{})
// Fetch initial config based on the InstrumentationConfig CR
instrumentationConfig := &odigosv1.InstrumentationConfig{}
initialConfig := goAutoConfig.InstrumentationConfig{}
instrumentationConfigKey := client.ObjectKey{
Namespace: podWorkload.Namespace,
Name: workload.CalculateWorkloadRuntimeObjectName(podWorkload.Name, podWorkload.Kind),
}
if err := g.kubeclient.Get(ctx, instrumentationConfigKey, instrumentationConfig); err == nil {
initialConfig = convertToGoInstrumentationConfig(instrumentationConfig)
}

cp := NewConfigProvider(initialConfig)

inst, err := auto.NewInstrumentation(
ctx,
Expand Down Expand Up @@ -74,11 +90,11 @@ func (g *GoOtelEbpfSdk) Close(ctx context.Context) error {
return g.inst.Close()
}

func (g *GoOtelEbpfSdk) ApplyConfig(ctx context.Context, instConfig *v1alpha1.InstrumentationConfig) error {
func (g *GoOtelEbpfSdk) ApplyConfig(ctx context.Context, instConfig *odigosv1.InstrumentationConfig) error {
return g.cp.SendConfig(ctx, convertToGoInstrumentationConfig(instConfig))
}

func convertToGoInstrumentationConfig(instConfig *v1alpha1.InstrumentationConfig) goAutoConfig.InstrumentationConfig {
func convertToGoInstrumentationConfig(instConfig *odigosv1.InstrumentationConfig) goAutoConfig.InstrumentationConfig {
ic := goAutoConfig.InstrumentationConfig{}
ic.InstrumentationLibraryConfigs = make(map[goAutoConfig.InstrumentationLibraryID]goAutoConfig.InstrumentationLibrary)
for _, sdkConfig := range instConfig.Spec.SdkConfigs {
Expand Down
Loading