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

feat: add running field to ii + set it to false once opamp shutdown #1847

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions api/config/crd/bases/odigos.io_instrumentationinstances.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ spec:
Producers of specific condition types may define expected values and meanings for this field,
and whether the values are considered a guaranteed API.
type: string
running:
description: |-
Running true means that the SDK is running and generating telemetry.
It is set to false when the SDK is not running or the agent has stopped the SDK.
type: boolean
required:
- lastStatusTime
type: object
Expand Down

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

4 changes: 4 additions & 0 deletions api/odigos/v1alpha1/instrumentationinstance_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ type InstrumentationInstanceStatus struct {
// Healthy nil means that the agent did not report any health status yet (prefer to always report health status).
Healthy *bool `json:"healthy,omitempty"`

// Running true means that the SDK is running and generating telemetry.
// It is set to false when the SDK is not running or the agent has stopped the SDK.
Running *bool `json:"running,omitempty"`

// message is a human readable message indicating details about the SDK general health.
// can be omitted if healthy is true
// +kubebuilder:validation:MaxLength=32768
Expand Down
5 changes: 5 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.

9 changes: 8 additions & 1 deletion k8sutils/pkg/describe/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,14 @@ func printPodsInfo(analyze *source.SourceAnalyze, sb *strings.Builder) {
describeText(sb, 3, "")
describeText(sb, 3, "Instrumentation Instances:")
for _, ii := range container.InstrumentationInstances {
printProperty(sb, 4, &ii.Healthy)

// This situation may occur when a process has completed successfully (exit code 0).
// In such cases, we want to reflect that the process is no longer running.
if ii.Healthy.Value == true && ii.Running.Value == false {
printProperty(sb, 4, &ii.Running)
} else {
printProperty(sb, 4, &ii.Healthy)
}
printProperty(sb, 4, ii.Message)
if len(ii.IdentifyingAttributes) > 0 {
describeText(sb, 4, "Identifying Attributes:")
Expand Down
11 changes: 11 additions & 0 deletions k8sutils/pkg/describe/source/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type InstrumentationDeviceAnalyze struct {

type InstrumentationInstanceAnalyze struct {
Healthy properties.EntityProperty `json:"healthy"`
Running properties.EntityProperty `json:"running"`
Message *properties.EntityProperty `json:"message"`
IdentifyingAttributes []properties.EntityProperty `json:"identifyingAttributes"`
}
Expand Down Expand Up @@ -390,6 +391,15 @@ func analyzeInstrumentationInstance(instrumentationInstance *odigosv1.Instrument
}
}

var running properties.EntityProperty
if instrumentationInstance.Status.Running != nil {
running = properties.EntityProperty{
Name: "Running",
Value: *instrumentationInstance.Status.Running,
Status: properties.PropertyStatusTransitioning,
}
}

identifyingAttributes := make([]properties.EntityProperty, 0, len(instrumentationInstance.Status.IdentifyingAttributes))
for _, attribute := range instrumentationInstance.Status.IdentifyingAttributes {
identifyingAttributes = append(identifyingAttributes, properties.EntityProperty{
Expand All @@ -402,6 +412,7 @@ func analyzeInstrumentationInstance(instrumentationInstance *odigosv1.Instrument
Healthy: healthy,
Message: message,
IdentifyingAttributes: identifyingAttributes,
Running: running,
}
}

Expand Down
8 changes: 8 additions & 0 deletions k8sutils/pkg/instrumentation_instance/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ func WithHealthy(healthy *bool, reason string, message *string) InstrumentationI
})
}

// set Running and related fields in InstrumentationInstanceStatus
func WithRunning(running *bool) InstrumentationInstanceOption {
return updateInstrumentationInstanceStatusOpt(func(s odigosv1.InstrumentationInstanceStatus) odigosv1.InstrumentationInstanceStatus {
s.Running = running
return s
})
}

func WithAttributes(identifying []odigosv1.Attribute, nonIdentifying []odigosv1.Attribute) InstrumentationInstanceOption {
return updateInstrumentationInstanceStatusOpt(func(s odigosv1.InstrumentationInstanceStatus) odigosv1.InstrumentationInstanceStatus {
s.IdentifyingAttributes = identifying
Expand Down
8 changes: 3 additions & 5 deletions opampserver/pkg/server/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,21 +153,19 @@ func (c *ConnectionHandlers) UpdateInstrumentationInstanceStatus(ctx context.Con

isAgentDisconnect := message.AgentDisconnect != nil
hasHealth := message.Health != nil
dynamicOptions := make([]instrumentation_instance.InstrumentationInstanceOption, 0)
// when agent disconnects, it need to report that it is unhealthy and disconnected
if isAgentDisconnect {
if !hasHealth {
return fmt.Errorf("missing health in agent disconnect message")
}
if message.Health.Healthy {
return fmt.Errorf("agent disconnect message with healthy status")
}
if message.Health.LastError == "" {
return fmt.Errorf("missing last error in unhealthy message")
}
running := false
dynamicOptions = append(dynamicOptions, instrumentation_instance.WithRunning(&running))
}

dynamicOptions := make([]instrumentation_instance.InstrumentationInstanceOption, 0)

if message.AgentDescription != nil {
identifyingAttributes := make([]odigosv1.Attribute, 0, len(message.AgentDescription.IdentifyingAttributes))
for _, attr := range message.AgentDescription.IdentifyingAttributes {
Expand Down
Loading