working
This commit is contained in:
@@ -45,6 +45,10 @@ function updateTemplatingVar(dashboard, varName, value) {
|
||||
variable.query = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dashboard domain service.
|
||||
* Builds Grafana dashboard payloads from EVOLV node config and child topology.
|
||||
*/
|
||||
class DashboardApi {
|
||||
constructor(config = {}) {
|
||||
this.config = {
|
||||
@@ -88,11 +92,13 @@ class DashboardApi {
|
||||
if (fs.existsSync(fullPath)) return fullPath;
|
||||
}
|
||||
|
||||
throw new Error(`No dashboard template found for softwareType=${st}`);
|
||||
this.logger.warn(`No dashboard template found for softwareType=${st}`);
|
||||
return null;
|
||||
}
|
||||
|
||||
loadTemplate(softwareType) {
|
||||
const templatePath = this._templateFileForSoftwareType(softwareType);
|
||||
if (!templatePath) return null;
|
||||
const raw = fs.readFileSync(templatePath, 'utf8');
|
||||
return JSON.parse(raw);
|
||||
}
|
||||
@@ -111,7 +117,12 @@ class DashboardApi {
|
||||
const measurementName = `${softwareType}_${nodeId}`;
|
||||
const title = nodeConfig?.general?.name || String(nodeId);
|
||||
|
||||
// Missing templates are treated as non-fatal: we skip only that dashboard.
|
||||
const dashboard = this.loadTemplate(softwareType);
|
||||
if (!dashboard) {
|
||||
this.logger.warn(`Skipping dashboard generation: no template for softwareType=${softwareType}`);
|
||||
return null;
|
||||
}
|
||||
const uid = stableUid(`${softwareType}:${nodeId}`);
|
||||
|
||||
dashboard.id = null;
|
||||
@@ -150,11 +161,13 @@ class DashboardApi {
|
||||
|
||||
generateDashboardsForGraph(rootSource, { includeChildren = true } = {}) {
|
||||
if (!rootSource?.config) {
|
||||
throw new Error('generateDashboardsForGraph requires a node source with `.config`');
|
||||
this.logger.warn('generateDashboardsForGraph skipped: root source missing config');
|
||||
return [];
|
||||
}
|
||||
|
||||
const rootPosition = rootSource?.positionVsParent || rootSource?.config?.functionality?.positionVsParent;
|
||||
const rootDash = this.buildDashboard({ nodeConfig: rootSource.config, positionVsParent: rootPosition });
|
||||
if (!rootDash) return [];
|
||||
|
||||
const results = [rootDash];
|
||||
|
||||
@@ -163,7 +176,7 @@ class DashboardApi {
|
||||
const children = this.extractChildren(rootSource);
|
||||
for (const { childSource, positionVsParent } of children) {
|
||||
const childDash = this.buildDashboard({ nodeConfig: childSource.config, positionVsParent });
|
||||
results.push(childDash);
|
||||
if (childDash) results.push(childDash);
|
||||
}
|
||||
|
||||
// Add links from the root dashboard to children dashboards (when possible)
|
||||
|
||||
Reference in New Issue
Block a user