Skip to content

Commit

Permalink
continue removing device id
Browse files Browse the repository at this point in the history
  • Loading branch information
edeNFed committed Jan 2, 2025
1 parent 098a745 commit 32bcd16
Show file tree
Hide file tree
Showing 15 changed files with 67 additions and 143 deletions.
2 changes: 1 addition & 1 deletion instrumentation/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ require (
github.com/go-logr/logr v1.4.2
github.com/odigos-io/odigos/common v0.0.0
github.com/odigos-io/runtime-detector v0.0.5
go.opentelemetry.io/otel v1.33.0
golang.org/x/sync v0.10.0
)

require (
github.com/cilium/ebpf v0.16.0 // indirect
github.com/hashicorp/go-version v1.7.0 // indirect
go.opentelemetry.io/otel v1.33.0 // indirect
go.opentelemetry.io/otel/trace v1.33.0 // indirect
golang.org/x/exp v0.0.0-20230224173230-c95f2b4c22f2 // indirect
golang.org/x/sys v0.20.0 // indirect
Expand Down
25 changes: 17 additions & 8 deletions instrumentor/controllers/webhook/env_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ var (
)

type envVarModification struct {
Value string
Action modificationFunc
Value string
ValueFrom *corev1.EnvVarSource
Action modificationFunc
}

// modifyEnvVars modifies the environment variables of a container based on the modifications map.
Expand All @@ -34,12 +35,16 @@ func (p *PodsWebhook) modifyEnvVars(original []corev1.EnvVar, modifications map[
var result []corev1.EnvVar
for _, envVar := range original {
if modification, ok := modifications[envVar.Name]; ok {
val := modification.Value
if modification.Action != nil {
val = modification.Action(envVar.Value, modification.Value)
}
if modification.ValueFrom != nil {
result = append(result, corev1.EnvVar{Name: envVar.Name, ValueFrom: modification.ValueFrom})
} else {
val := modification.Value
if modification.Action != nil {
val = modification.Action(envVar.Value, modification.Value)
}

result = append(result, corev1.EnvVar{Name: envVar.Name, Value: val})
result = append(result, corev1.EnvVar{Name: envVar.Name, Value: val})
}
delete(remainingModifications, envVar.Name)
} else {
result = append(result, envVar)
Expand All @@ -48,7 +53,11 @@ func (p *PodsWebhook) modifyEnvVars(original []corev1.EnvVar, modifications map[

for k := range remainingModifications {
details := modifications[k]
result = append(result, corev1.EnvVar{Name: k, Value: details.Value})
if details.ValueFrom != nil {
result = append(result, corev1.EnvVar{Name: k, ValueFrom: details.ValueFrom})
} else {
result = append(result, corev1.EnvVar{Name: k, Value: details.Value})
}
}

return result
Expand Down
25 changes: 25 additions & 0 deletions instrumentor/controllers/webhook/env_vars_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,31 @@ func TestModifyEnvVars(t *testing.T) {
{Name: "VAR2", Value: "value2"},
},
},
{
name: "Add value with ValueFrom",
original: []corev1.EnvVar{
{Name: "VAR1", Value: "value1"},
},
modifications: map[string]envVarModification{
"VAR2": {ValueFrom: &corev1.EnvVarSource{FieldRef: &corev1.ObjectFieldSelector{FieldPath: "metadata.name"}}, Action: Upsert},
},
expected: []corev1.EnvVar{
{Name: "VAR1", Value: "value1"},
{Name: "VAR2", ValueFrom: &corev1.EnvVarSource{FieldRef: &corev1.ObjectFieldSelector{FieldPath: "metadata.name"}}},
},
},
{
name: "Modify existing key with ValueFrom",
original: []corev1.EnvVar{
{Name: "VAR1", Value: "value1"},
},
modifications: map[string]envVarModification{
"VAR1": {ValueFrom: &corev1.EnvVarSource{FieldRef: &corev1.ObjectFieldSelector{FieldPath: "metadata.name"}}, Action: Upsert},
},
expected: []corev1.EnvVar{
{Name: "VAR1", ValueFrom: &corev1.EnvVarSource{FieldRef: &corev1.ObjectFieldSelector{FieldPath: "metadata.name"}}},
},
},
}

for _, tt := range tests {
Expand Down
14 changes: 11 additions & 3 deletions instrumentor/controllers/webhook/pods_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,17 @@ func (p *PodsWebhook) getServiceNameForEnv(ctx context.Context, pod *corev1.Pod)
func (p *PodsWebhook) injectOdigosEnvVars(pod *corev1.Pod, podWorkload *workload.PodWorkload, serviceName *string) {
for i := range pod.Spec.Containers {
container := &pod.Spec.Containers[i]

// Pod name is not available yet in webhook so use downward API to get it
podName := fmt.Sprintf("$(%s)", k8sconsts.OdigosEnvVarPodName)

identifier := &resourceattributes.ContainerIdentifier{
PodName: pod.Name,
PodName: podName,
Namespace: pod.Namespace,
ContainerName: container.Name,
}

// Add container identifier as seperate env vars:
// Add container identifier as separate env vars:
// This is used by process discovery to identify the container
// Also, used by OpAMP clients to send it back to the server on the first heartbeat
// TODO(edenfed): these values will be duplicated between the resource attributes and the env vars
Expand All @@ -88,7 +92,11 @@ func (p *PodsWebhook) injectOdigosEnvVars(pod *corev1.Pod, podWorkload *workload
Action: Upsert,
},
k8sconsts.OdigosEnvVarPodName: {
Value: identifier.PodName,
ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
FieldPath: "metadata.name",
},
},
Action: Upsert,
},
k8sconsts.OdigosEnvVarContainerName: {
Expand Down
2 changes: 1 addition & 1 deletion odiglet/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ require (
github.com/odigos-io/runtime-detector v0.0.5
github.com/stretchr/testify v1.10.0
go.opentelemetry.io/auto v0.19.0-alpha
go.opentelemetry.io/otel v1.33.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.33.0
go.uber.org/zap v1.27.0
golang.org/x/sync v0.10.0
Expand Down Expand Up @@ -73,6 +72,7 @@ require (
go.opentelemetry.io/collector/pdata v1.21.0 // indirect
go.opentelemetry.io/contrib/bridges/prometheus v0.57.0 // indirect
go.opentelemetry.io/contrib/exporters/autoexport v0.57.0 // indirect
go.opentelemetry.io/otel v1.33.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.8.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.8.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.32.0 // indirect
Expand Down
91 changes: 0 additions & 91 deletions odiglet/pkg/instrumentation/devices/kubelet.go

This file was deleted.

6 changes: 1 addition & 5 deletions odiglet/pkg/instrumentation/instrumentlang/dotnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ const (
profilerId = "{918728DD-259F-4A6A-AC2B-B85E1B658318}"
profilerPathEnv = "CORECLR_PROFILER_PATH"
profilerPath = "/var/odigos/dotnet/linux-glibc-%s/OpenTelemetry.AutoInstrumentation.Native.so"
serviceNameEnv = "OTEL_SERVICE_NAME"
collectorUrlEnv = "OTEL_EXPORTER_OTLP_ENDPOINT"
tracerHomeEnv = "OTEL_DOTNET_AUTO_HOME"
exportTypeEnv = "OTEL_TRACES_EXPORTER"
tracerHome = "/var/odigos/dotnet"
resourceAttrEnv = "OTEL_RESOURCE_ATTRIBUTES"
startupHookEnv = "DOTNET_STARTUP_HOOKS"
startupHook = "/var/odigos/dotnet/net/OpenTelemetry.AutoInstrumentation.StartupHook.dll"
additonalDepsEnv = "DOTNET_ADDITIONAL_DEPS"
Expand All @@ -30,17 +28,15 @@ const (
sharedStore = "/var/odigos/dotnet/store"
)

func DotNet(deviceId string, uniqueDestinationSignals map[common.ObservabilitySignal]struct{}) *v1beta1.ContainerAllocateResponse {
func DotNet(uniqueDestinationSignals map[common.ObservabilitySignal]struct{}) *v1beta1.ContainerAllocateResponse {
return &v1beta1.ContainerAllocateResponse{
Envs: map[string]string{
enableProfilingEnvVar: "1",
profilerEndVar: profilerId,
profilerPathEnv: fmt.Sprintf(profilerPath, getArch()),
tracerHomeEnv: tracerHome,
collectorUrlEnv: fmt.Sprintf("http://%s:%d", env.Current.NodeIP, consts.OTLPHttpPort),
serviceNameEnv: deviceId,
exportTypeEnv: "otlp",
resourceAttrEnv: "odigos.device=dotnet",
startupHookEnv: startupHook,
additonalDepsEnv: additonalDeps,
sharedStoreEnv: sharedStore,
Expand Down
2 changes: 1 addition & 1 deletion odiglet/pkg/instrumentation/instrumentlang/golang.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import (

// Go is a dummy device available only on eBPF nodes. This will help us schedule applications that needs eBPF
// instrumentation on eBPF nodes only.
func Go(deviceId string, uniqueDestinationSignals map[common.ObservabilitySignal]struct{}) *v1beta1.ContainerAllocateResponse {
func Go(uniqueDestinationSignals map[common.ObservabilitySignal]struct{}) *v1beta1.ContainerAllocateResponse {
return &v1beta1.ContainerAllocateResponse{}
}
5 changes: 1 addition & 4 deletions odiglet/pkg/instrumentation/instrumentlang/java.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
)

const (
otelResourceAttributesEnvVar = "OTEL_RESOURCE_ATTRIBUTES"
otelResourceAttrPattern = "service.name=%s,odigos.device=java"
javaToolOptionsEnvVar = "JAVA_TOOL_OPTIONS"
javaOptsEnvVar = "JAVA_OPTS"
javaOtlpEndpointEnvVar = "OTEL_EXPORTER_OTLP_ENDPOINT"
Expand All @@ -23,7 +21,7 @@ const (
javaOtelTracesSamplerEnvVar = "OTEL_TRACES_SAMPLER"
)

func Java(deviceId string, uniqueDestinationSignals map[common.ObservabilitySignal]struct{}) *v1beta1.ContainerAllocateResponse {
func Java(uniqueDestinationSignals map[common.ObservabilitySignal]struct{}) *v1beta1.ContainerAllocateResponse {
otlpEndpoint := fmt.Sprintf("http://%s:%d", env.Current.NodeIP, consts.OTLPPort)
javaOptsVal, _ := envOverwrite.ValToAppend(javaOptsEnvVar, common.OtelSdkNativeCommunity)
javaToolOptionsVal, _ := envOverwrite.ValToAppend(javaToolOptionsEnvVar, common.OtelSdkNativeCommunity)
Expand All @@ -45,7 +43,6 @@ func Java(deviceId string, uniqueDestinationSignals map[common.ObservabilitySign

return &v1beta1.ContainerAllocateResponse{
Envs: map[string]string{
otelResourceAttributesEnvVar: fmt.Sprintf(otelResourceAttrPattern, deviceId),
javaToolOptionsEnvVar: javaToolOptionsVal,
javaOptsEnvVar: javaOptsVal,
javaOtlpEndpointEnvVar: otlpEndpoint,
Expand Down
2 changes: 1 addition & 1 deletion odiglet/pkg/instrumentation/instrumentlang/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import (
"k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
)

func Nginx(deviceId string, uniqueDestinationSignals map[common.ObservabilitySignal]struct{}) *v1beta1.ContainerAllocateResponse {
func Nginx(uniqueDestinationSignals map[common.ObservabilitySignal]struct{}) *v1beta1.ContainerAllocateResponse {
return &v1beta1.ContainerAllocateResponse{}
}
6 changes: 2 additions & 4 deletions odiglet/pkg/instrumentation/instrumentlang/nodejs.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,22 @@ import (
const (
nodeMountPath = "/var/odigos/nodejs"
nodeEnvEndpoint = "OTEL_EXPORTER_OTLP_ENDPOINT"
nodeEnvServiceName = "OTEL_SERVICE_NAME"
nodeEnvNodeOptions = "NODE_OPTIONS"
nodeOdigosOpampServer = "ODIGOS_OPAMP_SERVER_HOST"
nodeOdigosDeviceId = "ODIGOS_INSTRUMENTATION_DEVICE_ID"
)

func NodeJS(deviceId string, uniqueDestinationSignals map[common.ObservabilitySignal]struct{}) *v1beta1.ContainerAllocateResponse {
func NodeJS(uniqueDestinationSignals map[common.ObservabilitySignal]struct{}) *v1beta1.ContainerAllocateResponse {
otlpEndpoint := fmt.Sprintf("http://%s:%d", env.Current.NodeIP, consts.OTLPHttpPort)
nodeOptionsVal, _ := envOverwrite.ValToAppend(nodeEnvNodeOptions, common.OtelSdkNativeCommunity)
opampServerHost := fmt.Sprintf("%s:%d", env.Current.NodeIP, consts.OpAMPPort)

return &v1beta1.ContainerAllocateResponse{
Envs: map[string]string{
nodeEnvEndpoint: otlpEndpoint,
nodeEnvServiceName: deviceId, // temporary set the device id as well, so if opamp fails we can fallback to resolve k8s attributes in the collector
nodeEnvNodeOptions: nodeOptionsVal,
nodeOdigosOpampServer: opampServerHost,
nodeOdigosDeviceId: deviceId,
nodeOdigosDeviceId: "123123123", //TODO(edenfed): this is not needed anymore, delete it from nodejs instrumentation and then delete from here
},
Mounts: []*v1beta1.Mount{
{
Expand Down
4 changes: 2 additions & 2 deletions odiglet/pkg/instrumentation/instrumentlang/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const (
pythonOdigosDeviceId = "ODIGOS_INSTRUMENTATION_DEVICE_ID"
)

func Python(deviceId string, uniqueDestinationSignals map[common.ObservabilitySignal]struct{}) *v1beta1.ContainerAllocateResponse {
func Python(uniqueDestinationSignals map[common.ObservabilitySignal]struct{}) *v1beta1.ContainerAllocateResponse {
otlpEndpoint := fmt.Sprintf("http://%s:%d", env.Current.NodeIP, consts.OTLPHttpPort)
pythonpathVal, _ := envOverwrite.ValToAppend(envPythonPath, common.OtelSdkNativeCommunity)
opampServerHost := fmt.Sprintf("%s:%d", env.Current.NodeIP, consts.OpAMPPort)
Expand All @@ -43,7 +43,7 @@ func Python(deviceId string, uniqueDestinationSignals map[common.ObservabilitySi

return &v1beta1.ContainerAllocateResponse{
Envs: map[string]string{
pythonOdigosDeviceId: deviceId,
pythonOdigosDeviceId: "123123123", //TODO(edenfed): this is not needed anymore, delete it from python instrumentation and then delete from here
pythonOdigosOpampServer: opampServerHost,
envLogCorrelation: "true",
envPythonPath: pythonpathVal,
Expand Down
17 changes: 4 additions & 13 deletions odiglet/pkg/instrumentation/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
)

type LangSpecificFunc func(deviceId string, uniqueDestinationSignals map[common.ObservabilitySignal]struct{}) *v1beta1.ContainerAllocateResponse
type LangSpecificFunc func(uniqueDestinationSignals map[common.ObservabilitySignal]struct{}) *v1beta1.ContainerAllocateResponse

type plugin struct {
idsManager devices.DeviceManager
Expand All @@ -39,8 +39,8 @@ func NewPlugin(maxPods int64, lsf LangSpecificFunc, odigosKubeClient *odigosclie
}

func NewMuslPlugin(lang common.ProgrammingLanguage, maxPods int64, lsf LangSpecificFunc, odigosKubeClient *odigosclientset.Clientset) dpm.PluginInterface {
wrappedLsf := func(deviceId string, uniqueDestinationSignals map[common.ObservabilitySignal]struct{}) *v1beta1.ContainerAllocateResponse {
res := lsf(deviceId, uniqueDestinationSignals)
wrappedLsf := func(uniqueDestinationSignals map[common.ObservabilitySignal]struct{}) *v1beta1.ContainerAllocateResponse {
res := lsf(uniqueDestinationSignals)
libc.ModifyEnvVarsForMusl(lang, res.Envs)
return res
}
Expand Down Expand Up @@ -107,16 +107,7 @@ func (p *plugin) Allocate(ctx context.Context, request *v1beta1.AllocateRequest)
}
}

for _, req := range request.ContainerRequests {
if len(req.DevicesIDs) != 1 {
log.Logger.V(0).Info("got instrumentation device not equal to 1, skipping", "devices", req.DevicesIDs)
continue
}

deviceId := req.DevicesIDs[0]
res.ContainerResponses = append(res.ContainerResponses, p.LangSpecificFunc(deviceId, enabledSignals))
}

res.ContainerResponses = append(res.ContainerResponses, p.LangSpecificFunc(enabledSignals))
return res, nil
}

Expand Down
Loading

0 comments on commit 32bcd16

Please sign in to comment.