Repository navigation
Commit 2d2709e
perf(metrics): update the rpc_endpoint_* series positionally, without a label map per call (MAG-4244) (#609)
Sixteen rpc_endpoint_* metrics went through MappedLabelsCounterVec and
MappedLabelsGaugeVec, wrappers written for "a dynamic number of labels
based on flags given upon startup". No metric has that: every label set
is fixed. Yet each update built a map[string]string of its labels, and
the wrapper then built a []string to put them back in order. These are
per-relay updates (relays serviced, in flight) and per-poll ones.
They are now plain *prometheus.CounterVec / *prometheus.GaugeVec,
registered through registerOrReuse like the metrics beside them, and
updated with positional WithLabelValues. The three wrapper files and the
wrapper's own test are deleted (MAG-4244 section 7).
registerOrReuse is a true drop-in here, checked rather than assumed: all
sixteen passed prometheus.DefaultRegisterer, which is the registry
registerOrReuse uses, and both reuse an already-registered collector of
the same type and panic otherwise.
Measured, steady-state allocations per update:
relay serviced, in flight, fetch success, tracker request 1 -> 0
latest block 2 -> 1
url relay serviced 3 -> 1
What could go wrong, and what rules it out:
- A wrong count of positional values makes Prometheus panic, where the
wrapper filled a missing label with "" and dropped an extra one. Every
one of the 17 update sites supplied exactly its metric's declared keys,
so nothing relied on either; the conversion derived each positional
order from the declared labels and refused any key-set mismatch.
- A swapped order would mislabel series the stuck-tip and per-url alerts
read, silently. Proved absent: a fixed sequence of updates through
every wrapped metric, including a url that two providers share and a
url that is then forgotten, renders 43 series whose names, help text,
label sets and values are BYTE-IDENTICAL to main's (only
answered_until's value is redacted, being time.Now()-derived).
Order now matters where it did not, so it gets a durable guard.
TestPositionalLabels_EveryWrappedMetric drives every metric with a
different value in every label position and requires each value under
its own name, then requires ForgetEndpointURLLatestBlock to remove the
url series. It passes on main's code too, so it pins the labels main
already produces. Against six swaps in the new code (spec with
apiInterface; endpoint_id with function, twice; endpoint_id with kind;
url with internal_path in the url helper; a forget that deletes nothing)
it fails every one.
urlSeriesLabelValuesLocked returns the url labels positionally for both
updates and DeleteLabelValues; its comment names the test that guards
its order. The nil guard comment on AddEndpointTrackerRequest named the
deleted wrapper type; it now names prometheus.CounterVec, whose
WithLabelValues dereferences its receiver all the same.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>1 parent 924600c commit 2d2709e
10 files changed
Lines changed: 279 additions & 458 deletions
File tree
- protocol/metrics
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
| |||
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
26 | | - | |
| 28 | + | |
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
| |||
33 | 35 | | |
34 | 36 | | |
35 | 37 | | |
36 | | - | |
| 38 | + | |
37 | 39 | | |
38 | 40 | | |
39 | 41 | | |
| |||
45 | 47 | | |
46 | 48 | | |
47 | 49 | | |
48 | | - | |
49 | | - | |
50 | | - | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
51 | 53 | | |
52 | 54 | | |
53 | 55 | | |
| |||
58 | 60 | | |
59 | 61 | | |
60 | 62 | | |
61 | | - | |
62 | | - | |
| 63 | + | |
| 64 | + | |
63 | 65 | | |
64 | 66 | | |
65 | 67 | | |
| |||
70 | 72 | | |
71 | 73 | | |
72 | 74 | | |
73 | | - | |
74 | | - | |
| 75 | + | |
| 76 | + | |
75 | 77 | | |
76 | 78 | | |
77 | 79 | | |
| |||
126 | 128 | | |
127 | 129 | | |
128 | 130 | | |
129 | | - | |
130 | | - | |
| 131 | + | |
| 132 | + | |
131 | 133 | | |
132 | 134 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
84 | | - | |
| 84 | + | |
85 | 85 | | |
86 | | - | |
| 86 | + | |
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | | - | |
| 91 | + | |
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
111 | | - | |
| 111 | + | |
112 | 112 | | |
113 | 113 | | |
114 | | - | |
| 114 | + | |
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
125 | | - | |
126 | | - | |
| 125 | + | |
| 126 | + | |
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
| |||
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
136 | | - | |
| 136 | + | |
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
| |||
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
151 | | - | |
| 151 | + | |
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
| |||
161 | 161 | | |
162 | 162 | | |
163 | 163 | | |
164 | | - | |
165 | | - | |
166 | | - | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
| |||
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
0 commit comments