feat(scripts/metricsdocgen): add prometheus.New*() and New*Vec() patterns to metrics scanner - #21462
Conversation
f64fdaf to
d2a562c
Compare
ee2942e to
b0e8dc4
Compare
d2a562c to
4340913
Compare
b0e8dc4 to
c4b0acc
Compare
4340913 to
1c42124
Compare
c4b0acc to
0243d78
Compare
1c42124 to
b52d9eb
Compare
602f312 to
ca16038
Compare
b52d9eb to
44b7bba
Compare
| @@ -1,21 +1,147 @@ | |||
| # HELP agent_reconnecting_pty_connections_total | |||
There was a problem hiding this comment.
There are some metrics without a HELP definition (description). This indicates that those metrics should be updated in the source code, but that's out of scope for this PR.
As a follow-up, the scanner should probably warn about these metrics and exclude them from the generated_metrics file, since their descriptions would appear empty in the final documentation. Wdyt?
There was a problem hiding this comment.
Added a warning log in scanFile when a metric has an empty HELP description. The metric is still included in the output for now. Added a TODO to consider filtering them out in a future PR.
There was a problem hiding this comment.
SGTM.
out of curiosity: how many metrics without HELP do we have? maybe we can fix them here, and agree to fail fast when HELP is missing
There was a problem hiding this comment.
2026/02/13 10:36:42 WARNING: metric "agent_scripts_executed_total" has no HELP description, skipping
2026/02/13 10:36:42 WARNING: metric "agent_ssh_server_failed_connections_total" has no HELP description, skipping
2026/02/13 10:36:42 WARNING: metric "agent_ssh_server_sftp_connections_total" has no HELP description, skipping
2026/02/13 10:36:42 WARNING: metric "agent_ssh_server_sftp_server_errors_total" has no HELP description, skipping
2026/02/13 10:36:42 WARNING: metric "agent_x11_handler_errors_total" has no HELP description, skipping
2026/02/13 10:36:42 WARNING: metric "agent_sessions_total" has no HELP description, skipping
2026/02/13 10:36:42 WARNING: metric "agent_sessions_errors_total" has no HELP description, skipping
2026/02/13 10:36:42 WARNING: metric "agent_reconnecting_pty_connections_total" has no HELP description, skipping
2026/02/13 10:36:42 WARNING: metric "agent_reconnecting_pty_errors_total" has no HELP description, skipping
2026/02/13 10:36:42 WARNING: metric "coderd_notifications_dispatch_attempts_total" has no HELP description, skipping
We have 10 metrics without HELP. The script already logs a warning for these cases. The last one uses fmt.Sprintf for the description, which the scanner cannot evaluate at compile time. We can address this in a follow-up PR 👍
ca16038 to
8bc9baa
Compare
70d2452 to
a14ee38
Compare
7c7892d to
8fc6317
Compare
| // extractOptsMetric extracts a metric from prometheus.New*() or prometheus.New*Vec() calls. | ||
| // Supported patterns: | ||
| // - prometheus.NewGauge(prometheus.GaugeOpts{...}) | ||
| // - prometheus.NewCounter(prometheus.CounterOpts{...}) | ||
| // - prometheus.NewHistogram(prometheus.HistogramOpts{...}) | ||
| // - prometheus.NewSummary(prometheus.SummaryOpts{...}) | ||
| // - prometheus.NewGaugeVec(prometheus.GaugeOpts{...}, labels) | ||
| // - prometheus.NewCounterVec(prometheus.CounterOpts{...}, labels) | ||
| // - prometheus.NewHistogramVec(prometheus.HistogramOpts{...}, labels) | ||
| // - prometheus.NewSummaryVec(prometheus.SummaryOpts{...}, labels) |
There was a problem hiding this comment.
since you identified these code snippets, maybe claude can generate fake .go files that use these patterns?
There was a problem hiding this comment.
Good idea 👍 we can create test fixtures with each pattern as a follow-up
| if name != "" { | ||
| parts = append(parts, name) | ||
| } | ||
| return strings.Join(parts, "_") |
There was a problem hiding this comment.
We can't use fmt.Sprintf here, namespace and subsystem are optional. This could generate something like "__name". The current approach only joins non-empty parts. Added a comment for clarity
a14ee38 to
7464012
Compare
b6a4028 to
9bae7b7
Compare
9bae7b7 to
f8f98ee
Compare
0462360 to
2caf0ad
Compare
Documentation CheckNo Changes NeededThis PR enhances the internal metrics documentation generator () to recognize additional Prometheus metric patterns ( and ). Since this is an internal development tool that automatically generates metrics documentation and doesn't affect user-facing features or workflows, no documentation updates are required. The generated metrics file () is auto-generated and properly updated by the script itself. Automated review via Coder Tasks |
a94b964 to
cd66231
Compare
49f44c7 to
2b637bb
Compare
cd66231 to
13618b3
Compare
2b637bb to
fd7a05c
Compare
13618b3 to
143e11f
Compare
fd7a05c to
a65ba82
Compare
2463ea5 to
89e829c
Compare
a65ba82 to
1ada5a6
Compare
c110fa1 to
9832bc8
Compare
36ce1aa to
27c0d16
Compare
Merge activity
|
9832bc8 to
777de5c
Compare

Description
This PR implements extraction of metrics defined using
prometheus.New*()andprometheus.New*Vec()patterns with*Opts{}structs.Changes
extractOptsMetric()to handle:prometheus.NewGauge(prometheus.GaugeOpts{...})prometheus.NewCounter(prometheus.CounterOpts{...})prometheus.NewHistogram(prometheus.HistogramOpts{...})prometheus.NewSummary(prometheus.SummaryOpts{...})prometheus.New*Vec(prometheus.*Opts{...}, labels)scripts/metricsdocgen/generated_metricsfileRelated to: #13223
Disclosure: This PR was mainly developed with Claude Sonnet 4, with iterative review and refinement by @ssncferreira