Skip to content

Expose metrics server in tests without starting Prometheus agent / remote write #4362

@AminR443

Description

@AminR443

Context and scope

In test runs (e.g., re-execution), avalanchego only exposes metrics when METRICS_ENABLED is set. That path currently (a) starts a Prometheus agent configured for remote write and (b) opens a metrics HTTP server on a random port. For firewood re-execution tests, we want to pull metrics locally (scrape /ext/metrics) without starting Prometheus agent/remote write and need a deterministic way to discover or set the listen port. We need these changes so we can configure our own Prometheus to scrape from it and monitor the metrics using Grafana during the re-execution test.

References:

  • random port bind in tests:
    const defaultPrometheusListenAddr = "127.0.0.1:0"
  • metrics-enabled path that starts both agent and server:
    func collectRegistry(tb testing.TB, name string, timeout time.Duration, gatherer prometheus.Gatherer, labels map[string]string) {
    r := require.New(tb)
    ctx, cancel := context.WithTimeout(context.Background(), timeout)
    tb.Cleanup(cancel)
    r.NoError(tmpnet.StartPrometheus(ctx, tests.NewDefaultLogger("prometheus")))
    server, err := tests.NewPrometheusServer(gatherer)
    r.NoError(err)
    var sdConfigFilePath string

Discussion and alternatives

Proposed code changes:

  • Refactor test metrics setup so the HTTP server and Prometheus agent can be started independently.
  • Support explicit port for metrics.

We can do this in two ways:

  1. Split env toggles: METRICS_SERVER_ENABLED / METRICS_PUSH_ENABLED.
  2. Mode selector: METRICS_MODE=server|push|both.

We could also add METRICS_PORT or agree on a constant to use instead of 0.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions