@netgreener/runtime 0.1.8 → 0.1.9
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/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 +43 -1
- package/dist/externalApiMeter.js +267 -5
- package/dist/fastify.js +17 -6
- package/dist/index.d.ts +10 -2
- package/dist/index.js +9 -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/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 +61 -0
- package/dist/next.js +195 -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 +29 -1
- package/dist/runtime.js +94 -16
- 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 +35 -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/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/package.json +23 -2
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,15 +38,40 @@ 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;
|
|
@@ -105,6 +132,8 @@ export type MeasurementProvenance = {
|
|
|
105
132
|
value: number | null;
|
|
106
133
|
unit?: string;
|
|
107
134
|
source?: string;
|
|
135
|
+
version?: string;
|
|
136
|
+
location?: string | null;
|
|
108
137
|
};
|
|
109
138
|
evidence_grades?: EvidenceGrades;
|
|
110
139
|
[key: string]: unknown;
|
|
@@ -113,6 +142,12 @@ export type RunContext = {
|
|
|
113
142
|
deploy_environment?: string;
|
|
114
143
|
client?: string;
|
|
115
144
|
release_tag?: string;
|
|
145
|
+
git_sha?: string;
|
|
146
|
+
deploy_id?: string;
|
|
147
|
+
is_ci?: boolean;
|
|
148
|
+
ci?: boolean;
|
|
149
|
+
continuous_integration?: boolean;
|
|
150
|
+
ci_provider?: string;
|
|
116
151
|
/** Downstream customer company org id when tenant attribution is enabled. */
|
|
117
152
|
tenant_id?: TenantId;
|
|
118
153
|
/** e.g. jwt_claim:organization_id */
|
|
@@ -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,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Laptop Express smoke → dry-run by default; live upload when credentials set.
|
|
3
|
+
*
|
|
4
|
+
* Dry-run (no cloud):
|
|
5
|
+
* npm run example:express-local-live
|
|
6
|
+
*
|
|
7
|
+
* Live (needs token + project; uses your local or prod api_server):
|
|
8
|
+
* $env:NETGREENER_RUNTIME_DRY_RUN="0"
|
|
9
|
+
* $env:NETGREENER_API_URL="http://127.0.0.1:8000" # or https://core-api.netgreener.com
|
|
10
|
+
* $env:NETGREENER_TOKEN="ngs_..."
|
|
11
|
+
* $env:NETGREENER_PROJECT_ID="97"
|
|
12
|
+
* $env:NETGREENER_SERVICE_RUNTIME="1"
|
|
13
|
+
* npm run example:express-local-live
|
|
14
|
+
*
|
|
15
|
+
* Does not flip EXPORT_MODE. Prints run_id when live upload succeeds.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { createServer } from 'node:http'
|
|
19
|
+
|
|
20
|
+
import { extractPersistedRunId } from '../dist/dogfood/tenantDogfoodGates.js'
|
|
21
|
+
import {
|
|
22
|
+
getExpressRuntime,
|
|
23
|
+
loadRuntimeConfig,
|
|
24
|
+
netgreenerExpressMiddleware,
|
|
25
|
+
} from '../dist/index.js'
|
|
26
|
+
|
|
27
|
+
const dryRun =
|
|
28
|
+
(process.env.NETGREENER_RUNTIME_DRY_RUN || '1').trim() !== '0' &&
|
|
29
|
+
(process.env.NETGREENER_RUNTIME_DRY_RUN || '1').trim().toLowerCase() !== 'false'
|
|
30
|
+
const live = !dryRun
|
|
31
|
+
|
|
32
|
+
if (live) {
|
|
33
|
+
const token = (process.env.NETGREENER_TOKEN || '').trim()
|
|
34
|
+
const projectId = (process.env.NETGREENER_PROJECT_ID || '').trim()
|
|
35
|
+
if (!token || token.startsWith('ngs_local') || !projectId) {
|
|
36
|
+
console.error(
|
|
37
|
+
'LIVE mode requires real NETGREENER_TOKEN and NETGREENER_PROJECT_ID (not ngs_local_*).',
|
|
38
|
+
)
|
|
39
|
+
process.exit(2)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const config = loadRuntimeConfig({
|
|
44
|
+
...process.env,
|
|
45
|
+
NETGREENER_SERVICE_RUNTIME: '1',
|
|
46
|
+
NETGREENER_TOKEN: process.env.NETGREENER_TOKEN || 'ngs_local_express_smoke',
|
|
47
|
+
NETGREENER_PROJECT_ID: process.env.NETGREENER_PROJECT_ID || '97',
|
|
48
|
+
NETGREENER_RUNTIME_DRY_RUN: dryRun ? '1' : '0',
|
|
49
|
+
NETGREENER_API_URL:
|
|
50
|
+
process.env.NETGREENER_API_URL ||
|
|
51
|
+
(live ? 'https://core-api.netgreener.com' : 'http://127.0.0.1:8000'),
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
const mw = netgreenerExpressMiddleware({
|
|
55
|
+
config,
|
|
56
|
+
onFlush: (result) => {
|
|
57
|
+
console.log(
|
|
58
|
+
'flush:',
|
|
59
|
+
result?.ok
|
|
60
|
+
? result.dryRun
|
|
61
|
+
? 'dry-run ok'
|
|
62
|
+
: `HTTP ${result.status}`
|
|
63
|
+
: result?.error || 'failed',
|
|
64
|
+
)
|
|
65
|
+
},
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
const server = createServer((req, res) => {
|
|
69
|
+
const fakeReq = {
|
|
70
|
+
method: req.method,
|
|
71
|
+
path: (req.url || '/').split('?')[0],
|
|
72
|
+
url: req.url,
|
|
73
|
+
headers: req.headers,
|
|
74
|
+
}
|
|
75
|
+
const fakeRes = {
|
|
76
|
+
statusCode: 200,
|
|
77
|
+
on(event, fn) {
|
|
78
|
+
if (event === 'finish' || event === 'close') res.on(event, fn)
|
|
79
|
+
return this
|
|
80
|
+
},
|
|
81
|
+
}
|
|
82
|
+
mw(fakeReq, fakeRes, () => {
|
|
83
|
+
res.statusCode = 200
|
|
84
|
+
res.setHeader('content-type', 'application/json')
|
|
85
|
+
res.end(JSON.stringify({ ok: true, path: fakeReq.path, mode: live ? 'live' : 'dry-run' }))
|
|
86
|
+
})
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve))
|
|
90
|
+
const addr = server.address()
|
|
91
|
+
const bound = typeof addr === 'object' && addr ? addr.port : 0
|
|
92
|
+
|
|
93
|
+
console.log(
|
|
94
|
+
`mode: ${live ? 'LIVE upload' : 'DRY-RUN'} http://127.0.0.1:${bound}/smoke project=${process.env.NETGREENER_PROJECT_ID || '97'}`,
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
const resp = await fetch(`http://127.0.0.1:${bound}/smoke`)
|
|
98
|
+
const body = await resp.json()
|
|
99
|
+
console.log('response:', body)
|
|
100
|
+
|
|
101
|
+
const flushResult = await getExpressRuntime().flush('manual')
|
|
102
|
+
server.close()
|
|
103
|
+
|
|
104
|
+
if (!flushResult?.ok) {
|
|
105
|
+
console.error('flush failed:', flushResult?.error || flushResult)
|
|
106
|
+
process.exit(1)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (live) {
|
|
110
|
+
if (flushResult.dryRun) {
|
|
111
|
+
console.error('LIVE smoke returned dry-run — check NETGREENER_RUNTIME_DRY_RUN=0')
|
|
112
|
+
process.exit(1)
|
|
113
|
+
}
|
|
114
|
+
const runId = extractPersistedRunId(flushResult.body)
|
|
115
|
+
if (runId == null) {
|
|
116
|
+
console.warn('Upload ok but run_id not parsed — check dashboard for the latest run.')
|
|
117
|
+
console.log(JSON.stringify(flushResult.body, null, 2))
|
|
118
|
+
} else {
|
|
119
|
+
console.log(`PASS run_id=${runId}`)
|
|
120
|
+
}
|
|
121
|
+
} else {
|
|
122
|
+
if (!flushResult.dryRun) {
|
|
123
|
+
console.error('expected dry-run result')
|
|
124
|
+
process.exit(1)
|
|
125
|
+
}
|
|
126
|
+
console.log('Dry-run PASS. Set NETGREENER_RUNTIME_DRY_RUN=0 + token/project for live run_id.')
|
|
127
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Best-effort run_id extraction from RunSession upload JSON body. */
|
|
2
|
+
export function extractRunId(body) {
|
|
3
|
+
if (body == null || typeof body !== 'object') return null
|
|
4
|
+
const o = body
|
|
5
|
+
for (const key of ['id', 'run_id', 'runId', 'run_session_id']) {
|
|
6
|
+
const v = o[key]
|
|
7
|
+
if (typeof v === 'number' && Number.isFinite(v)) return String(v)
|
|
8
|
+
if (typeof v === 'string' && v.trim()) return v.trim()
|
|
9
|
+
}
|
|
10
|
+
return null
|
|
11
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wave 3 Next.js adapter dry-run (no Next server required).
|
|
3
|
+
*/
|
|
4
|
+
import {
|
|
5
|
+
getNextRuntime,
|
|
6
|
+
loadRuntimeConfig,
|
|
7
|
+
withNetGreenerRoute,
|
|
8
|
+
_resetRuntimeForTests,
|
|
9
|
+
} from '../dist/index.js'
|
|
10
|
+
|
|
11
|
+
_resetRuntimeForTests()
|
|
12
|
+
const config = loadRuntimeConfig({
|
|
13
|
+
NETGREENER_SERVICE_RUNTIME: '1',
|
|
14
|
+
NETGREENER_TOKEN: 'ngs_local_dry_run',
|
|
15
|
+
NETGREENER_PROJECT_ID: '1',
|
|
16
|
+
NETGREENER_RUNTIME_DRY_RUN: '1',
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
const POST = withNetGreenerRoute(
|
|
20
|
+
async () => new Response(JSON.stringify({ ok: true }), { status: 200 }),
|
|
21
|
+
{ config, routeTemplate: '/api/pilot' },
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
await POST({ method: 'POST', url: 'https://local/api/pilot', headers: {} })
|
|
25
|
+
const result = await getNextRuntime().flush('manual')
|
|
26
|
+
if (!result?.ok || !result.dryRun) {
|
|
27
|
+
console.error(result)
|
|
28
|
+
process.exit(1)
|
|
29
|
+
}
|
|
30
|
+
console.log('next pilot dry-run ok')
|
|
31
|
+
console.log(JSON.stringify(result.body?.session_metadata?.service_runtime_v0 || {}, null, 2))
|
|
32
|
+
_resetRuntimeForTests()
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wave 4 serverless thin gate — Vercel-shaped env, ephemeral flush, dry-run.
|
|
3
|
+
*/
|
|
4
|
+
import { mkdirSync, writeFileSync } from 'node:fs'
|
|
5
|
+
import { dirname, join } from 'node:path'
|
|
6
|
+
import { fileURLToPath } from 'node:url'
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
NetGreener,
|
|
10
|
+
_resetRuntimeForTests,
|
|
11
|
+
loadRuntimeConfig,
|
|
12
|
+
resolveLifecycle,
|
|
13
|
+
exportModeFromEnv,
|
|
14
|
+
} from '../dist/index.js'
|
|
15
|
+
import { extractRunId } from './extractRunId.mjs'
|
|
16
|
+
|
|
17
|
+
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
18
|
+
const artifactDir = join(__dirname, '../artifacts/serverless-thin-gate')
|
|
19
|
+
|
|
20
|
+
_resetRuntimeForTests()
|
|
21
|
+
process.env.VERCEL = '1'
|
|
22
|
+
process.env.VERCEL_ENV = 'preview'
|
|
23
|
+
process.env.NETGREENER_SERVICE_RUNTIME = '1'
|
|
24
|
+
process.env.NETGREENER_TOKEN = 'ngs_local_dry_run'
|
|
25
|
+
process.env.NETGREENER_PROJECT_ID = '1'
|
|
26
|
+
process.env.NETGREENER_RUNTIME_DRY_RUN = '1'
|
|
27
|
+
delete process.env.NETGREENER_EXPORT_MODE
|
|
28
|
+
|
|
29
|
+
const env = { ...process.env }
|
|
30
|
+
const lifecycle = resolveLifecycle({ mode: 'auto', env })
|
|
31
|
+
const exportMode = exportModeFromEnv(env, { lifecycle: lifecycle.lifecycle })
|
|
32
|
+
const config = loadRuntimeConfig(env)
|
|
33
|
+
const runtime = NetGreener.init({ config, runtime: 'auto' })
|
|
34
|
+
|
|
35
|
+
runtime.beginRequest()
|
|
36
|
+
runtime.recordHttp({
|
|
37
|
+
method: 'POST',
|
|
38
|
+
path: '/api/serverless-pilot',
|
|
39
|
+
statusCode: 200,
|
|
40
|
+
durationMs: 12,
|
|
41
|
+
cpuTimeMs: 1,
|
|
42
|
+
peakRssKb: 50_000,
|
|
43
|
+
})
|
|
44
|
+
runtime.endRequest()
|
|
45
|
+
const result = await NetGreener.flushForInvokeEnd()
|
|
46
|
+
|
|
47
|
+
mkdirSync(artifactDir, { recursive: true })
|
|
48
|
+
const runId = result?.ok && !result.dryRun ? extractRunId(result.body) : null
|
|
49
|
+
const summary = {
|
|
50
|
+
gate: 'CHK-R6.serverless-degraded',
|
|
51
|
+
label: 'Serverless Runtime (thin) pilot',
|
|
52
|
+
claim_ready: Boolean(runId),
|
|
53
|
+
lifecycle: lifecycle.lifecycle,
|
|
54
|
+
platform: lifecycle.platform,
|
|
55
|
+
export_mode: exportMode,
|
|
56
|
+
dry_run: Boolean(result?.dryRun),
|
|
57
|
+
ok: Boolean(result?.ok),
|
|
58
|
+
run_id: runId,
|
|
59
|
+
flushed_at: new Date().toISOString(),
|
|
60
|
+
}
|
|
61
|
+
writeFileSync(join(artifactDir, 'latest.json'), JSON.stringify({ summary, result }, null, 2))
|
|
62
|
+
writeFileSync(
|
|
63
|
+
join(artifactDir, 'SUMMARY.md'),
|
|
64
|
+
[
|
|
65
|
+
'# Serverless thin gate evidence',
|
|
66
|
+
'',
|
|
67
|
+
`- check_id: \`CHK-R6.serverless-degraded\``,
|
|
68
|
+
`- label: pilot (not production until live run_id + new approval_ref)`,
|
|
69
|
+
`- lifecycle: \`${lifecycle.lifecycle}\` (must be ephemeral)`,
|
|
70
|
+
`- platform: \`${lifecycle.platform}\``,
|
|
71
|
+
`- export_mode: \`${exportMode}\` (prefer thin when unset)`,
|
|
72
|
+
`- dry_run: \`${summary.dry_run}\``,
|
|
73
|
+
`- ok: \`${summary.ok}\``,
|
|
74
|
+
`- run_id: \`${runId ?? '(none — dry-run or upload body without id)'}\``,
|
|
75
|
+
`- claim_ready: \`${summary.claim_ready}\``,
|
|
76
|
+
`- flushed_at: \`${summary.flushed_at}\``,
|
|
77
|
+
'',
|
|
78
|
+
].join('\n'),
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
console.log(JSON.stringify(summary, null, 2))
|
|
82
|
+
_resetRuntimeForTests()
|
|
83
|
+
if (
|
|
84
|
+
!result?.ok ||
|
|
85
|
+
lifecycle.lifecycle !== 'ephemeral' ||
|
|
86
|
+
exportMode !== 'thin'
|
|
87
|
+
) {
|
|
88
|
+
process.exit(1)
|
|
89
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netgreener/runtime",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "NetGreener Node.js Runtime
|
|
3
|
+
"version": "0.1.9",
|
|
4
|
+
"description": "NetGreener Node.js Runtime — Express/Fastify/Nest/Next/process adapter uploading RunSessions to api_server.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -30,9 +30,21 @@
|
|
|
30
30
|
"types": "./dist/nest.d.ts",
|
|
31
31
|
"import": "./dist/nest.js"
|
|
32
32
|
},
|
|
33
|
+
"./next": {
|
|
34
|
+
"types": "./dist/next.d.ts",
|
|
35
|
+
"import": "./dist/next.js"
|
|
36
|
+
},
|
|
37
|
+
"./auto": {
|
|
38
|
+
"types": "./dist/auto.d.ts",
|
|
39
|
+
"import": "./dist/auto.js"
|
|
40
|
+
},
|
|
33
41
|
"./analyze": {
|
|
34
42
|
"types": "./dist/analyze/index.d.ts",
|
|
35
43
|
"import": "./dist/analyze/index.js"
|
|
44
|
+
},
|
|
45
|
+
"./sdk": {
|
|
46
|
+
"types": "./dist/sdk/index.d.ts",
|
|
47
|
+
"import": "./dist/sdk/index.js"
|
|
36
48
|
}
|
|
37
49
|
},
|
|
38
50
|
"files": [
|
|
@@ -53,6 +65,10 @@
|
|
|
53
65
|
"conformance:check": "npm run build && npm run conformance:test",
|
|
54
66
|
"conformance:run": "npm run conformance:check && node scripts/run-contract-conformance.mjs",
|
|
55
67
|
"example:dry-run": "npm run build && node examples/express-dry-run.mjs",
|
|
68
|
+
"example:express-local-live": "npm run build && node examples/express-local-live-smoke.mjs",
|
|
69
|
+
"example:aca-container-gate": "npm run build && node --env-file=examples/aca-container-gate/gate.env examples/aca-container-gate/server.mjs",
|
|
70
|
+
"example:next-pilot": "npm run build && node examples/next-pilot-dry-run.mjs",
|
|
71
|
+
"example:serverless-thin-gate": "npm run build && node examples/serverless-thin-gate.mjs",
|
|
56
72
|
"example:dogfood-tenant": "npm run build && node examples/tenant-dogfood.mjs",
|
|
57
73
|
"example:bullmq-live-smoke": "npm run build && node examples/bullmq-live-smoke.mjs",
|
|
58
74
|
"example:bullmq-mp3-gate": "npm run build && node examples/bullmq-mp3-worker-gate.mjs",
|
|
@@ -66,10 +82,13 @@
|
|
|
66
82
|
"example:production-prep-smoke": "npm run build && node scripts/production-prep-smoke.mjs",
|
|
67
83
|
"example:publish-prep": "npm run build && node scripts/publish-prep.mjs",
|
|
68
84
|
"example:sbom-prep": "node scripts/sbom-prep.mjs",
|
|
85
|
+
"example:overhead-measure": "npm run build && node scripts/overhead-measure.mjs",
|
|
69
86
|
"example:push-github-public": "node scripts/push-github-public.mjs",
|
|
70
87
|
"example:push-github-release": "node scripts/push-github-public.mjs --push-release-tag",
|
|
71
88
|
"example:retain-dry-run": "npm run build && node examples/retain-dry-run.mjs",
|
|
72
89
|
"example:dry-run-artifact-smoke": "npm run build && node scripts/dry-run-artifact-smoke.mjs",
|
|
90
|
+
"example:n5b-linux-gate": "npm run build && node scripts/n5b-linux-gate.mjs",
|
|
91
|
+
"example:n5b-flush-dogfood": "npm run build && node scripts/n5b-flush-dogfood.mjs",
|
|
73
92
|
"test:observation": "npm run build && node --test conformance/observation-v1.test.mjs"
|
|
74
93
|
},
|
|
75
94
|
"engines": {
|
|
@@ -90,6 +109,8 @@
|
|
|
90
109
|
"carbon",
|
|
91
110
|
"express",
|
|
92
111
|
"fastify",
|
|
112
|
+
"next",
|
|
113
|
+
"typescript",
|
|
93
114
|
"observability"
|
|
94
115
|
],
|
|
95
116
|
"license": "UNLICENSED",
|