Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat(scripts/metricsdocgen): add AST scanner core for metrics doc generation - #21460

Merged
ssncferreira merged 2 commits into
mainfrom
ssncferreira/metricsdocgen-ast-scanner-core
Feb 13, 2026
Merged

feat(scripts/metricsdocgen): add AST scanner core for metrics doc generation#21460
ssncferreira merged 2 commits into
mainfrom
ssncferreira/metricsdocgen-ast-scanner-core

Conversation

@ssncferreira

@ssncferreira ssncferreira commented Jan 8, 2026

Copy link
Copy Markdown
Contributor

Description

This PR adds an AST-based scanner to automatically generate Prometheus metrics documentation from the coder source code.

Changes

  • Add scripts/metricsdocgen/scanner/scanner.go with:
    • Directory walking for agent/, coderd/, enterprise/, provisionerd/
    • Go file parsing (skipping *_test.go files)
    • AST inspection for metric extraction
    • Metric.String() for Prometheus text exposition format rendering
    • writeMetrics() to output metrics to stdout
    • Placeholder extractMetricFromCall() (implemented in subsequent PRs)
  • Empty scripts/metricsdocgen/generated_metrics placeholder (populated by subsequent PRs)

Note: To facilitate the review process, this was separated into scoped stacked PRs. The division was based on the main structure, the different Prometheus patterns currently present in the codebase, and updates to the build process.

Related to: #13223

Disclosure: This PR was mainly developed with Claude Sonnet 4, with iterative review and refinement by @ssncferreira

@ssncferreira
ssncferreira force-pushed the ssncferreira/metricsdocgen-ast-scanner-core branch from 53b26d8 to 95bcc37 Compare January 8, 2026 19:58
@ssncferreira
ssncferreira force-pushed the ssncferreira/metricsdocgen-ast-scanner-core branch 5 times, most recently from b487f0c to aee2d85 Compare January 9, 2026 10:37
@ssncferreira ssncferreira changed the title feat(scripts): add AST scanner core for metrics doc generation feat(scripts/metricsdocgen): add AST scanner core for metrics doc generation Jan 9, 2026
@ssncferreira
ssncferreira marked this pull request as ready for review January 9, 2026 11:32
@ssncferreira
ssncferreira requested a review from mtojek January 9, 2026 11:36

@mtojek mtojek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing blocking, looking forward to next PR :)

Comment thread scripts/metricsdocgen/scanner/scanner.go
Comment on lines +27 to +32
var scanDirs = []string{
"agent",
"coderd",
"enterprise",
"provisionerd",
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: alternative approach .metricsignore file :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a good idea for the future, we can revisit this if needed 👍

Comment thread scripts/metricsdocgen/scanner/scanner.go Outdated
}

// scanFile parses a single Go file and extracts all Prometheus metric definitions.
func scanFile(path string) ([]Metric, error) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Future: We could add some smoke tests to prevent accidental AST logic changes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is missing testing. This is something we need to address in the future 👍

Comment thread scripts/metricsdocgen/scanner/scanner.go
Comment thread scripts/metricsdocgen/scanner/scanner.go Outdated
Comment thread scripts/metricsdocgen/scanner/scanner.go
Comment thread scripts/metricsdocgen/scanner/scanner.go
Comment thread scripts/metricsdocgen/scanner/scanner.go
@ssncferreira
ssncferreira force-pushed the ssncferreira/metricsdocgen-ast-scanner-core branch from aee2d85 to b8b4331 Compare January 16, 2026 19:01
@ssncferreira
ssncferreira force-pushed the ssncferreira/metricsdocgen-ast-scanner-core branch from b8b4331 to c6638df Compare January 23, 2026 19:18
@github-actions

Copy link
Copy Markdown
Contributor

@ssncferreira
ssncferreira force-pushed the ssncferreira/metricsdocgen-ast-scanner-core branch from c6638df to a370b3f Compare January 28, 2026 08:57
@coderagents

coderagents Bot commented Jan 28, 2026

Copy link
Copy Markdown
Contributor

Documentation Check

No Changes Needed

This PR adds foundational scanner infrastructure with placeholder implementations. The actual metric extraction logic (extractMetricFromCall) will be implemented in subsequent PRs in the stack (as noted in the PR description).

No documentation changes are required because:

  • This is build tooling infrastructure, not user-facing functionality
  • The implementation is intentionally incomplete (placeholder for upstack PRs)
  • Target documentation already exists at docs/admin/integrations/prometheus.md with proper auto-generated content markers
  • The Makefile already has the regeneration target: make docs/admin/integrations/prometheus.md

Automated review via Coder Tasks

@github-actions github-actions Bot added the stale This issue is like stale bread. label Feb 5, 2026
@ssncferreira ssncferreira removed the stale This issue is like stale bread. label Feb 6, 2026
@ssncferreira
ssncferreira force-pushed the ssncferreira/metricsdocgen-ast-scanner-core branch 3 times, most recently from 0f1be8c to 1bdb883 Compare February 12, 2026 17:23
@ssncferreira
ssncferreira force-pushed the ssncferreira/metricsdocgen-ast-scanner-core branch from 1bdb883 to f7f0213 Compare February 13, 2026 10:20

ssncferreira commented Feb 13, 2026

Copy link
Copy Markdown
Contributor Author

Merge activity

  • Feb 13, 10:48 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Feb 13, 10:48 AM UTC: @ssncferreira merged this pull request with Graphite.

@ssncferreira
ssncferreira merged commit a9180d4 into main Feb 13, 2026
31 checks passed
@ssncferreira
ssncferreira deleted the ssncferreira/metricsdocgen-ast-scanner-core branch February 13, 2026 10:48
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