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 new Go-based Prometheus metrics validator tool, test coverage, CI steps to run the tool's tests and set up Go, appends metrics validation to the calibnet test script, and documents local usage and .gitignore entries for metric files.

Changes

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

Suggested labels

github_actions, dependencies

Suggested reviewers

  • elmattic
  • akaladarshi
  • LesnyRumcajs

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 succinctly captures the main purpose of the PR by indicating that tests are being added to validate metrics compatibility with Grafana scrapper, aligning with the key change of integrating a validation tool and test steps, and it is clear and specific without extraneous details.
Linked Issues Check ✅ Passed The PR directly implements the linked issue by adding a Prometheus metrics validator CLI, integration test steps that fetch and validate live metrics from the running Forest instance, and corresponding CI workflow updates, fully satisfying the requirement to assert that Grafana scrapers can successfully read the exported metrics.
Out of Scope Changes Check ✅ Passed All introduced changes—including the new validator tool, test script enhancements, CI workflow adjustments, and documentation updates—are directly related to validating metrics compatibility and there are no unrelated or extraneous modifications present.
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 7737ceb and 45b1d8c.

📒 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
⏰ 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: Build Ubuntu
  • GitHub Check: cargo-publish-dry-run
  • GitHub Check: Build MacOS
  • GitHub Check: tests
  • GitHub Check: tests-release
  • GitHub Check: Build forest binaries on Linux AMD64
  • GitHub Check: All lint checks

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

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

2 participants