@jcit/signoz 0.1.1 → 0.1.2
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 +28 -20
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -60,28 +60,36 @@ function parseUntil(input) {
|
|
|
60
60
|
return parseSince(input);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
|
|
63
|
+
const MS_TO_NS = 1e6;
|
|
64
|
+
function buildPromqlRequest(query, startNs, endNs, step) {
|
|
64
65
|
return {
|
|
65
|
-
start,
|
|
66
|
-
end,
|
|
67
|
-
|
|
66
|
+
start: startNs,
|
|
67
|
+
end: endNs,
|
|
68
|
+
step,
|
|
68
69
|
compositeQuery: {
|
|
69
|
-
|
|
70
|
+
queryType: "promql",
|
|
71
|
+
panelType: "time_series",
|
|
72
|
+
promQueries: { A: { query, disabled: false } },
|
|
73
|
+
chQueries: {},
|
|
74
|
+
builderQueries: {}
|
|
70
75
|
}
|
|
71
76
|
};
|
|
72
77
|
}
|
|
73
|
-
function buildSqlRequest(query,
|
|
78
|
+
function buildSqlRequest(query, startNs, endNs) {
|
|
74
79
|
return {
|
|
75
|
-
start,
|
|
76
|
-
end,
|
|
77
|
-
requestType: "time_series",
|
|
80
|
+
start: startNs,
|
|
81
|
+
end: endNs,
|
|
78
82
|
compositeQuery: {
|
|
79
|
-
|
|
83
|
+
queryType: "clickhouse",
|
|
84
|
+
panelType: "time_series",
|
|
85
|
+
chQueries: { A: { query, disabled: false } },
|
|
86
|
+
promQueries: {},
|
|
87
|
+
builderQueries: {}
|
|
80
88
|
}
|
|
81
89
|
};
|
|
82
90
|
}
|
|
83
91
|
function registerQuery(program) {
|
|
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 (
|
|
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 (v3 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) => {
|
|
85
93
|
const modes = [opts.promql, opts.sql, opts.file].filter(Boolean);
|
|
86
94
|
if (modes.length === 0) {
|
|
87
95
|
cmd.error("specify one of --promql, --sql, or --file");
|
|
@@ -90,23 +98,23 @@ function registerQuery(program) {
|
|
|
90
98
|
cmd.error("specify only one of --promql, --sql, or --file");
|
|
91
99
|
}
|
|
92
100
|
const client = createSignozClient({ url: opts.url, token: opts.token });
|
|
93
|
-
const
|
|
94
|
-
const
|
|
101
|
+
const startNs = parseSince(opts.since) * MS_TO_NS;
|
|
102
|
+
const endNs = parseUntil(opts.until) * MS_TO_NS;
|
|
95
103
|
let body;
|
|
96
104
|
if (opts.promql) {
|
|
97
105
|
const step = Number(opts.step);
|
|
98
106
|
if (Number.isNaN(step) || step <= 0) {
|
|
99
107
|
cmd.error(`invalid --step value: "${opts.step}". Provide a positive number in seconds`);
|
|
100
108
|
}
|
|
101
|
-
body = buildPromqlRequest(opts.promql,
|
|
109
|
+
body = buildPromqlRequest(opts.promql, startNs, endNs, step);
|
|
102
110
|
} else if (opts.sql) {
|
|
103
|
-
body = buildSqlRequest(opts.sql,
|
|
111
|
+
body = buildSqlRequest(opts.sql, startNs, endNs);
|
|
104
112
|
} else {
|
|
105
113
|
body = JSON.parse(readFileSync(opts.file, "utf-8"));
|
|
106
|
-
body.start =
|
|
107
|
-
body.end =
|
|
114
|
+
body.start = startNs;
|
|
115
|
+
body.end = endNs;
|
|
108
116
|
}
|
|
109
|
-
const result = await client("/api/
|
|
117
|
+
const result = await client("/api/v3/query_range", {
|
|
110
118
|
method: "POST",
|
|
111
119
|
body
|
|
112
120
|
});
|
|
@@ -114,9 +122,9 @@ function registerQuery(program) {
|
|
|
114
122
|
});
|
|
115
123
|
addExamples(cmd, [
|
|
116
124
|
"signoz query --promql 'rate(http_requests_total[5m])' --since 1h",
|
|
117
|
-
"signoz query --sql 'SELECT count(*)
|
|
125
|
+
"signoz query --sql 'SELECT count(*) FROM signoz_logs.distributed_logs_v2 WHERE timestamp >= ...'",
|
|
118
126
|
"signoz query -f my-query.json --since 7d --until 1d",
|
|
119
|
-
"signoz query --promql 'up' --format table"
|
|
127
|
+
"signoz query --promql 'up' --format table --step 30"
|
|
120
128
|
]);
|
|
121
129
|
}
|
|
122
130
|
|