-
Notifications
You must be signed in to change notification settings - Fork 185
Add ControllerStartupLatency metric for SandboxClaims #522
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -92,15 +92,24 @@ func (r *SandboxClaimReconciler) Reconcile(ctx context.Context, req ctrl.Request | |||||
| return ctrl.Result{}, nil | ||||||
| } | ||||||
|
|
||||||
| // Initialize trace ID for active resources missing an ID. Inline patch, | ||||||
| // no early return, to avoid forcing a second reconcile cycle. | ||||||
| // Initialize trace ID and observation time for active resources missing them. | ||||||
| // Inline patch, no early return, to avoid forcing a second reconcile cycle. | ||||||
| tc := r.Tracer.GetTraceContext(ctx) | ||||||
| if tc != "" && (claim.Annotations == nil || claim.Annotations[asmetrics.TraceContextAnnotation] == "") { | ||||||
| obsAnnotation := "agent-sandbox.kubernetes.io/controller-first-observed-at" | ||||||
| needObsPatch := claim.Annotations == nil || claim.Annotations[obsAnnotation] == "" | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
You can read from a nil map, it is treated as the empty map |
||||||
| needTcPatch := tc != "" && (claim.Annotations == nil || claim.Annotations[asmetrics.TraceContextAnnotation] == "") | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| if needObsPatch || needTcPatch { | ||||||
| patch := client.MergeFrom(claim.DeepCopy()) | ||||||
| if claim.Annotations == nil { | ||||||
| claim.Annotations = make(map[string]string) | ||||||
| } | ||||||
| claim.Annotations[asmetrics.TraceContextAnnotation] = tc | ||||||
| if needObsPatch { | ||||||
| claim.Annotations[obsAnnotation] = time.Now().Format(time.RFC3339Nano) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You might consider just keeping an in memory map, but ... given we're already writing to the apiserver for the trace... sgtm |
||||||
| } | ||||||
| if needTcPatch { | ||||||
| claim.Annotations[asmetrics.TraceContextAnnotation] = tc | ||||||
| } | ||||||
| if err := r.Patch(ctx, claim, patch); err != nil { | ||||||
| return ctrl.Result{}, err | ||||||
| } | ||||||
|
|
@@ -822,6 +831,20 @@ func (r *SandboxClaimReconciler) recordCreationLatencyMetric( | |||||
| // startup latency when the TemplateRef is updated. | ||||||
| asmetrics.RecordClaimStartupLatency(claim.CreationTimestamp.Time, launchType, claim.Spec.TemplateRef.Name) | ||||||
|
|
||||||
| // Record controller startup latency | ||||||
| obsAnnotation := "agent-sandbox.kubernetes.io/controller-first-observed-at" | ||||||
| if claim.Annotations != nil && claim.Annotations[obsAnnotation] != "" { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| obsStr := claim.Annotations[obsAnnotation] | ||||||
| observedTime, err := time.Parse(time.RFC3339Nano, obsStr) | ||||||
| if err != nil { | ||||||
| logger.Error(err, "Failed to parse controller observation time", "value", obsStr) | ||||||
| } else { | ||||||
| latency := time.Since(observedTime).Milliseconds() | ||||||
| logger.V(1).Info("Recording controller startup latency", "claim", claim.Name, "latency_ms", latency) | ||||||
| asmetrics.RecordClaimControllerStartupLatency(observedTime, launchType, claim.Spec.TemplateRef.Name) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // For cold launches, also record the time from Sandbox creation to Ready state to capture controller overhead. | ||||||
| if sandbox == nil || sandbox.CreationTimestamp.IsZero() { | ||||||
| return | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I would just call the variables traceContext, observabilityAnnotation, needObservabilityPatch, needTraceContextPatch; it makes it easier to read