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.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 10, 2025

Walkthrough

Adds a new Go-based Prometheus metrics validator (with tests and go.mod/.gitignore), CI steps to set up Go and run its tests, appends metrics fetching and validation to the calibnet test script, and documents local usage in tools/README.md.

Changes

Cohort / File(s) Summary
CI workflow updates
.github/workflows/forest.yml
Add actions/setup-go@v6 to the calibnet-check job (uses go-version-file: "go.work") and add a go test -v ./tools/prometheus_metrics_validator step in the Ubuntu build job.
Calibnet test script
scripts/tests/calibnet_other_check.sh
Append steps that fetch http://localhost:6116/metrics to metrics.log and run the Prometheus validator via go run against that file.
Tools docs
tools/README.md
Add "Unit tests" and "Validate Forest metrics" instructions showing go test -v ., how to curl metrics into a file, and how to 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
New Go CLI validator exposing Validate(metrics []byte) error, unit tests for valid/invalid inputs, module dependencies in go.mod, and .gitignore entries for metrics/metrics.txt.

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
  • sudo-shashank

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 pull request title "test: validate metrics compatibility with Grafana scrapper" directly and clearly summarizes the main objective of the changeset. The title accurately reflects the introduction of a new metrics validator tool and its integration into the test suite to ensure Prometheus metrics are compatible with Grafana scrapers. The title is concise, specific, and provides sufficient context for a teammate scanning the commit history to understand the primary change without needing to review the full changeset details.
Linked Issues Check ✅ Passed The pull request successfully addresses the completion criteria from linked issue #6064. The changes introduce a new Prometheus metrics validator tool (tools/prometheus_metrics_validator/main.go) with a Validate() function that parses and validates Prometheus metric format. Integration tests are added to exercise this validator, and the validation is integrated into the CI workflow (via .github/workflows/forest.yml) and post-processing checks (via scripts/tests/calibnet_other_check.sh). These changes fulfill the requirement to "introduce integration tests that would assert that scraper works correctly" by providing a means to validate metrics compatibility with Prometheus/Grafana scrapers as part of the test pipeline.
Out of Scope Changes Check ✅ Passed All changes in this pull request are directly aligned with the objectives defined in linked issue #6064. The modifications include the new validator tool implementation, its unit tests, CI/workflow integration, documentation, and supporting configuration files—all essential components for establishing metrics validation in the Forest project. No extraneous changes or work unrelated to the metrics validation objective are present in the changeset.
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 45b1d8c and f80f720.

📒 Files selected for processing (1)
  • .github/workflows/forest.yml (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/forest.yml

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.

@akaladarshi
Copy link
Collaborator

@hanabi1224 CI check is failing

Copy link
Member

@LesnyRumcajs LesnyRumcajs left a comment

Choose a reason for hiding this comment

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

@hanabi1224 Could you please verify that this check fails on the Forest version (AFAIR the one that was used for NV27 calibnet) that had invalid characters in the metrics?

@hanabi1224
Copy link
Contributor Author

@LesnyRumcajs
Copy link
Member

@LesnyRumcajs I believe the invalid chars have been covered by this unit test: https://github.com/ChainSafe/forest/pull/6150/files#diff-086c82375fc31c5ee660c5cf4ab8b7da381735d9bf6cbed910f53f4333465d16R37

Yeah, but the unit test is a synthetic case here. I'd like to confirm that the test fails when Forest reports bad metrics. A one off manual check would suffice.

@hanabi1224
Copy link
Contributor Author

I'd like to confirm that the test fails when Forest reports bad metrics. A one off manual check would suffice.

@LesnyRumcajs Sure. I just grabbed metrics from https://github.com/ChainSafe/forest/actions/runs/17643806179/job/50137364758#step:8:3557 (CI for the commit before the metrics fix) and run the tool against it.

➜  prometheus_metrics_validator git:(hm/metrics-validation) go run -v . metrics
Validation failed: invalid metric type "receipt>_7_size_bytes gauge"
exit status 1

Copy link
Member

@LesnyRumcajs LesnyRumcajs left a comment

Choose a reason for hiding this comment

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

LGTM!

@hanabi1224 hanabi1224 enabled auto-merge October 21, 2025 10:09
@hanabi1224 hanabi1224 added this pull request to the merge queue Oct 22, 2025
Merged via the queue into main with commit fbb333c Oct 22, 2025
51 checks passed
@hanabi1224 hanabi1224 deleted the hm/metrics-validation branch October 22, 2025 13:15
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

4 participants