Skip to content

metric: embed source file in Metadata for CODEOWNERS resolution#167494

Draft
angles-n-daemons wants to merge 1 commit intocockroachdb:masterfrom
angles-n-daemons:bdillmann/metric-source-file
Draft

metric: embed source file in Metadata for CODEOWNERS resolution#167494
angles-n-daemons wants to merge 1 commit intocockroachdb:masterfrom
angles-n-daemons:bdillmann/metric-source-file

Conversation

@angles-n-daemons
Copy link
Copy Markdown
Contributor

Summary

  • Adds a source_file field to metric.Metadata proto, populated
    automatically by a new metric.NewMetadata() constructor via
    runtime.Caller.
  • At generation time, cockroach gen metric-list resolves metric
    ownership by calling codeowners.Match() on each metric's source
    file — eliminating the separate gen-metric-owners AST scanning
    tool, metric_owners.yaml, and bespoke CI/dev steps.
  • Adds a metadatanew nogo analyzer to enforce constructor usage
    across the codebase.

Epic: none

Release note: None

@angles-n-daemons angles-n-daemons requested review from a team as code owners April 3, 2026 18:15
@angles-n-daemons angles-n-daemons requested review from alyshanjahani-crl and removed request for a team April 3, 2026 18:15
@trunk-io
Copy link
Copy Markdown
Contributor

trunk-io bot commented Apr 3, 2026

Merging to master in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@angles-n-daemons angles-n-daemons requested review from mw5h and visheshbardia and removed request for a team April 3, 2026 18:15
@blathers-crl
Copy link
Copy Markdown

blathers-crl bot commented Apr 3, 2026

Your pull request contains more than 1000 changes. It is strongly encouraged to split big PRs into smaller chunks.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@angles-n-daemons angles-n-daemons requested review from aerfrei and dt and removed request for a team April 3, 2026 18:15
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@angles-n-daemons angles-n-daemons removed request for a team April 3, 2026 18:16
@angles-n-daemons angles-n-daemons marked this pull request as draft April 3, 2026 18:16
Previously, metric ownership was determined by a separate
gen-metric-owners tool that scanned Go source files via AST to find
metric.Metadata definitions, mapped each to its owning team via
CODEOWNERS, and produced a metric_owners.yaml file. This file was
checked into the tree but had no Bazel genrule, and required a
bespoke step in both ./dev generate and check-generated-code CI.

This commit eliminates that pipeline by embedding source file
information directly in metric.Metadata at definition time. A new
source_file proto field is populated by metric.InitMetadata(), which
captures the caller's file via runtime.Caller. At generation time,
cockroach gen metric-list resolves ownership by calling
codeowners.Match on each metric's source file — no separate AST
scanning needed.

To enforce adoption, a new metadatanew nogo analyzer flags bare
metric.Metadata{} composite literals that aren't wrapped in
InitMetadata(). The metric registry also logs a warning when metrics
are registered without a source file set.

Removed:
- pkg/cmd/gen-metric-owners and its Bazel target
- pkg/internal/metricscan/metric_owners.yaml and its go:embed wrapper
- The generateMetricOwners step from ./dev generate
- The bazel run //pkg/cmd/gen-metric-owners step from check-generated-code.sh
- The --metric-owners flag from cockroach gen metric-list

Epic: none

Release note: None
Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
@angles-n-daemons angles-n-daemons force-pushed the bdillmann/metric-source-file branch from 588f079 to 52318d2 Compare April 3, 2026 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants