Skip to content

Commit

Permalink
Report on other agent (#1718)
Browse files Browse the repository at this point in the history
Co-authored-by: Tamir David <tamirdavid@Tamirs-MacBook-Pro.local>
  • Loading branch information
tamirdavid1 and Tamir David authored Nov 10, 2024
1 parent b1cceb7 commit e92eb16
Show file tree
Hide file tree
Showing 13 changed files with 189 additions and 33 deletions.
5 changes: 5 additions & 0 deletions api/config/crd/bases/odigos.io_instrumentationconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,11 @@ spec:
- unknown
- ignored
type: string
otherAgent:
properties:
name:
type: string
type: object
runtimeVersion:
type: string
required:
Expand Down
5 changes: 5 additions & 0 deletions api/config/crd/bases/odigos.io_instrumentedapplications.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ spec:
- unknown
- ignored
type: string
otherAgent:
properties:
name:
type: string
type: object
runtimeVersion:
type: string
required:
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions api/generated/odigos/applyconfiguration/utils.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions api/odigos/v1alpha1/instrumentedapplication_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,17 @@ type EnvVar struct {
Value string `json:"value"`
}

type OtherAgent struct {
Name string `json:"name,omitempty"`
}

// +kubebuilder:object:generate=true
type RuntimeDetailsByContainer struct {
ContainerName string `json:"containerName"`
Language common.ProgrammingLanguage `json:"language"`
RuntimeVersion string `json:"runtimeVersion,omitempty"`
EnvVars []EnvVar `json:"envVars,omitempty"`
OtherAgent *OtherAgent `json:"otherAgent,omitempty"`
}

// +kubebuilder:object:generate=true
Expand Down
20 changes: 20 additions & 0 deletions api/odigos/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions frontend/endpoints/sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ import (
)

type SourceLanguage struct {
ContainerName string `json:"container_name"`
Language string `json:"language"`
RuntimeVersion string `json:"runtime_version,omitempty"`
ContainerName string `json:"container_name"`
Language string `json:"language"`
RuntimeVersion string `json:"runtime_version,omitempty"`
OtherAgent *v1alpha1.OtherAgent `json:"other_agent,omitempty"`
}

type InstrumentedApplicationDetails struct {
Expand Down Expand Up @@ -393,11 +394,14 @@ func k8sInstrumentedAppToThinSource(app *v1alpha1.InstrumentedApplication) ThinS
}

for _, language := range app.Spec.RuntimeDetails {
source.IaDetails.Languages = append(source.IaDetails.Languages, SourceLanguage{
sourceLanguage := SourceLanguage{
ContainerName: language.ContainerName,
Language: string(language.Language),
RuntimeVersion: language.RuntimeVersion,
})
OtherAgent: language.OtherAgent,
}

source.IaDetails.Languages = append(source.IaDetails.Languages, sourceLanguage)
}
return source
}
Expand Down
27 changes: 18 additions & 9 deletions instrumentor/controllers/instrumentationdevice/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,15 @@ func isDataCollectionReady(ctx context.Context, c client.Client) bool {
return nodeCollectorsGroup.Status.Ready
}

func addInstrumentationDeviceToWorkload(ctx context.Context, kubeClient client.Client, runtimeDetails *odigosv1.InstrumentedApplication) error {
func addInstrumentationDeviceToWorkload(ctx context.Context, kubeClient client.Client, runtimeDetails *odigosv1.InstrumentedApplication) (error, bool) {

// devicePartiallyApplied is used to indicate that the instrumentation device was partially applied for some of the containers.
devicePartiallyApplied := false

logger := log.FromContext(ctx)
obj, err := getWorkloadObject(ctx, kubeClient, runtimeDetails)
if err != nil {
return err
return err, false
}

workload := workload.PodWorkload{
Expand All @@ -92,7 +95,7 @@ func addInstrumentationDeviceToWorkload(ctx context.Context, kubeClient client.C
instrumentationRules := odigosv1.InstrumentationRuleList{}
err = kubeClient.List(ctx, &instrumentationRules)
if err != nil {
return err
return err, false
}

// default otel sdk map according to Odigos tier
Expand All @@ -119,17 +122,17 @@ func addInstrumentationDeviceToWorkload(ctx context.Context, kubeClient client.C
}

result, err := controllerutil.CreateOrPatch(ctx, kubeClient, obj, func() error {

podSpec, err := getPodSpecFromObject(obj)
if err != nil {
return err
}

err, deviceApplied := instrumentation.ApplyInstrumentationDevicesToPodTemplate(podSpec, runtimeDetails, otelSdkToUse, obj)
err, deviceApplied, tempDevicePartiallyApplied := instrumentation.ApplyInstrumentationDevicesToPodTemplate(podSpec, runtimeDetails, otelSdkToUse, obj, logger)
if err != nil {
return err
}

devicePartiallyApplied = tempDevicePartiallyApplied
// If instrumentation device is applied successfully, add odigos.io/inject-instrumentation label to enable the webhook
if deviceApplied {
instrumentation.SetInjectInstrumentationLabel(podSpec)
Expand All @@ -139,15 +142,15 @@ func addInstrumentationDeviceToWorkload(ctx context.Context, kubeClient client.C
})

if err != nil {
return err
return err, false
}

modified := result != controllerutil.OperationResultNone
if modified {
logger.V(0).Info("added instrumentation device to workload", "name", obj.GetName(), "namespace", obj.GetNamespace())
}

return nil
return nil, devicePartiallyApplied
}

func removeInstrumentationDeviceFromWorkload(ctx context.Context, kubeClient client.Client, namespace string, workloadKind workload.WorkloadKind, workloadName string, uninstrumentReason ApplyInstrumentationDeviceReason) error {
Expand Down Expand Up @@ -275,9 +278,15 @@ func reconcileSingleWorkload(ctx context.Context, kubeClient client.Client, inst
return nil
}

err = addInstrumentationDeviceToWorkload(ctx, kubeClient, instrumentedApplication)
err, devicePartiallyApplied := addInstrumentationDeviceToWorkload(ctx, kubeClient, instrumentedApplication)
if err == nil {
conditions.UpdateStatusConditions(ctx, kubeClient, instrumentedApplication, &instrumentedApplication.Status.Conditions, metav1.ConditionTrue, appliedInstrumentationDeviceType, "InstrumentationDeviceApplied", "Instrumentation device applied successfully")
var successMessage string
if devicePartiallyApplied {
successMessage = "Instrumentation device partially applied"
} else {
successMessage = "Instrumentation device applied successfully"
}
conditions.UpdateStatusConditions(ctx, kubeClient, instrumentedApplication, &instrumentedApplication.Status.Conditions, metav1.ConditionTrue, appliedInstrumentationDeviceType, "InstrumentationDeviceApplied", successMessage)
} else {
conditions.UpdateStatusConditions(ctx, kubeClient, instrumentedApplication, &instrumentedApplication.Status.Conditions, metav1.ConditionFalse, appliedInstrumentationDeviceType, string(ApplyInstrumentationDeviceReasonErrApplying), err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion instrumentor/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/odigos-io/odigos/instrumentor
go 1.22.0

require (
github.com/go-logr/logr v1.4.2
github.com/google/uuid v1.6.0
github.com/hashicorp/go-version v1.7.0
github.com/odigos-io/odigos/api v0.0.0
Expand All @@ -22,7 +23,6 @@ require (
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/fatih/color v1.10.0 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/goccy/go-yaml v1.11.3 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
Expand Down
Loading

0 comments on commit e92eb16

Please sign in to comment.