@jcit/signoz 0.1.2 → 0.1.3
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.mjs +18 -26
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -60,36 +60,28 @@ function parseUntil(input) {
|
|
|
60
60
|
return parseSince(input);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
function buildPromqlRequest(query, startNs, endNs, step) {
|
|
63
|
+
function buildPromqlRequest(query, start, end, step) {
|
|
65
64
|
return {
|
|
66
|
-
start
|
|
67
|
-
end
|
|
68
|
-
|
|
65
|
+
start,
|
|
66
|
+
end,
|
|
67
|
+
requestType: "time_series",
|
|
69
68
|
compositeQuery: {
|
|
70
|
-
|
|
71
|
-
panelType: "time_series",
|
|
72
|
-
promQueries: { A: { query, disabled: false } },
|
|
73
|
-
chQueries: {},
|
|
74
|
-
builderQueries: {}
|
|
69
|
+
queries: [{ type: "promql", spec: { name: "A", query, step, disabled: false } }]
|
|
75
70
|
}
|
|
76
71
|
};
|
|
77
72
|
}
|
|
78
|
-
function buildSqlRequest(query,
|
|
73
|
+
function buildSqlRequest(query, start, end) {
|
|
79
74
|
return {
|
|
80
|
-
start
|
|
81
|
-
end
|
|
75
|
+
start,
|
|
76
|
+
end,
|
|
77
|
+
requestType: "time_series",
|
|
82
78
|
compositeQuery: {
|
|
83
|
-
|
|
84
|
-
panelType: "time_series",
|
|
85
|
-
chQueries: { A: { query, disabled: false } },
|
|
86
|
-
promQueries: {},
|
|
87
|
-
builderQueries: {}
|
|
79
|
+
queries: [{ type: "clickhouse_sql", spec: { name: "A", query, disabled: false } }]
|
|
88
80
|
}
|
|
89
81
|
};
|
|
90
82
|
}
|
|
91
83
|
function registerQuery(program) {
|
|
92
|
-
const cmd = program.command("query").description("Query traces, logs, and metrics via the unified query API").option("--promql <expr>", "PromQL expression").option("--sql <query>", "ClickHouse SQL query (must include timestamp WHERE clause)").option("-f, --file <path>", "Load query from JSON file (
|
|
84
|
+
const cmd = program.command("query").description("Query traces, logs, and metrics via the unified query API").option("--promql <expr>", "PromQL expression").option("--sql <query>", "ClickHouse SQL query (must include timestamp WHERE clause)").option("-f, --file <path>", "Load query from JSON file (v5 query_range format)").option("--since <time>", "Start time: duration ago (1h, 30m, 7d) or ISO date", "1h").option("--until <time>", "End time: 'now', duration ago, or ISO date", "now").option("--step <seconds>", "Step interval in seconds (PromQL only)", "60").option("--format <format>", "Output format: json | table | text", "json").option("--url <url>", "SigNoz API base URL").option("--token <token>", "SigNoz API token").action(async (opts) => {
|
|
93
85
|
const modes = [opts.promql, opts.sql, opts.file].filter(Boolean);
|
|
94
86
|
if (modes.length === 0) {
|
|
95
87
|
cmd.error("specify one of --promql, --sql, or --file");
|
|
@@ -98,23 +90,23 @@ function registerQuery(program) {
|
|
|
98
90
|
cmd.error("specify only one of --promql, --sql, or --file");
|
|
99
91
|
}
|
|
100
92
|
const client = createSignozClient({ url: opts.url, token: opts.token });
|
|
101
|
-
const
|
|
102
|
-
const
|
|
93
|
+
const start = parseSince(opts.since);
|
|
94
|
+
const end = parseUntil(opts.until);
|
|
103
95
|
let body;
|
|
104
96
|
if (opts.promql) {
|
|
105
97
|
const step = Number(opts.step);
|
|
106
98
|
if (Number.isNaN(step) || step <= 0) {
|
|
107
99
|
cmd.error(`invalid --step value: "${opts.step}". Provide a positive number in seconds`);
|
|
108
100
|
}
|
|
109
|
-
body = buildPromqlRequest(opts.promql,
|
|
101
|
+
body = buildPromqlRequest(opts.promql, start, end, step);
|
|
110
102
|
} else if (opts.sql) {
|
|
111
|
-
body = buildSqlRequest(opts.sql,
|
|
103
|
+
body = buildSqlRequest(opts.sql, start, end);
|
|
112
104
|
} else {
|
|
113
105
|
body = JSON.parse(readFileSync(opts.file, "utf-8"));
|
|
114
|
-
body.start =
|
|
115
|
-
body.end =
|
|
106
|
+
body.start = start;
|
|
107
|
+
body.end = end;
|
|
116
108
|
}
|
|
117
|
-
const result = await client("/api/
|
|
109
|
+
const result = await client("/api/v5/query_range", {
|
|
118
110
|
method: "POST",
|
|
119
111
|
body
|
|
120
112
|
});
|