Repository navigation
feat(otel): trace sandbox deletion across services - #2432
JiaxPeaceLove wants to merge 1 commit into
Conversation
f0606d6 to
78ec006
Compare
Continue the inbound trace from CubeAPI through CubeMaster to Cubelet. Record the sandbox ID and business return code while preserving the existing Destroy RPC timeout and cancellation behavior. Signed-off-by: jiaxu <18910286396@163.com>
78ec006 to
354639e
Compare
| RetMsg: errorcode.ErrorCode_Success.String(), | ||
| }, | ||
| } | ||
| ctx, span := telemetry.StartIfTraced(ctx, "cubemaster.sandbox.delete") |
There was a problem hiding this comment.
nit: span name should be a constant in the telemetry package. Every other CubeMaster span name is declared in pkg/base/telemetry/telemetry.go (SpanCreate, SpanSandboxPausePrepare, …), and this same PR adds telemetry.SpanDelete for the Cubelet side. Please add e.g. SpanSandboxDelete = "cubemaster.sandbox.delete" to the Span* const block and use it here, so the name is discoverable and greppable like the rest.
| if rsp != nil && rsp.Ret != nil { | ||
| code = rsp.Ret.RetCode | ||
| } | ||
| telemetry.EndWithCode(span, code) |
There was a problem hiding this comment.
nit: the span only covers the enqueue for async deletes. When req.Sync == false, DestroySandbox returns right after task.AddAsyncTask(t) below, so this defer ends the span with cube.ret_code = 200 before anything is deleted. The Cubelet span raised later by DestroySandboxTaskHandler (pkg/task/handlers.go:259) is still linked (it inherits the span context through t.Ctx), but it starts after its parent has ended and a real destroy failure is not reflected on the master span.
CubeAPI always sends sync: true, so this only affects non-CubeAPI callers. If that trade-off is intended, a short comment on why the span stops at enqueue would prevent it being read as an end-to-end delete span; otherwise end the span in the task handler for the async branch.
| } | ||
|
|
||
| func (s *service) Destroy(ctx context.Context, req *cubebox.DestroyCubeSandboxRequest) (*cubebox.DestroyCubeSandboxResponse, error) { | ||
| ctx, span := telemetry.StartIfTraced(telemetry.ExtractGRPC(ctx), telemetry.SpanDelete, |
There was a problem hiding this comment.
nit: StartIfTraced diverges from the other Cubelet RPC root spans. Every instrumented Cubelet RPC root uses unconditional telemetry.Start — SpanCreate (service.go:337), SpanRollback (rollback.go:90), SpanPause (update.go:45), SpanTemplateCommit (template_ops.go:43), SpanImageCreate (images/service.go:217) — and StartIfTraced is otherwise reserved for stage spans.
With this form, a Cubelet that has tracing enabled but receives a Destroy without a traceparent (CubeMaster tracing disabled/misconfigured, or a direct/internal caller) emits no cubelet.sandbox.delete span at all, while create/rollback/pause still produce a root span. If that asymmetry is deliberate to avoid root spans for frequent internal cleanup deletes, a comment would help; otherwise use telemetry.Start(telemetry.ExtractGRPC(ctx), …) to match the siblings.
| rpcCtx, cancel := context.WithTimeout(context.Background(), timeout) | ||
| defer cancel() | ||
| return c.Destroy(ctx, req) | ||
| return c.Destroy(telemetry.InjectGRPC(telemetry.DetachTrace(rpcCtx, ctx)), req) |
There was a problem hiding this comment.
nit: the new CubeMaster → Cubelet trace link has no test. This line is the only thing carrying the trace from cubemaster.sandbox.delete onto the Cubelet Destroy RPC, and the new cubemaster.sandbox.delete span in sandbox_remove.go (attributes, parent, cube.ret_code, panic path) is likewise untested. The diff adds tests for the Gin middleware, the CubeAPI entry route and the Cubelet handler, but nothing asserts this injection or the master span — while the sibling pause/resume/create spans each have dedicated span tests (sandbox_update_trace_test.go, sandbox_create_test.go, queue_span_test.go). A small test asserting the outgoing traceparent parent matches the caller span (and that the span reports 200 / a failure code) would fit the existing pattern.
AI review — automated, not a human approvalReviewed the prefetched diff against the base branch ( What the change doesExtends the lifecycle tracing from #2165 to sandbox deletion:
Resulting chain for the CubeAPI delete path: Checks that came out clean
Findings
Process notes
|
Summary
Extend the lifecycle tracing introduced in #2165 to sandbox deletion.
DELETE /sandboxes/:sandboxIDcontinues the inbound W3C trace in CubeAPI. CubeMaster forwards the trace context to the CubeletDestroyRPC while preserving the existing RPC deadline and cancellation behavior.The delete spans carry the sandbox ID. The CubeMaster and Cubelet operation spans also record
cube.ret_code.Validation
Passed locally on Linux/amd64 at
354639e5:cube.sandbox_id, andcube.ret_code.KVM cluster smoke test
354639e5for a temporary canary. The test used the existing runtime images with the candidate binaries and an existing test template.traceparentreturned HTTP 204, and the subsequent lookup returned HTTP 404.1893646c064f6aff851890dcbd8a85edcontained 13 spans. The CubeAPI delete span inherited the supplied parent, and the trace continued through the CubeMaster HTTP and business spans to CubeletDestroy, including containerdTask/Kill,Task/Delete, andTask/Shutdown. The three operation spans recorded the samecube.sandbox_id, and CubeMaster and Cubelet recordedcube.ret_code=200.130597(no more resource). A retry succeeded and was used for the delete test.