Skip to content

Commit ea92c6b

Browse files
craig[bot]tbg
andcommitted
Merge #159046
159046: status: add node_id label to stores initialized after AddNode r=tbg a=tbg Previously, when a node restarted with additional stores, the new stores could be missing the node_id label in their metrics. This happened because stores added to an existing node are initialized asynchronously via initializeAdditionalStores, which can complete after recorder.AddNode has already run. AddNode sets the node_id label on all stores currently in storeRegistries, but AddStore didn't add the label for stores registered later. Fix this by having AddStore add the node_id label if AddNode has already been called (i.e., if desc.NodeID is set). There's no risk of duplicate labels since a store is either present when AddNode runs (and AddNode adds the label) or added afterward (and AddStore adds it). Fixes #159045 Release note (bug fix): Previously, when a node was restarted with additional stores for the first time, the metrics for these stores could be missing the node_id label. Co-authored-by: Tobias Grieger <[email protected]>
2 parents 74642a6 + 3655977 commit ea92c6b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

pkg/server/status/recorder.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,14 @@ func (mr *MetricsRecorder) AddStore(store storeMetrics) {
345345
defer mr.mu.Unlock()
346346
storeID := store.StoreID()
347347
store.Registry().AddLabel("store", strconv.Itoa(int(storeID)))
348+
// If AddNode has already been called, we need to add the node_id label here.
349+
// This can happen when stores are initialized asynchronously after node start.
350+
// There's no risk of duplicate labels: either the store is added before AddNode
351+
// runs (in which case desc.NodeID is 0 here, and AddNode adds the label), or it's
352+
// added after (in which case we add it here, and AddNode never saw this store).
353+
if !disableNodeAndTenantLabels && mr.mu.desc.NodeID != 0 {
354+
store.Registry().AddLabel("node_id", strconv.Itoa(int(mr.mu.desc.NodeID)))
355+
}
348356
mr.mu.storeRegistries[storeID] = store.Registry()
349357
mr.mu.stores[storeID] = store
350358
}

0 commit comments

Comments
 (0)