Skip to content

Feat/network label consistency - #560

Merged
AbdulmalikAlayande merged 3 commits into
TegoLabs:mainfrom
GazzyLee:feat/network-label-consistency
Jul 31, 2026
Merged

AbdulmalikAlayande merged 3 commits into
TegoLabs:mainfrom
GazzyLee:feat/network-label-consistency

Conversation

@GazzyLee

Copy link
Copy Markdown
Contributor

Summary

Adds a network label to the sorokeep_budget_remaining_xlm metric so testnet and mainnet contracts can be distinguished in dashboards. Without this, a TTL crisis on testnet and one on mainnet produce identical signals on shared Grafana panels.

Changes

src/observability/metrics/budget.ts

  • Added "network" to labelNames on budgetRemainingGauge
  • Pass network: contract.network in the .set() call
  • Added a header comment documenting the labeling convention for future metrics

tests/observability/metrics/budget.test.ts

  • Updated existing test to assert network: "testnet" on the sample
  • Added new test verifying mainnet contracts get network: "mainnet"
  • Added regression test that iterates over register.getMetricsAsArray() and asserts every sample carries a network label — this will catch any future metric that omits the label

Testing

  • Ran full test suite: 78 test files, 999 tests passed, 1 skipped (pre-existing skip)
  • All 4 new/modified tests pass

Labeling Convention

Documented in budget.ts:

Every metric MUST include a network label set to the contract's network (e.g. "testnet" or "mainnet"). The value MUST come from the network column of the contracts table. When adding a new metric, include "network" in the labelNames array and pass network: contract.network in the .set() / .inc() / .observe() call.

Closes #346

@drips-wave

drips-wave Bot commented Jul 29, 2026

Copy link
Copy Markdown

@GazzyLee Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@coderabbitai

coderabbitai Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@GazzyLee, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 45 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: a5827bdd-ce35-4f7f-9c08-c8660b656d3a

📥 Commits

Reviewing files that changed from the base of the PR and between 040aba3 and 827891e.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (4)
  • package.json
  • src/observability/metrics/budget.ts
  • src/observability/registry.ts
  • tests/observability/metrics/budget.test.ts
📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added Prometheus monitoring for remaining monthly XLM budget by contract and network.
    • Metrics now distinguish between testnet and mainnet environments.
    • Added centralized metric registration for observability integrations.
  • Bug Fixes

    • Contracts without configured budgets are excluded from budget-remaining metrics.
  • Chores

    • Updated dependency configuration to support the new monitoring capabilities and maintain consistent package versions.

Walkthrough

Adds a Prometheus gauge for remaining monthly XLM budget, registers it in a shared observability registry, pins glob, adds prom-client, and introduces SQLite-backed tests for budget calculations and network labels.

Changes

Budget observability

Layer / File(s) Summary
Metric dependency and collection
package.json, src/observability/metrics/budget.ts
Adds prom-client and computes limit - spend for each contract using contract_id and network labels.
Shared registry wiring
src/observability/registry.ts
Creates and exports a Prometheus registry containing the budget gauge.
Metric collection tests
tests/observability/metrics/budget.test.ts
Validates remaining values, network labels, missing budgets, and labeling conventions across registered metrics.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related issues

  • Issue 335 — Adds a related Prometheus gauge through the shared observability registry.
  • Issue 347 — Covers the same budget-remaining gauge and registry integration.

Possibly related PRs

Suggested reviewers: abdulmalikalayande

Poem

A rabbit watched the budgets glow,
With testnet, mainnet labels in a row.
“Less spend means more to spare!”
Prometheus hops through the air.
The registry keeps each metric fair.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR adds a new metric and changes registry structure, exceeding the issue's scope of labeling existing metrics only. Limit the change to existing metrics under src/observability/metrics and avoid registry structure changes or new metric additions.
Out of Scope Changes check ⚠️ Warning The PR includes unrelated package.json override/dependency changes and registry restructuring beyond the labeling-consistency objective. Remove the npm override/dependency cleanup and keep changes limited to the network-label fix and its tests.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately describes the network-label consistency change.
Description check ✅ Passed The description matches the metric-labeling update and related test coverage.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@gitguardian

gitguardian Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

️✅ There are no secrets present in this pull request anymore.

If these secrets were true positive and are still valid, we highly recommend you to revoke them.
While these secrets were previously flagged, we no longer have a reference to the
specific commits where they were detected. Once a secret has been leaked into a git
repository, you should consider it compromised, even if it was deleted immediately.
Find here more information about risks.


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

GazzyLee added 3 commits July 30, 2026 13:07
…et headroom

- Create src/observability/registry.ts with Prometheus registry
- Create src/observability/metrics/budget.ts with
  sorokeep_budget_remaining_xlm gauge (label: contract_id)
- Wire gauge into registry with one import + one registration line
- Only emit metric for contracts that have a configured budget
- Use existing getMonthlySpendProgress from core/budget.ts + repository
  functions -- no new SQL
- Add TDD tests (both passing):
  · Contract with  limit and  spend → remaining = 20
  · Contract with no budget → no sample emitted
…signals

- Add 'network' to budgetRemainingGauge labelNames
- Pass contract.network when setting the gauge value
- Update tests to assert network label presence (testnet + mainnet)
- Add regression test asserting every metric family includes a network label
- Document the labeling convention in the metrics source file

Closes #<issue>
@GazzyLee
GazzyLee force-pushed the feat/network-label-consistency branch from 040aba3 to 827891e Compare July 30, 2026 12:10
@AbdulmalikAlayande
AbdulmalikAlayande merged commit 9f3eee4 into TegoLabs:main Jul 31, 2026
2 checks passed
@AbdulmalikAlayande

Copy link
Copy Markdown
Collaborator

Merged as 2fca7f5 on main. Establishes the network-label convention (every Prometheus metric must carry a network label) with a concrete working example — the budget-remaining gauge. Since the base /metrics scaffold (#330) hasn't landed yet, this bootstraps a minimal registry.ts; expect that to get reconciled when #330 merges. Verified locally: lint, typecheck, full suite (1118/1118), build, and audit all clean.

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.

feat(observability): add per-network metric labels (testnet/mainnet)

2 participants