Skip to content

cubelog: remove the dead requestTrace aggregation path - #1481

Closed
dwin-gharibi wants to merge 1 commit into
TencentCloud:masterfrom
dwin-gharibi:cubelog-dead-request-trace-path
Closed

dwin-gharibi wants to merge 1 commit into
TencentCloud:masterfrom
dwin-gharibi:cubelog-dead-request-trace-path

Conversation

@dwin-gharibi

Copy link
Copy Markdown
Contributor

Closes #1480.

Motivation

requestTrace is never constructed anywhere in the tree, so its methods indexKey() and realKey()
have no callers, and slice2Str() is called only from realKey(). The whole block is unreachable.

It is not harmless dead weight: go vet reports possible misuse of reflect.StringHeader at
metric.go:179, inside slice2Str. Keeping unreachable unsafe-pointer code around means that warning
sits in the build output forever and any future reader has to work out whether it matters.

What this changes

cubelog/metric.go — deletes 109 lines:

  • type requestTrace struct (:77-130)
  • func (m *requestTrace) indexKey() (:128)
  • func (m *requestTrace) realKey() (:142)
  • func slice2Str(b []byte) string (:173)

and drops the four imports that only that block used: bytes, reflect, strconv, unsafe. io and
time remain.

The exported RequestTrace type (different type, capital R) and Trace() are untouched — those are
the live API.

Verified nothing outside the deleted block referenced any of these identifiers:

$ grep -rn "requestTrace\b|slice2Str|indexKey()" --include='*.go' .   # outside cubelog/: no hits

Cubelet/services/images/volumelifetime.go has its own separate slice2Str/realKey which are
live and are deliberately left alone here — they belong to the unsafe-header issue.

No comment changes.

Testing

Deletion only, so no new tests. Existing coverage confirms nothing depended on it:

$ cd cubelog && go build ./...
BUILD OK

$ go test -count=1 ./
ok  github.com/tencentcloud/CubeSandbox/cubelog  1.663s

$ go vet ./
(clean — the metric.go:179 reflect.StringHeader warning is gone)

CI gates checked locally:

  • gofmt -l . — clean (fmt-check).
  • go build ./..., go test ./..., go vet ./ — all clean.

git diff --stat: cubelog/metric.go | 109 ------ , 1 file changed, 109 deletions.

Risk / rollout

Very low — removing code with no callers and no exported surface. If the aggregation was intended to
come back, this PR is the wrong direction and it should be wired up instead; the deleted code is
recoverable from history either way.

Signed-off-by: Dwin Gharibi <dwin.gharibi@email.kntu.ac.ir>
Copilot AI lite review requested due to automatic review settings August 21, 2026 11:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@cubesandboxbot

Copy link
Copy Markdown

Review: cubelog — remove the dead requestTrace aggregation path

Verdict: Approve. This is a clean, well-scoped dead-code deletion. I verified the claims against the base tree.

Verification

  • No callers anywhere. Repo-wide grep for requestTrace, indexKey, realKey, slice2Str finds zero references to the removed identifiers outside the deleted block. The only near-misses are unrelated:
    • requestTraceMiddleware in CubeOps/internal/handler/integration_test.go (a different identifier).
    • meta.indexKey() / meta.realKey() / slice2Str() in Cubelet/services/images/volumelifetime.go — a separate, live type/function set that this PR correctly leaves untouched (confirmed at volumelifetime.go:858-903).
  • Imports pruned correctly. In cubelog/metric.go, bytes, reflect, strconv, and unsafe are referenced only inside the deleted block, so dropping them is safe. The retained imports are still used: io in SetTraceOutput(w io.Writer), time in RequestTrace.Timestamp/Cost and trace.Cost.Nanoseconds().
  • Exported surface untouched. RequestTrace, Trace(), EnableLogMetric(), DisableLogMetric(), SetTraceOutput(), DeepCopy(), and WithCallee() all remain intact.
  • Diff hygiene. Pure deletion (109 lines, 0 additions); the blank line between WithCallee and init() is preserved, so the resulting file is valid Go. No new code, no test churn, no dependency changes.

Notes

  • go vet scoping. After this change cd cubelog && go vet ./ is clean, but a repo-wide go vet ./... will still report the same possible misuse of reflect.SliceHeader/StringHeader warning at Cubelet/services/images/volumelifetime.go:896-903, which uses the identical unsafe zero-copy []bytestring pattern. The author acknowledges this in the PR description. Since the motivation for this PR is partly to get vet clean, a natural follow-up is to replace that call site with a plain string(buf.Bytes()) conversion (safe and correct — Go copies) and drop the unsafe usage there as well. Out of scope for this PR, but worth tracking.
  • Risk assessment is accurate. requestTrace is unexported and never constructed, so this is unreachable code; if the aggregation feature is ever wired back up, the block is recoverable from git history. Nothing to flag in the diff itself.

No correctness, reuse, or style issues found in the changed code.


This review was generated by an AI assistant and is not a human approval.

@fslongjin fslongjin closed this Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug Report] cubelog's requestTrace metric-aggregation path is dead code (and contains a vet-flagged unsafe misuse)

3 participants