@elumixor/devkit 0.12.14 → 0.12.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/package.json +1 -1
- package/src/cloud/overview.ts +22 -4
- package/src/cloud/project.ts +1 -1
package/package.json
CHANGED
package/src/cloud/overview.ts
CHANGED
|
@@ -34,8 +34,11 @@ export interface ProjectOverview {
|
|
|
34
34
|
stages: StageOverview[];
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
/**
|
|
38
|
-
|
|
37
|
+
/**
|
|
38
|
+
* What `status`, the MCP server and the dashboard all show: every stage, what is live on it, how it did today.
|
|
39
|
+
* CloudWatch bills every metric read, so a caller with its own numbers passes `metrics: false`.
|
|
40
|
+
*/
|
|
41
|
+
export async function overview(project?: string, { metrics: withMetrics = true } = {}): Promise<ProjectOverview[]> {
|
|
39
42
|
const registries = project
|
|
40
43
|
? [await readRegistry(project)].filter((registry) => registry !== undefined)
|
|
41
44
|
: await listProjects();
|
|
@@ -47,7 +50,7 @@ export async function overview(project?: string): Promise<ProjectOverview[]> {
|
|
|
47
50
|
const target = new Target(registry.project, stage);
|
|
48
51
|
const [current, metrics, deploys] = await Promise.all([
|
|
49
52
|
readCurrent(target),
|
|
50
|
-
metricsFor(target.functionName),
|
|
53
|
+
withMetrics ? metricsFor(target.functionName) : NO_METRICS,
|
|
51
54
|
listDeploys(target, 3),
|
|
52
55
|
]);
|
|
53
56
|
return {
|
|
@@ -65,7 +68,22 @@ export async function overview(project?: string): Promise<ProjectOverview[]> {
|
|
|
65
68
|
);
|
|
66
69
|
}
|
|
67
70
|
|
|
68
|
-
|
|
71
|
+
const NO_METRICS: Metrics = { calls: 0, errors: 0, p95ms: 0 };
|
|
72
|
+
|
|
73
|
+
/** Each read costs money and the numbers move slowly: one function's are reused this long. */
|
|
74
|
+
const METRICS_MAX_AGE_MS = 10 * 60_000;
|
|
75
|
+
const recent = new Map<string, { at: number; metrics: Promise<Metrics> }>();
|
|
76
|
+
|
|
77
|
+
function metricsFor(functionName: string): Promise<Metrics> {
|
|
78
|
+
const kept = recent.get(functionName);
|
|
79
|
+
if (kept && Date.now() - kept.at < METRICS_MAX_AGE_MS) return kept.metrics;
|
|
80
|
+
const metrics = readMetrics(functionName);
|
|
81
|
+
recent.set(functionName, { at: Date.now(), metrics });
|
|
82
|
+
metrics.catch(() => recent.delete(functionName));
|
|
83
|
+
return metrics;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async function readMetrics(functionName: string): Promise<Metrics> {
|
|
69
87
|
const end = new Date();
|
|
70
88
|
const start = new Date(end.getTime() - DAY_SECONDS * 1000);
|
|
71
89
|
const query = (id: string, metric: string, stat: string) => ({
|
package/src/cloud/project.ts
CHANGED
|
@@ -27,7 +27,7 @@ export interface AwsTargetOptions extends Omit<WebBuildOptions, "host" | "static
|
|
|
27
27
|
project?: string;
|
|
28
28
|
/** How the edge serves paths that aren't the API (default `spa`). */
|
|
29
29
|
routing?: Routing;
|
|
30
|
-
/** Function memory in MB (default 512
|
|
30
|
+
/** Function memory in MB (default 512). */
|
|
31
31
|
memory?: number;
|
|
32
32
|
/** Function timeout in seconds (default 120; CloudFront waits 60 s for a first byte, a stream may go on longer). */
|
|
33
33
|
timeout?: number;
|