@cloudcare/guance-front-tools 1.0.20 → 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
|
@@ -44,9 +44,11 @@ const PROMQL_RESERVED_WORDS = new Set([
|
|
|
44
44
|
]);
|
|
45
45
|
const UNIT_MAP = {
|
|
46
46
|
percent: ['percent', 'percent'],
|
|
47
|
+
percentunit: ['percent', 'percent_decimal'],
|
|
47
48
|
bytes: ['digital', 'B'],
|
|
48
49
|
decbytes: ['digital', 'B'],
|
|
49
50
|
bits: ['digital', 'b'],
|
|
51
|
+
decbits: ['digital', 'b'],
|
|
50
52
|
deckbytes: ['digital', 'KB'],
|
|
51
53
|
decgbytes: ['digital', 'GB'],
|
|
52
54
|
ms: ['time', 'ms'],
|
|
@@ -54,10 +56,16 @@ const UNIT_MAP = {
|
|
|
54
56
|
m: ['time', 'min'],
|
|
55
57
|
h: ['time', 'h'],
|
|
56
58
|
d: ['time', 'd'],
|
|
57
|
-
short: ['
|
|
59
|
+
short: ['number', 'short_scale'],
|
|
58
60
|
none: ['custom', 'none'],
|
|
59
|
-
reqps: ['
|
|
60
|
-
ops: ['
|
|
61
|
+
reqps: ['throughput', 'reqps'],
|
|
62
|
+
ops: ['throughput', 'ops'],
|
|
63
|
+
iops: ['throughput', 'iops'],
|
|
64
|
+
bps: ['bandWidth', 'bps'],
|
|
65
|
+
Bps: ['traffic', 'B/S'],
|
|
66
|
+
hertz: ['frequency', 'Hz'],
|
|
67
|
+
rotrpm: ['frequency', 'rpm'],
|
|
68
|
+
celsius: ['temperature', 'C'],
|
|
61
69
|
};
|
|
62
70
|
const COMPARE_OPTIONS = {
|
|
63
71
|
hourCompare: { label: '小时同比', value: 'hourCompare' },
|
|
@@ -68,14 +76,14 @@ const COMPARE_OPTIONS = {
|
|
|
68
76
|
};
|
|
69
77
|
export function convertDashboard(grafanaDashboard, options = {}) {
|
|
70
78
|
var _a, _b;
|
|
71
|
-
const
|
|
79
|
+
const variableContext = buildVariableContext((((_a = grafanaDashboard.templating) === null || _a === void 0 ? void 0 : _a.list) || []), options);
|
|
72
80
|
const state = {
|
|
73
81
|
groups: [],
|
|
74
82
|
groupUnfoldStatus: {},
|
|
75
83
|
charts: [],
|
|
76
84
|
};
|
|
77
85
|
const sortedPanels = sortPanels(grafanaDashboard.panels || []);
|
|
78
|
-
collectPanels(sortedPanels, state, null, variableNames, options);
|
|
86
|
+
collectPanels(sortedPanels, state, null, variableContext.variableNames, options);
|
|
79
87
|
return pruneEmpty({
|
|
80
88
|
title: grafanaDashboard.title || '',
|
|
81
89
|
description: grafanaDashboard.description || undefined,
|
|
@@ -85,13 +93,41 @@ export function convertDashboard(grafanaDashboard, options = {}) {
|
|
|
85
93
|
groupUnfoldStatus: state.groupUnfoldStatus,
|
|
86
94
|
},
|
|
87
95
|
main: {
|
|
88
|
-
vars: convertVariables(
|
|
96
|
+
vars: convertVariables(variableContext.variables, variableContext.variableNames, options),
|
|
89
97
|
charts: state.charts,
|
|
90
98
|
groups: state.groups,
|
|
91
99
|
type: 'template',
|
|
92
100
|
},
|
|
93
101
|
});
|
|
94
102
|
}
|
|
103
|
+
function buildVariableContext(variables, options = {}) {
|
|
104
|
+
const keptVariables = [];
|
|
105
|
+
const variableNames = new Set();
|
|
106
|
+
for (const variable of Array.isArray(variables) ? variables : []) {
|
|
107
|
+
if (shouldSkipVariable(variable, options)) {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
keptVariables.push(variable);
|
|
111
|
+
if (variable === null || variable === void 0 ? void 0 : variable.name) {
|
|
112
|
+
variableNames.add(variable.name);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
variables: keptVariables,
|
|
117
|
+
variableNames,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function shouldSkipVariable(variable, options = {}) {
|
|
121
|
+
const variableType = String(variable === null || variable === void 0 ? void 0 : variable.type).toLowerCase();
|
|
122
|
+
const variableName = normalizeVariableIdentifier(variable === null || variable === void 0 ? void 0 : variable.name);
|
|
123
|
+
if (variableType === 'datasource' || variableName === 'ds_prometheus') {
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
if (options.keepJobVariable === true) {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
return variableName === 'job';
|
|
130
|
+
}
|
|
95
131
|
function collectPanels(panels, state, inheritedGroup = null, variableNames = new Set(), options = {}) {
|
|
96
132
|
let activeRow = inheritedGroup;
|
|
97
133
|
let openRowPanel = null;
|
|
@@ -135,13 +171,14 @@ function sortPanels(panels) {
|
|
|
135
171
|
return (left.id || 0) - (right.id || 0);
|
|
136
172
|
});
|
|
137
173
|
}
|
|
138
|
-
function convertVariables(variables, variableNames) {
|
|
174
|
+
function convertVariables(variables, variableNames, options = {}) {
|
|
139
175
|
return variables
|
|
140
|
-
.map((variable, index) => convertVariable(variable, index, variableNames))
|
|
176
|
+
.map((variable, index) => convertVariable(variable, index, variableNames, options))
|
|
141
177
|
.filter(Boolean);
|
|
142
178
|
}
|
|
143
|
-
function convertVariable(variable, index, variableNames) {
|
|
179
|
+
function convertVariable(variable, index, variableNames, options = {}) {
|
|
144
180
|
const variableType = String(variable.type || '');
|
|
181
|
+
const queryString = sanitizeVariableQuery(extractVariableQuery(variable), options);
|
|
145
182
|
const current = variable.current || {};
|
|
146
183
|
const currentText = stringifyCurrent(current.text);
|
|
147
184
|
const currentValue = stringifyCurrent(current.value);
|
|
@@ -193,8 +230,7 @@ function convertVariable(variable, index, variableNames) {
|
|
|
193
230
|
});
|
|
194
231
|
}
|
|
195
232
|
if (variableType === 'query') {
|
|
196
|
-
const
|
|
197
|
-
const queryKind = inferVariableQueryType(variable, queryString);
|
|
233
|
+
const queryKind = inferVariableQueryType(variable);
|
|
198
234
|
return pruneEmpty({
|
|
199
235
|
...base,
|
|
200
236
|
datasource: queryKind === 'FIELD' ? 'object' : 'dataflux',
|
|
@@ -227,7 +263,7 @@ function convertPanel(panel, groupName, rowPanel, variableNames, options) {
|
|
|
227
263
|
return null;
|
|
228
264
|
}
|
|
229
265
|
const queries = buildQueries(panel, chartType, variableNames, options);
|
|
230
|
-
const settings = buildSettings(panel, chartType, queries, variableNames);
|
|
266
|
+
const settings = buildSettings(panel, chartType, queries, variableNames, options);
|
|
231
267
|
const links = extractPanelLinks(panel, variableNames);
|
|
232
268
|
const group = groupName !== null && groupName !== void 0 ? groupName : null;
|
|
233
269
|
const position = buildPosition(panel, rowPanel);
|
|
@@ -274,13 +310,14 @@ function buildQueries(panel, chartType, variableNames, options = {}) {
|
|
|
274
310
|
const targets = Array.isArray(panel.targets) ? panel.targets : [];
|
|
275
311
|
for (let index = 0; index < targets.length; index++) {
|
|
276
312
|
const target = targets[index];
|
|
277
|
-
const
|
|
313
|
+
const targetAlias = normalizeQueryAlias(target.legendFormat || target.alias || '');
|
|
314
|
+
const queryText = sanitizeTargetQuery(extractTargetQuery(target), options);
|
|
278
315
|
if (!queryText)
|
|
279
316
|
continue;
|
|
280
317
|
const qtype = inferQueryLanguage(target, queryText);
|
|
281
318
|
const normalizedQueryText = normalizeTargetQuery(queryText, qtype, options);
|
|
282
319
|
queries.push(pruneEmpty({
|
|
283
|
-
name:
|
|
320
|
+
name: targetAlias || undefined,
|
|
284
321
|
type: chartType,
|
|
285
322
|
qtype,
|
|
286
323
|
datasource: 'dataflux',
|
|
@@ -290,7 +327,6 @@ function buildQueries(panel, chartType, variableNames, options = {}) {
|
|
|
290
327
|
code: normalizeQueryCode(target.refId, index),
|
|
291
328
|
type: qtype,
|
|
292
329
|
promqlCode: qtype === 'promql' ? index + 1 : undefined,
|
|
293
|
-
alias: target.legendFormat || target.alias || '',
|
|
294
330
|
field: target.field || undefined,
|
|
295
331
|
},
|
|
296
332
|
extend: pruneEmpty({
|
|
@@ -310,14 +346,15 @@ function buildQueries(panel, chartType, variableNames, options = {}) {
|
|
|
310
346
|
}
|
|
311
347
|
return queries;
|
|
312
348
|
}
|
|
313
|
-
function buildSettings(panel, chartType, queries, variableNames) {
|
|
314
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
|
|
349
|
+
function buildSettings(panel, chartType, queries, variableNames, converterOptions = {}) {
|
|
350
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
|
|
315
351
|
const defaults = ((_a = panel.fieldConfig) === null || _a === void 0 ? void 0 : _a.defaults) || {};
|
|
316
352
|
const custom = defaults.custom || {};
|
|
317
353
|
const options = panel.options || {};
|
|
318
354
|
const legend = options.legend || panel.legend || {};
|
|
319
355
|
const transformationInfo = parseTransformations(panel.transformations || []);
|
|
320
|
-
const
|
|
356
|
+
const aliasInfo = buildAliases(queries, panel.fieldConfig, variableNames);
|
|
357
|
+
const aliases = aliasInfo.items;
|
|
321
358
|
const tableColumns = buildTableColumns(panel.fieldConfig, transformationInfo.organize, variableNames);
|
|
322
359
|
const fieldOverrides = buildFieldOverrides(panel.fieldConfig, variableNames);
|
|
323
360
|
const legacyGauge = panel.gauge || {};
|
|
@@ -352,6 +389,12 @@ function buildSettings(panel, chartType, queries, variableNames) {
|
|
|
352
389
|
const valColorMappings = buildValColorMappings(panel.fieldConfig, transformationInfo.organize);
|
|
353
390
|
const effectiveUnitType = customUnits.length ? 'custom' : unit ? 'global' : undefined;
|
|
354
391
|
const slimit = inferSeriesLimit(queries, options, chartType);
|
|
392
|
+
const levelFontColor = normalizeColor(firstDefined((_q = defaults.color) === null || _q === void 0 ? void 0 : _q.fixedColor, ''));
|
|
393
|
+
const levels = buildLevels(defaults.thresholds, chartType, {
|
|
394
|
+
min,
|
|
395
|
+
max,
|
|
396
|
+
fontColor: levelFontColor,
|
|
397
|
+
});
|
|
355
398
|
const settings = {
|
|
356
399
|
showTitle: true,
|
|
357
400
|
titleDesc: panel.description || '',
|
|
@@ -364,7 +407,7 @@ function buildSettings(panel, chartType, queries, variableNames) {
|
|
|
364
407
|
precision: typeof precision === 'number' ? String(precision) : '2',
|
|
365
408
|
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')),
|
|
366
409
|
fixedTime: panel.timeFrom || '',
|
|
367
|
-
maxPointCount: (_l = panel.maxDataPoints) !== null && _l !== void 0 ? _l :
|
|
410
|
+
maxPointCount: (_l = panel.maxDataPoints) !== null && _l !== void 0 ? _l : undefined,
|
|
368
411
|
showLegend: legend.showLegend,
|
|
369
412
|
legendPostion: mapLegendPlacement(legend.placement),
|
|
370
413
|
legendValues,
|
|
@@ -382,7 +425,7 @@ function buildSettings(panel, chartType, queries, variableNames) {
|
|
|
382
425
|
units: customUnits.length ? customUnits : undefined,
|
|
383
426
|
colors: customColors.length ? customColors : undefined,
|
|
384
427
|
colorMappings: colorMappings.length ? colorMappings : undefined,
|
|
385
|
-
levels
|
|
428
|
+
levels,
|
|
386
429
|
slimit,
|
|
387
430
|
mappings: mappingItems,
|
|
388
431
|
alias: aliases,
|
|
@@ -408,12 +451,12 @@ function buildSettings(panel, chartType, queries, variableNames) {
|
|
|
408
451
|
scientificNotation: unit === 'short' ? true : undefined,
|
|
409
452
|
mainMeasurementQueryCode: ((_p = (_o = queries[0]) === null || _o === void 0 ? void 0 : _o.query) === null || _p === void 0 ? void 0 : _p.code) || undefined,
|
|
410
453
|
mainMeasurementLimit: chartType === 'pie' ? extractReduceLimit(options) : undefined,
|
|
411
|
-
color: ((
|
|
412
|
-
fontColor: options.colorMode === 'value' ? (
|
|
413
|
-
bgColor: options.colorMode === 'background' ? (
|
|
454
|
+
color: ((_r = defaults.color) === null || _r === void 0 ? void 0 : _r.fixedColor) || undefined,
|
|
455
|
+
fontColor: options.colorMode === 'value' ? (_s = defaults.color) === null || _s === void 0 ? void 0 : _s.fixedColor : undefined,
|
|
456
|
+
bgColor: options.colorMode === 'background' ? (_t = defaults.color) === null || _t === void 0 ? void 0 : _t.fixedColor : undefined,
|
|
414
457
|
sequenceChartType: chartType === 'singlestat' && graphMode ? inferSequenceChartType(panel, graphMode) : undefined,
|
|
415
458
|
showLineAxis: chartType === 'singlestat' ? graphMode !== 'none' : undefined,
|
|
416
|
-
repeatChartVariable: typeof panel.repeat === 'string' && panel.repeat ? panel.repeat : undefined,
|
|
459
|
+
repeatChartVariable: typeof panel.repeat === 'string' && panel.repeat && variableNames.has(panel.repeat) ? panel.repeat : undefined,
|
|
417
460
|
repeatChartRowLimit: typeof panel.maxPerRow === 'number' ? panel.maxPerRow : undefined,
|
|
418
461
|
compares: compareInfo.compares,
|
|
419
462
|
compareType: compareInfo.compareType,
|
|
@@ -444,13 +487,13 @@ function buildSettings(panel, chartType, queries, variableNames) {
|
|
|
444
487
|
drawStyle: custom.drawStyle || undefined,
|
|
445
488
|
lineStyle: custom.lineStyle || undefined,
|
|
446
489
|
spanNulls: custom.spanNulls,
|
|
447
|
-
stackingGroup: ((
|
|
490
|
+
stackingGroup: ((_u = custom.stacking) === null || _u === void 0 ? void 0 : _u.group) || undefined,
|
|
448
491
|
graphMode,
|
|
449
492
|
colorMode: options.colorMode || undefined,
|
|
450
|
-
fieldColorMode: ((
|
|
451
|
-
fixedColor: ((
|
|
452
|
-
thresholdsMode: ((
|
|
453
|
-
thresholdsStyleMode: ((
|
|
493
|
+
fieldColorMode: ((_v = defaults.color) === null || _v === void 0 ? void 0 : _v.mode) || undefined,
|
|
494
|
+
fixedColor: ((_w = defaults.color) === null || _w === void 0 ? void 0 : _w.fixedColor) || undefined,
|
|
495
|
+
thresholdsMode: ((_x = defaults.thresholds) === null || _x === void 0 ? void 0 : _x.mode) || undefined,
|
|
496
|
+
thresholdsStyleMode: ((_y = custom.thresholdsStyle) === null || _y === void 0 ? void 0 : _y.mode) || undefined,
|
|
454
497
|
textMode: options.textMode || legacyTextMode,
|
|
455
498
|
reduceCalcs: Array.isArray(reduceOptions.calcs) ? reduceOptions.calcs : undefined,
|
|
456
499
|
reduceFields: reduceOptions.fields || undefined,
|
|
@@ -488,26 +531,99 @@ function buildSettings(panel, chartType, queries, variableNames) {
|
|
|
488
531
|
: undefined,
|
|
489
532
|
text: textInfo || undefined,
|
|
490
533
|
tableColumns: chartType === 'table' && tableColumns.length ? tableColumns : undefined,
|
|
491
|
-
fieldOverrides: fieldOverrides.length ? fieldOverrides : undefined,
|
|
492
|
-
transformations: transformationInfo.normalized.length ? transformationInfo.normalized : undefined,
|
|
493
|
-
fieldFilterPattern: transformationInfo.fieldFilterPattern || undefined,
|
|
494
|
-
valueFilters: transformationInfo.valueFilters.length ? transformationInfo.valueFilters : undefined,
|
|
534
|
+
fieldOverrides: converterOptions.keepGrafanaMeta && fieldOverrides.length ? fieldOverrides : undefined,
|
|
535
|
+
transformations: converterOptions.keepGrafanaMeta && transformationInfo.normalized.length ? transformationInfo.normalized : undefined,
|
|
536
|
+
fieldFilterPattern: converterOptions.keepGrafanaMeta ? transformationInfo.fieldFilterPattern || undefined : undefined,
|
|
537
|
+
valueFilters: converterOptions.keepGrafanaMeta && transformationInfo.valueFilters.length ? transformationInfo.valueFilters : undefined,
|
|
495
538
|
layout: pruneEmpty({
|
|
496
539
|
repeatDirection: panel.repeatDirection || undefined,
|
|
497
540
|
}),
|
|
541
|
+
aliasReview: converterOptions.keepGrafanaMeta ? aliasInfo.review : undefined,
|
|
498
542
|
});
|
|
499
543
|
return pruneEmpty(settings);
|
|
500
544
|
}
|
|
501
|
-
function buildLevels(thresholds) {
|
|
545
|
+
function buildLevels(thresholds, chartType, options = {}) {
|
|
546
|
+
if (chartType === 'gauge') {
|
|
547
|
+
return buildGaugeLevels(thresholds, options.max);
|
|
548
|
+
}
|
|
549
|
+
if (chartType === 'singlestat') {
|
|
550
|
+
return buildSinglestatLevels(thresholds, options.fontColor);
|
|
551
|
+
}
|
|
552
|
+
return buildGenericLevels(thresholds);
|
|
553
|
+
}
|
|
554
|
+
function buildGenericLevels(thresholds) {
|
|
502
555
|
const steps = Array.isArray(thresholds === null || thresholds === void 0 ? void 0 : thresholds.steps) ? thresholds.steps : [];
|
|
503
556
|
return steps
|
|
504
|
-
.filter((step) => typeof step.value === 'number' || typeof step.color === 'string')
|
|
557
|
+
.filter((step) => typeof normalizeLevelNumber(step.value) === 'number' || typeof step.color === 'string')
|
|
505
558
|
.map((step, index) => ({
|
|
506
559
|
title: `Level ${index + 1}`,
|
|
507
|
-
value:
|
|
560
|
+
value: normalizeLevelNumber(step.value) !== undefined ? normalizeLevelNumber(step.value) : 0,
|
|
508
561
|
bgColor: normalizeColor(step.color),
|
|
509
562
|
}));
|
|
510
563
|
}
|
|
564
|
+
function buildGaugeLevels(thresholds, max) {
|
|
565
|
+
const steps = Array.isArray(thresholds === null || thresholds === void 0 ? void 0 : thresholds.steps) ? thresholds.steps : [];
|
|
566
|
+
const levels = [];
|
|
567
|
+
for (let index = 0; index < steps.length; index++) {
|
|
568
|
+
const current = steps[index];
|
|
569
|
+
const next = steps[index + 1];
|
|
570
|
+
const nextValue = normalizeLevelNumber(next === null || next === void 0 ? void 0 : next.value);
|
|
571
|
+
const fallbackMax = normalizeLevelNumber(max);
|
|
572
|
+
const currentValue = normalizeLevelNumber(current === null || current === void 0 ? void 0 : current.value);
|
|
573
|
+
const upperBound = nextValue !== undefined ? nextValue : fallbackMax !== undefined ? fallbackMax : currentValue;
|
|
574
|
+
if (upperBound === undefined)
|
|
575
|
+
continue;
|
|
576
|
+
levels.push(pruneEmpty({
|
|
577
|
+
value: [upperBound],
|
|
578
|
+
lineColor: normalizeColor(current === null || current === void 0 ? void 0 : current.color),
|
|
579
|
+
operation: '<=',
|
|
580
|
+
}));
|
|
581
|
+
}
|
|
582
|
+
return levels;
|
|
583
|
+
}
|
|
584
|
+
function buildSinglestatLevels(thresholds, fontColor) {
|
|
585
|
+
const steps = Array.isArray(thresholds === null || thresholds === void 0 ? void 0 : thresholds.steps) ? thresholds.steps : [];
|
|
586
|
+
const levels = [];
|
|
587
|
+
for (let index = 0; index < steps.length; index++) {
|
|
588
|
+
const current = steps[index];
|
|
589
|
+
const next = steps[index + 1];
|
|
590
|
+
const currentValue = normalizeLevelNumber(current === null || current === void 0 ? void 0 : current.value);
|
|
591
|
+
const nextValue = normalizeLevelNumber(next === null || next === void 0 ? void 0 : next.value);
|
|
592
|
+
const color = normalizeColor(current === null || current === void 0 ? void 0 : current.color);
|
|
593
|
+
if (currentValue === undefined && nextValue === undefined)
|
|
594
|
+
continue;
|
|
595
|
+
if (currentValue === undefined && nextValue !== undefined) {
|
|
596
|
+
levels.push({
|
|
597
|
+
value: [nextValue],
|
|
598
|
+
bgColor: color,
|
|
599
|
+
fontColor: fontColor || color,
|
|
600
|
+
operation: '<',
|
|
601
|
+
});
|
|
602
|
+
continue;
|
|
603
|
+
}
|
|
604
|
+
if (currentValue !== undefined && nextValue !== undefined) {
|
|
605
|
+
levels.push({
|
|
606
|
+
value: [currentValue, nextValue],
|
|
607
|
+
bgColor: color,
|
|
608
|
+
fontColor: fontColor || color,
|
|
609
|
+
operation: 'between',
|
|
610
|
+
});
|
|
611
|
+
continue;
|
|
612
|
+
}
|
|
613
|
+
levels.push({
|
|
614
|
+
value: [currentValue],
|
|
615
|
+
bgColor: color,
|
|
616
|
+
fontColor: fontColor || color,
|
|
617
|
+
operation: '>=',
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
return levels;
|
|
621
|
+
}
|
|
622
|
+
function normalizeLevelNumber(value) {
|
|
623
|
+
if (typeof value !== 'number' || !Number.isFinite(value))
|
|
624
|
+
return undefined;
|
|
625
|
+
return Math.round(value);
|
|
626
|
+
}
|
|
511
627
|
function buildMappings(mappings) {
|
|
512
628
|
var _a;
|
|
513
629
|
if (!Array.isArray(mappings))
|
|
@@ -625,14 +741,119 @@ function buildTableColumns(fieldConfig, organize, variableNames = new Set()) {
|
|
|
625
741
|
}
|
|
626
742
|
return finalizeTableColumns([...columns.values()]);
|
|
627
743
|
}
|
|
628
|
-
function buildAliases(queries) {
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
744
|
+
function buildAliases(queries, fieldConfig, variableNames = new Set()) {
|
|
745
|
+
const aliases = [];
|
|
746
|
+
const seen = new Set();
|
|
747
|
+
const review = [];
|
|
748
|
+
const queryAliasTargets = buildQueryAliasTargets(queries);
|
|
749
|
+
for (const queryAliasTarget of queryAliasTargets) {
|
|
750
|
+
if (!queryAliasTarget.alias)
|
|
751
|
+
continue;
|
|
752
|
+
const aliasItem = pruneEmpty({
|
|
753
|
+
alias: queryAliasTarget.alias,
|
|
754
|
+
key: queryAliasTarget.key,
|
|
755
|
+
name: queryAliasTarget.name,
|
|
756
|
+
queryCode: queryAliasTarget.queryCode,
|
|
757
|
+
});
|
|
758
|
+
pushAliasItem(aliases, seen, aliasItem);
|
|
759
|
+
pushAliasReviewItem(review, aliasItem.alias, aliasItem.key);
|
|
760
|
+
}
|
|
761
|
+
const overrides = Array.isArray(fieldConfig === null || fieldConfig === void 0 ? void 0 : fieldConfig.overrides) ? fieldConfig.overrides : [];
|
|
762
|
+
for (const override of overrides) {
|
|
763
|
+
const matcherId = String((override === null || override === void 0 ? void 0 : override.matcher) && override.matcher.id || '');
|
|
764
|
+
const matcherOptions = String((override === null || override === void 0 ? void 0 : override.matcher) && override.matcher.options || '').trim();
|
|
765
|
+
if (matcherId !== 'byName' || !matcherOptions)
|
|
766
|
+
continue;
|
|
767
|
+
for (const property of Array.isArray(override === null || override === void 0 ? void 0 : override.properties) ? override.properties : []) {
|
|
768
|
+
if (!['displayName', 'displayNameFromDS'].includes(property === null || property === void 0 ? void 0 : property.id))
|
|
769
|
+
continue;
|
|
770
|
+
if (typeof property.value !== 'string' || !property.value.trim())
|
|
771
|
+
continue;
|
|
772
|
+
const aliasItem = {
|
|
773
|
+
alias: replaceVariables(property.value, variableNames),
|
|
774
|
+
key: matcherOptions,
|
|
775
|
+
name: matcherOptions,
|
|
776
|
+
};
|
|
777
|
+
pushAliasItem(aliases, seen, aliasItem);
|
|
778
|
+
pushAliasReviewItem(review, aliasItem.alias, aliasItem.key);
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
return {
|
|
782
|
+
items: aliases,
|
|
783
|
+
review: review.length ? review : undefined,
|
|
784
|
+
};
|
|
785
|
+
}
|
|
786
|
+
function pushAliasItem(aliases, seen, aliasItem) {
|
|
787
|
+
const normalized = pruneEmpty(aliasItem);
|
|
788
|
+
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))
|
|
789
|
+
return;
|
|
790
|
+
const key = JSON.stringify(normalized);
|
|
791
|
+
if (seen.has(key))
|
|
792
|
+
return;
|
|
793
|
+
seen.add(key);
|
|
794
|
+
aliases.push(normalized);
|
|
795
|
+
}
|
|
796
|
+
function buildQueryAliasTargets(queries) {
|
|
797
|
+
const targets = [];
|
|
798
|
+
for (let index = 0; index < (Array.isArray(queries) ? queries : []).length; index++) {
|
|
799
|
+
const query = queries[index];
|
|
800
|
+
const alias = normalizeQueryAlias((query === null || query === void 0 ? void 0 : query.name) || '');
|
|
801
|
+
if (!alias)
|
|
802
|
+
continue;
|
|
803
|
+
const queryInfo = (query === null || query === void 0 ? void 0 : query.query) || {};
|
|
804
|
+
const qtype = typeof (query === null || query === void 0 ? void 0 : query.qtype) === 'string' ? query.qtype : 'query';
|
|
805
|
+
const queryCode = typeof queryInfo.code === 'string' ? queryInfo.code : '';
|
|
806
|
+
const key = buildAliasSeriesKey(qtype, queryInfo, index);
|
|
807
|
+
targets.push({
|
|
808
|
+
alias,
|
|
809
|
+
key,
|
|
810
|
+
name: key,
|
|
811
|
+
queryCode: queryCode || undefined,
|
|
812
|
+
});
|
|
813
|
+
}
|
|
814
|
+
return targets;
|
|
815
|
+
}
|
|
816
|
+
function buildAliasSeriesKey(qtype, queryInfo, index) {
|
|
817
|
+
const normalizedType = typeof qtype === 'string' && qtype.trim() ? qtype.trim() : 'query';
|
|
818
|
+
if (normalizedType === 'promql') {
|
|
819
|
+
const promqlCode = Number.isInteger(queryInfo === null || queryInfo === void 0 ? void 0 : queryInfo.promqlCode) ? queryInfo.promqlCode : index + 1;
|
|
820
|
+
return `promql_${promqlCode}`;
|
|
821
|
+
}
|
|
822
|
+
return `${normalizedType}_${index + 1}`;
|
|
823
|
+
}
|
|
824
|
+
function normalizeQueryAlias(value) {
|
|
825
|
+
const alias = String(value || '').trim();
|
|
826
|
+
if (!alias || alias === '__auto')
|
|
827
|
+
return '';
|
|
828
|
+
return alias;
|
|
829
|
+
}
|
|
830
|
+
function pushAliasReviewItem(review, alias, key) {
|
|
831
|
+
const normalizedAlias = String(alias || '').trim();
|
|
832
|
+
const normalizedKey = String(key || '').trim();
|
|
833
|
+
if (!normalizedAlias || !normalizedKey)
|
|
834
|
+
return;
|
|
835
|
+
const classification = classifyAliasTemplate(normalizedAlias);
|
|
836
|
+
if (classification === 'safe_fixed')
|
|
837
|
+
return;
|
|
838
|
+
const item = {
|
|
839
|
+
alias: normalizedAlias,
|
|
840
|
+
key: normalizedKey,
|
|
841
|
+
classification,
|
|
842
|
+
};
|
|
843
|
+
const serialized = JSON.stringify(item);
|
|
844
|
+
if (review.some((current) => JSON.stringify(current) === serialized))
|
|
845
|
+
return;
|
|
846
|
+
review.push(item);
|
|
847
|
+
}
|
|
848
|
+
function classifyAliasTemplate(alias) {
|
|
849
|
+
if (!alias.includes('{{'))
|
|
850
|
+
return 'safe_fixed';
|
|
851
|
+
const tokens = [...alias.matchAll(/\{\{\s*([^}]+?)\s*\}\}/g)].map((match) => match[1].trim());
|
|
852
|
+
if (tokens.length === 0)
|
|
853
|
+
return 'safe_fixed';
|
|
854
|
+
if (tokens.every((token) => token === 'host' || token === 'tags'))
|
|
855
|
+
return 'safe_guance';
|
|
856
|
+
return 'compat_grafana_template';
|
|
636
857
|
}
|
|
637
858
|
function buildCustomUnits(fieldConfig) {
|
|
638
859
|
var _a;
|
|
@@ -1077,7 +1298,7 @@ function inferQueryLanguage(target, queryText) {
|
|
|
1077
1298
|
return 'dql';
|
|
1078
1299
|
return 'promql';
|
|
1079
1300
|
}
|
|
1080
|
-
function inferVariableQueryType(variable
|
|
1301
|
+
function inferVariableQueryType(variable) {
|
|
1081
1302
|
var _a;
|
|
1082
1303
|
const datasourceType = getDatasourceType(variable.datasource);
|
|
1083
1304
|
const explicitQtype = String(((_a = variable.query) === null || _a === void 0 ? void 0 : _a.qtype) || '').toLowerCase();
|
|
@@ -1086,15 +1307,7 @@ function inferVariableQueryType(variable, queryString) {
|
|
|
1086
1307
|
if (explicitQtype === 'promql')
|
|
1087
1308
|
return 'PROMQL_QUERY';
|
|
1088
1309
|
if (explicitQtype === 'dql')
|
|
1089
|
-
return '
|
|
1090
|
-
if (isDqlLikeDatasource(datasourceType) && /^\s*(with|select)\b/i.test(queryString))
|
|
1091
|
-
return 'QUERY';
|
|
1092
|
-
if (/field_values\(/i.test(queryString) || /label_values\(/i.test(queryString))
|
|
1093
|
-
return 'QUERY';
|
|
1094
|
-
if (/^[A-Z]::/.test(queryString) || /L\('/.test(queryString))
|
|
1095
|
-
return 'QUERY';
|
|
1096
|
-
if (/^\s*(with|select)\b/i.test(queryString))
|
|
1097
|
-
return 'QUERY';
|
|
1310
|
+
return 'PROMQL_QUERY';
|
|
1098
1311
|
return 'PROMQL_QUERY';
|
|
1099
1312
|
}
|
|
1100
1313
|
function extractVariableQuery(variable) {
|
|
@@ -1115,6 +1328,150 @@ function extractTargetQuery(target) {
|
|
|
1115
1328
|
}
|
|
1116
1329
|
return '';
|
|
1117
1330
|
}
|
|
1331
|
+
function sanitizeVariableQuery(queryText, options = {}) {
|
|
1332
|
+
return sanitizeQueryText(queryText, options);
|
|
1333
|
+
}
|
|
1334
|
+
function sanitizeTargetQuery(queryText, options = {}) {
|
|
1335
|
+
return sanitizeQueryText(queryText, options);
|
|
1336
|
+
}
|
|
1337
|
+
function sanitizeQueryText(queryText, options = {}) {
|
|
1338
|
+
if (typeof queryText !== 'string' || !queryText.trim()) {
|
|
1339
|
+
return queryText;
|
|
1340
|
+
}
|
|
1341
|
+
if (options.keepJobVariable === true) {
|
|
1342
|
+
return queryText;
|
|
1343
|
+
}
|
|
1344
|
+
if (looksLikeDqlQuery(queryText)) {
|
|
1345
|
+
return sanitizeDqlJobFilters(queryText).trim();
|
|
1346
|
+
}
|
|
1347
|
+
return sanitizePromqlJobFilters(queryText).trim();
|
|
1348
|
+
}
|
|
1349
|
+
function looksLikeDqlQuery(queryText) {
|
|
1350
|
+
return /^\s*(with|select)\b/i.test(queryText) || /^[A-Z]::/.test(queryText) || /[A-Z]\('/.test(queryText);
|
|
1351
|
+
}
|
|
1352
|
+
function sanitizePromqlJobFilters(queryText) {
|
|
1353
|
+
let result = queryText.replace(/\{([^{}]*)\}/g, (match, content) => sanitizePromqlSelector(content));
|
|
1354
|
+
result = result.replace(/([A-Za-z_:][A-Za-z0-9_:]*)\{\}/g, '$1');
|
|
1355
|
+
return result;
|
|
1356
|
+
}
|
|
1357
|
+
function sanitizePromqlSelector(content) {
|
|
1358
|
+
const parts = splitTopLevel(content, ',');
|
|
1359
|
+
const filtered = parts.filter((part) => !isJobPromqlMatcher(part));
|
|
1360
|
+
return `{${filtered.join(',')}}`;
|
|
1361
|
+
}
|
|
1362
|
+
function isJobPromqlMatcher(segment) {
|
|
1363
|
+
const match = String(segment).match(/^\s*([A-Za-z_][A-Za-z0-9_]*)\s*(=~|!~|=|!=)/);
|
|
1364
|
+
if (!match) {
|
|
1365
|
+
return false;
|
|
1366
|
+
}
|
|
1367
|
+
return normalizeVariableIdentifier(match[1]) === 'job';
|
|
1368
|
+
}
|
|
1369
|
+
function sanitizeDqlJobFilters(queryText) {
|
|
1370
|
+
return queryText.replace(/\{([^{}]*)\}/g, (match, content) => {
|
|
1371
|
+
const filtered = splitTopLevelLogical(content).filter((clause) => !isJobDqlClause(clause));
|
|
1372
|
+
if (filtered.length === 0) {
|
|
1373
|
+
return '';
|
|
1374
|
+
}
|
|
1375
|
+
return `{ ${filtered.join(' AND ')} }`;
|
|
1376
|
+
});
|
|
1377
|
+
}
|
|
1378
|
+
function isJobDqlClause(segment) {
|
|
1379
|
+
const match = String(segment).match(/^\s*`?([A-Za-z_][A-Za-z0-9_]*)`?\s*(=~|!~|=|!=|>=|<=|>|<|\bIN\b|\bNOT IN\b|\blike\b)/i);
|
|
1380
|
+
if (!match) {
|
|
1381
|
+
return false;
|
|
1382
|
+
}
|
|
1383
|
+
return normalizeVariableIdentifier(match[1]) === 'job';
|
|
1384
|
+
}
|
|
1385
|
+
function splitTopLevel(input, separator) {
|
|
1386
|
+
const segments = [];
|
|
1387
|
+
let current = '';
|
|
1388
|
+
let quote = '';
|
|
1389
|
+
let depth = 0;
|
|
1390
|
+
for (let index = 0; index < input.length; index++) {
|
|
1391
|
+
const char = input[index];
|
|
1392
|
+
const previous = index > 0 ? input[index - 1] : '';
|
|
1393
|
+
if (quote) {
|
|
1394
|
+
current += char;
|
|
1395
|
+
if (char === quote && previous !== '\\') {
|
|
1396
|
+
quote = '';
|
|
1397
|
+
}
|
|
1398
|
+
continue;
|
|
1399
|
+
}
|
|
1400
|
+
if (char === '"' || char === '\'' || char === '`') {
|
|
1401
|
+
quote = char;
|
|
1402
|
+
current += char;
|
|
1403
|
+
continue;
|
|
1404
|
+
}
|
|
1405
|
+
if (char === '(' || char === '[') {
|
|
1406
|
+
depth++;
|
|
1407
|
+
current += char;
|
|
1408
|
+
continue;
|
|
1409
|
+
}
|
|
1410
|
+
if ((char === ')' || char === ']') && depth > 0) {
|
|
1411
|
+
depth--;
|
|
1412
|
+
current += char;
|
|
1413
|
+
continue;
|
|
1414
|
+
}
|
|
1415
|
+
if (char === separator && depth === 0) {
|
|
1416
|
+
if (current.trim()) {
|
|
1417
|
+
segments.push(current.trim());
|
|
1418
|
+
}
|
|
1419
|
+
current = '';
|
|
1420
|
+
continue;
|
|
1421
|
+
}
|
|
1422
|
+
current += char;
|
|
1423
|
+
}
|
|
1424
|
+
if (current.trim()) {
|
|
1425
|
+
segments.push(current.trim());
|
|
1426
|
+
}
|
|
1427
|
+
return segments;
|
|
1428
|
+
}
|
|
1429
|
+
function splitTopLevelLogical(input) {
|
|
1430
|
+
const segments = [];
|
|
1431
|
+
let current = '';
|
|
1432
|
+
let quote = '';
|
|
1433
|
+
let depth = 0;
|
|
1434
|
+
for (let index = 0; index < input.length; index++) {
|
|
1435
|
+
const char = input[index];
|
|
1436
|
+
const previous = index > 0 ? input[index - 1] : '';
|
|
1437
|
+
if (quote) {
|
|
1438
|
+
current += char;
|
|
1439
|
+
if (char === quote && previous !== '\\') {
|
|
1440
|
+
quote = '';
|
|
1441
|
+
}
|
|
1442
|
+
continue;
|
|
1443
|
+
}
|
|
1444
|
+
if (char === '"' || char === '\'' || char === '`') {
|
|
1445
|
+
quote = char;
|
|
1446
|
+
current += char;
|
|
1447
|
+
continue;
|
|
1448
|
+
}
|
|
1449
|
+
if (char === '(' || char === '[') {
|
|
1450
|
+
depth++;
|
|
1451
|
+
current += char;
|
|
1452
|
+
continue;
|
|
1453
|
+
}
|
|
1454
|
+
if ((char === ')' || char === ']') && depth > 0) {
|
|
1455
|
+
depth--;
|
|
1456
|
+
current += char;
|
|
1457
|
+
continue;
|
|
1458
|
+
}
|
|
1459
|
+
if (depth === 0 && input.slice(index).match(/^(AND|OR)\b/i) && /\s/.test(previous || ' ')) {
|
|
1460
|
+
const operatorMatch = input.slice(index).match(/^(AND|OR)\b/i);
|
|
1461
|
+
if (operatorMatch && current.trim()) {
|
|
1462
|
+
segments.push(current.trim());
|
|
1463
|
+
current = '';
|
|
1464
|
+
index += operatorMatch[0].length - 1;
|
|
1465
|
+
continue;
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
current += char;
|
|
1469
|
+
}
|
|
1470
|
+
if (current.trim()) {
|
|
1471
|
+
segments.push(current.trim());
|
|
1472
|
+
}
|
|
1473
|
+
return segments;
|
|
1474
|
+
}
|
|
1118
1475
|
function extractWorkspaceInfo(targets) {
|
|
1119
1476
|
const workspaceUUIDs = [];
|
|
1120
1477
|
const workspaceNames = [];
|
|
@@ -1515,10 +1872,11 @@ function normalizeConnectNulls(value) {
|
|
|
1515
1872
|
function mapUnit(unit) {
|
|
1516
1873
|
if (!unit)
|
|
1517
1874
|
return [];
|
|
1518
|
-
const
|
|
1875
|
+
const rawUnit = String(unit);
|
|
1876
|
+
const mapped = UNIT_MAP[rawUnit] || UNIT_MAP[rawUnit.toLowerCase()];
|
|
1519
1877
|
if (mapped)
|
|
1520
1878
|
return mapped;
|
|
1521
|
-
return ['custom',
|
|
1879
|
+
return ['custom', rawUnit];
|
|
1522
1880
|
}
|
|
1523
1881
|
function buildLegacyValueMappings(valueMaps) {
|
|
1524
1882
|
if (!Array.isArray(valueMaps))
|
|
@@ -1592,6 +1950,9 @@ function normalizeTemplateVariable(expression) {
|
|
|
1592
1950
|
return '';
|
|
1593
1951
|
return beforeFormat;
|
|
1594
1952
|
}
|
|
1953
|
+
function normalizeVariableIdentifier(value) {
|
|
1954
|
+
return String(value || '').trim().toLowerCase();
|
|
1955
|
+
}
|
|
1595
1956
|
function normalizeQueryCode(refId, index) {
|
|
1596
1957
|
if (typeof refId === 'string' && refId.trim())
|
|
1597
1958
|
return refId.trim();
|