Compare commits
3 Commits
slice/35-m
...
slice/38-d
| Author | SHA1 | Date | |
|---|---|---|---|
| e5099de986 | |||
| 8639b02e6a | |||
| aac71eb129 |
1041
config/machine.json
1041
config/machine.json
File diff suppressed because it is too large
Load Diff
@@ -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
|
||||||
}
|
}
|
||||||
@@ -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),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -26,6 +26,29 @@ 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) {
|
||||||
@@ -78,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();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,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`;
|
||||||
@@ -168,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');
|
||||||
|
|||||||
73
test/basic/slice36-diff-predicate.basic.test.js
Normal file
73
test/basic/slice36-diff-predicate.basic.test.js
Normal 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'));
|
||||||
|
});
|
||||||
40
test/basic/slice37-emitted-fields.basic.test.js
Normal file
40
test/basic/slice37-emitted-fields.basic.test.js
Normal 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);
|
||||||
|
});
|
||||||
43
test/basic/slice38-dashed-bounds.basic.test.js
Normal file
43
test/basic/slice38-dashed-bounds.basic.test.js
Normal 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('rotatingMachine template carries byRegexp dashed overrides for .min/.max', () => {
|
||||||
|
const api = new DashboardApi({});
|
||||||
|
const dash = api.loadTemplate('machine');
|
||||||
|
const ts = dash.panels.filter((p) => p.type === 'timeseries');
|
||||||
|
assert.ok(ts.length >= 1, 'has at least one timeseries panel');
|
||||||
|
|
||||||
|
for (const panel of ts) {
|
||||||
|
const overrides = panel?.fieldConfig?.overrides || [];
|
||||||
|
const minOv = overrides.find(
|
||||||
|
(o) => o.matcher?.id === 'byRegexp' && /\.min\$/.test(o.matcher?.options || '')
|
||||||
|
);
|
||||||
|
const maxOv = overrides.find(
|
||||||
|
(o) => o.matcher?.id === 'byRegexp' && /\.max\$/.test(o.matcher?.options || '')
|
||||||
|
);
|
||||||
|
assert.ok(minOv, `panel "${panel.title}" missing .min override`);
|
||||||
|
assert.ok(maxOv, `panel "${panel.title}" missing .max override`);
|
||||||
|
|
||||||
|
const lineStyle = minOv.properties.find((p) => p.id === 'custom.lineStyle');
|
||||||
|
assert.equal(lineStyle?.value?.fill, 'dash', '.min override sets dashed lineStyle');
|
||||||
|
assert.deepEqual(lineStyle?.value?.dash, [10, 10], '.min override sets dash pattern [10,10]');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('dashed overrides are forward-compatible: no effect when fields absent', () => {
|
||||||
|
// The byRegexp matcher only affects series whose name ends in .min/.max.
|
||||||
|
// When the node doesn't emit those fields, the override has no effect on
|
||||||
|
// the rendered panel — series simply don't appear. Verified by the
|
||||||
|
// matcher pattern being a strict regex.
|
||||||
|
const api = new DashboardApi({});
|
||||||
|
const dash = api.loadTemplate('machine');
|
||||||
|
const ts = dash.panels.filter((p) => p.type === 'timeseries')[0];
|
||||||
|
const minOv = ts.fieldConfig.overrides.find(
|
||||||
|
(o) => o.matcher?.id === 'byRegexp' && /\.min\$/.test(o.matcher.options || '')
|
||||||
|
);
|
||||||
|
assert.match(minOv.matcher.options, /\$$/, 'matcher anchored to end of name');
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user