Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use instrumentation config for runtime details #2115

Merged
merged 16 commits into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

4 changes: 2 additions & 2 deletions cli/cmd/resources/instrumentor.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ 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"},
RonFed marked this conversation as resolved.
Show resolved Hide resolved
Resources: []string{"instrumentationconfigs/status"},
Verbs: []string{"get", "patch", "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"`
RonFed marked this conversation as resolved.
Show resolved Hide resolved
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
Loading