Files
coder/scripts/metricsdocgen
Mathias Fredriksson a6a8fd94d7 build(Makefile): enable parallel make -j gen with correct dependency graph (#22612)
`make gen` could not run with `-j` because inter-target dependency edges
were missing. Multiple recipes compile `coderd/rbac` (which includes
generated files like `object_gen.go`), and without explicit ordering,
parallel runs produced syntax errors from mid-write reads.

Three main changes:

**Dependency graph fixes** declare the compile-time chain through
`coderd/rbac` so that `object_gen.go` is written before anything that
imports it is compiled. The DB generation targets use a GNU Make 4.3+
grouped target (`&:`) so Make knows `generate.sh` co-produces
`querier.go`, `unique_constraint.go`, `dbmetrics`, and `dbauthz` in a
single invocation. `SKIP_DUMP_SQL=1` avoids re-entrant `make` inside
`generate.sh` when the Makefile already guarantees `dump.sql` is fresh.

**`scripts/atomicwrite` package** replaces `os.WriteFile` in all gen
scripts with a temp-file-in-same-dir + rename pattern, preventing
interrupted runs from leaving partial files.

**`.PRECIOUS` and shell atomic writes** protect git-tracked generated
files from Make's default delete-on-error behavior. Since these files
are committed, deletion is worse than staleness -- `git restore` is the
recovery path.

CI now runs `make -j --output-sync -B gen` (~32s, down from ~85s
serial).

| Scenario                          | Before             | After    |
|-----------------------------------|--------------------|----------|
| `make gen` (serial)               | 95s                | 95s      |
| `make -j gen` (parallel)          | race error         | **22s**  |
| CI `make -j --output-sync -B gen` | forced serial ~85s | **~32s** |
2026-03-05 11:58:10 +00:00
..

Metrics Documentation Generator

This tool generates the Prometheus metrics documentation at docs/admin/integrations/prometheus.md.

How It Works

The documentation is generated from two metrics files:

  1. metrics (static, manually maintained)
  2. generated_metrics (auto-generated, do not edit)

These files are merged and used to produce the final documentation.

metrics (static)

Contains metrics that are not directly defined in the coder source code:

  • go_*: Go runtime metrics
  • process_*: Process metrics from prometheus/client_golang
  • promhttp_*: Prometheus HTTP handler metrics
  • coder_aibridged_*: Metrics from external dependencies

Note

This file also contains edge cases where metric metadata cannot be accurately extracted by the scanner (e.g., labels determined by runtime logic). Static metrics take priority over generated metrics when both files contain the same metric name.

Edit this file to add metrics that should appear in the documentation but are not scanned from the coder codebase, or to manually override metrics where the scanner generates incorrect metadata (e.g., missing runtime-determined labels like in agent_scripts_executed_total).

generated_metrics (auto-generated)

Contains metrics extracted from the coder source code by the AST scanner (scanner/scanner.go).

Do not edit this file directly. It is regenerated by running:

make scripts/metricsdocgen/generated_metrics

Updating Metrics Documentation

To regenerate the documentation after code changes:

make docs/admin/integrations/prometheus.md

This will:

  • Run the scanner to update generated_metrics
  • Merge metrics and generated_metrics metric files
  • Update the documentation file