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

Better handling of sidecars #1536

Merged
merged 6 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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 common/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ var (

var (
SystemNamespaces = []string{DefaultOdigosNamespace, "kube-system", "local-path-storage", "istio-system", "linkerd", "kube-node-lease"}
IgnoredContainers = []string{"istio-proxy"}
IgnoredContainers = []string{"istio-proxy", "vault-agent", "filebeat", "linkerd-proxy", "fluentd", "akeyless-init"}
)
5 changes: 5 additions & 0 deletions helm/odigos/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ ignoredNamespaces:

ignoredContainers:
- istio-proxy
- vault-agent
- filebeat
- linkerd-proxy
- fluentd
- akeyless-init

collectorGateway:
# the memory request for the cluster gateway collector deployment.
Expand Down
30 changes: 19 additions & 11 deletions odiglet/pkg/kube/instrumentation_ebpf/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"errors"

"github.com/odigos-io/odigos/common"

odigosv1 "github.com/odigos-io/odigos/api/odigos/v1alpha1"
odgiosK8s "github.com/odigos-io/odigos/k8sutils/pkg/container"
"github.com/odigos-io/odigos/k8sutils/pkg/workload"
Expand All @@ -26,10 +28,14 @@ func instrumentPodWithEbpf(ctx context.Context, pod *corev1.Pod, directors ebpf.
logger := log.FromContext(ctx)
podUid := string(pod.UID)
instrumentedEbpf := false
ignoredContainers := getIgnoredContainers(runtimeDetails)

for _, container := range pod.Spec.Containers {
language, sdk, found := odgiosK8s.GetLanguageAndOtelSdk(container)
if _, ignored := ignoredContainers[container.Name]; ignored {
continue
}

language, sdk, found := odgiosK8s.GetLanguageAndOtelSdk(container)
if !found {
continue
}
Expand All @@ -39,15 +45,7 @@ func instrumentPodWithEbpf(ctx context.Context, pod *corev1.Pod, directors ebpf.
continue
}

// if we instrument multiple containers in the same pod,
// we want to give each one a unique service.name attribute to differentiate them
containerName := container.Name
serviceName := containerName
if len(runtimeDetails.Spec.RuntimeDetails) == 1 {
serviceName = podWorkload.Name
}

details, err := process.FindAllInContainer(podUid, containerName)
details, err := process.FindAllInContainer(podUid, container.Name)
if err != nil {
logger.Error(err, "error finding processes")
return err, instrumentedEbpf
Expand All @@ -65,7 +63,7 @@ func instrumentPodWithEbpf(ctx context.Context, pod *corev1.Pod, directors ebpf.
continue
}

err = director.Instrument(ctx, d.ProcessID, podDetails, podWorkload, serviceName, containerName)
err = director.Instrument(ctx, d.ProcessID, podDetails, podWorkload, podWorkload.Name, container.Name)

if err != nil {
logger.Error(err, "error initiating process instrumentation", "pid", d.ProcessID)
Expand All @@ -82,3 +80,13 @@ func instrumentPodWithEbpf(ctx context.Context, pod *corev1.Pod, directors ebpf.
}
return nil, instrumentedEbpf
}

func getIgnoredContainers(instApp *odigosv1.InstrumentedApplication) map[string]struct{} {
ignoredContainers := make(map[string]struct{})
for _, container := range instApp.Spec.RuntimeDetails {
if container.Language == common.IgnoredProgrammingLanguage {
ignoredContainers[container.ContainerName] = struct{}{}
}
}
return ignoredContainers
}
11 changes: 1 addition & 10 deletions opampserver/pkg/deviceid/k8sattributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ func (k *K8sPodInfoResolver) getWorkloadObject(ctx context.Context, name string,

// Resolves the service name, with the following priority:
// 1. If the user added reported name annotation to the workload, use it
// 2. If the pod has multiple containers, use the container name as service name
// 3. Otherwise, use the workload name as service name
// 2. Otherwise, use the workload name as service name
//
// if one of the above conditions has err, it will be logged and the next condition will be checked
func (k *K8sPodInfoResolver) ResolveServiceName(ctx context.Context, workloadName string, workloadKind string, containerDetails *ContainerDetails) string {
Expand All @@ -78,14 +77,6 @@ func (k *K8sPodInfoResolver) ResolveServiceName(ctx context.Context, workloadNam
return serviceName
}

if containerDetails.ContainersInPod > 1 {
// multiple containers in pod, use container name as service name
// might want to revisit in the future:
// should we include the workload name?
// should we use same service name for multiple containers if configured via annotation?
return containerDetails.ContainerName
}

return workloadName
}

Expand Down
Loading