Send usage metrics from operator proxies with default anonymous ID #2635
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR description:
Problem
Operator-deployed MCP server proxies were not sending tool count metrics to the usage API, despite:
Root Cause
Operator-deployed proxies run in distroless containers with read-only root filesystems and cannot read the
~/.local/share/toolhive/updates.jsonfile where anonymous IDs are stored.The flow was:
TryGetAnonymousID()attempts to read the file but it doesn't existNewClient()at startupSendMetrics()sees emptyanonymous_idand returnsnil(skips sending)Solution
Modified
pkg/usagemetrics/client.goto detect operator environments using Kubernetes environment variables. When running in K8s andanonymous_idis empty, use the default value"operator-proxy"instead of skipping the send.This allows operator-deployed proxies to send metrics with a consistent identifier while local deployments still wait for the version check to create the anonymous ID file.
This also means we lose traceability of operator anonymous_ids for usage metrics; anonymous_id isn't a mandatory field to understand usage metrics, but can still be useful. A better solution might exist, but this unblocks usage metrics gathering for operator.
Testing
Tested locally with Kind cluster:
anonymous_id=operator-proxy