@cloudcare/guance-front-tools 1.0.12 → 1.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/guance-all-charts.json +3415 -0
- package/lib/cjs/generated/dashboardCharts.d.ts +54 -13
- package/lib/cjs/scripts/grafana-covert-to-guance-core.d.ts +1 -1
- package/lib/cjs/scripts/grafana-covert-to-guance-core.js +5 -289
- package/lib/esm/generated/dashboardCharts.d.ts +54 -13
- package/lib/esm/scripts/grafana-covert-to-guance-core.d.ts +1 -1
- package/lib/esm/scripts/grafana-covert-to-guance-core.js +5 -289
- package/lib/example/grafana2.json +878 -0
- package/lib/example/guance-dahs-3.json +348 -0
- package/lib/scripts/grafana-covert-to-guance-core.js +5 -286
- package/lib/scripts/grafana-covert-to-guance-core.ts +12 -326
- package/lib/scripts/grafana-covert-to-guance.js +52 -29
- package/lib/scripts/grafana-covert-to-guance.ts +60 -32
- package/package.json +4 -3
- package/schemas/charts/chart-schema.json +8 -5
- package/schemas/charts/common/chart-link-item-schema.json +48 -0
- package/schemas/charts/common/chart-links-schema.json +9 -0
- package/schemas/charts/common/common-chart-types-schema.json +3 -1
- package/schemas/charts/dashboard-schema.json +11 -4
- package/schemas/charts/query/query-item-schema.json +19 -1
- package/schemas/charts/settings/settings-time-schema.json +1 -5
- package/schemas/charts/settings/settings-unit-items-schema.json +3 -1
- package/schemas/charts/settings/settings-units-schema.json +2 -3
- package/scripts/validate-file.mjs +57 -0
- package/skills/grafana-to-guance-dashboard/SKILL.md +102 -0
- package/skills/grafana-to-guance-dashboard/agents/openai.yaml +4 -0
- package/skills/grafana-to-guance-dashboard/references/converter-notes.md +134 -0
- package/skills/grafana-to-guance-dashboard/scripts/convert-grafana-dashboard.mjs +1899 -0
- package/test/cli.test.mjs +316 -0
- package/test-output/grafana2.cli.guance.json +1029 -0
- package/test-output/grafana2.guance.json +1029 -0
- package/test-output/grafana2.keep-meta.guance.json +1384 -0
- package/test-output/pod.guance.json +2153 -0
- package/test-output/skill-test2-enhanced.guance.json +21596 -0
- package/test-output/skill-test2-validated.guance.json +11610 -0
- package/test-output/skill-test2.guance.json +11610 -0
- package/test-output/test.guance.json +1086 -0
- package/test-output/test2.guance.guance-promql.json +23212 -0
- package/test-output/test2.guance.json +17554 -0
|
@@ -1,291 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
timeseries: 'sequence',
|
|
6
|
-
graph: 'sequence',
|
|
7
|
-
piechart: 'pie',
|
|
8
|
-
histogram: 'histogram',
|
|
9
|
-
bargauge: 'toplist',
|
|
10
|
-
gauge: 'gauge',
|
|
11
|
-
table: 'table',
|
|
12
|
-
text: 'text',
|
|
13
|
-
heatmap: 'heatmap',
|
|
14
|
-
treemap: 'treemap',
|
|
15
|
-
};
|
|
16
|
-
var GRAFANA_KEYWORKD = ['__interval'];
|
|
17
|
-
var VARIABLE_MAP = {
|
|
18
|
-
query: 'PROMQL_QUERY',
|
|
19
|
-
custom: 'CUSTOM_LIST',
|
|
20
|
-
};
|
|
21
|
-
var VARIABLE_DATASOURCE_MAP = {
|
|
22
|
-
query: 'dataflux',
|
|
23
|
-
custom: 'custom',
|
|
24
|
-
};
|
|
25
|
-
function isSupportedVariableType(type) {
|
|
26
|
-
return Object.prototype.hasOwnProperty.call(VARIABLE_MAP, type);
|
|
27
|
-
}
|
|
28
|
-
function replaceVariableStr(grafanaExpr) {
|
|
29
|
-
return grafanaExpr.replace(/\$\{?([\d_\w]+)\}?/g, function (match, variable) {
|
|
30
|
-
if (GRAFANA_KEYWORKD.indexOf(variable) > -1)
|
|
31
|
-
return match;
|
|
32
|
-
return "#{".concat(variable, "}");
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
function sortPanelItemsByRowCol(panels) {
|
|
36
|
-
return panels.slice(0).sort(function (panelA, panelB) {
|
|
37
|
-
var posA = panelA.gridPos;
|
|
38
|
-
var posB = panelB.gridPos;
|
|
39
|
-
if (!posA || !posB)
|
|
40
|
-
return -1;
|
|
41
|
-
if (posA.y === posB.y && posA.x === posB.x && posA.w > posB.w) {
|
|
42
|
-
return -1;
|
|
43
|
-
}
|
|
44
|
-
if (posA.y === posB.y && posA.x === posB.x) {
|
|
45
|
-
return 0;
|
|
46
|
-
}
|
|
47
|
-
if (posA.y > posB.y || (posA.y === posB.y && posA.x > posB.x)) {
|
|
48
|
-
return 1;
|
|
49
|
-
}
|
|
50
|
-
return -1;
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
function tenToTweenty(source) {
|
|
54
|
-
if (source === void 0) { source = 1; }
|
|
55
|
-
var numArr = [];
|
|
56
|
-
source--;
|
|
57
|
-
do {
|
|
58
|
-
numArr.push(source % 26);
|
|
59
|
-
source = Math.floor(source / 26);
|
|
60
|
-
} while (source > 0);
|
|
61
|
-
return numArr
|
|
62
|
-
.reverse()
|
|
63
|
-
.map(function (item, index) {
|
|
64
|
-
return String.fromCharCode(item + 97 + (index === numArr.length - 1 ? 0 : -1));
|
|
65
|
-
})
|
|
66
|
-
.join('')
|
|
67
|
-
.toLowerCase();
|
|
68
|
-
}
|
|
69
|
-
function getGridH(h, rowHeight, margin) {
|
|
70
|
-
return Math.round(h * rowHeight + Math.max(0, 2 * (h - 1)) * margin);
|
|
71
|
-
}
|
|
72
|
-
function getGuanceHByGrafanaH(granfanH) {
|
|
73
|
-
return (getGridH(granfanH, 30, 4) + 10) / 20;
|
|
74
|
-
}
|
|
75
|
-
function covertPanelToGuanceChart(grafanaPanel, rowPanel) {
|
|
76
|
-
var gridPos = grafanaPanel.gridPos, title = grafanaPanel.title, type = grafanaPanel.type, targets = grafanaPanel.targets, options = grafanaPanel.options;
|
|
77
|
-
var chartType = grafanaPanelTypeToGuanceChartMap[type];
|
|
78
|
-
var pos = {
|
|
79
|
-
x: gridPos.x,
|
|
80
|
-
w: gridPos.w,
|
|
81
|
-
y: gridPos.y,
|
|
82
|
-
h: gridPos.h,
|
|
83
|
-
};
|
|
84
|
-
if (rowPanel) {
|
|
85
|
-
var rowGridPos = rowPanel.gridPos;
|
|
86
|
-
if (rowGridPos && gridPos && !rowPanel.collapsed) {
|
|
87
|
-
pos = {
|
|
88
|
-
x: gridPos.x,
|
|
89
|
-
w: gridPos.w,
|
|
90
|
-
y: gridPos.y - rowGridPos.y,
|
|
91
|
-
h: gridPos.h,
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
var queries = [];
|
|
96
|
-
if (targets && targets.length) {
|
|
97
|
-
var currentIndex_1 = 0;
|
|
98
|
-
targets.forEach(function (_target) {
|
|
99
|
-
var queryStr = _target.expr || _target.query || _target.queryText;
|
|
100
|
-
if (!queryStr)
|
|
101
|
-
return;
|
|
102
|
-
currentIndex_1++;
|
|
103
|
-
var queryItem = {
|
|
104
|
-
datasource: 'dataflux',
|
|
105
|
-
qtype: 'promql',
|
|
106
|
-
type: chartType,
|
|
107
|
-
query: {
|
|
108
|
-
q: replaceVariableStr(queryStr),
|
|
109
|
-
type: 'promql',
|
|
110
|
-
code: tenToTweenty(currentIndex_1),
|
|
111
|
-
promqlCode: currentIndex_1,
|
|
112
|
-
},
|
|
113
|
-
};
|
|
114
|
-
queries.push(queryItem);
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
var settings = {};
|
|
118
|
-
if (options) {
|
|
119
|
-
switch (chartType) {
|
|
120
|
-
case 'text':
|
|
121
|
-
queries.push({
|
|
122
|
-
query: {
|
|
123
|
-
content: options.content,
|
|
124
|
-
},
|
|
125
|
-
});
|
|
126
|
-
break;
|
|
127
|
-
case 'toplist':
|
|
128
|
-
settings = {
|
|
129
|
-
showTopSize: true,
|
|
130
|
-
chartType: 'bar',
|
|
131
|
-
};
|
|
132
|
-
break;
|
|
133
|
-
default:
|
|
134
|
-
break;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
return {
|
|
138
|
-
extend: {
|
|
139
|
-
settings: settings,
|
|
140
|
-
},
|
|
141
|
-
group: {
|
|
142
|
-
name: rowPanel ? rowPanel.title : null,
|
|
143
|
-
},
|
|
144
|
-
pos: {
|
|
145
|
-
x: pos.x,
|
|
146
|
-
y: getGuanceHByGrafanaH(pos.y),
|
|
147
|
-
h: getGuanceHByGrafanaH(pos.h),
|
|
148
|
-
w: pos.w,
|
|
149
|
-
},
|
|
150
|
-
name: replaceVariableStr(title || ''),
|
|
151
|
-
queries: queries,
|
|
152
|
-
type: chartType,
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
function covertPanelsToCharts(grafanaPanelData, rowPanel) {
|
|
156
|
-
var guanceCharts = [];
|
|
157
|
-
grafanaPanelData.forEach(function (grafanaPanel) {
|
|
158
|
-
if (!grafanaPanel.gridPos)
|
|
159
|
-
return;
|
|
160
|
-
guanceCharts.push(covertPanelToGuanceChart(grafanaPanel, rowPanel));
|
|
161
|
-
});
|
|
162
|
-
return guanceCharts;
|
|
163
|
-
}
|
|
1
|
+
// This script is the shared conversion source for the published API and CLI.
|
|
2
|
+
// Keep it thin and delegate to the maintained converter implementation.
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
import { convertDashboard } from '../../skills/grafana-to-guance-dashboard/scripts/convert-grafana-dashboard.mjs';
|
|
164
5
|
export function covert(grafanaData) {
|
|
165
|
-
|
|
166
|
-
var covertGuanceResult = {};
|
|
167
|
-
covertGuanceResult.title = grafanaData.title;
|
|
168
|
-
var guanceVars = [];
|
|
169
|
-
(_b = (_a = grafanaData.templating) === null || _a === void 0 ? void 0 : _a.list) === null || _b === void 0 ? void 0 : _b.forEach(function (_variable, index) {
|
|
170
|
-
var current = _variable.current, type = _variable.type, allValue = _variable.allValue;
|
|
171
|
-
var variableType = String(type);
|
|
172
|
-
if (!isSupportedVariableType(variableType))
|
|
173
|
-
return;
|
|
174
|
-
var defaultVal = {
|
|
175
|
-
label: '',
|
|
176
|
-
value: '',
|
|
177
|
-
};
|
|
178
|
-
if (current) {
|
|
179
|
-
var labels = [];
|
|
180
|
-
var values = [];
|
|
181
|
-
if (Array.isArray(current.text)) {
|
|
182
|
-
labels = current.text;
|
|
183
|
-
}
|
|
184
|
-
else if (typeof current.text === 'string') {
|
|
185
|
-
labels = [current.text];
|
|
186
|
-
}
|
|
187
|
-
if (Array.isArray(current.value)) {
|
|
188
|
-
values = current.value;
|
|
189
|
-
}
|
|
190
|
-
else if (typeof current.value === 'string') {
|
|
191
|
-
values = [current.value];
|
|
192
|
-
}
|
|
193
|
-
labels = labels.map(function (label) {
|
|
194
|
-
if (label === 'All') {
|
|
195
|
-
if (allValue === '.*') {
|
|
196
|
-
return '*';
|
|
197
|
-
}
|
|
198
|
-
return 'all values';
|
|
199
|
-
}
|
|
200
|
-
return label;
|
|
201
|
-
});
|
|
202
|
-
values = values.map(function (value) {
|
|
203
|
-
if (value === '$__all') {
|
|
204
|
-
if (allValue === '.*') {
|
|
205
|
-
return '*';
|
|
206
|
-
}
|
|
207
|
-
return '__all__';
|
|
208
|
-
}
|
|
209
|
-
return value;
|
|
210
|
-
});
|
|
211
|
-
defaultVal = {
|
|
212
|
-
label: labels.join(','),
|
|
213
|
-
value: values.join(','),
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
var value = _variable.query;
|
|
217
|
-
if (value && typeof value === 'object' && value.query) {
|
|
218
|
-
value = replaceVariableStr(value.query);
|
|
219
|
-
}
|
|
220
|
-
else if (value && typeof value === 'string') {
|
|
221
|
-
value = replaceVariableStr(_variable.query);
|
|
222
|
-
}
|
|
223
|
-
else {
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
var guanceVariableItem = {
|
|
227
|
-
type: VARIABLE_MAP[variableType],
|
|
228
|
-
datasource: VARIABLE_DATASOURCE_MAP[variableType],
|
|
229
|
-
name: _variable.label || _variable.name || '',
|
|
230
|
-
seq: index,
|
|
231
|
-
hide: _variable.hide ? 1 : 0,
|
|
232
|
-
multiple: _variable.multi !== undefined ? _variable.multi : true,
|
|
233
|
-
includeStar: _variable.includeAll !== undefined ? _variable.includeAll : true,
|
|
234
|
-
valueSort: 'desc',
|
|
235
|
-
code: _variable.name,
|
|
236
|
-
definition: {
|
|
237
|
-
value: value,
|
|
238
|
-
defaultVal: defaultVal,
|
|
239
|
-
},
|
|
240
|
-
};
|
|
241
|
-
guanceVars.push(guanceVariableItem);
|
|
242
|
-
});
|
|
243
|
-
var guanceGroups = [];
|
|
244
|
-
var guanceExpand = {};
|
|
245
|
-
var guanceCharts = [];
|
|
246
|
-
var lastRowPanel;
|
|
247
|
-
var lastPanels = [];
|
|
248
|
-
var grafanaCharts = ((_c = grafanaData.panels) === null || _c === void 0 ? void 0 : _c.filter(function (_panel) { return _panel.type === 'row' || grafanaPanelTypeToGuanceChartMap[_panel.type]; })) || [];
|
|
249
|
-
grafanaCharts = sortPanelItemsByRowCol(grafanaCharts);
|
|
250
|
-
grafanaCharts.forEach(function (_panel) {
|
|
251
|
-
var _a;
|
|
252
|
-
if (_panel.type === 'row') {
|
|
253
|
-
var _rowPanel = _panel;
|
|
254
|
-
if (_rowPanel.title) {
|
|
255
|
-
guanceGroups.push({
|
|
256
|
-
name: _rowPanel.title,
|
|
257
|
-
});
|
|
258
|
-
guanceExpand[_rowPanel.title] = !_rowPanel.collapsed;
|
|
259
|
-
}
|
|
260
|
-
if (lastPanels.length) {
|
|
261
|
-
guanceCharts.push.apply(guanceCharts, covertPanelsToCharts(lastPanels, lastRowPanel));
|
|
262
|
-
lastPanels = [];
|
|
263
|
-
lastRowPanel = undefined;
|
|
264
|
-
}
|
|
265
|
-
if (_rowPanel.collapsed) {
|
|
266
|
-
var subPanels = ((_a = _rowPanel.panels) === null || _a === void 0 ? void 0 : _a.filter(function (_childPanel) {
|
|
267
|
-
return _childPanel.type === 'row' || grafanaPanelTypeToGuanceChartMap[_childPanel.type];
|
|
268
|
-
})) || [];
|
|
269
|
-
guanceCharts.push.apply(guanceCharts, covertPanelsToCharts(subPanels, _rowPanel));
|
|
270
|
-
}
|
|
271
|
-
else {
|
|
272
|
-
lastRowPanel = _rowPanel;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
else {
|
|
276
|
-
lastPanels.push(_panel);
|
|
277
|
-
}
|
|
278
|
-
});
|
|
279
|
-
if (lastPanels.length) {
|
|
280
|
-
guanceCharts.push.apply(guanceCharts, covertPanelsToCharts(lastPanels, lastRowPanel));
|
|
281
|
-
}
|
|
282
|
-
covertGuanceResult.dashboardExtend = {
|
|
283
|
-
groupUnfoldStatus: guanceExpand,
|
|
284
|
-
};
|
|
285
|
-
covertGuanceResult.main = {
|
|
286
|
-
vars: guanceVars,
|
|
287
|
-
charts: guanceCharts,
|
|
288
|
-
groups: guanceGroups,
|
|
289
|
-
};
|
|
290
|
-
return covertGuanceResult;
|
|
6
|
+
return convertDashboard(grafanaData);
|
|
291
7
|
}
|