diff --git a/.github/workflows/backcompat.yml b/.github/workflows/backcompat.yml index 16a095ca..d6d5bce0 100644 --- a/.github/workflows/backcompat.yml +++ b/.github/workflows/backcompat.yml @@ -18,7 +18,7 @@ jobs: steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version: ${{ matrix.node-version }} - run: npm i diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index bb8e51f5..27d3edad 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -21,7 +21,7 @@ jobs: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - run: openssl req -x509 -nodes -newkey rsa -keyout ./test/certs/server-key.pem -out ./test/certs/server-cert.pem -days 1 -subj "/C=CL/ST=RM/L=OpenTelemetryTest/O=Root/OU=Test/CN=ca" - name: Use Node.js ${{ matrix.node-version.version }} - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version: ${{ matrix.node-version.version }} - run: npm i diff --git a/.github/workflows/node.js-linux-arm64.yml b/.github/workflows/node.js-linux-arm64.yml index 48d9fefe..1e804103 100644 --- a/.github/workflows/node.js-linux-arm64.yml +++ b/.github/workflows/node.js-linux-arm64.yml @@ -27,7 +27,7 @@ jobs: openssl req -x509 -nodes -newkey rsa:2048 -keyout ./test/certs/server-key.pem -out ./test/certs/server-cert.pem -days 1 -subj "/C=CL/ST=RM/L=OpenTelemetryTest/O=Root/OU=Test/CN=ca" - name: Use Node.js ${{ matrix.node-version.version }} - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version: ${{ matrix.node-version.version }} diff --git a/.github/workflows/node.js-windows.yml b/.github/workflows/node.js-windows.yml index ccf44330..d41b10de 100644 --- a/.github/workflows/node.js-windows.yml +++ b/.github/workflows/node.js-windows.yml @@ -43,7 +43,7 @@ jobs: Set-Content -Path "$certsDir\server-key.pem" -Value "-----BEGIN PRIVATE KEY-----`r`n$randomKeyContent`r`n-----END PRIVATE KEY-----" - name: Use Node.js ${{ matrix.node-version.version }} - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version: ${{ matrix.node-version.version }} diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 5ab500bc..4fc58eb5 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -24,7 +24,7 @@ jobs: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - run: openssl req -x509 -nodes -newkey rsa -keyout ./test/certs/server-key.pem -out ./test/certs/server-cert.pem -days 1 -subj "/C=CL/ST=RM/L=OpenTelemetryTest/O=Root/OU=Test/CN=ca" - name: (${{ matrix.os }}) on Node.js ${{ matrix.node-version.version }} - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version: ${{ matrix.node-version.version }} - run: npm run clean diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index c2a78d0e..ed9bb4ed 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version: '22.23.4' - run: npm ci @@ -25,7 +25,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version: '22.23.4' registry-url: https://registry.npmjs.org/ diff --git a/.github/workflows/performance-comment.yml b/.github/workflows/performance-comment.yml index a00f9d9b..d7c1cf86 100644 --- a/.github/workflows/performance-comment.yml +++ b/.github/workflows/performance-comment.yml @@ -41,7 +41,7 @@ jobs: - name: Check out base repository (trusted) uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version: '22.23.4' @@ -50,7 +50,7 @@ jobs: # Don't fail this job if the upstream Performance run was cancelled # or failed before producing the artifact — we just skip posting. continue-on-error: true - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 with: name: perf-results path: perf-results diff --git a/.github/workflows/performance.yml b/.github/workflows/performance.yml index e9a79451..0d961c20 100644 --- a/.github/workflows/performance.yml +++ b/.github/workflows/performance.yml @@ -38,7 +38,7 @@ jobs: ref: ${{ github.event.pull_request.base.ref }} path: baseline - - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version: ${{ env.NODE_VERSION }} @@ -76,9 +76,9 @@ jobs: working-directory: pr/test/performanceTests run: npm install --no-save --no-package-lock "$GITHUB_WORKSPACE/candidate.tgz" - - name: Build perf harness (TS -> dist-esm) + - name: Build perf harness and check memory usage working-directory: pr/test/performanceTests - run: npm run build + run: npm run test:memory - name: Run candidate benchmarks working-directory: pr/test/performanceTests @@ -118,7 +118,7 @@ jobs: - name: Upload perf results artifact if: always() - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: perf-results path: | diff --git a/test/performanceTests/README.md b/test/performanceTests/README.md index 76a314e8..a7b1f8f8 100644 --- a/test/performanceTests/README.md +++ b/test/performanceTests/README.md @@ -36,11 +36,20 @@ Only **gating** scenarios block CI on regression. Upstream-OTel scenarios are reported as a reference for like-for-like comparison and are not owned by this repo, so they are never used for gate-fail decisions. +The upstream-OTel scenarios keep their simple processors but export to a +synchronous discard sink. This measures SDK processing without retaining every +span or log record, or accumulating timer-backed export callbacks, across warmup +and samples. Scenario failures still fail the benchmark run regardless of tier. + +Run `npm run test:memory` from this directory to check that both upstream-OTel +scenarios complete warmup and three samples with a 64 MiB old-space limit. + #### Regression CI -`.github/workflows/performance.yml` runs on every PR. It packs both the PR and -the base branch as tarballs, installs each in turn under the PR's perf harness, -runs the benchmark suite, and fails the job (blocking merge when set as a +`.github/workflows/performance.yml` runs the memory checks and benchmarks on +every PR. It packs both the PR and the base branch as tarballs, installs each +in turn under the PR's perf harness, runs the benchmark suite, and fails the +job (blocking merge when set as a required check) if any gating scenario regresses beyond `PERF_REGRESSION_THRESHOLD` percent (default 15%). All benchmark results are uploaded as the `perf-results` artifact. diff --git a/test/performanceTests/benchmarkMemory.test.mjs b/test/performanceTests/benchmarkMemory.test.mjs new file mode 100644 index 00000000..38142707 --- /dev/null +++ b/test/performanceTests/benchmarkMemory.test.mjs @@ -0,0 +1,45 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import assert from "node:assert/strict"; +import { spawnSync } from "node:child_process"; +import { mkdtempSync, readFileSync, rmSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { test } from "node:test"; +import { fileURLToPath } from "node:url"; + +for (const scenario of ["OtelSpanTest", "OtelLogTest"]) { + test(`${scenario} completes multiple samples with a bounded heap`, () => { + const tmp = mkdtempSync(join(tmpdir(), "perf-memory-")); + try { + const out = join(tmp, "samples.json"); + const child = spawnSync( + process.execPath, + [ + "--max-old-space-size=64", + fileURLToPath(new URL("./bench.mjs", import.meta.url)), + "--scenario", scenario, + "--samples", "3", + "--duration", "1", + "--warmup", "1", + "--out", out, + ], + { encoding: "utf8", timeout: 30000 }, + ); + assert.ifError(child.error); + assert.equal(child.signal, null, child.stderr); + assert.equal(child.status, 0, child.stderr); + const result = JSON.parse(readFileSync(out, "utf8")); + assert.equal(result.scenario, scenario); + assert.equal(result.samples.length, 3); + for (const sample of result.samples) { + assert.ok(sample.ops > 0); + assert.ok(sample.elapsedMs >= 1000); + assert.ok(Number.isFinite(sample.opsPerSec) && sample.opsPerSec > 0); + } + } finally { + rmSync(tmp, { recursive: true, force: true }); + } + }); +} diff --git a/test/performanceTests/package-lock.json b/test/performanceTests/package-lock.json index ed16e416..2852b99b 100644 --- a/test/performanceTests/package-lock.json +++ b/test/performanceTests/package-lock.json @@ -12,6 +12,7 @@ "@azure-tools/test-perf": "^1.0.0", "@opentelemetry/api": "^1.9.1", "@opentelemetry/api-logs": "^0.221.0", + "@opentelemetry/core": "^2.10.0", "@opentelemetry/sdk-logs": "^0.221.0", "@opentelemetry/sdk-trace-base": "^2.10.0", "applicationinsights": "^3.16.0", diff --git a/test/performanceTests/package.json b/test/performanceTests/package.json index 343a5a7f..d3d2723d 100644 --- a/test/performanceTests/package.json +++ b/test/performanceTests/package.json @@ -12,6 +12,7 @@ "@azure-tools/test-perf": "^1.0.0", "@opentelemetry/api": "^1.9.1", "@opentelemetry/api-logs": "^0.221.0", + "@opentelemetry/core": "^2.10.0", "@opentelemetry/sdk-logs": "^0.221.0", "@opentelemetry/sdk-trace-base": "^2.10.0", "applicationinsights": "^3.16.0", @@ -32,6 +33,7 @@ "perf-test:node": "npm run build && node dist-esm/index.spec.js", "perf:benchmark": "npm run build && node runBenchmarks.mjs", "perf:compare": "node comparePerf.mjs", + "test:memory": "npm run build && node --test benchmarkMemory.test.mjs", "audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit", "build": "npm run clean && tsc -p .", "build:samples": "echo skipped", diff --git a/test/performanceTests/test/discardingExporter.ts b/test/performanceTests/test/discardingExporter.ts new file mode 100644 index 00000000..5b324420 --- /dev/null +++ b/test/performanceTests/test/discardingExporter.ts @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { ExportResultCode, type ExportResult } from "@opentelemetry/core"; +import type { LogRecordExporter, ReadableLogRecord } from "@opentelemetry/sdk-logs"; +import type { ReadableSpan, SpanExporter } from "@opentelemetry/sdk-trace-base"; + +export class DiscardingExporter implements SpanExporter, LogRecordExporter { + export( + _items: ReadableSpan[] | ReadableLogRecord[], + resultCallback: (result: ExportResult) => void, + ): void { + // Retain neither telemetry nor timer callbacks across benchmark samples. + resultCallback({ code: ExportResultCode.SUCCESS }); + } + + forceFlush(): Promise { + return Promise.resolve(); + } + + shutdown(): Promise { + return Promise.resolve(); + } +} diff --git a/test/performanceTests/test/otelLog.spec.ts b/test/performanceTests/test/otelLog.spec.ts index 74ef890b..5a97e0a3 100644 --- a/test/performanceTests/test/otelLog.spec.ts +++ b/test/performanceTests/test/otelLog.spec.ts @@ -13,8 +13,8 @@ import type { Logger } from "@opentelemetry/api-logs"; import { LoggerProvider, SimpleLogRecordProcessor, - InMemoryLogRecordExporter, } from "@opentelemetry/sdk-logs"; +import { DiscardingExporter } from "./discardingExporter.js"; type OtelLogOptions = Record; @@ -24,7 +24,7 @@ function ensureProvider(): Logger { return logger; } const provider = new LoggerProvider({ - processors: [new SimpleLogRecordProcessor({ exporter: new InMemoryLogRecordExporter() })], + processors: [new SimpleLogRecordProcessor({ exporter: new DiscardingExporter() })], }); logger = provider.getLogger("perf-otel-log"); return logger; diff --git a/test/performanceTests/test/otelSpan.spec.ts b/test/performanceTests/test/otelSpan.spec.ts index ee664b06..db0b679e 100644 --- a/test/performanceTests/test/otelSpan.spec.ts +++ b/test/performanceTests/test/otelSpan.spec.ts @@ -13,8 +13,8 @@ import type { Tracer } from "@opentelemetry/api"; import { BasicTracerProvider, SimpleSpanProcessor, - InMemorySpanExporter, } from "@opentelemetry/sdk-trace-base"; +import { DiscardingExporter } from "./discardingExporter.js"; type OtelSpanOptions = Record; @@ -24,7 +24,7 @@ function ensureProvider(): Tracer { return tracer; } const provider = new BasicTracerProvider({ - spanProcessors: [new SimpleSpanProcessor(new InMemorySpanExporter())], + spanProcessors: [new SimpleSpanProcessor(new DiscardingExporter())], }); tracer = provider.getTracer("perf-otel-span"); return tracer;