Change interval unit type to seconds

This commit is contained in:
pleb 2026-03-22 16:02:18 -07:00
parent 0531a23680
commit dc5023d272
4 changed files with 23 additions and 20 deletions

View File

@ -1,8 +1,8 @@
export RELAYS=wss://offchain.pub,wss://nostr.bitcoiner.social export RELAYS=wss://offchain.pub,wss://nostr.bitcoiner.social
# 0 = run probes on each /metrics scrape; set >0 for periodic background probing. # 0 = run probes on each /metrics scrape; set >0 for periodic background probing.
# Example: 300000 = every 5 minutes. # Example: 300 = every 5 minutes.
export PROBE_INTERVAL_MS=300000 export PROBE_INTERVAL_SECONDS=300
export PROBE_TIMEOUT_MS=10000 export PROBE_TIMEOUT_SECONDS=10
export LISTEN_ADDR=0.0.0.0 export LISTEN_ADDR=0.0.0.0
export PORT=9464 export PORT=9464
export LOG_LEVEL=info export LOG_LEVEL=info

View File

@ -36,14 +36,14 @@ cp .env.example .env
Example: run probes every 5 minutes instead of on each scrape: Example: run probes every 5 minutes instead of on each scrape:
```bash ```bash
export PROBE_INTERVAL_MS=300000 export PROBE_INTERVAL_SECONDS=300
``` ```
Environment variables: Environment variables:
- `RELAYS` (required): comma-separated `wss://` URLs - `RELAYS` (required): comma-separated `wss://` URLs
- `PROBE_INTERVAL_MS` (default: `0`; `0` means run probes on each `/metrics` scrape) - `PROBE_INTERVAL_SECONDS` (default: `0`; `0` means run probes on each `/metrics` scrape)
- `PROBE_TIMEOUT_MS` (default: `10000`) - `PROBE_TIMEOUT_SECONDS` (default: `10`)
- `LISTEN_ADDR` (default: `0.0.0.0`) - `LISTEN_ADDR` (default: `0.0.0.0`)
- `PORT` (default: `9464`) - `PORT` (default: `9464`)
- `LOG_LEVEL` (default: `info`; one of `debug|info|warn|error`) - `LOG_LEVEL` (default: `info`; one of `debug|info|warn|error`)

View File

@ -27,15 +27,16 @@ export interface AppConfig {
warnings: string[]; warnings: string[];
} }
const DEFAULT_PROBE_INTERVAL_MS = 0; const MS_PER_SECOND = 1_000;
const DEFAULT_PROBE_TIMEOUT_MS = 10_000; const DEFAULT_PROBE_INTERVAL_SECONDS = 0;
const DEFAULT_PROBE_TIMEOUT_SECONDS = 10;
const DEFAULT_LISTEN_ADDR = "0.0.0.0"; const DEFAULT_LISTEN_ADDR = "0.0.0.0";
const DEFAULT_PORT = 9464; const DEFAULT_PORT = 9464;
const DEFAULT_LOG_LEVEL: LogLevel = "info"; const DEFAULT_LOG_LEVEL: LogLevel = "info";
const DEFAULT_WRITE_CHECK_ENABLED = true; const DEFAULT_WRITE_CHECK_ENABLED = true;
const DEFAULT_WRITE_CHECK_KIND = 30078; const DEFAULT_WRITE_CHECK_KIND = 30078;
const MIN_TIMEOUT_MS = 1_000; const MIN_TIMEOUT_SECONDS = 1;
const MIN_PORT = 1; const MIN_PORT = 1;
const MAX_PORT = 65_535; 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"); throw new Error("RELAYS did not contain any valid wss:// relay URLs");
} }
const probeIntervalMs = parseInteger( const probeIntervalSeconds = parseInteger(
env.PROBE_INTERVAL_MS, env.PROBE_INTERVAL_SECONDS,
DEFAULT_PROBE_INTERVAL_MS, DEFAULT_PROBE_INTERVAL_SECONDS,
0, 0,
"PROBE_INTERVAL_MS", "PROBE_INTERVAL_SECONDS",
); );
const probeTimeoutMs = parseInteger( const probeTimeoutSeconds = parseInteger(
env.PROBE_TIMEOUT_MS, env.PROBE_TIMEOUT_SECONDS,
DEFAULT_PROBE_TIMEOUT_MS, DEFAULT_PROBE_TIMEOUT_SECONDS,
MIN_TIMEOUT_MS, MIN_TIMEOUT_SECONDS,
"PROBE_TIMEOUT_MS", "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"); const port = parseInteger(env.PORT, DEFAULT_PORT, MIN_PORT, "PORT");
if (port > MAX_PORT) { if (port > MAX_PORT) {
throw new Error(`PORT must be <= ${MAX_PORT}`); throw new Error(`PORT must be <= ${MAX_PORT}`);

View File

@ -71,8 +71,8 @@ test("exporter serves healthz and metrics without crashing", async (t) => {
...process.env, ...process.env,
RELAYS: "wss://relay.damus.io,wss://nos.lol", RELAYS: "wss://relay.damus.io,wss://nos.lol",
WRITE_CHECK_ENABLED: "false", WRITE_CHECK_ENABLED: "false",
PROBE_TIMEOUT_MS: "2000", PROBE_TIMEOUT_SECONDS: "2",
PROBE_INTERVAL_MS: "3000", PROBE_INTERVAL_SECONDS: "3",
PORT: String(port), PORT: String(port),
LOG_LEVEL: "error", LOG_LEVEL: "error",
}, },