@lark-apaas/miaoda-cli 0.1.2-alpha.dd636c5 → 0.1.2-alpha.fb3be7a
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/README.md +8 -7
- package/dist/api/deploy/schemas.js +3 -1
- package/dist/api/observability/schemas.js +22 -1
- package/dist/cli/commands/app/index.js +3 -3
- package/dist/cli/commands/db/index.js +6 -5
- package/dist/cli/commands/deploy/index.js +29 -12
- package/dist/cli/commands/file/index.js +6 -5
- package/dist/cli/commands/index.js +10 -12
- package/dist/cli/commands/observability/index.js +23 -13
- package/dist/cli/commands/shared.js +24 -6
- package/dist/cli/handlers/app/get.js +2 -3
- package/dist/cli/handlers/app/update.js +4 -4
- package/dist/cli/handlers/db/data.js +2 -3
- package/dist/cli/handlers/db/schema.js +2 -3
- package/dist/cli/handlers/db/sql.js +1 -2
- package/dist/cli/handlers/deploy/deploy.js +4 -3
- package/dist/cli/handlers/deploy/error-log.js +4 -5
- package/dist/cli/handlers/deploy/format.js +39 -0
- package/dist/cli/handlers/deploy/get.js +5 -4
- package/dist/cli/handlers/deploy/helpers.js +4 -4
- package/dist/cli/handlers/deploy/history.js +3 -3
- package/dist/cli/handlers/deploy/polling.js +26 -3
- package/dist/cli/handlers/file/cp.js +1 -2
- package/dist/cli/handlers/file/ls.js +1 -2
- package/dist/cli/handlers/file/rm.js +1 -2
- package/dist/cli/handlers/file/sign.js +1 -2
- package/dist/cli/handlers/file/stat.js +1 -2
- package/dist/cli/handlers/observability/analytics.js +30 -8
- package/dist/cli/handlers/observability/helpers.js +2 -2
- package/dist/cli/handlers/observability/log.js +5 -5
- package/dist/cli/handlers/observability/metric.js +4 -4
- package/dist/cli/handlers/observability/trace.js +4 -4
- package/dist/main.js +6 -2
- package/dist/utils/args.js +8 -0
- package/dist/utils/http.js +34 -2
- package/dist/utils/time.js +82 -11
- package/package.json +1 -1
|
@@ -36,17 +36,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.handleDeploy = handleDeploy;
|
|
37
37
|
const api = __importStar(require("../../../api/index"));
|
|
38
38
|
const output_1 = require("../../../utils/output");
|
|
39
|
-
const shared_1 = require("../../../cli/commands/shared");
|
|
40
39
|
const index_1 = require("../../../api/deploy/index");
|
|
41
40
|
const polling_1 = require("./polling");
|
|
41
|
+
const format_1 = require("./format");
|
|
42
42
|
/** miaoda deploy [--branch ...] [--wait] [--timeout 300] */
|
|
43
43
|
async function handleDeploy(opts) {
|
|
44
|
-
const appID =
|
|
44
|
+
const appID = opts.appId;
|
|
45
45
|
const resp = await api.deploy.createRelease({ appID, branch: opts.branch });
|
|
46
46
|
const pipelineTaskID = resp.pipelineTaskID ?? "";
|
|
47
47
|
if (!opts.wait) {
|
|
48
48
|
if (!(0, output_1.isJsonMode)()) {
|
|
49
49
|
process.stdout.write(`✓ Deployment triggered. (deploy-id: ${pipelineTaskID})\n`);
|
|
50
|
+
process.stdout.write(` hint: No terminal status yet. Poll every 2s with \`miaoda deploy get ${pipelineTaskID} --json\`; if no deploy-id is visible, first get it from \`miaoda deploy history --limit 1 --json\`.\n`);
|
|
50
51
|
}
|
|
51
52
|
(0, output_1.emit)({
|
|
52
53
|
data: { pipelineTaskID },
|
|
@@ -76,7 +77,7 @@ async function handleDeploy(opts) {
|
|
|
76
77
|
}
|
|
77
78
|
}
|
|
78
79
|
(0, output_1.emit)({
|
|
79
|
-
data: { pipelineTaskID, detail },
|
|
80
|
+
data: { pipelineTaskID, detail: (0, format_1.formatPipelineInstance)(detail) },
|
|
80
81
|
next_cursor: null,
|
|
81
82
|
has_more: false,
|
|
82
83
|
});
|
|
@@ -36,24 +36,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.handleDeployErrorLog = handleDeployErrorLog;
|
|
37
37
|
const api = __importStar(require("../../../api/index"));
|
|
38
38
|
const output_1 = require("../../../utils/output");
|
|
39
|
-
const
|
|
39
|
+
const args_1 = require("../../../utils/args");
|
|
40
40
|
const index_1 = require("../../../api/deploy/index");
|
|
41
41
|
const helpers_1 = require("./helpers");
|
|
42
42
|
/** miaoda deploy error-log <deploy-id> */
|
|
43
43
|
async function handleDeployErrorLog(opts) {
|
|
44
44
|
if (!opts.deployId)
|
|
45
|
-
(0,
|
|
46
|
-
const appID =
|
|
45
|
+
(0, args_1.failArgs)("<deploy-id> 必填");
|
|
46
|
+
const appID = opts.appId;
|
|
47
47
|
(0, helpers_1.parseDeployId)(opts.deployId); // 仅校验数字形式;URL 直接用原字符串
|
|
48
48
|
const instanceID = opts.deployId;
|
|
49
49
|
const resp = await api.deploy.getErrorLog({ appID, instanceID });
|
|
50
|
-
// 信封带上 status 元信息(非 errorJobs 主体),便于 JSON 消费方读取
|
|
51
50
|
(0, output_1.emit)({
|
|
52
51
|
data: resp.errorJobs,
|
|
53
52
|
next_cursor: null,
|
|
54
53
|
has_more: false,
|
|
55
54
|
}, index_1.errorJobSchema);
|
|
56
|
-
// pretty
|
|
55
|
+
// pretty 模式额外打一行整体状态。
|
|
57
56
|
if (!process.stdout.isTTY)
|
|
58
57
|
return;
|
|
59
58
|
const statusText = (0, index_1.nodeStatusText)(resp.status) ?? String(resp.status);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatStatusMetadata = formatStatusMetadata;
|
|
4
|
+
exports.formatSimpleInstance = formatSimpleInstance;
|
|
5
|
+
exports.formatPipelineInstance = formatPipelineInstance;
|
|
6
|
+
const index_1 = require("../../../api/deploy/index");
|
|
7
|
+
function formatStatusMetadata(statusCode) {
|
|
8
|
+
return {
|
|
9
|
+
status: (0, index_1.nodeStatusText)(statusCode) ?? `unknown(${String(statusCode)})`,
|
|
10
|
+
status_code: statusCode,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function formatSimpleInstance(instance) {
|
|
14
|
+
if (instance.status === undefined)
|
|
15
|
+
return { ...instance };
|
|
16
|
+
return {
|
|
17
|
+
...instance,
|
|
18
|
+
...formatStatusMetadata(instance.status),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function formatPipelineInstance(detail) {
|
|
22
|
+
const stages = Array.isArray(detail.stages) ? detail.stages : [];
|
|
23
|
+
return {
|
|
24
|
+
...detail,
|
|
25
|
+
...formatStatusMetadata(detail.status),
|
|
26
|
+
stages: stages.map((stage) => ({
|
|
27
|
+
...stage,
|
|
28
|
+
...formatStatusMetadata(stage.status),
|
|
29
|
+
jobs: stage.jobs.map((group) => group.map((job) => ({
|
|
30
|
+
...job,
|
|
31
|
+
...formatStatusMetadata(job.status),
|
|
32
|
+
steps: job.steps?.map((step) => ({
|
|
33
|
+
...step,
|
|
34
|
+
...formatStatusMetadata(step.status),
|
|
35
|
+
})),
|
|
36
|
+
}))),
|
|
37
|
+
})),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -36,10 +36,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.handleDeployGet = handleDeployGet;
|
|
37
37
|
const api = __importStar(require("../../../api/index"));
|
|
38
38
|
const output_1 = require("../../../utils/output");
|
|
39
|
-
const
|
|
39
|
+
const args_1 = require("../../../utils/args");
|
|
40
40
|
const error_1 = require("../../../utils/error");
|
|
41
41
|
const index_1 = require("../../../api/deploy/index");
|
|
42
42
|
const helpers_1 = require("./helpers");
|
|
43
|
+
const format_1 = require("./format");
|
|
43
44
|
/**
|
|
44
45
|
* 单页拉取上限:BAM listPipelineInstances 限制 1~500,取 500 让 deploy get
|
|
45
46
|
* 在最近 500 条记录里按 ID 命中。
|
|
@@ -53,8 +54,8 @@ const DEPLOY_GET_LOOKUP_LIMIT = 500;
|
|
|
53
54
|
*/
|
|
54
55
|
async function handleDeployGet(opts) {
|
|
55
56
|
if (!opts.deployId)
|
|
56
|
-
(0,
|
|
57
|
-
const appID =
|
|
57
|
+
(0, args_1.failArgs)("<deploy-id> 必填");
|
|
58
|
+
const appID = opts.appId;
|
|
58
59
|
const deployId = (0, helpers_1.parseDeployId)(opts.deployId);
|
|
59
60
|
const resp = await api.deploy.listPipelineInstances({
|
|
60
61
|
appID,
|
|
@@ -66,5 +67,5 @@ async function handleDeployGet(opts) {
|
|
|
66
67
|
next_actions: ["运行 `miaoda deploy history` 确认 deploy-id 是否在最近窗口内"],
|
|
67
68
|
});
|
|
68
69
|
}
|
|
69
|
-
(0, output_1.emit)({ data: instance, next_cursor: null, has_more: false }, index_1.deployGetSchema);
|
|
70
|
+
(0, output_1.emit)({ data: (0, format_1.formatSimpleInstance)(instance), next_cursor: null, has_more: false }, index_1.deployGetSchema);
|
|
70
71
|
}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.parseStatusFlag = parseStatusFlag;
|
|
4
4
|
exports.validateLimit = validateLimit;
|
|
5
5
|
exports.parseDeployId = parseDeployId;
|
|
6
|
-
const
|
|
6
|
+
const args_1 = require("../../../utils/args");
|
|
7
7
|
const index_1 = require("../../../api/deploy/index");
|
|
8
8
|
/**
|
|
9
9
|
* 把 CLI --status 字符串映射成 BAM NodeStatus 数字;非法值抛 ARGS_INVALID。
|
|
@@ -14,7 +14,7 @@ const index_1 = require("../../../api/deploy/index");
|
|
|
14
14
|
function parseStatusFlag(text) {
|
|
15
15
|
const value = (0, index_1.nodeStatusFromText)(text);
|
|
16
16
|
if (value === undefined) {
|
|
17
|
-
(0,
|
|
17
|
+
(0, args_1.failArgs)(`--status 无效:'${text}'。可选值:todo | running | success | failed | canceled | hold_on`);
|
|
18
18
|
}
|
|
19
19
|
return value;
|
|
20
20
|
}
|
|
@@ -22,7 +22,7 @@ function parseStatusFlag(text) {
|
|
|
22
22
|
function validateLimit(limit, defaultLimit = 50) {
|
|
23
23
|
const n = Number.isFinite(limit) ? limit : defaultLimit;
|
|
24
24
|
if (n <= 0 || n > 100) {
|
|
25
|
-
(0,
|
|
25
|
+
(0, args_1.failArgs)(`--limit 必须在 1~100 之间,收到 ${String(n)}`);
|
|
26
26
|
}
|
|
27
27
|
return n;
|
|
28
28
|
}
|
|
@@ -35,7 +35,7 @@ function validateLimit(limit, defaultLimit = 50) {
|
|
|
35
35
|
function parseDeployId(text) {
|
|
36
36
|
const n = Number(text);
|
|
37
37
|
if (!Number.isFinite(n) || !/^\d+$/.test(text)) {
|
|
38
|
-
(0,
|
|
38
|
+
(0, args_1.failArgs)(`<deploy-id> 必须是数字 ID,收到 '${text}'`);
|
|
39
39
|
}
|
|
40
40
|
return n;
|
|
41
41
|
}
|
|
@@ -36,13 +36,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.handleDeployHistory = handleDeployHistory;
|
|
37
37
|
const api = __importStar(require("../../../api/index"));
|
|
38
38
|
const output_1 = require("../../../utils/output");
|
|
39
|
-
const shared_1 = require("../../../cli/commands/shared");
|
|
40
39
|
const time_1 = require("../../../utils/time");
|
|
41
40
|
const index_1 = require("../../../api/deploy/index");
|
|
42
41
|
const helpers_1 = require("./helpers");
|
|
42
|
+
const format_1 = require("./format");
|
|
43
43
|
/** miaoda deploy history */
|
|
44
44
|
async function handleDeployHistory(opts) {
|
|
45
|
-
const appID =
|
|
45
|
+
const appID = opts.appId;
|
|
46
46
|
const limit = (0, helpers_1.validateLimit)(opts.limit ?? 50);
|
|
47
47
|
const req = {
|
|
48
48
|
appID,
|
|
@@ -58,7 +58,7 @@ async function handleDeployHistory(opts) {
|
|
|
58
58
|
req.endTimestamp = msToSec((0, time_1.parseToMs)(opts.until));
|
|
59
59
|
const resp = await api.deploy.listPipelineInstances(req);
|
|
60
60
|
(0, output_1.emit)({
|
|
61
|
-
data: resp.instances ?? [],
|
|
61
|
+
data: (resp.instances ?? []).map(format_1.formatSimpleInstance),
|
|
62
62
|
next_cursor: resp.hasMore ? (resp.nextPageToken ?? null) : null,
|
|
63
63
|
has_more: resp.hasMore ?? false,
|
|
64
64
|
}, index_1.deployHistorySchema);
|
|
@@ -82,7 +82,7 @@ async function waitForPipeline(opts) {
|
|
|
82
82
|
appID: opts.appID,
|
|
83
83
|
instanceID: opts.pipelineTaskID,
|
|
84
84
|
});
|
|
85
|
-
const detail = resp
|
|
85
|
+
const detail = normalizePipelineInstance(resp);
|
|
86
86
|
if (spinner)
|
|
87
87
|
advanceProgress(detail, printedStages, spinner);
|
|
88
88
|
if (TERMINAL_STATUSES.includes(detail.status)) {
|
|
@@ -109,7 +109,8 @@ async function waitForPipeline(opts) {
|
|
|
109
109
|
* 再把 spinner 文本切到当前 running stage;没有 running 时显示"等待调度"。
|
|
110
110
|
*/
|
|
111
111
|
function advanceProgress(detail, printed, spinner) {
|
|
112
|
-
|
|
112
|
+
const stages = Array.isArray(detail.stages) ? detail.stages : [];
|
|
113
|
+
for (const stage of stages) {
|
|
113
114
|
if (printed.has(stage.id))
|
|
114
115
|
continue;
|
|
115
116
|
if (!TERMINAL_STATUSES.includes(stage.status))
|
|
@@ -120,7 +121,7 @@ function advanceProgress(detail, printed, spinner) {
|
|
|
120
121
|
});
|
|
121
122
|
printed.add(stage.id);
|
|
122
123
|
}
|
|
123
|
-
const running =
|
|
124
|
+
const running = stages.find((s) => s.status === index_1.NodeStatus.RUNNING);
|
|
124
125
|
const text = running ? `${running.name} 执行中` : "等待调度";
|
|
125
126
|
if (spinner.isSpinning) {
|
|
126
127
|
spinner.text = text;
|
|
@@ -129,6 +130,28 @@ function advanceProgress(detail, printed, spinner) {
|
|
|
129
130
|
spinner.start(text);
|
|
130
131
|
}
|
|
131
132
|
}
|
|
133
|
+
function normalizePipelineInstance(resp) {
|
|
134
|
+
const keyedDetail = readPipelineDetail(resp, "pipelineInstanceDetail") ?? readPipelineDetail(resp, "detail");
|
|
135
|
+
if (keyedDetail)
|
|
136
|
+
return keyedDetail;
|
|
137
|
+
if (isPipelineInstance(resp))
|
|
138
|
+
return resp;
|
|
139
|
+
throw new error_1.AppError("DEPLOY_RESPONSE_INVALID", "发布状态响应缺少 pipeline detail", {
|
|
140
|
+
next_actions: ["使用 --verbose 重试以查看请求 logid,并联系平台排查响应结构"],
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
function readPipelineDetail(resp, key) {
|
|
144
|
+
if (!(key in resp))
|
|
145
|
+
return undefined;
|
|
146
|
+
const detail = resp[key];
|
|
147
|
+
return isPipelineInstance(detail) ? detail : undefined;
|
|
148
|
+
}
|
|
149
|
+
function isPipelineInstance(value) {
|
|
150
|
+
if (typeof value !== "object" || value === null)
|
|
151
|
+
return false;
|
|
152
|
+
const item = value;
|
|
153
|
+
return typeof item.status === "number";
|
|
154
|
+
}
|
|
132
155
|
function stageSymbol(stage) {
|
|
133
156
|
return stage.status === index_1.NodeStatus.SUCCESS ? "✓" : stage.status === index_1.NodeStatus.FAILED ? "✗" : "•";
|
|
134
157
|
}
|
|
@@ -44,7 +44,6 @@ const api = __importStar(require("../../../api/index"));
|
|
|
44
44
|
const output_1 = require("../../../utils/output");
|
|
45
45
|
const render_1 = require("../../../utils/render");
|
|
46
46
|
const error_1 = require("../../../utils/error");
|
|
47
|
-
const shared_1 = require("../../../cli/commands/shared");
|
|
48
47
|
const colors_1 = require("../../../utils/colors");
|
|
49
48
|
const MAX_UPLOAD_BYTES = 100 * 1024 * 1024;
|
|
50
49
|
/**
|
|
@@ -233,7 +232,7 @@ async function handleDownload(appId, remoteRaw, localRaw) {
|
|
|
233
232
|
}
|
|
234
233
|
}
|
|
235
234
|
async function handleFileCp(src, dst, opts) {
|
|
236
|
-
const appId =
|
|
235
|
+
const appId = opts.appId;
|
|
237
236
|
// src 本地存在 → upload;其他情况(file_ref / `/path` / 裸文件名)→ download
|
|
238
237
|
if (isLocalSrc(src)) {
|
|
239
238
|
return handleUpload(appId, src, dst, opts.rename);
|
|
@@ -38,7 +38,6 @@ const api = __importStar(require("../../../api/index"));
|
|
|
38
38
|
const output_1 = require("../../../utils/output");
|
|
39
39
|
const render_1 = require("../../../utils/render");
|
|
40
40
|
const error_1 = require("../../../utils/error");
|
|
41
|
-
const shared_1 = require("../../../cli/commands/shared");
|
|
42
41
|
const index_1 = require("../../../api/file/index");
|
|
43
42
|
/**
|
|
44
43
|
* 把位置参数 `query` 路由到 `--path` 或 `--name`:
|
|
@@ -65,7 +64,7 @@ function resolveQueryRouting(opts) {
|
|
|
65
64
|
return { name: opts.query };
|
|
66
65
|
}
|
|
67
66
|
async function handleFileLs(opts) {
|
|
68
|
-
const appId =
|
|
67
|
+
const appId = opts.appId;
|
|
69
68
|
// commander 已经把 --limit 解析为 number;保留 ?? undefined 兼容老调用
|
|
70
69
|
const limit = opts.limit;
|
|
71
70
|
const sizeGt = opts.sizeGt ? (0, render_1.parseSize)(opts.sizeGt) : undefined;
|
|
@@ -40,7 +40,6 @@ exports.handleFileRm = handleFileRm;
|
|
|
40
40
|
const api = __importStar(require("../../../api/index"));
|
|
41
41
|
const output_1 = require("../../../utils/output");
|
|
42
42
|
const error_1 = require("../../../utils/error");
|
|
43
|
-
const shared_1 = require("../../../cli/commands/shared");
|
|
44
43
|
const index_1 = require("../../../api/file/index");
|
|
45
44
|
const render_1 = require("../../../utils/render");
|
|
46
45
|
const colors_1 = require("../../../utils/colors");
|
|
@@ -133,7 +132,7 @@ async function handleFileRm(paths, opts) {
|
|
|
133
132
|
if (totalCount > MAX_BATCH) {
|
|
134
133
|
throw new error_1.AppError("FILE_BATCH_TOO_MANY", `Batch size ${String(totalCount)} exceeds the 100 limit`);
|
|
135
134
|
}
|
|
136
|
-
const appId =
|
|
135
|
+
const appId = opts.appId;
|
|
137
136
|
// destructive guardrail
|
|
138
137
|
const tty = (0, render_1.isStdoutTty)();
|
|
139
138
|
if (tty && !opts.yes) {
|
|
@@ -38,7 +38,6 @@ const api = __importStar(require("../../../api/index"));
|
|
|
38
38
|
const output_1 = require("../../../utils/output");
|
|
39
39
|
const render_1 = require("../../../utils/render");
|
|
40
40
|
const error_1 = require("../../../utils/error");
|
|
41
|
-
const shared_1 = require("../../../cli/commands/shared");
|
|
42
41
|
const index_1 = require("../../../api/file/index");
|
|
43
42
|
const MAX_EXPIRES_SECONDS = 30 * 86400;
|
|
44
43
|
const DEFAULT_EXPIRES_SECONDS = 86400; // 1d(PRD 规定)
|
|
@@ -64,7 +63,7 @@ async function resolveFilePath(appId, input) {
|
|
|
64
63
|
return resolved.file.path;
|
|
65
64
|
}
|
|
66
65
|
async function handleFileSign(file, opts) {
|
|
67
|
-
const appId =
|
|
66
|
+
const appId = opts.appId;
|
|
68
67
|
let expiresSec = DEFAULT_EXPIRES_SECONDS;
|
|
69
68
|
if (opts.expires) {
|
|
70
69
|
expiresSec = (0, render_1.parseDuration)(opts.expires);
|
|
@@ -38,7 +38,6 @@ const api = __importStar(require("../../../api/index"));
|
|
|
38
38
|
const output_1 = require("../../../utils/output");
|
|
39
39
|
const render_1 = require("../../../utils/render");
|
|
40
40
|
const error_1 = require("../../../utils/error");
|
|
41
|
-
const shared_1 = require("../../../cli/commands/shared");
|
|
42
41
|
const index_1 = require("../../../api/file/index");
|
|
43
42
|
/**
|
|
44
43
|
* 解析 `<file>` 为后端 head 可用的 filePath。
|
|
@@ -67,7 +66,7 @@ async function resolveFile(appId, input) {
|
|
|
67
66
|
return head;
|
|
68
67
|
}
|
|
69
68
|
async function handleFileStat(file, opts) {
|
|
70
|
-
const appId =
|
|
69
|
+
const appId = opts.appId;
|
|
71
70
|
const info = await resolveFile(appId, file);
|
|
72
71
|
if ((0, output_1.isJsonMode)()) {
|
|
73
72
|
(0, output_1.emitOk)(info);
|
|
@@ -36,7 +36,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.handleObservabilityAnalytics = handleObservabilityAnalytics;
|
|
37
37
|
const api = __importStar(require("../../../api/index"));
|
|
38
38
|
const output_1 = require("../../../utils/output");
|
|
39
|
-
const
|
|
39
|
+
const args_1 = require("../../../utils/args");
|
|
40
40
|
const helpers_1 = require("./helpers");
|
|
41
41
|
const GRANULARITY_TO_UNIT = {
|
|
42
42
|
day: "DAY",
|
|
@@ -68,8 +68,8 @@ const ANALYTICS_LABELS = {
|
|
|
68
68
|
/** miaoda observability analytics <analytics-name> */
|
|
69
69
|
async function handleObservabilityAnalytics(opts) {
|
|
70
70
|
if (!opts.analyticsName)
|
|
71
|
-
(0,
|
|
72
|
-
const appID =
|
|
71
|
+
(0, args_1.failArgs)("<analytics-name> 必填");
|
|
72
|
+
const appID = opts.appId;
|
|
73
73
|
const { metricTypes, labelByMetric, extraFilters } = resolveAnalyticsSelection(opts.analyticsName, opts.series);
|
|
74
74
|
const timeAggregationUnit = opts.granularity
|
|
75
75
|
? (GRANULARITY_TO_UNIT[opts.granularity] ?? opts.granularity.toUpperCase())
|
|
@@ -149,22 +149,23 @@ function buildAnalyticsPivotSchema(seriesLabels) {
|
|
|
149
149
|
*/
|
|
150
150
|
function resolveAnalyticsSelection(cliName, series) {
|
|
151
151
|
const extras = [];
|
|
152
|
+
const normalizedSeries = normalizeAnalyticsSeries(cliName, series);
|
|
152
153
|
if (cliName === "users") {
|
|
153
|
-
if (
|
|
154
|
+
if (normalizedSeries === "active-users")
|
|
154
155
|
return single("ACTIVE_USER", "active-users", extras);
|
|
155
|
-
if (
|
|
156
|
+
if (normalizedSeries === "new-users")
|
|
156
157
|
return single("NEW_USER", "new-users", extras);
|
|
157
|
-
if (
|
|
158
|
+
if (normalizedSeries === "total-users")
|
|
158
159
|
return single("TOTAL_USER", "total-users", extras);
|
|
159
160
|
// 缺省:三条线
|
|
160
161
|
return all(ANALYTICS_LABELS.users, extras);
|
|
161
162
|
}
|
|
162
163
|
if (cliName === "page-view") {
|
|
163
|
-
if (
|
|
164
|
+
if (normalizedSeries === "desktop-view") {
|
|
164
165
|
extras.push({ key: "device_type", value: (0, helpers_1.eqFilter)("desktop") });
|
|
165
166
|
return single("PAGE_VIEW", "desktop-view", extras);
|
|
166
167
|
}
|
|
167
|
-
if (
|
|
168
|
+
if (normalizedSeries === "mobile-view") {
|
|
168
169
|
extras.push({ key: "device_type", value: (0, helpers_1.eqFilter)("mobile") });
|
|
169
170
|
return single("PAGE_VIEW", "mobile-view", extras);
|
|
170
171
|
}
|
|
@@ -174,6 +175,27 @@ function resolveAnalyticsSelection(cliName, series) {
|
|
|
174
175
|
// 兜底:CLI 名直接当 metricType + label
|
|
175
176
|
return single(cliName, cliName, extras);
|
|
176
177
|
}
|
|
178
|
+
function normalizeAnalyticsSeries(cliName, series) {
|
|
179
|
+
if (series === undefined)
|
|
180
|
+
return undefined;
|
|
181
|
+
if (cliName === "users") {
|
|
182
|
+
if (series === "active")
|
|
183
|
+
return "active-users";
|
|
184
|
+
if (series === "new")
|
|
185
|
+
return "new-users";
|
|
186
|
+
if (series === "total")
|
|
187
|
+
return "total-users";
|
|
188
|
+
}
|
|
189
|
+
if (cliName === "page-view") {
|
|
190
|
+
if (series === "all")
|
|
191
|
+
return "all-view";
|
|
192
|
+
if (series === "desktop")
|
|
193
|
+
return "desktop-view";
|
|
194
|
+
if (series === "mobile")
|
|
195
|
+
return "mobile-view";
|
|
196
|
+
}
|
|
197
|
+
return series;
|
|
198
|
+
}
|
|
177
199
|
function single(metricType, label, extras) {
|
|
178
200
|
return {
|
|
179
201
|
metricTypes: [metricType],
|
|
@@ -6,7 +6,7 @@ exports.rangeFilter = rangeFilter;
|
|
|
6
6
|
exports.fuzzyFilter = fuzzyFilter;
|
|
7
7
|
exports.buildFieldFilters = buildFieldFilters;
|
|
8
8
|
exports.validateLimit = validateLimit;
|
|
9
|
-
const
|
|
9
|
+
const args_1 = require("../../../utils/args");
|
|
10
10
|
const index_1 = require("../../../api/observability/index");
|
|
11
11
|
// 时间解析助手已抽到 utils/time.ts;这里 re-export 维持 observability handler 的旧 import 路径。
|
|
12
12
|
var time_1 = require("../../../utils/time");
|
|
@@ -60,7 +60,7 @@ function buildFieldFilters(entries) {
|
|
|
60
60
|
function validateLimit(limit, defaultLimit = 50) {
|
|
61
61
|
const n = Number.isFinite(limit) ? limit : defaultLimit;
|
|
62
62
|
if (n <= 0 || n > 100) {
|
|
63
|
-
(0,
|
|
63
|
+
(0, args_1.failArgs)(`--limit 必须在 1~100 之间,收到 ${String(n)}`);
|
|
64
64
|
}
|
|
65
65
|
return n;
|
|
66
66
|
}
|
|
@@ -36,21 +36,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.handleObservabilityLog = handleObservabilityLog;
|
|
37
37
|
const api = __importStar(require("../../../api/index"));
|
|
38
38
|
const output_1 = require("../../../utils/output");
|
|
39
|
-
const shared_1 = require("../../../cli/commands/shared");
|
|
40
39
|
const index_1 = require("../../../api/observability/index");
|
|
41
40
|
const helpers_1 = require("./helpers");
|
|
42
41
|
/** miaoda observability log */
|
|
43
42
|
async function handleObservabilityLog(opts) {
|
|
44
|
-
const appID =
|
|
43
|
+
const appID = opts.appId;
|
|
45
44
|
const appEnv = "runtime";
|
|
46
45
|
const limit = (0, helpers_1.validateLimit)(opts.limit ?? 50);
|
|
47
|
-
// 过滤 key 对齐 BAM
|
|
48
|
-
// - 顶层字段:severityText / traceID
|
|
49
|
-
// - attributes 里的业务字段:module / user_id / page / api(snake_case,
|
|
46
|
+
// 过滤 key 对齐 BAM 查询字段名:
|
|
47
|
+
// - 顶层字段:severity_text / trace_id(输出仍映射成 severityText / traceID)
|
|
48
|
+
// - attributes 里的业务字段:module / user_id / page / api / ob_data_id(snake_case,
|
|
50
49
|
// 依据 BAM IDL 的 LogItem.attributes 描述:"包括 tenant_id, module, user_id, page, api 等")
|
|
51
50
|
// - duration_ms 暂未在 BAM 描述里明确列出,留 TODO 等 e2e 验证
|
|
52
51
|
const fieldFilters = (0, helpers_1.buildFieldFilters)([
|
|
53
52
|
{ key: "severity_text", value: opts.level ? (0, helpers_1.eqFilter)(opts.level) : undefined },
|
|
53
|
+
{ key: "attributes.ob_data_id", value: opts.logId ? (0, helpers_1.eqFilter)(opts.logId) : undefined },
|
|
54
54
|
{ key: "trace_id", value: opts.traceId ? (0, helpers_1.eqFilter)(opts.traceId) : undefined },
|
|
55
55
|
{ key: "module", value: opts.module ? (0, helpers_1.eqFilter)(opts.module) : undefined },
|
|
56
56
|
{ key: "user_id", value: opts.userId ? (0, helpers_1.eqFilter)(opts.userId, "i64") : undefined },
|
|
@@ -36,7 +36,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.handleObservabilityMetric = handleObservabilityMetric;
|
|
37
37
|
const api = __importStar(require("../../../api/index"));
|
|
38
38
|
const output_1 = require("../../../utils/output");
|
|
39
|
-
const
|
|
39
|
+
const args_1 = require("../../../utils/args");
|
|
40
40
|
const helpers_1 = require("./helpers");
|
|
41
41
|
/**
|
|
42
42
|
* PRD <metric-name> + --series → 服务端 metric name → 表头列名(=对应 --series 取值)。
|
|
@@ -61,8 +61,8 @@ const METRIC_LABELS = {
|
|
|
61
61
|
/** miaoda observability metric <metric-name> */
|
|
62
62
|
async function handleObservabilityMetric(opts) {
|
|
63
63
|
if (!opts.metricName)
|
|
64
|
-
(0,
|
|
65
|
-
const appID =
|
|
64
|
+
(0, args_1.failArgs)("<metric-name> 必填");
|
|
65
|
+
const appID = opts.appId;
|
|
66
66
|
const { metricNames, labelByMetric, extraFilters } = resolveMetricSelection(opts.metricName, opts.series);
|
|
67
67
|
const filters = (0, helpers_1.buildFieldFilters)([
|
|
68
68
|
{ key: "referer_path", value: opts.page ? (0, helpers_1.eqFilter)(opts.page) : undefined },
|
|
@@ -71,7 +71,7 @@ async function handleObservabilityMetric(opts) {
|
|
|
71
71
|
]);
|
|
72
72
|
// since/until 直接以秒透传到 BAM;当前未做桶对齐(如需开启把 until
|
|
73
73
|
// 用 ceilMsToBucket(untilMs, downSample as GranularityBucket) 包一层即可)。
|
|
74
|
-
const downSample = opts.downSample ?? "
|
|
74
|
+
const downSample = opts.downSample ?? "1m";
|
|
75
75
|
const nowMs = Date.now();
|
|
76
76
|
const sinceMs = (0, helpers_1.parseToMs)(opts.since) ?? nowMs - 30 * 86_400_000;
|
|
77
77
|
const untilMs = (0, helpers_1.parseToMs)(opts.until) ?? nowMs;
|
|
@@ -37,12 +37,12 @@ exports.handleObservabilityTraceList = handleObservabilityTraceList;
|
|
|
37
37
|
exports.handleObservabilityTraceGet = handleObservabilityTraceGet;
|
|
38
38
|
const api = __importStar(require("../../../api/index"));
|
|
39
39
|
const output_1 = require("../../../utils/output");
|
|
40
|
-
const
|
|
40
|
+
const args_1 = require("../../../utils/args");
|
|
41
41
|
const index_1 = require("../../../api/observability/index");
|
|
42
42
|
const helpers_1 = require("./helpers");
|
|
43
43
|
/** miaoda observability trace list */
|
|
44
44
|
async function handleObservabilityTraceList(opts) {
|
|
45
|
-
const appID =
|
|
45
|
+
const appID = opts.appId;
|
|
46
46
|
const appEnv = "runtime";
|
|
47
47
|
const limit = (0, helpers_1.validateLimit)(opts.limit ?? 50);
|
|
48
48
|
// 过滤 key 对齐 BAM Span 字段名:
|
|
@@ -77,8 +77,8 @@ function emitSearchTracesResponse(resp) {
|
|
|
77
77
|
/** miaoda observability trace get <trace-id> */
|
|
78
78
|
async function handleObservabilityTraceGet(opts) {
|
|
79
79
|
if (!opts.traceId)
|
|
80
|
-
(0,
|
|
81
|
-
const appID =
|
|
80
|
+
(0, args_1.failArgs)("<trace-id> 必填");
|
|
81
|
+
const appID = opts.appId;
|
|
82
82
|
const appEnv = "runtime";
|
|
83
83
|
const resp = await api.observability.getTraces({
|
|
84
84
|
appID,
|
package/dist/main.js
CHANGED
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const commander_1 = require("commander");
|
|
7
7
|
const index_1 = require("./cli/commands/index");
|
|
8
|
+
const shared_1 = require("./cli/commands/shared");
|
|
8
9
|
const help_1 = require("./cli/help");
|
|
9
10
|
const config_1 = require("./utils/config");
|
|
10
11
|
const log_id_1 = require("./utils/log_id");
|
|
@@ -20,11 +21,14 @@ const program = new commander_1.Command();
|
|
|
20
21
|
const { version } = package_json_1.default;
|
|
21
22
|
program
|
|
22
23
|
.name("miaoda")
|
|
23
|
-
.description("妙搭平台 CLI
|
|
24
|
+
.description("妙搭平台 CLI,提供数据服务、文件存储等命令行操作。")
|
|
24
25
|
.usage("<command> [flags]")
|
|
25
26
|
.version(version, "-v, --version", "显示版本号")
|
|
26
27
|
.option("--json [fields]", "JSON 输出,可选字段级选择")
|
|
27
|
-
.
|
|
28
|
+
.addOption(new commander_1.Option("--output <format>", "输出格式(pretty | json,大小写不敏感)")
|
|
29
|
+
.choices(["pretty", "json"])
|
|
30
|
+
.argParser((0, shared_1.caseInsensitiveChoice)(["pretty", "json"]))
|
|
31
|
+
.default("pretty"))
|
|
28
32
|
.option("--verbose", "debug 日志到 stderr")
|
|
29
33
|
.helpOption("-h, --help", "显示帮助信息")
|
|
30
34
|
.hook("preAction", (_thisCmd, actionCmd) => {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.failArgs = failArgs;
|
|
4
|
+
const error_1 = require("./error");
|
|
5
|
+
/** 参数校验失败时抛出;命令层可配合 withHelp 自动打 help。 */
|
|
6
|
+
function failArgs(message) {
|
|
7
|
+
throw new error_1.AppError("ARGS_INVALID", message);
|
|
8
|
+
}
|
package/dist/utils/http.js
CHANGED
|
@@ -73,14 +73,28 @@ function applyCanaryHeader(reqConfig) {
|
|
|
73
73
|
/** 走管理端 innerapi 的 POST + 信封解析 */
|
|
74
74
|
async function postInnerApi(url, body, opts) {
|
|
75
75
|
const startMs = logRequestStart("POST", url, body);
|
|
76
|
-
|
|
76
|
+
let response;
|
|
77
|
+
try {
|
|
78
|
+
response = await getHttpClient().post(url, body);
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
logResponseFailure("POST", url, err, startMs);
|
|
82
|
+
throw err;
|
|
83
|
+
}
|
|
77
84
|
logResponseEnd("POST", url, response, startMs);
|
|
78
85
|
return handleInnerEnvelope(response, url, opts);
|
|
79
86
|
}
|
|
80
87
|
/** 走管理端 innerapi 的 GET + 信封解析 */
|
|
81
88
|
async function getInnerApi(url, opts) {
|
|
82
89
|
const startMs = logRequestStart("GET", url);
|
|
83
|
-
|
|
90
|
+
let response;
|
|
91
|
+
try {
|
|
92
|
+
response = await getHttpClient().get(url);
|
|
93
|
+
}
|
|
94
|
+
catch (err) {
|
|
95
|
+
logResponseFailure("GET", url, err, startMs);
|
|
96
|
+
throw err;
|
|
97
|
+
}
|
|
84
98
|
logResponseEnd("GET", url, response, startMs);
|
|
85
99
|
return handleInnerEnvelope(response, url, opts);
|
|
86
100
|
}
|
|
@@ -131,6 +145,24 @@ function logResponseEnd(method, url, response, startMs) {
|
|
|
131
145
|
const tail = logid ? ` logid=${logid}` : "";
|
|
132
146
|
(0, logger_1.debug)(`← ${method} ${url} ${String(response.status)} ${String(elapsedMs)}ms${tail}`);
|
|
133
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* http-client 在 4xx/5xx / 网络错误时直接 reject(不返回 Response);
|
|
150
|
+
* 这条路径下 logResponseEnd 不会跑——这里专门补一行,尽可能从 HttpError
|
|
151
|
+
* 上抠出 status / logid,让 verbose 仍能看到失败请求的关键信息。
|
|
152
|
+
*/
|
|
153
|
+
function logResponseFailure(method, url, err, startMs) {
|
|
154
|
+
if (!(0, config_1.getConfig)().verbose)
|
|
155
|
+
return;
|
|
156
|
+
const elapsedMs = Date.now() - startMs;
|
|
157
|
+
// @lark-apaas/http-client 的 HttpError.response: Response | undefined
|
|
158
|
+
const e = err;
|
|
159
|
+
const status = e.response?.status;
|
|
160
|
+
const logid = e.response?.headers ? pickLogid(e.response.headers) : null;
|
|
161
|
+
const statusPart = status !== undefined ? String(status) : "ERR";
|
|
162
|
+
const logidPart = logid ? ` logid=${logid}` : "";
|
|
163
|
+
const msgPart = e.message ? ` (${e.message})` : "";
|
|
164
|
+
(0, logger_1.debug)(`✗ ${method} ${url} ${statusPart} ${String(elapsedMs)}ms${logidPart}${msgPart}`);
|
|
165
|
+
}
|
|
134
166
|
/** BAM gateway 在不同 PSM/版本上 logid 落在不同 header;按命中顺序取第一个非空。 */
|
|
135
167
|
function pickLogid(headers) {
|
|
136
168
|
return (headers.get("x-tt-logid") ??
|