datahaven/test/package.json
Ahmad Kaouk b08570b645
feat: add Prometheus metrics and debug logging to submitter (#456)
## Summary

Adds production observability to the validator set submitter:

- **Prometheus metrics** via `prom-client` exposed on a configurable
HTTP port (default `:9090`)
- **Debug-level logging** for all silent skip paths in the tick handler
- **Health endpoints** for container orchestration (`/healthz` liveness,
`/readyz` readiness)

## Metrics

All metrics use the `validator_set_submitter_` prefix.

**Counters:** `submissions_total{outcome}`, `ticks_total{result}`,
`errors_total{type}`, `missed_eras_total`

**Gauges:** `active_era`, `target_era`, `external_index`,
`current_session`, `last_submitted_era`, `consecutive_missed_eras`,
`up`, `ready`

**Histograms:** `submission_duration_seconds`, `tick_duration_seconds`

## Changes

- **`metrics.ts`** (new): Metric definitions, dedicated `Registry` (no
`collectDefaultMetrics()` to avoid Bun compatibility issue),
`Bun.serve()` HTTP server with `/metrics`, `/healthz`, `/readyz`
- **`config.ts`**: Add `metricsPort` field, resolved from CLI > env >
YAML > default 9090
- **`submitter.ts`**: Instrument all tick/submission paths with metrics;
add `logger.debug()` for skip paths (already submitted, already
confirmed, not last session); track consecutive and total missed eras
- **`main.ts`**: Add `--metrics-port` CLI option, start metrics server
early (before startup checks), stop in `finally` block
- **`config.yml`**: Document `metrics_port` option
- **`Dockerfile`**: Add `EXPOSE 9090`
- **`README.md`**: Document observability section
- **`package.json`**: Add `prom-client ^15.1.0`

## Design decisions

- Uses a dedicated `Registry` instance instead of
`collectDefaultMetrics()` which crashes on Bun due to missing
`monitorEventLoopDelay`
- Timers always closed via `try/finally` to ensure histograms record
even on errors or early returns
- `submissions_total{outcome}` is the single source of truth for
submission results; `errors_total` only tracks non-submission errors
(tick_error, subscription_error)
- Metrics server starts before startup checks so `/healthz` is available
during init; `/readyz` returns 503 until startup completes

## Test plan

- [x] `bun typecheck` passes
- [x] `bun biome check` passes on changed files
- [x] Manual smoke test: launched local network, ran submitter with
`LOG_LEVEL=debug`, verified `/metrics` returns correct Prometheus
output, `/healthz` returns 200, `/readyz` returns 200 after startup
- [x] Verified counters increment correctly across multiple tick cycles

---------

Co-authored-by: Gonza Montiel <gonzamontiel@users.noreply.github.com>
2026-03-03 11:06:59 +00:00

90 lines
4.3 KiB
JSON

{
"name": "@datahaven/e2e-test",
"module": "index.ts",
"type": "module",
"private": true,
"scripts": {
"cli": "bun run cli/index.ts",
"fmt": "biome check .",
"fmt:fix": "biome check --write .",
"build:docker:operator": "docker build --no-cache --platform linux/amd64 -t datahavenxyz/datahaven:local -f ../docker/datahaven-dev.Dockerfile ../.",
"generate:wagmi": "wagmi generate",
"generate:snowbridge-cfgs": "bun -e \"import {generateSnowbridgeConfigs} from './scripts/gen-snowbridge-cfgs.ts'; await generateSnowbridgeConfigs()\"",
"generate:contracts": "bun -e \"import {generateContracts} from './scripts/generate-contracts.ts'; await generateContracts()\"",
"generate:types": "(cd ../operator && cargo build --release) && bun x papi add --wasm \"../operator/target/release/wbuild/datahaven-stagenet-runtime/datahaven_stagenet_runtime.wasm\" datahaven",
"generate:types:fast": "(cd ../operator && cargo build --release --features fast-runtime) && bun x papi add --wasm \"../operator/target/release/wbuild/datahaven-stagenet-runtime/datahaven_stagenet_runtime.wasm\" datahaven",
"start:e2e:verified": "bun cli launch --verified --blockscout --deploy-contracts --setup-validators --update-validator-set --fund-validators",
"start:e2e:verified:relayers": "bun cli launch --verified --blockscout --deploy-contracts --setup-validators --update-validator-set --fund-validators --relayer --datahaven",
"start:e2e:local": "LOG_LEVEL=debug bun start:e2e:ci --bd",
"start:e2e:ci": "bun cli launch --datahaven --no-build-datahaven --launch-kurtosis --deploy-contracts --fund-validators --setup-validators --update-validator-set --set-parameters --relayer --clean-network --slot-time 1",
"start:e2e:minrelayer": "bun cli launch --relayer --deploy-contracts --no-setup-validators --no-update-validator-set --no-fund-validators --datahaven",
"stop:docker:datahaven": "docker rm -f $(docker ps -aq --filter name='^datahaven-') 2>/dev/null || true; docker network rm datahaven-net || true",
"stop:docker:relayer": "docker rm -f $(docker ps -aq --filter name='^snowbridge-') 2>/dev/null || true",
"stop:e2e": "bun cli stop --all",
"stop:dh": "bun cli stop --datahaven --no-enclave --no-relayer ",
"stop:sb": "bun cli stop --relayer --no-datahaven --no-enclave",
"stop:eth": "bun cli stop --enclave --no-datahaven --no-relayer",
"stop:engine": "bun cli stop --kurtosisEngine --no-datahaven --no-relayer --no-enclave",
"test:e2e": "bun test ./e2e/suites --timeout 900000",
"compile:contracts": "bun x tsx scripts/compile-contracts.ts compile",
"test:e2e:parallel": "bun scripts/test-parallel.ts",
"moonwall:test": "moonwall test dev_datahaven",
"moonwall:run": "moonwall run dev_datahaven",
"submitter": "bun run tools/validator-set-submitter/main.ts run",
"submitter:dry-run": "bun run tools/validator-set-submitter/main.ts run --dry-run",
"typecheck": "tsc --noEmit",
"tsgo": "tsgo tsc --noEmit --pretty --skipLibCheck",
"postinstall": "papi"
},
"devDependencies": {
"@types/bun": "latest",
"@types/yargs": "^17.0.33",
"@typescript/native-preview": "^7.0.0-dev.20250618.1"
},
"peerDependencies": {
"typescript": "^5.8.3"
},
"dependencies": {
"@biomejs/biome": "^2.0.0",
"@commander-js/extra-typings": "^13.1.0",
"@dotenvx/dotenvx": "^1.44.2",
"@inquirer/prompts": "^7.5.3",
"@moonwall/cli": "^5.15.0",
"@moonwall/util": "^5.15.0",
"@noble/curves": "^1.9.2",
"@noble/hashes": "^1.8.0",
"@polkadot-api/descriptors": "file:.papi/descriptors",
"@types/dockerode": "^3.3.41",
"@types/node": "^22.15.32",
"@wagmi/cli": "^2.3.1",
"@wagmi/core": "^2.17.3",
"chalk": "^5.4.1",
"commander": "^13.1.0",
"dockerode": "^4.0.7",
"dotenv": "^16.5.0",
"ethers": "^6.13.4",
"octokit": "^4.1.4",
"ora": "^8.2.0",
"pino": "^9.7.0",
"pino-pretty": "^13.0.0",
"polkadot-api": "^1.15.1",
"prom-client": "^15.1.0",
"solc": "^0.8.30",
"tiny-invariant": "^1.3.3",
"viem": "^2.31.3",
"wagmi": "^2.15.6",
"yaml": "^2.8.0",
"yargs": "^18.0.0",
"zod": "^3.25.67"
},
"trustedDependencies": [
"@biomejs/biome",
"bufferutil",
"cpu-features",
"esbuild",
"keccak",
"protobufjs",
"ssh2",
"utf-8-validate"
]
}