k6-perf-reporter 1.7.0 → 1.7.1
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/dist/cli.js +54 -18
- package/dist/cli.js.map +1 -1
- package/package.json +2 -3
- package/src/cli.ts +65 -16
package/dist/cli.js
CHANGED
|
@@ -6,6 +6,39 @@ const config_1 = require("./config");
|
|
|
6
6
|
const data_collector_1 = require("./data-collector");
|
|
7
7
|
const datasources_1 = require("./datasources");
|
|
8
8
|
const reporters_1 = require("./reporters");
|
|
9
|
+
const VALID_REPORTERS = ["cli", "json", "markdown", "slack"];
|
|
10
|
+
function defaultOutputPath(name, runId) {
|
|
11
|
+
const extensions = {
|
|
12
|
+
json: "json",
|
|
13
|
+
markdown: "md",
|
|
14
|
+
};
|
|
15
|
+
const ext = extensions[name];
|
|
16
|
+
return ext ? `report-${runId}.${ext}` : undefined;
|
|
17
|
+
}
|
|
18
|
+
async function runReporter(name, report, options, configInstance) {
|
|
19
|
+
const output = options.output || defaultOutputPath(name, report.runId);
|
|
20
|
+
switch (name) {
|
|
21
|
+
case "json":
|
|
22
|
+
new reporters_1.JsonReporter().report(report, output);
|
|
23
|
+
break;
|
|
24
|
+
case "markdown":
|
|
25
|
+
new reporters_1.MarkdownReporter().report(report, output);
|
|
26
|
+
break;
|
|
27
|
+
case "slack": {
|
|
28
|
+
const slackConfig = configInstance.getSlackConfig();
|
|
29
|
+
if (!slackConfig) {
|
|
30
|
+
throw new Error("Slack token not configured. Set SLACK_TOKEN environment variable or configure in config file.");
|
|
31
|
+
}
|
|
32
|
+
const slackReporter = new reporters_1.SlackReporter(slackConfig.token, slackConfig.channel);
|
|
33
|
+
await slackReporter.report(report);
|
|
34
|
+
console.log("Report sent to Slack");
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
case "cli":
|
|
38
|
+
new reporters_1.CliReporter().report(report);
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
9
42
|
function main() {
|
|
10
43
|
commander_1.program
|
|
11
44
|
.name("k6-reporter")
|
|
@@ -20,36 +53,32 @@ function main() {
|
|
|
20
53
|
.option("-c, --config <path>", "Path to config file", ".config.json")
|
|
21
54
|
.option("-d, --datasource <type>", "Data source: 'influxdb' or 'prometheus'")
|
|
22
55
|
.option("-f, --format <format>", "Output format: 'json', 'cli', 'markdown', or 'slack'", "cli")
|
|
23
|
-
.option("-
|
|
56
|
+
.option("-r, --report <reporters>", "Run one or more reporters (comma-separated): cli, json, markdown, slack")
|
|
57
|
+
.option("-o, --output <path>", "Output file path (for json and markdown formats)")
|
|
24
58
|
.option("--no-cache", "Disable cache, always fetch fresh data")
|
|
25
59
|
.action(async (options) => {
|
|
26
60
|
try {
|
|
61
|
+
if (options.report && options.format !== "cli") {
|
|
62
|
+
throw new Error("Cannot use --report and --format together. Use --report for multiple reporters.");
|
|
63
|
+
}
|
|
27
64
|
const configInstance = config_1.Config.getInstance(options.config);
|
|
28
65
|
const dsType = (options.datasource || configInstance.getDataSourceType());
|
|
29
66
|
const dataSource = (0, datasources_1.createDataSource)(dsType, configInstance);
|
|
30
67
|
const cacheTtl = options.cache ? configInstance.getCacheConfig().ttl : 0;
|
|
31
68
|
const collector = new data_collector_1.DataCollector(dataSource, cacheTtl);
|
|
32
69
|
const report = await collector.collect(options.runId, options.startTime || "-1h", options.endTime || "now()");
|
|
33
|
-
if (options.
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
else if (options.format === "slack") {
|
|
42
|
-
const slackConfig = configInstance.getSlackConfig();
|
|
43
|
-
if (!slackConfig) {
|
|
44
|
-
throw new Error("Slack token not configured. Set SLACK_TOKEN environment variable or configure in config file.");
|
|
70
|
+
if (options.report) {
|
|
71
|
+
const reporters = options.report.split(",").map((r) => r.trim());
|
|
72
|
+
const invalid = reporters.filter((r) => !VALID_REPORTERS.includes(r));
|
|
73
|
+
if (invalid.length > 0) {
|
|
74
|
+
throw new Error(`Invalid reporter(s): ${invalid.join(", ")}. Valid options: ${VALID_REPORTERS.join(", ")}`);
|
|
75
|
+
}
|
|
76
|
+
for (const name of reporters) {
|
|
77
|
+
await runReporter(name, report, options, configInstance);
|
|
45
78
|
}
|
|
46
|
-
const slackReporter = new reporters_1.SlackReporter(slackConfig.token, slackConfig.channel);
|
|
47
|
-
await slackReporter.report(report);
|
|
48
|
-
console.log("Report sent to Slack");
|
|
49
79
|
}
|
|
50
80
|
else {
|
|
51
|
-
|
|
52
|
-
cliReporter.report(report);
|
|
81
|
+
await runReporter(options.format, report, options, configInstance);
|
|
53
82
|
}
|
|
54
83
|
}
|
|
55
84
|
catch (error) {
|
|
@@ -81,6 +110,7 @@ OPTIONS:
|
|
|
81
110
|
-c, --config Path to config file (default: .config.json)
|
|
82
111
|
-d, --datasource Data source: 'influxdb' or 'prometheus' (default: influxdb)
|
|
83
112
|
-f, --format Output format: 'json', 'cli', 'markdown', or 'slack' (default: cli)
|
|
113
|
+
-r, --report Run one or more reporters (comma-separated): cli, json, markdown, slack
|
|
84
114
|
-o, --output Output file path (for json and markdown formats)
|
|
85
115
|
--no-cache Disable cache, always fetch fresh data
|
|
86
116
|
-h, --help Show command help
|
|
@@ -115,6 +145,12 @@ EXAMPLES:
|
|
|
115
145
|
9. Get help for generate command:
|
|
116
146
|
k6-reporter generate --help
|
|
117
147
|
|
|
148
|
+
10. Run multiple reporters at once:
|
|
149
|
+
k6-reporter generate --run-id 123456790121 --report cli,slack
|
|
150
|
+
|
|
151
|
+
11. Generate Markdown and JSON reports together:
|
|
152
|
+
k6-reporter generate --run-id 123456790121 --report markdown,json -o report
|
|
153
|
+
|
|
118
154
|
TIME FORMAT:
|
|
119
155
|
|
|
120
156
|
Relative times (from now):
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;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E,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,MAAM,WAAW,CAAC,OAAO,CAAC,MAAsB,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,CAAC,CAAC;YACrF,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;YACxE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC,CAAC,CAAC;IAEL,mBAAO;SACJ,OAAO,CAAC,MAAM,CAAC;SACf,WAAW,CAAC,wBAAwB,CAAC;SACrC,MAAM,CAAC,GAAG,EAAE;QACX,OAAO,CAAC,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgGX,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEL,mBAAO,CAAC,KAAK,EAAE,CAAC;AAClB,CAAC;AAED,IAAI,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "k6-perf-reporter",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.1",
|
|
4
4
|
"description": "Reporting tool for k6 performance tests with InfluxDB 2 integration",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -12,8 +12,7 @@
|
|
|
12
12
|
"build": "tsc",
|
|
13
13
|
"start": "node dist/index.js",
|
|
14
14
|
"report": "tsx src/cli.ts",
|
|
15
|
-
"report:example": "tsx src/cli.ts generate --run-id '
|
|
16
|
-
"report:example:json": "LOG_LEVEL=info tsx src/cli.ts generate --run-id '977442' -st '-24h' --format slack",
|
|
15
|
+
"report:example": "LOG_LEVEL=info tsx src/cli.ts generate --run-id '980231' -st '-24h' --report slack,markdown",
|
|
17
16
|
"lint": "eslint src",
|
|
18
17
|
"type-check": "tsc --noEmit"
|
|
19
18
|
},
|
package/src/cli.ts
CHANGED
|
@@ -5,6 +5,49 @@ import { Config, DataSourceType } from "./config";
|
|
|
5
5
|
import { DataCollector } from "./data-collector";
|
|
6
6
|
import { createDataSource } from "./datasources";
|
|
7
7
|
import { JsonReporter, CliReporter, SlackReporter, MarkdownReporter } from "./reporters";
|
|
8
|
+
import { ReporterResponse } from "./types";
|
|
9
|
+
|
|
10
|
+
const VALID_REPORTERS = ["cli", "json", "markdown", "slack"] as const;
|
|
11
|
+
type ReporterName = (typeof VALID_REPORTERS)[number];
|
|
12
|
+
|
|
13
|
+
function defaultOutputPath(name: ReporterName, runId: string): string | undefined {
|
|
14
|
+
const extensions: Partial<Record<ReporterName, string>> = {
|
|
15
|
+
json: "json",
|
|
16
|
+
markdown: "md",
|
|
17
|
+
};
|
|
18
|
+
const ext = extensions[name];
|
|
19
|
+
return ext ? `report-${runId}.${ext}` : undefined;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async function runReporter(
|
|
23
|
+
name: ReporterName,
|
|
24
|
+
report: ReporterResponse,
|
|
25
|
+
options: { output?: string },
|
|
26
|
+
configInstance: Config
|
|
27
|
+
): Promise<void> {
|
|
28
|
+
const output = options.output || defaultOutputPath(name, report.runId);
|
|
29
|
+
switch (name) {
|
|
30
|
+
case "json":
|
|
31
|
+
new JsonReporter().report(report, output);
|
|
32
|
+
break;
|
|
33
|
+
case "markdown":
|
|
34
|
+
new MarkdownReporter().report(report, output);
|
|
35
|
+
break;
|
|
36
|
+
case "slack": {
|
|
37
|
+
const slackConfig = configInstance.getSlackConfig();
|
|
38
|
+
if (!slackConfig) {
|
|
39
|
+
throw new Error("Slack token not configured. Set SLACK_TOKEN environment variable or configure in config file.");
|
|
40
|
+
}
|
|
41
|
+
const slackReporter = new SlackReporter(slackConfig.token, slackConfig.channel);
|
|
42
|
+
await slackReporter.report(report);
|
|
43
|
+
console.log("Report sent to Slack");
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
case "cli":
|
|
47
|
+
new CliReporter().report(report);
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
8
51
|
|
|
9
52
|
function main(): void {
|
|
10
53
|
program
|
|
@@ -21,10 +64,15 @@ function main(): void {
|
|
|
21
64
|
.option("-c, --config <path>", "Path to config file", ".config.json")
|
|
22
65
|
.option("-d, --datasource <type>", "Data source: 'influxdb' or 'prometheus'")
|
|
23
66
|
.option("-f, --format <format>", "Output format: 'json', 'cli', 'markdown', or 'slack'", "cli")
|
|
24
|
-
.option("-
|
|
67
|
+
.option("-r, --report <reporters>", "Run one or more reporters (comma-separated): cli, json, markdown, slack")
|
|
68
|
+
.option("-o, --output <path>", "Output file path (for json and markdown formats)")
|
|
25
69
|
.option("--no-cache", "Disable cache, always fetch fresh data")
|
|
26
70
|
.action(async (options) => {
|
|
27
71
|
try {
|
|
72
|
+
if (options.report && options.format !== "cli") {
|
|
73
|
+
throw new Error("Cannot use --report and --format together. Use --report for multiple reporters.");
|
|
74
|
+
}
|
|
75
|
+
|
|
28
76
|
const configInstance = Config.getInstance(options.config);
|
|
29
77
|
const dsType = (options.datasource || configInstance.getDataSourceType()) as DataSourceType;
|
|
30
78
|
const dataSource = createDataSource(dsType, configInstance);
|
|
@@ -36,23 +84,17 @@ function main(): void {
|
|
|
36
84
|
options.endTime || "now()"
|
|
37
85
|
);
|
|
38
86
|
|
|
39
|
-
if (options.
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (!slackConfig) {
|
|
48
|
-
throw new Error("Slack token not configured. Set SLACK_TOKEN environment variable or configure in config file.");
|
|
87
|
+
if (options.report) {
|
|
88
|
+
const reporters = options.report.split(",").map((r: string) => r.trim());
|
|
89
|
+
const invalid = reporters.filter((r: string) => !VALID_REPORTERS.includes(r as ReporterName));
|
|
90
|
+
if (invalid.length > 0) {
|
|
91
|
+
throw new Error(`Invalid reporter(s): ${invalid.join(", ")}. Valid options: ${VALID_REPORTERS.join(", ")}`);
|
|
92
|
+
}
|
|
93
|
+
for (const name of reporters) {
|
|
94
|
+
await runReporter(name as ReporterName, report, options, configInstance);
|
|
49
95
|
}
|
|
50
|
-
const slackReporter = new SlackReporter(slackConfig.token, slackConfig.channel);
|
|
51
|
-
await slackReporter.report(report);
|
|
52
|
-
console.log("Report sent to Slack");
|
|
53
96
|
} else {
|
|
54
|
-
|
|
55
|
-
cliReporter.report(report);
|
|
97
|
+
await runReporter(options.format as ReporterName, report, options, configInstance);
|
|
56
98
|
}
|
|
57
99
|
} catch (error) {
|
|
58
100
|
console.error("Error:", error instanceof Error ? error.message : error);
|
|
@@ -84,6 +126,7 @@ OPTIONS:
|
|
|
84
126
|
-c, --config Path to config file (default: .config.json)
|
|
85
127
|
-d, --datasource Data source: 'influxdb' or 'prometheus' (default: influxdb)
|
|
86
128
|
-f, --format Output format: 'json', 'cli', 'markdown', or 'slack' (default: cli)
|
|
129
|
+
-r, --report Run one or more reporters (comma-separated): cli, json, markdown, slack
|
|
87
130
|
-o, --output Output file path (for json and markdown formats)
|
|
88
131
|
--no-cache Disable cache, always fetch fresh data
|
|
89
132
|
-h, --help Show command help
|
|
@@ -118,6 +161,12 @@ EXAMPLES:
|
|
|
118
161
|
9. Get help for generate command:
|
|
119
162
|
k6-reporter generate --help
|
|
120
163
|
|
|
164
|
+
10. Run multiple reporters at once:
|
|
165
|
+
k6-reporter generate --run-id 123456790121 --report cli,slack
|
|
166
|
+
|
|
167
|
+
11. Generate Markdown and JSON reports together:
|
|
168
|
+
k6-reporter generate --run-id 123456790121 --report markdown,json -o report
|
|
169
|
+
|
|
121
170
|
TIME FORMAT:
|
|
122
171
|
|
|
123
172
|
Relative times (from now):
|