Skip to content

fix(prometheus): tolerate malformed exporter env#7557

Open
yyswhsccc wants to merge 1 commit into
Scottcjn:mainfrom
yyswhsccc:codex/prometheus-exporter-env-guard
Open

fix(prometheus): tolerate malformed exporter env#7557
yyswhsccc wants to merge 1 commit into
Scottcjn:mainfrom
yyswhsccc:codex/prometheus-exporter-env-guard

Conversation

@yyswhsccc

Copy link
Copy Markdown
Contributor

Problem

prometheus_exporter.py parsed PROMETHEUS_EXPORTER_PORT and SCRAPE_INTERVAL directly at import time. A malformed deployment env value raises ValueError before the exporter can fall back or start.

Impact

A single bad numeric env value can crash the RustChain Prometheus exporter during startup, removing metrics visibility until the environment is corrected.

Fix

Add a small local _safe_int_env helper that logs malformed numeric env values and falls back to the existing defaults. Valid numeric env overrides are preserved.

Tests

  • uv run --no-project --with pytest --with flask --with requests python -B -m pytest -q tests/test_prometheus_exporter_security.py -> 5 passed
  • python3 -m py_compile prometheus_exporter.py tests/test_prometheus_exporter_security.py -> passed
  • git diff --check -> passed

Boundaries

Related to the general bug bounty surface (#305). This PR does not change payout amounts, wallet crediting, admin secrets, or production wallet behavior.

wallet: RTC47bc28896a1a4bf240d1fd780f4559b242bcd945

@github-actions github-actions Bot added BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) tests Test suite changes size/S PR: 11-50 lines labels Jun 23, 2026
@yyswhsccc

Copy link
Copy Markdown
Contributor Author

@Scottcjn Please take a look when you have a chance. This is a small startup hardening fix for the Prometheus exporter: malformed numeric env values now fall back to existing defaults instead of crashing import/startup.

Validation:

  • uv run --no-project --with pytest --with flask --with requests python -B -m pytest -q tests/test_prometheus_exporter_security.py -> 5 passed
  • python3 -m py_compile prometheus_exporter.py tests/test_prometheus_exporter_security.py -> passed
  • git diff --check -> passed

@jaxint jaxint left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Code reviewed - implementation verified.

@jaxint jaxint left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Code reviewed - implementation verified. Good work on the changes.

@jaxint

jaxint commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Good addition! This will be useful for the project.

Reviewed for Bounty #71
Wallet: AhqbFaPBPLMMiaLDzA9WhQcyvv4hMxiteLhPk3NhG1iG

@jaxint jaxint left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Code reviewed - implementation verified. Per bounty #71.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) size/S PR: 11-50 lines tests Test suite changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants