-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: otel sdk instrumentation rule (#1499)
Add a instrumentation rule which allows to configure the SDKs to use. This replaces the need to use `odigos-config` which must be applied as a whole which is inconvenient and error prone. By using the new instrumentation rule, one can specify the usecase in a separate manifest, and gain more flexibility on how it is applied (workloads list, languages, multiple levels, etc)
- Loading branch information
Showing
14 changed files
with
259 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
api/generated/odigos/applyconfiguration/odigos/v1alpha1/instrumentationrulespec.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package instrumentationrules | ||
|
||
import "github.com/odigos-io/odigos/common" | ||
|
||
// +kubebuilder:object:generate=true | ||
// +kubebuilder:deepcopy-gen=true | ||
type OtelSdks struct { | ||
OtelSdkByLanguage map[common.ProgrammingLanguage]common.OtelSdk `json:"otelSdkByLanguage"` | ||
} |
26 changes: 25 additions & 1 deletion
26
api/odigos/v1alpha1/instrumentationrules/zz_generated.deepcopy.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
cli/cmd/resources/profiles/java-native-instrumentations.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
apiVersion: odigos.io/v1alpha1 | ||
kind: InstrumentationRule | ||
metadata: | ||
name: java-native-instrumentations | ||
spec: | ||
ruleName: "java native instrumentations" | ||
notes: "Auto generated rule from java-native-instrumentations profile. Do not edit." | ||
otelSdks: | ||
otelSdkByLanguage: | ||
java: | ||
sdkTier: "enterprise" | ||
sdkType: "native" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
instrumentor/controllers/instrumentationdevice/instrumentationrule_controller.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package instrumentationdevice | ||
|
||
import ( | ||
"context" | ||
|
||
odigosv1 "github.com/odigos-io/odigos/api/odigos/v1alpha1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/log" | ||
) | ||
|
||
type InstrumentationRuleReconciler struct { | ||
client.Client | ||
Scheme *runtime.Scheme | ||
} | ||
|
||
func (r *InstrumentationRuleReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { | ||
|
||
var instApps odigosv1.InstrumentedApplicationList | ||
if err := r.List(ctx, &instApps); err != nil { | ||
return ctrl.Result{}, err | ||
} | ||
isNodeCollectorReady := isDataCollectionReady(ctx, r.Client) | ||
|
||
for _, runtimeDetails := range instApps.Items { | ||
err := reconcileSingleWorkload(ctx, r.Client, &runtimeDetails, isNodeCollectorReady) | ||
if err != nil { | ||
return ctrl.Result{}, err | ||
} | ||
} | ||
|
||
logger := log.FromContext(ctx) | ||
logger.V(0).Info("InstrumentationRule changed, recalculating instrumentation device for potential changes of otel sdks") | ||
|
||
return ctrl.Result{}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package utils | ||
|
||
import ( | ||
odigosv1alpha1 "github.com/odigos-io/odigos/api/odigos/v1alpha1" | ||
"github.com/odigos-io/odigos/k8sutils/pkg/workload" | ||
) | ||
|
||
// naive implementation, can be optimized. | ||
// assumption is that the list of workloads is small | ||
func IsWorkloadParticipatingInRule(workload workload.PodWorkload, rule *odigosv1alpha1.InstrumentationRule) bool { | ||
// nil means all workloads are participating | ||
if rule.Spec.Workloads == nil { | ||
return true | ||
} | ||
for _, allowedWorkload := range *rule.Spec.Workloads { | ||
if allowedWorkload == workload { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
Oops, something went wrong.