Skip to content

Conversation

hanabi1224
Copy link
Contributor

@hanabi1224 hanabi1224 commented Oct 10, 2025

Summary of changes

Changes introduced in this pull request:

Reference issue to close (if applicable)

Closes #6064

Other information and links

Change checklist

  • I have performed a self-review of my own code,
  • I have made corresponding changes to the documentation. All new code adheres to the team's documentation standards,
  • I have added tests that prove my fix is effective or that my feature works (if possible),
  • I have made sure the CHANGELOG is up-to-date. All user-facing changes should be reflected in this document.

Summary by CodeRabbit

  • New Features
    • Added a CLI tool to validate Prometheus metrics text files.
  • Tests
    • Integrated metrics validation into the calibnet test flow.
    • Added unit tests covering valid and invalid metrics scenarios.
  • Documentation
    • Added instructions for running unit tests and validating metrics.
  • Chores
    • Updated gitignore to exclude metrics artifacts.
    • Enhanced CI to configure Go and run validator tests on Ubuntu.

Copy link
Contributor

coderabbitai bot commented Oct 10, 2025

Walkthrough

Adds a Go-based Prometheus metrics validator tool, integrates it into calibnet test scripts, documents local usage, and updates CI to set up Go and run the validator's tests.

Changes

Cohort / File(s) Summary
CI workflow updates
.github/workflows/forest.yml
Adds actions/setup-go@v6 in the calibnet-check job and adds a step to run go test -v ./tools/prometheus_metrics_validator in the ubuntu build job.
Calibnet test script
scripts/tests/calibnet_other_check.sh
Appends commands to fetch http://localhost:6116/metrics into a file and run the Prometheus metrics validator via go run against that file.
Tools docs
tools/README.md
Adds "Unit tests" and "Validate Forest metrics" instructions showing go test and how to fetch/run the validator locally.
Prometheus metrics validator tool
tools/prometheus_metrics_validator/*
tools/prometheus_metrics_validator/main.go, tools/prometheus_metrics_validator/main_test.go, tools/prometheus_metrics_validator/go.mod, tools/prometheus_metrics_validator/.gitignore
Adds a new Go CLI tool with Validate(metrics []byte) error, tests covering valid/invalid inputs, module dependencies, and ignore rules for local metric files.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Script as calibnet_other_check.sh
  participant Node as Forest Node (:6116)
  participant Validator as prometheus_metrics_validator (go run)

  Script->>Node: GET /metrics
  Node-->>Script: metrics text
  Script->>Validator: go run main.go metrics.log
  Validator->>Validator: Validate(metrics)
  alt parse ok
    Validator-->>Script: exit 0 (valid)
  else parse error
    Validator-->>Script: exit 1 (invalid)
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

github_actions, dependencies

Suggested reviewers

  • elmattic
  • akaladarshi

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly and concisely summarizes the primary change, namely adding tests to validate that Forest’s metrics are compatible with a Grafana scraper. It directly reflects the introduction of validation logic and CI integration without extraneous details.
Linked Issues Check ✅ Passed The changes implement a CLI validator for Prometheus metrics, integrate it into the CI workflow, and add integration steps in the test script to fetch and validate live metrics, thereby satisfying the core requirement of issue #6064 to assert scraper compatibility without a full observability stack. These additions directly address the completion criteria by ensuring Forest’s exported metrics can be parsed by a Grafana-compatible scraper.
Out of Scope Changes Check ✅ Passed All modifications—including CI workflow updates, the metrics validator tool and its tests, script adjustments, documentation changes, and .gitignore entries—are directly related to enabling and testing Prometheus metrics compatibility and no unrelated functionality or out-of-scope edits were introduced.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch hm/metrics-validation

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cfa2944 and 7737ceb.

📒 Files selected for processing (1)
  • tools/prometheus_metrics_validator/go.mod (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tools/prometheus_metrics_validator/go.mod
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: All lint checks
  • GitHub Check: cargo-publish-dry-run
  • GitHub Check: Build Ubuntu
  • GitHub Check: Build MacOS
  • GitHub Check: tests-release
  • GitHub Check: tests
  • GitHub Check: Build forest binaries on Linux AMD64

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.5.0)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain modules listed in go.work or their selected dependencies"


Comment @coderabbitai help to get the list of available commands and usage tips.

@hanabi1224 hanabi1224 marked this pull request as ready for review October 10, 2025 15:43
@hanabi1224 hanabi1224 requested a review from a team as a code owner October 10, 2025 15:43
@hanabi1224 hanabi1224 requested review from akaladarshi and elmattic and removed request for a team October 10, 2025 15:43
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
tools/README.md (1)

1-10: Clarify the working directory for test commands.

The unit test command go test -v . implies it should be run from tools/prometheus_metrics_validator/, but this isn't explicitly stated. Consider adding a note about the working directory or using the full path as in the CI workflow.

Apply this diff to clarify:

 ### Unit tests
 
-- run `go test -v .`
+Run from the repository root:
+```bash
+go test -v ./tools/prometheus_metrics_validator
+```
+
+Or from the `tools/prometheus_metrics_validator/` directory:
+```bash
+go test -v .
+```
 
 ### Validate Forest metrics
tools/prometheus_metrics_validator/main.go (1)

45-60: Consider documenting the textparse.New boolean parameters.

The textparse.New call uses three boolean parameters (false, false, true) whose purpose is unclear without referring to the Prometheus documentation. Adding a brief comment would improve code maintainability.

Apply this diff to add clarity:

 func Validate(metrics []byte) error {
+	// textparse.New parameters: content, contentType, timestamp, parseClassicHistograms, skipMetrics, enableUTF8, symbolTable
 	p, err := textparse.New(metrics, "text/plain", "", false, false, true, labels.NewSymbolTable())
 	if err != nil {
 		return err
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bb6e3f3 and cfa2944.

⛔ Files ignored due to path filters (2)
  • go.work is excluded by !**/*.work
  • tools/prometheus_metrics_validator/go.sum is excluded by !**/*.sum
📒 Files selected for processing (7)
  • .github/workflows/forest.yml (2 hunks)
  • scripts/tests/calibnet_other_check.sh (1 hunks)
  • tools/README.md (1 hunks)
  • tools/prometheus_metrics_validator/.gitignore (1 hunks)
  • tools/prometheus_metrics_validator/go.mod (1 hunks)
  • tools/prometheus_metrics_validator/main.go (1 hunks)
  • tools/prometheus_metrics_validator/main_test.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
tools/prometheus_metrics_validator/main_test.go (1)
tools/prometheus_metrics_validator/main.go (1)
  • Validate (45-60)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: tests-release
  • GitHub Check: tests
  • GitHub Check: Build forest binaries on Linux AMD64
  • GitHub Check: Diff snapshot export checks
  • GitHub Check: V1 snapshot export checks
🔇 Additional comments (7)
.github/workflows/forest.yml (2)

86-88: LGTM! Go test step is correctly configured.

The test command targets the correct path and will run the validator's unit tests during CI.


161-163: LGTM! Go setup is required for metrics validation.

The calibnet-check job correctly sets up Go before running the validation script that invokes the metrics validator.

tools/prometheus_metrics_validator/main.go (1)

15-43: LGTM! CLI implementation is clean and functional.

The CLI properly handles file reading, validation, and error reporting. The use of os.Exit(1) on validation failure is appropriate for a CLI tool.

tools/prometheus_metrics_validator/main_test.go (1)

9-45: LGTM! Test coverage is appropriate.

The tests cover key scenarios:

  • Metrics without EOF marker
  • Metrics with proper metadata (HELP, TYPE, UNIT) and EOF
  • Invalid syntax with unsupported characters

This provides good baseline coverage for the validator's core functionality.

scripts/tests/calibnet_other_check.sh (1)

83-85: LGTM! Metrics validation is properly integrated.

The script correctly:

  1. Downloads metrics from the Forest node
  2. Invokes the validator to check compatibility

Using go run is appropriate for the CI environment and keeps the script simple.

tools/prometheus_metrics_validator/go.mod (2)

6-6: Prometheus module tag and parser import are correct v0.306.0 maps to Prometheus v3.6.0; import the text parser from "github.com/prometheus/prometheus/model/textparse".


3-3: Go version 1.25.2 is valid The go version command downloads and runs go1.25.2 without error.

hanabi1224 and others added 2 commits October 12, 2025 18:53
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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.

Integration tests with Grafana scraper

1 participant