diff --git a/.env.example b/.env.example index af83228..1ff6263 100644 --- a/.env.example +++ b/.env.example @@ -1,8 +1,8 @@ export RELAYS=wss://offchain.pub,wss://nostr.bitcoiner.social # 0 = run probes on each /metrics scrape; set >0 for periodic background probing. -# Example: 300000 = every 5 minutes. -export PROBE_INTERVAL_MS=300000 -export PROBE_TIMEOUT_MS=10000 +# Example: 300 = every 5 minutes. +export PROBE_INTERVAL_SECONDS=300 +export PROBE_TIMEOUT_SECONDS=10 export LISTEN_ADDR=0.0.0.0 export PORT=9464 export LOG_LEVEL=info diff --git a/README.md b/README.md index 28bdc93..87b4878 100644 --- a/README.md +++ b/README.md @@ -36,14 +36,14 @@ cp .env.example .env Example: run probes every 5 minutes instead of on each scrape: ```bash -export PROBE_INTERVAL_MS=300000 +export PROBE_INTERVAL_SECONDS=300 ``` Environment variables: - `RELAYS` (required): comma-separated `wss://` URLs -- `PROBE_INTERVAL_MS` (default: `0`; `0` means run probes on each `/metrics` scrape) -- `PROBE_TIMEOUT_MS` (default: `10000`) +- `PROBE_INTERVAL_SECONDS` (default: `0`; `0` means run probes on each `/metrics` scrape) +- `PROBE_TIMEOUT_SECONDS` (default: `10`) - `LISTEN_ADDR` (default: `0.0.0.0`) - `PORT` (default: `9464`) - `LOG_LEVEL` (default: `info`; one of `debug|info|warn|error`) diff --git a/src/config.ts b/src/config.ts index 3c76fdd..6c57c7f 100644 --- a/src/config.ts +++ b/src/config.ts @@ -27,15 +27,16 @@ export interface AppConfig { warnings: string[]; } -const DEFAULT_PROBE_INTERVAL_MS = 0; -const DEFAULT_PROBE_TIMEOUT_MS = 10_000; +const MS_PER_SECOND = 1_000; +const DEFAULT_PROBE_INTERVAL_SECONDS = 0; +const DEFAULT_PROBE_TIMEOUT_SECONDS = 10; const DEFAULT_LISTEN_ADDR = "0.0.0.0"; const DEFAULT_PORT = 9464; const DEFAULT_LOG_LEVEL: LogLevel = "info"; const DEFAULT_WRITE_CHECK_ENABLED = true; const DEFAULT_WRITE_CHECK_KIND = 30078; -const MIN_TIMEOUT_MS = 1_000; +const MIN_TIMEOUT_SECONDS = 1; const MIN_PORT = 1; const MAX_PORT = 65_535; @@ -149,18 +150,20 @@ export function loadConfig(env: NodeJS.ProcessEnv = process.env): AppConfig { throw new Error("RELAYS did not contain any valid wss:// relay URLs"); } - const probeIntervalMs = parseInteger( - env.PROBE_INTERVAL_MS, - DEFAULT_PROBE_INTERVAL_MS, + const probeIntervalSeconds = parseInteger( + env.PROBE_INTERVAL_SECONDS, + DEFAULT_PROBE_INTERVAL_SECONDS, 0, - "PROBE_INTERVAL_MS", + "PROBE_INTERVAL_SECONDS", ); - const probeTimeoutMs = parseInteger( - env.PROBE_TIMEOUT_MS, - DEFAULT_PROBE_TIMEOUT_MS, - MIN_TIMEOUT_MS, - "PROBE_TIMEOUT_MS", + const probeTimeoutSeconds = parseInteger( + env.PROBE_TIMEOUT_SECONDS, + DEFAULT_PROBE_TIMEOUT_SECONDS, + MIN_TIMEOUT_SECONDS, + "PROBE_TIMEOUT_SECONDS", ); + const probeIntervalMs = probeIntervalSeconds * MS_PER_SECOND; + const probeTimeoutMs = probeTimeoutSeconds * MS_PER_SECOND; const port = parseInteger(env.PORT, DEFAULT_PORT, MIN_PORT, "PORT"); if (port > MAX_PORT) { throw new Error(`PORT must be <= ${MAX_PORT}`); diff --git a/test/smoke.test.ts b/test/smoke.test.ts index c30aa7c..eadf8b5 100644 --- a/test/smoke.test.ts +++ b/test/smoke.test.ts @@ -71,8 +71,8 @@ test("exporter serves healthz and metrics without crashing", async (t) => { ...process.env, RELAYS: "wss://relay.damus.io,wss://nos.lol", WRITE_CHECK_ENABLED: "false", - PROBE_TIMEOUT_MS: "2000", - PROBE_INTERVAL_MS: "3000", + PROBE_TIMEOUT_SECONDS: "2", + PROBE_INTERVAL_SECONDS: "3", PORT: String(port), LOG_LEVEL: "error", },