Skip to content

Commit

Permalink
fix: avoid log stacktrace when run alongside OtherAagent (#2117)
Browse files Browse the repository at this point in the history
  • Loading branch information
tamirdavid1 authored Jan 2, 2025
1 parent 56f3f13 commit 0bf1896
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

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

k8sutils "github.com/odigos-io/odigos/k8sutils/pkg/utils"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -71,6 +72,9 @@ func (r *CollectorsGroupReconciler) Reconcile(ctx context.Context, req ctrl.Requ
if apierrors.IsConflict(err) {
gotConflict = true
}
if errors.Is(err, k8sutils.OtherAgentRunError) {
continue
}
reconcileErr = errors.Join(reconcileErr, err)
}
}
Expand Down
3 changes: 1 addition & 2 deletions instrumentor/controllers/instrumentationdevice/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package instrumentationdevice
import (
"context"
"errors"
"fmt"

odigosv1 "github.com/odigos-io/odigos/api/odigos/v1alpha1"
"github.com/odigos-io/odigos/instrumentor/controllers/utils"
Expand Down Expand Up @@ -153,7 +152,7 @@ func addInstrumentationDeviceToWorkload(ctx context.Context, kubeClient client.C

// if non of the devices were applied due to the presence of another agent, return an error.
if deviceNotAppliedDueToPresenceOfAnotherAgent {
return fmt.Errorf("device not added to any container due to the presence of another agent"), false
return k8sutils.OtherAgentRunError, false
}

if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package instrumentationdevice

import (
"context"
"errors"

odigosv1 "github.com/odigos-io/odigos/api/odigos/v1alpha1"
k8sutils "github.com/odigos-io/odigos/k8sutils/pkg/utils"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
Expand All @@ -30,6 +32,8 @@ func (r *InstrumentationRuleReconciler) Reconcile(ctx context.Context, req ctrl.
if err != nil {
if apierrors.IsConflict(err) {
gotConflict = true
} else if errors.Is(err, k8sutils.OtherAgentRunError) {
continue
} else {
return ctrl.Result{}, err
}
Expand Down
5 changes: 5 additions & 0 deletions k8sutils/pkg/utils/other_agent.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package utils

import "errors"

var OtherAgentRunError = errors.New("device not added to any container due to the presence of another agent")
7 changes: 7 additions & 0 deletions k8sutils/pkg/utils/retryonconflict.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package utils

import (
nativeErrors "errors"

"k8s.io/apimachinery/pkg/api/errors"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)
Expand All @@ -20,6 +22,11 @@ func K8SUpdateErrorHandler(err error) (reconcile.Result, error) {
// For not found errors, ignore
return reconcile.Result{}, nil
}

if nativeErrors.Is(err, OtherAgentRunError) {
// For other agent run no need to log the stack trace
return reconcile.Result{}, nil
}
// For other errors, return as is (will log the stack trace)
return reconcile.Result{}, err
}

0 comments on commit 0bf1896

Please sign in to comment.