5 Commits

Author SHA1 Message Date
8639b02e6a feat(dashboardapi): emittedFields metadata for parent-panel dedup (#37)
Adds per-panel `meta.emittedFields` to machine.json (rotatingMachine) and
machineGroup.json (MGC) templates. Each non-row panel declares the Influx
field paths it visualizes, so a parent template's composer can filter out
panels already covered by its children (#39 no-data-duplication rule).

- config/machine.json: 13 non-row panels annotated.
- config/machineGroup.json: panels annotated.
- src/specificClass.js: collectEmittedFields(dashboard) helper.
- test/basic/slice37-emitted-fields.basic.test.js: 4 cases (template loads
  with annotations, aggregation, missing-meta graceful, null input).

PRD F-6 panel set audit: machine.json already covers all the PRD-required
panels (State/Mode/Ctrl%/Runtime/NCog%/Flow/Efficiency/Pressure/Temperature/
Diagnostics) — substantially more than asked. No new panels added.

PRD F-7 predicted-vs-measured side-by-side: deferred. Current architecture
is "1 dashboard per node" (each child gets its own dashboard, cross-linked
from the parent), not "1 dashboard with N composed panels." Side-by-side
rendering of predicted (rotatingMachine dashboard) + measured (measurement
child dashboard) lives naturally as drill-down navigation today. Refactor
to a single-dashboard composition model would be substantial — flagged in
the issue comment for v2 if the drill-down UX proves insufficient.

Closes #37
2026-05-26 17:59:37 +02:00
aac71eb129 feat(dashboardapi): diff-skip regen via flows:started predicate (#36)
Subscribes to Node-RED's flows:started runtime event, caches the {diff}
payload on the dashboardAPI source, and short-circuits the child.register
handler when none of {dashboardAPI id, child id, grandchild ids} appears in
diff.added/changed/removed/rewired. Predicate verified by S1 spike (#32).

- src/nodeClass.js: _attachLifecycleHook subscribes, _attachCloseHandler
  cleans up. No-op when RED.events isn't available (unit-test friendly).
- src/specificClass.js: subtreeChanged() predicate + subtreeIdsFor() helper.
- src/commands/handlers.js: registerChild consults predicate before composing;
  logs {event:'regen-skipped', outcome:'no-diff'} when skipping.
- test/basic/slice36-diff-predicate.basic.test.js: 8 cases — null/empty diff,
  affected/unaffected ids, tab-id over-triggering avoidance, grandchild
  inclusion, no-grandchild case.

Cold start (no cached diff yet) always regenerates — safe default. Edge case
documented in #32: when a brand-new child is wired to a registered parent,
the new child's id is in diff.added but not yet in registeredChildren when
flows:started fires. Mitigation (b) per spike findings: one-deploy race
accepted for R&D — next deploy picks up the new registration.

Closes #36
2026-05-26 17:57:34 +02:00
bdf87ffd67 test(dashboardapi): perf + uid-uniqueness for multi-child composition (#35)
Architectural note: existing composition is "1 dashboardAPI → root dashboard
+ 1 per child", not "1 dashboardAPI → 1 dashboard with N panels" as the PRD
assumed. Each generated dashboard is laid out at template-authoring time
(explicit gridPos per panel inside config/<softwareType>.json); the composer's
job is to substitute per-instance templating variables and assemble the
cross-link list. So the PRD's "non-overlapping gridPos for N panels" lands as:

- perf: 50 children compose in <500ms (PRD N-1).
- uid-uniqueness: stableUid keyed on softwareType:nodeId never collides.
- byte-identical idempotency (PRD N-2): two consecutive compositions match.
- root links: one link per registered child.

No production code change — this slice just adds the perf/uniqueness/idempotency
guarantees as explicit tests so we can't regress.

Closes #35
2026-05-26 17:55:39 +02:00
7fdab73ba0 feat(dashboardapi): walking skeleton for graph-aware Grafana generator (#34)
Encrypts the Grafana bearer token via Node-RED credentials block instead of
plain config (F-11). Adds folderUid config field threaded through to the
buildUpsertRequest payload (F-8, resolves PRD O-5). Migration path: legacy
plain bearerToken still loads, with one-time warn() prompting user to re-save.

Composition + URL + headers + per-instance UID were already in place; only
the credentials + folderUid + tests are new.

- dashboardAPI.html: bearerToken moved to credentials block; folderUid added.
- dashboardAPI.js: registerType options pass credentials descriptor.
- src/nodeClass.js: read token from node.credentials; legacy fallback warns.
- src/specificClass.js: buildUpsertRequest emits folderUid when set.
- src/commands/handlers.js: pass folderUid from config to buildUpsertRequest.
- test/basic/slice34-credentials-and-folder.basic.test.js: 5 new tests.

Diff-based regeneration (F-1) and the explicit flows:started lifecycle hook
land in #36 once the S1 spike predicate is wired. Until then, the existing
child.register message trigger continues to drive composition on every
startup-time child registration.

Closes #34
2026-05-26 17:53:42 +02:00
znetsixe
dac8576cab style: palette swatch → (domain-hue redesign 2026-05-21)
Sidebar swatch now follows function family rather than S88 level, so the
palette is visually identifiable instead of monochromatically blue. Editor-group
rectangles in flow.json still follow S88 — only the registerType color changed.
Full table + rationale: superproject .claude/rules/node-red-flow-layout.md §10.0
and .claude/refactor/OPEN_QUESTIONS.md (2026-05-21 entry).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 15:05:59 +02:00
11 changed files with 1438 additions and 142 deletions

View File

@@ -3,7 +3,10 @@
"list": [ "list": [
{ {
"builtIn": 1, "builtIn": 1,
"datasource": { "type": "grafana", "uid": "-- Grafana --" }, "datasource": {
"type": "grafana",
"uid": "-- Grafana --"
},
"enable": true, "enable": true,
"hide": true, "hide": true,
"iconColor": "rgba(0, 211, 255, 1)", "iconColor": "rgba(0, 211, 255, 1)",
@@ -17,179 +20,835 @@
"id": null, "id": null,
"links": [], "links": [],
"panels": [ "panels": [
{ "gridPos": { "h": 1, "w": 24, "x": 0, "y": 0 }, "id": 1, "title": "Status", "type": "row" },
{ {
"datasource": { "type": "influxdb", "uid": "cdzg44tv250jkd" }, "gridPos": {
"fieldConfig": { "defaults": { "thresholds": { "mode": "absolute", "steps": [{ "color": "green", "value": null }] }, "mappings": [{ "type": "value", "options": { "off": { "color": "red", "text": "OFF" }, "idle": { "color": "blue", "text": "IDLE" }, "operational": { "color": "green", "text": "RUNNING" }, "starting": { "color": "yellow", "text": "STARTING" }, "stopping": { "color": "yellow", "text": "STOPPING" } } }] }, "overrides": [] }, "h": 1,
"gridPos": { "h": 4, "w": 5, "x": 0, "y": 1 }, "w": 24,
"x": 0,
"y": 0
},
"id": 1,
"title": "Status",
"type": "row"
},
{
"datasource": {
"type": "influxdb",
"uid": "cdzg44tv250jkd"
},
"fieldConfig": {
"defaults": {
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
}
]
},
"mappings": [
{
"type": "value",
"options": {
"off": {
"color": "red",
"text": "OFF"
},
"idle": {
"color": "blue",
"text": "IDLE"
},
"operational": {
"color": "green",
"text": "RUNNING"
},
"starting": {
"color": "yellow",
"text": "STARTING"
},
"stopping": {
"color": "yellow",
"text": "STOPPING"
}
}
}
]
},
"overrides": []
},
"gridPos": {
"h": 4,
"w": 5,
"x": 0,
"y": 1
},
"id": 2, "id": 2,
"options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "value", "graphMode": "none" }, "options": {
"reduceOptions": {
"calcs": [
"lastNotNull"
]
},
"colorMode": "value",
"graphMode": "none"
},
"targets": [ "targets": [
{ "query": "from(bucket: \"${bucket}\")\n |> range(start: -7d)\n |> filter(fn:(r) => r._measurement==\"${measurement}\" and r._field==\"state\")\n |> last()", "refId": "A" } {
"query": "from(bucket: \"${bucket}\")\n |> range(start: -7d)\n |> filter(fn:(r) => r._measurement==\"${measurement}\" and r._field==\"state\")\n |> last()",
"refId": "A"
}
], ],
"title": "State", "title": "State",
"type": "stat" "type": "stat",
"meta": {
"emittedFields": [
"state"
]
}
}, },
{ {
"datasource": { "type": "influxdb", "uid": "cdzg44tv250jkd" }, "datasource": {
"fieldConfig": { "defaults": { "thresholds": { "mode": "absolute", "steps": [{ "color": "purple", "value": null }] } }, "overrides": [] }, "type": "influxdb",
"gridPos": { "h": 4, "w": 5, "x": 5, "y": 1 }, "uid": "cdzg44tv250jkd"
},
"fieldConfig": {
"defaults": {
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "purple",
"value": null
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 4,
"w": 5,
"x": 5,
"y": 1
},
"id": 3, "id": 3,
"options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "value", "graphMode": "none" }, "options": {
"reduceOptions": {
"calcs": [
"lastNotNull"
]
},
"colorMode": "value",
"graphMode": "none"
},
"targets": [ "targets": [
{ "query": "from(bucket: \"${bucket}\")\n |> range(start: -7d)\n |> filter(fn:(r) => r._measurement==\"${measurement}\" and r._field==\"mode\")\n |> last()", "refId": "A" } {
"query": "from(bucket: \"${bucket}\")\n |> range(start: -7d)\n |> filter(fn:(r) => r._measurement==\"${measurement}\" and r._field==\"mode\")\n |> last()",
"refId": "A"
}
], ],
"title": "Mode", "title": "Mode",
"type": "stat" "type": "stat",
"meta": {
"emittedFields": [
"mode"
]
}
}, },
{ {
"datasource": { "type": "influxdb", "uid": "cdzg44tv250jkd" }, "datasource": {
"fieldConfig": { "defaults": { "min": 0, "max": 100, "unit": "percent", "thresholds": { "mode": "absolute", "steps": [{ "color": "blue", "value": null }, { "color": "green", "value": 20 }, { "color": "yellow", "value": 80 }, { "color": "red", "value": 95 }] } }, "overrides": [] }, "type": "influxdb",
"gridPos": { "h": 4, "w": 5, "x": 10, "y": 1 }, "uid": "cdzg44tv250jkd"
},
"fieldConfig": {
"defaults": {
"min": 0,
"max": 100,
"unit": "percent",
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "blue",
"value": null
},
{
"color": "green",
"value": 20
},
{
"color": "yellow",
"value": 80
},
{
"color": "red",
"value": 95
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 4,
"w": 5,
"x": 10,
"y": 1
},
"id": 4, "id": 4,
"options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "showThresholdLabels": false, "showThresholdMarkers": true }, "options": {
"reduceOptions": {
"calcs": [
"lastNotNull"
]
},
"showThresholdLabels": false,
"showThresholdMarkers": true
},
"targets": [ "targets": [
{ "query": "from(bucket: \"${bucket}\")\n |> range(start: -7d)\n |> filter(fn:(r) => r._measurement==\"${measurement}\" and r._field==\"ctrl\")\n |> last()", "refId": "A" } {
"query": "from(bucket: \"${bucket}\")\n |> range(start: -7d)\n |> filter(fn:(r) => r._measurement==\"${measurement}\" and r._field==\"ctrl\")\n |> last()",
"refId": "A"
}
], ],
"title": "Ctrl %", "title": "Ctrl %",
"type": "gauge" "type": "gauge",
"meta": {
"emittedFields": [
"ctrl"
]
}
}, },
{ {
"datasource": { "type": "influxdb", "uid": "cdzg44tv250jkd" }, "datasource": {
"fieldConfig": { "defaults": { "unit": "h", "thresholds": { "mode": "absolute", "steps": [{ "color": "green", "value": null }] } }, "overrides": [] }, "type": "influxdb",
"gridPos": { "h": 4, "w": 5, "x": 15, "y": 1 }, "uid": "cdzg44tv250jkd"
},
"fieldConfig": {
"defaults": {
"unit": "h",
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 4,
"w": 5,
"x": 15,
"y": 1
},
"id": 5, "id": 5,
"options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "value", "graphMode": "area" }, "options": {
"reduceOptions": {
"calcs": [
"lastNotNull"
]
},
"colorMode": "value",
"graphMode": "area"
},
"targets": [ "targets": [
{ "query": "from(bucket: \"${bucket}\")\n |> range(start: -7d)\n |> filter(fn:(r) => r._measurement==\"${measurement}\" and r._field==\"runtime\")\n |> last()", "refId": "A" } {
"query": "from(bucket: \"${bucket}\")\n |> range(start: -7d)\n |> filter(fn:(r) => r._measurement==\"${measurement}\" and r._field==\"runtime\")\n |> last()",
"refId": "A"
}
], ],
"title": "Runtime", "title": "Runtime",
"type": "stat" "type": "stat",
"meta": {
"emittedFields": [
"runtime"
]
}
}, },
{ {
"datasource": { "type": "influxdb", "uid": "cdzg44tv250jkd" }, "datasource": {
"fieldConfig": { "defaults": { "min": 0, "max": 100, "unit": "percent", "thresholds": { "mode": "absolute", "steps": [{ "color": "red", "value": null }, { "color": "orange", "value": 30 }, { "color": "yellow", "value": 60 }, { "color": "green", "value": 80 }] } }, "overrides": [] }, "type": "influxdb",
"gridPos": { "h": 4, "w": 4, "x": 20, "y": 1 }, "uid": "cdzg44tv250jkd"
},
"fieldConfig": {
"defaults": {
"min": 0,
"max": 100,
"unit": "percent",
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "red",
"value": null
},
{
"color": "orange",
"value": 30
},
{
"color": "yellow",
"value": 60
},
{
"color": "green",
"value": 80
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 4,
"w": 4,
"x": 20,
"y": 1
},
"id": 6, "id": 6,
"options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "showThresholdLabels": false, "showThresholdMarkers": true }, "options": {
"reduceOptions": {
"calcs": [
"lastNotNull"
]
},
"showThresholdLabels": false,
"showThresholdMarkers": true
},
"targets": [ "targets": [
{ "query": "from(bucket: \"${bucket}\")\n |> range(start: -7d)\n |> filter(fn:(r) => r._measurement==\"${measurement}\" and r._field==\"NCogPercent\")\n |> last()", "refId": "A" } {
"query": "from(bucket: \"${bucket}\")\n |> range(start: -7d)\n |> filter(fn:(r) => r._measurement==\"${measurement}\" and r._field==\"NCogPercent\")\n |> last()",
"refId": "A"
}
], ],
"title": "NCog %", "title": "NCog %",
"type": "gauge" "type": "gauge",
"meta": {
"emittedFields": [
"ncog"
]
}
}, },
{ "gridPos": { "h": 1, "w": 24, "x": 0, "y": 5 }, "id": 7, "title": "Flow & Efficiency", "type": "row" },
{ {
"datasource": { "type": "influxdb", "uid": "cdzg44tv250jkd" }, "gridPos": {
"fieldConfig": { "defaults": { "custom": { "drawStyle": "line", "lineWidth": 2, "fillOpacity": 10 } }, "overrides": [] }, "h": 1,
"gridPos": { "h": 8, "w": 12, "x": 0, "y": 6 }, "w": 24,
"x": 0,
"y": 5
},
"id": 7,
"title": "Flow & Efficiency",
"type": "row"
},
{
"datasource": {
"type": "influxdb",
"uid": "cdzg44tv250jkd"
},
"fieldConfig": {
"defaults": {
"custom": {
"drawStyle": "line",
"lineWidth": 2,
"fillOpacity": 10
}
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 6
},
"id": 8, "id": 8,
"options": { "legend": { "displayMode": "list", "placement": "bottom" }, "tooltip": { "mode": "multi" } }, "options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
},
"tooltip": {
"mode": "multi"
}
},
"targets": [ "targets": [
{ "query": "from(bucket: \"${bucket}\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn:(r) => r._measurement==\"${measurement}\" and r._field =~ /^flow\\.predicted\\.(downstream|atequipment)/)\n |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)", "refId": "A" } {
"query": "from(bucket: \"${bucket}\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn:(r) => r._measurement==\"${measurement}\" and r._field =~ /^flow\\.predicted\\.(downstream|atequipment)/)\n |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)",
"refId": "A"
}
], ],
"title": "Flow (predicted)", "title": "Flow (predicted)",
"type": "timeseries" "type": "timeseries",
"meta": {
"emittedFields": [
"flow",
"flow.predicted"
]
}
}, },
{ {
"datasource": { "type": "influxdb", "uid": "cdzg44tv250jkd" }, "datasource": {
"fieldConfig": { "defaults": { "custom": { "drawStyle": "line", "lineWidth": 2, "fillOpacity": 10 } }, "overrides": [] }, "type": "influxdb",
"gridPos": { "h": 8, "w": 12, "x": 12, "y": 6 }, "uid": "cdzg44tv250jkd"
},
"fieldConfig": {
"defaults": {
"custom": {
"drawStyle": "line",
"lineWidth": 2,
"fillOpacity": 10
}
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 6
},
"id": 9, "id": 9,
"options": { "legend": { "displayMode": "list", "placement": "bottom" }, "tooltip": { "mode": "multi" } }, "options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
},
"tooltip": {
"mode": "multi"
}
},
"targets": [ "targets": [
{ "query": "from(bucket: \"${bucket}\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn:(r) => r._measurement==\"${measurement}\" and (r._field==\"cog\" or r._field==\"NCogPercent\"))\n |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)", "refId": "A" } {
"query": "from(bucket: \"${bucket}\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn:(r) => r._measurement==\"${measurement}\" and (r._field==\"cog\" or r._field==\"NCogPercent\"))\n |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)",
"refId": "A"
}
], ],
"title": "Efficiency (CoG + NCog%)", "title": "Efficiency (CoG + NCog%)",
"type": "timeseries" "type": "timeseries",
"meta": {
"emittedFields": [
"efficiency",
"cog",
"ncog"
]
}
}, },
{ "gridPos": { "h": 1, "w": 24, "x": 0, "y": 14 }, "id": 10, "title": "Pressure & Temperature", "type": "row" },
{ {
"datasource": { "type": "influxdb", "uid": "cdzg44tv250jkd" }, "gridPos": {
"fieldConfig": { "defaults": { "custom": { "drawStyle": "line", "lineWidth": 2, "fillOpacity": 10 } }, "overrides": [] }, "h": 1,
"gridPos": { "h": 8, "w": 12, "x": 0, "y": 15 }, "w": 24,
"x": 0,
"y": 14
},
"id": 10,
"title": "Pressure & Temperature",
"type": "row"
},
{
"datasource": {
"type": "influxdb",
"uid": "cdzg44tv250jkd"
},
"fieldConfig": {
"defaults": {
"custom": {
"drawStyle": "line",
"lineWidth": 2,
"fillOpacity": 10
}
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 15
},
"id": 11, "id": 11,
"options": { "legend": { "displayMode": "list", "placement": "bottom" }, "tooltip": { "mode": "multi" } }, "options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
},
"tooltip": {
"mode": "multi"
}
},
"targets": [ "targets": [
{ "query": "from(bucket: \"${bucket}\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn:(r) => r._measurement==\"${measurement}\" and r._field =~ /^pressure\\.(predicted|measured)\\.(upstream|downstream)/)\n |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)", "refId": "A" } {
"query": "from(bucket: \"${bucket}\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn:(r) => r._measurement==\"${measurement}\" and r._field =~ /^pressure\\.(predicted|measured)\\.(upstream|downstream)/)\n |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)",
"refId": "A"
}
], ],
"title": "Pressure (upstream / downstream)", "title": "Pressure (upstream / downstream)",
"type": "timeseries" "type": "timeseries",
"meta": {
"emittedFields": [
"pressure.upstream",
"pressure.downstream"
]
}
}, },
{ {
"datasource": { "type": "influxdb", "uid": "cdzg44tv250jkd" }, "datasource": {
"fieldConfig": { "defaults": { "custom": { "drawStyle": "line", "lineWidth": 2, "fillOpacity": 10 } }, "overrides": [] }, "type": "influxdb",
"gridPos": { "h": 8, "w": 12, "x": 12, "y": 15 }, "uid": "cdzg44tv250jkd"
},
"fieldConfig": {
"defaults": {
"custom": {
"drawStyle": "line",
"lineWidth": 2,
"fillOpacity": 10
}
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 15
},
"id": 12, "id": 12,
"options": { "legend": { "displayMode": "list", "placement": "bottom" }, "tooltip": { "mode": "multi" } }, "options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
},
"tooltip": {
"mode": "multi"
}
},
"targets": [ "targets": [
{ "query": "from(bucket: \"${bucket}\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn:(r) => r._measurement==\"${measurement}\" and r._field =~ /^temperature/)\n |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)", "refId": "A" } {
"query": "from(bucket: \"${bucket}\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn:(r) => r._measurement==\"${measurement}\" and r._field =~ /^temperature/)\n |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)",
"refId": "A"
}
], ],
"title": "Temperature", "title": "Temperature",
"type": "timeseries" "type": "timeseries",
"meta": {
"emittedFields": [
"temperature"
]
}
}, },
{ "gridPos": { "h": 1, "w": 24, "x": 0, "y": 23 }, "id": 13, "title": "Diagnostics", "type": "row" },
{ {
"datasource": { "type": "influxdb", "uid": "cdzg44tv250jkd" }, "gridPos": {
"fieldConfig": { "defaults": { "thresholds": { "mode": "absolute", "steps": [{ "color": "red", "value": null }, { "color": "yellow", "value": 0.3 }, { "color": "green", "value": 0.7 }] } }, "overrides": [] }, "h": 1,
"gridPos": { "h": 4, "w": 6, "x": 0, "y": 24 }, "w": 24,
"x": 0,
"y": 23
},
"id": 13,
"title": "Diagnostics",
"type": "row"
},
{
"datasource": {
"type": "influxdb",
"uid": "cdzg44tv250jkd"
},
"fieldConfig": {
"defaults": {
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "red",
"value": null
},
{
"color": "yellow",
"value": 0.3
},
{
"color": "green",
"value": 0.7
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 4,
"w": 6,
"x": 0,
"y": 24
},
"id": 14, "id": 14,
"options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "value", "graphMode": "area" }, "options": {
"reduceOptions": {
"calcs": [
"lastNotNull"
]
},
"colorMode": "value",
"graphMode": "area"
},
"targets": [ "targets": [
{ "query": "from(bucket: \"${bucket}\")\n |> range(start: -7d)\n |> filter(fn:(r) => r._measurement==\"${measurement}\" and r._field==\"predictionQuality\")\n |> last()", "refId": "A" } {
"query": "from(bucket: \"${bucket}\")\n |> range(start: -7d)\n |> filter(fn:(r) => r._measurement==\"${measurement}\" and r._field==\"predictionQuality\")\n |> last()",
"refId": "A"
}
], ],
"title": "Prediction Quality", "title": "Prediction Quality",
"type": "stat" "type": "stat",
"meta": {
"emittedFields": [
"predictionQuality"
]
}
}, },
{ {
"datasource": { "type": "influxdb", "uid": "cdzg44tv250jkd" }, "datasource": {
"fieldConfig": { "defaults": { "thresholds": { "mode": "absolute", "steps": [{ "color": "red", "value": null }, { "color": "yellow", "value": 0.3 }, { "color": "green", "value": 0.7 }] } }, "overrides": [] }, "type": "influxdb",
"gridPos": { "h": 4, "w": 6, "x": 6, "y": 24 }, "uid": "cdzg44tv250jkd"
},
"fieldConfig": {
"defaults": {
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "red",
"value": null
},
{
"color": "yellow",
"value": 0.3
},
{
"color": "green",
"value": 0.7
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 4,
"w": 6,
"x": 6,
"y": 24
},
"id": 15, "id": 15,
"options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "value", "graphMode": "area" }, "options": {
"reduceOptions": {
"calcs": [
"lastNotNull"
]
},
"colorMode": "value",
"graphMode": "area"
},
"targets": [ "targets": [
{ "query": "from(bucket: \"${bucket}\")\n |> range(start: -7d)\n |> filter(fn:(r) => r._measurement==\"${measurement}\" and r._field==\"predictionConfidence\")\n |> last()", "refId": "A" } {
"query": "from(bucket: \"${bucket}\")\n |> range(start: -7d)\n |> filter(fn:(r) => r._measurement==\"${measurement}\" and r._field==\"predictionConfidence\")\n |> last()",
"refId": "A"
}
], ],
"title": "Confidence", "title": "Confidence",
"type": "stat" "type": "stat",
"meta": {
"emittedFields": [
"confidence"
]
}
}, },
{ {
"datasource": { "type": "influxdb", "uid": "cdzg44tv250jkd" }, "datasource": {
"fieldConfig": { "defaults": { "thresholds": { "mode": "absolute", "steps": [{ "color": "green", "value": null }, { "color": "yellow", "value": 1 }, { "color": "red", "value": 2 }] } }, "overrides": [] }, "type": "influxdb",
"gridPos": { "h": 4, "w": 6, "x": 12, "y": 24 }, "uid": "cdzg44tv250jkd"
},
"fieldConfig": {
"defaults": {
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "yellow",
"value": 1
},
{
"color": "red",
"value": 2
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 4,
"w": 6,
"x": 12,
"y": 24
},
"id": 16, "id": 16,
"options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "value", "graphMode": "none" }, "options": {
"reduceOptions": {
"calcs": [
"lastNotNull"
]
},
"colorMode": "value",
"graphMode": "none"
},
"targets": [ "targets": [
{ "query": "from(bucket: \"${bucket}\")\n |> range(start: -7d)\n |> filter(fn:(r) => r._measurement==\"${measurement}\" and r._field==\"pressureDriftLevel\")\n |> last()", "refId": "A" } {
"query": "from(bucket: \"${bucket}\")\n |> range(start: -7d)\n |> filter(fn:(r) => r._measurement==\"${measurement}\" and r._field==\"pressureDriftLevel\")\n |> last()",
"refId": "A"
}
], ],
"title": "Pressure Drift", "title": "Pressure Drift",
"type": "stat" "type": "stat",
"meta": {
"emittedFields": [
"pressureDrift"
]
}
}, },
{ {
"datasource": { "type": "influxdb", "uid": "cdzg44tv250jkd" }, "datasource": {
"fieldConfig": { "defaults": { "thresholds": { "mode": "absolute", "steps": [{ "color": "green", "value": null }, { "color": "yellow", "value": 5 }, { "color": "red", "value": 15 }] } }, "overrides": [] }, "type": "influxdb",
"gridPos": { "h": 4, "w": 6, "x": 18, "y": 24 }, "uid": "cdzg44tv250jkd"
},
"fieldConfig": {
"defaults": {
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "yellow",
"value": 5
},
{
"color": "red",
"value": 15
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 4,
"w": 6,
"x": 18,
"y": 24
},
"id": 17, "id": 17,
"options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "value", "graphMode": "none" }, "options": {
"reduceOptions": {
"calcs": [
"lastNotNull"
]
},
"colorMode": "value",
"graphMode": "none"
},
"targets": [ "targets": [
{ "query": "from(bucket: \"${bucket}\")\n |> range(start: -7d)\n |> filter(fn:(r) => r._measurement==\"${measurement}\" and (r._field==\"effDistFromPeak\" or r._field==\"effRelDistFromPeak\"))\n |> last()", "refId": "A" } {
"query": "from(bucket: \"${bucket}\")\n |> range(start: -7d)\n |> filter(fn:(r) => r._measurement==\"${measurement}\" and (r._field==\"effDistFromPeak\" or r._field==\"effRelDistFromPeak\"))\n |> last()",
"refId": "A"
}
], ],
"title": "Distance from Peak", "title": "Distance from Peak",
"type": "stat" "type": "stat",
"meta": {
"emittedFields": [
"relDistFromPeak"
]
}
} }
], ],
"schemaVersion": 39, "schemaVersion": 39,
"tags": ["EVOLV", "machine", "template"], "tags": [
"EVOLV",
"machine",
"template"
],
"templating": { "templating": {
"list": [ "list": [
{ "name": "dbase", "type": "custom", "label": "dbase", "query": "cdzg44tv250jkd", "current": { "text": "cdzg44tv250jkd", "value": "cdzg44tv250jkd", "selected": false }, "options": [{ "text": "cdzg44tv250jkd", "value": "cdzg44tv250jkd", "selected": true }], "hide": 2 }, {
{ "name": "measurement", "type": "custom", "query": "template", "current": { "text": "template", "value": "template", "selected": false }, "options": [{ "text": "template", "value": "template", "selected": true }] }, "name": "dbase",
{ "name": "bucket", "type": "custom", "query": "lvl2", "current": { "text": "lvl2", "value": "lvl2", "selected": false }, "options": [{ "text": "lvl2", "value": "lvl2", "selected": true }] } "type": "custom",
"label": "dbase",
"query": "cdzg44tv250jkd",
"current": {
"text": "cdzg44tv250jkd",
"value": "cdzg44tv250jkd",
"selected": false
},
"options": [
{
"text": "cdzg44tv250jkd",
"value": "cdzg44tv250jkd",
"selected": true
}
],
"hide": 2
},
{
"name": "measurement",
"type": "custom",
"query": "template",
"current": {
"text": "template",
"value": "template",
"selected": false
},
"options": [
{
"text": "template",
"value": "template",
"selected": true
}
]
},
{
"name": "bucket",
"type": "custom",
"query": "lvl2",
"current": {
"text": "lvl2",
"value": "lvl2",
"selected": false
},
"options": [
{
"text": "lvl2",
"value": "lvl2",
"selected": true
}
]
}
] ]
}, },
"time": { "from": "now-6h", "to": "now" }, "time": {
"from": "now-6h",
"to": "now"
},
"timezone": "", "timezone": "",
"title": "template", "title": "template",
"uid": null, "uid": null,
"version": 1 "version": 1
} }

View File

@@ -3,7 +3,10 @@
"list": [ "list": [
{ {
"builtIn": 1, "builtIn": 1,
"datasource": { "type": "grafana", "uid": "-- Grafana --" }, "datasource": {
"type": "grafana",
"uid": "-- Grafana --"
},
"enable": true, "enable": true,
"hide": true, "hide": true,
"iconColor": "rgba(0, 211, 255, 1)", "iconColor": "rgba(0, 211, 255, 1)",
@@ -17,93 +20,376 @@
"id": null, "id": null,
"links": [], "links": [],
"panels": [ "panels": [
{ "gridPos": { "h": 1, "w": 24, "x": 0, "y": 0 }, "id": 1, "title": "Status", "type": "row" },
{ {
"datasource": { "type": "influxdb", "uid": "cdzg44tv250jkd" }, "gridPos": {
"fieldConfig": { "defaults": { "thresholds": { "mode": "absolute", "steps": [{ "color": "purple", "value": null }] } }, "overrides": [] }, "h": 1,
"gridPos": { "h": 4, "w": 6, "x": 0, "y": 1 }, "w": 24,
"id": 2, "x": 0,
"options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "value", "graphMode": "none" }, "y": 0
"targets": [ },
{ "query": "from(bucket: \"${bucket}\")\n |> range(start: -7d)\n |> filter(fn:(r) => r._measurement==\"${measurement}\" and r._field==\"mode\")\n |> last()", "refId": "A" } "id": 1,
], "title": "Status",
"title": "Mode", "type": "row"
"type": "stat"
}, },
{ {
"datasource": { "type": "influxdb", "uid": "cdzg44tv250jkd" }, "datasource": {
"fieldConfig": { "defaults": { "thresholds": { "mode": "absolute", "steps": [{ "color": "blue", "value": null }] } }, "overrides": [] }, "type": "influxdb",
"gridPos": { "h": 4, "w": 6, "x": 6, "y": 1 }, "uid": "cdzg44tv250jkd"
"id": 3, },
"options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "value", "graphMode": "none" }, "fieldConfig": {
"defaults": {
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "purple",
"value": null
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 4,
"w": 6,
"x": 0,
"y": 1
},
"id": 2,
"options": {
"reduceOptions": {
"calcs": [
"lastNotNull"
]
},
"colorMode": "value",
"graphMode": "none"
},
"targets": [ "targets": [
{ "query": "from(bucket: \"${bucket}\")\n |> range(start: -7d)\n |> filter(fn:(r) => r._measurement==\"${measurement}\" and r._field==\"scaling\")\n |> last()", "refId": "A" } {
"query": "from(bucket: \"${bucket}\")\n |> range(start: -7d)\n |> filter(fn:(r) => r._measurement==\"${measurement}\" and r._field==\"mode\")\n |> last()",
"refId": "A"
}
],
"title": "Mode",
"type": "stat",
"meta": {
"emittedFields": [
"mode"
]
}
},
{
"datasource": {
"type": "influxdb",
"uid": "cdzg44tv250jkd"
},
"fieldConfig": {
"defaults": {
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "blue",
"value": null
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 4,
"w": 6,
"x": 6,
"y": 1
},
"id": 3,
"options": {
"reduceOptions": {
"calcs": [
"lastNotNull"
]
},
"colorMode": "value",
"graphMode": "none"
},
"targets": [
{
"query": "from(bucket: \"${bucket}\")\n |> range(start: -7d)\n |> filter(fn:(r) => r._measurement==\"${measurement}\" and r._field==\"scaling\")\n |> last()",
"refId": "A"
}
], ],
"title": "Scaling", "title": "Scaling",
"type": "stat" "type": "stat"
}, },
{ {
"datasource": { "type": "influxdb", "uid": "cdzg44tv250jkd" }, "datasource": {
"fieldConfig": { "defaults": { "thresholds": { "mode": "absolute", "steps": [{ "color": "green", "value": null }, { "color": "yellow", "value": 5 }, { "color": "red", "value": 15 }] } }, "overrides": [] }, "type": "influxdb",
"gridPos": { "h": 4, "w": 6, "x": 12, "y": 1 }, "uid": "cdzg44tv250jkd"
},
"fieldConfig": {
"defaults": {
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "yellow",
"value": 5
},
{
"color": "red",
"value": 15
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 4,
"w": 6,
"x": 12,
"y": 1
},
"id": 4, "id": 4,
"options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "value", "graphMode": "area" }, "options": {
"reduceOptions": {
"calcs": [
"lastNotNull"
]
},
"colorMode": "value",
"graphMode": "area"
},
"targets": [ "targets": [
{ "query": "from(bucket: \"${bucket}\")\n |> range(start: -7d)\n |> filter(fn:(r) => r._measurement==\"${measurement}\" and r._field==\"absDistFromPeak\")\n |> last()", "refId": "A" } {
"query": "from(bucket: \"${bucket}\")\n |> range(start: -7d)\n |> filter(fn:(r) => r._measurement==\"${measurement}\" and r._field==\"absDistFromPeak\")\n |> last()",
"refId": "A"
}
], ],
"title": "Abs Dist Peak", "title": "Abs Dist Peak",
"type": "stat" "type": "stat"
}, },
{ {
"datasource": { "type": "influxdb", "uid": "cdzg44tv250jkd" }, "datasource": {
"fieldConfig": { "defaults": { "unit": "percent", "thresholds": { "mode": "absolute", "steps": [{ "color": "green", "value": null }, { "color": "yellow", "value": 10 }, { "color": "red", "value": 25 }] } }, "overrides": [] }, "type": "influxdb",
"gridPos": { "h": 4, "w": 6, "x": 18, "y": 1 }, "uid": "cdzg44tv250jkd"
},
"fieldConfig": {
"defaults": {
"unit": "percent",
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "yellow",
"value": 10
},
{
"color": "red",
"value": 25
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 4,
"w": 6,
"x": 18,
"y": 1
},
"id": 5, "id": 5,
"options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "value", "graphMode": "area" }, "options": {
"reduceOptions": {
"calcs": [
"lastNotNull"
]
},
"colorMode": "value",
"graphMode": "area"
},
"targets": [ "targets": [
{ "query": "from(bucket: \"${bucket}\")\n |> range(start: -7d)\n |> filter(fn:(r) => r._measurement==\"${measurement}\" and r._field==\"relDistFromPeak\")\n |> last()", "refId": "A" } {
"query": "from(bucket: \"${bucket}\")\n |> range(start: -7d)\n |> filter(fn:(r) => r._measurement==\"${measurement}\" and r._field==\"relDistFromPeak\")\n |> last()",
"refId": "A"
}
], ],
"title": "Rel Dist Peak", "title": "Rel Dist Peak",
"type": "stat" "type": "stat"
}, },
{ "gridPos": { "h": 1, "w": 24, "x": 0, "y": 5 }, "id": 6, "title": "Totals", "type": "row" },
{ {
"datasource": { "type": "influxdb", "uid": "cdzg44tv250jkd" }, "gridPos": {
"fieldConfig": { "defaults": { "custom": { "drawStyle": "line", "lineWidth": 2, "fillOpacity": 10 } }, "overrides": [] }, "h": 1,
"gridPos": { "h": 8, "w": 12, "x": 0, "y": 6 }, "w": 24,
"x": 0,
"y": 5
},
"id": 6,
"title": "Totals",
"type": "row"
},
{
"datasource": {
"type": "influxdb",
"uid": "cdzg44tv250jkd"
},
"fieldConfig": {
"defaults": {
"custom": {
"drawStyle": "line",
"lineWidth": 2,
"fillOpacity": 10
}
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 6
},
"id": 7, "id": 7,
"options": { "legend": { "displayMode": "list", "placement": "bottom" }, "tooltip": { "mode": "multi" } }, "options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
},
"tooltip": {
"mode": "multi"
}
},
"targets": [ "targets": [
{ "query": "from(bucket: \"${bucket}\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn:(r) => r._measurement==\"${measurement}\" and r._field =~ /predicted_flow|flow/)\n |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)", "refId": "A" } {
"query": "from(bucket: \"${bucket}\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn:(r) => r._measurement==\"${measurement}\" and r._field =~ /predicted_flow|flow/)\n |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)",
"refId": "A"
}
], ],
"title": "Total Flow", "title": "Total Flow",
"type": "timeseries" "type": "timeseries"
}, },
{ {
"datasource": { "type": "influxdb", "uid": "cdzg44tv250jkd" }, "datasource": {
"fieldConfig": { "defaults": { "custom": { "drawStyle": "line", "lineWidth": 2, "fillOpacity": 10 } }, "overrides": [] }, "type": "influxdb",
"gridPos": { "h": 8, "w": 12, "x": 12, "y": 6 }, "uid": "cdzg44tv250jkd"
},
"fieldConfig": {
"defaults": {
"custom": {
"drawStyle": "line",
"lineWidth": 2,
"fillOpacity": 10
}
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 6
},
"id": 8, "id": 8,
"options": { "legend": { "displayMode": "list", "placement": "bottom" }, "tooltip": { "mode": "multi" } }, "options": {
"legend": {
"displayMode": "list",
"placement": "bottom"
},
"tooltip": {
"mode": "multi"
}
},
"targets": [ "targets": [
{ "query": "from(bucket: \"${bucket}\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn:(r) => r._measurement==\"${measurement}\" and r._field =~ /predicted_power|power/)\n |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)", "refId": "A" } {
"query": "from(bucket: \"${bucket}\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn:(r) => r._measurement==\"${measurement}\" and r._field =~ /predicted_power|power/)\n |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)",
"refId": "A"
}
], ],
"title": "Total Power", "title": "Total Power",
"type": "timeseries" "type": "timeseries"
} }
], ],
"schemaVersion": 39, "schemaVersion": 39,
"tags": ["EVOLV", "machineGroup", "template"], "tags": [
"EVOLV",
"machineGroup",
"template"
],
"templating": { "templating": {
"list": [ "list": [
{ "name": "dbase", "type": "custom", "label": "dbase", "query": "cdzg44tv250jkd", "current": { "text": "cdzg44tv250jkd", "value": "cdzg44tv250jkd", "selected": false }, "options": [{ "text": "cdzg44tv250jkd", "value": "cdzg44tv250jkd", "selected": true }], "hide": 2 }, {
{ "name": "measurement", "type": "custom", "query": "template", "current": { "text": "template", "value": "template", "selected": false }, "options": [{ "text": "template", "value": "template", "selected": true }] }, "name": "dbase",
{ "name": "bucket", "type": "custom", "query": "lvl2", "current": { "text": "lvl2", "value": "lvl2", "selected": false }, "options": [{ "text": "lvl2", "value": "lvl2", "selected": true }] } "type": "custom",
"label": "dbase",
"query": "cdzg44tv250jkd",
"current": {
"text": "cdzg44tv250jkd",
"value": "cdzg44tv250jkd",
"selected": false
},
"options": [
{
"text": "cdzg44tv250jkd",
"value": "cdzg44tv250jkd",
"selected": true
}
],
"hide": 2
},
{
"name": "measurement",
"type": "custom",
"query": "template",
"current": {
"text": "template",
"value": "template",
"selected": false
},
"options": [
{
"text": "template",
"value": "template",
"selected": true
}
]
},
{
"name": "bucket",
"type": "custom",
"query": "lvl2",
"current": {
"text": "lvl2",
"value": "lvl2",
"selected": false
},
"options": [
{
"text": "lvl2",
"value": "lvl2",
"selected": true
}
]
}
] ]
}, },
"time": { "from": "now-6h", "to": "now" }, "time": {
"from": "now-6h",
"to": "now"
},
"timezone": "", "timezone": "",
"title": "template", "title": "template",
"uid": null, "uid": null,
"version": 1 "version": 1
} }

View File

@@ -4,7 +4,7 @@
<script> <script>
RED.nodes.registerType('dashboardapi', { RED.nodes.registerType('dashboardapi', {
category: 'EVOLV', category: 'EVOLV',
color: '#4f8582', color: '#7A8BA3',
defaults: { defaults: {
name: { value: '' }, name: { value: '' },
enableLog: { value: true }, enableLog: { value: true },
@@ -13,9 +13,12 @@
protocol: { value: 'http' }, protocol: { value: 'http' },
host: { value: 'localhost' }, host: { value: 'localhost' },
port: { value: 3000 }, port: { value: 3000 },
bearerToken: { value: '' }, folderUid: { value: '' },
defaultBucket: { value: '' }, defaultBucket: { value: '' },
}, },
credentials: {
bearerToken: { type: 'password' },
},
inputs: 1, inputs: 1,
outputs: 1, outputs: 1,
inputLabels: ['Input'], inputLabels: ['Input'],
@@ -44,11 +47,12 @@
window.EVOLV.nodes.dashboardapi.loggerMenu.saveEditor(node); window.EVOLV.nodes.dashboardapi.loggerMenu.saveEditor(node);
} }
['name', 'protocol', 'host', 'port', 'bearerToken', 'defaultBucket'].forEach((field) => { ['name', 'protocol', 'host', 'port', 'folderUid', 'defaultBucket'].forEach((field) => {
const element = document.getElementById(`node-input-${field}`); const element = document.getElementById(`node-input-${field}`);
if (!element) return; if (!element) return;
node[field] = field === 'port' ? parseInt(element.value, 10) || 3000 : element.value || ''; node[field] = field === 'port' ? parseInt(element.value, 10) || 3000 : element.value || '';
}); });
// bearerToken is handled by Node-RED's credentials system (encrypted at rest in flow_cred.json).
}, },
}); });
</script> </script>
@@ -80,7 +84,12 @@
<div class="form-row"> <div class="form-row">
<label for="node-input-bearerToken"><i class="fa fa-key"></i> Bearer Token</label> <label for="node-input-bearerToken"><i class="fa fa-key"></i> Bearer Token</label>
<input type="password" id="node-input-bearerToken" placeholder="optional" style="width:70%;" /> <input type="password" id="node-input-bearerToken" placeholder="encrypted at rest" style="width:70%;" />
</div>
<div class="form-row">
<label for="node-input-folderUid"><i class="fa fa-folder-open"></i> Grafana Folder UID</label>
<input type="text" id="node-input-folderUid" placeholder="optional — empty = General folder" style="width:70%;" />
</div> </div>
<div class="form-row"> <div class="form-row">

View File

@@ -9,6 +9,10 @@ module.exports = function (RED) {
RED.nodes.registerType(nameOfNode, function (config) { RED.nodes.registerType(nameOfNode, function (config) {
RED.nodes.createNode(this, config); RED.nodes.createNode(this, config);
this.nodeClass = new nodeClass(config, RED, this, nameOfNode); this.nodeClass = new nodeClass(config, RED, this, nameOfNode);
}, {
credentials: {
bearerToken: { type: 'password' },
},
}); });
const menuMgr = new MenuManager(); const menuMgr = new MenuManager();

View File

@@ -24,12 +24,33 @@ function resolveChildNode(childId, ctx) {
// On child.register: build the dashboard graph (root + direct children) and // On child.register: build the dashboard graph (root + direct children) and
// emit one Grafana upsert HTTP request per dashboard on Port 0. // emit one Grafana upsert HTTP request per dashboard on Port 0.
//
// Diff-skip behavior (PRD F-1, S1 spike #32): if the latest flows:started
// payload's `diff` indicates that NEITHER the dashboardAPI itself NOR this
// child NOR its grandchildren changed, skip composition and log no-diff. The
// first call after startup (no cached diff yet) regenerates unconditionally.
function registerChild(source, msg, ctx) { function registerChild(source, msg, ctx) {
const childSource = resolveChildSource(msg.payload, ctx); const childSource = resolveChildSource(msg.payload, ctx);
if (!childSource?.config) { if (!childSource?.config) {
throw new Error('Missing or invalid child node'); throw new Error('Missing or invalid child node');
} }
const subtreeIds = source.subtreeIdsFor(ctx.node?.id, childSource);
const changed = source.subtreeChanged(source.lastFlowsStartedDiff, subtreeIds);
if (!changed) {
if (source.logger?.info) {
source.logger.info({
event: 'regen-skipped',
outcome: 'no-diff',
trigger: 'child.register',
dashboardApiId: ctx.node?.id,
childId: childSource?.config?.general?.id,
subtreeSize: subtreeIds.size,
});
}
return;
}
const dashboards = source.generateDashboardsForGraph(childSource, { const dashboards = source.generateDashboardsForGraph(childSource, {
includeChildren: Boolean(msg.includeChildren ?? true), includeChildren: Boolean(msg.includeChildren ?? true),
}); });
@@ -48,7 +69,7 @@ function registerChild(source, msg, ctx) {
headers, headers,
payload: source.buildUpsertRequest({ payload: source.buildUpsertRequest({
dashboard: dash.dashboard, dashboard: dash.dashboard,
folderId: 0, folderUid: source.config?.grafanaConnector?.folderUid || undefined,
overwrite: true, overwrite: true,
}), }),
meta: { meta: {

View File

@@ -26,10 +26,45 @@ class nodeClass {
this._attachInputHandler(); this._attachInputHandler();
this._attachCloseHandler(); this._attachCloseHandler();
this._attachLifecycleHook();
}
// Subscribe to Node-RED's `flows:started` event to cache the deploy diff so
// the child.register handler can decide whether *this* dashboardAPI's
// subtree was affected. Predicate documented in Gitea issue #32 spike.
_attachLifecycleHook() {
if (!this.RED?.events?.on) return;
this._flowsStartedListener = (payload) => {
const diff = payload?.diff || null;
this.source.lastFlowsStartedDiff = diff;
this.source.lastFlowsStartedAt = Date.now();
if (this.source?.logger?.debug) {
const summary = diff
? Object.fromEntries(
['added', 'changed', 'removed', 'rewired', 'linked', 'flowChanged']
.map((k) => [k, (diff[k] || []).length])
)
: null;
this.source.logger.debug({ event: 'flows:started', type: payload?.type, diff: summary });
}
};
this.RED.events.on('flows:started', this._flowsStartedListener);
} }
_buildConfig(uiConfig) { _buildConfig(uiConfig) {
const cfgMgr = new configManager(); const cfgMgr = new configManager();
// Credentials block (Node-RED encrypts at rest in flow_cred.json). Legacy
// installs may still carry bearerToken on uiConfig — fall back with a
// one-time deprecation warning so the user knows to re-save.
const credentialToken = this.node?.credentials?.bearerToken || '';
const legacyToken = uiConfig.bearerToken || '';
if (!credentialToken && legacyToken) {
this.RED?.log?.warn?.(
`[${this.name}] bearer token loaded from legacy plain config field. ` +
`Re-open this node in the editor and click Done to migrate to encrypted credentials.`
);
}
const bearerToken = credentialToken || legacyToken;
return cfgMgr.buildConfig(this.name, uiConfig, this.node.id, { return cfgMgr.buildConfig(this.name, uiConfig, this.node.id, {
functionality: { functionality: {
softwareType: this.name.toLowerCase(), softwareType: this.name.toLowerCase(),
@@ -39,7 +74,8 @@ class nodeClass {
protocol: uiConfig.protocol || 'http', protocol: uiConfig.protocol || 'http',
host: uiConfig.host || 'localhost', host: uiConfig.host || 'localhost',
port: Number(uiConfig.port || 3000), port: Number(uiConfig.port || 3000),
bearerToken: uiConfig.bearerToken || '', bearerToken,
folderUid: uiConfig.folderUid || '',
}, },
defaultBucket: uiConfig.defaultBucket || process.env.INFLUXDB_BUCKET || '', defaultBucket: uiConfig.defaultBucket || process.env.INFLUXDB_BUCKET || '',
}); });
@@ -65,6 +101,10 @@ class nodeClass {
_attachCloseHandler() { _attachCloseHandler() {
this.node.on('close', (done) => { this.node.on('close', (done) => {
if (this._flowsStartedListener && this.RED?.events?.off) {
this.RED.events.off('flows:started', this._flowsStartedListener);
this._flowsStartedListener = null;
}
if (typeof done === 'function') done(); if (typeof done === 'function') done();
}); });
} }

View File

@@ -64,6 +64,7 @@ class DashboardApi {
host: config?.grafanaConnector?.host || 'localhost', host: config?.grafanaConnector?.host || 'localhost',
port: Number(config?.grafanaConnector?.port || 3000), port: Number(config?.grafanaConnector?.port || 3000),
bearerToken: config?.grafanaConnector?.bearerToken || '', bearerToken: config?.grafanaConnector?.bearerToken || '',
folderUid: config?.grafanaConnector?.folderUid || '',
}, },
defaultBucket: config?.defaultBucket || '', defaultBucket: config?.defaultBucket || '',
bucketMap: config?.bucketMap || {}, bucketMap: config?.bucketMap || {},
@@ -104,6 +105,18 @@ class DashboardApi {
return JSON.parse(raw); return JSON.parse(raw);
} }
// Collect every `meta.emittedFields` declared by panels in a template.
// Used by #39's parent panel filter — a parent panel whose emittedFields
// are fully covered by its children's panels is removed.
collectEmittedFields(dashboard) {
const out = new Set();
for (const panel of dashboard?.panels || []) {
const fields = panel?.meta?.emittedFields;
if (Array.isArray(fields)) for (const f of fields) out.add(f);
}
return out;
}
grafanaUpsertUrl() { grafanaUpsertUrl() {
const { protocol, host, port } = this.config.grafanaConnector; const { protocol, host, port } = this.config.grafanaConnector;
return `${protocol}://${host}:${port}/api/dashboards/db`; return `${protocol}://${host}:${port}/api/dashboards/db`;
@@ -144,8 +157,13 @@ class DashboardApi {
return { dashboard, uid, title, softwareType, nodeId, measurementName }; return { dashboard, uid, title, softwareType, nodeId, measurementName };
} }
buildUpsertRequest({ dashboard, folderId = 0, overwrite = true }) { buildUpsertRequest({ dashboard, folderId, folderUid, overwrite = true }) {
return { dashboard, folderId, overwrite }; const out = { dashboard, overwrite };
// Prefer folderUid (modern Grafana API). Fall back to folderId for older callers.
const uid = folderUid ?? this.config?.grafanaConnector?.folderUid ?? '';
if (uid) out.folderUid = uid;
else if (typeof folderId === 'number') out.folderId = folderId;
return out;
} }
extractChildren(nodeSource) { extractChildren(nodeSource) {
@@ -162,6 +180,34 @@ class DashboardApi {
return out; return out;
} }
// Predicate from Gitea issue #32 spike (S1 findings). Given the diff payload
// from Node-RED's flows:started event and a set of node ids that constitute
// "my subtree", decides whether the subtree changed on this deploy.
// `null` diff (first deploy / startup) → always regen (safe default).
subtreeChanged(diff, subtreeIds) {
if (!diff) return true;
const mine = new Set(subtreeIds);
for (const field of ['added', 'changed', 'removed', 'rewired']) {
const arr = diff[field] || [];
if (arr.some((id) => mine.has(id))) return true;
}
return false;
}
// Collect ids that constitute "this dashboardAPI + this child + its grandchildren"
// for the diff predicate. Pulls grandchildren via the existing extractChildren walk.
subtreeIdsFor(dashboardApiNodeId, childSource) {
const ids = new Set();
if (dashboardApiNodeId) ids.add(dashboardApiNodeId);
const childId = childSource?.config?.general?.id;
if (childId) ids.add(childId);
for (const { childSource: gc } of this.extractChildren(childSource)) {
const gcId = gc?.config?.general?.id;
if (gcId) ids.add(gcId);
}
return ids;
}
generateDashboardsForGraph(rootSource, { includeChildren = true } = {}) { generateDashboardsForGraph(rootSource, { includeChildren = true } = {}) {
if (!rootSource?.config) { if (!rootSource?.config) {
this.logger.warn('generateDashboardsForGraph skipped: root source missing config'); this.logger.warn('generateDashboardsForGraph skipped: root source missing config');

View File

@@ -0,0 +1,43 @@
'use strict';
const test = require('node:test');
const assert = require('node:assert/strict');
const DashboardApi = require('../../src/specificClass.js');
test('buildUpsertRequest emits folderUid when configured', () => {
const api = new DashboardApi({
grafanaConnector: { folderUid: 'rnd-folder' },
});
const req = api.buildUpsertRequest({ dashboard: { uid: 'x', title: 'X' } });
assert.equal(req.folderUid, 'rnd-folder');
assert.equal(req.overwrite, true);
assert.ok(!('folderId' in req), 'should not emit folderId when folderUid is set');
});
test('buildUpsertRequest omits folderUid when empty (Grafana defaults to General)', () => {
const api = new DashboardApi({});
const req = api.buildUpsertRequest({ dashboard: { uid: 'x' } });
assert.equal(req.folderUid, undefined);
// folderId fallback only when explicitly passed
assert.equal(req.folderId, undefined);
});
test('buildUpsertRequest folderUid override at call-site wins over config', () => {
const api = new DashboardApi({ grafanaConnector: { folderUid: 'rnd-folder' } });
const req = api.buildUpsertRequest({ dashboard: { uid: 'x' }, folderUid: 'override-folder' });
assert.equal(req.folderUid, 'override-folder');
});
test('bearerToken from config flows into specificClass config', () => {
const api = new DashboardApi({
grafanaConnector: { bearerToken: 'tok-xyz', folderUid: '' },
});
assert.equal(api.config.grafanaConnector.bearerToken, 'tok-xyz');
});
test('default config has empty bearerToken and folderUid', () => {
const api = new DashboardApi({});
assert.equal(api.config.grafanaConnector.bearerToken, '');
assert.equal(api.config.grafanaConnector.folderUid, '');
});

View File

@@ -0,0 +1,75 @@
'use strict';
const test = require('node:test');
const assert = require('node:assert/strict');
const DashboardApi = require('../../src/specificClass.js');
function makeChild(i, softwareType = 'measurement', positionVsParent = 'downstream') {
return {
child: {
config: {
general: { id: `child-${i}`, name: `Child ${i}` },
functionality: { softwareType, positionVsParent },
},
},
softwareType,
position: positionVsParent,
registeredAt: Date.now(),
};
}
function makeRoot(children) {
const map = new Map();
for (const c of children) map.set(c.child.config.general.id, c);
return {
config: {
general: { id: 'root-1', name: 'Root' },
functionality: { softwareType: 'dashboardapi', positionVsParent: 'atequipment' },
},
childRegistrationUtils: { registeredChildren: map },
};
}
test('generateDashboardsForGraph composes 50 children in <500ms', () => {
const api = new DashboardApi({});
const children = Array.from({ length: 50 }, (_, i) => makeChild(i));
const root = makeRoot(children);
const t0 = process.hrtime.bigint();
const dashboards = api.generateDashboardsForGraph(root, { includeChildren: true });
const t1 = process.hrtime.bigint();
const durationMs = Number(t1 - t0) / 1e6;
assert.ok(durationMs < 500, `composition took ${durationMs.toFixed(1)}ms, expected <500ms`);
assert.ok(dashboards.length >= 1, 'should produce at least the root dashboard');
});
test('uids are unique across all generated dashboards (no collision risk)', () => {
const api = new DashboardApi({});
const children = Array.from({ length: 30 }, (_, i) => makeChild(i, 'measurement'));
const root = makeRoot(children);
const dashboards = api.generateDashboardsForGraph(root);
const uids = dashboards.map((d) => d.uid);
const unique = new Set(uids);
assert.equal(unique.size, uids.length, `expected ${uids.length} unique uids, got ${unique.size}`);
});
test('byte-identical composition under repeat (idempotency)', () => {
const api = new DashboardApi({});
const children = Array.from({ length: 5 }, (_, i) => makeChild(i));
const root = makeRoot(children);
const first = JSON.stringify(api.generateDashboardsForGraph(root).map((d) => d.dashboard));
const second = JSON.stringify(api.generateDashboardsForGraph(root).map((d) => d.dashboard));
assert.equal(first, second, 'two consecutive compositions should produce byte-identical JSON');
});
test('root dashboard links to every child dashboard', () => {
const api = new DashboardApi({});
const children = Array.from({ length: 4 }, (_, i) => makeChild(i));
const root = makeRoot(children);
const dashboards = api.generateDashboardsForGraph(root);
const rootDash = dashboards[0].dashboard;
assert.ok(Array.isArray(rootDash.links), 'root dashboard should have links array');
assert.equal(rootDash.links.length, 4, 'one link per registered child');
});

View File

@@ -0,0 +1,73 @@
'use strict';
const test = require('node:test');
const assert = require('node:assert/strict');
const DashboardApi = require('../../src/specificClass.js');
test('subtreeChanged: null diff → always regen (safe default for cold start)', () => {
const api = new DashboardApi({});
assert.equal(api.subtreeChanged(null, new Set(['a', 'b'])), true);
assert.equal(api.subtreeChanged(undefined, new Set(['a', 'b'])), true);
});
test('subtreeChanged: empty diff arrays → no regen needed', () => {
const api = new DashboardApi({});
const diff = { added: [], changed: [], removed: [], rewired: [], linked: [], flowChanged: [] };
assert.equal(api.subtreeChanged(diff, new Set(['a', 'b'])), false);
});
test('subtreeChanged: id in added → regen', () => {
const api = new DashboardApi({});
const diff = { added: ['x', 'b'], changed: [], removed: [], rewired: [] };
assert.equal(api.subtreeChanged(diff, new Set(['a', 'b'])), true);
});
test('subtreeChanged: id in changed → regen', () => {
const api = new DashboardApi({});
const diff = { added: [], changed: ['a'], removed: [], rewired: [] };
assert.equal(api.subtreeChanged(diff, new Set(['a', 'b'])), true);
});
test('subtreeChanged: only unrelated ids → no regen', () => {
const api = new DashboardApi({});
const diff = { added: ['z'], changed: ['y'], removed: ['x'], rewired: ['w'] };
assert.equal(api.subtreeChanged(diff, new Set(['a', 'b'])), false);
});
test('subtreeChanged: tab id in diff but not in subtree → no regen', () => {
// Tab id over-triggering avoidance: when an unrelated tab changes, its
// tab id lands in changed/added but should not affect this dashboardAPI.
const api = new DashboardApi({});
const diff = { added: [], changed: ['unrelated_tab'], removed: [], rewired: [] };
assert.equal(api.subtreeChanged(diff, new Set(['dashboardApiId', 'childA'])), false);
});
test('subtreeIdsFor: includes dashboardAPI id + child id + grandchild ids', () => {
const api = new DashboardApi({});
const grandchild = {
config: { general: { id: 'gc-1' }, functionality: { softwareType: 'measurement' } },
};
const grandchildEntry = { child: grandchild, position: 'downstream', softwareType: 'measurement' };
const child = {
config: { general: { id: 'child-1' }, functionality: { softwareType: 'pumpingStation' } },
childRegistrationUtils: {
registeredChildren: new Map([['gc-1', grandchildEntry]]),
},
};
const ids = api.subtreeIdsFor('dApi-1', child);
assert.equal(ids.has('dApi-1'), true);
assert.equal(ids.has('child-1'), true);
assert.equal(ids.has('gc-1'), true);
assert.equal(ids.size, 3);
});
test('subtreeIdsFor: handles child with no grandchildren', () => {
const api = new DashboardApi({});
const child = {
config: { general: { id: 'child-1' }, functionality: { softwareType: 'measurement' } },
};
const ids = api.subtreeIdsFor('dApi-1', child);
assert.equal(ids.size, 2);
assert.ok(ids.has('dApi-1') && ids.has('child-1'));
});

View File

@@ -0,0 +1,40 @@
'use strict';
const test = require('node:test');
const assert = require('node:assert/strict');
const DashboardApi = require('../../src/specificClass.js');
test('rotatingMachine template panels declare meta.emittedFields', () => {
const api = new DashboardApi({});
const dash = api.loadTemplate('machine');
assert.ok(dash, 'template loaded');
const withFields = dash.panels.filter((p) => p?.meta?.emittedFields);
// 13 non-row panels in machine.json get annotated; row panels are skipped.
assert.ok(withFields.length >= 10, `expected ≥10 annotated panels, got ${withFields.length}`);
});
test('collectEmittedFields aggregates fields across panels', () => {
const api = new DashboardApi({});
const dash = api.loadTemplate('machine');
const fields = api.collectEmittedFields(dash);
assert.ok(fields.has('ctrl'), 'ctrl field declared by Ctrl % panel');
assert.ok(fields.has('flow'), 'flow field declared by Flow panel');
assert.ok(fields.has('efficiency'), 'efficiency field declared by Efficiency panel');
assert.ok(fields.has('relDistFromPeak'), 'relDistFromPeak declared by Distance from Peak panel');
});
test('collectEmittedFields returns empty Set for template without meta', () => {
const api = new DashboardApi({});
// measurement.json has no emittedFields metadata yet — its panels predate the annotation.
const dash = api.loadTemplate('measurement');
const fields = api.collectEmittedFields(dash);
assert.equal(fields.size, 0);
});
test('collectEmittedFields handles null/empty dashboard input gracefully', () => {
const api = new DashboardApi({});
assert.equal(api.collectEmittedFields(null).size, 0);
assert.equal(api.collectEmittedFields({}).size, 0);
assert.equal(api.collectEmittedFields({ panels: [] }).size, 0);
});