@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
|
@@ -1,1770 +1,2036 @@
|
|
|
1
1
|
const PANEL_TYPE_MAP = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
2
|
+
stat: 'singlestat',
|
|
3
|
+
singlestat: 'singlestat',
|
|
4
|
+
timeseries: 'sequence',
|
|
5
|
+
graph: 'sequence',
|
|
6
|
+
trend: 'sequence',
|
|
7
|
+
bargauge: 'toplist',
|
|
8
|
+
gauge: 'gauge',
|
|
9
|
+
barchart: 'bar',
|
|
10
|
+
piechart: 'pie',
|
|
11
|
+
table: 'table',
|
|
12
|
+
text: 'text',
|
|
13
|
+
heatmap: 'heatmap',
|
|
14
|
+
histogram: 'histogram',
|
|
15
|
+
treemap: 'treemap',
|
|
16
|
+
geomap: 'worldmap',
|
|
17
|
+
logs: 'log',
|
|
18
|
+
};
|
|
20
19
|
const GRAFANA_BUILTIN_VARS = new Set([
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
])
|
|
33
|
-
|
|
20
|
+
'__interval',
|
|
21
|
+
'__interval_ms',
|
|
22
|
+
'__range',
|
|
23
|
+
'__range_s',
|
|
24
|
+
'__range_ms',
|
|
25
|
+
'__from',
|
|
26
|
+
'__to',
|
|
27
|
+
'__dashboard',
|
|
28
|
+
'__name',
|
|
29
|
+
'__org',
|
|
30
|
+
'__user',
|
|
31
|
+
]);
|
|
34
32
|
const PROMQL_RESERVED_WORDS = new Set([
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
])
|
|
47
|
-
|
|
33
|
+
'and',
|
|
34
|
+
'or',
|
|
35
|
+
'unless',
|
|
36
|
+
'by',
|
|
37
|
+
'without',
|
|
38
|
+
'on',
|
|
39
|
+
'ignoring',
|
|
40
|
+
'group_left',
|
|
41
|
+
'group_right',
|
|
42
|
+
'bool',
|
|
43
|
+
'offset',
|
|
44
|
+
]);
|
|
48
45
|
const UNIT_MAP = {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
46
|
+
percent: ['percent', 'percent'],
|
|
47
|
+
percentunit: ['percent', 'percent_decimal'],
|
|
48
|
+
bytes: ['digital', 'B'],
|
|
49
|
+
decbytes: ['digital', 'B'],
|
|
50
|
+
bits: ['digital', 'b'],
|
|
51
|
+
decbits: ['digital', 'b'],
|
|
52
|
+
deckbytes: ['digital', 'KB'],
|
|
53
|
+
decgbytes: ['digital', 'GB'],
|
|
54
|
+
ms: ['time', 'ms'],
|
|
55
|
+
s: ['time', 's'],
|
|
56
|
+
m: ['time', 'min'],
|
|
57
|
+
h: ['time', 'h'],
|
|
58
|
+
d: ['time', 'd'],
|
|
59
|
+
short: ['number', 'short_scale'],
|
|
60
|
+
none: ['custom', 'none'],
|
|
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'],
|
|
69
|
+
};
|
|
66
70
|
const COMPARE_OPTIONS = {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
71
|
+
hourCompare: { label: '小时同比', value: 'hourCompare' },
|
|
72
|
+
dayCompare: { label: '日同比', value: 'dayCompare' },
|
|
73
|
+
weekCompare: { label: '周同比', value: 'weekCompare' },
|
|
74
|
+
monthCompare: { label: '月同比', value: 'monthCompare' },
|
|
75
|
+
circleCompare: { label: '环比', value: 'circleCompare' },
|
|
76
|
+
};
|
|
74
77
|
export function convertDashboard(grafanaDashboard, options = {}) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
|
|
78
|
+
var _a, _b;
|
|
79
|
+
const variableContext = buildVariableContext((((_a = grafanaDashboard.templating) === null || _a === void 0 ? void 0 : _a.list) || []), options);
|
|
80
|
+
const state = {
|
|
81
|
+
groups: [],
|
|
82
|
+
groupUnfoldStatus: {},
|
|
83
|
+
charts: [],
|
|
84
|
+
};
|
|
85
|
+
const sortedPanels = sortPanels(grafanaDashboard.panels || []);
|
|
86
|
+
collectPanels(sortedPanels, state, null, variableContext.variableNames, options);
|
|
87
|
+
return pruneEmpty({
|
|
88
|
+
title: grafanaDashboard.title || '',
|
|
89
|
+
description: grafanaDashboard.description || undefined,
|
|
90
|
+
tags: grafanaDashboard.tags || undefined,
|
|
91
|
+
uid: grafanaDashboard.uid || undefined,
|
|
92
|
+
dashboardExtend: {
|
|
93
|
+
groupUnfoldStatus: state.groupUnfoldStatus,
|
|
94
|
+
},
|
|
95
|
+
main: {
|
|
96
|
+
vars: convertVariables(variableContext.variables, variableContext.variableNames, options),
|
|
97
|
+
charts: state.charts,
|
|
98
|
+
groups: state.groups,
|
|
99
|
+
type: 'template',
|
|
100
|
+
},
|
|
101
|
+
});
|
|
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
|
+
}
|
|
102
131
|
function collectPanels(panels, state, inheritedGroup = null, variableNames = new Set(), options = {}) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
+
let activeRow = inheritedGroup;
|
|
133
|
+
let openRowPanel = null;
|
|
134
|
+
for (const panel of panels) {
|
|
135
|
+
if (panel.type === 'row') {
|
|
136
|
+
const rowName = panel.title || '';
|
|
137
|
+
if (rowName) {
|
|
138
|
+
state.groups.push({ name: rowName });
|
|
139
|
+
state.groupUnfoldStatus[rowName] = !panel.collapsed;
|
|
140
|
+
}
|
|
141
|
+
if (panel.collapsed) {
|
|
142
|
+
collectPanels(sortPanels(panel.panels || []), state, rowName || null, variableNames, options);
|
|
143
|
+
activeRow = inheritedGroup;
|
|
144
|
+
openRowPanel = null;
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
activeRow = rowName || null;
|
|
148
|
+
openRowPanel = panel;
|
|
149
|
+
}
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
const chart = convertPanel(panel, activeRow, openRowPanel, variableNames, options);
|
|
153
|
+
if (chart) {
|
|
154
|
+
state.charts.push(chart);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
132
158
|
function sortPanels(panels) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
159
|
+
return [...panels].sort((left, right) => {
|
|
160
|
+
var _a, _b, _c, _d;
|
|
161
|
+
const leftPos = left.gridPos || {};
|
|
162
|
+
const rightPos = right.gridPos || {};
|
|
163
|
+
const leftY = (_a = leftPos.y) !== null && _a !== void 0 ? _a : Number.MAX_SAFE_INTEGER;
|
|
164
|
+
const rightY = (_b = rightPos.y) !== null && _b !== void 0 ? _b : Number.MAX_SAFE_INTEGER;
|
|
165
|
+
if (leftY !== rightY)
|
|
166
|
+
return leftY - rightY;
|
|
167
|
+
const leftX = (_c = leftPos.x) !== null && _c !== void 0 ? _c : Number.MAX_SAFE_INTEGER;
|
|
168
|
+
const rightX = (_d = rightPos.x) !== null && _d !== void 0 ? _d : Number.MAX_SAFE_INTEGER;
|
|
169
|
+
if (leftX !== rightX)
|
|
170
|
+
return leftX - rightX;
|
|
171
|
+
return (left.id || 0) - (right.id || 0);
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
function convertVariables(variables, variableNames, options = {}) {
|
|
175
|
+
return variables
|
|
176
|
+
.map((variable, index) => convertVariable(variable, index, variableNames, options))
|
|
177
|
+
.filter(Boolean);
|
|
178
|
+
}
|
|
179
|
+
function convertVariable(variable, index, variableNames, options = {}) {
|
|
180
|
+
const variableType = String(variable.type || '');
|
|
181
|
+
const queryString = sanitizeVariableQuery(extractVariableQuery(variable), options);
|
|
182
|
+
const current = variable.current || {};
|
|
183
|
+
const currentText = stringifyCurrent(current.text);
|
|
184
|
+
const currentValue = stringifyCurrent(current.value);
|
|
185
|
+
const includeAll = Boolean(variable.includeAll);
|
|
186
|
+
const defaultVal = {
|
|
187
|
+
label: normalizeAllValue(currentText, variable.allValue),
|
|
188
|
+
value: normalizeAllValue(currentValue, variable.allValue, true),
|
|
189
|
+
};
|
|
190
|
+
const base = {
|
|
191
|
+
name: variable.label || variable.name || '',
|
|
192
|
+
seq: index,
|
|
193
|
+
code: variable.name || `var_${index}`,
|
|
194
|
+
hide: variable.hide && variable.hide !== 0 ? 1 : 0,
|
|
195
|
+
multiple: Boolean(variable.multi),
|
|
196
|
+
includeStar: includeAll,
|
|
197
|
+
valueSort: 'desc',
|
|
198
|
+
extend: pruneEmpty({
|
|
199
|
+
originalType: variableType,
|
|
200
|
+
description: variable.description || undefined,
|
|
201
|
+
starMeaning: includeAll ? '*' : undefined,
|
|
202
|
+
options: Array.isArray(variable.options) ? variable.options : undefined,
|
|
203
|
+
refresh: variable.refresh,
|
|
204
|
+
skipUrlSync: variable.skipUrlSync,
|
|
205
|
+
sort: variable.sort,
|
|
206
|
+
}),
|
|
207
|
+
};
|
|
208
|
+
if (variableType === 'textbox' || variableType === 'constant' || variableType === 'interval') {
|
|
209
|
+
return pruneEmpty({
|
|
210
|
+
...base,
|
|
211
|
+
datasource: 'custom',
|
|
212
|
+
type: 'CUSTOM_LIST',
|
|
213
|
+
multiple: false,
|
|
214
|
+
includeStar: false,
|
|
215
|
+
definition: {
|
|
216
|
+
value: variable.query || currentValue || '',
|
|
217
|
+
defaultVal,
|
|
218
|
+
},
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
if (variableType === 'custom' || variableType === 'datasource') {
|
|
222
|
+
return pruneEmpty({
|
|
223
|
+
...base,
|
|
224
|
+
datasource: 'custom',
|
|
225
|
+
type: 'CUSTOM_LIST',
|
|
226
|
+
definition: {
|
|
227
|
+
value: variable.query || extractCustomOptions(variable.options || []),
|
|
228
|
+
defaultVal,
|
|
229
|
+
},
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
if (variableType === 'query') {
|
|
233
|
+
const queryKind = inferVariableQueryType(variable);
|
|
234
|
+
return pruneEmpty({
|
|
235
|
+
...base,
|
|
236
|
+
datasource: queryKind === 'FIELD' ? 'object' : 'dataflux',
|
|
237
|
+
type: queryKind,
|
|
238
|
+
definition: {
|
|
239
|
+
tag: '',
|
|
240
|
+
field: queryKind === 'FIELD' ? extractFieldName(queryString) : '',
|
|
241
|
+
value: replaceVariables(queryString || '', variableNames),
|
|
242
|
+
metric: extractMetricName(queryString, variableNames),
|
|
243
|
+
object: queryKind === 'FIELD' ? 'HOST' : '',
|
|
244
|
+
defaultVal,
|
|
245
|
+
},
|
|
246
|
+
});
|
|
247
|
+
}
|
|
211
248
|
return pruneEmpty({
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
})
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
return pruneEmpty({
|
|
227
|
-
...base,
|
|
228
|
-
datasource: 'custom',
|
|
229
|
-
type: 'CUSTOM_LIST',
|
|
230
|
-
multiple: false,
|
|
231
|
-
includeStar: false,
|
|
232
|
-
definition: {
|
|
233
|
-
value: variable.query || currentValue || '',
|
|
234
|
-
defaultVal,
|
|
235
|
-
},
|
|
236
|
-
})
|
|
237
|
-
}
|
|
238
|
-
|
|
249
|
+
...base,
|
|
250
|
+
datasource: 'custom',
|
|
251
|
+
type: 'CUSTOM_LIST',
|
|
252
|
+
multiple: false,
|
|
253
|
+
includeStar: false,
|
|
254
|
+
definition: {
|
|
255
|
+
value: variable.query || currentValue || '',
|
|
256
|
+
defaultVal,
|
|
257
|
+
},
|
|
258
|
+
});
|
|
259
|
+
}
|
|
239
260
|
function convertPanel(panel, groupName, rowPanel, variableNames, options) {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
return pruneEmpty({
|
|
252
|
-
name: replaceVariables(panel.title || '', variableNames),
|
|
253
|
-
type: chartType,
|
|
254
|
-
group: { name: group },
|
|
255
|
-
pos: position,
|
|
256
|
-
extend: {
|
|
257
|
-
settings,
|
|
258
|
-
links: links.length ? links : undefined,
|
|
259
|
-
sourcePanelType: options.keepGrafanaMeta ? panel.type : undefined,
|
|
260
|
-
sourcePanelId: options.keepGrafanaMeta ? panel.id : undefined,
|
|
261
|
-
pluginVersion: options.keepGrafanaMeta ? panel.pluginVersion || undefined : undefined,
|
|
262
|
-
grafana: options.keepGrafanaMeta
|
|
263
|
-
? pruneEmpty({
|
|
264
|
-
fieldConfig: panel.fieldConfig,
|
|
265
|
-
options: panel.options,
|
|
266
|
-
transformations: panel.transformations,
|
|
267
|
-
transparent: panel.transparent,
|
|
268
|
-
repeat: panel.repeat,
|
|
269
|
-
datasource: panel.datasource,
|
|
270
|
-
})
|
|
271
|
-
: undefined,
|
|
272
|
-
},
|
|
273
|
-
queries,
|
|
274
|
-
})
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
function buildPosition(panel, rowPanel) {
|
|
278
|
-
const gridPos = panel.gridPos || {}
|
|
279
|
-
const rowOffset = rowPanel?.gridPos?.y ?? 0
|
|
280
|
-
const rawY = typeof gridPos.y === 'number' ? gridPos.y - rowOffset : 0
|
|
281
|
-
|
|
282
|
-
return {
|
|
283
|
-
x: numberOr(gridPos.x, 0),
|
|
284
|
-
y: round1(rawY * 1.9 + 0.5),
|
|
285
|
-
w: numberOr(gridPos.w, 12),
|
|
286
|
-
h: round1(numberOr(gridPos.h, 8) * 1.9 + 0.1),
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
function buildQueries(panel, chartType, variableNames, options = {}) {
|
|
291
|
-
const queries = []
|
|
292
|
-
const targets = Array.isArray(panel.targets) ? panel.targets : []
|
|
293
|
-
|
|
294
|
-
for (let index = 0; index < targets.length; index++) {
|
|
295
|
-
const target = targets[index]
|
|
296
|
-
const queryText = extractTargetQuery(target)
|
|
297
|
-
if (!queryText) continue
|
|
298
|
-
|
|
299
|
-
const qtype = inferQueryLanguage(target, queryText)
|
|
300
|
-
const normalizedQueryText = normalizeTargetQuery(queryText, qtype, options)
|
|
301
|
-
queries.push(
|
|
302
|
-
pruneEmpty({
|
|
303
|
-
name: target.legendFormat || target.alias || '',
|
|
261
|
+
const chartType = inferChartType(panel);
|
|
262
|
+
if (!chartType || !panel.gridPos) {
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
const queries = buildQueries(panel, chartType, variableNames, options);
|
|
266
|
+
const settings = buildSettings(panel, chartType, queries, variableNames, options);
|
|
267
|
+
const links = extractPanelLinks(panel, variableNames);
|
|
268
|
+
const group = groupName !== null && groupName !== void 0 ? groupName : null;
|
|
269
|
+
const position = buildPosition(panel, rowPanel);
|
|
270
|
+
return pruneEmpty({
|
|
271
|
+
name: replaceVariables(panel.title || '', variableNames),
|
|
304
272
|
type: chartType,
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
273
|
+
group: { name: group },
|
|
274
|
+
pos: position,
|
|
275
|
+
extend: {
|
|
276
|
+
settings,
|
|
277
|
+
links: links.length ? links : undefined,
|
|
278
|
+
sourcePanelType: options.keepGrafanaMeta ? panel.type : undefined,
|
|
279
|
+
sourcePanelId: options.keepGrafanaMeta ? panel.id : undefined,
|
|
280
|
+
pluginVersion: options.keepGrafanaMeta ? panel.pluginVersion || undefined : undefined,
|
|
281
|
+
grafana: options.keepGrafanaMeta
|
|
282
|
+
? pruneEmpty({
|
|
283
|
+
fieldConfig: panel.fieldConfig,
|
|
284
|
+
options: panel.options,
|
|
285
|
+
transformations: panel.transformations,
|
|
286
|
+
transparent: panel.transparent,
|
|
287
|
+
repeat: panel.repeat,
|
|
288
|
+
datasource: panel.datasource,
|
|
289
|
+
})
|
|
290
|
+
: undefined,
|
|
315
291
|
},
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
292
|
+
queries,
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
function buildPosition(panel, rowPanel) {
|
|
296
|
+
var _a, _b;
|
|
297
|
+
const gridPos = panel.gridPos || {};
|
|
298
|
+
const rowOffset = (_b = (_a = rowPanel === null || rowPanel === void 0 ? void 0 : rowPanel.gridPos) === null || _a === void 0 ? void 0 : _a.y) !== null && _b !== void 0 ? _b : 0;
|
|
299
|
+
const rawY = typeof gridPos.y === 'number' ? gridPos.y - rowOffset : 0;
|
|
300
|
+
return {
|
|
301
|
+
x: numberOr(gridPos.x, 0),
|
|
302
|
+
y: round1(rawY * 1.9 + 0.5),
|
|
303
|
+
w: numberOr(gridPos.w, 12),
|
|
304
|
+
h: round1(numberOr(gridPos.h, 8) * 1.9 + 0.1),
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
function buildQueries(panel, chartType, variableNames, options = {}) {
|
|
308
|
+
var _a;
|
|
309
|
+
const queries = [];
|
|
310
|
+
const targets = Array.isArray(panel.targets) ? panel.targets : [];
|
|
311
|
+
for (let index = 0; index < targets.length; index++) {
|
|
312
|
+
const target = targets[index];
|
|
313
|
+
const targetAlias = normalizeQueryAlias(target.legendFormat || target.alias || '');
|
|
314
|
+
const queryText = sanitizeTargetQuery(extractTargetQuery(target), options);
|
|
315
|
+
if (!queryText)
|
|
316
|
+
continue;
|
|
317
|
+
const qtype = inferQueryLanguage(target, queryText);
|
|
318
|
+
const normalizedQueryText = normalizeTargetQuery(queryText, qtype, options);
|
|
319
|
+
queries.push(pruneEmpty({
|
|
320
|
+
name: targetAlias || undefined,
|
|
321
|
+
type: chartType,
|
|
322
|
+
qtype,
|
|
323
|
+
datasource: 'dataflux',
|
|
324
|
+
disabled: Boolean(target.hide),
|
|
325
|
+
query: {
|
|
326
|
+
q: replaceVariables(normalizedQueryText, variableNames),
|
|
327
|
+
code: normalizeQueryCode(target.refId, index),
|
|
328
|
+
type: qtype,
|
|
329
|
+
promqlCode: qtype === 'promql' ? index + 1 : undefined,
|
|
330
|
+
field: target.field || undefined,
|
|
331
|
+
},
|
|
332
|
+
extend: pruneEmpty({
|
|
333
|
+
refId: target.refId || undefined,
|
|
334
|
+
datasource: target.datasource || undefined,
|
|
335
|
+
editorMode: target.editorMode || undefined,
|
|
336
|
+
queryMode: target.queryMode || undefined,
|
|
337
|
+
}),
|
|
338
|
+
}));
|
|
339
|
+
}
|
|
340
|
+
if (chartType === 'text' && ((_a = panel.options) === null || _a === void 0 ? void 0 : _a.content)) {
|
|
341
|
+
queries.push({
|
|
342
|
+
query: {
|
|
343
|
+
content: replaceVariables(panel.options.content, variableNames),
|
|
344
|
+
},
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
return queries;
|
|
348
|
+
}
|
|
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;
|
|
351
|
+
const defaults = ((_a = panel.fieldConfig) === null || _a === void 0 ? void 0 : _a.defaults) || {};
|
|
352
|
+
const custom = defaults.custom || {};
|
|
353
|
+
const options = panel.options || {};
|
|
354
|
+
const legend = options.legend || panel.legend || {};
|
|
355
|
+
const transformationInfo = parseTransformations(panel.transformations || []);
|
|
356
|
+
const aliasInfo = buildAliases(queries, panel.fieldConfig, variableNames);
|
|
357
|
+
const aliases = aliasInfo.items;
|
|
358
|
+
const tableColumns = buildTableColumns(panel.fieldConfig, transformationInfo.organize, variableNames);
|
|
359
|
+
const fieldOverrides = buildFieldOverrides(panel.fieldConfig, variableNames);
|
|
360
|
+
const legacyGauge = panel.gauge || {};
|
|
361
|
+
const valueMappings = buildLegacyValueMappings(panel.valueMaps);
|
|
362
|
+
const rangeMappings = buildLegacyRangeMappings(panel.rangeMaps);
|
|
363
|
+
const mappingItems = [...buildMappings(defaults.mappings), ...valueMappings, ...rangeMappings];
|
|
364
|
+
const explicitUnit = firstDefined(defaults.unit, panel.format, (_c = (_b = panel.yaxes) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.format);
|
|
365
|
+
const unit = explicitUnit || inferUnitFromQueries(queries, chartType);
|
|
366
|
+
const precision = firstDefinedNumber(defaults.decimals, panel.decimals);
|
|
367
|
+
const min = firstDefinedNumber(defaults.min, legacyGauge.minValue, (_e = (_d = panel.yaxes) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.min);
|
|
368
|
+
const max = firstDefinedNumber(defaults.max, legacyGauge.maxValue, (_g = (_f = panel.yaxes) === null || _f === void 0 ? void 0 : _f[0]) === null || _g === void 0 ? void 0 : _g.max);
|
|
369
|
+
const lineWidth = firstDefinedNumber(custom.lineWidth, panel.linewidth);
|
|
370
|
+
const fillOpacity = firstDefinedNumber(custom.fillOpacity, normalizeLegacyFill(panel.fill));
|
|
371
|
+
const reduceOptions = options.reduceOptions || {};
|
|
372
|
+
const legendValues = mapLegendCalcs(((_h = legend.calcs) === null || _h === void 0 ? void 0 : _h.length) ? legend.calcs : extractLegacyLegendCalcs(legend));
|
|
373
|
+
const connectNulls = normalizeConnectNulls(firstDefined(custom.spanNulls, panel.nullPointMode));
|
|
374
|
+
const pointMode = firstDefined(custom.showPoints, panel.points === true ? 'always' : panel.points === false ? 'never' : undefined);
|
|
375
|
+
const graphMode = options.graphMode || undefined;
|
|
376
|
+
const legacyTextMode = panel.valueName || undefined;
|
|
377
|
+
const workspaceInfo = extractWorkspaceInfo(panel.targets || []);
|
|
378
|
+
const tooltip = options.tooltip || panel.tooltip || {};
|
|
379
|
+
const statText = options.text || {};
|
|
380
|
+
const textInfo = chartType === 'text' ? analyzeTextPanel(options.content, options.mode) : null;
|
|
381
|
+
const tableFooter = options.footer || {};
|
|
382
|
+
const tableSortBy = Array.isArray(options.sortBy) ? options.sortBy : [];
|
|
383
|
+
const tableCustom = chartType === 'table' ? custom : {};
|
|
384
|
+
const compareInfo = inferCompareSettings(queries, chartType);
|
|
385
|
+
const sortInfo = inferSortSettings(chartType, legend, tableSortBy);
|
|
386
|
+
const customUnits = buildCustomUnits(panel.fieldConfig);
|
|
387
|
+
const customColors = buildCustomColors(panel.fieldConfig);
|
|
388
|
+
const colorMappings = buildColorMappings(panel.fieldConfig, chartType);
|
|
389
|
+
const valColorMappings = buildValColorMappings(panel.fieldConfig, transformationInfo.organize);
|
|
390
|
+
const effectiveUnitType = customUnits.length ? 'custom' : unit ? 'global' : undefined;
|
|
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
|
+
});
|
|
398
|
+
const settings = {
|
|
399
|
+
showTitle: true,
|
|
400
|
+
titleDesc: panel.description || '',
|
|
401
|
+
isSampling: true,
|
|
402
|
+
changeWorkspace: workspaceInfo.changeWorkspace,
|
|
403
|
+
workspaceUUID: workspaceInfo.workspaceUUID,
|
|
404
|
+
workspaceName: workspaceInfo.workspaceName,
|
|
405
|
+
showFieldMapping: false,
|
|
406
|
+
openThousandsSeparator: true,
|
|
407
|
+
precision: typeof precision === 'number' ? String(precision) : '2',
|
|
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')),
|
|
409
|
+
fixedTime: panel.timeFrom || '',
|
|
410
|
+
maxPointCount: (_l = panel.maxDataPoints) !== null && _l !== void 0 ? _l : undefined,
|
|
411
|
+
showLegend: legend.showLegend,
|
|
412
|
+
legendPostion: mapLegendPlacement(legend.placement),
|
|
413
|
+
legendValues,
|
|
414
|
+
showLegend: firstDefined(legend.showLegend, legend.show),
|
|
415
|
+
showLine: chartType === 'sequence' ? inferShowLine(panel, custom) : undefined,
|
|
416
|
+
lineType: mapLineInterpolation(custom.lineInterpolation),
|
|
417
|
+
connectNulls,
|
|
418
|
+
openStack: inferOpenStack(panel, custom),
|
|
419
|
+
stackType: mapStackType(firstDefined((_m = custom.stacking) === null || _m === void 0 ? void 0 : _m.mode, panel.stack ? 'normal' : 'none')),
|
|
420
|
+
chartType: inferDisplayChartType(panel, chartType),
|
|
421
|
+
isTimeInterval: chartType === 'sequence' || chartType === 'bar' || chartType === 'heatmap' || chartType === 'histogram',
|
|
422
|
+
xAxisShowType: chartType === 'sequence' || chartType === 'bar' ? 'time' : undefined,
|
|
423
|
+
unitType: effectiveUnitType,
|
|
424
|
+
globalUnit: customUnits.length ? undefined : mapUnit(unit),
|
|
425
|
+
units: customUnits.length ? customUnits : undefined,
|
|
426
|
+
colors: customColors.length ? customColors : undefined,
|
|
427
|
+
colorMappings: colorMappings.length ? colorMappings : undefined,
|
|
428
|
+
levels,
|
|
429
|
+
slimit,
|
|
430
|
+
mappings: mappingItems,
|
|
431
|
+
alias: aliases,
|
|
432
|
+
min,
|
|
433
|
+
max,
|
|
434
|
+
showPercent: Array.isArray(options.displayLabels) ? options.displayLabels.includes('percent') : undefined,
|
|
435
|
+
showLabel: chartType === 'pie' ? Array.isArray(options.displayLabels) && options.displayLabels.length > 0 : undefined,
|
|
436
|
+
showLabelValue: Array.isArray(options.displayLabels)
|
|
437
|
+
? options.displayLabels.includes('value') || options.displayLabels.includes('name')
|
|
438
|
+
: undefined,
|
|
439
|
+
direction: options.orientation || undefined,
|
|
440
|
+
queryMode: chartType === 'table' ? 'toGroupColumn' : undefined,
|
|
441
|
+
showTableHead: chartType === 'table' ? options.showHeader !== false : undefined,
|
|
442
|
+
pageEnable: chartType === 'table' ? false : undefined,
|
|
443
|
+
pageSize: chartType === 'table' ? 20 : undefined,
|
|
444
|
+
showColumns: chartType === 'table' ? tableColumns.map((column) => column.title || column.field) : undefined,
|
|
445
|
+
valMappings: chartType === 'table' ? buildTableMappings(panel.fieldConfig, transformationInfo.organize) : undefined,
|
|
446
|
+
valColorMappings: chartType === 'table' && valColorMappings.length ? valColorMappings : undefined,
|
|
447
|
+
legendValueOpen: Array.isArray(legend.values) ? legend.values.includes('value') : undefined,
|
|
448
|
+
legendValuePercentOpen: Array.isArray(legend.values) ? legend.values.includes('percent') : undefined,
|
|
449
|
+
showTopSize: chartType === 'toplist' ? true : undefined,
|
|
450
|
+
topSize: chartType === 'toplist' ? extractReduceLimit(options) : undefined,
|
|
451
|
+
scientificNotation: unit === 'short' ? true : undefined,
|
|
452
|
+
mainMeasurementQueryCode: ((_p = (_o = queries[0]) === null || _o === void 0 ? void 0 : _o.query) === null || _p === void 0 ? void 0 : _p.code) || undefined,
|
|
453
|
+
mainMeasurementLimit: chartType === 'pie' ? extractReduceLimit(options) : undefined,
|
|
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,
|
|
457
|
+
sequenceChartType: chartType === 'singlestat' && graphMode ? inferSequenceChartType(panel, graphMode) : undefined,
|
|
458
|
+
showLineAxis: chartType === 'singlestat' ? graphMode !== 'none' : undefined,
|
|
459
|
+
repeatChartVariable: typeof panel.repeat === 'string' && panel.repeat && variableNames.has(panel.repeat) ? panel.repeat : undefined,
|
|
460
|
+
repeatChartRowLimit: typeof panel.maxPerRow === 'number' ? panel.maxPerRow : undefined,
|
|
461
|
+
compares: compareInfo.compares,
|
|
462
|
+
compareType: compareInfo.compareType,
|
|
463
|
+
openCompare: compareInfo.openCompare,
|
|
464
|
+
compareChartType: compareInfo.compareChartType,
|
|
465
|
+
mainMeasurementSort: sortInfo.mainMeasurementSort,
|
|
466
|
+
sorderByOrder: sortInfo.sorderByOrder,
|
|
467
|
+
};
|
|
468
|
+
const links = extractPanelLinks(panel);
|
|
469
|
+
if (links.length) {
|
|
470
|
+
settings.queryCodes = queries.map((query) => { var _a; return (_a = query.query) === null || _a === void 0 ? void 0 : _a.code; }).filter(Boolean);
|
|
471
|
+
}
|
|
472
|
+
settings.extend = pruneEmpty({
|
|
473
|
+
appearance: pruneEmpty({
|
|
474
|
+
lineWidth,
|
|
475
|
+
fillOpacity,
|
|
476
|
+
gradientMode: custom.gradientMode || undefined,
|
|
477
|
+
pointMode,
|
|
478
|
+
pointSize: firstDefinedNumber(custom.pointSize, panel.pointradius),
|
|
479
|
+
axisPlacement: custom.axisPlacement || undefined,
|
|
480
|
+
axisLabel: custom.axisLabel || undefined,
|
|
481
|
+
axisColorMode: custom.axisColorMode || undefined,
|
|
482
|
+
axisCenteredZero: typeof custom.axisCenteredZero === 'boolean' ? custom.axisCenteredZero : undefined,
|
|
483
|
+
axisSoftMin: numberOrUndefined(custom.axisSoftMin),
|
|
484
|
+
axisSoftMax: numberOrUndefined(custom.axisSoftMax),
|
|
485
|
+
barAlignment: numberOrUndefined(custom.barAlignment),
|
|
486
|
+
scaleDistribution: custom.scaleDistribution || undefined,
|
|
487
|
+
drawStyle: custom.drawStyle || undefined,
|
|
488
|
+
lineStyle: custom.lineStyle || undefined,
|
|
489
|
+
spanNulls: custom.spanNulls,
|
|
490
|
+
stackingGroup: ((_u = custom.stacking) === null || _u === void 0 ? void 0 : _u.group) || undefined,
|
|
491
|
+
graphMode,
|
|
492
|
+
colorMode: options.colorMode || undefined,
|
|
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,
|
|
497
|
+
textMode: options.textMode || legacyTextMode,
|
|
498
|
+
reduceCalcs: Array.isArray(reduceOptions.calcs) ? reduceOptions.calcs : undefined,
|
|
499
|
+
reduceFields: reduceOptions.fields || undefined,
|
|
500
|
+
reduceValues: typeof reduceOptions.values === 'boolean' ? reduceOptions.values : undefined,
|
|
501
|
+
pieType: options.pieType || undefined,
|
|
502
|
+
gaugeMode: chartType === 'gauge' || panel.type === 'singlestat' ? inferGaugeMode(panel, options, legacyGauge) : undefined,
|
|
503
|
+
thresholdMarkers: typeof legacyGauge.thresholdMarkers === 'boolean' ? legacyGauge.thresholdMarkers : undefined,
|
|
504
|
+
thresholdLabels: typeof legacyGauge.thresholdLabels === 'boolean' ? legacyGauge.thresholdLabels : undefined,
|
|
505
|
+
hideFrom: custom.hideFrom || undefined,
|
|
506
|
+
justifyMode: options.justifyMode || undefined,
|
|
507
|
+
titleSize: typeof statText.titleSize === 'number' ? statText.titleSize : undefined,
|
|
508
|
+
valueSize: typeof statText.valueSize === 'number' ? statText.valueSize : undefined,
|
|
321
509
|
}),
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
repeatChartVariable: typeof panel.repeat === 'string' && panel.repeat ? panel.repeat : undefined,
|
|
440
|
-
repeatChartRowLimit: typeof panel.maxPerRow === 'number' ? panel.maxPerRow : undefined,
|
|
441
|
-
compares: compareInfo.compares,
|
|
442
|
-
compareType: compareInfo.compareType,
|
|
443
|
-
openCompare: compareInfo.openCompare,
|
|
444
|
-
compareChartType: compareInfo.compareChartType,
|
|
445
|
-
mainMeasurementSort: sortInfo.mainMeasurementSort,
|
|
446
|
-
sorderByOrder: sortInfo.sorderByOrder,
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
const links = extractPanelLinks(panel)
|
|
450
|
-
if (links.length) {
|
|
451
|
-
settings.queryCodes = queries.map((query) => query.query?.code).filter(Boolean)
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
settings.extend = pruneEmpty({
|
|
455
|
-
appearance: pruneEmpty({
|
|
456
|
-
lineWidth,
|
|
457
|
-
fillOpacity,
|
|
458
|
-
gradientMode: custom.gradientMode || undefined,
|
|
459
|
-
pointMode,
|
|
460
|
-
pointSize: firstDefinedNumber(custom.pointSize, panel.pointradius),
|
|
461
|
-
axisPlacement: custom.axisPlacement || undefined,
|
|
462
|
-
axisLabel: custom.axisLabel || undefined,
|
|
463
|
-
axisColorMode: custom.axisColorMode || undefined,
|
|
464
|
-
axisCenteredZero: typeof custom.axisCenteredZero === 'boolean' ? custom.axisCenteredZero : undefined,
|
|
465
|
-
axisSoftMin: numberOrUndefined(custom.axisSoftMin),
|
|
466
|
-
axisSoftMax: numberOrUndefined(custom.axisSoftMax),
|
|
467
|
-
barAlignment: numberOrUndefined(custom.barAlignment),
|
|
468
|
-
scaleDistribution: custom.scaleDistribution || undefined,
|
|
469
|
-
drawStyle: custom.drawStyle || undefined,
|
|
470
|
-
lineStyle: custom.lineStyle || undefined,
|
|
471
|
-
spanNulls: custom.spanNulls,
|
|
472
|
-
stackingGroup: custom.stacking?.group || undefined,
|
|
473
|
-
graphMode,
|
|
474
|
-
colorMode: options.colorMode || undefined,
|
|
475
|
-
fieldColorMode: defaults.color?.mode || undefined,
|
|
476
|
-
fixedColor: defaults.color?.fixedColor || undefined,
|
|
477
|
-
thresholdsMode: defaults.thresholds?.mode || undefined,
|
|
478
|
-
thresholdsStyleMode: custom.thresholdsStyle?.mode || undefined,
|
|
479
|
-
textMode: options.textMode || legacyTextMode,
|
|
480
|
-
reduceCalcs: Array.isArray(reduceOptions.calcs) ? reduceOptions.calcs : undefined,
|
|
481
|
-
reduceFields: reduceOptions.fields || undefined,
|
|
482
|
-
reduceValues: typeof reduceOptions.values === 'boolean' ? reduceOptions.values : undefined,
|
|
483
|
-
pieType: options.pieType || undefined,
|
|
484
|
-
gaugeMode: chartType === 'gauge' || panel.type === 'singlestat' ? inferGaugeMode(panel, options, legacyGauge) : undefined,
|
|
485
|
-
thresholdMarkers: typeof legacyGauge.thresholdMarkers === 'boolean' ? legacyGauge.thresholdMarkers : undefined,
|
|
486
|
-
thresholdLabels: typeof legacyGauge.thresholdLabels === 'boolean' ? legacyGauge.thresholdLabels : undefined,
|
|
487
|
-
hideFrom: custom.hideFrom || undefined,
|
|
488
|
-
justifyMode: options.justifyMode || undefined,
|
|
489
|
-
titleSize: typeof statText.titleSize === 'number' ? statText.titleSize : undefined,
|
|
490
|
-
valueSize: typeof statText.valueSize === 'number' ? statText.valueSize : undefined,
|
|
491
|
-
}),
|
|
492
|
-
legend: pruneEmpty({
|
|
493
|
-
displayMode: legend.displayMode || undefined,
|
|
494
|
-
sortBy: legend.sortBy || legend.sort || undefined,
|
|
495
|
-
sortDesc: typeof legend.sortDesc === 'boolean' ? legend.sortDesc : undefined,
|
|
496
|
-
width: firstDefinedNumber(legend.width, legend.sideWidth),
|
|
497
|
-
}),
|
|
498
|
-
tooltip: pruneEmpty({
|
|
499
|
-
mode: tooltip.mode || tooltip.sharedMode || undefined,
|
|
500
|
-
sort: tooltip.sort || tooltip.value_type || undefined,
|
|
501
|
-
}),
|
|
502
|
-
table: chartType === 'table'
|
|
503
|
-
? pruneEmpty({
|
|
504
|
-
align: tableCustom.align || undefined,
|
|
505
|
-
displayMode: tableCustom.displayMode || undefined,
|
|
506
|
-
sortBy: tableSortBy,
|
|
507
|
-
footer: pruneEmpty({
|
|
508
|
-
fields: tableFooter.fields || undefined,
|
|
509
|
-
reducer: Array.isArray(tableFooter.reducer) ? tableFooter.reducer : undefined,
|
|
510
|
-
show: typeof tableFooter.show === 'boolean' ? tableFooter.show : undefined,
|
|
511
|
-
}),
|
|
512
|
-
})
|
|
513
|
-
: undefined,
|
|
514
|
-
text: textInfo || undefined,
|
|
515
|
-
tableColumns: chartType === 'table' && tableColumns.length ? tableColumns : undefined,
|
|
516
|
-
fieldOverrides: fieldOverrides.length ? fieldOverrides : undefined,
|
|
517
|
-
transformations: transformationInfo.normalized.length ? transformationInfo.normalized : undefined,
|
|
518
|
-
fieldFilterPattern: transformationInfo.fieldFilterPattern || undefined,
|
|
519
|
-
valueFilters: transformationInfo.valueFilters.length ? transformationInfo.valueFilters : undefined,
|
|
520
|
-
layout: pruneEmpty({
|
|
521
|
-
repeatDirection: panel.repeatDirection || undefined,
|
|
522
|
-
}),
|
|
523
|
-
})
|
|
524
|
-
|
|
525
|
-
return pruneEmpty(settings)
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
function buildLevels(thresholds) {
|
|
529
|
-
const steps = Array.isArray(thresholds?.steps) ? thresholds.steps : []
|
|
530
|
-
return steps
|
|
531
|
-
.filter((step) => typeof step.value === 'number' || typeof step.color === 'string')
|
|
532
|
-
.map((step, index) => ({
|
|
533
|
-
title: `Level ${index + 1}`,
|
|
534
|
-
value: typeof step.value === 'number' ? step.value : 0,
|
|
535
|
-
bgColor: normalizeColor(step.color),
|
|
536
|
-
}))
|
|
537
|
-
}
|
|
538
|
-
|
|
510
|
+
legend: pruneEmpty({
|
|
511
|
+
displayMode: legend.displayMode || undefined,
|
|
512
|
+
sortBy: legend.sortBy || legend.sort || undefined,
|
|
513
|
+
sortDesc: typeof legend.sortDesc === 'boolean' ? legend.sortDesc : undefined,
|
|
514
|
+
width: firstDefinedNumber(legend.width, legend.sideWidth),
|
|
515
|
+
}),
|
|
516
|
+
tooltip: pruneEmpty({
|
|
517
|
+
mode: tooltip.mode || tooltip.sharedMode || undefined,
|
|
518
|
+
sort: tooltip.sort || tooltip.value_type || undefined,
|
|
519
|
+
}),
|
|
520
|
+
table: chartType === 'table'
|
|
521
|
+
? pruneEmpty({
|
|
522
|
+
align: tableCustom.align || undefined,
|
|
523
|
+
displayMode: tableCustom.displayMode || undefined,
|
|
524
|
+
sortBy: tableSortBy,
|
|
525
|
+
footer: pruneEmpty({
|
|
526
|
+
fields: tableFooter.fields || undefined,
|
|
527
|
+
reducer: Array.isArray(tableFooter.reducer) ? tableFooter.reducer : undefined,
|
|
528
|
+
show: typeof tableFooter.show === 'boolean' ? tableFooter.show : undefined,
|
|
529
|
+
}),
|
|
530
|
+
})
|
|
531
|
+
: undefined,
|
|
532
|
+
text: textInfo || undefined,
|
|
533
|
+
tableColumns: chartType === 'table' && tableColumns.length ? tableColumns : 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,
|
|
538
|
+
layout: pruneEmpty({
|
|
539
|
+
repeatDirection: panel.repeatDirection || undefined,
|
|
540
|
+
}),
|
|
541
|
+
aliasReview: converterOptions.keepGrafanaMeta ? aliasInfo.review : undefined,
|
|
542
|
+
});
|
|
543
|
+
return pruneEmpty(settings);
|
|
544
|
+
}
|
|
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) {
|
|
555
|
+
const steps = Array.isArray(thresholds === null || thresholds === void 0 ? void 0 : thresholds.steps) ? thresholds.steps : [];
|
|
556
|
+
return steps
|
|
557
|
+
.filter((step) => typeof normalizeLevelNumber(step.value) === 'number' || typeof step.color === 'string')
|
|
558
|
+
.map((step, index) => ({
|
|
559
|
+
title: `Level ${index + 1}`,
|
|
560
|
+
value: normalizeLevelNumber(step.value) !== undefined ? normalizeLevelNumber(step.value) : 0,
|
|
561
|
+
bgColor: normalizeColor(step.color),
|
|
562
|
+
}));
|
|
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
|
+
}
|
|
539
627
|
function buildMappings(mappings) {
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
}
|
|
567
|
-
|
|
628
|
+
var _a;
|
|
629
|
+
if (!Array.isArray(mappings))
|
|
630
|
+
return [];
|
|
631
|
+
const result = [];
|
|
632
|
+
for (const mapping of mappings) {
|
|
633
|
+
if (mapping.type === 'value' && mapping.options && typeof mapping.options === 'object') {
|
|
634
|
+
for (const [rawValue, item] of Object.entries(mapping.options)) {
|
|
635
|
+
result.push({
|
|
636
|
+
originalVal: [rawValue],
|
|
637
|
+
operation: '=',
|
|
638
|
+
mappingVal: item.text || rawValue,
|
|
639
|
+
});
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
if (mapping.type === 'range' && mapping.options) {
|
|
643
|
+
const from = mapping.options.from;
|
|
644
|
+
const to = mapping.options.to;
|
|
645
|
+
result.push({
|
|
646
|
+
originalVal: [String(from !== null && from !== void 0 ? from : ''), String(to !== null && to !== void 0 ? to : '')],
|
|
647
|
+
operation: 'between',
|
|
648
|
+
mappingVal: ((_a = mapping.options.result) === null || _a === void 0 ? void 0 : _a.text) || '',
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
return result;
|
|
653
|
+
}
|
|
568
654
|
function buildTableMappings(fieldConfig, organize) {
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
655
|
+
var _a;
|
|
656
|
+
const overrideMappings = [];
|
|
657
|
+
const overrides = Array.isArray(fieldConfig === null || fieldConfig === void 0 ? void 0 : fieldConfig.overrides) ? fieldConfig.overrides : [];
|
|
658
|
+
const organizeMaps = createOrganizeMaps(organize);
|
|
659
|
+
for (const override of overrides) {
|
|
660
|
+
const field = (_a = override.matcher) === null || _a === void 0 ? void 0 : _a.options;
|
|
661
|
+
if (!field)
|
|
662
|
+
continue;
|
|
663
|
+
const displayField = resolveDisplayFieldName(field, organizeMaps);
|
|
664
|
+
const properties = Array.isArray(override.properties) ? override.properties : [];
|
|
665
|
+
for (const property of properties) {
|
|
666
|
+
if (property.id !== 'mappings')
|
|
667
|
+
continue;
|
|
668
|
+
const mappings = buildMappings(property.value);
|
|
669
|
+
for (const mapping of mappings) {
|
|
670
|
+
overrideMappings.push({
|
|
671
|
+
field: displayField,
|
|
672
|
+
...mapping,
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
return overrideMappings;
|
|
678
|
+
}
|
|
593
679
|
function buildTableColumns(fieldConfig, organize, variableNames = new Set()) {
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
680
|
+
var _a, _b;
|
|
681
|
+
const columns = new Map();
|
|
682
|
+
const defaultCustom = ((_a = fieldConfig === null || fieldConfig === void 0 ? void 0 : fieldConfig.defaults) === null || _a === void 0 ? void 0 : _a.custom) || {};
|
|
683
|
+
const overrides = Array.isArray(fieldConfig === null || fieldConfig === void 0 ? void 0 : fieldConfig.overrides) ? fieldConfig.overrides : [];
|
|
684
|
+
const organizeMaps = createOrganizeMaps(organize);
|
|
685
|
+
const { renamedFields, excludedFields, indexedFields } = organizeMaps;
|
|
686
|
+
for (const override of overrides) {
|
|
687
|
+
const rawField = (_b = override.matcher) === null || _b === void 0 ? void 0 : _b.options;
|
|
688
|
+
if (!rawField)
|
|
689
|
+
continue;
|
|
690
|
+
const field = resolveRawFieldName(rawField, organizeMaps);
|
|
691
|
+
if (excludedFields[field] === true || excludedFields[rawField] === true)
|
|
692
|
+
continue;
|
|
693
|
+
const columnKey = resolveDisplayFieldName(field, organizeMaps);
|
|
694
|
+
const currentColumn = columns.get(columnKey) || {
|
|
695
|
+
field,
|
|
696
|
+
title: columnKey,
|
|
697
|
+
order: typeof indexedFields[field] === 'number' ? indexedFields[field] : undefined,
|
|
698
|
+
align: defaultCustom.align || undefined,
|
|
699
|
+
displayMode: defaultCustom.displayMode || undefined,
|
|
700
|
+
};
|
|
701
|
+
for (const property of override.properties || []) {
|
|
702
|
+
if (property.id === 'custom.width') {
|
|
703
|
+
currentColumn.width = property.value;
|
|
704
|
+
}
|
|
705
|
+
if (property.id === 'custom.align') {
|
|
706
|
+
currentColumn.align = property.value;
|
|
707
|
+
}
|
|
708
|
+
if (property.id === 'custom.displayMode') {
|
|
709
|
+
currentColumn.displayMode = property.value;
|
|
710
|
+
}
|
|
711
|
+
if (property.id === 'links') {
|
|
712
|
+
currentColumn.links = Array.isArray(property.value)
|
|
713
|
+
? property.value.map((link) => normalizeGuanceLinkItem(link, variableNames))
|
|
714
|
+
: undefined;
|
|
715
|
+
}
|
|
716
|
+
if (property.id === 'mappings') {
|
|
717
|
+
currentColumn.mappings = buildMappings(property.value);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
columns.set(columnKey, pruneEmpty(currentColumn));
|
|
721
|
+
}
|
|
722
|
+
if (organize) {
|
|
723
|
+
for (const [field, order] of Object.entries(indexedFields)) {
|
|
724
|
+
if (excludedFields[field] === true)
|
|
725
|
+
continue;
|
|
726
|
+
const columnKey = resolveDisplayFieldName(field, organizeMaps);
|
|
727
|
+
if (columns.has(columnKey)) {
|
|
728
|
+
const currentColumn = columns.get(columnKey);
|
|
729
|
+
currentColumn.field = field;
|
|
730
|
+
currentColumn.order = typeof order === 'number' ? order : currentColumn.order;
|
|
731
|
+
currentColumn.title = columnKey;
|
|
732
|
+
columns.set(columnKey, pruneEmpty(currentColumn));
|
|
733
|
+
continue;
|
|
734
|
+
}
|
|
735
|
+
columns.set(columnKey, pruneEmpty({
|
|
736
|
+
field,
|
|
737
|
+
title: columnKey,
|
|
738
|
+
order: typeof order === 'number' ? order : undefined,
|
|
739
|
+
}));
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
return finalizeTableColumns([...columns.values()]);
|
|
743
|
+
}
|
|
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';
|
|
857
|
+
}
|
|
671
858
|
function buildCustomUnits(fieldConfig) {
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
return units
|
|
696
|
-
}
|
|
697
|
-
|
|
859
|
+
var _a;
|
|
860
|
+
const overrides = Array.isArray(fieldConfig === null || fieldConfig === void 0 ? void 0 : fieldConfig.overrides) ? fieldConfig.overrides : [];
|
|
861
|
+
const units = [];
|
|
862
|
+
for (const override of overrides) {
|
|
863
|
+
const rawKey = String(((_a = override === null || override === void 0 ? void 0 : override.matcher) === null || _a === void 0 ? void 0 : _a.options) || '').trim();
|
|
864
|
+
if (!rawKey)
|
|
865
|
+
continue;
|
|
866
|
+
const unitProperty = Array.isArray(override === null || override === void 0 ? void 0 : override.properties)
|
|
867
|
+
? override.properties.find((property) => (property === null || property === void 0 ? void 0 : property.id) === 'unit')
|
|
868
|
+
: undefined;
|
|
869
|
+
if (!unitProperty || typeof unitProperty.value !== 'string')
|
|
870
|
+
continue;
|
|
871
|
+
const unit = unitProperty.value;
|
|
872
|
+
units.push(pruneEmpty({
|
|
873
|
+
key: rawKey,
|
|
874
|
+
name: rawKey,
|
|
875
|
+
unit,
|
|
876
|
+
units: mapUnit(unit),
|
|
877
|
+
}));
|
|
878
|
+
}
|
|
879
|
+
return units;
|
|
880
|
+
}
|
|
698
881
|
function buildCustomColors(fieldConfig) {
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
return colors
|
|
724
|
-
}
|
|
725
|
-
|
|
882
|
+
var _a, _b, _c;
|
|
883
|
+
const overrides = Array.isArray(fieldConfig === null || fieldConfig === void 0 ? void 0 : fieldConfig.overrides) ? fieldConfig.overrides : [];
|
|
884
|
+
const colors = [];
|
|
885
|
+
for (const override of overrides) {
|
|
886
|
+
const rawKey = String(((_a = override === null || override === void 0 ? void 0 : override.matcher) === null || _a === void 0 ? void 0 : _a.options) || '').trim();
|
|
887
|
+
if (!rawKey)
|
|
888
|
+
continue;
|
|
889
|
+
const colorProperty = Array.isArray(override === null || override === void 0 ? void 0 : override.properties)
|
|
890
|
+
? override.properties.find((property) => (property === null || property === void 0 ? void 0 : property.id) === 'color')
|
|
891
|
+
: undefined;
|
|
892
|
+
const fixedColor = (_b = colorProperty === null || colorProperty === void 0 ? void 0 : colorProperty.value) === null || _b === void 0 ? void 0 : _b.fixedColor;
|
|
893
|
+
const colorMode = (_c = colorProperty === null || colorProperty === void 0 ? void 0 : colorProperty.value) === null || _c === void 0 ? void 0 : _c.mode;
|
|
894
|
+
if (typeof fixedColor !== 'string' || !fixedColor)
|
|
895
|
+
continue;
|
|
896
|
+
if (colorMode && colorMode !== 'fixed')
|
|
897
|
+
continue;
|
|
898
|
+
colors.push(pruneEmpty({
|
|
899
|
+
key: rawKey,
|
|
900
|
+
name: rawKey,
|
|
901
|
+
color: normalizeColor(fixedColor),
|
|
902
|
+
}));
|
|
903
|
+
}
|
|
904
|
+
return colors;
|
|
905
|
+
}
|
|
726
906
|
function buildColorMappings(fieldConfig, chartType) {
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
return mappings
|
|
768
|
-
}
|
|
769
|
-
|
|
907
|
+
var _a, _b;
|
|
908
|
+
if (chartType !== 'toplist')
|
|
909
|
+
return [];
|
|
910
|
+
const steps = Array.isArray((_b = (_a = fieldConfig === null || fieldConfig === void 0 ? void 0 : fieldConfig.defaults) === null || _a === void 0 ? void 0 : _a.thresholds) === null || _b === void 0 ? void 0 : _b.steps) ? fieldConfig.defaults.thresholds.steps : [];
|
|
911
|
+
if (steps.length === 0)
|
|
912
|
+
return [];
|
|
913
|
+
const mappings = [];
|
|
914
|
+
for (let index = 0; index < steps.length; index++) {
|
|
915
|
+
const current = steps[index];
|
|
916
|
+
const next = steps[index + 1];
|
|
917
|
+
const bgColor = normalizeColor(current === null || current === void 0 ? void 0 : current.color);
|
|
918
|
+
const start = current === null || current === void 0 ? void 0 : current.value;
|
|
919
|
+
const end = next === null || next === void 0 ? void 0 : next.value;
|
|
920
|
+
if (typeof start === 'number' && typeof end === 'number') {
|
|
921
|
+
mappings.push({
|
|
922
|
+
value: [start, end],
|
|
923
|
+
bgColor,
|
|
924
|
+
operation: 'between',
|
|
925
|
+
});
|
|
926
|
+
continue;
|
|
927
|
+
}
|
|
928
|
+
if (typeof start === 'number') {
|
|
929
|
+
mappings.push({
|
|
930
|
+
value: [start],
|
|
931
|
+
bgColor,
|
|
932
|
+
operation: '>=',
|
|
933
|
+
});
|
|
934
|
+
continue;
|
|
935
|
+
}
|
|
936
|
+
if (typeof end === 'number') {
|
|
937
|
+
mappings.push({
|
|
938
|
+
value: [end],
|
|
939
|
+
bgColor,
|
|
940
|
+
operation: '<',
|
|
941
|
+
});
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
return mappings;
|
|
945
|
+
}
|
|
770
946
|
function buildValColorMappings(fieldConfig, organize) {
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
return mappings
|
|
803
|
-
}
|
|
804
|
-
|
|
947
|
+
var _a, _b;
|
|
948
|
+
const overrides = Array.isArray(fieldConfig === null || fieldConfig === void 0 ? void 0 : fieldConfig.overrides) ? fieldConfig.overrides : [];
|
|
949
|
+
const organizeMaps = createOrganizeMaps(organize);
|
|
950
|
+
const mappings = [];
|
|
951
|
+
for (const override of overrides) {
|
|
952
|
+
const rawField = (_a = override === null || override === void 0 ? void 0 : override.matcher) === null || _a === void 0 ? void 0 : _a.options;
|
|
953
|
+
if (!rawField)
|
|
954
|
+
continue;
|
|
955
|
+
const field = resolveDisplayFieldName(resolveRawFieldName(rawField, organizeMaps), organizeMaps);
|
|
956
|
+
const properties = Array.isArray(override === null || override === void 0 ? void 0 : override.properties) ? override.properties : [];
|
|
957
|
+
const mappingProperty = properties.find((property) => (property === null || property === void 0 ? void 0 : property.id) === 'mappings');
|
|
958
|
+
if (!mappingProperty)
|
|
959
|
+
continue;
|
|
960
|
+
const colorProperty = properties.find((property) => (property === null || property === void 0 ? void 0 : property.id) === 'color');
|
|
961
|
+
const fixedColor = typeof ((_b = colorProperty === null || colorProperty === void 0 ? void 0 : colorProperty.value) === null || _b === void 0 ? void 0 : _b.fixedColor) === 'string' ? normalizeColor(colorProperty.value.fixedColor) : '';
|
|
962
|
+
const tableMappings = buildMappings(mappingProperty.value);
|
|
963
|
+
for (const mapping of tableMappings) {
|
|
964
|
+
mappings.push(pruneEmpty({
|
|
965
|
+
field,
|
|
966
|
+
value: mapping.originalVal,
|
|
967
|
+
bgColor: '',
|
|
968
|
+
fontColor: fixedColor,
|
|
969
|
+
lineColor: '',
|
|
970
|
+
operation: mapping.operation,
|
|
971
|
+
}));
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
return mappings;
|
|
975
|
+
}
|
|
805
976
|
function buildFieldOverrides(fieldConfig, variableNames = new Set()) {
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
})
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
}
|
|
827
|
-
|
|
828
|
-
return normalized
|
|
829
|
-
}
|
|
830
|
-
|
|
977
|
+
var _a, _b;
|
|
978
|
+
const overrides = Array.isArray(fieldConfig === null || fieldConfig === void 0 ? void 0 : fieldConfig.overrides) ? fieldConfig.overrides : [];
|
|
979
|
+
const normalized = [];
|
|
980
|
+
for (const override of overrides) {
|
|
981
|
+
const properties = Array.isArray(override.properties) ? override.properties : [];
|
|
982
|
+
const normalizedProperties = properties
|
|
983
|
+
.map((property) => normalizeOverrideProperty(property, variableNames))
|
|
984
|
+
.filter(Boolean);
|
|
985
|
+
if (normalizedProperties.length === 0)
|
|
986
|
+
continue;
|
|
987
|
+
normalized.push(pruneEmpty({
|
|
988
|
+
matcher: pruneEmpty({
|
|
989
|
+
id: ((_a = override.matcher) === null || _a === void 0 ? void 0 : _a.id) || undefined,
|
|
990
|
+
options: (_b = override.matcher) === null || _b === void 0 ? void 0 : _b.options,
|
|
991
|
+
}),
|
|
992
|
+
properties: normalizedProperties,
|
|
993
|
+
}));
|
|
994
|
+
}
|
|
995
|
+
return normalized;
|
|
996
|
+
}
|
|
831
997
|
function normalizeOverrideProperty(property, variableNames = new Set()) {
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
998
|
+
if (!(property === null || property === void 0 ? void 0 : property.id))
|
|
999
|
+
return undefined;
|
|
1000
|
+
if (property.id === 'links') {
|
|
1001
|
+
return pruneEmpty({
|
|
1002
|
+
id: property.id,
|
|
1003
|
+
value: Array.isArray(property.value)
|
|
1004
|
+
? property.value.map((link) => normalizeGuanceLinkItem(link, variableNames))
|
|
1005
|
+
: undefined,
|
|
1006
|
+
});
|
|
1007
|
+
}
|
|
835
1008
|
return pruneEmpty({
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
})
|
|
841
|
-
}
|
|
842
|
-
|
|
843
|
-
return pruneEmpty({
|
|
844
|
-
id: property.id,
|
|
845
|
-
value: property.value,
|
|
846
|
-
})
|
|
847
|
-
}
|
|
848
|
-
|
|
1009
|
+
id: property.id,
|
|
1010
|
+
value: property.value,
|
|
1011
|
+
});
|
|
1012
|
+
}
|
|
849
1013
|
function analyzeTextPanel(content, mode) {
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
}
|
|
865
|
-
|
|
1014
|
+
if (typeof content !== 'string' || !content.trim())
|
|
1015
|
+
return undefined;
|
|
1016
|
+
const normalizedMode = typeof mode === 'string' ? mode : undefined;
|
|
1017
|
+
const containsScript = /<script\b/i.test(content);
|
|
1018
|
+
const containsHtml = /<[a-z][\s\S]*>/i.test(content);
|
|
1019
|
+
const contentKind = containsScript ? 'interactive_html' : containsHtml ? 'html' : 'markdown';
|
|
1020
|
+
const actions = extractTextActions(content);
|
|
1021
|
+
return pruneEmpty({
|
|
1022
|
+
mode: normalizedMode,
|
|
1023
|
+
contentKind,
|
|
1024
|
+
containsScript: containsScript || undefined,
|
|
1025
|
+
actions: actions.length ? actions : undefined,
|
|
1026
|
+
});
|
|
1027
|
+
}
|
|
866
1028
|
function extractTextActions(content) {
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
}
|
|
906
|
-
|
|
907
|
-
return actions
|
|
1029
|
+
var _a, _b;
|
|
1030
|
+
const actions = [];
|
|
1031
|
+
const seen = new Set();
|
|
1032
|
+
const anchorRegex = /<a\b[^>]*href=(['"])(.*?)\1[^>]*>([\s\S]*?)<\/a>/gi;
|
|
1033
|
+
for (const match of content.matchAll(anchorRegex)) {
|
|
1034
|
+
const url = (match[2] || '').trim();
|
|
1035
|
+
const label = stripHtmlTags(match[3] || '').trim();
|
|
1036
|
+
pushTextAction(actions, seen, {
|
|
1037
|
+
title: label || undefined,
|
|
1038
|
+
url: url || undefined,
|
|
1039
|
+
open: url === '#' ? 'curWin' : 'newWin',
|
|
1040
|
+
type: inferGuanceLinkType({ title: label, url }),
|
|
1041
|
+
show: true,
|
|
1042
|
+
showChanged: false,
|
|
1043
|
+
});
|
|
1044
|
+
}
|
|
1045
|
+
const constUrlRegex = /\bconst\s+([A-Za-z_$][A-Za-z0-9_$]*)\s*=\s*([`'"])([\s\S]*?)\2\s*;/g;
|
|
1046
|
+
const constantUrls = new Map();
|
|
1047
|
+
for (const match of content.matchAll(constUrlRegex)) {
|
|
1048
|
+
constantUrls.set(match[1], match[3]);
|
|
1049
|
+
}
|
|
1050
|
+
const windowOpenRegex = /window\.open\(\s*([A-Za-z_$][A-Za-z0-9_$]*|[`'"][\s\S]*?[`'"])\s*(?:,\s*([`'"][\s\S]*?[`'"]))?\s*\)/g;
|
|
1051
|
+
for (const match of content.matchAll(windowOpenRegex)) {
|
|
1052
|
+
const rawTarget = ((_a = match[1]) === null || _a === void 0 ? void 0 : _a.trim()) || '';
|
|
1053
|
+
const rawBlank = ((_b = match[2]) === null || _b === void 0 ? void 0 : _b.trim()) || '';
|
|
1054
|
+
const directUrl = unwrapQuoted(rawTarget);
|
|
1055
|
+
const variableUrl = constantUrls.get(rawTarget);
|
|
1056
|
+
const url = directUrl || variableUrl;
|
|
1057
|
+
pushTextAction(actions, seen, {
|
|
1058
|
+
title: inferActionTitle(content, url),
|
|
1059
|
+
url: url || undefined,
|
|
1060
|
+
open: rawBlank.includes('_blank') ? 'newWin' : 'curWin',
|
|
1061
|
+
type: inferGuanceLinkType({ title: inferActionTitle(content, url), url }),
|
|
1062
|
+
show: true,
|
|
1063
|
+
showChanged: false,
|
|
1064
|
+
});
|
|
1065
|
+
}
|
|
1066
|
+
return actions;
|
|
908
1067
|
}
|
|
909
|
-
|
|
910
1068
|
function pushTextAction(actions, seen, action) {
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
1069
|
+
const normalized = pruneEmpty(action);
|
|
1070
|
+
const key = JSON.stringify(normalized);
|
|
1071
|
+
if (!key || seen.has(key) || Object.keys(normalized).length === 0)
|
|
1072
|
+
return;
|
|
1073
|
+
seen.add(key);
|
|
1074
|
+
actions.push(normalized);
|
|
916
1075
|
}
|
|
917
|
-
|
|
918
1076
|
function inferActionTitle(content, url) {
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
1077
|
+
if (typeof url !== 'string' || !url)
|
|
1078
|
+
return undefined;
|
|
1079
|
+
if (content.includes('HotCall') || url.includes('hotcall'))
|
|
1080
|
+
return 'HotCall';
|
|
1081
|
+
if (content.includes('业务大盘'))
|
|
1082
|
+
return '业务大盘';
|
|
1083
|
+
if (content.includes('拓扑图') || content.includes('traceLink'))
|
|
1084
|
+
return '跳转观测云';
|
|
1085
|
+
return undefined;
|
|
924
1086
|
}
|
|
925
|
-
|
|
926
1087
|
function unwrapQuoted(value) {
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
}
|
|
936
|
-
|
|
1088
|
+
if (typeof value !== 'string')
|
|
1089
|
+
return '';
|
|
1090
|
+
const trimmed = value.trim();
|
|
1091
|
+
if (trimmed.length < 2)
|
|
1092
|
+
return '';
|
|
1093
|
+
const quote = trimmed[0];
|
|
1094
|
+
if ((quote === '"' || quote === "'" || quote === '`') && trimmed.at(-1) === quote) {
|
|
1095
|
+
return trimmed.slice(1, -1);
|
|
1096
|
+
}
|
|
1097
|
+
return '';
|
|
1098
|
+
}
|
|
937
1099
|
function stripHtmlTags(value) {
|
|
938
|
-
|
|
1100
|
+
return String(value).replace(/<[^>]+>/g, ' ');
|
|
939
1101
|
}
|
|
940
|
-
|
|
941
1102
|
function normalizeColumnTitle(field, renamedField) {
|
|
942
|
-
|
|
943
|
-
|
|
1103
|
+
if (typeof renamedField === 'string' && renamedField.trim())
|
|
1104
|
+
return renamedField.trim();
|
|
1105
|
+
return field;
|
|
944
1106
|
}
|
|
945
|
-
|
|
946
1107
|
function finalizeTableColumns(columns) {
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
})
|
|
971
|
-
)
|
|
972
|
-
}
|
|
973
|
-
|
|
974
|
-
return [...mergedColumns.values()].sort(
|
|
975
|
-
(left, right) => numberOr(left.order, Number.MAX_SAFE_INTEGER) - numberOr(right.order, Number.MAX_SAFE_INTEGER)
|
|
976
|
-
)
|
|
977
|
-
}
|
|
978
|
-
|
|
1108
|
+
const mergedColumns = new Map();
|
|
1109
|
+
for (const column of columns) {
|
|
1110
|
+
const key = column.title || column.field;
|
|
1111
|
+
const existing = mergedColumns.get(key);
|
|
1112
|
+
if (!existing) {
|
|
1113
|
+
mergedColumns.set(key, { ...column });
|
|
1114
|
+
continue;
|
|
1115
|
+
}
|
|
1116
|
+
mergedColumns.set(key, pruneEmpty({
|
|
1117
|
+
...existing,
|
|
1118
|
+
...column,
|
|
1119
|
+
field: existing.field || column.field,
|
|
1120
|
+
title: key,
|
|
1121
|
+
order: Math.min(numberOr(existing.order, Number.MAX_SAFE_INTEGER), numberOr(column.order, Number.MAX_SAFE_INTEGER)),
|
|
1122
|
+
width: firstDefined(existing.width, column.width),
|
|
1123
|
+
align: firstDefined(existing.align, column.align),
|
|
1124
|
+
displayMode: firstDefined(existing.displayMode, column.displayMode),
|
|
1125
|
+
links: existing.links || column.links,
|
|
1126
|
+
mappings: existing.mappings || column.mappings,
|
|
1127
|
+
}));
|
|
1128
|
+
}
|
|
1129
|
+
return [...mergedColumns.values()].sort((left, right) => numberOr(left.order, Number.MAX_SAFE_INTEGER) - numberOr(right.order, Number.MAX_SAFE_INTEGER));
|
|
1130
|
+
}
|
|
979
1131
|
function createOrganizeMaps(organize) {
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
}
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
}
|
|
998
|
-
}
|
|
999
|
-
|
|
1132
|
+
const renamedFields = (organize === null || organize === void 0 ? void 0 : organize.renameByName) || {};
|
|
1133
|
+
const excludedFields = (organize === null || organize === void 0 ? void 0 : organize.excludeByName) || {};
|
|
1134
|
+
const indexedFields = (organize === null || organize === void 0 ? void 0 : organize.indexByName) || {};
|
|
1135
|
+
const displayToRaw = {};
|
|
1136
|
+
for (const [rawField, renamedField] of Object.entries(renamedFields)) {
|
|
1137
|
+
const title = normalizeColumnTitle(rawField, renamedField);
|
|
1138
|
+
if (title && title !== rawField) {
|
|
1139
|
+
displayToRaw[title] = rawField;
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
return {
|
|
1143
|
+
renamedFields,
|
|
1144
|
+
excludedFields,
|
|
1145
|
+
indexedFields,
|
|
1146
|
+
displayToRaw,
|
|
1147
|
+
};
|
|
1148
|
+
}
|
|
1000
1149
|
function resolveRawFieldName(field, organizeMaps) {
|
|
1001
|
-
|
|
1150
|
+
return organizeMaps.displayToRaw[field] || field;
|
|
1002
1151
|
}
|
|
1003
|
-
|
|
1004
1152
|
function resolveDisplayFieldName(field, organizeMaps) {
|
|
1005
|
-
|
|
1153
|
+
return normalizeColumnTitle(field, organizeMaps.renamedFields[field]);
|
|
1006
1154
|
}
|
|
1007
|
-
|
|
1008
1155
|
function parseTransformations(transformations) {
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
pruneEmpty({
|
|
1064
|
-
type: transformation.id,
|
|
1065
|
-
options: transformation.options,
|
|
1066
|
-
})
|
|
1067
|
-
)
|
|
1068
|
-
}
|
|
1069
|
-
|
|
1070
|
-
return {
|
|
1071
|
-
organize,
|
|
1072
|
-
fieldFilterPattern,
|
|
1073
|
-
valueFilters,
|
|
1074
|
-
normalized,
|
|
1075
|
-
}
|
|
1076
|
-
}
|
|
1077
|
-
|
|
1156
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
1157
|
+
const normalized = [];
|
|
1158
|
+
let organize = null;
|
|
1159
|
+
let fieldFilterPattern = '';
|
|
1160
|
+
const valueFilters = [];
|
|
1161
|
+
for (const transformation of Array.isArray(transformations) ? transformations : []) {
|
|
1162
|
+
if (!(transformation === null || transformation === void 0 ? void 0 : transformation.id))
|
|
1163
|
+
continue;
|
|
1164
|
+
if (transformation.id === 'organize') {
|
|
1165
|
+
organize = transformation.options || {};
|
|
1166
|
+
normalized.push(pruneEmpty({
|
|
1167
|
+
type: 'organize',
|
|
1168
|
+
renameByName: organize.renameByName,
|
|
1169
|
+
excludeByName: organize.excludeByName,
|
|
1170
|
+
indexByName: organize.indexByName,
|
|
1171
|
+
}));
|
|
1172
|
+
continue;
|
|
1173
|
+
}
|
|
1174
|
+
if (transformation.id === 'filterFieldsByName') {
|
|
1175
|
+
fieldFilterPattern = ((_b = (_a = transformation.options) === null || _a === void 0 ? void 0 : _a.include) === null || _b === void 0 ? void 0 : _b.pattern) || ((_d = (_c = transformation.options) === null || _c === void 0 ? void 0 : _c.exclude) === null || _d === void 0 ? void 0 : _d.pattern) || '';
|
|
1176
|
+
normalized.push(pruneEmpty({
|
|
1177
|
+
type: 'filterFieldsByName',
|
|
1178
|
+
include: (_e = transformation.options) === null || _e === void 0 ? void 0 : _e.include,
|
|
1179
|
+
exclude: (_f = transformation.options) === null || _f === void 0 ? void 0 : _f.exclude,
|
|
1180
|
+
}));
|
|
1181
|
+
continue;
|
|
1182
|
+
}
|
|
1183
|
+
if (transformation.id === 'filterByValue') {
|
|
1184
|
+
const filters = Array.isArray((_g = transformation.options) === null || _g === void 0 ? void 0 : _g.filters) ? transformation.options.filters : [];
|
|
1185
|
+
valueFilters.push(pruneEmpty({
|
|
1186
|
+
match: ((_h = transformation.options) === null || _h === void 0 ? void 0 : _h.match) || undefined,
|
|
1187
|
+
type: ((_j = transformation.options) === null || _j === void 0 ? void 0 : _j.type) || undefined,
|
|
1188
|
+
filters,
|
|
1189
|
+
}));
|
|
1190
|
+
normalized.push(pruneEmpty({
|
|
1191
|
+
type: 'filterByValue',
|
|
1192
|
+
match: ((_k = transformation.options) === null || _k === void 0 ? void 0 : _k.match) || undefined,
|
|
1193
|
+
mode: ((_l = transformation.options) === null || _l === void 0 ? void 0 : _l.type) || undefined,
|
|
1194
|
+
filters,
|
|
1195
|
+
}));
|
|
1196
|
+
continue;
|
|
1197
|
+
}
|
|
1198
|
+
normalized.push(pruneEmpty({
|
|
1199
|
+
type: transformation.id,
|
|
1200
|
+
options: transformation.options,
|
|
1201
|
+
}));
|
|
1202
|
+
}
|
|
1203
|
+
return {
|
|
1204
|
+
organize,
|
|
1205
|
+
fieldFilterPattern,
|
|
1206
|
+
valueFilters,
|
|
1207
|
+
normalized,
|
|
1208
|
+
};
|
|
1209
|
+
}
|
|
1078
1210
|
function extractPanelLinks(panel, variableNames) {
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
(override.properties || [])
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
links
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
return links
|
|
1101
|
-
}
|
|
1102
|
-
|
|
1211
|
+
var _a, _b;
|
|
1212
|
+
const links = [];
|
|
1213
|
+
const defaults = ((_a = panel.fieldConfig) === null || _a === void 0 ? void 0 : _a.defaults) || {};
|
|
1214
|
+
const overrideLinks = Array.isArray((_b = panel.fieldConfig) === null || _b === void 0 ? void 0 : _b.overrides)
|
|
1215
|
+
? panel.fieldConfig.overrides.flatMap((override) => (override.properties || [])
|
|
1216
|
+
.filter((property) => property.id === 'links')
|
|
1217
|
+
.flatMap((property) => property.value || []))
|
|
1218
|
+
: [];
|
|
1219
|
+
const allLinks = [
|
|
1220
|
+
...(Array.isArray(panel.links) ? panel.links : []),
|
|
1221
|
+
...(Array.isArray(defaults.links) ? defaults.links : []),
|
|
1222
|
+
...overrideLinks,
|
|
1223
|
+
];
|
|
1224
|
+
for (const link of allLinks) {
|
|
1225
|
+
if (!link || !link.url)
|
|
1226
|
+
continue;
|
|
1227
|
+
links.push(normalizeGuanceLinkItem(link, variableNames));
|
|
1228
|
+
}
|
|
1229
|
+
return links;
|
|
1230
|
+
}
|
|
1103
1231
|
function normalizeGuanceLinkItem(link, variableNames = new Set()) {
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
}
|
|
1112
|
-
|
|
1232
|
+
return pruneEmpty({
|
|
1233
|
+
url: replaceVariables(link.url || '', variableNames),
|
|
1234
|
+
open: Boolean(link.targetBlank) ? 'newWin' : 'curWin',
|
|
1235
|
+
show: true,
|
|
1236
|
+
type: inferGuanceLinkType(link),
|
|
1237
|
+
showChanged: false,
|
|
1238
|
+
});
|
|
1239
|
+
}
|
|
1113
1240
|
function inferGuanceLinkType(link) {
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1241
|
+
const title = String((link === null || link === void 0 ? void 0 : link.title) || '').toLowerCase();
|
|
1242
|
+
const url = String((link === null || link === void 0 ? void 0 : link.url) || '').toLowerCase();
|
|
1243
|
+
const combined = `${title} ${url}`;
|
|
1244
|
+
if (url.includes('pipeline-log'))
|
|
1245
|
+
return 'custom';
|
|
1246
|
+
if (url.includes('/tracing/'))
|
|
1247
|
+
return 'tracing';
|
|
1248
|
+
if (url.includes('/logindi/') || url.includes('/log/') || url.includes('/logging/'))
|
|
1249
|
+
return 'logging';
|
|
1250
|
+
if (url.includes('/objectadmin/docker_containers') || url.includes('/container'))
|
|
1251
|
+
return 'container';
|
|
1252
|
+
if (url.includes('/objectadmin/host_processes') || url.includes('/process'))
|
|
1253
|
+
return 'processes';
|
|
1254
|
+
if (url.includes('/scene/builtinview/detail') || url.includes('/host'))
|
|
1255
|
+
return 'host';
|
|
1256
|
+
if (title.includes('trace') || title.includes('tracing'))
|
|
1257
|
+
return 'tracing';
|
|
1258
|
+
if (title.includes('日志'))
|
|
1259
|
+
return 'logging';
|
|
1260
|
+
return 'custom';
|
|
1261
|
+
}
|
|
1129
1262
|
function inferChartType(panel) {
|
|
1130
|
-
|
|
1263
|
+
return PANEL_TYPE_MAP[panel.type] || null;
|
|
1131
1264
|
}
|
|
1132
|
-
|
|
1133
1265
|
function inferDisplayChartType(panel, chartType) {
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1266
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1267
|
+
if (chartType === 'pie') {
|
|
1268
|
+
return ((_a = panel.options) === null || _a === void 0 ? void 0 : _a.pieType) === 'donut' ? 'donut' : 'pie';
|
|
1269
|
+
}
|
|
1270
|
+
if (chartType === 'bar')
|
|
1271
|
+
return 'bar';
|
|
1272
|
+
if (chartType === 'toplist')
|
|
1273
|
+
return 'bar';
|
|
1274
|
+
const drawStyle = (_d = (_c = (_b = panel.fieldConfig) === null || _b === void 0 ? void 0 : _b.defaults) === null || _c === void 0 ? void 0 : _c.custom) === null || _d === void 0 ? void 0 : _d.drawStyle;
|
|
1275
|
+
const fillOpacity = (_g = (_f = (_e = panel.fieldConfig) === null || _e === void 0 ? void 0 : _e.defaults) === null || _f === void 0 ? void 0 : _f.custom) === null || _g === void 0 ? void 0 : _g.fillOpacity;
|
|
1276
|
+
if (drawStyle === 'bars')
|
|
1277
|
+
return 'bar';
|
|
1278
|
+
if (fillOpacity && fillOpacity > 0)
|
|
1279
|
+
return 'areaLine';
|
|
1280
|
+
return 'line';
|
|
1281
|
+
}
|
|
1148
1282
|
function inferQueryLanguage(target, queryText) {
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1283
|
+
const datasourceType = getDatasourceType(target.datasource);
|
|
1284
|
+
// Guance datasource defaults to DQL unless the Grafana target explicitly marks the query as PromQL.
|
|
1285
|
+
if (target.qtype === 'promql')
|
|
1286
|
+
return 'promql';
|
|
1287
|
+
if (target.qtype === 'dql')
|
|
1288
|
+
return 'dql';
|
|
1289
|
+
if (datasourceType.includes('guance-guance-datasource'))
|
|
1290
|
+
return 'dql';
|
|
1291
|
+
if (isPrometheusLikeDatasource(datasourceType))
|
|
1292
|
+
return 'promql';
|
|
1293
|
+
if (isDqlLikeDatasource(datasourceType))
|
|
1294
|
+
return 'dql';
|
|
1295
|
+
if (/^\s*(with|select)\b/i.test(queryText))
|
|
1296
|
+
return 'dql';
|
|
1297
|
+
if (/^[A-Z]::/.test(queryText))
|
|
1298
|
+
return 'dql';
|
|
1299
|
+
return 'promql';
|
|
1300
|
+
}
|
|
1301
|
+
function inferVariableQueryType(variable) {
|
|
1302
|
+
var _a;
|
|
1303
|
+
const datasourceType = getDatasourceType(variable.datasource);
|
|
1304
|
+
const explicitQtype = String(((_a = variable.query) === null || _a === void 0 ? void 0 : _a.qtype) || '').toLowerCase();
|
|
1305
|
+
if (datasourceType.includes('object'))
|
|
1306
|
+
return 'FIELD';
|
|
1307
|
+
if (explicitQtype === 'promql')
|
|
1308
|
+
return 'PROMQL_QUERY';
|
|
1309
|
+
if (explicitQtype === 'dql')
|
|
1310
|
+
return 'PROMQL_QUERY';
|
|
1311
|
+
return 'PROMQL_QUERY';
|
|
1312
|
+
}
|
|
1174
1313
|
function extractVariableQuery(variable) {
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1314
|
+
if (typeof variable.query === 'string')
|
|
1315
|
+
return variable.query;
|
|
1316
|
+
if (variable.query && typeof variable.query === 'object') {
|
|
1317
|
+
return variable.query.rawQuery || variable.query.query || variable.query.expr || '';
|
|
1318
|
+
}
|
|
1319
|
+
if (typeof variable.definition === 'string')
|
|
1320
|
+
return variable.definition;
|
|
1321
|
+
return '';
|
|
1322
|
+
}
|
|
1183
1323
|
function extractTargetQuery(target) {
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1324
|
+
const candidates = [target.expr, target.query, target.queryText, target.expression, target.rawSql];
|
|
1325
|
+
for (const candidate of candidates) {
|
|
1326
|
+
if (typeof candidate === 'string' && candidate.trim())
|
|
1327
|
+
return candidate;
|
|
1328
|
+
}
|
|
1329
|
+
return '';
|
|
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;
|
|
1189
1474
|
}
|
|
1190
|
-
|
|
1191
1475
|
function extractWorkspaceInfo(targets) {
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
}
|
|
1208
|
-
|
|
1476
|
+
const workspaceUUIDs = [];
|
|
1477
|
+
const workspaceNames = [];
|
|
1478
|
+
for (const target of Array.isArray(targets) ? targets : []) {
|
|
1479
|
+
for (const item of Array.isArray(target.workspaceUUIDs) ? target.workspaceUUIDs : []) {
|
|
1480
|
+
if ((item === null || item === void 0 ? void 0 : item.value) && !workspaceUUIDs.includes(item.value))
|
|
1481
|
+
workspaceUUIDs.push(item.value);
|
|
1482
|
+
if ((item === null || item === void 0 ? void 0 : item.label) && !workspaceNames.includes(item.label))
|
|
1483
|
+
workspaceNames.push(item.label);
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
return pruneEmpty({
|
|
1487
|
+
changeWorkspace: workspaceUUIDs.length > 0,
|
|
1488
|
+
workspaceUUID: workspaceUUIDs.length ? workspaceUUIDs.join(',') : undefined,
|
|
1489
|
+
workspaceName: workspaceNames.length ? workspaceNames : undefined,
|
|
1490
|
+
});
|
|
1491
|
+
}
|
|
1209
1492
|
function normalizeTargetQuery(queryText, qtype, options = {}) {
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1493
|
+
if (qtype !== 'promql')
|
|
1494
|
+
return queryText;
|
|
1495
|
+
if (!options.guancePromqlCompatible)
|
|
1496
|
+
return queryText;
|
|
1497
|
+
return normalizePromqlForGuance(queryText);
|
|
1213
1498
|
}
|
|
1214
|
-
|
|
1215
1499
|
function extractMetricName(queryString, variableNames) {
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1500
|
+
if (/^\s*(with|select)\b/i.test(queryString))
|
|
1501
|
+
return '';
|
|
1502
|
+
const labelValuesMatch = queryString.match(/label_values\(([^,]+),\s*([^)]+)\)/i);
|
|
1503
|
+
if (labelValuesMatch)
|
|
1504
|
+
return replaceVariables(labelValuesMatch[1].trim(), variableNames);
|
|
1505
|
+
return '';
|
|
1220
1506
|
}
|
|
1221
|
-
|
|
1222
1507
|
function extractFieldName(queryString) {
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1508
|
+
const fieldValuesMatch = queryString.match(/field_values\(`?([^`)\s]+)`?\)/i);
|
|
1509
|
+
if (fieldValuesMatch)
|
|
1510
|
+
return fieldValuesMatch[1].trim();
|
|
1511
|
+
const labelValuesMatch = queryString.match(/label_values\([^,]+,\s*([^)]+)\)/i);
|
|
1512
|
+
if (labelValuesMatch)
|
|
1513
|
+
return labelValuesMatch[1].replace(/[`'"]/g, '').trim();
|
|
1514
|
+
return '';
|
|
1228
1515
|
}
|
|
1229
|
-
|
|
1230
1516
|
function normalizeTimeInterval(value) {
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1517
|
+
if (!value || typeof value !== 'string')
|
|
1518
|
+
return 'auto';
|
|
1519
|
+
const normalized = value.trim();
|
|
1520
|
+
if (!normalized)
|
|
1521
|
+
return 'auto';
|
|
1522
|
+
return normalized;
|
|
1235
1523
|
}
|
|
1236
|
-
|
|
1237
1524
|
function normalizePromqlForGuance(queryText) {
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
return result
|
|
1279
|
-
}
|
|
1280
|
-
|
|
1525
|
+
if (typeof queryText !== 'string' || !queryText.trim())
|
|
1526
|
+
return queryText;
|
|
1527
|
+
let result = '';
|
|
1528
|
+
let index = 0;
|
|
1529
|
+
let braceDepth = 0;
|
|
1530
|
+
while (index < queryText.length) {
|
|
1531
|
+
const current = queryText[index];
|
|
1532
|
+
if (current === '{') {
|
|
1533
|
+
braceDepth++;
|
|
1534
|
+
result += current;
|
|
1535
|
+
index++;
|
|
1536
|
+
continue;
|
|
1537
|
+
}
|
|
1538
|
+
if (current === '}') {
|
|
1539
|
+
braceDepth = Math.max(0, braceDepth - 1);
|
|
1540
|
+
result += current;
|
|
1541
|
+
index++;
|
|
1542
|
+
continue;
|
|
1543
|
+
}
|
|
1544
|
+
if (braceDepth === 0 && /[A-Za-z_:]/.test(current)) {
|
|
1545
|
+
let end = index + 1;
|
|
1546
|
+
while (end < queryText.length && /[A-Za-z0-9_:]/.test(queryText[end]))
|
|
1547
|
+
end++;
|
|
1548
|
+
const token = queryText.slice(index, end);
|
|
1549
|
+
let lookahead = end;
|
|
1550
|
+
while (lookahead < queryText.length && /\s/.test(queryText[lookahead]))
|
|
1551
|
+
lookahead++;
|
|
1552
|
+
const next = queryText[lookahead];
|
|
1553
|
+
if (next === '{' || next === '[') {
|
|
1554
|
+
result += toGuancePromqlMetricName(token);
|
|
1555
|
+
index = end;
|
|
1556
|
+
continue;
|
|
1557
|
+
}
|
|
1558
|
+
}
|
|
1559
|
+
result += current;
|
|
1560
|
+
index++;
|
|
1561
|
+
}
|
|
1562
|
+
return result;
|
|
1563
|
+
}
|
|
1281
1564
|
function inferUnitFromQueries(queries, chartType) {
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
}
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
return bestUnit
|
|
1307
|
-
}
|
|
1308
|
-
|
|
1565
|
+
if (!Array.isArray(queries) || queries.length === 0)
|
|
1566
|
+
return undefined;
|
|
1567
|
+
if (['text', 'table', 'topology', 'iframe', 'picture', 'video'].includes(chartType))
|
|
1568
|
+
return undefined;
|
|
1569
|
+
const inferredUnits = queries
|
|
1570
|
+
.map((query) => { var _a; return inferUnitFromQueryText(((_a = query === null || query === void 0 ? void 0 : query.query) === null || _a === void 0 ? void 0 : _a.q) || ''); })
|
|
1571
|
+
.filter(Boolean);
|
|
1572
|
+
if (inferredUnits.length === 0)
|
|
1573
|
+
return undefined;
|
|
1574
|
+
const counts = new Map();
|
|
1575
|
+
for (const unit of inferredUnits) {
|
|
1576
|
+
counts.set(unit, (counts.get(unit) || 0) + 1);
|
|
1577
|
+
}
|
|
1578
|
+
let bestUnit = inferredUnits[0];
|
|
1579
|
+
let bestCount = counts.get(bestUnit) || 0;
|
|
1580
|
+
for (const unit of inferredUnits) {
|
|
1581
|
+
const currentCount = counts.get(unit) || 0;
|
|
1582
|
+
if (currentCount > bestCount) {
|
|
1583
|
+
bestUnit = unit;
|
|
1584
|
+
bestCount = currentCount;
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
return bestUnit;
|
|
1588
|
+
}
|
|
1309
1589
|
function inferCompareSettings(queries, chartType) {
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
}
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
return {
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
compareChartType: chartType,
|
|
1335
|
-
}
|
|
1336
|
-
}
|
|
1337
|
-
|
|
1590
|
+
var _a;
|
|
1591
|
+
if (!Array.isArray(queries) || queries.length === 0) {
|
|
1592
|
+
return { compares: undefined, compareType: undefined, openCompare: undefined, compareChartType: undefined };
|
|
1593
|
+
}
|
|
1594
|
+
if (!['sequence', 'singlestat'].includes(chartType)) {
|
|
1595
|
+
return { compares: undefined, compareType: undefined, openCompare: undefined, compareChartType: undefined };
|
|
1596
|
+
}
|
|
1597
|
+
const compareTypes = [];
|
|
1598
|
+
for (const query of queries) {
|
|
1599
|
+
const compareType = inferCompareTypeFromQuery(((_a = query === null || query === void 0 ? void 0 : query.query) === null || _a === void 0 ? void 0 : _a.q) || '');
|
|
1600
|
+
if (compareType && !compareTypes.includes(compareType)) {
|
|
1601
|
+
compareTypes.push(compareType);
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
if (compareTypes.length === 0) {
|
|
1605
|
+
return { compares: undefined, compareType: undefined, openCompare: undefined, compareChartType: undefined };
|
|
1606
|
+
}
|
|
1607
|
+
return {
|
|
1608
|
+
compares: compareTypes.map((type) => COMPARE_OPTIONS[type]).filter(Boolean),
|
|
1609
|
+
compareType: compareTypes,
|
|
1610
|
+
openCompare: true,
|
|
1611
|
+
compareChartType: chartType,
|
|
1612
|
+
};
|
|
1613
|
+
}
|
|
1338
1614
|
function inferCompareTypeFromQuery(queryText) {
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1615
|
+
if (typeof queryText !== 'string' || !queryText.trim())
|
|
1616
|
+
return undefined;
|
|
1617
|
+
const normalized = queryText.toLowerCase();
|
|
1618
|
+
if (/\boffset\s+1h\b/.test(normalized))
|
|
1619
|
+
return 'hourCompare';
|
|
1620
|
+
if (/\boffset\s+1d\b/.test(normalized))
|
|
1621
|
+
return 'dayCompare';
|
|
1622
|
+
if (/\boffset\s+(7d|1w)\b/.test(normalized))
|
|
1623
|
+
return 'weekCompare';
|
|
1624
|
+
if (/\boffset\s+(30d|4w)\b/.test(normalized))
|
|
1625
|
+
return 'monthCompare';
|
|
1626
|
+
return undefined;
|
|
1627
|
+
}
|
|
1350
1628
|
function inferSortSettings(chartType, legend, tableSortBy) {
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
}
|
|
1359
|
-
|
|
1629
|
+
const sequenceSort = inferSequenceSortOrder(legend);
|
|
1630
|
+
const mainMeasurementSort = inferMainMeasurementSort(chartType, legend, tableSortBy);
|
|
1631
|
+
return {
|
|
1632
|
+
sorderByOrder: sequenceSort,
|
|
1633
|
+
mainMeasurementSort,
|
|
1634
|
+
};
|
|
1635
|
+
}
|
|
1360
1636
|
function inferSeriesLimit(queries, options, chartType) {
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
return undefined
|
|
1371
|
-
}
|
|
1372
|
-
|
|
1637
|
+
const explicitLimit = extractReduceLimit(options);
|
|
1638
|
+
if (['pie', 'toplist', 'treemap'].includes(chartType)) {
|
|
1639
|
+
return extractTopkLimit(queries) || explicitLimit;
|
|
1640
|
+
}
|
|
1641
|
+
if (['sequence', 'table'].includes(chartType)) {
|
|
1642
|
+
return extractTopkLimit(queries) || undefined;
|
|
1643
|
+
}
|
|
1644
|
+
return undefined;
|
|
1645
|
+
}
|
|
1373
1646
|
function extractTopkLimit(queries) {
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
const
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
}
|
|
1386
|
-
|
|
1647
|
+
var _a;
|
|
1648
|
+
if (!Array.isArray(queries))
|
|
1649
|
+
return undefined;
|
|
1650
|
+
for (const query of queries) {
|
|
1651
|
+
const queryText = String(((_a = query === null || query === void 0 ? void 0 : query.query) === null || _a === void 0 ? void 0 : _a.q) || '');
|
|
1652
|
+
const match = queryText.match(/\btopk\s*\(\s*(\d+)/i);
|
|
1653
|
+
if (!match)
|
|
1654
|
+
continue;
|
|
1655
|
+
const limit = Number(match[1]);
|
|
1656
|
+
if (Number.isFinite(limit))
|
|
1657
|
+
return limit;
|
|
1658
|
+
}
|
|
1659
|
+
return undefined;
|
|
1660
|
+
}
|
|
1387
1661
|
function inferSequenceSortOrder(legend) {
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1662
|
+
if (typeof (legend === null || legend === void 0 ? void 0 : legend.sortDesc) === 'boolean') {
|
|
1663
|
+
return legend.sortDesc ? 'desc' : 'asc';
|
|
1664
|
+
}
|
|
1665
|
+
return undefined;
|
|
1392
1666
|
}
|
|
1393
|
-
|
|
1394
1667
|
function inferMainMeasurementSort(chartType, legend, tableSortBy) {
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
return undefined
|
|
1409
|
-
}
|
|
1410
|
-
|
|
1668
|
+
if (!['pie', 'toplist', 'table', 'treemap'].includes(chartType))
|
|
1669
|
+
return undefined;
|
|
1670
|
+
if (chartType === 'table') {
|
|
1671
|
+
const primarySort = Array.isArray(tableSortBy) ? tableSortBy[0] : undefined;
|
|
1672
|
+
if (primarySort && typeof primarySort.desc === 'boolean') {
|
|
1673
|
+
return primarySort.desc ? 'top' : 'bottom';
|
|
1674
|
+
}
|
|
1675
|
+
}
|
|
1676
|
+
if (typeof (legend === null || legend === void 0 ? void 0 : legend.sortDesc) === 'boolean') {
|
|
1677
|
+
return legend.sortDesc ? 'top' : 'bottom';
|
|
1678
|
+
}
|
|
1679
|
+
return undefined;
|
|
1680
|
+
}
|
|
1411
1681
|
function inferUnitFromQueryText(queryText) {
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
return 's'
|
|
1460
|
-
}
|
|
1461
|
-
|
|
1462
|
-
if (
|
|
1463
|
-
/\bqps\b|\brps\b|reqps|requests?_per_second|interface_qps|host_qps|requests?_total/.test(normalized) && isRateLike
|
|
1464
|
-
) {
|
|
1465
|
-
return 'reqps'
|
|
1466
|
-
}
|
|
1467
|
-
|
|
1468
|
-
if (
|
|
1469
|
-
/\btps\b|\biops\b|\bops\b|operations?_per_second|ops_total/.test(normalized) && isRateLike
|
|
1470
|
-
) {
|
|
1471
|
-
return 'ops'
|
|
1472
|
-
}
|
|
1473
|
-
|
|
1474
|
-
if (
|
|
1475
|
-
/cpu:load\d+s|load5s|load1s|load15s|system_load/.test(normalized)
|
|
1476
|
-
) {
|
|
1477
|
-
return 'short'
|
|
1478
|
-
}
|
|
1479
|
-
|
|
1480
|
-
if (
|
|
1481
|
-
!isRateLike &&
|
|
1482
|
-
/goroutines?|threads?|connections?|conn_count|fd|file_descriptors?|queue(_size|_depth)?|pool(_size)?|inflight|pending|blocked|active_requests|jvm_.*_count|_count\b|_total\b|count_over_time\(/.test(normalized)
|
|
1483
|
-
) {
|
|
1484
|
-
return 'none'
|
|
1485
|
-
}
|
|
1486
|
-
|
|
1487
|
-
if (
|
|
1488
|
-
/_seconds\b/.test(normalized) && !/rate\(|increase\(|irate\(/.test(normalized)
|
|
1489
|
-
) {
|
|
1490
|
-
return 's'
|
|
1491
|
-
}
|
|
1492
|
-
|
|
1493
|
-
return undefined
|
|
1494
|
-
}
|
|
1495
|
-
|
|
1682
|
+
if (typeof queryText !== 'string' || !queryText.trim())
|
|
1683
|
+
return undefined;
|
|
1684
|
+
const normalized = queryText.toLowerCase();
|
|
1685
|
+
const isRateLike = /rate\(|irate\(|increase\(|delta\(|deriv\(/.test(normalized);
|
|
1686
|
+
if (/cpu.*(?:usage|utili[sz]ation|used)|cpu_usage|cpu_used|usage_seconds_total/.test(normalized) &&
|
|
1687
|
+
/limit|quota|max|capacity|total|cores?|100/.test(normalized)) {
|
|
1688
|
+
return 'percent';
|
|
1689
|
+
}
|
|
1690
|
+
if (/memory.*(?:usage|used|utili[sz]ation)|heap.*used|rss|working_set|used_bytes|usage_bytes/.test(normalized)) {
|
|
1691
|
+
return 'bytes';
|
|
1692
|
+
}
|
|
1693
|
+
if (/disk.*(?:usage|used|utili[sz]ation)|filesystem.*(?:avail|free|size|used)|storage.*(?:used|usage)/.test(normalized)) {
|
|
1694
|
+
return 'bytes';
|
|
1695
|
+
}
|
|
1696
|
+
if (/error_rate|success_rate|failure_rate|biz_error_rate|_ratio\b|_percent\b|percent/.test(normalized) ||
|
|
1697
|
+
/container_cpu_usage_seconds_total/.test(normalized) && /kube_pod_container_resource_limits/.test(normalized) ||
|
|
1698
|
+
/\*\s*100\b/.test(normalized)) {
|
|
1699
|
+
return 'percent';
|
|
1700
|
+
}
|
|
1701
|
+
if (/p99|p95|p90|latency|duration|response_time|cost\b|elapsed|load_time|_ms\b|milliseconds?/.test(normalized) ||
|
|
1702
|
+
/performance_host_interface_p\d+/.test(normalized)) {
|
|
1703
|
+
return 'ms';
|
|
1704
|
+
}
|
|
1705
|
+
if (/_bytes\b|_bytes_total\b|memory|heap|rss|bandwidth|byte\b/.test(normalized)) {
|
|
1706
|
+
return 'bytes';
|
|
1707
|
+
}
|
|
1708
|
+
if (/gc_pause_seconds|gc.*(?:pause|time)|duration_seconds|latency_seconds|response_seconds/.test(normalized)) {
|
|
1709
|
+
return 's';
|
|
1710
|
+
}
|
|
1711
|
+
if (/\bqps\b|\brps\b|reqps|requests?_per_second|interface_qps|host_qps|requests?_total/.test(normalized) && isRateLike) {
|
|
1712
|
+
return 'reqps';
|
|
1713
|
+
}
|
|
1714
|
+
if (/\btps\b|\biops\b|\bops\b|operations?_per_second|ops_total/.test(normalized) && isRateLike) {
|
|
1715
|
+
return 'ops';
|
|
1716
|
+
}
|
|
1717
|
+
if (/cpu:load\d+s|load5s|load1s|load15s|system_load/.test(normalized)) {
|
|
1718
|
+
return 'short';
|
|
1719
|
+
}
|
|
1720
|
+
if (!isRateLike &&
|
|
1721
|
+
/goroutines?|threads?|connections?|conn_count|fd|file_descriptors?|queue(_size|_depth)?|pool(_size)?|inflight|pending|blocked|active_requests|jvm_.*_count|_count\b|_total\b|count_over_time\(/.test(normalized)) {
|
|
1722
|
+
return 'none';
|
|
1723
|
+
}
|
|
1724
|
+
if (/_seconds\b/.test(normalized) && !/rate\(|increase\(|irate\(/.test(normalized)) {
|
|
1725
|
+
return 's';
|
|
1726
|
+
}
|
|
1727
|
+
return undefined;
|
|
1728
|
+
}
|
|
1496
1729
|
function toGuancePromqlMetricName(token) {
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1730
|
+
if (!token)
|
|
1731
|
+
return token;
|
|
1732
|
+
if (token.includes(':'))
|
|
1733
|
+
return token;
|
|
1734
|
+
if (!token.includes('_'))
|
|
1735
|
+
return token;
|
|
1736
|
+
if (token.startsWith('__'))
|
|
1737
|
+
return token;
|
|
1738
|
+
if (PROMQL_RESERVED_WORDS.has(token))
|
|
1739
|
+
return token;
|
|
1740
|
+
const firstUnderscore = token.indexOf('_');
|
|
1741
|
+
if (firstUnderscore <= 0 || firstUnderscore === token.length - 1)
|
|
1742
|
+
return token;
|
|
1743
|
+
return `${token.slice(0, firstUnderscore)}:${token.slice(firstUnderscore + 1)}`;
|
|
1744
|
+
}
|
|
1507
1745
|
function getDatasourceType(datasource) {
|
|
1508
|
-
|
|
1746
|
+
return String((datasource === null || datasource === void 0 ? void 0 : datasource.type) || datasource || '').toLowerCase();
|
|
1509
1747
|
}
|
|
1510
|
-
|
|
1511
1748
|
function isPrometheusLikeDatasource(datasourceType) {
|
|
1512
|
-
|
|
1749
|
+
return datasourceType.includes('prometheus') || datasourceType.includes('guance-guance-datasource');
|
|
1513
1750
|
}
|
|
1514
|
-
|
|
1515
1751
|
function isDqlLikeDatasource(datasourceType) {
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
)
|
|
1530
|
-
}
|
|
1531
|
-
|
|
1752
|
+
return (datasourceType.includes('mysql') ||
|
|
1753
|
+
datasourceType.includes('postgres') ||
|
|
1754
|
+
datasourceType.includes('mssql') ||
|
|
1755
|
+
datasourceType.includes('sql') ||
|
|
1756
|
+
datasourceType.includes('loki') ||
|
|
1757
|
+
datasourceType.includes('elasticsearch') ||
|
|
1758
|
+
datasourceType.includes('opensearch') ||
|
|
1759
|
+
datasourceType.includes('cloudwatch') ||
|
|
1760
|
+
datasourceType.includes('influx') ||
|
|
1761
|
+
datasourceType.includes('tempo') ||
|
|
1762
|
+
datasourceType.includes('jaeger') ||
|
|
1763
|
+
datasourceType.includes('zipkin'));
|
|
1764
|
+
}
|
|
1532
1765
|
function extractReduceLimit(options) {
|
|
1533
|
-
|
|
1534
|
-
|
|
1766
|
+
var _a;
|
|
1767
|
+
const limit = (_a = options.reduceOptions) === null || _a === void 0 ? void 0 : _a.limit;
|
|
1768
|
+
return typeof limit === 'number' ? limit : 10;
|
|
1535
1769
|
}
|
|
1536
|
-
|
|
1537
1770
|
function extractCustomOptions(options) {
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1771
|
+
if (!Array.isArray(options))
|
|
1772
|
+
return '';
|
|
1773
|
+
return options
|
|
1774
|
+
.filter((item) => item && item.value !== '$__all')
|
|
1775
|
+
.map((item) => item.text || item.value || '')
|
|
1776
|
+
.filter(Boolean)
|
|
1777
|
+
.join(',');
|
|
1778
|
+
}
|
|
1546
1779
|
function mapLegendPlacement(value) {
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1780
|
+
if (value === 'bottom')
|
|
1781
|
+
return 'bottom';
|
|
1782
|
+
if (value === 'right')
|
|
1783
|
+
return 'right';
|
|
1784
|
+
if (value === 'left')
|
|
1785
|
+
return 'left';
|
|
1786
|
+
if (value === 'top')
|
|
1787
|
+
return 'top';
|
|
1788
|
+
return 'none';
|
|
1552
1789
|
}
|
|
1553
|
-
|
|
1554
1790
|
function mapLegendCalcs(values) {
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1791
|
+
if (!Array.isArray(values))
|
|
1792
|
+
return [];
|
|
1793
|
+
const allowed = new Set(['first', 'last', 'avg', 'min', 'max', 'sum', 'count']);
|
|
1794
|
+
return values
|
|
1795
|
+
.map((value) => String(value).toLowerCase())
|
|
1796
|
+
.filter((value) => allowed.has(value));
|
|
1560
1797
|
}
|
|
1561
|
-
|
|
1562
1798
|
function extractLegacyLegendCalcs(legend) {
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1799
|
+
if (!legend || typeof legend !== 'object')
|
|
1800
|
+
return [];
|
|
1801
|
+
const calcs = [];
|
|
1802
|
+
if (legend.current)
|
|
1803
|
+
calcs.push('last');
|
|
1804
|
+
if (legend.avg)
|
|
1805
|
+
calcs.push('avg');
|
|
1806
|
+
if (legend.min)
|
|
1807
|
+
calcs.push('min');
|
|
1808
|
+
if (legend.max)
|
|
1809
|
+
calcs.push('max');
|
|
1810
|
+
if (legend.total)
|
|
1811
|
+
calcs.push('sum');
|
|
1812
|
+
return calcs;
|
|
1813
|
+
}
|
|
1573
1814
|
function mapLineInterpolation(value) {
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1815
|
+
if (value === 'smooth')
|
|
1816
|
+
return 'smooth';
|
|
1817
|
+
if (value === 'stepAfter')
|
|
1818
|
+
return 'stepAfter';
|
|
1819
|
+
if (value === 'stepBefore')
|
|
1820
|
+
return 'stepBefore';
|
|
1821
|
+
return 'linear';
|
|
1578
1822
|
}
|
|
1579
|
-
|
|
1580
1823
|
function mapStackType(value) {
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1824
|
+
if (value === 'percent')
|
|
1825
|
+
return 'percent';
|
|
1826
|
+
if (value === 'normal')
|
|
1827
|
+
return 'time';
|
|
1828
|
+
return 'time';
|
|
1584
1829
|
}
|
|
1585
|
-
|
|
1586
1830
|
function inferShowLine(panel, custom) {
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1831
|
+
if (typeof panel.lines === 'boolean')
|
|
1832
|
+
return panel.lines;
|
|
1833
|
+
if (custom.drawStyle === 'bars')
|
|
1834
|
+
return false;
|
|
1835
|
+
return true;
|
|
1590
1836
|
}
|
|
1591
|
-
|
|
1592
1837
|
function inferOpenStack(panel, custom) {
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1838
|
+
var _a;
|
|
1839
|
+
if ((_a = custom.stacking) === null || _a === void 0 ? void 0 : _a.mode)
|
|
1840
|
+
return custom.stacking.mode !== 'none';
|
|
1841
|
+
if (typeof panel.stack === 'boolean')
|
|
1842
|
+
return panel.stack;
|
|
1843
|
+
return undefined;
|
|
1596
1844
|
}
|
|
1597
|
-
|
|
1598
1845
|
function inferSequenceChartType(panel, graphMode) {
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1846
|
+
if (graphMode === 'area')
|
|
1847
|
+
return 'line';
|
|
1848
|
+
if (graphMode === 'none')
|
|
1849
|
+
return undefined;
|
|
1850
|
+
return inferDisplayChartType(panel, 'sequence') === 'bar' ? 'bar' : 'line';
|
|
1602
1851
|
}
|
|
1603
|
-
|
|
1604
1852
|
function inferGaugeMode(panel, options, legacyGauge) {
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1853
|
+
if (panel.type === 'gauge')
|
|
1854
|
+
return 'gauge';
|
|
1855
|
+
if (legacyGauge.show)
|
|
1856
|
+
return 'gauge';
|
|
1857
|
+
if (options.graphMode === 'none')
|
|
1858
|
+
return 'value';
|
|
1859
|
+
return 'value';
|
|
1609
1860
|
}
|
|
1610
|
-
|
|
1611
1861
|
function normalizeConnectNulls(value) {
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1862
|
+
if (typeof value === 'boolean')
|
|
1863
|
+
return value;
|
|
1864
|
+
if (typeof value === 'number')
|
|
1865
|
+
return value > 0;
|
|
1866
|
+
if (value === 'connected')
|
|
1867
|
+
return true;
|
|
1868
|
+
if (value === 'null' || value === 'null as zero')
|
|
1869
|
+
return false;
|
|
1870
|
+
return undefined;
|
|
1617
1871
|
}
|
|
1618
|
-
|
|
1619
1872
|
function mapUnit(unit) {
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1873
|
+
if (!unit)
|
|
1874
|
+
return [];
|
|
1875
|
+
const rawUnit = String(unit);
|
|
1876
|
+
const mapped = UNIT_MAP[rawUnit] || UNIT_MAP[rawUnit.toLowerCase()];
|
|
1877
|
+
if (mapped)
|
|
1878
|
+
return mapped;
|
|
1879
|
+
return ['custom', rawUnit];
|
|
1624
1880
|
}
|
|
1625
|
-
|
|
1626
1881
|
function buildLegacyValueMappings(valueMaps) {
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
}
|
|
1636
|
-
|
|
1882
|
+
if (!Array.isArray(valueMaps))
|
|
1883
|
+
return [];
|
|
1884
|
+
return valueMaps
|
|
1885
|
+
.filter((item) => item && Object.prototype.hasOwnProperty.call(item, 'value'))
|
|
1886
|
+
.map((item) => ({
|
|
1887
|
+
originalVal: [String(item.value)],
|
|
1888
|
+
operation: normalizeLegacyMappingOperation(item.op),
|
|
1889
|
+
mappingVal: item.text || String(item.value),
|
|
1890
|
+
}));
|
|
1891
|
+
}
|
|
1637
1892
|
function buildLegacyRangeMappings(rangeMaps) {
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1893
|
+
if (!Array.isArray(rangeMaps))
|
|
1894
|
+
return [];
|
|
1895
|
+
return rangeMaps.map((item) => {
|
|
1896
|
+
var _a, _b;
|
|
1897
|
+
return ({
|
|
1898
|
+
originalVal: [String((_a = item.from) !== null && _a !== void 0 ? _a : ''), String((_b = item.to) !== null && _b !== void 0 ? _b : '')],
|
|
1899
|
+
operation: 'between',
|
|
1900
|
+
mappingVal: item.text || '',
|
|
1901
|
+
});
|
|
1902
|
+
});
|
|
1903
|
+
}
|
|
1646
1904
|
function normalizeLegacyMappingOperation(value) {
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1905
|
+
const allowed = new Set(['>', '>=', '<', '<=', '=', '!=', 'between', '=~', '!=~', 'nodata']);
|
|
1906
|
+
if (allowed.has(value))
|
|
1907
|
+
return value;
|
|
1908
|
+
return '=';
|
|
1650
1909
|
}
|
|
1651
|
-
|
|
1652
1910
|
function normalizeLegacyFill(value) {
|
|
1653
|
-
|
|
1654
|
-
|
|
1911
|
+
if (typeof value !== 'number')
|
|
1912
|
+
return undefined;
|
|
1913
|
+
return Math.max(0, Math.min(100, value * 10));
|
|
1655
1914
|
}
|
|
1656
|
-
|
|
1657
1915
|
function firstDefinedNumber(...values) {
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1916
|
+
for (const value of values) {
|
|
1917
|
+
if (typeof value === 'number' && Number.isFinite(value))
|
|
1918
|
+
return value;
|
|
1919
|
+
}
|
|
1920
|
+
return undefined;
|
|
1662
1921
|
}
|
|
1663
|
-
|
|
1664
1922
|
function replaceVariables(input, variableNames = new Set()) {
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
return `${prefix}#{${variable}}`
|
|
1923
|
+
if (typeof input !== 'string')
|
|
1924
|
+
return input;
|
|
1925
|
+
return input
|
|
1926
|
+
.replace(/\$\{([^}]+)\}/g, (match, expression) => {
|
|
1927
|
+
const variable = normalizeTemplateVariable(expression);
|
|
1928
|
+
if (!variable)
|
|
1929
|
+
return match;
|
|
1930
|
+
if (GRAFANA_BUILTIN_VARS.has(variable))
|
|
1931
|
+
return match;
|
|
1932
|
+
if (!variableNames.has(variable))
|
|
1933
|
+
return match;
|
|
1934
|
+
return `#{${variable}}`;
|
|
1678
1935
|
})
|
|
1936
|
+
.replace(/(^|[^{])\$([A-Za-z0-9_]+)/g, (match, prefix, variable) => {
|
|
1937
|
+
if (GRAFANA_BUILTIN_VARS.has(variable))
|
|
1938
|
+
return match;
|
|
1939
|
+
if (!variableNames.has(variable))
|
|
1940
|
+
return match;
|
|
1941
|
+
return `${prefix}#{${variable}}`;
|
|
1942
|
+
});
|
|
1679
1943
|
}
|
|
1680
|
-
|
|
1681
1944
|
function normalizeTemplateVariable(expression) {
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1945
|
+
const trimmed = String(expression).trim();
|
|
1946
|
+
if (!trimmed)
|
|
1947
|
+
return '';
|
|
1948
|
+
const beforeFormat = trimmed.split(':')[0];
|
|
1949
|
+
if (!/^[A-Za-z0-9_.]+$/.test(beforeFormat))
|
|
1950
|
+
return '';
|
|
1951
|
+
return beforeFormat;
|
|
1952
|
+
}
|
|
1953
|
+
function normalizeVariableIdentifier(value) {
|
|
1954
|
+
return String(value || '').trim().toLowerCase();
|
|
1687
1955
|
}
|
|
1688
|
-
|
|
1689
1956
|
function normalizeQueryCode(refId, index) {
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1957
|
+
if (typeof refId === 'string' && refId.trim())
|
|
1958
|
+
return refId.trim();
|
|
1959
|
+
const codePoint = 65 + index;
|
|
1960
|
+
return String.fromCharCode(codePoint);
|
|
1693
1961
|
}
|
|
1694
|
-
|
|
1695
1962
|
function stringifyCurrent(value) {
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1963
|
+
if (Array.isArray(value))
|
|
1964
|
+
return value.join(',');
|
|
1965
|
+
if (typeof value === 'string')
|
|
1966
|
+
return value;
|
|
1967
|
+
if (typeof value === 'number' || typeof value === 'boolean')
|
|
1968
|
+
return String(value);
|
|
1969
|
+
return '';
|
|
1700
1970
|
}
|
|
1701
|
-
|
|
1702
1971
|
function normalizeAllValue(value, allValue, isValue = false) {
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1972
|
+
if (value === 'All')
|
|
1973
|
+
return allValue === '.*' ? '*' : 'all values';
|
|
1974
|
+
if (value === '$__all')
|
|
1975
|
+
return allValue === '.*' ? '*' : '__all__';
|
|
1976
|
+
if (isValue && value === '.*')
|
|
1977
|
+
return '*';
|
|
1978
|
+
return value;
|
|
1707
1979
|
}
|
|
1708
|
-
|
|
1709
1980
|
function normalizeColor(color) {
|
|
1710
|
-
|
|
1711
|
-
|
|
1981
|
+
if (!color)
|
|
1982
|
+
return '#999999';
|
|
1983
|
+
return String(color);
|
|
1712
1984
|
}
|
|
1713
|
-
|
|
1714
1985
|
function numberOr(value, fallback) {
|
|
1715
|
-
|
|
1986
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : fallback;
|
|
1716
1987
|
}
|
|
1717
|
-
|
|
1718
1988
|
function numberOrUndefined(value) {
|
|
1719
|
-
|
|
1989
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
|
|
1720
1990
|
}
|
|
1721
|
-
|
|
1722
1991
|
function round1(value) {
|
|
1723
|
-
|
|
1992
|
+
return Number(value.toFixed(1));
|
|
1724
1993
|
}
|
|
1725
|
-
|
|
1726
1994
|
function firstDefined(...values) {
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1995
|
+
for (const value of values) {
|
|
1996
|
+
if (value !== undefined && value !== null && value !== '')
|
|
1997
|
+
return value;
|
|
1998
|
+
}
|
|
1999
|
+
return undefined;
|
|
1731
2000
|
}
|
|
1732
|
-
|
|
1733
2001
|
function pruneEmpty(value) {
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
})
|
|
1753
|
-
|
|
1754
|
-
return Object.fromEntries(entries)
|
|
2002
|
+
if (Array.isArray(value)) {
|
|
2003
|
+
return value
|
|
2004
|
+
.map((item) => pruneEmpty(item))
|
|
2005
|
+
.filter((item) => item !== undefined);
|
|
2006
|
+
}
|
|
2007
|
+
if (!value || typeof value !== 'object') {
|
|
2008
|
+
return value;
|
|
2009
|
+
}
|
|
2010
|
+
const entries = Object.entries(value)
|
|
2011
|
+
.map(([key, current]) => [key, pruneEmpty(current)])
|
|
2012
|
+
.filter(([, current]) => {
|
|
2013
|
+
if (current === undefined)
|
|
2014
|
+
return false;
|
|
2015
|
+
if (Array.isArray(current) && current.length === 0)
|
|
2016
|
+
return false;
|
|
2017
|
+
if (current && typeof current === 'object' && !Array.isArray(current) && Object.keys(current).length === 0)
|
|
2018
|
+
return false;
|
|
2019
|
+
return true;
|
|
2020
|
+
});
|
|
2021
|
+
return Object.fromEntries(entries);
|
|
1755
2022
|
}
|
|
1756
|
-
|
|
1757
2023
|
function readJson(filePath) {
|
|
1758
|
-
|
|
2024
|
+
return JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
|
1759
2025
|
}
|
|
1760
|
-
|
|
1761
2026
|
function forEachFile(directoryPath, callback) {
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
2027
|
+
for (const entry of fs.readdirSync(directoryPath, { withFileTypes: true })) {
|
|
2028
|
+
const entryPath = path.join(directoryPath, entry.name);
|
|
2029
|
+
if (entry.isDirectory()) {
|
|
2030
|
+
forEachFile(entryPath, callback);
|
|
2031
|
+
}
|
|
2032
|
+
else {
|
|
2033
|
+
callback(entryPath);
|
|
2034
|
+
}
|
|
2035
|
+
}
|
|
1770
2036
|
}
|