@cloudcare/guance-front-tools 1.0.13 → 1.0.16
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/lib/cjs/scripts/convert-grafana-dashboard-core.js +1678 -0
- package/lib/cjs/scripts/convert-grafana-dashboard.js +130 -0
- package/lib/cjs/scripts/grafana-covert-to-guance-core.js +2 -2
- package/lib/esm/scripts/convert-grafana-dashboard-core.js +1675 -0
- package/lib/esm/scripts/convert-grafana-dashboard.js +125 -0
- package/lib/esm/scripts/grafana-covert-to-guance-core.js +1 -1
- package/lib/scripts/convert-grafana-dashboard-core.js +1770 -0
- package/lib/scripts/convert-grafana-dashboard.js +147 -0
- package/lib/scripts/grafana-covert-to-guance-core.js +1 -1
- package/lib/scripts/grafana-covert-to-guance-core.ts +1 -1
- package/lib/scripts/grafana-covert-to-guance.js +3 -1
- package/lib/scripts/grafana-covert-to-guance.ts +3 -4
- package/package.json +3 -2
- package/scripts/sync-converter.mjs +57 -0
- package/skills/grafana-to-guance-dashboard/scripts/convert-grafana-dashboard-core.js +1675 -0
- package/skills/grafana-to-guance-dashboard/scripts/convert-grafana-dashboard.mjs +106 -1880
- package/test/cli.test.mjs +123 -1
package/test/cli.test.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import fs from 'node:fs'
|
|
|
4
4
|
import os from 'node:os'
|
|
5
5
|
import path from 'node:path'
|
|
6
6
|
import { spawnSync } from 'node:child_process'
|
|
7
|
-
import { fileURLToPath } from 'node:url'
|
|
7
|
+
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
8
8
|
|
|
9
9
|
import { covert } from '../lib/scripts/grafana-covert-to-guance-core.js'
|
|
10
10
|
import {
|
|
@@ -15,6 +15,10 @@ const __filename = fileURLToPath(import.meta.url)
|
|
|
15
15
|
const __dirname = path.dirname(__filename)
|
|
16
16
|
const projectRoot = path.resolve(__dirname, '..')
|
|
17
17
|
const cliPath = path.join(projectRoot, 'cli.js')
|
|
18
|
+
const skillCliPath = path.join(
|
|
19
|
+
projectRoot,
|
|
20
|
+
'skills/grafana-to-guance-dashboard/scripts/convert-grafana-dashboard.mjs'
|
|
21
|
+
)
|
|
18
22
|
const grafanaInputPath = path.join(projectRoot, 'lib/example/test2.json')
|
|
19
23
|
const grafanaLoadInputPath = path.join(projectRoot, 'lib/example/grafana2.json')
|
|
20
24
|
|
|
@@ -26,6 +30,14 @@ function runCli(args, options = {}) {
|
|
|
26
30
|
})
|
|
27
31
|
}
|
|
28
32
|
|
|
33
|
+
function runSkillCli(args, options = {}) {
|
|
34
|
+
return spawnSync(process.execPath, [skillCliPath, ...args], {
|
|
35
|
+
cwd: projectRoot,
|
|
36
|
+
encoding: 'utf-8',
|
|
37
|
+
...options,
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
|
|
29
41
|
function createTempDir() {
|
|
30
42
|
return fs.mkdtempSync(path.join(os.tmpdir(), 'guance-front-tools-cli-'))
|
|
31
43
|
}
|
|
@@ -39,6 +51,47 @@ test('covert delegates to the shared converter implementation', () => {
|
|
|
39
51
|
assert.deepEqual(actual, expected)
|
|
40
52
|
})
|
|
41
53
|
|
|
54
|
+
test('published esm converter entry does not depend on skills path', async () => {
|
|
55
|
+
const esmCorePath = path.join(projectRoot, 'lib/esm/scripts/grafana-covert-to-guance-core.js')
|
|
56
|
+
const esmCoreSource = fs.readFileSync(esmCorePath, 'utf-8')
|
|
57
|
+
const esmConverterCorePath = path.join(projectRoot, 'lib/esm/scripts/convert-grafana-dashboard-core.js')
|
|
58
|
+
const esmConverterCoreSource = fs.readFileSync(esmConverterCorePath, 'utf-8')
|
|
59
|
+
|
|
60
|
+
assert.match(esmCoreSource, /convert-grafana-dashboard-core\.js/)
|
|
61
|
+
assert.doesNotMatch(esmCoreSource, /skills\/grafana-to-guance-dashboard/)
|
|
62
|
+
assert.doesNotMatch(esmConverterCoreSource, /from 'fs'|from "fs"|from 'path'|from "path"|from 'url'|from "url"|from 'ajv'|from "ajv"/)
|
|
63
|
+
assert.doesNotMatch(esmConverterCoreSource, /\?\.|\?\?/)
|
|
64
|
+
|
|
65
|
+
const publishedModule = await import(pathToFileURL(esmCorePath).href)
|
|
66
|
+
const grafanaDashboard = JSON.parse(fs.readFileSync(grafanaLoadInputPath, 'utf-8'))
|
|
67
|
+
const actual = publishedModule.covert(grafanaDashboard)
|
|
68
|
+
const expected = convertDashboard(grafanaDashboard)
|
|
69
|
+
|
|
70
|
+
assert.deepEqual(actual, expected)
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
test('skill converter script ships wrapper and core files without importing lib paths', () => {
|
|
74
|
+
const skillWrapperPath = path.join(
|
|
75
|
+
projectRoot,
|
|
76
|
+
'skills/grafana-to-guance-dashboard/scripts/convert-grafana-dashboard.mjs'
|
|
77
|
+
)
|
|
78
|
+
const skillCorePath = path.join(
|
|
79
|
+
projectRoot,
|
|
80
|
+
'skills/grafana-to-guance-dashboard/scripts/convert-grafana-dashboard-core.js'
|
|
81
|
+
)
|
|
82
|
+
const skillWrapperSource = fs.readFileSync(skillWrapperPath, 'utf-8')
|
|
83
|
+
const skillCoreSource = fs.readFileSync(skillCorePath, 'utf-8')
|
|
84
|
+
|
|
85
|
+
assert.doesNotMatch(skillWrapperSource, /lib\/scripts\/convert-grafana-dashboard/)
|
|
86
|
+
assert.match(skillWrapperSource, /import \{ convertDashboard \} from '\.\/convert-grafana-dashboard-core\.js'/)
|
|
87
|
+
assert.match(skillWrapperSource, /^#!\/usr\/bin\/env node/m)
|
|
88
|
+
assert.match(skillWrapperSource, /export function main\(/)
|
|
89
|
+
assert.match(skillWrapperSource, /export function validateDashboardFile\(/)
|
|
90
|
+
assert.match(skillCoreSource, /export function convertDashboard\(/)
|
|
91
|
+
assert.doesNotMatch(skillWrapperSource, /\?\.|\?\?/)
|
|
92
|
+
assert.doesNotMatch(skillCoreSource, /\?\.|\?\?/)
|
|
93
|
+
})
|
|
94
|
+
|
|
42
95
|
test('shared converter infers units from query text when panel unit is missing', () => {
|
|
43
96
|
const grafanaDashboard = JSON.parse(fs.readFileSync(grafanaLoadInputPath, 'utf-8'))
|
|
44
97
|
|
|
@@ -371,3 +424,72 @@ test('cli writes default output file to current working directory', () => {
|
|
|
371
424
|
const actual = JSON.parse(fs.readFileSync(outPath, 'utf-8'))
|
|
372
425
|
assert.deepEqual(actual, expected)
|
|
373
426
|
})
|
|
427
|
+
|
|
428
|
+
test('skill cli converts and validates a grafana dashboard with explicit output path', () => {
|
|
429
|
+
const tempDir = createTempDir()
|
|
430
|
+
const outPath = path.join(tempDir, 'skill', 'guance-dashboard.json')
|
|
431
|
+
const expected = convertDashboard(JSON.parse(fs.readFileSync(grafanaInputPath, 'utf-8')))
|
|
432
|
+
|
|
433
|
+
const result = runSkillCli([
|
|
434
|
+
'--input',
|
|
435
|
+
grafanaInputPath,
|
|
436
|
+
'--output',
|
|
437
|
+
outPath,
|
|
438
|
+
'--validate',
|
|
439
|
+
])
|
|
440
|
+
|
|
441
|
+
assert.equal(result.status, 0, result.stderr || result.stdout)
|
|
442
|
+
assert.match(result.stdout, /Validated /)
|
|
443
|
+
assert.equal(fs.existsSync(outPath), true)
|
|
444
|
+
|
|
445
|
+
const actual = JSON.parse(fs.readFileSync(outPath, 'utf-8'))
|
|
446
|
+
assert.deepEqual(actual, expected)
|
|
447
|
+
})
|
|
448
|
+
|
|
449
|
+
test('skill cli supports guance promql compatible output', () => {
|
|
450
|
+
const tempDir = createTempDir()
|
|
451
|
+
const outPath = path.join(tempDir, 'skill', 'guance-promql.json')
|
|
452
|
+
const expected = convertDashboard(JSON.parse(fs.readFileSync(grafanaInputPath, 'utf-8')), {
|
|
453
|
+
guancePromqlCompatible: true,
|
|
454
|
+
})
|
|
455
|
+
|
|
456
|
+
const result = runSkillCli([
|
|
457
|
+
'--input',
|
|
458
|
+
grafanaInputPath,
|
|
459
|
+
'--output',
|
|
460
|
+
outPath,
|
|
461
|
+
'--validate',
|
|
462
|
+
'--guance-promql-compatible',
|
|
463
|
+
])
|
|
464
|
+
|
|
465
|
+
assert.equal(result.status, 0, result.stderr || result.stdout)
|
|
466
|
+
assert.match(result.stdout, /Validated /)
|
|
467
|
+
assert.equal(fs.existsSync(outPath), true)
|
|
468
|
+
|
|
469
|
+
const actual = JSON.parse(fs.readFileSync(outPath, 'utf-8'))
|
|
470
|
+
assert.deepEqual(actual, expected)
|
|
471
|
+
})
|
|
472
|
+
|
|
473
|
+
test('skill cli supports keep grafana meta output', () => {
|
|
474
|
+
const tempDir = createTempDir()
|
|
475
|
+
const outPath = path.join(tempDir, 'skill', 'guance-keep-meta.json')
|
|
476
|
+
const expected = convertDashboard(JSON.parse(fs.readFileSync(grafanaInputPath, 'utf-8')), {
|
|
477
|
+
keepGrafanaMeta: true,
|
|
478
|
+
})
|
|
479
|
+
|
|
480
|
+
const result = runSkillCli([
|
|
481
|
+
'--input',
|
|
482
|
+
grafanaInputPath,
|
|
483
|
+
'--output',
|
|
484
|
+
outPath,
|
|
485
|
+
'--validate',
|
|
486
|
+
'--keep-grafana-meta',
|
|
487
|
+
])
|
|
488
|
+
|
|
489
|
+
assert.equal(result.status, 0, result.stderr || result.stdout)
|
|
490
|
+
assert.match(result.stdout, /Validated /)
|
|
491
|
+
assert.equal(fs.existsSync(outPath), true)
|
|
492
|
+
|
|
493
|
+
const actual = JSON.parse(fs.readFileSync(outPath, 'utf-8'))
|
|
494
|
+
assert.deepEqual(actual, expected)
|
|
495
|
+
})
|