@cloudcare/guance-front-tools 1.0.19 → 1.0.21
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/README.md +0 -64
- package/lib/cjs/generated/dashboardCharts.d.ts +172 -69
- package/lib/cjs/scripts/convert-grafana-dashboard-core.js +417 -56
- package/lib/esm/generated/dashboardCharts.d.ts +172 -69
- package/lib/esm/scripts/convert-grafana-dashboard-core.js +417 -56
- package/lib/example/1860_rev45.json +15536 -0
- package/lib/example/guance-dashboard.json +16766 -2702
- package/lib/scripts/convert-grafana-dashboard-core.js +1899 -1633
- package/package.json +1 -1
- package/schemas/charts/chart-schema.json +711 -1
- package/schemas/charts/settings/_common-settings-gradual-color-schema.json +17 -3
- package/schemas/charts/settings/_common-settings-legend-values-schema.json +23 -15
- package/{skills/grafana-to-guance-dashboard/schemas/charts/settings/chart-treemap-settings-schema.json → schemas/charts/settings/chart-change-settings-schema.json} +34 -32
- package/schemas/charts/settings/chart-chinamap-settings-schema.json +2 -1
- package/schemas/charts/settings/chart-command-settings-schema.json +16 -0
- package/schemas/charts/settings/chart-hexgon-settings-schema.json +2 -1
- package/{skills/grafana-to-guance-dashboard/schemas/charts/settings/chart-log-settings-schema.json → schemas/charts/settings/chart-monitor-settings-schema.json} +27 -30
- package/schemas/charts/settings/chart-sequence-settings-schema.json +2 -3
- package/schemas/charts/settings/chart-topology-settings-schema.json +1 -6
- package/schemas/charts/settings/chart-video-settings-schema.json +45 -0
- package/schemas/charts/settings/chart-worldmap-settings-schema.json +2 -1
- package/schemas/charts/settings/settings-alias-schema.json +14 -1
- package/schemas/charts/settings/settings-compare-schema.json +20 -12
- package/schemas/charts/settings/settings-schema.json +13 -1
- package/schemas/charts/settings/settings-time-schema.json +38 -23
- package/schemas/charts/settings/settings-unit-items-schema.json +222 -210
- package/schemas/charts/settings/settings-units-schema.json +0 -3
- package/test/cli.test.mjs +66 -44
- package/skills/grafana-to-guance-dashboard/SKILL.md +0 -490
- package/skills/grafana-to-guance-dashboard/agents/openai.yaml +0 -4
- package/skills/grafana-to-guance-dashboard/fixtures/grafana-dashboard.guance.json +0 -1029
- package/skills/grafana-to-guance-dashboard/fixtures/grafana-dashboard.json +0 -878
- package/skills/grafana-to-guance-dashboard/package.json +0 -16
- package/skills/grafana-to-guance-dashboard/references/conversion-audit-checklist.md +0 -183
- package/skills/grafana-to-guance-dashboard/references/converter-notes.md +0 -244
- package/skills/grafana-to-guance-dashboard/references/promql-compatibility-cheatsheet.md +0 -172
- package/skills/grafana-to-guance-dashboard/references/unit-inference-cheatsheet.md +0 -174
- package/skills/grafana-to-guance-dashboard/schemas/charts/chart-schema.json +0 -84
- package/skills/grafana-to-guance-dashboard/schemas/charts/common/chart-link-item-schema.json +0 -48
- package/skills/grafana-to-guance-dashboard/schemas/charts/common/chart-links-schema.json +0 -9
- package/skills/grafana-to-guance-dashboard/schemas/charts/common/common-chart-types-schema.json +0 -39
- package/skills/grafana-to-guance-dashboard/schemas/charts/common/common-vars-item-schema.json +0 -117
- package/skills/grafana-to-guance-dashboard/schemas/charts/common/common-vars-schema.json +0 -10
- package/skills/grafana-to-guance-dashboard/schemas/charts/dashboard-schema.json +0 -80
- package/skills/grafana-to-guance-dashboard/schemas/charts/query/queries-schema.json +0 -10
- package/skills/grafana-to-guance-dashboard/schemas/charts/query/query-item-schema.json +0 -60
- package/skills/grafana-to-guance-dashboard/schemas/charts/settings/_common-settings-connect-null-schema.json +0 -7
- package/skills/grafana-to-guance-dashboard/schemas/charts/settings/_common-settings-gradual-color-schema.json +0 -72
- package/skills/grafana-to-guance-dashboard/schemas/charts/settings/_common-settings-groupby-schema.json +0 -22
- package/skills/grafana-to-guance-dashboard/schemas/charts/settings/_common-settings-legend-position-schema.json +0 -14
- package/skills/grafana-to-guance-dashboard/schemas/charts/settings/_common-settings-legend-values-schema.json +0 -19
- package/skills/grafana-to-guance-dashboard/schemas/charts/settings/_common-settings-open-stack-schema.json +0 -8
- package/skills/grafana-to-guance-dashboard/schemas/charts/settings/_common-settings-show-label-schema.json +0 -8
- package/skills/grafana-to-guance-dashboard/schemas/charts/settings/_common-settings-show-line-schema.json +0 -8
- package/skills/grafana-to-guance-dashboard/schemas/charts/settings/_common-settings-stack-content-schema.json +0 -12
- package/skills/grafana-to-guance-dashboard/schemas/charts/settings/_common-settings-stack-type-schema.json +0 -11
- package/skills/grafana-to-guance-dashboard/schemas/charts/settings/chart-alarm-settings-schema.json +0 -48
- package/skills/grafana-to-guance-dashboard/schemas/charts/settings/chart-bar-settings-schema.json +0 -69
- package/skills/grafana-to-guance-dashboard/schemas/charts/settings/chart-chinamap-settings-schema.json +0 -102
- package/skills/grafana-to-guance-dashboard/schemas/charts/settings/chart-funnel-settings-schema.json +0 -34
- package/skills/grafana-to-guance-dashboard/schemas/charts/settings/chart-gauge-settings-schema.json +0 -65
- package/skills/grafana-to-guance-dashboard/schemas/charts/settings/chart-heatmap-settings-schema.json +0 -50
- package/skills/grafana-to-guance-dashboard/schemas/charts/settings/chart-hexgon-settings-schema.json +0 -90
- package/skills/grafana-to-guance-dashboard/schemas/charts/settings/chart-histogram-settings-schema.json +0 -47
- package/skills/grafana-to-guance-dashboard/schemas/charts/settings/chart-iframe-settings-schema.json +0 -24
- package/skills/grafana-to-guance-dashboard/schemas/charts/settings/chart-object-settings-schema.json +0 -52
- package/skills/grafana-to-guance-dashboard/schemas/charts/settings/chart-picture-settings-schema.json +0 -46
- package/skills/grafana-to-guance-dashboard/schemas/charts/settings/chart-pie-settings-schema.json +0 -90
- package/skills/grafana-to-guance-dashboard/schemas/charts/settings/chart-sankey-settings-schema.json +0 -34
- package/skills/grafana-to-guance-dashboard/schemas/charts/settings/chart-scatter-bubble-settings-schema.json +0 -31
- package/skills/grafana-to-guance-dashboard/schemas/charts/settings/chart-sequence-settings-schema.json +0 -76
- package/skills/grafana-to-guance-dashboard/schemas/charts/settings/chart-singlestat-settings-schema.json +0 -163
- package/skills/grafana-to-guance-dashboard/schemas/charts/settings/chart-table-settings-schema.json +0 -184
- package/skills/grafana-to-guance-dashboard/schemas/charts/settings/chart-text-settings-schema.json +0 -20
- package/skills/grafana-to-guance-dashboard/schemas/charts/settings/chart-toplist-settings-schema.json +0 -117
- package/skills/grafana-to-guance-dashboard/schemas/charts/settings/chart-topology-settings-schema.json +0 -71
- package/skills/grafana-to-guance-dashboard/schemas/charts/settings/chart-worldmap-settings-schema.json +0 -102
- package/skills/grafana-to-guance-dashboard/schemas/charts/settings/common-settings-schema.json +0 -82
- package/skills/grafana-to-guance-dashboard/schemas/charts/settings/settings-alias-schema.json +0 -47
- package/skills/grafana-to-guance-dashboard/schemas/charts/settings/settings-chart-type-schema.json +0 -27
- package/skills/grafana-to-guance-dashboard/schemas/charts/settings/settings-colors-schema.json +0 -46
- package/skills/grafana-to-guance-dashboard/schemas/charts/settings/settings-compare-schema.json +0 -58
- package/skills/grafana-to-guance-dashboard/schemas/charts/settings/settings-fixed-time-schema.json +0 -49
- package/skills/grafana-to-guance-dashboard/schemas/charts/settings/settings-levels-schema.json +0 -33
- package/skills/grafana-to-guance-dashboard/schemas/charts/settings/settings-schema.json +0 -79
- package/skills/grafana-to-guance-dashboard/schemas/charts/settings/settings-time-schema.json +0 -43
- package/skills/grafana-to-guance-dashboard/schemas/charts/settings/settings-unit-items-schema.json +0 -228
- package/skills/grafana-to-guance-dashboard/schemas/charts/settings/settings-units-schema.json +0 -59
- package/skills/grafana-to-guance-dashboard/schemas/dashboard-schema.json +0 -5
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/browser/attribute-mutation-schema.json +0 -21
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/browser/attributes-schema.json +0 -10
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/browser/cdata-node-schema.json +0 -19
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/browser/creation-reason-schema.json +0 -17
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/browser/document-fragment-node-schema.json +0 -35
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/browser/document-node-schema.json +0 -30
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/browser/document-type-node-schema.json +0 -28
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/browser/element-node-schema.json +0 -33
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/browser/frustration-record-schema.json +0 -49
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/browser/full-snapshot-record-schema.json +0 -26
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/browser/incremental-data-schema.json +0 -36
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/browser/incremental-snapshot-record-schema.json +0 -29
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/browser/input-data-schema.json +0 -27
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/browser/input-state-schema.json +0 -27
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/browser/media-interaction-data-schema.json +0 -23
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/browser/media-interaction-schema.json +0 -20
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/browser/mouse-interaction-data-schema.json +0 -23
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/browser/mouse-interaction-schema.json +0 -47
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/browser/mouse-move-data-schema.json +0 -23
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/browser/mouse-position-schema.json +0 -26
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/browser/mutation-data-schema.json +0 -23
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/browser/mutation-payload-schema.json +0 -42
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/browser/node-added-mutation-schema.json +0 -41
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/browser/node-removed-mutation-schema.json +0 -18
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/browser/node-schema.json +0 -28
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/browser/record-schema.json +0 -30
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/browser/scroll-data-schema.json +0 -23
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/browser/scroll-position-schema.json +0 -22
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/browser/segment-metadata-schema.json +0 -28
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/browser/segment-schema.json +0 -25
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/browser/serialized-node-schema.json +0 -15
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/browser/serialized-node-with-id-schema.json +0 -21
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/browser/stylesheet-rule-add-schema.json +0 -28
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/browser/stylesheet-rule-data-schema.json +0 -23
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/browser/stylesheet-rule-delete-schema.json +0 -24
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/browser/stylesheet-rule-schema.json +0 -29
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/browser/stylesheet-schema.json +0 -30
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/browser/text-mutation-schema.json +0 -27
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/browser/text-node-schema.json +0 -23
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/common/_common-record-schema.json +0 -14
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/common/_common-segment-metadata-schema.json +0 -30
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/common/_slot-supported-common-record-schema.json +0 -21
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/common/focus-record-schema.json +0 -34
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/common/meta-record-schema.json +0 -42
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/common/pointer-interaction-data-schema.json +0 -23
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/common/pointer-interaction-schema.json +0 -34
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/common/segment-context-schema.json +0 -46
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/common/view-end-record-schema.json +0 -23
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/common/viewport-resize-data-schema.json +0 -23
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/common/viewport-resize-dimension-schema.json +0 -18
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/common/visual-viewport-record-schema.json +0 -50
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/full-snapshot-record-schema.json +0 -14
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/incremental-data-schema.json +0 -14
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/incremental-snapshot-record-schema.json +0 -14
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/mobile/_common-shape-wireframe-schema.json +0 -22
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/mobile/_common-shape-wireframe-update-schema.json +0 -22
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/mobile/_common-wireframe-schema.json +0 -38
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/mobile/_common-wireframe-update-schema.json +0 -38
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/mobile/full-snapshot-record-schema.json +0 -38
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/mobile/image-wireframe-schema.json +0 -43
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/mobile/image-wireframe-update-schema.json +0 -43
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/mobile/incremental-data-schema.json +0 -21
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/mobile/incremental-snapshot-record-schema.json +0 -26
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/mobile/mutation-data-schema.json +0 -23
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/mobile/mutation-payload-schema.json +0 -55
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/mobile/placeholder-wireframe-schema.json +0 -28
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/mobile/placeholder-wireframe-update-schema.json +0 -28
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/mobile/record-schema.json +0 -27
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/mobile/segment-metadata-schema.json +0 -25
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/mobile/segment-schema.json +0 -25
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/mobile/shape-border-schema.json +0 -25
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/mobile/shape-style-schema.json +0 -29
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/mobile/shape-wireframe-schema.json +0 -23
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/mobile/shape-wireframe-update-schema.json +0 -23
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/mobile/text-position-schema.json +0 -57
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/mobile/text-style-schema.json +0 -31
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/mobile/text-wireframe-schema.json +0 -34
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/mobile/text-wireframe-update-schema.json +0 -34
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/mobile/touch-data-schema.json +0 -51
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/mobile/webview-wireframe-schema.json +0 -33
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/mobile/webview-wireframe-update-schema.json +0 -33
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/mobile/wireframe-clip-schema.json +0 -29
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/mobile/wireframe-schema.json +0 -24
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/mobile/wireframe-update-mutation-schema.json +0 -24
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/mutation-data-schema.json +0 -14
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/mutation-payload-schema.json +0 -14
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/record-schema.json +0 -14
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/segment-metadata-schema.json +0 -14
- package/skills/grafana-to-guance-dashboard/schemas/session-replay/segment-schema.json +0 -15
- package/skills/grafana-to-guance-dashboard/schemas/session-replay-browser-schema.json +0 -5
- package/skills/grafana-to-guance-dashboard/schemas/session-replay-mobile-schema.json +0 -5
- package/skills/grafana-to-guance-dashboard/schemas/session-replay-schema.json +0 -33
- package/skills/grafana-to-guance-dashboard/scripts/convert-grafana-dashboard-core.js +0 -1675
- package/skills/grafana-to-guance-dashboard/scripts/convert-grafana-dashboard.mjs +0 -120
- package/skills/grafana-to-guance-dashboard/scripts/validate-file.mjs +0 -62
- package/skills/grafana-to-guance-dashboard/test/convert.test.mjs +0 -54
|
@@ -47,9 +47,11 @@ const PROMQL_RESERVED_WORDS = new Set([
|
|
|
47
47
|
]);
|
|
48
48
|
const UNIT_MAP = {
|
|
49
49
|
percent: ['percent', 'percent'],
|
|
50
|
+
percentunit: ['percent', 'percent_decimal'],
|
|
50
51
|
bytes: ['digital', 'B'],
|
|
51
52
|
decbytes: ['digital', 'B'],
|
|
52
53
|
bits: ['digital', 'b'],
|
|
54
|
+
decbits: ['digital', 'b'],
|
|
53
55
|
deckbytes: ['digital', 'KB'],
|
|
54
56
|
decgbytes: ['digital', 'GB'],
|
|
55
57
|
ms: ['time', 'ms'],
|
|
@@ -57,10 +59,16 @@ const UNIT_MAP = {
|
|
|
57
59
|
m: ['time', 'min'],
|
|
58
60
|
h: ['time', 'h'],
|
|
59
61
|
d: ['time', 'd'],
|
|
60
|
-
short: ['
|
|
62
|
+
short: ['number', 'short_scale'],
|
|
61
63
|
none: ['custom', 'none'],
|
|
62
|
-
reqps: ['
|
|
63
|
-
ops: ['
|
|
64
|
+
reqps: ['throughput', 'reqps'],
|
|
65
|
+
ops: ['throughput', 'ops'],
|
|
66
|
+
iops: ['throughput', 'iops'],
|
|
67
|
+
bps: ['bandWidth', 'bps'],
|
|
68
|
+
Bps: ['traffic', 'B/S'],
|
|
69
|
+
hertz: ['frequency', 'Hz'],
|
|
70
|
+
rotrpm: ['frequency', 'rpm'],
|
|
71
|
+
celsius: ['temperature', 'C'],
|
|
64
72
|
};
|
|
65
73
|
const COMPARE_OPTIONS = {
|
|
66
74
|
hourCompare: { label: '小时同比', value: 'hourCompare' },
|
|
@@ -71,14 +79,14 @@ const COMPARE_OPTIONS = {
|
|
|
71
79
|
};
|
|
72
80
|
function convertDashboard(grafanaDashboard, options = {}) {
|
|
73
81
|
var _a, _b;
|
|
74
|
-
const
|
|
82
|
+
const variableContext = buildVariableContext((((_a = grafanaDashboard.templating) === null || _a === void 0 ? void 0 : _a.list) || []), options);
|
|
75
83
|
const state = {
|
|
76
84
|
groups: [],
|
|
77
85
|
groupUnfoldStatus: {},
|
|
78
86
|
charts: [],
|
|
79
87
|
};
|
|
80
88
|
const sortedPanels = sortPanels(grafanaDashboard.panels || []);
|
|
81
|
-
collectPanels(sortedPanels, state, null, variableNames, options);
|
|
89
|
+
collectPanels(sortedPanels, state, null, variableContext.variableNames, options);
|
|
82
90
|
return pruneEmpty({
|
|
83
91
|
title: grafanaDashboard.title || '',
|
|
84
92
|
description: grafanaDashboard.description || undefined,
|
|
@@ -88,13 +96,41 @@ function convertDashboard(grafanaDashboard, options = {}) {
|
|
|
88
96
|
groupUnfoldStatus: state.groupUnfoldStatus,
|
|
89
97
|
},
|
|
90
98
|
main: {
|
|
91
|
-
vars: convertVariables(
|
|
99
|
+
vars: convertVariables(variableContext.variables, variableContext.variableNames, options),
|
|
92
100
|
charts: state.charts,
|
|
93
101
|
groups: state.groups,
|
|
94
102
|
type: 'template',
|
|
95
103
|
},
|
|
96
104
|
});
|
|
97
105
|
}
|
|
106
|
+
function buildVariableContext(variables, options = {}) {
|
|
107
|
+
const keptVariables = [];
|
|
108
|
+
const variableNames = new Set();
|
|
109
|
+
for (const variable of Array.isArray(variables) ? variables : []) {
|
|
110
|
+
if (shouldSkipVariable(variable, options)) {
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
keptVariables.push(variable);
|
|
114
|
+
if (variable === null || variable === void 0 ? void 0 : variable.name) {
|
|
115
|
+
variableNames.add(variable.name);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
variables: keptVariables,
|
|
120
|
+
variableNames,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function shouldSkipVariable(variable, options = {}) {
|
|
124
|
+
const variableType = String(variable === null || variable === void 0 ? void 0 : variable.type).toLowerCase();
|
|
125
|
+
const variableName = normalizeVariableIdentifier(variable === null || variable === void 0 ? void 0 : variable.name);
|
|
126
|
+
if (variableType === 'datasource' || variableName === 'ds_prometheus') {
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
if (options.keepJobVariable === true) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
return variableName === 'job';
|
|
133
|
+
}
|
|
98
134
|
function collectPanels(panels, state, inheritedGroup = null, variableNames = new Set(), options = {}) {
|
|
99
135
|
let activeRow = inheritedGroup;
|
|
100
136
|
let openRowPanel = null;
|
|
@@ -138,13 +174,14 @@ function sortPanels(panels) {
|
|
|
138
174
|
return (left.id || 0) - (right.id || 0);
|
|
139
175
|
});
|
|
140
176
|
}
|
|
141
|
-
function convertVariables(variables, variableNames) {
|
|
177
|
+
function convertVariables(variables, variableNames, options = {}) {
|
|
142
178
|
return variables
|
|
143
|
-
.map((variable, index) => convertVariable(variable, index, variableNames))
|
|
179
|
+
.map((variable, index) => convertVariable(variable, index, variableNames, options))
|
|
144
180
|
.filter(Boolean);
|
|
145
181
|
}
|
|
146
|
-
function convertVariable(variable, index, variableNames) {
|
|
182
|
+
function convertVariable(variable, index, variableNames, options = {}) {
|
|
147
183
|
const variableType = String(variable.type || '');
|
|
184
|
+
const queryString = sanitizeVariableQuery(extractVariableQuery(variable), options);
|
|
148
185
|
const current = variable.current || {};
|
|
149
186
|
const currentText = stringifyCurrent(current.text);
|
|
150
187
|
const currentValue = stringifyCurrent(current.value);
|
|
@@ -196,8 +233,7 @@ function convertVariable(variable, index, variableNames) {
|
|
|
196
233
|
});
|
|
197
234
|
}
|
|
198
235
|
if (variableType === 'query') {
|
|
199
|
-
const
|
|
200
|
-
const queryKind = inferVariableQueryType(variable, queryString);
|
|
236
|
+
const queryKind = inferVariableQueryType(variable);
|
|
201
237
|
return pruneEmpty({
|
|
202
238
|
...base,
|
|
203
239
|
datasource: queryKind === 'FIELD' ? 'object' : 'dataflux',
|
|
@@ -230,7 +266,7 @@ function convertPanel(panel, groupName, rowPanel, variableNames, options) {
|
|
|
230
266
|
return null;
|
|
231
267
|
}
|
|
232
268
|
const queries = buildQueries(panel, chartType, variableNames, options);
|
|
233
|
-
const settings = buildSettings(panel, chartType, queries, variableNames);
|
|
269
|
+
const settings = buildSettings(panel, chartType, queries, variableNames, options);
|
|
234
270
|
const links = extractPanelLinks(panel, variableNames);
|
|
235
271
|
const group = groupName !== null && groupName !== void 0 ? groupName : null;
|
|
236
272
|
const position = buildPosition(panel, rowPanel);
|
|
@@ -277,13 +313,14 @@ function buildQueries(panel, chartType, variableNames, options = {}) {
|
|
|
277
313
|
const targets = Array.isArray(panel.targets) ? panel.targets : [];
|
|
278
314
|
for (let index = 0; index < targets.length; index++) {
|
|
279
315
|
const target = targets[index];
|
|
280
|
-
const
|
|
316
|
+
const targetAlias = normalizeQueryAlias(target.legendFormat || target.alias || '');
|
|
317
|
+
const queryText = sanitizeTargetQuery(extractTargetQuery(target), options);
|
|
281
318
|
if (!queryText)
|
|
282
319
|
continue;
|
|
283
320
|
const qtype = inferQueryLanguage(target, queryText);
|
|
284
321
|
const normalizedQueryText = normalizeTargetQuery(queryText, qtype, options);
|
|
285
322
|
queries.push(pruneEmpty({
|
|
286
|
-
name:
|
|
323
|
+
name: targetAlias || undefined,
|
|
287
324
|
type: chartType,
|
|
288
325
|
qtype,
|
|
289
326
|
datasource: 'dataflux',
|
|
@@ -293,7 +330,6 @@ function buildQueries(panel, chartType, variableNames, options = {}) {
|
|
|
293
330
|
code: normalizeQueryCode(target.refId, index),
|
|
294
331
|
type: qtype,
|
|
295
332
|
promqlCode: qtype === 'promql' ? index + 1 : undefined,
|
|
296
|
-
alias: target.legendFormat || target.alias || '',
|
|
297
333
|
field: target.field || undefined,
|
|
298
334
|
},
|
|
299
335
|
extend: pruneEmpty({
|
|
@@ -313,14 +349,15 @@ function buildQueries(panel, chartType, variableNames, options = {}) {
|
|
|
313
349
|
}
|
|
314
350
|
return queries;
|
|
315
351
|
}
|
|
316
|
-
function buildSettings(panel, chartType, queries, variableNames) {
|
|
317
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
|
|
352
|
+
function buildSettings(panel, chartType, queries, variableNames, converterOptions = {}) {
|
|
353
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
|
|
318
354
|
const defaults = ((_a = panel.fieldConfig) === null || _a === void 0 ? void 0 : _a.defaults) || {};
|
|
319
355
|
const custom = defaults.custom || {};
|
|
320
356
|
const options = panel.options || {};
|
|
321
357
|
const legend = options.legend || panel.legend || {};
|
|
322
358
|
const transformationInfo = parseTransformations(panel.transformations || []);
|
|
323
|
-
const
|
|
359
|
+
const aliasInfo = buildAliases(queries, panel.fieldConfig, variableNames);
|
|
360
|
+
const aliases = aliasInfo.items;
|
|
324
361
|
const tableColumns = buildTableColumns(panel.fieldConfig, transformationInfo.organize, variableNames);
|
|
325
362
|
const fieldOverrides = buildFieldOverrides(panel.fieldConfig, variableNames);
|
|
326
363
|
const legacyGauge = panel.gauge || {};
|
|
@@ -355,6 +392,12 @@ function buildSettings(panel, chartType, queries, variableNames) {
|
|
|
355
392
|
const valColorMappings = buildValColorMappings(panel.fieldConfig, transformationInfo.organize);
|
|
356
393
|
const effectiveUnitType = customUnits.length ? 'custom' : unit ? 'global' : undefined;
|
|
357
394
|
const slimit = inferSeriesLimit(queries, options, chartType);
|
|
395
|
+
const levelFontColor = normalizeColor(firstDefined((_q = defaults.color) === null || _q === void 0 ? void 0 : _q.fixedColor, ''));
|
|
396
|
+
const levels = buildLevels(defaults.thresholds, chartType, {
|
|
397
|
+
min,
|
|
398
|
+
max,
|
|
399
|
+
fontColor: levelFontColor,
|
|
400
|
+
});
|
|
358
401
|
const settings = {
|
|
359
402
|
showTitle: true,
|
|
360
403
|
titleDesc: panel.description || '',
|
|
@@ -367,7 +410,7 @@ function buildSettings(panel, chartType, queries, variableNames) {
|
|
|
367
410
|
precision: typeof precision === 'number' ? String(precision) : '2',
|
|
368
411
|
timeInterval: normalizeTimeInterval(firstDefined(panel.interval, (_k = (_j = panel.targets) === null || _j === void 0 ? void 0 : _j.find((item) => item.interval)) === null || _k === void 0 ? void 0 : _k.interval, 'auto')),
|
|
369
412
|
fixedTime: panel.timeFrom || '',
|
|
370
|
-
maxPointCount: (_l = panel.maxDataPoints) !== null && _l !== void 0 ? _l :
|
|
413
|
+
maxPointCount: (_l = panel.maxDataPoints) !== null && _l !== void 0 ? _l : undefined,
|
|
371
414
|
showLegend: legend.showLegend,
|
|
372
415
|
legendPostion: mapLegendPlacement(legend.placement),
|
|
373
416
|
legendValues,
|
|
@@ -385,7 +428,7 @@ function buildSettings(panel, chartType, queries, variableNames) {
|
|
|
385
428
|
units: customUnits.length ? customUnits : undefined,
|
|
386
429
|
colors: customColors.length ? customColors : undefined,
|
|
387
430
|
colorMappings: colorMappings.length ? colorMappings : undefined,
|
|
388
|
-
levels
|
|
431
|
+
levels,
|
|
389
432
|
slimit,
|
|
390
433
|
mappings: mappingItems,
|
|
391
434
|
alias: aliases,
|
|
@@ -411,12 +454,12 @@ function buildSettings(panel, chartType, queries, variableNames) {
|
|
|
411
454
|
scientificNotation: unit === 'short' ? true : undefined,
|
|
412
455
|
mainMeasurementQueryCode: ((_p = (_o = queries[0]) === null || _o === void 0 ? void 0 : _o.query) === null || _p === void 0 ? void 0 : _p.code) || undefined,
|
|
413
456
|
mainMeasurementLimit: chartType === 'pie' ? extractReduceLimit(options) : undefined,
|
|
414
|
-
color: ((
|
|
415
|
-
fontColor: options.colorMode === 'value' ? (
|
|
416
|
-
bgColor: options.colorMode === 'background' ? (
|
|
457
|
+
color: ((_r = defaults.color) === null || _r === void 0 ? void 0 : _r.fixedColor) || undefined,
|
|
458
|
+
fontColor: options.colorMode === 'value' ? (_s = defaults.color) === null || _s === void 0 ? void 0 : _s.fixedColor : undefined,
|
|
459
|
+
bgColor: options.colorMode === 'background' ? (_t = defaults.color) === null || _t === void 0 ? void 0 : _t.fixedColor : undefined,
|
|
417
460
|
sequenceChartType: chartType === 'singlestat' && graphMode ? inferSequenceChartType(panel, graphMode) : undefined,
|
|
418
461
|
showLineAxis: chartType === 'singlestat' ? graphMode !== 'none' : undefined,
|
|
419
|
-
repeatChartVariable: typeof panel.repeat === 'string' && panel.repeat ? panel.repeat : undefined,
|
|
462
|
+
repeatChartVariable: typeof panel.repeat === 'string' && panel.repeat && variableNames.has(panel.repeat) ? panel.repeat : undefined,
|
|
420
463
|
repeatChartRowLimit: typeof panel.maxPerRow === 'number' ? panel.maxPerRow : undefined,
|
|
421
464
|
compares: compareInfo.compares,
|
|
422
465
|
compareType: compareInfo.compareType,
|
|
@@ -447,13 +490,13 @@ function buildSettings(panel, chartType, queries, variableNames) {
|
|
|
447
490
|
drawStyle: custom.drawStyle || undefined,
|
|
448
491
|
lineStyle: custom.lineStyle || undefined,
|
|
449
492
|
spanNulls: custom.spanNulls,
|
|
450
|
-
stackingGroup: ((
|
|
493
|
+
stackingGroup: ((_u = custom.stacking) === null || _u === void 0 ? void 0 : _u.group) || undefined,
|
|
451
494
|
graphMode,
|
|
452
495
|
colorMode: options.colorMode || undefined,
|
|
453
|
-
fieldColorMode: ((
|
|
454
|
-
fixedColor: ((
|
|
455
|
-
thresholdsMode: ((
|
|
456
|
-
thresholdsStyleMode: ((
|
|
496
|
+
fieldColorMode: ((_v = defaults.color) === null || _v === void 0 ? void 0 : _v.mode) || undefined,
|
|
497
|
+
fixedColor: ((_w = defaults.color) === null || _w === void 0 ? void 0 : _w.fixedColor) || undefined,
|
|
498
|
+
thresholdsMode: ((_x = defaults.thresholds) === null || _x === void 0 ? void 0 : _x.mode) || undefined,
|
|
499
|
+
thresholdsStyleMode: ((_y = custom.thresholdsStyle) === null || _y === void 0 ? void 0 : _y.mode) || undefined,
|
|
457
500
|
textMode: options.textMode || legacyTextMode,
|
|
458
501
|
reduceCalcs: Array.isArray(reduceOptions.calcs) ? reduceOptions.calcs : undefined,
|
|
459
502
|
reduceFields: reduceOptions.fields || undefined,
|
|
@@ -491,26 +534,99 @@ function buildSettings(panel, chartType, queries, variableNames) {
|
|
|
491
534
|
: undefined,
|
|
492
535
|
text: textInfo || undefined,
|
|
493
536
|
tableColumns: chartType === 'table' && tableColumns.length ? tableColumns : undefined,
|
|
494
|
-
fieldOverrides: fieldOverrides.length ? fieldOverrides : undefined,
|
|
495
|
-
transformations: transformationInfo.normalized.length ? transformationInfo.normalized : undefined,
|
|
496
|
-
fieldFilterPattern: transformationInfo.fieldFilterPattern || undefined,
|
|
497
|
-
valueFilters: transformationInfo.valueFilters.length ? transformationInfo.valueFilters : undefined,
|
|
537
|
+
fieldOverrides: converterOptions.keepGrafanaMeta && fieldOverrides.length ? fieldOverrides : undefined,
|
|
538
|
+
transformations: converterOptions.keepGrafanaMeta && transformationInfo.normalized.length ? transformationInfo.normalized : undefined,
|
|
539
|
+
fieldFilterPattern: converterOptions.keepGrafanaMeta ? transformationInfo.fieldFilterPattern || undefined : undefined,
|
|
540
|
+
valueFilters: converterOptions.keepGrafanaMeta && transformationInfo.valueFilters.length ? transformationInfo.valueFilters : undefined,
|
|
498
541
|
layout: pruneEmpty({
|
|
499
542
|
repeatDirection: panel.repeatDirection || undefined,
|
|
500
543
|
}),
|
|
544
|
+
aliasReview: converterOptions.keepGrafanaMeta ? aliasInfo.review : undefined,
|
|
501
545
|
});
|
|
502
546
|
return pruneEmpty(settings);
|
|
503
547
|
}
|
|
504
|
-
function buildLevels(thresholds) {
|
|
548
|
+
function buildLevels(thresholds, chartType, options = {}) {
|
|
549
|
+
if (chartType === 'gauge') {
|
|
550
|
+
return buildGaugeLevels(thresholds, options.max);
|
|
551
|
+
}
|
|
552
|
+
if (chartType === 'singlestat') {
|
|
553
|
+
return buildSinglestatLevels(thresholds, options.fontColor);
|
|
554
|
+
}
|
|
555
|
+
return buildGenericLevels(thresholds);
|
|
556
|
+
}
|
|
557
|
+
function buildGenericLevels(thresholds) {
|
|
505
558
|
const steps = Array.isArray(thresholds === null || thresholds === void 0 ? void 0 : thresholds.steps) ? thresholds.steps : [];
|
|
506
559
|
return steps
|
|
507
|
-
.filter((step) => typeof step.value === 'number' || typeof step.color === 'string')
|
|
560
|
+
.filter((step) => typeof normalizeLevelNumber(step.value) === 'number' || typeof step.color === 'string')
|
|
508
561
|
.map((step, index) => ({
|
|
509
562
|
title: `Level ${index + 1}`,
|
|
510
|
-
value:
|
|
563
|
+
value: normalizeLevelNumber(step.value) !== undefined ? normalizeLevelNumber(step.value) : 0,
|
|
511
564
|
bgColor: normalizeColor(step.color),
|
|
512
565
|
}));
|
|
513
566
|
}
|
|
567
|
+
function buildGaugeLevels(thresholds, max) {
|
|
568
|
+
const steps = Array.isArray(thresholds === null || thresholds === void 0 ? void 0 : thresholds.steps) ? thresholds.steps : [];
|
|
569
|
+
const levels = [];
|
|
570
|
+
for (let index = 0; index < steps.length; index++) {
|
|
571
|
+
const current = steps[index];
|
|
572
|
+
const next = steps[index + 1];
|
|
573
|
+
const nextValue = normalizeLevelNumber(next === null || next === void 0 ? void 0 : next.value);
|
|
574
|
+
const fallbackMax = normalizeLevelNumber(max);
|
|
575
|
+
const currentValue = normalizeLevelNumber(current === null || current === void 0 ? void 0 : current.value);
|
|
576
|
+
const upperBound = nextValue !== undefined ? nextValue : fallbackMax !== undefined ? fallbackMax : currentValue;
|
|
577
|
+
if (upperBound === undefined)
|
|
578
|
+
continue;
|
|
579
|
+
levels.push(pruneEmpty({
|
|
580
|
+
value: [upperBound],
|
|
581
|
+
lineColor: normalizeColor(current === null || current === void 0 ? void 0 : current.color),
|
|
582
|
+
operation: '<=',
|
|
583
|
+
}));
|
|
584
|
+
}
|
|
585
|
+
return levels;
|
|
586
|
+
}
|
|
587
|
+
function buildSinglestatLevels(thresholds, fontColor) {
|
|
588
|
+
const steps = Array.isArray(thresholds === null || thresholds === void 0 ? void 0 : thresholds.steps) ? thresholds.steps : [];
|
|
589
|
+
const levels = [];
|
|
590
|
+
for (let index = 0; index < steps.length; index++) {
|
|
591
|
+
const current = steps[index];
|
|
592
|
+
const next = steps[index + 1];
|
|
593
|
+
const currentValue = normalizeLevelNumber(current === null || current === void 0 ? void 0 : current.value);
|
|
594
|
+
const nextValue = normalizeLevelNumber(next === null || next === void 0 ? void 0 : next.value);
|
|
595
|
+
const color = normalizeColor(current === null || current === void 0 ? void 0 : current.color);
|
|
596
|
+
if (currentValue === undefined && nextValue === undefined)
|
|
597
|
+
continue;
|
|
598
|
+
if (currentValue === undefined && nextValue !== undefined) {
|
|
599
|
+
levels.push({
|
|
600
|
+
value: [nextValue],
|
|
601
|
+
bgColor: color,
|
|
602
|
+
fontColor: fontColor || color,
|
|
603
|
+
operation: '<',
|
|
604
|
+
});
|
|
605
|
+
continue;
|
|
606
|
+
}
|
|
607
|
+
if (currentValue !== undefined && nextValue !== undefined) {
|
|
608
|
+
levels.push({
|
|
609
|
+
value: [currentValue, nextValue],
|
|
610
|
+
bgColor: color,
|
|
611
|
+
fontColor: fontColor || color,
|
|
612
|
+
operation: 'between',
|
|
613
|
+
});
|
|
614
|
+
continue;
|
|
615
|
+
}
|
|
616
|
+
levels.push({
|
|
617
|
+
value: [currentValue],
|
|
618
|
+
bgColor: color,
|
|
619
|
+
fontColor: fontColor || color,
|
|
620
|
+
operation: '>=',
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
return levels;
|
|
624
|
+
}
|
|
625
|
+
function normalizeLevelNumber(value) {
|
|
626
|
+
if (typeof value !== 'number' || !Number.isFinite(value))
|
|
627
|
+
return undefined;
|
|
628
|
+
return Math.round(value);
|
|
629
|
+
}
|
|
514
630
|
function buildMappings(mappings) {
|
|
515
631
|
var _a;
|
|
516
632
|
if (!Array.isArray(mappings))
|
|
@@ -628,14 +744,119 @@ function buildTableColumns(fieldConfig, organize, variableNames = new Set()) {
|
|
|
628
744
|
}
|
|
629
745
|
return finalizeTableColumns([...columns.values()]);
|
|
630
746
|
}
|
|
631
|
-
function buildAliases(queries) {
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
747
|
+
function buildAliases(queries, fieldConfig, variableNames = new Set()) {
|
|
748
|
+
const aliases = [];
|
|
749
|
+
const seen = new Set();
|
|
750
|
+
const review = [];
|
|
751
|
+
const queryAliasTargets = buildQueryAliasTargets(queries);
|
|
752
|
+
for (const queryAliasTarget of queryAliasTargets) {
|
|
753
|
+
if (!queryAliasTarget.alias)
|
|
754
|
+
continue;
|
|
755
|
+
const aliasItem = pruneEmpty({
|
|
756
|
+
alias: queryAliasTarget.alias,
|
|
757
|
+
key: queryAliasTarget.key,
|
|
758
|
+
name: queryAliasTarget.name,
|
|
759
|
+
queryCode: queryAliasTarget.queryCode,
|
|
760
|
+
});
|
|
761
|
+
pushAliasItem(aliases, seen, aliasItem);
|
|
762
|
+
pushAliasReviewItem(review, aliasItem.alias, aliasItem.key);
|
|
763
|
+
}
|
|
764
|
+
const overrides = Array.isArray(fieldConfig === null || fieldConfig === void 0 ? void 0 : fieldConfig.overrides) ? fieldConfig.overrides : [];
|
|
765
|
+
for (const override of overrides) {
|
|
766
|
+
const matcherId = String((override === null || override === void 0 ? void 0 : override.matcher) && override.matcher.id || '');
|
|
767
|
+
const matcherOptions = String((override === null || override === void 0 ? void 0 : override.matcher) && override.matcher.options || '').trim();
|
|
768
|
+
if (matcherId !== 'byName' || !matcherOptions)
|
|
769
|
+
continue;
|
|
770
|
+
for (const property of Array.isArray(override === null || override === void 0 ? void 0 : override.properties) ? override.properties : []) {
|
|
771
|
+
if (!['displayName', 'displayNameFromDS'].includes(property === null || property === void 0 ? void 0 : property.id))
|
|
772
|
+
continue;
|
|
773
|
+
if (typeof property.value !== 'string' || !property.value.trim())
|
|
774
|
+
continue;
|
|
775
|
+
const aliasItem = {
|
|
776
|
+
alias: replaceVariables(property.value, variableNames),
|
|
777
|
+
key: matcherOptions,
|
|
778
|
+
name: matcherOptions,
|
|
779
|
+
};
|
|
780
|
+
pushAliasItem(aliases, seen, aliasItem);
|
|
781
|
+
pushAliasReviewItem(review, aliasItem.alias, aliasItem.key);
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
return {
|
|
785
|
+
items: aliases,
|
|
786
|
+
review: review.length ? review : undefined,
|
|
787
|
+
};
|
|
788
|
+
}
|
|
789
|
+
function pushAliasItem(aliases, seen, aliasItem) {
|
|
790
|
+
const normalized = pruneEmpty(aliasItem);
|
|
791
|
+
if (!(normalized === null || normalized === void 0 ? void 0 : normalized.alias) || !(normalized === null || normalized === void 0 ? void 0 : normalized.key) || !(normalized === null || normalized === void 0 ? void 0 : normalized.name))
|
|
792
|
+
return;
|
|
793
|
+
const key = JSON.stringify(normalized);
|
|
794
|
+
if (seen.has(key))
|
|
795
|
+
return;
|
|
796
|
+
seen.add(key);
|
|
797
|
+
aliases.push(normalized);
|
|
798
|
+
}
|
|
799
|
+
function buildQueryAliasTargets(queries) {
|
|
800
|
+
const targets = [];
|
|
801
|
+
for (let index = 0; index < (Array.isArray(queries) ? queries : []).length; index++) {
|
|
802
|
+
const query = queries[index];
|
|
803
|
+
const alias = normalizeQueryAlias((query === null || query === void 0 ? void 0 : query.name) || '');
|
|
804
|
+
if (!alias)
|
|
805
|
+
continue;
|
|
806
|
+
const queryInfo = (query === null || query === void 0 ? void 0 : query.query) || {};
|
|
807
|
+
const qtype = typeof (query === null || query === void 0 ? void 0 : query.qtype) === 'string' ? query.qtype : 'query';
|
|
808
|
+
const queryCode = typeof queryInfo.code === 'string' ? queryInfo.code : '';
|
|
809
|
+
const key = buildAliasSeriesKey(qtype, queryInfo, index);
|
|
810
|
+
targets.push({
|
|
811
|
+
alias,
|
|
812
|
+
key,
|
|
813
|
+
name: key,
|
|
814
|
+
queryCode: queryCode || undefined,
|
|
815
|
+
});
|
|
816
|
+
}
|
|
817
|
+
return targets;
|
|
818
|
+
}
|
|
819
|
+
function buildAliasSeriesKey(qtype, queryInfo, index) {
|
|
820
|
+
const normalizedType = typeof qtype === 'string' && qtype.trim() ? qtype.trim() : 'query';
|
|
821
|
+
if (normalizedType === 'promql') {
|
|
822
|
+
const promqlCode = Number.isInteger(queryInfo === null || queryInfo === void 0 ? void 0 : queryInfo.promqlCode) ? queryInfo.promqlCode : index + 1;
|
|
823
|
+
return `promql_${promqlCode}`;
|
|
824
|
+
}
|
|
825
|
+
return `${normalizedType}_${index + 1}`;
|
|
826
|
+
}
|
|
827
|
+
function normalizeQueryAlias(value) {
|
|
828
|
+
const alias = String(value || '').trim();
|
|
829
|
+
if (!alias || alias === '__auto')
|
|
830
|
+
return '';
|
|
831
|
+
return alias;
|
|
832
|
+
}
|
|
833
|
+
function pushAliasReviewItem(review, alias, key) {
|
|
834
|
+
const normalizedAlias = String(alias || '').trim();
|
|
835
|
+
const normalizedKey = String(key || '').trim();
|
|
836
|
+
if (!normalizedAlias || !normalizedKey)
|
|
837
|
+
return;
|
|
838
|
+
const classification = classifyAliasTemplate(normalizedAlias);
|
|
839
|
+
if (classification === 'safe_fixed')
|
|
840
|
+
return;
|
|
841
|
+
const item = {
|
|
842
|
+
alias: normalizedAlias,
|
|
843
|
+
key: normalizedKey,
|
|
844
|
+
classification,
|
|
845
|
+
};
|
|
846
|
+
const serialized = JSON.stringify(item);
|
|
847
|
+
if (review.some((current) => JSON.stringify(current) === serialized))
|
|
848
|
+
return;
|
|
849
|
+
review.push(item);
|
|
850
|
+
}
|
|
851
|
+
function classifyAliasTemplate(alias) {
|
|
852
|
+
if (!alias.includes('{{'))
|
|
853
|
+
return 'safe_fixed';
|
|
854
|
+
const tokens = [...alias.matchAll(/\{\{\s*([^}]+?)\s*\}\}/g)].map((match) => match[1].trim());
|
|
855
|
+
if (tokens.length === 0)
|
|
856
|
+
return 'safe_fixed';
|
|
857
|
+
if (tokens.every((token) => token === 'host' || token === 'tags'))
|
|
858
|
+
return 'safe_guance';
|
|
859
|
+
return 'compat_grafana_template';
|
|
639
860
|
}
|
|
640
861
|
function buildCustomUnits(fieldConfig) {
|
|
641
862
|
var _a;
|
|
@@ -1080,7 +1301,7 @@ function inferQueryLanguage(target, queryText) {
|
|
|
1080
1301
|
return 'dql';
|
|
1081
1302
|
return 'promql';
|
|
1082
1303
|
}
|
|
1083
|
-
function inferVariableQueryType(variable
|
|
1304
|
+
function inferVariableQueryType(variable) {
|
|
1084
1305
|
var _a;
|
|
1085
1306
|
const datasourceType = getDatasourceType(variable.datasource);
|
|
1086
1307
|
const explicitQtype = String(((_a = variable.query) === null || _a === void 0 ? void 0 : _a.qtype) || '').toLowerCase();
|
|
@@ -1089,15 +1310,7 @@ function inferVariableQueryType(variable, queryString) {
|
|
|
1089
1310
|
if (explicitQtype === 'promql')
|
|
1090
1311
|
return 'PROMQL_QUERY';
|
|
1091
1312
|
if (explicitQtype === 'dql')
|
|
1092
|
-
return '
|
|
1093
|
-
if (isDqlLikeDatasource(datasourceType) && /^\s*(with|select)\b/i.test(queryString))
|
|
1094
|
-
return 'QUERY';
|
|
1095
|
-
if (/field_values\(/i.test(queryString) || /label_values\(/i.test(queryString))
|
|
1096
|
-
return 'QUERY';
|
|
1097
|
-
if (/^[A-Z]::/.test(queryString) || /L\('/.test(queryString))
|
|
1098
|
-
return 'QUERY';
|
|
1099
|
-
if (/^\s*(with|select)\b/i.test(queryString))
|
|
1100
|
-
return 'QUERY';
|
|
1313
|
+
return 'PROMQL_QUERY';
|
|
1101
1314
|
return 'PROMQL_QUERY';
|
|
1102
1315
|
}
|
|
1103
1316
|
function extractVariableQuery(variable) {
|
|
@@ -1118,6 +1331,150 @@ function extractTargetQuery(target) {
|
|
|
1118
1331
|
}
|
|
1119
1332
|
return '';
|
|
1120
1333
|
}
|
|
1334
|
+
function sanitizeVariableQuery(queryText, options = {}) {
|
|
1335
|
+
return sanitizeQueryText(queryText, options);
|
|
1336
|
+
}
|
|
1337
|
+
function sanitizeTargetQuery(queryText, options = {}) {
|
|
1338
|
+
return sanitizeQueryText(queryText, options);
|
|
1339
|
+
}
|
|
1340
|
+
function sanitizeQueryText(queryText, options = {}) {
|
|
1341
|
+
if (typeof queryText !== 'string' || !queryText.trim()) {
|
|
1342
|
+
return queryText;
|
|
1343
|
+
}
|
|
1344
|
+
if (options.keepJobVariable === true) {
|
|
1345
|
+
return queryText;
|
|
1346
|
+
}
|
|
1347
|
+
if (looksLikeDqlQuery(queryText)) {
|
|
1348
|
+
return sanitizeDqlJobFilters(queryText).trim();
|
|
1349
|
+
}
|
|
1350
|
+
return sanitizePromqlJobFilters(queryText).trim();
|
|
1351
|
+
}
|
|
1352
|
+
function looksLikeDqlQuery(queryText) {
|
|
1353
|
+
return /^\s*(with|select)\b/i.test(queryText) || /^[A-Z]::/.test(queryText) || /[A-Z]\('/.test(queryText);
|
|
1354
|
+
}
|
|
1355
|
+
function sanitizePromqlJobFilters(queryText) {
|
|
1356
|
+
let result = queryText.replace(/\{([^{}]*)\}/g, (match, content) => sanitizePromqlSelector(content));
|
|
1357
|
+
result = result.replace(/([A-Za-z_:][A-Za-z0-9_:]*)\{\}/g, '$1');
|
|
1358
|
+
return result;
|
|
1359
|
+
}
|
|
1360
|
+
function sanitizePromqlSelector(content) {
|
|
1361
|
+
const parts = splitTopLevel(content, ',');
|
|
1362
|
+
const filtered = parts.filter((part) => !isJobPromqlMatcher(part));
|
|
1363
|
+
return `{${filtered.join(',')}}`;
|
|
1364
|
+
}
|
|
1365
|
+
function isJobPromqlMatcher(segment) {
|
|
1366
|
+
const match = String(segment).match(/^\s*([A-Za-z_][A-Za-z0-9_]*)\s*(=~|!~|=|!=)/);
|
|
1367
|
+
if (!match) {
|
|
1368
|
+
return false;
|
|
1369
|
+
}
|
|
1370
|
+
return normalizeVariableIdentifier(match[1]) === 'job';
|
|
1371
|
+
}
|
|
1372
|
+
function sanitizeDqlJobFilters(queryText) {
|
|
1373
|
+
return queryText.replace(/\{([^{}]*)\}/g, (match, content) => {
|
|
1374
|
+
const filtered = splitTopLevelLogical(content).filter((clause) => !isJobDqlClause(clause));
|
|
1375
|
+
if (filtered.length === 0) {
|
|
1376
|
+
return '';
|
|
1377
|
+
}
|
|
1378
|
+
return `{ ${filtered.join(' AND ')} }`;
|
|
1379
|
+
});
|
|
1380
|
+
}
|
|
1381
|
+
function isJobDqlClause(segment) {
|
|
1382
|
+
const match = String(segment).match(/^\s*`?([A-Za-z_][A-Za-z0-9_]*)`?\s*(=~|!~|=|!=|>=|<=|>|<|\bIN\b|\bNOT IN\b|\blike\b)/i);
|
|
1383
|
+
if (!match) {
|
|
1384
|
+
return false;
|
|
1385
|
+
}
|
|
1386
|
+
return normalizeVariableIdentifier(match[1]) === 'job';
|
|
1387
|
+
}
|
|
1388
|
+
function splitTopLevel(input, separator) {
|
|
1389
|
+
const segments = [];
|
|
1390
|
+
let current = '';
|
|
1391
|
+
let quote = '';
|
|
1392
|
+
let depth = 0;
|
|
1393
|
+
for (let index = 0; index < input.length; index++) {
|
|
1394
|
+
const char = input[index];
|
|
1395
|
+
const previous = index > 0 ? input[index - 1] : '';
|
|
1396
|
+
if (quote) {
|
|
1397
|
+
current += char;
|
|
1398
|
+
if (char === quote && previous !== '\\') {
|
|
1399
|
+
quote = '';
|
|
1400
|
+
}
|
|
1401
|
+
continue;
|
|
1402
|
+
}
|
|
1403
|
+
if (char === '"' || char === '\'' || char === '`') {
|
|
1404
|
+
quote = char;
|
|
1405
|
+
current += char;
|
|
1406
|
+
continue;
|
|
1407
|
+
}
|
|
1408
|
+
if (char === '(' || char === '[') {
|
|
1409
|
+
depth++;
|
|
1410
|
+
current += char;
|
|
1411
|
+
continue;
|
|
1412
|
+
}
|
|
1413
|
+
if ((char === ')' || char === ']') && depth > 0) {
|
|
1414
|
+
depth--;
|
|
1415
|
+
current += char;
|
|
1416
|
+
continue;
|
|
1417
|
+
}
|
|
1418
|
+
if (char === separator && depth === 0) {
|
|
1419
|
+
if (current.trim()) {
|
|
1420
|
+
segments.push(current.trim());
|
|
1421
|
+
}
|
|
1422
|
+
current = '';
|
|
1423
|
+
continue;
|
|
1424
|
+
}
|
|
1425
|
+
current += char;
|
|
1426
|
+
}
|
|
1427
|
+
if (current.trim()) {
|
|
1428
|
+
segments.push(current.trim());
|
|
1429
|
+
}
|
|
1430
|
+
return segments;
|
|
1431
|
+
}
|
|
1432
|
+
function splitTopLevelLogical(input) {
|
|
1433
|
+
const segments = [];
|
|
1434
|
+
let current = '';
|
|
1435
|
+
let quote = '';
|
|
1436
|
+
let depth = 0;
|
|
1437
|
+
for (let index = 0; index < input.length; index++) {
|
|
1438
|
+
const char = input[index];
|
|
1439
|
+
const previous = index > 0 ? input[index - 1] : '';
|
|
1440
|
+
if (quote) {
|
|
1441
|
+
current += char;
|
|
1442
|
+
if (char === quote && previous !== '\\') {
|
|
1443
|
+
quote = '';
|
|
1444
|
+
}
|
|
1445
|
+
continue;
|
|
1446
|
+
}
|
|
1447
|
+
if (char === '"' || char === '\'' || char === '`') {
|
|
1448
|
+
quote = char;
|
|
1449
|
+
current += char;
|
|
1450
|
+
continue;
|
|
1451
|
+
}
|
|
1452
|
+
if (char === '(' || char === '[') {
|
|
1453
|
+
depth++;
|
|
1454
|
+
current += char;
|
|
1455
|
+
continue;
|
|
1456
|
+
}
|
|
1457
|
+
if ((char === ')' || char === ']') && depth > 0) {
|
|
1458
|
+
depth--;
|
|
1459
|
+
current += char;
|
|
1460
|
+
continue;
|
|
1461
|
+
}
|
|
1462
|
+
if (depth === 0 && input.slice(index).match(/^(AND|OR)\b/i) && /\s/.test(previous || ' ')) {
|
|
1463
|
+
const operatorMatch = input.slice(index).match(/^(AND|OR)\b/i);
|
|
1464
|
+
if (operatorMatch && current.trim()) {
|
|
1465
|
+
segments.push(current.trim());
|
|
1466
|
+
current = '';
|
|
1467
|
+
index += operatorMatch[0].length - 1;
|
|
1468
|
+
continue;
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
current += char;
|
|
1472
|
+
}
|
|
1473
|
+
if (current.trim()) {
|
|
1474
|
+
segments.push(current.trim());
|
|
1475
|
+
}
|
|
1476
|
+
return segments;
|
|
1477
|
+
}
|
|
1121
1478
|
function extractWorkspaceInfo(targets) {
|
|
1122
1479
|
const workspaceUUIDs = [];
|
|
1123
1480
|
const workspaceNames = [];
|
|
@@ -1518,10 +1875,11 @@ function normalizeConnectNulls(value) {
|
|
|
1518
1875
|
function mapUnit(unit) {
|
|
1519
1876
|
if (!unit)
|
|
1520
1877
|
return [];
|
|
1521
|
-
const
|
|
1878
|
+
const rawUnit = String(unit);
|
|
1879
|
+
const mapped = UNIT_MAP[rawUnit] || UNIT_MAP[rawUnit.toLowerCase()];
|
|
1522
1880
|
if (mapped)
|
|
1523
1881
|
return mapped;
|
|
1524
|
-
return ['custom',
|
|
1882
|
+
return ['custom', rawUnit];
|
|
1525
1883
|
}
|
|
1526
1884
|
function buildLegacyValueMappings(valueMaps) {
|
|
1527
1885
|
if (!Array.isArray(valueMaps))
|
|
@@ -1595,6 +1953,9 @@ function normalizeTemplateVariable(expression) {
|
|
|
1595
1953
|
return '';
|
|
1596
1954
|
return beforeFormat;
|
|
1597
1955
|
}
|
|
1956
|
+
function normalizeVariableIdentifier(value) {
|
|
1957
|
+
return String(value || '').trim().toLowerCase();
|
|
1958
|
+
}
|
|
1598
1959
|
function normalizeQueryCode(refId, index) {
|
|
1599
1960
|
if (typeof refId === 'string' && refId.trim())
|
|
1600
1961
|
return refId.trim();
|