signalk-grafana 0.1.13 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +93 -0
- package/CLAUDE.md +1 -0
- package/README.md +15 -12
- package/dist/full-export.d.ts +16 -0
- package/dist/full-export.js +330 -0
- package/dist/full-export.js.map +1 -0
- package/dist/index.js +108 -54
- package/dist/index.js.map +1 -1
- package/dist/provisioning.d.ts +5 -0
- package/dist/provisioning.js +34 -9
- package/dist/provisioning.js.map +1 -1
- package/dist/rehydrate.d.ts +7 -0
- package/dist/rehydrate.js +31 -0
- package/dist/rehydrate.js.map +1 -0
- package/dist/test/full-export.test.d.ts +1 -0
- package/dist/test/full-export.test.js +285 -0
- package/dist/test/full-export.test.js.map +1 -0
- package/dist/test/provisioning.test.js +58 -3
- package/dist/test/provisioning.test.js.map +1 -1
- package/dist/test/rehydrate.test.d.ts +1 -0
- package/dist/test/rehydrate.test.js +86 -0
- package/dist/test/rehydrate.test.js.map +1 -0
- package/docs/screenshot/signalk_grafana_1.png +0 -0
- package/docs/screenshot/signalk_grafana_2.png +0 -0
- package/package.json +6 -2
- package/public/805.js +1 -1
package/AGENTS.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
Notes for AI coding agents working on this repository. Human-facing usage and dashboard examples live in [README.md](README.md); this file is the orientation an agent needs before making non-trivial changes.
|
|
4
|
+
|
|
5
|
+
## What this is
|
|
6
|
+
|
|
7
|
+
A Signal K server plugin that runs Grafana in a Podman/Docker container and auto-provisions both QuestDB and Signal K datasources via YAML, so opening Grafana for the first time shows a working setup. The plugin itself does not embed Grafana — it delegates container lifecycle to a sibling plugin.
|
|
8
|
+
|
|
9
|
+
## Companion plugins (hard runtime dependencies)
|
|
10
|
+
|
|
11
|
+
The plugin will refuse to start without these — they are listed in `package.json` under `signalk.requires`:
|
|
12
|
+
|
|
13
|
+
- **signalk-container** — provides the global `__signalk_containerManager` API used to create networks, pull images, start/stop/exec containers, and detect runtime (Podman vs Docker, host vs containerized Signal K). All container ops in [src/index.ts](src/index.ts) go through it.
|
|
14
|
+
- **signalk-questdb** — provides the QuestDB time-series store at `sk-signalk-questdb:8812` on the shared network. The QuestDB datasource YAML hard-codes that DNS name; if the user renames the QuestDB container, the QuestDB plugin's name must match `config.questdbContainerName`.
|
|
15
|
+
|
|
16
|
+
## File layout
|
|
17
|
+
|
|
18
|
+
- [src/index.ts](src/index.ts) — plugin entrypoint. Three responsibilities:
|
|
19
|
+
1. `asyncStart(config)` — wait for `__signalk_containerManager`, ensure network, generate provisioning, recreate the container if its config-hash changed, start it, then exec the admin-password reset. The Grafana env passes `GF_INSTALL_PLUGINS=tkurki-signalk-datasource` so the Signal K datasource plugin loads on first boot.
|
|
20
|
+
2. `registerWithRouter(router)` — exposes `/api/status`, `/api/versions`, `/api/update/check`, `/api/update/apply`, `/api/set-password`. `/api/status` resolves the Signal K datasource UID by name then probes through the Grafana proxy at `/signalk` to report reachability + server version. The config panel polls it every 5s. `/api/set-password` writes the new password back into `currentConfig.adminPassword` so the probe keeps authenticating.
|
|
21
|
+
3. `stop()` — best-effort container stop, clears `currentConfig`.
|
|
22
|
+
- [src/provisioning.ts](src/provisioning.ts) — generates `provisioning/datasources/*.yaml` under `app.getDataDirPath()`. Both datasources are YAML-provisioned. `resolveSignalkEndpoint(config)` parses `config.signalkUrl` with `new URL()`, preserves `http`/`https`, defaults to `http://host.containers.internal:${process.env.PORT}` when no override is set, and throws on non-http(s) schemes (catches typos like `htps://`).
|
|
23
|
+
- [src/config/schema.ts](src/config/schema.ts) — typebox schema → Signal K admin UI form. Adding a config field starts here.
|
|
24
|
+
- [src/configpanel/PluginConfigurationPanel.js](src/configpanel/PluginConfigurationPanel.js) — React (19) panel rendered inside Signal K admin. JavaScript, not TypeScript; bundled by webpack via `module federation` so React is shared with the host.
|
|
25
|
+
- [src/test/provisioning.test.ts](src/test/provisioning.test.ts) — `node:test`, no test framework. Tests run against the compiled `dist/` (`node --test 'dist/test/**/*.test.js'`), so a stale build is the most common test failure.
|
|
26
|
+
|
|
27
|
+
## Build, lint, test
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm run format # prettier + eslint --fix
|
|
31
|
+
npm run build # tsc + webpack
|
|
32
|
+
npm run build:all # build + test
|
|
33
|
+
npm run ci-lint # eslint + prettier --check (no auto-fix)
|
|
34
|
+
npm test # node --test on dist/
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
There is no separate `npm run dev` — the plugin runs inside a real Signal K server (see "Local dev loop").
|
|
38
|
+
|
|
39
|
+
## Local dev loop
|
|
40
|
+
|
|
41
|
+
The plugin runs inside whichever Signal K server has `signalk-grafana` in its `node_modules`. In this repo's typical dev layout, a Signal K data dir (e.g. `~/.signalk-charts-docker`) symlinks `node_modules/signalk-grafana` → `~/dev/signalk-grafana`. After editing source:
|
|
42
|
+
|
|
43
|
+
1. `npm run build:all` — webpack writes `dist/`, tests run.
|
|
44
|
+
2. Reload the plugin. The Signal K admin API at `/skServer/plugins/<id>/config` saves config and triggers stop+start, but **does not re-`require()` the plugin code** — Node's `require.cache` keeps the old module. To pick up code changes you must restart the Signal K _process_.
|
|
45
|
+
3. `curl http://127.0.0.1:<sk-port>/plugins/signalk-grafana/api/status` to confirm the new code is live.
|
|
46
|
+
|
|
47
|
+
## Debugging recipes
|
|
48
|
+
|
|
49
|
+
Inspect the running Grafana container directly — logs and on-disk plugin state often answer "why doesn't X work":
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
podman ps # find sk-signalk-grafana
|
|
53
|
+
podman logs sk-signalk-grafana | grep -iE 'tkurki|plugin' # plugin load errors
|
|
54
|
+
podman exec sk-signalk-grafana ls /var/lib/grafana/plugins # what's actually installed
|
|
55
|
+
podman exec sk-signalk-grafana cat /etc/grafana/provisioning/datasources/questdb.yaml
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Test datasource reachability from inside Grafana's network namespace:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
podman exec sk-signalk-grafana wget -qO- http://host.containers.internal:<sk-port>/signalk
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Probe Grafana's view of the datasources, and confirm the Signal K proxy hop works end-to-end:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
curl -u admin:<pw> http://127.0.0.1:3001/api/datasources
|
|
68
|
+
curl -u admin:<pw> http://127.0.0.1:3001/api/datasources/proxy/uid/signalk/signalk
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
The plugin's own status endpoint surfaces the same probe result with the resolved upstream URL:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
curl http://127.0.0.1:<sk-port>/plugins/signalk-grafana/api/status
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Gotchas
|
|
78
|
+
|
|
79
|
+
- **`host.containers.internal` works on `sk-network` for rootless Podman.** Don't assume the user-defined network breaks the magic hostname — netavark injects it. Verify before redesigning networking. (The earlier theory that the network was the problem turned out to be wrong; the actual issue was plugin load timing.)
|
|
80
|
+
- **The `tkurki-signalk-datasource` Grafana plugin is frontend-only.** Grafana's `/api/datasources/uid/<uid>/health` endpoint returns `{"messageId":"plugin.unavailable"}` for _any_ frontend-only datasource regardless of whether it works. Use the proxy path (`/api/datasources/proxy/uid/<uid>/signalk`) as the truthful reachability signal.
|
|
81
|
+
- **Grafana does not hot-reload plugins from disk.** Installing via `grafana cli plugins install` _after_ Grafana started leaves the plugin file on disk but unregistered until the next process restart. Prefer `GF_INSTALL_PLUGINS` env var (runs before plugin loader) over post-start CLI install.
|
|
82
|
+
- **The container is recreated when its config hash changes.** [src/index.ts](src/index.ts) hashes `{ tag, ports, env, networkMode }` and compares against `<dataDir>.container-hash`. Adding/changing an env var force-recreates on next plugin start, which is normally what you want — but means existing users see container churn whenever you touch this code.
|
|
83
|
+
- **`bindToAllInterfaces` controls only Grafana's host port mapping.** It has no effect on how Grafana reaches Signal K or QuestDB. Don't accept user reports that frame it as a Signal K reachability setting.
|
|
84
|
+
- **`process.env.PORT` inside `asyncStart` is the Signal K server's HTTP port.** That's why `host.containers.internal:${process.env.PORT}` is a sensible default for Signal K's URL: the plugin runs _inside_ the Signal K process, so its env reflects how Signal K was launched.
|
|
85
|
+
- **`provisioning.test.ts` runs against `dist/`, not `src/`.** If you edit `src/test/provisioning.test.ts` and run `npm test` directly, you're running the previous compiled version. Use `npm run build:all`.
|
|
86
|
+
|
|
87
|
+
## Conventions
|
|
88
|
+
|
|
89
|
+
- **No comments restating what the code does** — Signal K maintainers and the project author dislike echo comments. Comments should explain _why_ something non-obvious is the way it is (e.g. "Grafana doesn't hot-reload, so we install via env var"), not narrate the diff.
|
|
90
|
+
- **Angular-style commit messages** (`fix(grafana): ...`, `feat(grafana): ...`, `docs(grafana): ...`). The PR title matches the commit subject.
|
|
91
|
+
- **Branch names use hyphens, not slashes.** Signal K maintainers' convention.
|
|
92
|
+
- **TypeScript is strict.** Don't add `as any` to silence errors — fix the type.
|
|
93
|
+
- **Don't write multi-line comment blocks or docstrings.** A short single-line comment for a non-obvious WHY is fine; everything else is noise.
|
package/CLAUDE.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
See [AGENTS.md](AGENTS.md).
|
package/README.md
CHANGED
|
@@ -11,9 +11,11 @@ Runs Grafana in a container (via [signalk-container](https://github.com/dirkwa/s
|
|
|
11
11
|
- **Shared container network** -- Grafana and QuestDB communicate on a private Podman/Docker network
|
|
12
12
|
- **Table auto-discovery** -- QuestDB supports `information_schema`, Grafana query builder works
|
|
13
13
|
- **Anonymous access** -- view dashboards without login (configurable)
|
|
14
|
+
- **Live reachability** -- config panel shows whether Grafana can actually reach your Signal K server
|
|
14
15
|
- **One-click update** -- check for new Grafana versions and update from the config panel
|
|
15
16
|
- **Password management** -- set admin password from Signal K config panel
|
|
16
17
|
- **Config panel** -- Grafana status with direct link, settings, all in Admin UI
|
|
18
|
+
- **Backup & restore integration** -- exposes `/api/full-export/{db,dashboards,provisioning}` endpoints for [signalk-backup](https://github.com/dirkwa/signalk-backup) to pull a consistent SQLite checkpoint plus dashboard JSONs and provisioning YAMLs. On plugin start, if a kopia restore left a staged `grafana.db` on disk but the live one is missing, it's automatically copied into place before Grafana starts -- dashboards and datasources come back without any manual step.
|
|
17
19
|
|
|
18
20
|
## How It Works
|
|
19
21
|
|
|
@@ -111,21 +113,22 @@ QuestDB's `SAMPLE BY` handles time bucketing (e.g., `SAMPLE BY 10s`, `SAMPLE BY
|
|
|
111
113
|
|
|
112
114
|
## Configuration
|
|
113
115
|
|
|
114
|
-
| Setting | Default | Description
|
|
115
|
-
| --------------------- | ----------------- |
|
|
116
|
-
| Grafana port | `3001` | Host port for Grafana UI
|
|
117
|
-
| Image version | `latest` | Grafana Docker image tag
|
|
118
|
-
| Admin password | `admin` | Grafana admin password (applied on every start)
|
|
119
|
-
| Anonymous access | `true` | Allow viewing without login
|
|
120
|
-
| Signal K URL override | auto | Auto-detected
|
|
121
|
-
| QuestDB container | `signalk-questdb` | Container name (without sk- prefix)
|
|
122
|
-
| PostgreSQL port | `8812` | QuestDB PG wire port
|
|
123
|
-
| Network name | `sk-network` | Shared container network name
|
|
124
|
-
| Bind to 0.0.0.0 | `false` | Expose Grafana outside localhost
|
|
116
|
+
| Setting | Default | Description |
|
|
117
|
+
| --------------------- | ----------------- | ------------------------------------------------------------ |
|
|
118
|
+
| Grafana port | `3001` | Host port for Grafana UI |
|
|
119
|
+
| Image version | `latest` | Grafana Docker image tag |
|
|
120
|
+
| Admin password | `admin` | Grafana admin password (applied on every start) |
|
|
121
|
+
| Anonymous access | `true` | Allow viewing without login |
|
|
122
|
+
| Signal K URL override | auto | Auto-detected; set to override (use `http://` or `https://`) |
|
|
123
|
+
| QuestDB container | `signalk-questdb` | Container name (without sk- prefix) |
|
|
124
|
+
| PostgreSQL port | `8812` | QuestDB PG wire port |
|
|
125
|
+
| Network name | `sk-network` | Shared container network name |
|
|
126
|
+
| Bind to 0.0.0.0 | `false` | Expose Grafana outside localhost |
|
|
127
|
+
| Sub-path | empty | Set to `/grafana/` when running behind a reverse proxy |
|
|
125
128
|
|
|
126
129
|
## Requirements
|
|
127
130
|
|
|
128
|
-
- Node.js >= 22
|
|
131
|
+
- Node.js >= 22.16 (needs `node:sqlite` `backup()` for the SQLite checkpoint endpoint)
|
|
129
132
|
- [signalk-container](https://github.com/dirkwa/signalk-container) plugin
|
|
130
133
|
- [signalk-questdb](https://github.com/dirkwa/signalk-questdb) plugin (with network set to `sk-network`)
|
|
131
134
|
- Signal K server
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Response } from "express";
|
|
2
|
+
export interface ExportRequest {
|
|
3
|
+
params: Record<string, string | string[] | undefined>;
|
|
4
|
+
}
|
|
5
|
+
export type DbBackupFn = (sourcePath: string, destPath: string) => Promise<void>;
|
|
6
|
+
export interface FullExportDeps {
|
|
7
|
+
dataDir: string;
|
|
8
|
+
dbBackup?: DbBackupFn;
|
|
9
|
+
log?: (msg: string) => void;
|
|
10
|
+
}
|
|
11
|
+
export declare function handleDbExport(_req: ExportRequest, res: Response, deps: FullExportDeps): Promise<void>;
|
|
12
|
+
export declare function handleDashboardManifest(_req: ExportRequest, res: Response, deps: FullExportDeps): Promise<void>;
|
|
13
|
+
export declare function handleDashboardFile(req: ExportRequest, res: Response, deps: FullExportDeps): Promise<void>;
|
|
14
|
+
export declare function handleProvisioningManifest(_req: ExportRequest, res: Response, deps: FullExportDeps): Promise<void>;
|
|
15
|
+
export declare function handleProvisioningFile(req: ExportRequest, res: Response, deps: FullExportDeps): Promise<void>;
|
|
16
|
+
export declare function _resetInflightForTesting(): void;
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handleDbExport = handleDbExport;
|
|
4
|
+
exports.handleDashboardManifest = handleDashboardManifest;
|
|
5
|
+
exports.handleDashboardFile = handleDashboardFile;
|
|
6
|
+
exports.handleProvisioningManifest = handleProvisioningManifest;
|
|
7
|
+
exports.handleProvisioningFile = handleProvisioningFile;
|
|
8
|
+
exports._resetInflightForTesting = _resetInflightForTesting;
|
|
9
|
+
const fs_1 = require("fs");
|
|
10
|
+
const promises_1 = require("fs/promises");
|
|
11
|
+
const crypto_1 = require("crypto");
|
|
12
|
+
const path_1 = require("path");
|
|
13
|
+
const promises_2 = require("stream/promises");
|
|
14
|
+
const node_sqlite_1 = require("node:sqlite");
|
|
15
|
+
// signalk-backup pulls these endpoints over loopback HTTP; this module
|
|
16
|
+
// gives it a consistent SQLite checkpoint of grafana.db plus the
|
|
17
|
+
// dashboard JSONs and provisioning YAMLs. Mirrors the signalk-questdb
|
|
18
|
+
// export pattern so signalk-backup can treat both plugins uniformly.
|
|
19
|
+
// `/var/lib/grafana` is bind-mounted to `<dataDir>/grafana-data` (see
|
|
20
|
+
// src/index.ts where the container config is built). Both the live DB
|
|
21
|
+
// and the checkpoint live under that subtree so the plugin can reach
|
|
22
|
+
// them with plain fs APIs.
|
|
23
|
+
const GRAFANA_DATA_SUBDIR = "grafana-data";
|
|
24
|
+
const CHECKPOINT_SUBDIR = ".signalk-backup";
|
|
25
|
+
const CHECKPOINT_FILE = "grafana-backup.db";
|
|
26
|
+
const GRAFANA_DB_FILENAME = "grafana.db";
|
|
27
|
+
const CHECKPOINT_HOST_SUBPATH = (0, path_1.join)(GRAFANA_DATA_SUBDIR, CHECKPOINT_SUBDIR, CHECKPOINT_FILE);
|
|
28
|
+
// Dashboard files live under <dataDir>/dashboards/ and are flat JSON
|
|
29
|
+
// files (one dashboard per file). Provisioning lives under
|
|
30
|
+
// <dataDir>/provisioning/ with `datasources/` and `dashboards/`
|
|
31
|
+
// subdirectories of YAML.
|
|
32
|
+
const DASHBOARDS_SUBDIR = "dashboards";
|
|
33
|
+
const PROVISIONING_SUBDIR = "provisioning";
|
|
34
|
+
// File names are validated against this pattern before being used in
|
|
35
|
+
// a filesystem read. Allow letters / digits / dot / dash / underscore;
|
|
36
|
+
// disallow anything that could escape the directory or hide intent.
|
|
37
|
+
const SAFE_FILENAME = /^[a-zA-Z0-9._-]+$/;
|
|
38
|
+
// Coalesce concurrent DB-export requests onto a single sqlite3 .backup
|
|
39
|
+
// and synchronize cleanup so the file lives long enough for every
|
|
40
|
+
// piggybacking reader to consume it. Without coalescing, a periodic
|
|
41
|
+
// scheduler firing at the same moment as a manual export would race
|
|
42
|
+
// on the same checkpoint file. Without reader counting, the first
|
|
43
|
+
// finisher would unlink the file out from under the second reader
|
|
44
|
+
// (the second reader's createReadStream would hit ENOENT).
|
|
45
|
+
let inflightDbExport = null;
|
|
46
|
+
let inflightReaders = 0;
|
|
47
|
+
function defaultLog(msg) {
|
|
48
|
+
console.error(`[full-export] ${msg}`);
|
|
49
|
+
}
|
|
50
|
+
function sendError(res, status, message) {
|
|
51
|
+
if (res.headersSent) {
|
|
52
|
+
// Stream already started — best we can do is destroy the response.
|
|
53
|
+
res.destroy();
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
res.status(status).json({ error: message });
|
|
57
|
+
}
|
|
58
|
+
async function sha256File(path) {
|
|
59
|
+
const hash = (0, crypto_1.createHash)("sha256");
|
|
60
|
+
await (0, promises_2.pipeline)((0, fs_1.createReadStream)(path), hash);
|
|
61
|
+
return hash.digest("hex");
|
|
62
|
+
}
|
|
63
|
+
// Resolve a host path inside a known root, refusing anything that
|
|
64
|
+
// escapes via `..` or absolute paths. Returns the resolved path on
|
|
65
|
+
// success, throws otherwise.
|
|
66
|
+
function safeJoin(root, ...parts) {
|
|
67
|
+
const candidate = (0, path_1.normalize)((0, path_1.join)(root, ...parts));
|
|
68
|
+
const rel = (0, path_1.relative)(root, candidate);
|
|
69
|
+
if (rel.startsWith("..") || rel.startsWith(path_1.sep) || rel === "") {
|
|
70
|
+
throw new Error(`path escapes root: ${parts.join("/")}`);
|
|
71
|
+
}
|
|
72
|
+
return candidate;
|
|
73
|
+
}
|
|
74
|
+
async function defaultDbBackup(sourcePath, destPath) {
|
|
75
|
+
const src = new node_sqlite_1.DatabaseSync(sourcePath, { readOnly: true });
|
|
76
|
+
try {
|
|
77
|
+
await (0, node_sqlite_1.backup)(src, destPath);
|
|
78
|
+
}
|
|
79
|
+
finally {
|
|
80
|
+
src.close();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
async function runCheckpoint(deps) {
|
|
84
|
+
const log = deps.log ?? defaultLog;
|
|
85
|
+
const sourcePath = (0, path_1.join)(deps.dataDir, GRAFANA_DATA_SUBDIR, GRAFANA_DB_FILENAME);
|
|
86
|
+
const hostPath = (0, path_1.join)(deps.dataDir, CHECKPOINT_HOST_SUBPATH);
|
|
87
|
+
const dbBackup = deps.dbBackup ?? defaultDbBackup;
|
|
88
|
+
await (0, promises_1.mkdir)((0, path_1.join)(deps.dataDir, GRAFANA_DATA_SUBDIR, CHECKPOINT_SUBDIR), {
|
|
89
|
+
recursive: true,
|
|
90
|
+
});
|
|
91
|
+
// Drop any previous checkpoint first — node:sqlite backup() overwrites
|
|
92
|
+
// an existing file, but leaving stale bytes around on failure would
|
|
93
|
+
// mask the error.
|
|
94
|
+
await (0, promises_1.unlink)(hostPath).catch(() => { });
|
|
95
|
+
await dbBackup(sourcePath, hostPath);
|
|
96
|
+
// Sanity-check the checkpoint is a real SQLite file before we stream
|
|
97
|
+
// it. A 0-byte file shouldn't be possible with node:sqlite backup()
|
|
98
|
+
// succeeding, but cheap to verify and gives a clearer error than the
|
|
99
|
+
// client seeing a truncated body.
|
|
100
|
+
const st = await (0, promises_1.stat)(hostPath);
|
|
101
|
+
if (st.size === 0) {
|
|
102
|
+
throw new Error(`checkpoint produced an empty file at ${hostPath}`);
|
|
103
|
+
}
|
|
104
|
+
log(`wrote SQLite checkpoint: ${st.size} bytes`);
|
|
105
|
+
return hostPath;
|
|
106
|
+
}
|
|
107
|
+
async function handleDbExport(_req, res, deps) {
|
|
108
|
+
// Coalesce: piggyback on any in-flight checkpoint AND keep the
|
|
109
|
+
// checkpoint file alive until the last coalesced reader finishes
|
|
110
|
+
// streaming it. Increment before the await so a request arriving
|
|
111
|
+
// during another request's streaming phase still pins the file.
|
|
112
|
+
inflightReaders++;
|
|
113
|
+
if (!inflightDbExport) {
|
|
114
|
+
inflightDbExport = runCheckpoint(deps).then(() => undefined);
|
|
115
|
+
}
|
|
116
|
+
let hostPath;
|
|
117
|
+
try {
|
|
118
|
+
await inflightDbExport;
|
|
119
|
+
hostPath = (0, path_1.join)(deps.dataDir, CHECKPOINT_HOST_SUBPATH);
|
|
120
|
+
}
|
|
121
|
+
catch (err) {
|
|
122
|
+
sendError(res, 500, err instanceof Error ? err.message : "checkpoint failed");
|
|
123
|
+
await releaseReader();
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
res.setHeader("content-type", "application/octet-stream");
|
|
127
|
+
try {
|
|
128
|
+
await (0, promises_2.pipeline)((0, fs_1.createReadStream)(hostPath), res);
|
|
129
|
+
}
|
|
130
|
+
catch (err) {
|
|
131
|
+
(deps.log ?? defaultLog)(`stream failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
132
|
+
// Response is already in-flight; can't change status. The client
|
|
133
|
+
// sees a truncated body and treats it as a failed download.
|
|
134
|
+
}
|
|
135
|
+
finally {
|
|
136
|
+
await releaseReader();
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
// Drop the in-flight reader count by one; when the last reader leaves,
|
|
140
|
+
// clear the inflight slot so the next request triggers a fresh
|
|
141
|
+
// checkpoint.
|
|
142
|
+
//
|
|
143
|
+
// We deliberately do NOT unlink the checkpoint file here. The previous
|
|
144
|
+
// version did, and CR caught the race: clearing `inflightDbExport`
|
|
145
|
+
// before `await unlink` lets a new request start a fresh checkpoint
|
|
146
|
+
// at the same hostPath, and the still-pending unlink from the old
|
|
147
|
+
// generation can then delete the new file out from under it.
|
|
148
|
+
// Reversing the order doesn't help either (it just shifts the race).
|
|
149
|
+
// Generation-unique filenames would also work but add plumbing.
|
|
150
|
+
//
|
|
151
|
+
// Instead we rely on `runCheckpoint` clearing the file at the start
|
|
152
|
+
// of every export via `unlink`. The leftover sits under
|
|
153
|
+
// `<dataDir>/grafana-data/.signalk-backup/grafana-backup.db` — a
|
|
154
|
+
// hidden subdir of an already-private bind mount, ~MB scale, owned
|
|
155
|
+
// by the SignalK user — until the next scheduled export overwrites
|
|
156
|
+
// it. Worst-case crash-before-next-export leaves one stale file there.
|
|
157
|
+
async function releaseReader() {
|
|
158
|
+
inflightReaders--;
|
|
159
|
+
if (inflightReaders > 0)
|
|
160
|
+
return;
|
|
161
|
+
inflightDbExport = null;
|
|
162
|
+
}
|
|
163
|
+
async function buildManifest(root, keepRelPath) {
|
|
164
|
+
const out = [];
|
|
165
|
+
async function walk(dir) {
|
|
166
|
+
let entries;
|
|
167
|
+
try {
|
|
168
|
+
entries = await (0, promises_1.readdir)(dir, { withFileTypes: true });
|
|
169
|
+
}
|
|
170
|
+
catch (err) {
|
|
171
|
+
// Missing root just means the user hasn't generated anything
|
|
172
|
+
// there yet (e.g. fresh install). Empty manifest is the right
|
|
173
|
+
// response, not a 500.
|
|
174
|
+
if (err.code === "ENOENT")
|
|
175
|
+
return;
|
|
176
|
+
throw err;
|
|
177
|
+
}
|
|
178
|
+
for (const entry of entries) {
|
|
179
|
+
const full = (0, path_1.join)(dir, entry.name);
|
|
180
|
+
if (entry.isDirectory()) {
|
|
181
|
+
// Skip subdirectories entirely in flat mode (dashboards). Without
|
|
182
|
+
// this, a nested file would be advertised in the manifest by its
|
|
183
|
+
// basename only — but `/dashboards/:name` only accepts a single
|
|
184
|
+
// segment, so the client couldn't fetch it. Recursive walks stay
|
|
185
|
+
// enabled for provisioning where the per-file endpoint accepts
|
|
186
|
+
// an encoded relPath.
|
|
187
|
+
if (keepRelPath)
|
|
188
|
+
await walk(full);
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
if (!entry.isFile())
|
|
192
|
+
continue;
|
|
193
|
+
const st = await (0, promises_1.stat)(full);
|
|
194
|
+
const hash = await sha256File(full);
|
|
195
|
+
const rel = (0, path_1.relative)(root, full);
|
|
196
|
+
out.push({
|
|
197
|
+
name: entry.name,
|
|
198
|
+
// `relPath` is only meaningful for the provisioning tree
|
|
199
|
+
// which has subdirectories. Dashboards is flat, so we omit it
|
|
200
|
+
// to keep the manifest shape obvious.
|
|
201
|
+
...(keepRelPath ? { relPath: rel } : {}),
|
|
202
|
+
sha256: hash,
|
|
203
|
+
bytes: st.size,
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
await walk(root);
|
|
208
|
+
// Sort for deterministic output — kopia dedup loves byte-stable.
|
|
209
|
+
out.sort((a, b) => (a.relPath ?? a.name).localeCompare(b.relPath ?? b.name));
|
|
210
|
+
return out;
|
|
211
|
+
}
|
|
212
|
+
async function handleDashboardManifest(_req, res, deps) {
|
|
213
|
+
try {
|
|
214
|
+
const root = (0, path_1.join)(deps.dataDir, DASHBOARDS_SUBDIR);
|
|
215
|
+
const dashboards = await buildManifest(root, false);
|
|
216
|
+
res.json({ dashboards });
|
|
217
|
+
}
|
|
218
|
+
catch (err) {
|
|
219
|
+
sendError(res, 500, err instanceof Error ? err.message : "manifest build failed");
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
async function handleDashboardFile(req, res, deps) {
|
|
223
|
+
const rawName = req.params.name;
|
|
224
|
+
const name = typeof rawName === "string" ? rawName : "";
|
|
225
|
+
// SAFE_FILENAME allows `.` and `..` as a side-effect of `[a-zA-Z0-9._-]+`,
|
|
226
|
+
// so reject them explicitly. Without this they'd hit safeJoin and produce
|
|
227
|
+
// a 500 with a "path escapes root" message that leaks an internal detail
|
|
228
|
+
// (and is the wrong status — the input is malformed, not the runtime).
|
|
229
|
+
if (name === "." || name === ".." || !SAFE_FILENAME.test(name)) {
|
|
230
|
+
sendError(res, 400, "invalid dashboard name");
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
try {
|
|
234
|
+
const root = (0, path_1.join)(deps.dataDir, DASHBOARDS_SUBDIR);
|
|
235
|
+
const filePath = safeJoin(root, name);
|
|
236
|
+
// lstat (not stat) so we see the symlink itself rather than its
|
|
237
|
+
// target. Refusing symlinks closes the "plant a symlink inside
|
|
238
|
+
// /dashboards pointing to /etc/passwd" hole — safeJoin only does
|
|
239
|
+
// lexical containment so it can't detect that on its own.
|
|
240
|
+
const st = await (0, promises_1.lstat)(filePath);
|
|
241
|
+
if (st.isSymbolicLink()) {
|
|
242
|
+
sendError(res, 400, "symlink rejected");
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
if (!st.isFile()) {
|
|
246
|
+
sendError(res, 404, "not a file");
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
res.setHeader("content-type", "application/json");
|
|
250
|
+
await (0, promises_2.pipeline)((0, fs_1.createReadStream)(filePath), res);
|
|
251
|
+
}
|
|
252
|
+
catch (err) {
|
|
253
|
+
const code = err.code;
|
|
254
|
+
if (code === "ENOENT") {
|
|
255
|
+
sendError(res, 404, "dashboard not found");
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
sendError(res, 500, err instanceof Error ? err.message : "stream failed");
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
async function handleProvisioningManifest(_req, res, deps) {
|
|
262
|
+
try {
|
|
263
|
+
const root = (0, path_1.join)(deps.dataDir, PROVISIONING_SUBDIR);
|
|
264
|
+
const files = await buildManifest(root, true);
|
|
265
|
+
res.json({ files });
|
|
266
|
+
}
|
|
267
|
+
catch (err) {
|
|
268
|
+
sendError(res, 500, err instanceof Error ? err.message : "manifest build failed");
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
async function handleProvisioningFile(req, res, deps) {
|
|
272
|
+
// Express collapses path params on a single `:relPath` segment; the
|
|
273
|
+
// signalk-backup side url-encodes the slashes. Decode here and then
|
|
274
|
+
// run safeJoin to refuse anything that escapes the provisioning
|
|
275
|
+
// root. Reject any segment containing `..` even before joining.
|
|
276
|
+
const rawRelPath = req.params.relPath;
|
|
277
|
+
const encoded = typeof rawRelPath === "string" ? rawRelPath : "";
|
|
278
|
+
let decoded;
|
|
279
|
+
try {
|
|
280
|
+
decoded = decodeURIComponent(encoded);
|
|
281
|
+
}
|
|
282
|
+
catch {
|
|
283
|
+
sendError(res, 400, "invalid path encoding");
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
const segments = decoded.split("/").filter(Boolean);
|
|
287
|
+
if (segments.length === 0 || segments.some((s) => s === ".." || s === ".")) {
|
|
288
|
+
sendError(res, 400, "invalid provisioning path");
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
for (const segment of segments) {
|
|
292
|
+
if (!SAFE_FILENAME.test(segment)) {
|
|
293
|
+
sendError(res, 400, "invalid provisioning path");
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
try {
|
|
298
|
+
const root = (0, path_1.join)(deps.dataDir, PROVISIONING_SUBDIR);
|
|
299
|
+
const filePath = safeJoin(root, ...segments);
|
|
300
|
+
// Same lstat-rejects-symlinks hardening as the dashboard handler.
|
|
301
|
+
const st = await (0, promises_1.lstat)(filePath);
|
|
302
|
+
if (st.isSymbolicLink()) {
|
|
303
|
+
sendError(res, 400, "symlink rejected");
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
if (!st.isFile()) {
|
|
307
|
+
sendError(res, 404, "not a file");
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
// YAML — content-type is more about "give me bytes" than format
|
|
311
|
+
// detection on the consumer side, so use text/yaml for clarity.
|
|
312
|
+
res.setHeader("content-type", "text/yaml");
|
|
313
|
+
await (0, promises_2.pipeline)((0, fs_1.createReadStream)(filePath), res);
|
|
314
|
+
}
|
|
315
|
+
catch (err) {
|
|
316
|
+
const code = err.code;
|
|
317
|
+
if (code === "ENOENT") {
|
|
318
|
+
sendError(res, 404, "file not found");
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
sendError(res, 500, err instanceof Error ? err.message : "stream failed");
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
// Test-only escape hatch so the in-process lock can be reset between
|
|
325
|
+
// test cases. Exported with a leading underscore to flag intent.
|
|
326
|
+
function _resetInflightForTesting() {
|
|
327
|
+
inflightDbExport = null;
|
|
328
|
+
inflightReaders = 0;
|
|
329
|
+
}
|
|
330
|
+
//# sourceMappingURL=full-export.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"full-export.js","sourceRoot":"","sources":["../src/full-export.ts"],"names":[],"mappings":";;AAiJA,wCAwCC;AAoFD,0DAgBC;AAED,kDAyCC;AAED,gEAgBC;AAED,wDAuDC;AAID,4DAGC;AAzZD,2BAAsC;AACtC,0CAAkE;AAClE,mCAAoC;AACpC,+BAAsD;AACtD,8CAA2C;AAC3C,6CAAmD;AASnD,uEAAuE;AACvE,iEAAiE;AACjE,sEAAsE;AACtE,qEAAqE;AAErE,sEAAsE;AACtE,sEAAsE;AACtE,qEAAqE;AACrE,2BAA2B;AAC3B,MAAM,mBAAmB,GAAG,cAAc,CAAC;AAC3C,MAAM,iBAAiB,GAAG,iBAAiB,CAAC;AAC5C,MAAM,eAAe,GAAG,mBAAmB,CAAC;AAC5C,MAAM,mBAAmB,GAAG,YAAY,CAAC;AACzC,MAAM,uBAAuB,GAAG,IAAA,WAAI,EAClC,mBAAmB,EACnB,iBAAiB,EACjB,eAAe,CAChB,CAAC;AAEF,qEAAqE;AACrE,2DAA2D;AAC3D,gEAAgE;AAChE,0BAA0B;AAC1B,MAAM,iBAAiB,GAAG,YAAY,CAAC;AACvC,MAAM,mBAAmB,GAAG,cAAc,CAAC;AAE3C,qEAAqE;AACrE,uEAAuE;AACvE,oEAAoE;AACpE,MAAM,aAAa,GAAG,mBAAmB,CAAC;AAgB1C,uEAAuE;AACvE,kEAAkE;AAClE,oEAAoE;AACpE,oEAAoE;AACpE,kEAAk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