Skip to content

Commit

Permalink
Use instrumentation config for runtime details (#2115)
Browse files Browse the repository at this point in the history
- Add conditions to `instrumentationConfig` status.
- Update the relevant conversion in UI to handle this change.
- Modify the controllers under `instrumentor/instrumentationdevice` to
rely on instrumnentation config, This means that when we add our device
as a resource we'll look at the instrumentationConfig to decide.
- Remove `envoverwriter_test` as it becomes un-relevant and conflicts
with these changes.
- Update `workload-lifecycle` chainsaw assertions to be based on
`instrumentationConfig`.
- Remove the `language-change` deployment from the `workload-lifecycle`
test. This is done because a) The test requires the restart of the
`instrumentor` which is not the desired behavior and b) The
instrumentationConfig is currently enforced to only set the runtime
details once, hence we currently don't support this use case.
- Remove instrumented Application from describe.
  • Loading branch information
RonFed authored Jan 4, 2025
1 parent 0bf1896 commit 52ee331
Show file tree
Hide file tree
Showing 41 changed files with 484 additions and 2,057 deletions.
58 changes: 58 additions & 0 deletions api/config/crd/bases/odigos.io_instrumentationconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,64 @@ spec:
type: object
status:
properties:
conditions:
description: Represents the observations of a InstrumentationConfig's
current state.
items:
description: Condition contains details for one aspect of the current
state of this API Resource.
properties:
lastTransitionTime:
description: |-
lastTransitionTime is the last time the condition transitioned from one status to another.
This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
format: date-time
type: string
message:
description: |-
message is a human readable message indicating details about the transition.
This may be an empty string.
maxLength: 32768
type: string
observedGeneration:
description: |-
observedGeneration represents the .metadata.generation that the condition was set based upon.
For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
with respect to the current state of the instance.
format: int64
minimum: 0
type: integer
reason:
description: |-
reason contains a programmatic identifier indicating the reason for the condition's last transition.
Producers of specific condition types may define expected values and meanings for this field,
and whether the values are considered a guaranteed API.
The value should be a CamelCase string.
This field may not be empty.
maxLength: 1024
minLength: 1
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
type: string
status:
description: status of the condition, one of True, False, Unknown.
enum:
- "True"
- "False"
- Unknown
type: string
type:
description: type of condition in CamelCase or in foo.example.com/CamelCase.
maxLength: 316
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
type: string
required:
- lastTransitionTime
- message
- reason
- status
- type
type: object
type: array
runtimeDetailsByContainer:
description: Capture Runtime Details for the workloads that this CR
applies to.
Expand Down

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

3 changes: 3 additions & 0 deletions api/odigos/v1alpha1/instrumentationconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ type RuntimeDetailsByContainer struct {
type InstrumentationConfigStatus struct {
// Capture Runtime Details for the workloads that this CR applies to.
RuntimeDetailsByContainer []RuntimeDetailsByContainer `json:"runtimeDetailsByContainer,omitempty"`

// Represents the observations of a InstrumentationConfig's current state.
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" protobuf:"bytes,1,rep,name=conditions"`
}

// Config for the OpenTelemeetry SDKs that should be applied to a workload.
Expand Down
7 changes: 7 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.

2 changes: 1 addition & 1 deletion cli/cmd/resources/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ In this doc, we'll keep track of the permissions requested across different reso
| Instrumentor | "" | nodes, namespaces | get, list, watch | Tracks runtime detection and resource labels for instrumentation. |
| Instrumentor | apps | daemonsets, deployments, statefulsets | get, list, watch, update, patch | Adjusts pod specifications for instrumentation. |
| Instrumentor | odigos.io | instrumentedapplications | delete, get, list, watch | Reacts to runtime detections in workloads. |
| Instrumentor | odigos.io | instrumentedapplications/status | get, patch, update | Updates application statuses post-injection. |
| Instrumentor | odigos.io | instrumentationconfigs/status | get, patch, update | Updates application statuses post-injection. |
| Instrumentor | odigos.io | instrumentationconfigs | create, delete, get, list, patch, update, watch | Manages instrumentation configurations. |
| Scheduler | odigos.io | instrumentationconfigs | get, list, watch | Monitors changes in instrumentation configurations for scheduling updates. |
| Autoscaler | odigos.io | instrumentationconfigs | get, list, watch | Reads instrumentation configurations to populate the `data-collector` configmaps. |
Expand Down
9 changes: 2 additions & 7 deletions cli/cmd/resources/instrumentor.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,21 +181,16 @@ func NewInstrumentorClusterRole() *rbacv1.ClusterRole {
Resources: []string{"instrumentedapplications"},
Verbs: []string{"delete", "get", "list", "watch"},
},
{ // Update the status of the instrumented applications after device injection
{ // Update the status of the instrumentation configs after device injection
APIGroups: []string{"odigos.io"},
Resources: []string{"instrumentedapplications/status"},
Resources: []string{"instrumentationconfigs/status"},
Verbs: []string{"get", "patch", "update"},
},
{
APIGroups: []string{"odigos.io"},
Resources: []string{"instrumentationconfigs"},
Verbs: []string{"create", "delete", "get", "list", "patch", "update", "watch"},
},
{
APIGroups: []string{"odigos.io"},
Resources: []string{"instrumentationconfigs/status"},
Verbs: []string{"update"},
},
},
}
}
Expand Down
44 changes: 12 additions & 32 deletions frontend/endpoints/sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ type SourceLanguage struct {
}

type InstrumentedApplicationDetails struct {
Languages []SourceLanguage `json:"languages,omitempty"`
Conditions []metav1.Condition `json:"conditions,omitempty"`
InstrumentationOptions []v1alpha1.WorkloadInstrumentationConfig `json:"instrumentation_options,omitempty"`
Languages []SourceLanguage `json:"languages,omitempty"`
Conditions []metav1.Condition `json:"conditions,omitempty"`
}

// this object contains only part of the source fields. It is used to display the sources in the frontend
Expand All @@ -54,7 +53,7 @@ func GetSources(c *gin.Context, odigosns string) {

var (
items []GetApplicationItem
instrumentedApplications *v1alpha1.InstrumentedApplicationList
instrumentedApplications *v1alpha1.InstrumentationConfigList
)

g, errCtx := errgroup.WithContext(reqCtx)
Expand All @@ -76,7 +75,7 @@ func GetSources(c *gin.Context, odigosns string) {

g.Go(func() error {
var err error
instrumentedApplications, err = kube.DefaultClient.OdigosClient.InstrumentedApplications("").List(errCtx, metav1.ListOptions{})
instrumentedApplications, err = kube.DefaultClient.OdigosClient.InstrumentationConfigs("").List(errCtx, metav1.ListOptions{})
return err
})

Expand Down Expand Up @@ -148,7 +147,7 @@ func GetSource(c *gin.Context) {
NumberOfRunningInstances: numberOfRunningInstances,
}

instrumentedApplication, err := kube.DefaultClient.OdigosClient.InstrumentedApplications(ns).Get(c, k8sObjectName, metav1.GetOptions{})
instrumentedApplication, err := kube.DefaultClient.OdigosClient.InstrumentationConfigs(ns).Get(c, k8sObjectName, metav1.GetOptions{})

if err == nil {
// valid instrumented application, grab the runtime details
Expand Down Expand Up @@ -354,7 +353,7 @@ func handleInstrumentationConfigRequest(c *gin.Context, ns, kind, name string, c
return err
}

func k8sInstrumentedAppToThinSource(app *v1alpha1.InstrumentedApplication) ThinSource {
func k8sInstrumentedAppToThinSource(app *v1alpha1.InstrumentationConfig) ThinSource {
var source ThinSource
source.Name = app.OwnerReferences[0].Name
source.Kind = workload.WorkloadKind(app.OwnerReferences[0].Kind)
Expand All @@ -369,31 +368,12 @@ func k8sInstrumentedAppToThinSource(app *v1alpha1.InstrumentedApplication) ThinS
})
}

var instrumentationOptions []v1alpha1.WorkloadInstrumentationConfig

for _, option := range app.Spec.Options {
for _, libOptions := range option.InstrumentationLibraries {
for _, configOption := range libOptions.Options {
instrumentationOptions = append(instrumentationOptions, v1alpha1.WorkloadInstrumentationConfig{
OptionKey: configOption.OptionKey,
SpanKind: configOption.SpanKind,
InstrumentationLibraries: []v1alpha1.InstrumentationLibrary{
{
InstrumentationLibraryName: libOptions.LibraryName,
},
},
})
}
}
}

source.IaDetails = &InstrumentedApplicationDetails{
Languages: []SourceLanguage{},
Conditions: conditions,
InstrumentationOptions: instrumentationOptions,
Languages: []SourceLanguage{},
Conditions: conditions,
}

for _, language := range app.Spec.RuntimeDetails {
for _, language := range app.Status.RuntimeDetailsByContainer {
sourceLanguage := SourceLanguage{
ContainerName: language.ContainerName,
Language: string(language.Language),
Expand All @@ -406,9 +386,9 @@ func k8sInstrumentedAppToThinSource(app *v1alpha1.InstrumentedApplication) ThinS
return source
}

func addHealthyInstrumentationInstancesCondition(ctx context.Context, app *v1alpha1.InstrumentedApplication, source *ThinSource) error {
labelSelector := fmt.Sprintf("%s=%s", consts.InstrumentedAppNameLabel, app.Name)
instancesList, err := kube.DefaultClient.OdigosClient.InstrumentationInstances(app.Namespace).List(ctx, metav1.ListOptions{
func addHealthyInstrumentationInstancesCondition(ctx context.Context, instConfig *v1alpha1.InstrumentationConfig, source *ThinSource) error {
labelSelector := fmt.Sprintf("%s=%s", consts.InstrumentedAppNameLabel, instConfig.Name)
instancesList, err := kube.DefaultClient.OdigosClient.InstrumentationInstances(instConfig.Namespace).List(ctx, metav1.ListOptions{
LabelSelector: labelSelector,
})

Expand Down
15 changes: 7 additions & 8 deletions frontend/graph/conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ func k8sLastTransitionTimeToGql(t v1.Time) *string {
return &str
}

func instrumentedApplicationToActualSource(instrumentedApp v1alpha1.InstrumentedApplication) *model.K8sActualSource {
func instrumentationConfigToActualSource(instruConfig v1alpha1.InstrumentationConfig) *model.K8sActualSource {
// Map the container runtime details
var containers []*model.SourceContainerRuntimeDetails
for _, container := range instrumentedApp.Spec.RuntimeDetails {
for _, container := range instruConfig.Status.RuntimeDetailsByContainer {
var otherAgentName *string
if container.OtherAgent != nil {
otherAgentName = &container.OtherAgent.Name
Expand All @@ -61,7 +61,7 @@ func instrumentedApplicationToActualSource(instrumentedApp v1alpha1.Instrumented

// Map the conditions of the application
var conditions []*model.Condition
for _, condition := range instrumentedApp.Status.Conditions {
for _, condition := range instruConfig.Status.Conditions {
conditions = append(conditions, &model.Condition{
Type: condition.Type,
Status: k8sConditionStatusToGql(condition.Status),
Expand All @@ -73,12 +73,11 @@ func instrumentedApplicationToActualSource(instrumentedApp v1alpha1.Instrumented

// Return the converted K8sActualSource object
return &model.K8sActualSource{
Namespace: instrumentedApp.Namespace,
Kind: k8sKindToGql(instrumentedApp.OwnerReferences[0].Kind),
Name: instrumentedApp.OwnerReferences[0].Name,
ServiceName: &instrumentedApp.Name,
Namespace: instruConfig.Namespace,
Kind: k8sKindToGql(instruConfig.OwnerReferences[0].Kind),
Name: instruConfig.OwnerReferences[0].Name,
ReportedName: &instruConfig.Spec.ServiceName,
NumberOfInstances: nil,
AutoInstrumented: instrumentedApp.Spec.Options != nil,
InstrumentedApplicationDetails: &model.InstrumentedApplicationDetails{
Containers: containers,
Conditions: conditions,
Expand Down
Loading

0 comments on commit 52ee331

Please sign in to comment.