@netgreener/runtime 0.1.8 → 0.1.10
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/CHANGELOG.md +12 -0
- package/TUTORIAL.md +120 -29
- package/dist/aggregator.d.ts +12 -2
- package/dist/aggregator.js +135 -8
- package/dist/analyze/buildResourceFindings.d.ts +4 -0
- package/dist/analyze/buildResourceFindings.js +17 -0
- package/dist/analyze/cli.d.ts +1 -0
- package/dist/analyze/cli.js +22 -1
- package/dist/analyze/declaredExternalApis.d.ts +31 -0
- package/dist/analyze/declaredExternalApis.js +174 -0
- package/dist/analyze/index.d.ts +1 -0
- package/dist/analyze/index.js +1 -0
- package/dist/auto.d.ts +7 -0
- package/dist/auto.js +8 -0
- package/dist/bullmq.d.ts +2 -2
- package/dist/bullmq.js +28 -58
- package/dist/carbonLedger.d.ts +28 -0
- package/dist/carbonLedger.js +52 -0
- package/dist/cgroupV2.d.ts +44 -0
- package/dist/cgroupV2.js +174 -0
- package/dist/cli/helpText.d.ts +3 -3
- package/dist/cli/helpText.js +42 -35
- package/dist/cli/netgreener.d.ts +7 -7
- package/dist/cli/netgreener.js +23 -16
- package/dist/cli/runCli.d.ts +20 -0
- package/dist/cli/runCli.js +249 -0
- package/dist/cli/runPreload.d.ts +5 -0
- package/dist/cli/runPreload.js +43 -0
- package/dist/collectorMetadata.d.ts +1 -1
- package/dist/collectorMetadata.js +2 -0
- package/dist/config.d.ts +2 -0
- package/dist/config.js +6 -2
- package/dist/exporter.d.ts +7 -2
- package/dist/exporter.js +12 -6
- package/dist/express.js +17 -6
- package/dist/externalApiMeter.d.ts +51 -2
- package/dist/externalApiMeter.js +379 -26
- package/dist/fastify.js +17 -6
- package/dist/index.d.ts +12 -2
- package/dist/index.js +11 -1
- package/dist/init.d.ts +30 -0
- package/dist/init.js +31 -0
- package/dist/lifecycle.d.ts +45 -0
- package/dist/lifecycle.js +112 -0
- package/dist/managedCollectorLauncher.d.ts +37 -0
- package/dist/managedCollectorLauncher.js +162 -0
- package/dist/mcpToolMeter.d.ts +101 -0
- package/dist/mcpToolMeter.js +496 -0
- package/dist/n4/deploymentMatrix.d.ts +9 -5
- package/dist/n4/deploymentMatrix.js +13 -9
- package/dist/n4/missingnessInventory.js +3 -3
- package/dist/next.d.ts +89 -0
- package/dist/next.js +328 -0
- package/dist/nextConfig.d.ts +34 -0
- package/dist/nextConfig.js +73 -0
- package/dist/nextEntryTransform.d.ts +9 -0
- package/dist/nextEntryTransform.js +181 -0
- package/dist/occupancyTracker.d.ts +27 -0
- package/dist/occupancyTracker.js +87 -0
- package/dist/optimize/apply.d.ts +38 -0
- package/dist/optimize/apply.js +173 -0
- package/dist/optimize/cli.d.ts +26 -0
- package/dist/optimize/cli.js +323 -0
- package/dist/optimize/index.d.ts +6 -0
- package/dist/optimize/index.js +5 -0
- package/dist/optimize/llmApply.d.ts +22 -0
- package/dist/optimize/llmApply.js +80 -0
- package/dist/optimize/llmSession.d.ts +88 -0
- package/dist/optimize/llmSession.js +135 -0
- package/dist/optimize/provider.d.ts +17 -0
- package/dist/optimize/provider.js +119 -0
- package/dist/optimize/safePatches.d.ts +18 -0
- package/dist/optimize/safePatches.js +247 -0
- package/dist/optimize/types.d.ts +79 -0
- package/dist/optimize/types.js +6 -0
- package/dist/optimize/verification.d.ts +16 -0
- package/dist/optimize/verification.js +165 -0
- package/dist/processResources.d.ts +5 -0
- package/dist/processResources.js +28 -4
- package/dist/processRuntime.js +7 -28
- package/dist/processTree.d.ts +47 -0
- package/dist/processTree.js +148 -0
- package/dist/runContextEnrichment.d.ts +11 -0
- package/dist/runContextEnrichment.js +92 -0
- package/dist/runtime.d.ts +36 -1
- package/dist/runtime.js +140 -17
- package/dist/sdk/client.d.ts +152 -0
- package/dist/sdk/client.js +396 -0
- package/dist/sdk/gitUrl.d.ts +6 -0
- package/dist/sdk/gitUrl.js +87 -0
- package/dist/sdk/index.d.ts +5 -0
- package/dist/sdk/index.js +5 -0
- package/dist/serverlessHints.d.ts +9 -6
- package/dist/serverlessHints.js +10 -7
- package/dist/taskMeter.d.ts +14 -0
- package/dist/taskMeter.js +53 -0
- package/dist/types.d.ts +43 -0
- package/examples/aca-container-gate/Dockerfile +20 -0
- package/examples/aca-container-gate/azure-container-app.yaml +27 -0
- package/examples/aca-container-gate/gate.env +7 -0
- package/examples/aca-container-gate/server.mjs +117 -0
- package/examples/azure-functions-gate/.funcignore +6 -0
- package/examples/azure-functions-gate/README.md +25 -0
- package/examples/azure-functions-gate/host.json +15 -0
- package/examples/azure-functions-gate/package-lock.json +161 -0
- package/examples/azure-functions-gate/package.json +14 -0
- package/examples/azure-functions-gate/src/functions/health.js +27 -0
- package/examples/express-local-live-smoke.mjs +127 -0
- package/examples/extractRunId.mjs +11 -0
- package/examples/next-pilot-dry-run.mjs +32 -0
- package/examples/serverless-thin-gate.mjs +89 -0
- package/fixtures/run-smoke/hello.mjs +4 -0
- package/loaders/next-entry-loader.cjs +14 -0
- package/package.json +25 -2
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Serverless / thin-flush platform hints
|
|
2
|
+
* Serverless / thin-flush platform hints.
|
|
3
3
|
*
|
|
4
|
-
* Detection
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* Detection lives here; lifecycle cutover lives in ``lifecycle.ts``.
|
|
5
|
+
* Platform signals alone used to be informational only. With lifecycle
|
|
6
|
+
* ``auto``, serverless signals select **ephemeral** flush behavior and
|
|
7
|
+
* prefer thin export when ``NETGREENER_EXPORT_MODE`` is unset.
|
|
8
|
+
* Explicit ``NETGREENER_EXPORT_MODE`` / ``NETGREENER_RUNTIME=persistent`` win.
|
|
9
|
+
* Long-running Node (Docker/VM/K8s) stays on default ``direct``.
|
|
8
10
|
*/
|
|
9
11
|
export type ServerlessPlatformSignal = 'aws_lambda' | 'azure_functions' | 'google_cloud_functions' | 'vercel' | 'netlify';
|
|
10
12
|
export type ServerlessPlatformHint = {
|
|
@@ -13,7 +15,8 @@ export type ServerlessPlatformHint = {
|
|
|
13
15
|
signals: ServerlessPlatformSignal[];
|
|
14
16
|
/**
|
|
15
17
|
* Suggested export mode when a sibling collector cannot run.
|
|
16
|
-
*
|
|
18
|
+
* Applied by ``exportModeFromEnv`` only when lifecycle resolves ephemeral
|
|
19
|
+
* and ``NETGREENER_EXPORT_MODE`` is unset (see ``lifecycle.ts``).
|
|
17
20
|
*/
|
|
18
21
|
suggestedExportMode: 'thin' | null;
|
|
19
22
|
notes: string[];
|
package/dist/serverlessHints.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Serverless / thin-flush platform hints
|
|
2
|
+
* Serverless / thin-flush platform hints.
|
|
3
3
|
*
|
|
4
|
-
* Detection
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* Detection lives here; lifecycle cutover lives in ``lifecycle.ts``.
|
|
5
|
+
* Platform signals alone used to be informational only. With lifecycle
|
|
6
|
+
* ``auto``, serverless signals select **ephemeral** flush behavior and
|
|
7
|
+
* prefer thin export when ``NETGREENER_EXPORT_MODE`` is unset.
|
|
8
|
+
* Explicit ``NETGREENER_EXPORT_MODE`` / ``NETGREENER_RUNTIME=persistent`` win.
|
|
9
|
+
* Long-running Node (Docker/VM/K8s) stays on default ``direct``.
|
|
8
10
|
*/
|
|
9
11
|
function present(env, key) {
|
|
10
12
|
return Boolean(String(env[key] || '').trim());
|
|
@@ -33,8 +35,9 @@ export function detectServerlessPlatformSignals(env = process.env) {
|
|
|
33
35
|
const unique = [...new Set(signals)];
|
|
34
36
|
const detected = unique.length > 0;
|
|
35
37
|
if (detected) {
|
|
36
|
-
notes.push('serverless host signal present;
|
|
37
|
-
notes.push('
|
|
38
|
+
notes.push('serverless host signal present; lifecycle auto → ephemeral (invoke-end flush; no periodic timer)');
|
|
39
|
+
notes.push('when NETGREENER_EXPORT_MODE unset, ephemeral prefers thin (best_effort_bounded); explicit EXPORT_MODE wins');
|
|
40
|
+
notes.push('no durable sibling spool in thin/ephemeral mode; override with NETGREENER_RUNTIME=persistent if needed');
|
|
38
41
|
}
|
|
39
42
|
return {
|
|
40
43
|
detected,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared task/job metering (process runtime, BullMQ) — one hot path.
|
|
3
|
+
*
|
|
4
|
+
* Twins Python process_runtime / Celery: OccupancyTracker begin/end around the
|
|
5
|
+
* task so BullMQ/process flushes carry ``cpu_and_occupancy_v1`` anomaly evidence.
|
|
6
|
+
*/
|
|
7
|
+
import type { NetGreenerRuntime } from './runtime.js';
|
|
8
|
+
export declare function recordMeteredTask<T>(runtime: NetGreenerRuntime, sample: {
|
|
9
|
+
serviceUnit: string;
|
|
10
|
+
tenantId: string | null;
|
|
11
|
+
fn: () => T | Promise<T>;
|
|
12
|
+
/** Stable id for occupancy (BullMQ job id); defaults to UUID. */
|
|
13
|
+
taskId?: string | null;
|
|
14
|
+
}): T | Promise<T>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared task/job metering (process runtime, BullMQ) — one hot path.
|
|
3
|
+
*
|
|
4
|
+
* Twins Python process_runtime / Celery: OccupancyTracker begin/end around the
|
|
5
|
+
* task so BullMQ/process flushes carry ``cpu_and_occupancy_v1`` anomaly evidence.
|
|
6
|
+
*/
|
|
7
|
+
import { randomUUID } from 'node:crypto';
|
|
8
|
+
import { getOccupancyTracker } from './occupancyTracker.js';
|
|
9
|
+
import { beginProcessResourceSample, endProcessResourceSample, } from './processResources.js';
|
|
10
|
+
export function recordMeteredTask(runtime, sample) {
|
|
11
|
+
if (!runtime.enabled) {
|
|
12
|
+
return sample.fn();
|
|
13
|
+
}
|
|
14
|
+
const started = performance.now();
|
|
15
|
+
const resourceMark = beginProcessResourceSample();
|
|
16
|
+
const taskId = String(sample.taskId || '').trim() || randomUUID();
|
|
17
|
+
getOccupancyTracker().begin(taskId);
|
|
18
|
+
let error = false;
|
|
19
|
+
runtime.beginRequest();
|
|
20
|
+
const finalize = () => {
|
|
21
|
+
const resources = endProcessResourceSample(resourceMark);
|
|
22
|
+
getOccupancyTracker().end(taskId, sample.serviceUnit);
|
|
23
|
+
runtime.recordTask({
|
|
24
|
+
serviceUnit: sample.serviceUnit,
|
|
25
|
+
durationMs: performance.now() - started,
|
|
26
|
+
error,
|
|
27
|
+
tenantId: sample.tenantId,
|
|
28
|
+
cpuTimeMs: resources.cpuTimeMs,
|
|
29
|
+
peakRssKb: resources.rssKb,
|
|
30
|
+
});
|
|
31
|
+
runtime.endRequest();
|
|
32
|
+
};
|
|
33
|
+
try {
|
|
34
|
+
const result = sample.fn();
|
|
35
|
+
if (result instanceof Promise) {
|
|
36
|
+
return result.then((value) => {
|
|
37
|
+
finalize();
|
|
38
|
+
return value;
|
|
39
|
+
}, (err) => {
|
|
40
|
+
error = true;
|
|
41
|
+
finalize();
|
|
42
|
+
throw err;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
finalize();
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
error = true;
|
|
50
|
+
finalize();
|
|
51
|
+
throw err;
|
|
52
|
+
}
|
|
53
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -16,6 +16,8 @@ export type ServiceRuntimeUnit = {
|
|
|
16
16
|
cpu_percent_hours?: number;
|
|
17
17
|
ram_gb_hours?: number;
|
|
18
18
|
process_gpu_hours?: number;
|
|
19
|
+
/** Concurrency-normalized occupancy seconds (when OccupancyTracker wired). */
|
|
20
|
+
occupancy_seconds?: number;
|
|
19
21
|
};
|
|
20
22
|
export type AllocationReconciliationV0 = {
|
|
21
23
|
schema_version: number;
|
|
@@ -36,21 +38,48 @@ export type ServiceRuntimeTenantBucket = {
|
|
|
36
38
|
errors: number;
|
|
37
39
|
units: ServiceRuntimeUnit[];
|
|
38
40
|
};
|
|
41
|
+
export type AttributionDetailV0 = {
|
|
42
|
+
cpu?: {
|
|
43
|
+
method: string;
|
|
44
|
+
kind: string;
|
|
45
|
+
};
|
|
46
|
+
ram?: {
|
|
47
|
+
method: string;
|
|
48
|
+
kind: string;
|
|
49
|
+
};
|
|
50
|
+
gpu?: {
|
|
51
|
+
method: string;
|
|
52
|
+
kind: string;
|
|
53
|
+
};
|
|
54
|
+
energy?: Record<string, string>;
|
|
55
|
+
};
|
|
39
56
|
export type ServiceRuntimeV0 = {
|
|
40
57
|
framework?: string | null;
|
|
41
58
|
collector: string;
|
|
42
59
|
window_seconds: number;
|
|
43
60
|
attribution: string;
|
|
61
|
+
/** Optional detail for anomaly runtime_evidence (additive). */
|
|
62
|
+
attribution_detail?: AttributionDetailV0;
|
|
44
63
|
accuracy: string;
|
|
45
64
|
units: ServiceRuntimeUnit[];
|
|
46
65
|
by_tenant?: Record<TenantId, ServiceRuntimeTenantBucket>;
|
|
47
66
|
allocation_reconciliation_v0?: AllocationReconciliationV0;
|
|
67
|
+
/** Idle / in-flight occupancy not yet attributed to a unit. */
|
|
68
|
+
unattributed?: {
|
|
69
|
+
occupancy_seconds?: number;
|
|
70
|
+
idle_seconds?: number;
|
|
71
|
+
in_flight_seconds?: number;
|
|
72
|
+
/** Occupancy-share of window RAM when ``ram_gb_hours`` is allocated. */
|
|
73
|
+
ram_gb_hours?: number;
|
|
74
|
+
};
|
|
48
75
|
};
|
|
49
76
|
export type ExternalApiModelBucket = {
|
|
50
77
|
model: string;
|
|
51
78
|
calls: number;
|
|
52
79
|
errors: number;
|
|
53
80
|
calls_with_usage?: number;
|
|
81
|
+
/** Calls seen with no provider usage. Not a per-call price. */
|
|
82
|
+
calls_unknown?: number;
|
|
54
83
|
input_tokens?: number;
|
|
55
84
|
output_tokens?: number;
|
|
56
85
|
total_tokens?: number;
|
|
@@ -60,6 +89,8 @@ export type ExternalApiProvider = {
|
|
|
60
89
|
calls: number;
|
|
61
90
|
errors: number;
|
|
62
91
|
calls_with_usage?: number;
|
|
92
|
+
/** Calls seen with no provider usage. Not a per-call price. */
|
|
93
|
+
calls_unknown?: number;
|
|
63
94
|
duration_ms_avg?: number;
|
|
64
95
|
hosts?: string[];
|
|
65
96
|
input_tokens?: number;
|
|
@@ -105,6 +136,8 @@ export type MeasurementProvenance = {
|
|
|
105
136
|
value: number | null;
|
|
106
137
|
unit?: string;
|
|
107
138
|
source?: string;
|
|
139
|
+
version?: string;
|
|
140
|
+
location?: string | null;
|
|
108
141
|
};
|
|
109
142
|
evidence_grades?: EvidenceGrades;
|
|
110
143
|
[key: string]: unknown;
|
|
@@ -113,6 +146,12 @@ export type RunContext = {
|
|
|
113
146
|
deploy_environment?: string;
|
|
114
147
|
client?: string;
|
|
115
148
|
release_tag?: string;
|
|
149
|
+
git_sha?: string;
|
|
150
|
+
deploy_id?: string;
|
|
151
|
+
is_ci?: boolean;
|
|
152
|
+
ci?: boolean;
|
|
153
|
+
continuous_integration?: boolean;
|
|
154
|
+
ci_provider?: string;
|
|
116
155
|
/** Downstream customer company org id when tenant attribution is enabled. */
|
|
117
156
|
tenant_id?: TenantId;
|
|
118
157
|
/** e.g. jwt_claim:organization_id */
|
|
@@ -126,6 +165,10 @@ export type RuntimeSessionMetadata = {
|
|
|
126
165
|
run_context?: RunContext;
|
|
127
166
|
service_runtime_v0?: ServiceRuntimeV0;
|
|
128
167
|
external_api_v0?: ExternalApiV0;
|
|
168
|
+
/** Same-process MCP tool series. Not an API cost and not a second bill. */
|
|
169
|
+
mcp_tool_v0?: Record<string, unknown>;
|
|
170
|
+
/** Wall time beside MCP and HTTP durations. Overlap is marked, not stacked. */
|
|
171
|
+
mcp_latency_v0?: Record<string, unknown>;
|
|
129
172
|
measurement_provenance?: MeasurementProvenance;
|
|
130
173
|
[key: string]: unknown;
|
|
131
174
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Azure Container Apps / local Docker gate image for Node Runtime (Express dry-run).
|
|
2
|
+
# Does not change default EXPORT_MODE. Build from netgreener_node/:
|
|
3
|
+
# docker build -f examples/aca-container-gate/Dockerfile -t ng-aca-gate .
|
|
4
|
+
|
|
5
|
+
FROM node:22-bookworm-slim
|
|
6
|
+
WORKDIR /app
|
|
7
|
+
COPY package.json package-lock.json ./
|
|
8
|
+
RUN npm ci --omit=dev=false
|
|
9
|
+
COPY . .
|
|
10
|
+
RUN npm run build
|
|
11
|
+
ENV NETGREENER_SERVICE_RUNTIME=1
|
|
12
|
+
ENV NETGREENER_RUNTIME_DRY_RUN=1
|
|
13
|
+
ENV NETGREENER_TOKEN=ngs_local_dry_run
|
|
14
|
+
ENV NETGREENER_PROJECT_ID=1
|
|
15
|
+
# ACA-shaped signals (persistent lifecycle — not serverless)
|
|
16
|
+
ENV CONTAINER_APP_NAME=netgreener-aca-gate
|
|
17
|
+
ENV CONTAINER_APP_REVISION=local-gate
|
|
18
|
+
ENV container=docker
|
|
19
|
+
EXPOSE 8080
|
|
20
|
+
CMD ["node", "examples/aca-container-gate/server.mjs"]
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Example Azure Container Apps revision env for NetGreener Runtime (Node Express).
|
|
2
|
+
# Apply with your own image + secrets. Does not flip NETGREENER_EXPORT_MODE.
|
|
3
|
+
#
|
|
4
|
+
# az containerapp update -n <app> -g <rg> --set-env-vars \
|
|
5
|
+
# NETGREENER_SERVICE_RUNTIME=1 \
|
|
6
|
+
# NETGREENER_API_URL=https://core-api.netgreener.com \
|
|
7
|
+
# NETGREENER_TOKEN=secretref:netgreener-token \
|
|
8
|
+
# NETGREENER_PROJECT_ID=<id> \
|
|
9
|
+
# NETGREENER_ORG_ID=<id> \
|
|
10
|
+
# NETGREENER_EXPORT_MODE=direct
|
|
11
|
+
|
|
12
|
+
properties:
|
|
13
|
+
template:
|
|
14
|
+
containers:
|
|
15
|
+
- name: app
|
|
16
|
+
env:
|
|
17
|
+
- name: NETGREENER_SERVICE_RUNTIME
|
|
18
|
+
value: "1"
|
|
19
|
+
- name: NETGREENER_EXPORT_MODE
|
|
20
|
+
value: direct
|
|
21
|
+
- name: NETGREENER_API_URL
|
|
22
|
+
value: https://core-api.netgreener.com
|
|
23
|
+
- name: NETGREENER_PROJECT_ID
|
|
24
|
+
value: "<project-id>"
|
|
25
|
+
- name: NETGREENER_ORG_ID
|
|
26
|
+
value: "<org-id>"
|
|
27
|
+
# CONTAINER_APP_NAME / REVISION are injected by the platform
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal Express-shaped HTTP server for ACA / Docker container gate.
|
|
3
|
+
* Records routes via netgreenerExpressMiddleware; flushes dry-run payload.
|
|
4
|
+
*/
|
|
5
|
+
import { createServer } from 'node:http'
|
|
6
|
+
import { writeFileSync, mkdirSync } from 'node:fs'
|
|
7
|
+
import { dirname, join } from 'node:path'
|
|
8
|
+
import { fileURLToPath } from 'node:url'
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
getExpressRuntime,
|
|
12
|
+
loadRuntimeConfig,
|
|
13
|
+
netgreenerExpressMiddleware,
|
|
14
|
+
resolveLifecycle,
|
|
15
|
+
} from '../../dist/index.js'
|
|
16
|
+
import { extractRunId } from '../extractRunId.mjs'
|
|
17
|
+
|
|
18
|
+
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
19
|
+
const artifactDir = join(__dirname, '../../artifacts/aca-container-gate')
|
|
20
|
+
|
|
21
|
+
const config = loadRuntimeConfig({
|
|
22
|
+
...process.env,
|
|
23
|
+
NETGREENER_SERVICE_RUNTIME: '1',
|
|
24
|
+
NETGREENER_TOKEN: process.env.NETGREENER_TOKEN || 'ngs_local_dry_run',
|
|
25
|
+
NETGREENER_PROJECT_ID: process.env.NETGREENER_PROJECT_ID || '1',
|
|
26
|
+
NETGREENER_RUNTIME_DRY_RUN: process.env.NETGREENER_RUNTIME_DRY_RUN || '1',
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
const lifecycle = resolveLifecycle({ env: process.env })
|
|
30
|
+
const mw = netgreenerExpressMiddleware({
|
|
31
|
+
config,
|
|
32
|
+
fetchImpl: async () => {
|
|
33
|
+
throw new Error('aca-container-gate attempted outbound API request')
|
|
34
|
+
},
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
const server = createServer((req, res) => {
|
|
38
|
+
const pathOnly = (req.url || '/').split('?')[0]
|
|
39
|
+
const fakeReq = {
|
|
40
|
+
method: req.method,
|
|
41
|
+
path: pathOnly,
|
|
42
|
+
url: req.url,
|
|
43
|
+
route: { path: pathOnly === '/health' ? '/health' : pathOnly },
|
|
44
|
+
}
|
|
45
|
+
const fakeRes = {
|
|
46
|
+
statusCode: 200,
|
|
47
|
+
on(event, fn) {
|
|
48
|
+
if (event === 'finish' || event === 'close') res.on(event, fn)
|
|
49
|
+
return this
|
|
50
|
+
},
|
|
51
|
+
}
|
|
52
|
+
mw(fakeReq, fakeRes, () => {
|
|
53
|
+
if (pathOnly === '/health') {
|
|
54
|
+
res.statusCode = 200
|
|
55
|
+
fakeRes.statusCode = 200
|
|
56
|
+
res.end(JSON.stringify({ ok: true, lifecycle: lifecycle.lifecycle, platform: lifecycle.platform }))
|
|
57
|
+
return
|
|
58
|
+
}
|
|
59
|
+
res.statusCode = 200
|
|
60
|
+
fakeRes.statusCode = 200
|
|
61
|
+
res.end(JSON.stringify({ path: pathOnly }))
|
|
62
|
+
})
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
const port = Number(process.env.PORT || 8080)
|
|
66
|
+
server.listen(port, async () => {
|
|
67
|
+
const base = `http://127.0.0.1:${port}`
|
|
68
|
+
await fetch(`${base}/health`)
|
|
69
|
+
await fetch(`${base}/v1/predict`, { method: 'POST' })
|
|
70
|
+
const result = await getExpressRuntime().flush('manual')
|
|
71
|
+
mkdirSync(artifactDir, { recursive: true })
|
|
72
|
+
const runId =
|
|
73
|
+
result?.ok && !result.dryRun ? extractRunId(result.body) : null
|
|
74
|
+
const summary = {
|
|
75
|
+
gate: 'CHK-R6.container',
|
|
76
|
+
platform_claim: 'azure_container_apps',
|
|
77
|
+
claim_ready: Boolean(runId),
|
|
78
|
+
lifecycle: lifecycle.lifecycle,
|
|
79
|
+
platform: lifecycle.platform,
|
|
80
|
+
container_app_name: process.env.CONTAINER_APP_NAME || null,
|
|
81
|
+
dry_run: Boolean(result?.dryRun),
|
|
82
|
+
ok: Boolean(result?.ok),
|
|
83
|
+
run_id: runId,
|
|
84
|
+
flushed_at: new Date().toISOString(),
|
|
85
|
+
}
|
|
86
|
+
writeFileSync(join(artifactDir, 'latest.json'), JSON.stringify({ summary, result }, null, 2))
|
|
87
|
+
writeFileSync(
|
|
88
|
+
join(artifactDir, 'SUMMARY.md'),
|
|
89
|
+
[
|
|
90
|
+
'# ACA / container gate evidence',
|
|
91
|
+
'',
|
|
92
|
+
`- check_id: \`CHK-R6.container\``,
|
|
93
|
+
`- claimed platform: **Azure Container Apps** (local Docker uses ACA env shape)`,
|
|
94
|
+
`- lifecycle: \`${lifecycle.lifecycle}\` (must be persistent)`,
|
|
95
|
+
`- platform hint: \`${lifecycle.platform}\``,
|
|
96
|
+
`- dry_run: \`${summary.dry_run}\``,
|
|
97
|
+
`- ok: \`${summary.ok}\``,
|
|
98
|
+
`- run_id: \`${runId ?? '(none — dry-run or upload body without id)'}\``,
|
|
99
|
+
`- claim_ready: \`${summary.claim_ready}\``,
|
|
100
|
+
`- flushed_at: \`${summary.flushed_at}\``,
|
|
101
|
+
'',
|
|
102
|
+
'Live claim: set real `NETGREENER_*`, `NETGREENER_RUNTIME_DRY_RUN=0`, deploy on ACA, re-run until `run_id` is set, then flip DEPLOYMENT_MATRIX.',
|
|
103
|
+
'',
|
|
104
|
+
].join('\n'),
|
|
105
|
+
)
|
|
106
|
+
console.log(JSON.stringify(summary, null, 2))
|
|
107
|
+
if (!result?.ok || lifecycle.lifecycle !== 'persistent') {
|
|
108
|
+
server.close()
|
|
109
|
+
process.exit(1)
|
|
110
|
+
}
|
|
111
|
+
// Live mode without run_id is a soft warn (API shape may vary); dry-run stays green.
|
|
112
|
+
if (!result.dryRun && !runId) {
|
|
113
|
+
console.warn('WARN: live upload ok but run_id not found in response body')
|
|
114
|
+
}
|
|
115
|
+
server.close()
|
|
116
|
+
process.exit(0)
|
|
117
|
+
})
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Azure Functions gate (isolated)
|
|
2
|
+
|
|
3
|
+
Isolated serverless-thin dogfood for `CHK-R6.serverless-degraded`.
|
|
4
|
+
|
|
5
|
+
**Does not** touch existing NetGreener prod resources. Create under
|
|
6
|
+
`rg-ng-runtime-gate-test` only. Env secrets live in
|
|
7
|
+
`../../.env.azure-test-servers` (gitignored).
|
|
8
|
+
|
|
9
|
+
## Deployed app (example)
|
|
10
|
+
|
|
11
|
+
- Function App: `fn-ng-runtime-gate-20261014`
|
|
12
|
+
- URL: `https://fn-ng-runtime-gate-20261014.azurewebsites.net/api/health`
|
|
13
|
+
|
|
14
|
+
## Local publish
|
|
15
|
+
|
|
16
|
+
```powershell
|
|
17
|
+
npm install
|
|
18
|
+
func azure functionapp publish fn-ng-runtime-gate-20261014 --javascript
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Tear down
|
|
22
|
+
|
|
23
|
+
```powershell
|
|
24
|
+
az group delete -n rg-ng-runtime-gate-test --yes
|
|
25
|
+
```
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "2.0",
|
|
3
|
+
"logging": {
|
|
4
|
+
"applicationInsights": {
|
|
5
|
+
"samplingSettings": {
|
|
6
|
+
"isEnabled": true,
|
|
7
|
+
"excludedTypes": "Request"
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"extensionBundle": {
|
|
12
|
+
"id": "Microsoft.Azure.Functions.ExtensionBundle",
|
|
13
|
+
"version": "[4.*, 5.0.0)"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ng-azure-functions-gate",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"lockfileVersion": 3,
|
|
5
|
+
"requires": true,
|
|
6
|
+
"packages": {
|
|
7
|
+
"": {
|
|
8
|
+
"name": "ng-azure-functions-gate",
|
|
9
|
+
"version": "0.1.0",
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@azure/functions": "^4.6.0",
|
|
12
|
+
"@netgreener/runtime": "0.1.9"
|
|
13
|
+
},
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": "^22.0.0 || ^24.0.0"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"node_modules/@azure/functions": {
|
|
19
|
+
"version": "4.16.5",
|
|
20
|
+
"resolved": "https://registry.npmjs.org/@azure/functions/-/functions-4.16.5.tgz",
|
|
21
|
+
"integrity": "sha512-h0lVUeI/Q36SyE2xGQOXZqBbmSgQHNLk8pvMxhq3Dw1TaT3eGWs2X25dceGJ153aXXkjcTEdkxg3D2Gcz1uJ0w==",
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@azure/functions-extensions-base": "0.3.0",
|
|
25
|
+
"cookie": "^0.7.0"
|
|
26
|
+
},
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=20.0"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"node_modules/@azure/functions-extensions-base": {
|
|
32
|
+
"version": "0.3.0",
|
|
33
|
+
"resolved": "https://registry.npmjs.org/@azure/functions-extensions-base/-/functions-extensions-base-0.3.0.tgz",
|
|
34
|
+
"integrity": "sha512-Cux0hLu5ZXlC/Kb+yvJVhRLIdkfFwui2HeT5oGZL00r/GCUUkhGTzRfZUjRN4Bq729mPv3okPucz2z7SMQLStA==",
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=18.0"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"node_modules/@netgreener/runtime": {
|
|
41
|
+
"version": "0.1.9",
|
|
42
|
+
"resolved": "https://registry.npmjs.org/@netgreener/runtime/-/runtime-0.1.9.tgz",
|
|
43
|
+
"integrity": "sha512-dp4vwl968K58zk6eTCurJjLFQMaFg2jZrtOoEI5AREuZbl1v9Tkgbvm80A4GAWgIWA7la2TJS6MlUFKt7w3G7Q==",
|
|
44
|
+
"license": "UNLICENSED",
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"ajv": "^8.20.0",
|
|
47
|
+
"ajv-formats": "^3.0.1"
|
|
48
|
+
},
|
|
49
|
+
"bin": {
|
|
50
|
+
"netgreener": "dist/cli/netgreener.js",
|
|
51
|
+
"netgreener-analyze": "dist/analyze/cli.js"
|
|
52
|
+
},
|
|
53
|
+
"engines": {
|
|
54
|
+
"node": "^22.0.0 || ^24.0.0"
|
|
55
|
+
},
|
|
56
|
+
"peerDependencies": {
|
|
57
|
+
"axios": ">=1",
|
|
58
|
+
"bullmq": ">=4",
|
|
59
|
+
"express": ">=4",
|
|
60
|
+
"fastify": ">=4",
|
|
61
|
+
"typescript": ">=5"
|
|
62
|
+
},
|
|
63
|
+
"peerDependenciesMeta": {
|
|
64
|
+
"axios": {
|
|
65
|
+
"optional": true
|
|
66
|
+
},
|
|
67
|
+
"bullmq": {
|
|
68
|
+
"optional": true
|
|
69
|
+
},
|
|
70
|
+
"express": {
|
|
71
|
+
"optional": true
|
|
72
|
+
},
|
|
73
|
+
"fastify": {
|
|
74
|
+
"optional": true
|
|
75
|
+
},
|
|
76
|
+
"typescript": {
|
|
77
|
+
"optional": true
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
"node_modules/ajv": {
|
|
82
|
+
"version": "8.20.0",
|
|
83
|
+
"resolved": "https://registry.npmjs.org/ajv/-/ajv-8.20.0.tgz",
|
|
84
|
+
"integrity": "sha512-Thbli+OlOj+iMPYFBVBfJ3OmCAnaSyNn4M1vz9T6Gka5Jt9ba/HIR56joy65tY6kx/FCF5VXNB819Y7/GUrBGA==",
|
|
85
|
+
"license": "MIT",
|
|
86
|
+
"dependencies": {
|
|
87
|
+
"fast-deep-equal": "^3.1.3",
|
|
88
|
+
"fast-uri": "^3.0.1",
|
|
89
|
+
"json-schema-traverse": "^1.0.0",
|
|
90
|
+
"require-from-string": "^2.0.2"
|
|
91
|
+
},
|
|
92
|
+
"funding": {
|
|
93
|
+
"type": "github",
|
|
94
|
+
"url": "https://github.com/sponsors/epoberezkin"
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
"node_modules/ajv-formats": {
|
|
98
|
+
"version": "3.0.1",
|
|
99
|
+
"resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-3.0.1.tgz",
|
|
100
|
+
"integrity": "sha512-8iUql50EUR+uUcdRQ3HDqa6EVyo3docL8g5WJ3FNcWmu62IbkGUue/pEyLBW8VGKKucTPgqeks4fIU1DA4yowQ==",
|
|
101
|
+
"license": "MIT",
|
|
102
|
+
"dependencies": {
|
|
103
|
+
"ajv": "^8.0.0"
|
|
104
|
+
},
|
|
105
|
+
"peerDependencies": {
|
|
106
|
+
"ajv": "^8.0.0"
|
|
107
|
+
},
|
|
108
|
+
"peerDependenciesMeta": {
|
|
109
|
+
"ajv": {
|
|
110
|
+
"optional": true
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
"node_modules/cookie": {
|
|
115
|
+
"version": "0.7.2",
|
|
116
|
+
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz",
|
|
117
|
+
"integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==",
|
|
118
|
+
"license": "MIT",
|
|
119
|
+
"engines": {
|
|
120
|
+
"node": ">= 0.6"
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
"node_modules/fast-deep-equal": {
|
|
124
|
+
"version": "3.1.3",
|
|
125
|
+
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
|
|
126
|
+
"integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==",
|
|
127
|
+
"license": "MIT"
|
|
128
|
+
},
|
|
129
|
+
"node_modules/fast-uri": {
|
|
130
|
+
"version": "3.1.8",
|
|
131
|
+
"resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.1.8.tgz",
|
|
132
|
+
"integrity": "sha512-GZMtZUTNRpOVIECoXwLNZS5xUGE+mVNbTB8h/7Rwh2TFWcBQiPzTgyZi05BF9UMZKkLJv8XBRJTlU7zg8+ZfMg==",
|
|
133
|
+
"funding": [
|
|
134
|
+
{
|
|
135
|
+
"type": "github",
|
|
136
|
+
"url": "https://github.com/sponsors/fastify"
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
"type": "opencollective",
|
|
140
|
+
"url": "https://opencollective.com/fastify"
|
|
141
|
+
}
|
|
142
|
+
],
|
|
143
|
+
"license": "BSD-3-Clause"
|
|
144
|
+
},
|
|
145
|
+
"node_modules/json-schema-traverse": {
|
|
146
|
+
"version": "1.0.0",
|
|
147
|
+
"resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz",
|
|
148
|
+
"integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==",
|
|
149
|
+
"license": "MIT"
|
|
150
|
+
},
|
|
151
|
+
"node_modules/require-from-string": {
|
|
152
|
+
"version": "2.0.2",
|
|
153
|
+
"resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz",
|
|
154
|
+
"integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==",
|
|
155
|
+
"license": "MIT",
|
|
156
|
+
"engines": {
|
|
157
|
+
"node": ">=0.10.0"
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ng-azure-functions-gate",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/functions/*.js",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": "^22.0.0 || ^24.0.0"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@azure/functions": "^4.6.0",
|
|
12
|
+
"@netgreener/runtime": "0.1.9"
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Isolated Azure Functions gate for serverless-thin live run_id evidence.
|
|
3
|
+
* Does not modify existing NetGreener Azure resources.
|
|
4
|
+
*/
|
|
5
|
+
import { app } from '@azure/functions'
|
|
6
|
+
import { NetGreener } from '@netgreener/runtime'
|
|
7
|
+
|
|
8
|
+
NetGreener.init({ runtime: 'auto' })
|
|
9
|
+
|
|
10
|
+
app.http('health', {
|
|
11
|
+
methods: ['GET', 'POST'],
|
|
12
|
+
authLevel: 'anonymous',
|
|
13
|
+
handler: async (_request, _context) => {
|
|
14
|
+
try {
|
|
15
|
+
return {
|
|
16
|
+
status: 200,
|
|
17
|
+
jsonBody: {
|
|
18
|
+
ok: true,
|
|
19
|
+
gate: 'CHK-R6.serverless-degraded',
|
|
20
|
+
platform: 'azure_functions',
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
} finally {
|
|
24
|
+
await NetGreener.flushForInvokeEnd()
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
})
|