Skip to content

Commit

Permalink
feat: delete instrumentation instance if exit with healthy state (#2209)
Browse files Browse the repository at this point in the history
  • Loading branch information
tamirdavid1 authored Jan 13, 2025
1 parent 920ada0 commit d208952
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
4 changes: 2 additions & 2 deletions agents/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
index_url = None

# DEV - Local Uncomment to develop locally \/
# index_url = 'http://host.docker.internal:8080/packages/odigos_opentelemetry_python-0.1.1-py3-none-any.whl'
# index_url = 'http://host.docker.internal:8081/packages/odigos_opentelemetry_python-0.1.1-py3-none-any.whl'

install_requires = [
f"odigos-opentelemetry-python @ {index_url}" if index_url else "odigos-opentelemetry-python==1.0.24"
f"odigos-opentelemetry-python @ {index_url}" if index_url else "odigos-opentelemetry-python==1.0.25"
]

setup(
Expand Down
24 changes: 24 additions & 0 deletions k8sutils/pkg/instrumentation_instance/object.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package instrumentation_instance

import (
"context"

v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/odigos-io/odigos/api/odigos/v1alpha1"
)

func DeleteInstrumentationInstance(ctx context.Context, owner client.Object, containerName string, kubeClient client.Client, pid int) error {
instrumentationInstanceName := InstrumentationInstanceName(owner.GetName(), pid)
err := kubeClient.Delete(ctx, &v1alpha1.InstrumentationInstance{
ObjectMeta: v1.ObjectMeta{
Name: instrumentationInstanceName,
Namespace: owner.GetNamespace(),
},
})
if err != nil {
return client.IgnoreNotFound(err)
}
return nil
}
9 changes: 7 additions & 2 deletions opampserver/pkg/server/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,19 @@ func (c *ConnectionHandlers) UpdateInstrumentationInstanceStatus(ctx context.Con

isAgentDisconnect := message.AgentDisconnect != nil
hasHealth := message.Health != nil
// when agent disconnects, it need to report that it is unhealthy and disconnected
// When agent disconnects, it need to report that it's health and disconnected
// 1. In case disconnect with healthy status, we will delete the instrumentationInstnace CR
// 2. Otherwise, we will keep the CR in unhealthy state so it can be used for troubleshooting
if isAgentDisconnect {
if !hasHealth {
return fmt.Errorf("missing health in agent disconnect message")
}
// [1] - agent disconnects with healthy status, delete the instrumentation instance CR
if message.Health.Healthy {
return fmt.Errorf("agent disconnect message with healthy status")
c.logger.Info("Agent disconnected with healthy status, deleting instrumentation instance", "workloadNamespace", connectionInfo.Workload.Namespace, "workloadName", connectionInfo.Workload.Name, "workloadKind", connectionInfo.Workload.Kind)
return instrumentation_instance.DeleteInstrumentationInstance(ctx, connectionInfo.Pod, connectionInfo.ContainerName, c.kubeclient, int(connectionInfo.Pid))
}

if message.Health.LastError == "" {
return fmt.Errorf("missing last error in unhealthy message")
}
Expand Down

0 comments on commit d208952

Please sign in to comment.