From dda11b915b7e7ecccc68dffcde529336c0a946e4 Mon Sep 17 00:00:00 2001 From: 3alpha <15694175+3alpha@users.noreply.github.com> Date: Mon, 30 Nov 2026 15:23:08 +0100 Subject: [PATCH 1/2] feat: add node status helpers for package healthchecks Shared shell helpers for the healthcheck scripts that print a node's status report: JSON-RPC calls, Prometheus metric lookup and report printing with the contract's limits. --- .github/workflows/test.yml | 16 ++ README.md | 57 +++++++ scripts/node_status_tools.sh | 232 +++++++++++++++++++++++++++ test/node_status_tools_test.sh | 283 +++++++++++++++++++++++++++++++++ 4 files changed, 588 insertions(+) create mode 100644 .github/workflows/test.yml create mode 100644 scripts/node_status_tools.sh create mode 100644 test/node_status_tools_test.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..50dc300 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,16 @@ +name: Test + +on: + pull_request: + +jobs: + node-status-tools: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Test with dash + run: sh test/node_status_tools_test.sh + + - name: Test with busybox ash + run: docker run --rm -v "$PWD:/w" -w /w alpine:3 sh -c 'apk add -q jq curl && sh test/node_status_tools_test.sh' diff --git a/README.md b/README.md index cfef7fd..ac82cb0 100644 --- a/README.md +++ b/README.md @@ -23,3 +23,60 @@ ADD https://raw.githubusercontent.com/dappnode/staker-package-scripts/${STAKER_S . /etc/profile ``` + +## Node status tools + +`node_status_tools.sh` holds the shared helpers for a package's Docker healthcheck script that prints a node status report: one compact JSON line, the last line of stdout, describing what the node is doing (state, phase, progress, blocks, peers, issues). Each package keeps its client-specific logic in its own script; these functions only call the node's JSON-RPC or HTTP API on `127.0.0.1` with short timeouts, read Prometheus metrics and print a report that always respects the size and field limits. They are POSIX `sh` (busybox ash, dash), depend only on `curl` and `jq` (1.6 or later), define functions only and print nothing on failure. + +```Docker +ADD ${STAKER_SCRIPTS_URL}/node_status_tools.sh /etc/profile.d/ +``` + +Environment: `NS_RPC_PORT` is the JSON-RPC port used by `ns_rpc` (default `8545`), `NS_TIMEOUT` the timeout in seconds of every request, also used as connect timeout (default `3`). + +| Function | Arguments | Output (stdout) | Exit status | +| --- | --- | --- | --- | +| `ns_rpc` | ` [params_json]` (default `[]`) | The JSON `result`, compact (`false` and `null` are valid results) | 0 ok, 1 no answer / not JSON / `error` in the reply, 2 invalid arguments | +| `ns_http_get` | `` starting with `http://127.0.0.1` or `http://localhost` | The body | 0 ok, 1 request failed or status not 2xx, 2 URL not local | +| `ns_metric` | ` [label=value ...]`, Prometheus text on stdin | Value of the first sample of `name` carrying all given labels, as a plain number (`2.4E7` gives `24000000`) | 0 found, 1 absent or NaN/Inf, 2 no name | +| `ns_hex_to_dec` | `<0x… or decimal>` | Decimal integer, up to 2^63-1 | 0 ok, 1 anything else | +| `ns_json_get` | ` [jq_filter]` (default `.`) | `jq -r` output (compact for objects), nothing when null or absent | 0 ok, non-zero for empty or invalid JSON or a failing filter | +| `ns_block_head` | none | `height= headTime=` of the latest block, to pass unquoted to `ns_emit` | 0 ok, 1 no answer or no block | +| `ns_emit` | ` [key=value ...]` | The report as one JSON line | 0 for `starting`, `syncing`, `synced`; 1 for `error`; 2 invalid state (nothing printed) | + +`ns_emit` states are `starting`, `syncing`, `synced` and `error`. Keys: `phase`, `progress`, `height`, `headTime`, `position`, `target`, `unit`, `peers`, `awaitingTarget` (only `true` is emitted), `background`, plus repeatable `issue=` and `detail=