@cloudcare/guance-front-tools 1.0.12 → 1.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/guance-all-charts.json +3415 -0
  2. package/lib/cjs/generated/dashboardCharts.d.ts +54 -13
  3. package/lib/cjs/scripts/grafana-covert-to-guance-core.d.ts +1 -1
  4. package/lib/cjs/scripts/grafana-covert-to-guance-core.js +5 -289
  5. package/lib/esm/generated/dashboardCharts.d.ts +54 -13
  6. package/lib/esm/scripts/grafana-covert-to-guance-core.d.ts +1 -1
  7. package/lib/esm/scripts/grafana-covert-to-guance-core.js +5 -289
  8. package/lib/example/grafana2.json +878 -0
  9. package/lib/example/guance-dahs-3.json +348 -0
  10. package/lib/scripts/grafana-covert-to-guance-core.js +5 -286
  11. package/lib/scripts/grafana-covert-to-guance-core.ts +12 -326
  12. package/lib/scripts/grafana-covert-to-guance.js +52 -29
  13. package/lib/scripts/grafana-covert-to-guance.ts +60 -32
  14. package/package.json +4 -3
  15. package/schemas/charts/chart-schema.json +8 -5
  16. package/schemas/charts/common/chart-link-item-schema.json +48 -0
  17. package/schemas/charts/common/chart-links-schema.json +9 -0
  18. package/schemas/charts/common/common-chart-types-schema.json +3 -1
  19. package/schemas/charts/dashboard-schema.json +11 -4
  20. package/schemas/charts/query/query-item-schema.json +19 -1
  21. package/schemas/charts/settings/settings-time-schema.json +1 -5
  22. package/schemas/charts/settings/settings-unit-items-schema.json +3 -1
  23. package/schemas/charts/settings/settings-units-schema.json +2 -3
  24. package/scripts/validate-file.mjs +57 -0
  25. package/skills/grafana-to-guance-dashboard/SKILL.md +102 -0
  26. package/skills/grafana-to-guance-dashboard/agents/openai.yaml +4 -0
  27. package/skills/grafana-to-guance-dashboard/references/converter-notes.md +134 -0
  28. package/skills/grafana-to-guance-dashboard/scripts/convert-grafana-dashboard.mjs +1899 -0
  29. package/test/cli.test.mjs +316 -0
  30. package/test-output/grafana2.cli.guance.json +1029 -0
  31. package/test-output/grafana2.guance.json +1029 -0
  32. package/test-output/grafana2.keep-meta.guance.json +1384 -0
  33. package/test-output/pod.guance.json +2153 -0
  34. package/test-output/skill-test2-enhanced.guance.json +21596 -0
  35. package/test-output/skill-test2-validated.guance.json +11610 -0
  36. package/test-output/skill-test2.guance.json +11610 -0
  37. package/test-output/test.guance.json +1086 -0
  38. package/test-output/test2.guance.guance-promql.json +23212 -0
  39. package/test-output/test2.guance.json +17554 -0
@@ -5,6 +5,10 @@
5
5
  * 图表视图变量列表结构
6
6
  */
7
7
  export type ChartVarsSettings = ChartVarsItem[];
8
+ /**
9
+ * 图表跳转链接列表
10
+ */
11
+ export type ChartsCommonChartLinksSchemaJson = ChartsCommonChartLinkItemSchemaJson[];
8
12
  /**
9
13
  * 图表设置配置完整结构。
10
14
  */
@@ -201,22 +205,20 @@ export type CommonChartStackContentSettings = 'group' | 'index';
201
205
  /**
202
206
  * 图表全局设置单位
203
207
  *
208
+ * @minItems 2
204
209
  * @maxItems 2
205
210
  */
206
- export type ChartUnitItemsSettings = [] | [
207
- 'custom' | 'length' | 'area' | 'mass' | 'volume' | 'each' | 'temperature' | 'time' | 'digital' | 'diitalUnit' | 'partsPer' | 'speed' | 'pace' | 'pressure' | 'current' | 'voltage' | 'power' | 'reactivePower' | 'apparentPower' | 'energy' | 'reactiveEnergy' | 'volumeFlowRate' | 'illuminance' | 'frequency' | 'angle' | 'throughput' | 'percent' | 'rmb' | 'currencySymbol'
208
- ] | [
211
+ export type ChartUnitItemsSettings = [
209
212
  ('custom' | 'length' | 'area' | 'mass' | 'volume' | 'each' | 'temperature' | 'time' | 'digital' | 'diitalUnit' | 'partsPer' | 'speed' | 'pace' | 'pressure' | 'current' | 'voltage' | 'power' | 'reactivePower' | 'apparentPower' | 'energy' | 'reactiveEnergy' | 'volumeFlowRate' | 'illuminance' | 'frequency' | 'angle' | 'throughput' | 'percent' | 'rmb' | 'currencySymbol'),
210
213
  (('mm' | 'cm' | 'm' | 'in' | 'ft-us' | 'ft' | 'mi' | 'mm2' | 'cm2' | 'm2' | 'ha' | 'km2' | 'in2' | 'ft2' | 'ac' | 'mi2' | 'mcg' | 'mg' | 'g' | 'kg' | 'oz' | 'lb' | 'mt' | 't' | 'mm3' | 'cm3' | 'ml' | 'l' | 'kl' | 'm3' | 'km3' | 'tsp' | 'Tbs' | 'in3' | 'fl-oz' | 'cup' | 'pnt' | 'qt' | 'gal' | 'ft3' | 'yd3' | 'mm3/s' | 'cm3/s' | 'ml/s' | 'cl/s' | 'dl/s' | 'l/s' | 'l/min' | 'l/h' | 'kl/s' | 'kl/min' | 'kl/h' | 'm3/s' | 'm3/min' | 'm3/h' | 'km3/s' | 'tsp/s' | 'Tbs/s' | 'in3/s' | 'in3/min' | 'in3/h' | 'fl-oz/s' | 'fl-oz/min' | 'fl-oz/h' | 'cup/s' | 'pnt/s' | 'pnt/min' | 'pnt/h' | 'qt/s' | 'gal/s' | 'gal/min' | 'gal/h' | 'ft3/s' | 'ft3/min' | 'ft3/h' | 'yd3/s' | 'yd3/min' | 'yd3/h' | 'C' | 'F' | 'K' | 'R' | 'ns' | 'μs' | 'ms' | 's' | 'min' | 'h' | 'd' | 'week' | 'month' | 'year' | 'Hz' | 'mHz' | 'kHz' | 'MHz' | 'GHz' | 'THz' | 'rpm' | 'deg/s' | 'rad/s' | 'm/s' | 'km/h' | 'm/h' | 'knot' | 'ft/s' | 's/m' | 'min/km' | 's/ft' | 'Pa' | 'hPa' | 'kPa' | 'MPa' | 'bar' | 'torr' | 'psi' | 'ksi' | 'b' | 'Kb' | 'Mb' | 'Gb' | 'Tb' | 'B' | 'KB' | 'MB' | 'GB' | 'TB' | 'lx' | 'ft-cd' | 'ppm' | 'ppb' | 'ppt' | 'ppq' | 'V' | 'mV' | 'kV' | 'A' | 'mA' | 'kA' | 'W' | 'mW' | 'kW' | 'MW' | 'GW' | 'VA' | 'mVA' | 'kVA' | 'MVA' | 'GVA' | 'VAR' | 'mVAR' | 'kVAR' | 'MVAR' | 'GVAR' | 'Wh' | 'mWh' | 'kWh' | 'MWh' | 'GWh' | 'J' | 'kJ' | 'VARh' | 'mVARh' | 'kVARh' | 'MVARh' | 'GVARh' | 'deg' | 'rad' | 'grad' | 'arcmin' | 'arcsec') | string)
211
214
  ];
212
215
  /**
213
216
  * 图表单位数据配置
214
217
  *
218
+ * @minItems 2
215
219
  * @maxItems 2
216
220
  */
217
- export type ChartUnitItemsSettings1 = [] | [
218
- 'custom' | 'length' | 'area' | 'mass' | 'volume' | 'each' | 'temperature' | 'time' | 'digital' | 'diitalUnit' | 'partsPer' | 'speed' | 'pace' | 'pressure' | 'current' | 'voltage' | 'power' | 'reactivePower' | 'apparentPower' | 'energy' | 'reactiveEnergy' | 'volumeFlowRate' | 'illuminance' | 'frequency' | 'angle' | 'throughput' | 'percent' | 'rmb' | 'currencySymbol'
219
- ] | [
221
+ export type ChartUnitItemsSettings1 = [
220
222
  ('custom' | 'length' | 'area' | 'mass' | 'volume' | 'each' | 'temperature' | 'time' | 'digital' | 'diitalUnit' | 'partsPer' | 'speed' | 'pace' | 'pressure' | 'current' | 'voltage' | 'power' | 'reactivePower' | 'apparentPower' | 'energy' | 'reactiveEnergy' | 'volumeFlowRate' | 'illuminance' | 'frequency' | 'angle' | 'throughput' | 'percent' | 'rmb' | 'currencySymbol'),
221
223
  (('mm' | 'cm' | 'm' | 'in' | 'ft-us' | 'ft' | 'mi' | 'mm2' | 'cm2' | 'm2' | 'ha' | 'km2' | 'in2' | 'ft2' | 'ac' | 'mi2' | 'mcg' | 'mg' | 'g' | 'kg' | 'oz' | 'lb' | 'mt' | 't' | 'mm3' | 'cm3' | 'ml' | 'l' | 'kl' | 'm3' | 'km3' | 'tsp' | 'Tbs' | 'in3' | 'fl-oz' | 'cup' | 'pnt' | 'qt' | 'gal' | 'ft3' | 'yd3' | 'mm3/s' | 'cm3/s' | 'ml/s' | 'cl/s' | 'dl/s' | 'l/s' | 'l/min' | 'l/h' | 'kl/s' | 'kl/min' | 'kl/h' | 'm3/s' | 'm3/min' | 'm3/h' | 'km3/s' | 'tsp/s' | 'Tbs/s' | 'in3/s' | 'in3/min' | 'in3/h' | 'fl-oz/s' | 'fl-oz/min' | 'fl-oz/h' | 'cup/s' | 'pnt/s' | 'pnt/min' | 'pnt/h' | 'qt/s' | 'gal/s' | 'gal/min' | 'gal/h' | 'ft3/s' | 'ft3/min' | 'ft3/h' | 'yd3/s' | 'yd3/min' | 'yd3/h' | 'C' | 'F' | 'K' | 'R' | 'ns' | 'μs' | 'ms' | 's' | 'min' | 'h' | 'd' | 'week' | 'month' | 'year' | 'Hz' | 'mHz' | 'kHz' | 'MHz' | 'GHz' | 'THz' | 'rpm' | 'deg/s' | 'rad/s' | 'm/s' | 'km/h' | 'm/h' | 'knot' | 'ft/s' | 's/m' | 'min/km' | 's/ft' | 'Pa' | 'hPa' | 'kPa' | 'MPa' | 'bar' | 'torr' | 'psi' | 'ksi' | 'b' | 'Kb' | 'Mb' | 'Gb' | 'Tb' | 'B' | 'KB' | 'MB' | 'GB' | 'TB' | 'lx' | 'ft-cd' | 'ppm' | 'ppb' | 'ppt' | 'ppq' | 'V' | 'mV' | 'kV' | 'A' | 'mA' | 'kA' | 'W' | 'mW' | 'kW' | 'MW' | 'GW' | 'VA' | 'mVA' | 'kVA' | 'MVA' | 'GVA' | 'VAR' | 'mVAR' | 'kVAR' | 'MVAR' | 'GVAR' | 'Wh' | 'mWh' | 'kWh' | 'MWh' | 'GWh' | 'J' | 'kJ' | 'VARh' | 'mVARh' | 'kVARh' | 'MVARh' | 'GVARh' | 'deg' | 'rad' | 'grad' | 'arcmin' | 'arcsec') | string)
222
224
  ];
@@ -625,7 +627,7 @@ export type CommonChartLegendValuesSettings = ('first' | 'last' | 'avg' | 'min'
625
627
  /**
626
628
  * 支持图表类型枚举
627
629
  */
628
- export type ChartType = 'group' | 'sequence' | 'singlestat' | 'pie' | 'bar' | 'histogram' | 'slo' | 'toplist' | 'gauge' | 'scatter' | 'bubble' | 'table' | 'treemap' | 'funnel' | 'chinamap' | 'worldmap' | 'hexgon' | 'heatmap' | 'topology' | 'sankey' | 'log' | 'object' | 'alarm' | 'text' | 'video' | 'picture' | 'command' | 'iframe';
630
+ export type ChartType = 'group' | 'sequence' | 'singlestat' | 'pie' | 'bar' | 'histogram' | 'slo' | 'toplist' | 'gauge' | 'scatter' | 'bubble' | 'table' | 'treemap' | 'funnel' | 'chinamap' | 'worldmap' | 'hexgon' | 'heatmap' | 'topology' | 'sankey' | 'change' | 'log' | 'object' | 'monitor' | 'alarm' | 'text' | 'video' | 'picture' | 'command' | 'iframe';
629
631
  /**
630
632
  * 概览图配置信息
631
633
  */
@@ -919,11 +921,11 @@ export type ChartWorldMapSettings = CommonChartSettings & {
919
921
  /**
920
922
  * 支持图表类型枚举
921
923
  */
922
- export type ChartType1 = 'group' | 'sequence' | 'singlestat' | 'pie' | 'bar' | 'histogram' | 'slo' | 'toplist' | 'gauge' | 'scatter' | 'bubble' | 'table' | 'treemap' | 'funnel' | 'chinamap' | 'worldmap' | 'hexgon' | 'heatmap' | 'topology' | 'sankey' | 'log' | 'object' | 'alarm' | 'text' | 'video' | 'picture' | 'command' | 'iframe';
924
+ export type ChartType1 = 'group' | 'sequence' | 'singlestat' | 'pie' | 'bar' | 'histogram' | 'slo' | 'toplist' | 'gauge' | 'scatter' | 'bubble' | 'table' | 'treemap' | 'funnel' | 'chinamap' | 'worldmap' | 'hexgon' | 'heatmap' | 'topology' | 'sankey' | 'change' | 'log' | 'object' | 'monitor' | 'alarm' | 'text' | 'video' | 'picture' | 'command' | 'iframe';
923
925
  /**
924
926
  * 支持图表类型枚举
925
927
  */
926
- export type ChartType2 = 'group' | 'sequence' | 'singlestat' | 'pie' | 'bar' | 'histogram' | 'slo' | 'toplist' | 'gauge' | 'scatter' | 'bubble' | 'table' | 'treemap' | 'funnel' | 'chinamap' | 'worldmap' | 'hexgon' | 'heatmap' | 'topology' | 'sankey' | 'log' | 'object' | 'alarm' | 'text' | 'video' | 'picture' | 'command' | 'iframe';
928
+ export type ChartType2 = 'group' | 'sequence' | 'singlestat' | 'pie' | 'bar' | 'histogram' | 'slo' | 'toplist' | 'gauge' | 'scatter' | 'bubble' | 'table' | 'treemap' | 'funnel' | 'chinamap' | 'worldmap' | 'hexgon' | 'heatmap' | 'topology' | 'sankey' | 'change' | 'log' | 'object' | 'monitor' | 'alarm' | 'text' | 'video' | 'picture' | 'command' | 'iframe';
927
929
  /**
928
930
  * 图表查询语句列表结构
929
931
  */
@@ -966,9 +968,9 @@ export interface DashboardData {
966
968
  [k: string]: unknown;
967
969
  }[];
968
970
  /**
969
- * 固定字段
971
+ * 仪表板主体类型,现有数据中常缺省,存在时固定为 template
970
972
  */
971
- type?: 'template';
973
+ type?: 'template' | null;
972
974
  [k: string]: unknown;
973
975
  };
974
976
  /**
@@ -1072,6 +1074,7 @@ export interface ChartVarsItem {
1072
1074
  */
1073
1075
  export interface ChartData {
1074
1076
  extend: {
1077
+ links?: ChartsCommonChartLinksSchemaJson;
1075
1078
  settings?: ChartSettings;
1076
1079
  [k: string]: unknown;
1077
1080
  };
@@ -1109,16 +1112,42 @@ export interface ChartData {
1109
1112
  queries: ChartQueries;
1110
1113
  [k: string]: unknown;
1111
1114
  }
1115
+ /**
1116
+ * 图表联动跳转项
1117
+ */
1118
+ export interface ChartsCommonChartLinkItemSchemaJson {
1119
+ /**
1120
+ * 跳转地址
1121
+ */
1122
+ url: string;
1123
+ /**
1124
+ * 打开方式
1125
+ */
1126
+ open: 'newWin' | 'curWin' | 'drawerWin';
1127
+ /**
1128
+ * 是否展示
1129
+ */
1130
+ show: boolean;
1131
+ /**
1132
+ * 跳转类型
1133
+ */
1134
+ type: 'logging' | 'container' | 'processes' | 'tracing' | 'host' | 'custom';
1135
+ /**
1136
+ * 是否修改过显示状态
1137
+ */
1138
+ showChanged: boolean;
1139
+ [k: string]: unknown;
1140
+ }
1112
1141
  /**
1113
1142
  * 图表时间相关配置完整结构。
1114
1143
  */
1115
1144
  export interface ChartTimeSettings {
1116
- timeInterval: 'auto' | '1ms' | '10ms' | '50ms' | '100ms' | '500ms' | '1s' | '10s' | '20s' | '30s' | '1m' | '5m' | '10m' | '30m' | '1h' | '6h' | '12h' | '1d' | '7d' | '30d';
1145
+ timeInterval?: 'auto' | '1ms' | '10ms' | '50ms' | '100ms' | '500ms' | '1s' | '10s' | '20s' | '30s' | '1m' | '5m' | '10m' | '30m' | '1h' | '6h' | '12h' | '1d' | '7d' | '30d';
1117
1146
  /**
1118
1147
  * 返回最大数据电枢
1119
1148
  */
1120
1149
  maxPointCount?: number;
1121
- fixedTime: ChartsSettingsSettingsFixedTimeSchemaJson;
1150
+ fixedTime?: ChartsSettingsSettingsFixedTimeSchemaJson;
1122
1151
  [k: string]: unknown;
1123
1152
  }
1124
1153
  /**
@@ -1359,10 +1388,22 @@ export interface ChartQueryItem {
1359
1388
  * 图表查询语句,可以是 dql语句,也可以是 promql 语句
1360
1389
  */
1361
1390
  q?: string;
1391
+ /**
1392
+ * 文本图内容,支持 HTML 或 Markdown 文本
1393
+ */
1394
+ content?: string;
1362
1395
  /**
1363
1396
  * 查询语句的唯一标识,由单个大写英文字母构成
1364
1397
  */
1365
1398
  code?: string;
1399
+ /**
1400
+ * 查询语句类型冗余字段,实际数据中可能是 promql/dql,也可能是 default/simple 这类查询模式
1401
+ */
1402
+ type?: 'default' | 'simple' | 'dql' | 'promql';
1403
+ /**
1404
+ * PromQL 查询顺序编号
1405
+ */
1406
+ promqlCode?: number;
1366
1407
  [k: string]: unknown;
1367
1408
  };
1368
1409
  [k: string]: unknown;
@@ -1,4 +1,4 @@
1
1
  import type { DashboardData as GuanceDashboardType } from '../generated/dashboardCharts';
2
2
  import type { DashboardData as GrafanaDashboardType, VariableModel, Panel, RowPanel } from './grafana-dashbord';
3
3
  export declare function covert(grafanaData: GrafanaDashboardType): GuanceDashboardType;
4
- export type { GrafanaDashboardType, Panel as GrafanaPanel, RowPanel as GrafanaRowPanel, VariableModel as GrafanaVariableModel };
4
+ export type { GrafanaDashboardType, Panel as GrafanaPanel, RowPanel as GrafanaRowPanel, VariableModel as GrafanaVariableModel, };
@@ -1,294 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.covert = covert;
4
- var grafanaPanelTypeToGuanceChartMap = {
5
- stat: 'singlestat',
6
- singlestat: 'singlestat',
7
- barchart: 'bar',
8
- timeseries: 'sequence',
9
- graph: 'sequence',
10
- piechart: 'pie',
11
- histogram: 'histogram',
12
- bargauge: 'toplist',
13
- gauge: 'gauge',
14
- table: 'table',
15
- text: 'text',
16
- heatmap: 'heatmap',
17
- treemap: 'treemap',
18
- };
19
- var GRAFANA_KEYWORKD = ['__interval'];
20
- var VARIABLE_MAP = {
21
- query: 'PROMQL_QUERY',
22
- custom: 'CUSTOM_LIST',
23
- };
24
- var VARIABLE_DATASOURCE_MAP = {
25
- query: 'dataflux',
26
- custom: 'custom',
27
- };
28
- function isSupportedVariableType(type) {
29
- return Object.prototype.hasOwnProperty.call(VARIABLE_MAP, type);
30
- }
31
- function replaceVariableStr(grafanaExpr) {
32
- return grafanaExpr.replace(/\$\{?([\d_\w]+)\}?/g, function (match, variable) {
33
- if (GRAFANA_KEYWORKD.indexOf(variable) > -1)
34
- return match;
35
- return "#{".concat(variable, "}");
36
- });
37
- }
38
- function sortPanelItemsByRowCol(panels) {
39
- return panels.slice(0).sort(function (panelA, panelB) {
40
- var posA = panelA.gridPos;
41
- var posB = panelB.gridPos;
42
- if (!posA || !posB)
43
- return -1;
44
- if (posA.y === posB.y && posA.x === posB.x && posA.w > posB.w) {
45
- return -1;
46
- }
47
- if (posA.y === posB.y && posA.x === posB.x) {
48
- return 0;
49
- }
50
- if (posA.y > posB.y || (posA.y === posB.y && posA.x > posB.x)) {
51
- return 1;
52
- }
53
- return -1;
54
- });
55
- }
56
- function tenToTweenty(source) {
57
- if (source === void 0) { source = 1; }
58
- var numArr = [];
59
- source--;
60
- do {
61
- numArr.push(source % 26);
62
- source = Math.floor(source / 26);
63
- } while (source > 0);
64
- return numArr
65
- .reverse()
66
- .map(function (item, index) {
67
- return String.fromCharCode(item + 97 + (index === numArr.length - 1 ? 0 : -1));
68
- })
69
- .join('')
70
- .toLowerCase();
71
- }
72
- function getGridH(h, rowHeight, margin) {
73
- return Math.round(h * rowHeight + Math.max(0, 2 * (h - 1)) * margin);
74
- }
75
- function getGuanceHByGrafanaH(granfanH) {
76
- return (getGridH(granfanH, 30, 4) + 10) / 20;
77
- }
78
- function covertPanelToGuanceChart(grafanaPanel, rowPanel) {
79
- var gridPos = grafanaPanel.gridPos, title = grafanaPanel.title, type = grafanaPanel.type, targets = grafanaPanel.targets, options = grafanaPanel.options;
80
- var chartType = grafanaPanelTypeToGuanceChartMap[type];
81
- var pos = {
82
- x: gridPos.x,
83
- w: gridPos.w,
84
- y: gridPos.y,
85
- h: gridPos.h,
86
- };
87
- if (rowPanel) {
88
- var rowGridPos = rowPanel.gridPos;
89
- if (rowGridPos && gridPos && !rowPanel.collapsed) {
90
- pos = {
91
- x: gridPos.x,
92
- w: gridPos.w,
93
- y: gridPos.y - rowGridPos.y,
94
- h: gridPos.h,
95
- };
96
- }
97
- }
98
- var queries = [];
99
- if (targets && targets.length) {
100
- var currentIndex_1 = 0;
101
- targets.forEach(function (_target) {
102
- var queryStr = _target.expr || _target.query || _target.queryText;
103
- if (!queryStr)
104
- return;
105
- currentIndex_1++;
106
- var queryItem = {
107
- datasource: 'dataflux',
108
- qtype: 'promql',
109
- type: chartType,
110
- query: {
111
- q: replaceVariableStr(queryStr),
112
- type: 'promql',
113
- code: tenToTweenty(currentIndex_1),
114
- promqlCode: currentIndex_1,
115
- },
116
- };
117
- queries.push(queryItem);
118
- });
119
- }
120
- var settings = {};
121
- if (options) {
122
- switch (chartType) {
123
- case 'text':
124
- queries.push({
125
- query: {
126
- content: options.content,
127
- },
128
- });
129
- break;
130
- case 'toplist':
131
- settings = {
132
- showTopSize: true,
133
- chartType: 'bar',
134
- };
135
- break;
136
- default:
137
- break;
138
- }
139
- }
140
- return {
141
- extend: {
142
- settings: settings,
143
- },
144
- group: {
145
- name: rowPanel ? rowPanel.title : null,
146
- },
147
- pos: {
148
- x: pos.x,
149
- y: getGuanceHByGrafanaH(pos.y),
150
- h: getGuanceHByGrafanaH(pos.h),
151
- w: pos.w,
152
- },
153
- name: replaceVariableStr(title || ''),
154
- queries: queries,
155
- type: chartType,
156
- };
157
- }
158
- function covertPanelsToCharts(grafanaPanelData, rowPanel) {
159
- var guanceCharts = [];
160
- grafanaPanelData.forEach(function (grafanaPanel) {
161
- if (!grafanaPanel.gridPos)
162
- return;
163
- guanceCharts.push(covertPanelToGuanceChart(grafanaPanel, rowPanel));
164
- });
165
- return guanceCharts;
166
- }
4
+ // This script is the shared conversion source for the published API and CLI.
5
+ // Keep it thin and delegate to the maintained converter implementation.
6
+ // @ts-ignore
7
+ var convert_grafana_dashboard_mjs_1 = require("../../skills/grafana-to-guance-dashboard/scripts/convert-grafana-dashboard.mjs");
167
8
  function covert(grafanaData) {
168
- var _a, _b, _c;
169
- var covertGuanceResult = {};
170
- covertGuanceResult.title = grafanaData.title;
171
- var guanceVars = [];
172
- (_b = (_a = grafanaData.templating) === null || _a === void 0 ? void 0 : _a.list) === null || _b === void 0 ? void 0 : _b.forEach(function (_variable, index) {
173
- var current = _variable.current, type = _variable.type, allValue = _variable.allValue;
174
- var variableType = String(type);
175
- if (!isSupportedVariableType(variableType))
176
- return;
177
- var defaultVal = {
178
- label: '',
179
- value: '',
180
- };
181
- if (current) {
182
- var labels = [];
183
- var values = [];
184
- if (Array.isArray(current.text)) {
185
- labels = current.text;
186
- }
187
- else if (typeof current.text === 'string') {
188
- labels = [current.text];
189
- }
190
- if (Array.isArray(current.value)) {
191
- values = current.value;
192
- }
193
- else if (typeof current.value === 'string') {
194
- values = [current.value];
195
- }
196
- labels = labels.map(function (label) {
197
- if (label === 'All') {
198
- if (allValue === '.*') {
199
- return '*';
200
- }
201
- return 'all values';
202
- }
203
- return label;
204
- });
205
- values = values.map(function (value) {
206
- if (value === '$__all') {
207
- if (allValue === '.*') {
208
- return '*';
209
- }
210
- return '__all__';
211
- }
212
- return value;
213
- });
214
- defaultVal = {
215
- label: labels.join(','),
216
- value: values.join(','),
217
- };
218
- }
219
- var value = _variable.query;
220
- if (value && typeof value === 'object' && value.query) {
221
- value = replaceVariableStr(value.query);
222
- }
223
- else if (value && typeof value === 'string') {
224
- value = replaceVariableStr(_variable.query);
225
- }
226
- else {
227
- return;
228
- }
229
- var guanceVariableItem = {
230
- type: VARIABLE_MAP[variableType],
231
- datasource: VARIABLE_DATASOURCE_MAP[variableType],
232
- name: _variable.label || _variable.name || '',
233
- seq: index,
234
- hide: _variable.hide ? 1 : 0,
235
- multiple: _variable.multi !== undefined ? _variable.multi : true,
236
- includeStar: _variable.includeAll !== undefined ? _variable.includeAll : true,
237
- valueSort: 'desc',
238
- code: _variable.name,
239
- definition: {
240
- value: value,
241
- defaultVal: defaultVal,
242
- },
243
- };
244
- guanceVars.push(guanceVariableItem);
245
- });
246
- var guanceGroups = [];
247
- var guanceExpand = {};
248
- var guanceCharts = [];
249
- var lastRowPanel;
250
- var lastPanels = [];
251
- var grafanaCharts = ((_c = grafanaData.panels) === null || _c === void 0 ? void 0 : _c.filter(function (_panel) { return _panel.type === 'row' || grafanaPanelTypeToGuanceChartMap[_panel.type]; })) || [];
252
- grafanaCharts = sortPanelItemsByRowCol(grafanaCharts);
253
- grafanaCharts.forEach(function (_panel) {
254
- var _a;
255
- if (_panel.type === 'row') {
256
- var _rowPanel = _panel;
257
- if (_rowPanel.title) {
258
- guanceGroups.push({
259
- name: _rowPanel.title,
260
- });
261
- guanceExpand[_rowPanel.title] = !_rowPanel.collapsed;
262
- }
263
- if (lastPanels.length) {
264
- guanceCharts.push.apply(guanceCharts, covertPanelsToCharts(lastPanels, lastRowPanel));
265
- lastPanels = [];
266
- lastRowPanel = undefined;
267
- }
268
- if (_rowPanel.collapsed) {
269
- var subPanels = ((_a = _rowPanel.panels) === null || _a === void 0 ? void 0 : _a.filter(function (_childPanel) {
270
- return _childPanel.type === 'row' || grafanaPanelTypeToGuanceChartMap[_childPanel.type];
271
- })) || [];
272
- guanceCharts.push.apply(guanceCharts, covertPanelsToCharts(subPanels, _rowPanel));
273
- }
274
- else {
275
- lastRowPanel = _rowPanel;
276
- }
277
- }
278
- else {
279
- lastPanels.push(_panel);
280
- }
281
- });
282
- if (lastPanels.length) {
283
- guanceCharts.push.apply(guanceCharts, covertPanelsToCharts(lastPanels, lastRowPanel));
284
- }
285
- covertGuanceResult.dashboardExtend = {
286
- groupUnfoldStatus: guanceExpand,
287
- };
288
- covertGuanceResult.main = {
289
- vars: guanceVars,
290
- charts: guanceCharts,
291
- groups: guanceGroups,
292
- };
293
- return covertGuanceResult;
9
+ return (0, convert_grafana_dashboard_mjs_1.convertDashboard)(grafanaData);
294
10
  }
@@ -5,6 +5,10 @@
5
5
  * 图表视图变量列表结构
6
6
  */
7
7
  export type ChartVarsSettings = ChartVarsItem[];
8
+ /**
9
+ * 图表跳转链接列表
10
+ */
11
+ export type ChartsCommonChartLinksSchemaJson = ChartsCommonChartLinkItemSchemaJson[];
8
12
  /**
9
13
  * 图表设置配置完整结构。
10
14
  */
@@ -201,22 +205,20 @@ export type CommonChartStackContentSettings = 'group' | 'index';
201
205
  /**
202
206
  * 图表全局设置单位
203
207
  *
208
+ * @minItems 2
204
209
  * @maxItems 2
205
210
  */
206
- export type ChartUnitItemsSettings = [] | [
207
- 'custom' | 'length' | 'area' | 'mass' | 'volume' | 'each' | 'temperature' | 'time' | 'digital' | 'diitalUnit' | 'partsPer' | 'speed' | 'pace' | 'pressure' | 'current' | 'voltage' | 'power' | 'reactivePower' | 'apparentPower' | 'energy' | 'reactiveEnergy' | 'volumeFlowRate' | 'illuminance' | 'frequency' | 'angle' | 'throughput' | 'percent' | 'rmb' | 'currencySymbol'
208
- ] | [
211
+ export type ChartUnitItemsSettings = [
209
212
  ('custom' | 'length' | 'area' | 'mass' | 'volume' | 'each' | 'temperature' | 'time' | 'digital' | 'diitalUnit' | 'partsPer' | 'speed' | 'pace' | 'pressure' | 'current' | 'voltage' | 'power' | 'reactivePower' | 'apparentPower' | 'energy' | 'reactiveEnergy' | 'volumeFlowRate' | 'illuminance' | 'frequency' | 'angle' | 'throughput' | 'percent' | 'rmb' | 'currencySymbol'),
210
213
  (('mm' | 'cm' | 'm' | 'in' | 'ft-us' | 'ft' | 'mi' | 'mm2' | 'cm2' | 'm2' | 'ha' | 'km2' | 'in2' | 'ft2' | 'ac' | 'mi2' | 'mcg' | 'mg' | 'g' | 'kg' | 'oz' | 'lb' | 'mt' | 't' | 'mm3' | 'cm3' | 'ml' | 'l' | 'kl' | 'm3' | 'km3' | 'tsp' | 'Tbs' | 'in3' | 'fl-oz' | 'cup' | 'pnt' | 'qt' | 'gal' | 'ft3' | 'yd3' | 'mm3/s' | 'cm3/s' | 'ml/s' | 'cl/s' | 'dl/s' | 'l/s' | 'l/min' | 'l/h' | 'kl/s' | 'kl/min' | 'kl/h' | 'm3/s' | 'm3/min' | 'm3/h' | 'km3/s' | 'tsp/s' | 'Tbs/s' | 'in3/s' | 'in3/min' | 'in3/h' | 'fl-oz/s' | 'fl-oz/min' | 'fl-oz/h' | 'cup/s' | 'pnt/s' | 'pnt/min' | 'pnt/h' | 'qt/s' | 'gal/s' | 'gal/min' | 'gal/h' | 'ft3/s' | 'ft3/min' | 'ft3/h' | 'yd3/s' | 'yd3/min' | 'yd3/h' | 'C' | 'F' | 'K' | 'R' | 'ns' | 'μs' | 'ms' | 's' | 'min' | 'h' | 'd' | 'week' | 'month' | 'year' | 'Hz' | 'mHz' | 'kHz' | 'MHz' | 'GHz' | 'THz' | 'rpm' | 'deg/s' | 'rad/s' | 'm/s' | 'km/h' | 'm/h' | 'knot' | 'ft/s' | 's/m' | 'min/km' | 's/ft' | 'Pa' | 'hPa' | 'kPa' | 'MPa' | 'bar' | 'torr' | 'psi' | 'ksi' | 'b' | 'Kb' | 'Mb' | 'Gb' | 'Tb' | 'B' | 'KB' | 'MB' | 'GB' | 'TB' | 'lx' | 'ft-cd' | 'ppm' | 'ppb' | 'ppt' | 'ppq' | 'V' | 'mV' | 'kV' | 'A' | 'mA' | 'kA' | 'W' | 'mW' | 'kW' | 'MW' | 'GW' | 'VA' | 'mVA' | 'kVA' | 'MVA' | 'GVA' | 'VAR' | 'mVAR' | 'kVAR' | 'MVAR' | 'GVAR' | 'Wh' | 'mWh' | 'kWh' | 'MWh' | 'GWh' | 'J' | 'kJ' | 'VARh' | 'mVARh' | 'kVARh' | 'MVARh' | 'GVARh' | 'deg' | 'rad' | 'grad' | 'arcmin' | 'arcsec') | string)
211
214
  ];
212
215
  /**
213
216
  * 图表单位数据配置
214
217
  *
218
+ * @minItems 2
215
219
  * @maxItems 2
216
220
  */
217
- export type ChartUnitItemsSettings1 = [] | [
218
- 'custom' | 'length' | 'area' | 'mass' | 'volume' | 'each' | 'temperature' | 'time' | 'digital' | 'diitalUnit' | 'partsPer' | 'speed' | 'pace' | 'pressure' | 'current' | 'voltage' | 'power' | 'reactivePower' | 'apparentPower' | 'energy' | 'reactiveEnergy' | 'volumeFlowRate' | 'illuminance' | 'frequency' | 'angle' | 'throughput' | 'percent' | 'rmb' | 'currencySymbol'
219
- ] | [
221
+ export type ChartUnitItemsSettings1 = [
220
222
  ('custom' | 'length' | 'area' | 'mass' | 'volume' | 'each' | 'temperature' | 'time' | 'digital' | 'diitalUnit' | 'partsPer' | 'speed' | 'pace' | 'pressure' | 'current' | 'voltage' | 'power' | 'reactivePower' | 'apparentPower' | 'energy' | 'reactiveEnergy' | 'volumeFlowRate' | 'illuminance' | 'frequency' | 'angle' | 'throughput' | 'percent' | 'rmb' | 'currencySymbol'),
221
223
  (('mm' | 'cm' | 'm' | 'in' | 'ft-us' | 'ft' | 'mi' | 'mm2' | 'cm2' | 'm2' | 'ha' | 'km2' | 'in2' | 'ft2' | 'ac' | 'mi2' | 'mcg' | 'mg' | 'g' | 'kg' | 'oz' | 'lb' | 'mt' | 't' | 'mm3' | 'cm3' | 'ml' | 'l' | 'kl' | 'm3' | 'km3' | 'tsp' | 'Tbs' | 'in3' | 'fl-oz' | 'cup' | 'pnt' | 'qt' | 'gal' | 'ft3' | 'yd3' | 'mm3/s' | 'cm3/s' | 'ml/s' | 'cl/s' | 'dl/s' | 'l/s' | 'l/min' | 'l/h' | 'kl/s' | 'kl/min' | 'kl/h' | 'm3/s' | 'm3/min' | 'm3/h' | 'km3/s' | 'tsp/s' | 'Tbs/s' | 'in3/s' | 'in3/min' | 'in3/h' | 'fl-oz/s' | 'fl-oz/min' | 'fl-oz/h' | 'cup/s' | 'pnt/s' | 'pnt/min' | 'pnt/h' | 'qt/s' | 'gal/s' | 'gal/min' | 'gal/h' | 'ft3/s' | 'ft3/min' | 'ft3/h' | 'yd3/s' | 'yd3/min' | 'yd3/h' | 'C' | 'F' | 'K' | 'R' | 'ns' | 'μs' | 'ms' | 's' | 'min' | 'h' | 'd' | 'week' | 'month' | 'year' | 'Hz' | 'mHz' | 'kHz' | 'MHz' | 'GHz' | 'THz' | 'rpm' | 'deg/s' | 'rad/s' | 'm/s' | 'km/h' | 'm/h' | 'knot' | 'ft/s' | 's/m' | 'min/km' | 's/ft' | 'Pa' | 'hPa' | 'kPa' | 'MPa' | 'bar' | 'torr' | 'psi' | 'ksi' | 'b' | 'Kb' | 'Mb' | 'Gb' | 'Tb' | 'B' | 'KB' | 'MB' | 'GB' | 'TB' | 'lx' | 'ft-cd' | 'ppm' | 'ppb' | 'ppt' | 'ppq' | 'V' | 'mV' | 'kV' | 'A' | 'mA' | 'kA' | 'W' | 'mW' | 'kW' | 'MW' | 'GW' | 'VA' | 'mVA' | 'kVA' | 'MVA' | 'GVA' | 'VAR' | 'mVAR' | 'kVAR' | 'MVAR' | 'GVAR' | 'Wh' | 'mWh' | 'kWh' | 'MWh' | 'GWh' | 'J' | 'kJ' | 'VARh' | 'mVARh' | 'kVARh' | 'MVARh' | 'GVARh' | 'deg' | 'rad' | 'grad' | 'arcmin' | 'arcsec') | string)
222
224
  ];
@@ -625,7 +627,7 @@ export type CommonChartLegendValuesSettings = ('first' | 'last' | 'avg' | 'min'
625
627
  /**
626
628
  * 支持图表类型枚举
627
629
  */
628
- export type ChartType = 'group' | 'sequence' | 'singlestat' | 'pie' | 'bar' | 'histogram' | 'slo' | 'toplist' | 'gauge' | 'scatter' | 'bubble' | 'table' | 'treemap' | 'funnel' | 'chinamap' | 'worldmap' | 'hexgon' | 'heatmap' | 'topology' | 'sankey' | 'log' | 'object' | 'alarm' | 'text' | 'video' | 'picture' | 'command' | 'iframe';
630
+ export type ChartType = 'group' | 'sequence' | 'singlestat' | 'pie' | 'bar' | 'histogram' | 'slo' | 'toplist' | 'gauge' | 'scatter' | 'bubble' | 'table' | 'treemap' | 'funnel' | 'chinamap' | 'worldmap' | 'hexgon' | 'heatmap' | 'topology' | 'sankey' | 'change' | 'log' | 'object' | 'monitor' | 'alarm' | 'text' | 'video' | 'picture' | 'command' | 'iframe';
629
631
  /**
630
632
  * 概览图配置信息
631
633
  */
@@ -919,11 +921,11 @@ export type ChartWorldMapSettings = CommonChartSettings & {
919
921
  /**
920
922
  * 支持图表类型枚举
921
923
  */
922
- export type ChartType1 = 'group' | 'sequence' | 'singlestat' | 'pie' | 'bar' | 'histogram' | 'slo' | 'toplist' | 'gauge' | 'scatter' | 'bubble' | 'table' | 'treemap' | 'funnel' | 'chinamap' | 'worldmap' | 'hexgon' | 'heatmap' | 'topology' | 'sankey' | 'log' | 'object' | 'alarm' | 'text' | 'video' | 'picture' | 'command' | 'iframe';
924
+ export type ChartType1 = 'group' | 'sequence' | 'singlestat' | 'pie' | 'bar' | 'histogram' | 'slo' | 'toplist' | 'gauge' | 'scatter' | 'bubble' | 'table' | 'treemap' | 'funnel' | 'chinamap' | 'worldmap' | 'hexgon' | 'heatmap' | 'topology' | 'sankey' | 'change' | 'log' | 'object' | 'monitor' | 'alarm' | 'text' | 'video' | 'picture' | 'command' | 'iframe';
923
925
  /**
924
926
  * 支持图表类型枚举
925
927
  */
926
- export type ChartType2 = 'group' | 'sequence' | 'singlestat' | 'pie' | 'bar' | 'histogram' | 'slo' | 'toplist' | 'gauge' | 'scatter' | 'bubble' | 'table' | 'treemap' | 'funnel' | 'chinamap' | 'worldmap' | 'hexgon' | 'heatmap' | 'topology' | 'sankey' | 'log' | 'object' | 'alarm' | 'text' | 'video' | 'picture' | 'command' | 'iframe';
928
+ export type ChartType2 = 'group' | 'sequence' | 'singlestat' | 'pie' | 'bar' | 'histogram' | 'slo' | 'toplist' | 'gauge' | 'scatter' | 'bubble' | 'table' | 'treemap' | 'funnel' | 'chinamap' | 'worldmap' | 'hexgon' | 'heatmap' | 'topology' | 'sankey' | 'change' | 'log' | 'object' | 'monitor' | 'alarm' | 'text' | 'video' | 'picture' | 'command' | 'iframe';
927
929
  /**
928
930
  * 图表查询语句列表结构
929
931
  */
@@ -966,9 +968,9 @@ export interface DashboardData {
966
968
  [k: string]: unknown;
967
969
  }[];
968
970
  /**
969
- * 固定字段
971
+ * 仪表板主体类型,现有数据中常缺省,存在时固定为 template
970
972
  */
971
- type?: 'template';
973
+ type?: 'template' | null;
972
974
  [k: string]: unknown;
973
975
  };
974
976
  /**
@@ -1072,6 +1074,7 @@ export interface ChartVarsItem {
1072
1074
  */
1073
1075
  export interface ChartData {
1074
1076
  extend: {
1077
+ links?: ChartsCommonChartLinksSchemaJson;
1075
1078
  settings?: ChartSettings;
1076
1079
  [k: string]: unknown;
1077
1080
  };
@@ -1109,16 +1112,42 @@ export interface ChartData {
1109
1112
  queries: ChartQueries;
1110
1113
  [k: string]: unknown;
1111
1114
  }
1115
+ /**
1116
+ * 图表联动跳转项
1117
+ */
1118
+ export interface ChartsCommonChartLinkItemSchemaJson {
1119
+ /**
1120
+ * 跳转地址
1121
+ */
1122
+ url: string;
1123
+ /**
1124
+ * 打开方式
1125
+ */
1126
+ open: 'newWin' | 'curWin' | 'drawerWin';
1127
+ /**
1128
+ * 是否展示
1129
+ */
1130
+ show: boolean;
1131
+ /**
1132
+ * 跳转类型
1133
+ */
1134
+ type: 'logging' | 'container' | 'processes' | 'tracing' | 'host' | 'custom';
1135
+ /**
1136
+ * 是否修改过显示状态
1137
+ */
1138
+ showChanged: boolean;
1139
+ [k: string]: unknown;
1140
+ }
1112
1141
  /**
1113
1142
  * 图表时间相关配置完整结构。
1114
1143
  */
1115
1144
  export interface ChartTimeSettings {
1116
- timeInterval: 'auto' | '1ms' | '10ms' | '50ms' | '100ms' | '500ms' | '1s' | '10s' | '20s' | '30s' | '1m' | '5m' | '10m' | '30m' | '1h' | '6h' | '12h' | '1d' | '7d' | '30d';
1145
+ timeInterval?: 'auto' | '1ms' | '10ms' | '50ms' | '100ms' | '500ms' | '1s' | '10s' | '20s' | '30s' | '1m' | '5m' | '10m' | '30m' | '1h' | '6h' | '12h' | '1d' | '7d' | '30d';
1117
1146
  /**
1118
1147
  * 返回最大数据电枢
1119
1148
  */
1120
1149
  maxPointCount?: number;
1121
- fixedTime: ChartsSettingsSettingsFixedTimeSchemaJson;
1150
+ fixedTime?: ChartsSettingsSettingsFixedTimeSchemaJson;
1122
1151
  [k: string]: unknown;
1123
1152
  }
1124
1153
  /**
@@ -1359,10 +1388,22 @@ export interface ChartQueryItem {
1359
1388
  * 图表查询语句,可以是 dql语句,也可以是 promql 语句
1360
1389
  */
1361
1390
  q?: string;
1391
+ /**
1392
+ * 文本图内容,支持 HTML 或 Markdown 文本
1393
+ */
1394
+ content?: string;
1362
1395
  /**
1363
1396
  * 查询语句的唯一标识,由单个大写英文字母构成
1364
1397
  */
1365
1398
  code?: string;
1399
+ /**
1400
+ * 查询语句类型冗余字段,实际数据中可能是 promql/dql,也可能是 default/simple 这类查询模式
1401
+ */
1402
+ type?: 'default' | 'simple' | 'dql' | 'promql';
1403
+ /**
1404
+ * PromQL 查询顺序编号
1405
+ */
1406
+ promqlCode?: number;
1366
1407
  [k: string]: unknown;
1367
1408
  };
1368
1409
  [k: string]: unknown;
@@ -1,4 +1,4 @@
1
1
  import type { DashboardData as GuanceDashboardType } from '../generated/dashboardCharts';
2
2
  import type { DashboardData as GrafanaDashboardType, VariableModel, Panel, RowPanel } from './grafana-dashbord';
3
3
  export declare function covert(grafanaData: GrafanaDashboardType): GuanceDashboardType;
4
- export type { GrafanaDashboardType, Panel as GrafanaPanel, RowPanel as GrafanaRowPanel, VariableModel as GrafanaVariableModel };
4
+ export type { GrafanaDashboardType, Panel as GrafanaPanel, RowPanel as GrafanaRowPanel, VariableModel as GrafanaVariableModel, };