Conversation
| return load_info | ||
|
|
||
| except Exception as e: | ||
| metrics.increment("get_cluster_loadinfo_failure", tags={"cluster_name": cluster_name}) |
Contributor
There was a problem hiding this comment.
Bug: If get_cluster() fails, the except block references cluster_name before it's assigned, causing an UnboundLocalError and masking the original exception.
Severity: MEDIUM
Suggested Fix
Initialize cluster_name to a default value like None before the try block. This ensures the variable is always defined when the except block is executed, preventing the UnboundLocalError.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: snuba/web/rpc/storage_routing/load_retriever.py#L169
Potential issue: In the `get_cluster_loadinfo` function, if
`get_cluster(storage_set_key)` raises an exception, such as `UndefinedClickhouseCluster`
due to a misconfiguration, the `cluster_name` variable is never assigned. The `except`
block then attempts to reference `cluster_name` when creating a metric tag. This will
raise an `UnboundLocalError`, which masks the original, more informative exception about
the cluster configuration problem, making debugging more difficult.
Did we get this right? 👍 / 👎 to inform future reviews.
pbhandari
marked this pull request as draft
September 11, 2026 21:13
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
get_cluster_loadinfonow returns a widerLoadInfobag so we can graph hottest-replica load and pick thresholds for a later routing / dynamic-sampling strategy. This PR is probe + gauges only; nothing branches on the new fields yet.Signals (all
float, default-1.0):cluster_load— max 1m load / CPU, as beforeconcurrent_queries— maxsystem.metrics.Query(wascount()onsystem.processes)cgroup_user_time_normalizedblock_in_flight_opsmemory_trackingpart_mutationReplica aggregations are max (the hot node). Missing CH metrics and old Redis blobs become
-1.0; treat that as not-loaded. Probe failure still incrementsget_cluster_loadinfo_failureand does not gauge.One INTERNAL query per cache miss. Single-node vs
clusterAllReplicasSQL is unchanged.Follow-up: look at the gauges, set thresholds, then a strategy that actually reads these.