coder / coder

Provision remote development environments via Terraform
https://coder.com
GNU Affero General Public License v3.0
8.15k stars 687 forks source link

docs: generate admin/prometheus.md dynamically #13223

Open dannykopping opened 5 months ago

dannykopping commented 5 months ago

scripts/metricsdocgen generates this list of available metrics. However, it relies on a static dump of metrics from scripts/metricsdocgen/metrics; this means that new metrics are not automatically detected.

We can generate this list of metrics more reliably by calling CODER_PROMETHEUS_ENABLE=true coder server and add some kind of flag to force a dump of metrics like so:

--- a/cli/server.go
+++ b/cli/server.go
@@ -1016,6 +1016,8 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
                                }
                        }

+                       prometheus.WriteToTextfile("./scripts/metricsdocgen/metrics", promRegistry)
+
                        eg := errgroup.Group{}
                        eg.Go(func() error {
                                defer closeListenersNow()

This won't catch any metrics for which there have not been any collected values yet, however, but it's a step closer.

@mtojek what do you think?

mtojek commented 5 months ago

AFAIR It was the original idea, but too many metrics were skipped. It might be hard to decide when is the cut-off point, so the list is stable.