@elumixor/devkit 0.12.14 → 0.12.15

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elumixor/devkit",
3
- "version": "0.12.14",
3
+ "version": "0.12.15",
4
4
  "description": "Dev orchestrator for bun monorepos — free ports, run apps side-by-side, open the browser when ready",
5
5
  "author": "elumixor",
6
6
  "license": "ISC",
@@ -34,8 +34,11 @@ export interface ProjectOverview {
34
34
  stages: StageOverview[];
35
35
  }
36
36
 
37
- /** What `status`, the MCP server and the dashboard all show: every stage, what is live on it, how it did today. */
38
- export async function overview(project?: string): Promise<ProjectOverview[]> {
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
- async function metricsFor(functionName: string): Promise<Metrics> {
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) => ({