From c905149fb9befb58473c314b2c593c152f9d8977 Mon Sep 17 00:00:00 2001 From: Jackson Weber Date: Wed, 21 May 2025 15:02:16 -0700 Subject: [PATCH 01/18] Add new architecture test builds. --- .github/workflows/node.js-linux-arm64.yml | 30 ++++++++++++ .github/workflows/node.js-windows-arm64.yml | 51 ++++++++++++++++++++ .github/workflows/node.js-windows-x86.yml | 53 +++++++++++++++++++++ .github/workflows/node.js.yml | 2 +- 4 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/node.js-linux-arm64.yml create mode 100644 .github/workflows/node.js-windows-arm64.yml create mode 100644 .github/workflows/node.js-windows-x86.yml diff --git a/.github/workflows/node.js-linux-arm64.yml b/.github/workflows/node.js-linux-arm64.yml new file mode 100644 index 000000000..c0801789c --- /dev/null +++ b/.github/workflows/node.js-linux-arm64.yml @@ -0,0 +1,30 @@ +name: Node.js CI (Linux ARM64) + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + + runs-on: ubuntu-20.04-arm64 + + strategy: + matrix: + # Using the same Node versions as the main workflow + node-version: [16.x, 18.x, 20.x, 22.x] + + steps: + - uses: actions/checkout@v2 + - 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: (Linux ARM64) on Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - run: npm run clean + - run: npm i + - run: npm run build --if-present + - run: npm run lint + - run: npm test diff --git a/.github/workflows/node.js-windows-arm64.yml b/.github/workflows/node.js-windows-arm64.yml new file mode 100644 index 000000000..6fb73adf3 --- /dev/null +++ b/.github/workflows/node.js-windows-arm64.yml @@ -0,0 +1,51 @@ +name: Node.js CI (Windows ARM64) + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + + runs-on: windows-latest-arm64 + + strategy: + matrix: + # Using the same Node versions as the main workflow + node-version: [16.x, 18.x, 20.x, 22.x] + + steps: + - uses: actions/checkout@v2 + # For Windows, we'll need to use different commands to generate certificates + - name: Generate SSL Certificate + shell: pwsh + run: | + $cert = New-SelfSignedCertificate -Subject "CN=ca,OU=Test,O=Root,L=OpenTelemetryTest,ST=RM,C=CL" -NotAfter (Get-Date).AddDays(1) + $certPath = ".\test\certs\server-cert.pem" + $keyPath = ".\test\certs\server-key.pem" + + $certsDir = ".\test\certs" + if (-not (Test-Path $certsDir)) { + New-Item -ItemType Directory -Path $certsDir + } + + # Export certificate to PEM format + $certBytesExported = $cert.Export("Cert") + $pemCert = "-----BEGIN CERTIFICATE-----`r`n" + [Convert]::ToBase64String($certBytesExported, [System.Base64FormattingOptions]::InsertLineBreaks) + "`r`n-----END CERTIFICATE-----" + Set-Content -Path $certPath -Value $pemCert + + # For the key, we'll output a placeholder PEM file (since getting the private key in correct format is complex) + Set-Content -Path $keyPath -Value "-----BEGIN PRIVATE KEY-----`r`nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDErOYjDfNuL+uI`r`nSamplePrivateKeyContentPlaceholder==`r`n-----END PRIVATE KEY-----" + + - name: (Windows ARM64) on Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + + - run: npm run clean + - run: npm i + - run: npm run build --if-present + - run: npm run lint + - run: npm test diff --git a/.github/workflows/node.js-windows-x86.yml b/.github/workflows/node.js-windows-x86.yml new file mode 100644 index 000000000..09034dc42 --- /dev/null +++ b/.github/workflows/node.js-windows-x86.yml @@ -0,0 +1,53 @@ +name: Node.js CI (Windows x86) + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + + runs-on: windows-latest + + strategy: + matrix: + # Using the same Node versions as the main workflow + node-version: [16.x, 18.x, 20.x, 22.x] + architecture: ["x86"] # 32-bit architecture + + steps: + - uses: actions/checkout@v2 + # For Windows, we''ll need to use different commands to generate certificates + - name: Generate SSL Certificate + shell: pwsh + run: | + $cert = New-SelfSignedCertificate -Subject "CN=ca,OU=Test,O=Root,L=OpenTelemetryTest,ST=RM,C=CL" -NotAfter (Get-Date).AddDays(1) + $certPath = ".\test\certs\server-cert.pem" + $keyPath = ".\test\certs\server-key.pem" + + $certsDir = ".\test\certs" + if (-not (Test-Path $certsDir)) { + New-Item -ItemType Directory -Path $certsDir + } + + # Export certificate to PEM format + $certBytesExported = $cert.Export("Cert") + $pemCert = "-----BEGIN CERTIFICATE-----`r`n" + [Convert]::ToBase64String($certBytesExported, [System.Base64FormattingOptions]::InsertLineBreaks) + "`r`n-----END CERTIFICATE-----" + Set-Content -Path $certPath -Value $pemCert + + # For the key, we''ll output a placeholder PEM file (since getting the private key in correct format is complex) + Set-Content -Path $keyPath -Value "-----BEGIN PRIVATE KEY-----`r`nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDErOYjDfNuL+uI`r`nSamplePrivateKeyContentPlaceholder==`r`n-----END PRIVATE KEY-----" + + - name: (Windows x86) on Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + architecture: ${{ matrix.architecture }} # Specify x86 architecture + + - run: npm run clean + - run: npm i + - run: npm run build --if-present + - run: npm run lint + - run: npm test diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 36f87f6dd..6ad18a72d 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -15,7 +15,7 @@ jobs: matrix: os: [ubuntu-latest] # TODO: Enable Node 14.x when we update the pipeline to support AbortController - node-version: [16.x, 18.x] + node-version: [16.x, 18.x, 20.x, 22.x] steps: - uses: actions/checkout@v2 From bfec9493d82523ae747215a9d294dcd57bb080cb Mon Sep 17 00:00:00 2001 From: Jackson Weber Date: Wed, 21 May 2025 15:09:42 -0700 Subject: [PATCH 02/18] Comment x86 for now. --- .github/workflows/node.js-windows-x86.yml | 86 +++++++++++------------ 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/.github/workflows/node.js-windows-x86.yml b/.github/workflows/node.js-windows-x86.yml index 09034dc42..f4772a02f 100644 --- a/.github/workflows/node.js-windows-x86.yml +++ b/.github/workflows/node.js-windows-x86.yml @@ -1,53 +1,53 @@ -name: Node.js CI (Windows x86) +# name: Node.js CI (Windows x86) -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] +# on: +# push: +# branches: [ main ] +# pull_request: +# branches: [ main ] -jobs: - build: +# jobs: +# build: - runs-on: windows-latest +# runs-on: windows-latest - strategy: - matrix: - # Using the same Node versions as the main workflow - node-version: [16.x, 18.x, 20.x, 22.x] - architecture: ["x86"] # 32-bit architecture +# strategy: +# matrix: +# # Using the same Node versions as the main workflow +# node-version: [16.x] +# architecture: ["x86"] # 32-bit architecture - steps: - - uses: actions/checkout@v2 - # For Windows, we''ll need to use different commands to generate certificates - - name: Generate SSL Certificate - shell: pwsh - run: | - $cert = New-SelfSignedCertificate -Subject "CN=ca,OU=Test,O=Root,L=OpenTelemetryTest,ST=RM,C=CL" -NotAfter (Get-Date).AddDays(1) - $certPath = ".\test\certs\server-cert.pem" - $keyPath = ".\test\certs\server-key.pem" +# steps: +# - uses: actions/checkout@v2 +# # For Windows, we''ll need to use different commands to generate certificates +# - name: Generate SSL Certificate +# shell: pwsh +# run: | +# $cert = New-SelfSignedCertificate -Subject "CN=ca,OU=Test,O=Root,L=OpenTelemetryTest,ST=RM,C=CL" -NotAfter (Get-Date).AddDays(1) +# $certPath = ".\test\certs\server-cert.pem" +# $keyPath = ".\test\certs\server-key.pem" - $certsDir = ".\test\certs" - if (-not (Test-Path $certsDir)) { - New-Item -ItemType Directory -Path $certsDir - } +# $certsDir = ".\test\certs" +# if (-not (Test-Path $certsDir)) { +# New-Item -ItemType Directory -Path $certsDir +# } - # Export certificate to PEM format - $certBytesExported = $cert.Export("Cert") - $pemCert = "-----BEGIN CERTIFICATE-----`r`n" + [Convert]::ToBase64String($certBytesExported, [System.Base64FormattingOptions]::InsertLineBreaks) + "`r`n-----END CERTIFICATE-----" - Set-Content -Path $certPath -Value $pemCert +# # Export certificate to PEM format +# $certBytesExported = $cert.Export("Cert") +# $pemCert = "-----BEGIN CERTIFICATE-----`r`n" + [Convert]::ToBase64String($certBytesExported, [System.Base64FormattingOptions]::InsertLineBreaks) + "`r`n-----END CERTIFICATE-----" +# Set-Content -Path $certPath -Value $pemCert - # For the key, we''ll output a placeholder PEM file (since getting the private key in correct format is complex) - Set-Content -Path $keyPath -Value "-----BEGIN PRIVATE KEY-----`r`nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDErOYjDfNuL+uI`r`nSamplePrivateKeyContentPlaceholder==`r`n-----END PRIVATE KEY-----" +# # For the key, we''ll output a placeholder PEM file (since getting the private key in correct format is complex) +# Set-Content -Path $keyPath -Value "-----BEGIN PRIVATE KEY-----`r`nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDErOYjDfNuL+uI`r`nSamplePrivateKeyContentPlaceholder==`r`n-----END PRIVATE KEY-----" - - name: (Windows x86) on Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - architecture: ${{ matrix.architecture }} # Specify x86 architecture +# - name: (Windows x86) on Node.js ${{ matrix.node-version }} +# uses: actions/setup-node@v1 +# with: +# node-version: ${{ matrix.node-version }} +# architecture: ${{ matrix.architecture }} # Specify x86 architecture - - run: npm run clean - - run: npm i - - run: npm run build --if-present - - run: npm run lint - - run: npm test +# - run: npm run clean +# - run: npm i +# - run: npm run build --if-present +# - run: npm run lint +# - run: npm test From 1186435483149d5ccf43994caa51cce129875c3d Mon Sep 17 00:00:00 2001 From: Jackson Weber Date: Wed, 21 May 2025 15:14:09 -0700 Subject: [PATCH 03/18] Fix key generation. --- .github/workflows/node.js-windows-arm64.yml | 8 +- .github/workflows/node.js-windows-x86.yml | 90 +++++++++++---------- 2 files changed, 53 insertions(+), 45 deletions(-) diff --git a/.github/workflows/node.js-windows-arm64.yml b/.github/workflows/node.js-windows-arm64.yml index 6fb73adf3..6675480fb 100644 --- a/.github/workflows/node.js-windows-arm64.yml +++ b/.github/workflows/node.js-windows-arm64.yml @@ -36,8 +36,12 @@ jobs: $pemCert = "-----BEGIN CERTIFICATE-----`r`n" + [Convert]::ToBase64String($certBytesExported, [System.Base64FormattingOptions]::InsertLineBreaks) + "`r`n-----END CERTIFICATE-----" Set-Content -Path $certPath -Value $pemCert - # For the key, we'll output a placeholder PEM file (since getting the private key in correct format is complex) - Set-Content -Path $keyPath -Value "-----BEGIN PRIVATE KEY-----`r`nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDErOYjDfNuL+uI`r`nSamplePrivateKeyContentPlaceholder==`r`n-----END PRIVATE KEY-----" + # For the key, we'll output a placeholder PEM file + # Using secure random bytes for the key content rather than hardcoded text + $randomBytes = New-Object byte[] 32 + [Security.Cryptography.RNGCryptoServiceProvider]::Create().GetBytes($randomBytes) + $randomKeyContent = [Convert]::ToBase64String($randomBytes) + Set-Content -Path $keyPath -Value "-----BEGIN PRIVATE KEY-----`r`n$randomKeyContent`r`n-----END PRIVATE KEY-----" - name: (Windows ARM64) on Node.js ${{ matrix.node-version }} uses: actions/setup-node@v1 diff --git a/.github/workflows/node.js-windows-x86.yml b/.github/workflows/node.js-windows-x86.yml index f4772a02f..a48e7017a 100644 --- a/.github/workflows/node.js-windows-x86.yml +++ b/.github/workflows/node.js-windows-x86.yml @@ -1,53 +1,57 @@ -# name: Node.js CI (Windows x86) +name: Node.js CI (Windows x86) -# on: -# push: -# branches: [ main ] -# pull_request: -# branches: [ main ] +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] -# jobs: -# build: +jobs: + build: -# runs-on: windows-latest + runs-on: windows-latest -# strategy: -# matrix: -# # Using the same Node versions as the main workflow -# node-version: [16.x] -# architecture: ["x86"] # 32-bit architecture + strategy: + matrix: + # Using the same Node versions as the main workflow + node-version: [16.x, 18.x, 20.x, 22.x] + architecture: ["x86"] # 32-bit architecture -# steps: -# - uses: actions/checkout@v2 -# # For Windows, we''ll need to use different commands to generate certificates -# - name: Generate SSL Certificate -# shell: pwsh -# run: | -# $cert = New-SelfSignedCertificate -Subject "CN=ca,OU=Test,O=Root,L=OpenTelemetryTest,ST=RM,C=CL" -NotAfter (Get-Date).AddDays(1) -# $certPath = ".\test\certs\server-cert.pem" -# $keyPath = ".\test\certs\server-key.pem" + steps: + - uses: actions/checkout@v2 + # For Windows, we''ll need to use different commands to generate certificates + - name: Generate SSL Certificate + shell: pwsh + run: | + $cert = New-SelfSignedCertificate -Subject "CN=ca,OU=Test,O=Root,L=OpenTelemetryTest,ST=RM,C=CL" -NotAfter (Get-Date).AddDays(1) + $certPath = ".\test\certs\server-cert.pem" + $keyPath = ".\test\certs\server-key.pem" -# $certsDir = ".\test\certs" -# if (-not (Test-Path $certsDir)) { -# New-Item -ItemType Directory -Path $certsDir -# } + $certsDir = ".\test\certs" + if (-not (Test-Path $certsDir)) { + New-Item -ItemType Directory -Path $certsDir + } -# # Export certificate to PEM format -# $certBytesExported = $cert.Export("Cert") -# $pemCert = "-----BEGIN CERTIFICATE-----`r`n" + [Convert]::ToBase64String($certBytesExported, [System.Base64FormattingOptions]::InsertLineBreaks) + "`r`n-----END CERTIFICATE-----" -# Set-Content -Path $certPath -Value $pemCert + # Export certificate to PEM format + $certBytesExported = $cert.Export("Cert") + $pemCert = "-----BEGIN CERTIFICATE-----`r`n" + [Convert]::ToBase64String($certBytesExported, [System.Base64FormattingOptions]::InsertLineBreaks) + "`r`n-----END CERTIFICATE-----" + Set-Content -Path $certPath -Value $pemCert -# # For the key, we''ll output a placeholder PEM file (since getting the private key in correct format is complex) -# Set-Content -Path $keyPath -Value "-----BEGIN PRIVATE KEY-----`r`nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDErOYjDfNuL+uI`r`nSamplePrivateKeyContentPlaceholder==`r`n-----END PRIVATE KEY-----" + # For the key, we''ll output a placeholder PEM file + # Using secure random bytes for the key content rather than hardcoded text + $randomBytes = New-Object byte[] 32 + [Security.Cryptography.RNGCryptoServiceProvider]::Create().GetBytes($randomBytes) + $randomKeyContent = [Convert]::ToBase64String($randomBytes) + Set-Content -Path $keyPath -Value "-----BEGIN PRIVATE KEY-----`r`n$randomKeyContent`r`n-----END PRIVATE KEY-----" -# - name: (Windows x86) on Node.js ${{ matrix.node-version }} -# uses: actions/setup-node@v1 -# with: -# node-version: ${{ matrix.node-version }} -# architecture: ${{ matrix.architecture }} # Specify x86 architecture + - name: (Windows x86) on Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + architecture: ${{ matrix.architecture }} # Specify x86 architecture -# - run: npm run clean -# - run: npm i -# - run: npm run build --if-present -# - run: npm run lint -# - run: npm test + - run: npm run clean + - run: npm i + - run: npm run build --if-present + - run: npm run lint + - run: npm test From 404bc3c3dbe82d300dda04a71c71395284d1a62b Mon Sep 17 00:00:00 2001 From: Jackson Weber Date: Wed, 21 May 2025 15:43:27 -0700 Subject: [PATCH 04/18] Update node.js-windows-x86.yml --- .github/workflows/node.js-windows-x86.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/node.js-windows-x86.yml b/.github/workflows/node.js-windows-x86.yml index a48e7017a..59891a58f 100644 --- a/.github/workflows/node.js-windows-x86.yml +++ b/.github/workflows/node.js-windows-x86.yml @@ -51,7 +51,13 @@ jobs: architecture: ${{ matrix.architecture }} # Specify x86 architecture - run: npm run clean - - run: npm i + - name: Install dependencies + run: | + npm i + # Verify diagnostic-channel-publishers is properly installed + if (!(Test-Path -Path node_modules/diagnostic-channel-publishers)) { + npm i diagnostic-channel-publishers --no-save + } - run: npm run build --if-present - run: npm run lint - run: npm test From 789a041f1b4136fac692e9de29623d0e4391ecbc Mon Sep 17 00:00:00 2001 From: Jackson Weber Date: Wed, 21 May 2025 15:55:52 -0700 Subject: [PATCH 05/18] Fix x86 test attempting to establish a network connection during quickpulse tests. --- .github/workflows/node.js-windows-x86.yml | 5 +++- package.json | 1 + test/mocks/quickpulse-mock.js | 32 +++++++++++++++++++++++ test/test-setup.js | 14 ++++++++++ 4 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 test/mocks/quickpulse-mock.js create mode 100644 test/test-setup.js diff --git a/.github/workflows/node.js-windows-x86.yml b/.github/workflows/node.js-windows-x86.yml index 59891a58f..ae5d7f7c0 100644 --- a/.github/workflows/node.js-windows-x86.yml +++ b/.github/workflows/node.js-windows-x86.yml @@ -60,4 +60,7 @@ jobs: } - run: npm run build --if-present - run: npm run lint - - run: npm test + - name: Run tests with mocks + run: | + # Run tests with mock setup to prevent any real network connections + npm run test:mocked diff --git a/package.json b/package.json index 5e9819b05..0f2f539f3 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "lint": "eslint ./ --fix", "pretest": "npm run build", "test": "nyc mocha ./out/test --recursive", + "test:mocked": "node ./test/test-setup.js && nyc mocha ./out/test --recursive", "test:debug": "nyc mocha ./out/test --inspect-brk --recursive", "test:unit": "nyc mocha ./out/test/unitTests --recursive", "test:e2e": "nyc mocha ./out/test/endToEnd --recursive", diff --git a/test/mocks/quickpulse-mock.js b/test/mocks/quickpulse-mock.js new file mode 100644 index 000000000..029eede85 --- /dev/null +++ b/test/mocks/quickpulse-mock.js @@ -0,0 +1,32 @@ +// Helper to mock QuickPulse service endpoints +// This ensures tests never connect to real external endpoints + +const nock = require("nock"); + +// Mock QuickPulse service endpoints +function mockQuickPulseEndpoints() { + // Mock the ping endpoint with a successful response + nock("https://global.livediagnostics.monitor.azure.com:443") + .persist() + .get(/\/QuickPulseService\.svc\/ping/) + .reply(200, { + "StatusCode": 200, + "ResponseType": 0, + "ConnectionPollingInterval": 60000, + "Messages": [] + }); + + // Mock the post endpoint for submitting metrics + nock("https://global.livediagnostics.monitor.azure.com:443") + .persist() + .post(/\/QuickPulseService\.svc\/post/) + .reply(200, { + "StatusCode": 200, + "ResponseType": 0, + "ConnectionPollingInterval": 60000, + "Messages": [] + }); +} + +// Export the mocking function so it can be used by tests +module.exports = { mockQuickPulseEndpoints }; diff --git a/test/test-setup.js b/test/test-setup.js new file mode 100644 index 000000000..99d3662e9 --- /dev/null +++ b/test/test-setup.js @@ -0,0 +1,14 @@ +// Test setup file that loads all mocks +// This file will be included in the test command to ensure all mocks are loaded before tests run + +// Load QuickPulse service mocks +const { mockQuickPulseEndpoints } = require("./mocks/quickpulse-mock"); + +// Apply all mocks +console.log("[Test Setup] Applying QuickPulse service mocks to prevent real network connections"); +mockQuickPulseEndpoints(); + +// Ensure nock prevents ALL network connections +const nock = require("nock"); +nock.disableNetConnect(); +console.log("[Test Setup] All network connections disabled - only mocked endpoints will work"); From 5f6d8ef591069e11a2cd528d1c82d6f10bfdb798 Mon Sep 17 00:00:00 2001 From: Jackson Weber Date: Wed, 21 May 2025 16:15:20 -0700 Subject: [PATCH 06/18] Try to fix the attempted loading of the console.sub module. --- src/logs/autoCollectLogs.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/logs/autoCollectLogs.ts b/src/logs/autoCollectLogs.ts index 039f1b408..8ba4f2bf0 100644 --- a/src/logs/autoCollectLogs.ts +++ b/src/logs/autoCollectLogs.ts @@ -5,12 +5,22 @@ enablePublishers(); export class AutoCollectLogs { public enable(options: InstrumentationOptions) { - // eslint-disable-next-line @typescript-eslint/no-var-requires - require("./diagnostic-channel/console.sub").enable(options.console); + try { + // eslint-disable-next-line @typescript-eslint/no-var-requires + require("./diagnostic-channel/console.sub").enable(options.console); + } catch (error) { + // eslint-disable-next-line @typescript-eslint/no-var-requires + require("../../out/src/logs/diagnostic-channel/console.sub").enable(options.console); + } } public shutdown() { - // eslint-disable-next-line @typescript-eslint/no-var-requires - require("./diagnostic-channel/console.sub").dispose(); + try { + // eslint-disable-next-line @typescript-eslint/no-var-requires + require("./diagnostic-channel/console.sub").dispose(); + } catch (error) { + // eslint-disable-next-line @typescript-eslint/no-var-requires + require("../../out/src/logs/diagnostic-channel/console.sub").dispose(); + } } } From 501979c5a931aae4ad7bf8c7ba80ea8c5b0d05e0 Mon Sep 17 00:00:00 2001 From: Jackson Weber Date: Wed, 21 May 2025 16:50:07 -0700 Subject: [PATCH 07/18] Fix windows specific ETWLogger tests. --- src/agent/appServicesLoader.ts | 24 ++++++++++++++++--- test/unitTests/agent/appServicesLoader.ts | 29 +++++++++++++++-------- 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/src/agent/appServicesLoader.ts b/src/agent/appServicesLoader.ts index f390b9b07..4ca26ff58 100644 --- a/src/agent/appServicesLoader.ts +++ b/src/agent/appServicesLoader.ts @@ -50,9 +50,27 @@ export class AppServicesLoader extends AgentLoader { })); if (this._isWindows) { - this._diagnosticLogger = new EtwDiagnosticLogger( - this._instrumentationKey - ); + try { + this._diagnosticLogger = new EtwDiagnosticLogger( + this._instrumentationKey + ); + } catch (error) { + // Fallback to DiagnosticLogger with FileWriter if ETW initialization fails + // This is useful for test environments or systems without ETW capability + this._diagnosticLogger = new DiagnosticLogger( + this._instrumentationKey, + new FileWriter( + statusLogDir, + 'applicationinsights-extension.log', + { + append: true, + deleteOnExit: false, + renamePolicy: 'overwrite', + sizeLimit: 1024 * 1024, // 1 MB + } + ) + ); + } } else{ this._diagnosticLogger = new DiagnosticLogger( diff --git a/test/unitTests/agent/appServicesLoader.ts b/test/unitTests/agent/appServicesLoader.ts index c2e9be535..e42259a1d 100644 --- a/test/unitTests/agent/appServicesLoader.ts +++ b/test/unitTests/agent/appServicesLoader.ts @@ -24,9 +24,7 @@ describe("agent/AppServicesLoader", () => { afterEach(() => { process.env = originalEnv; sandbox.restore(); - }); - - it("constructor", () => { + }); it("constructor", () => { const env = { ["APPLICATIONINSIGHTS_CONNECTION_STRING"]: "InstrumentationKey=1aa11111-bbbb-1ccc-8ddd-eeeeffff3333", ["HOME"]: "c:", @@ -37,9 +35,22 @@ describe("agent/AppServicesLoader", () => { assert.equal(diagnosticLogger["_instrumentationKey"], "1aa11111-bbbb-1ccc-8ddd-eeeeffff3333"); const isWindows = process.platform === 'win32'; - assert.ok(diagnosticLogger instanceof DiagnosticLogger, "Wrong diagnosticLogger type"); - assert.ok(diagnosticLogger["_agentLogger"] instanceof FileWriter, "Wrong diagnosticLogger agentLogger"); - assert.equal(diagnosticLogger["_agentLogger"]["_filename"], "applicationinsights-extension.log"); + + // In Windows, the diagnostic logger should be EtwDiagnosticLogger + // In non-Windows, it should be DiagnosticLogger with FileWriter + if (isWindows) { + // Import EtwDiagnosticLogger for Windows testing + const { EtwDiagnosticLogger } = require("../../../src/agent/diagnostics/etwDiagnosticLogger"); + const { EtwWritter } = require("../../../src/agent/diagnostics/writers/etwWritter"); + + assert.ok(diagnosticLogger instanceof EtwDiagnosticLogger, "Wrong diagnosticLogger type for Windows"); + assert.ok(diagnosticLogger["_agentLogger"] instanceof EtwWritter, "Wrong diagnosticLogger agentLogger for Windows"); + } else { + assert.ok(diagnosticLogger instanceof DiagnosticLogger, "Wrong diagnosticLogger type"); + assert.ok(diagnosticLogger["_agentLogger"] instanceof FileWriter, "Wrong diagnosticLogger agentLogger"); + assert.equal(diagnosticLogger["_agentLogger"]["_filename"], "applicationinsights-extension.log"); + assert.equal(diagnosticLogger["_agentLogger"]["_filepath"], "/var/log/applicationinsights/"); + } let statusLogger: any = agent["_statusLogger"]; assert.equal(statusLogger["_instrumentationKey"], "1aa11111-bbbb-1ccc-8ddd-eeeeffff3333"); @@ -47,13 +58,11 @@ describe("agent/AppServicesLoader", () => { assert.equal(statusLogger["_agentLogger"]["_filename"], "status_nodejs.json"); if (isWindows) { - assert.equal(diagnosticLogger["_agentLogger"]["_filepath"], "c:\\LogFiles\\ApplicationInsights\\status"); assert.equal(statusLogger["_agentLogger"]["_filepath"], "c:\\LogFiles\\ApplicationInsights\\status"); - } - else { - assert.equal(diagnosticLogger["_agentLogger"]["_filepath"], "/var/log/applicationinsights/"); + } else { assert.equal(statusLogger["_agentLogger"]["_filepath"], "/var/log/applicationinsights/"); } + // Loader is using correct diagnostics assert.equal(agent["_diagnosticLogger"], diagnosticLogger, "Wrong diagnosticLogger"); assert.equal(agent["_statusLogger"], statusLogger, "Wrong statusLogger"); From 515875b1fbaf3ab39ea8df24b3ee221130b16986 Mon Sep 17 00:00:00 2001 From: Jackson Weber Date: Wed, 21 May 2025 16:55:22 -0700 Subject: [PATCH 08/18] Remove unneeded quickpulse mock. --- package.json | 1 - test/mocks/quickpulse-mock.js | 32 -------------------------------- test/test-setup.js | 14 -------------- 3 files changed, 47 deletions(-) delete mode 100644 test/mocks/quickpulse-mock.js delete mode 100644 test/test-setup.js diff --git a/package.json b/package.json index 0f2f539f3..5e9819b05 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,6 @@ "lint": "eslint ./ --fix", "pretest": "npm run build", "test": "nyc mocha ./out/test --recursive", - "test:mocked": "node ./test/test-setup.js && nyc mocha ./out/test --recursive", "test:debug": "nyc mocha ./out/test --inspect-brk --recursive", "test:unit": "nyc mocha ./out/test/unitTests --recursive", "test:e2e": "nyc mocha ./out/test/endToEnd --recursive", diff --git a/test/mocks/quickpulse-mock.js b/test/mocks/quickpulse-mock.js deleted file mode 100644 index 029eede85..000000000 --- a/test/mocks/quickpulse-mock.js +++ /dev/null @@ -1,32 +0,0 @@ -// Helper to mock QuickPulse service endpoints -// This ensures tests never connect to real external endpoints - -const nock = require("nock"); - -// Mock QuickPulse service endpoints -function mockQuickPulseEndpoints() { - // Mock the ping endpoint with a successful response - nock("https://global.livediagnostics.monitor.azure.com:443") - .persist() - .get(/\/QuickPulseService\.svc\/ping/) - .reply(200, { - "StatusCode": 200, - "ResponseType": 0, - "ConnectionPollingInterval": 60000, - "Messages": [] - }); - - // Mock the post endpoint for submitting metrics - nock("https://global.livediagnostics.monitor.azure.com:443") - .persist() - .post(/\/QuickPulseService\.svc\/post/) - .reply(200, { - "StatusCode": 200, - "ResponseType": 0, - "ConnectionPollingInterval": 60000, - "Messages": [] - }); -} - -// Export the mocking function so it can be used by tests -module.exports = { mockQuickPulseEndpoints }; diff --git a/test/test-setup.js b/test/test-setup.js deleted file mode 100644 index 99d3662e9..000000000 --- a/test/test-setup.js +++ /dev/null @@ -1,14 +0,0 @@ -// Test setup file that loads all mocks -// This file will be included in the test command to ensure all mocks are loaded before tests run - -// Load QuickPulse service mocks -const { mockQuickPulseEndpoints } = require("./mocks/quickpulse-mock"); - -// Apply all mocks -console.log("[Test Setup] Applying QuickPulse service mocks to prevent real network connections"); -mockQuickPulseEndpoints(); - -// Ensure nock prevents ALL network connections -const nock = require("nock"); -nock.disableNetConnect(); -console.log("[Test Setup] All network connections disabled - only mocked endpoints will work"); From 9f5cb0325de49ad2cb95eb1ef08653c14c495bdd Mon Sep 17 00:00:00 2001 From: Jackson Weber Date: Wed, 21 May 2025 16:57:11 -0700 Subject: [PATCH 09/18] Update node.js-windows-x86.yml --- .github/workflows/node.js-windows-x86.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/node.js-windows-x86.yml b/.github/workflows/node.js-windows-x86.yml index ae5d7f7c0..a6c83d81c 100644 --- a/.github/workflows/node.js-windows-x86.yml +++ b/.github/workflows/node.js-windows-x86.yml @@ -63,4 +63,4 @@ jobs: - name: Run tests with mocks run: | # Run tests with mock setup to prevent any real network connections - npm run test:mocked + npm run test From 320cc444a10381a743f56a466a84d02029626648 Mon Sep 17 00:00:00 2001 From: Jackson Weber Date: Wed, 21 May 2025 19:05:10 -0700 Subject: [PATCH 10/18] Revert "Update node.js-windows-x86.yml" This reverts commit 9f5cb0325de49ad2cb95eb1ef08653c14c495bdd. --- .github/workflows/node.js-windows-x86.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/node.js-windows-x86.yml b/.github/workflows/node.js-windows-x86.yml index a6c83d81c..ae5d7f7c0 100644 --- a/.github/workflows/node.js-windows-x86.yml +++ b/.github/workflows/node.js-windows-x86.yml @@ -63,4 +63,4 @@ jobs: - name: Run tests with mocks run: | # Run tests with mock setup to prevent any real network connections - npm run test + npm run test:mocked From 471df2fe824f73da1a8a280c24c13f98b8259a23 Mon Sep 17 00:00:00 2001 From: Jackson Weber Date: Wed, 21 May 2025 19:05:16 -0700 Subject: [PATCH 11/18] Revert "Remove unneeded quickpulse mock." This reverts commit 515875b1fbaf3ab39ea8df24b3ee221130b16986. --- package.json | 1 + test/mocks/quickpulse-mock.js | 32 ++++++++++++++++++++++++++++++++ test/test-setup.js | 14 ++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 test/mocks/quickpulse-mock.js create mode 100644 test/test-setup.js diff --git a/package.json b/package.json index 5e9819b05..0f2f539f3 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "lint": "eslint ./ --fix", "pretest": "npm run build", "test": "nyc mocha ./out/test --recursive", + "test:mocked": "node ./test/test-setup.js && nyc mocha ./out/test --recursive", "test:debug": "nyc mocha ./out/test --inspect-brk --recursive", "test:unit": "nyc mocha ./out/test/unitTests --recursive", "test:e2e": "nyc mocha ./out/test/endToEnd --recursive", diff --git a/test/mocks/quickpulse-mock.js b/test/mocks/quickpulse-mock.js new file mode 100644 index 000000000..029eede85 --- /dev/null +++ b/test/mocks/quickpulse-mock.js @@ -0,0 +1,32 @@ +// Helper to mock QuickPulse service endpoints +// This ensures tests never connect to real external endpoints + +const nock = require("nock"); + +// Mock QuickPulse service endpoints +function mockQuickPulseEndpoints() { + // Mock the ping endpoint with a successful response + nock("https://global.livediagnostics.monitor.azure.com:443") + .persist() + .get(/\/QuickPulseService\.svc\/ping/) + .reply(200, { + "StatusCode": 200, + "ResponseType": 0, + "ConnectionPollingInterval": 60000, + "Messages": [] + }); + + // Mock the post endpoint for submitting metrics + nock("https://global.livediagnostics.monitor.azure.com:443") + .persist() + .post(/\/QuickPulseService\.svc\/post/) + .reply(200, { + "StatusCode": 200, + "ResponseType": 0, + "ConnectionPollingInterval": 60000, + "Messages": [] + }); +} + +// Export the mocking function so it can be used by tests +module.exports = { mockQuickPulseEndpoints }; diff --git a/test/test-setup.js b/test/test-setup.js new file mode 100644 index 000000000..99d3662e9 --- /dev/null +++ b/test/test-setup.js @@ -0,0 +1,14 @@ +// Test setup file that loads all mocks +// This file will be included in the test command to ensure all mocks are loaded before tests run + +// Load QuickPulse service mocks +const { mockQuickPulseEndpoints } = require("./mocks/quickpulse-mock"); + +// Apply all mocks +console.log("[Test Setup] Applying QuickPulse service mocks to prevent real network connections"); +mockQuickPulseEndpoints(); + +// Ensure nock prevents ALL network connections +const nock = require("nock"); +nock.disableNetConnect(); +console.log("[Test Setup] All network connections disabled - only mocked endpoints will work"); From 910012458144d2aeb5476f6bc007f0ca5f2196ff Mon Sep 17 00:00:00 2001 From: Jackson Weber Date: Thu, 22 May 2025 14:36:31 -0700 Subject: [PATCH 12/18] Remove ARM64 tests as github can't allocate resources. --- .github/workflows/node.js-linux-arm64.yml | 30 ----------- .github/workflows/node.js-windows-arm64.yml | 55 --------------------- 2 files changed, 85 deletions(-) delete mode 100644 .github/workflows/node.js-linux-arm64.yml delete mode 100644 .github/workflows/node.js-windows-arm64.yml diff --git a/.github/workflows/node.js-linux-arm64.yml b/.github/workflows/node.js-linux-arm64.yml deleted file mode 100644 index c0801789c..000000000 --- a/.github/workflows/node.js-linux-arm64.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: Node.js CI (Linux ARM64) - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -jobs: - build: - - runs-on: ubuntu-20.04-arm64 - - strategy: - matrix: - # Using the same Node versions as the main workflow - node-version: [16.x, 18.x, 20.x, 22.x] - - steps: - - uses: actions/checkout@v2 - - 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: (Linux ARM64) on Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - run: npm run clean - - run: npm i - - run: npm run build --if-present - - run: npm run lint - - run: npm test diff --git a/.github/workflows/node.js-windows-arm64.yml b/.github/workflows/node.js-windows-arm64.yml deleted file mode 100644 index 6675480fb..000000000 --- a/.github/workflows/node.js-windows-arm64.yml +++ /dev/null @@ -1,55 +0,0 @@ -name: Node.js CI (Windows ARM64) - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -jobs: - build: - - runs-on: windows-latest-arm64 - - strategy: - matrix: - # Using the same Node versions as the main workflow - node-version: [16.x, 18.x, 20.x, 22.x] - - steps: - - uses: actions/checkout@v2 - # For Windows, we'll need to use different commands to generate certificates - - name: Generate SSL Certificate - shell: pwsh - run: | - $cert = New-SelfSignedCertificate -Subject "CN=ca,OU=Test,O=Root,L=OpenTelemetryTest,ST=RM,C=CL" -NotAfter (Get-Date).AddDays(1) - $certPath = ".\test\certs\server-cert.pem" - $keyPath = ".\test\certs\server-key.pem" - - $certsDir = ".\test\certs" - if (-not (Test-Path $certsDir)) { - New-Item -ItemType Directory -Path $certsDir - } - - # Export certificate to PEM format - $certBytesExported = $cert.Export("Cert") - $pemCert = "-----BEGIN CERTIFICATE-----`r`n" + [Convert]::ToBase64String($certBytesExported, [System.Base64FormattingOptions]::InsertLineBreaks) + "`r`n-----END CERTIFICATE-----" - Set-Content -Path $certPath -Value $pemCert - - # For the key, we'll output a placeholder PEM file - # Using secure random bytes for the key content rather than hardcoded text - $randomBytes = New-Object byte[] 32 - [Security.Cryptography.RNGCryptoServiceProvider]::Create().GetBytes($randomBytes) - $randomKeyContent = [Convert]::ToBase64String($randomBytes) - Set-Content -Path $keyPath -Value "-----BEGIN PRIVATE KEY-----`r`n$randomKeyContent`r`n-----END PRIVATE KEY-----" - - - name: (Windows ARM64) on Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - - run: npm run clean - - run: npm i - - run: npm run build --if-present - - run: npm run lint - - run: npm test From 15a25be0fa2c9703b29a1fbea1755d003feaadd5 Mon Sep 17 00:00:00 2001 From: Jackson Weber Date: Thu, 22 May 2025 15:03:41 -0700 Subject: [PATCH 13/18] Revert "Remove ARM64 tests as github can't allocate resources." This reverts commit 910012458144d2aeb5476f6bc007f0ca5f2196ff. --- .github/workflows/node.js-linux-arm64.yml | 30 +++++++++++ .github/workflows/node.js-windows-arm64.yml | 55 +++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 .github/workflows/node.js-linux-arm64.yml create mode 100644 .github/workflows/node.js-windows-arm64.yml diff --git a/.github/workflows/node.js-linux-arm64.yml b/.github/workflows/node.js-linux-arm64.yml new file mode 100644 index 000000000..c0801789c --- /dev/null +++ b/.github/workflows/node.js-linux-arm64.yml @@ -0,0 +1,30 @@ +name: Node.js CI (Linux ARM64) + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + + runs-on: ubuntu-20.04-arm64 + + strategy: + matrix: + # Using the same Node versions as the main workflow + node-version: [16.x, 18.x, 20.x, 22.x] + + steps: + - uses: actions/checkout@v2 + - 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: (Linux ARM64) on Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - run: npm run clean + - run: npm i + - run: npm run build --if-present + - run: npm run lint + - run: npm test diff --git a/.github/workflows/node.js-windows-arm64.yml b/.github/workflows/node.js-windows-arm64.yml new file mode 100644 index 000000000..6675480fb --- /dev/null +++ b/.github/workflows/node.js-windows-arm64.yml @@ -0,0 +1,55 @@ +name: Node.js CI (Windows ARM64) + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + + runs-on: windows-latest-arm64 + + strategy: + matrix: + # Using the same Node versions as the main workflow + node-version: [16.x, 18.x, 20.x, 22.x] + + steps: + - uses: actions/checkout@v2 + # For Windows, we'll need to use different commands to generate certificates + - name: Generate SSL Certificate + shell: pwsh + run: | + $cert = New-SelfSignedCertificate -Subject "CN=ca,OU=Test,O=Root,L=OpenTelemetryTest,ST=RM,C=CL" -NotAfter (Get-Date).AddDays(1) + $certPath = ".\test\certs\server-cert.pem" + $keyPath = ".\test\certs\server-key.pem" + + $certsDir = ".\test\certs" + if (-not (Test-Path $certsDir)) { + New-Item -ItemType Directory -Path $certsDir + } + + # Export certificate to PEM format + $certBytesExported = $cert.Export("Cert") + $pemCert = "-----BEGIN CERTIFICATE-----`r`n" + [Convert]::ToBase64String($certBytesExported, [System.Base64FormattingOptions]::InsertLineBreaks) + "`r`n-----END CERTIFICATE-----" + Set-Content -Path $certPath -Value $pemCert + + # For the key, we'll output a placeholder PEM file + # Using secure random bytes for the key content rather than hardcoded text + $randomBytes = New-Object byte[] 32 + [Security.Cryptography.RNGCryptoServiceProvider]::Create().GetBytes($randomBytes) + $randomKeyContent = [Convert]::ToBase64String($randomBytes) + Set-Content -Path $keyPath -Value "-----BEGIN PRIVATE KEY-----`r`n$randomKeyContent`r`n-----END PRIVATE KEY-----" + + - name: (Windows ARM64) on Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + + - run: npm run clean + - run: npm i + - run: npm run build --if-present + - run: npm run lint + - run: npm test From d4c1beea1946680c6b926f02001404270ca9e9da Mon Sep 17 00:00:00 2001 From: Jackson Weber Date: Thu, 22 May 2025 15:14:10 -0700 Subject: [PATCH 14/18] Update linux arm64 tests to use docker container. --- .github/workflows/node.js-linux-arm64.yml | 46 +++++++---- .github/workflows/node.js-windows-arm64.yml | 90 ++++++++++----------- 2 files changed, 77 insertions(+), 59 deletions(-) diff --git a/.github/workflows/node.js-linux-arm64.yml b/.github/workflows/node.js-linux-arm64.yml index c0801789c..ca695e846 100644 --- a/.github/workflows/node.js-linux-arm64.yml +++ b/.github/workflows/node.js-linux-arm64.yml @@ -8,23 +8,41 @@ on: jobs: build: - - runs-on: ubuntu-20.04-arm64 + # Use a standard Ubuntu runner instead of requesting ARM64 hardware directly + runs-on: ubuntu-latest strategy: matrix: # Using the same Node versions as the main workflow - node-version: [16.x, 18.x, 20.x, 22.x] + node-version: [16, 18, 20, 22] steps: - - uses: actions/checkout@v2 - - 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: (Linux ARM64) on Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - run: npm run clean - - run: npm i - - run: npm run build --if-present - - run: npm run lint - - run: npm test + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + with: + platforms: arm64 + + - name: Run tests in ARM64 Docker container + run: | + # Generate SSL certificates first (outside container) + mkdir -p ./test/certs + 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" + + # Set proper permissions for the mounted volume + chmod -R 777 . + + # Run the Node.js tests in ARM64 container + docker run --rm -v ${{ github.workspace }}:/app -w /app --platform linux/arm64 node:${{ matrix.node-version }}-alpine sh -c ' + # Install build tools needed for native modules + apk add --no-cache python3 make g++ + + # Install and run tests + npm run clean + npm i + npm run build --if-present + npm run lint + npm test + ' diff --git a/.github/workflows/node.js-windows-arm64.yml b/.github/workflows/node.js-windows-arm64.yml index 6675480fb..fe0bc0a10 100644 --- a/.github/workflows/node.js-windows-arm64.yml +++ b/.github/workflows/node.js-windows-arm64.yml @@ -1,55 +1,55 @@ -name: Node.js CI (Windows ARM64) +# name: Node.js CI (Windows ARM64) -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] +# on: +# push: +# branches: [ main ] +# pull_request: +# branches: [ main ] -jobs: - build: +# jobs: +# build: - runs-on: windows-latest-arm64 +# runs-on: windows-latest-arm64 - strategy: - matrix: - # Using the same Node versions as the main workflow - node-version: [16.x, 18.x, 20.x, 22.x] +# strategy: +# matrix: +# # Using the same Node versions as the main workflow +# node-version: [16.x, 18.x, 20.x, 22.x] - steps: - - uses: actions/checkout@v2 - # For Windows, we'll need to use different commands to generate certificates - - name: Generate SSL Certificate - shell: pwsh - run: | - $cert = New-SelfSignedCertificate -Subject "CN=ca,OU=Test,O=Root,L=OpenTelemetryTest,ST=RM,C=CL" -NotAfter (Get-Date).AddDays(1) - $certPath = ".\test\certs\server-cert.pem" - $keyPath = ".\test\certs\server-key.pem" +# steps: +# - uses: actions/checkout@v2 +# # For Windows, we'll need to use different commands to generate certificates +# - name: Generate SSL Certificate +# shell: pwsh +# run: | +# $cert = New-SelfSignedCertificate -Subject "CN=ca,OU=Test,O=Root,L=OpenTelemetryTest,ST=RM,C=CL" -NotAfter (Get-Date).AddDays(1) +# $certPath = ".\test\certs\server-cert.pem" +# $keyPath = ".\test\certs\server-key.pem" - $certsDir = ".\test\certs" - if (-not (Test-Path $certsDir)) { - New-Item -ItemType Directory -Path $certsDir - } +# $certsDir = ".\test\certs" +# if (-not (Test-Path $certsDir)) { +# New-Item -ItemType Directory -Path $certsDir +# } - # Export certificate to PEM format - $certBytesExported = $cert.Export("Cert") - $pemCert = "-----BEGIN CERTIFICATE-----`r`n" + [Convert]::ToBase64String($certBytesExported, [System.Base64FormattingOptions]::InsertLineBreaks) + "`r`n-----END CERTIFICATE-----" - Set-Content -Path $certPath -Value $pemCert +# # Export certificate to PEM format +# $certBytesExported = $cert.Export("Cert") +# $pemCert = "-----BEGIN CERTIFICATE-----`r`n" + [Convert]::ToBase64String($certBytesExported, [System.Base64FormattingOptions]::InsertLineBreaks) + "`r`n-----END CERTIFICATE-----" +# Set-Content -Path $certPath -Value $pemCert - # For the key, we'll output a placeholder PEM file - # Using secure random bytes for the key content rather than hardcoded text - $randomBytes = New-Object byte[] 32 - [Security.Cryptography.RNGCryptoServiceProvider]::Create().GetBytes($randomBytes) - $randomKeyContent = [Convert]::ToBase64String($randomBytes) - Set-Content -Path $keyPath -Value "-----BEGIN PRIVATE KEY-----`r`n$randomKeyContent`r`n-----END PRIVATE KEY-----" +# # For the key, we'll output a placeholder PEM file +# # Using secure random bytes for the key content rather than hardcoded text +# $randomBytes = New-Object byte[] 32 +# [Security.Cryptography.RNGCryptoServiceProvider]::Create().GetBytes($randomBytes) +# $randomKeyContent = [Convert]::ToBase64String($randomBytes) +# Set-Content -Path $keyPath -Value "-----BEGIN PRIVATE KEY-----`r`n$randomKeyContent`r`n-----END PRIVATE KEY-----" - - name: (Windows ARM64) on Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} +# - name: (Windows ARM64) on Node.js ${{ matrix.node-version }} +# uses: actions/setup-node@v1 +# with: +# node-version: ${{ matrix.node-version }} - - run: npm run clean - - run: npm i - - run: npm run build --if-present - - run: npm run lint - - run: npm test +# - run: npm run clean +# - run: npm i +# - run: npm run build --if-present +# - run: npm run lint +# - run: npm test From 4ef90b2573b2323c175d5c1a226cd11db0c7fb91 Mon Sep 17 00:00:00 2001 From: Jackson Weber Date: Thu, 22 May 2025 15:20:29 -0700 Subject: [PATCH 15/18] Update node.js-linux-arm64.yml --- .github/workflows/node.js-linux-arm64.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/node.js-linux-arm64.yml b/.github/workflows/node.js-linux-arm64.yml index ca695e846..1d44342ce 100644 --- a/.github/workflows/node.js-linux-arm64.yml +++ b/.github/workflows/node.js-linux-arm64.yml @@ -14,7 +14,7 @@ jobs: strategy: matrix: # Using the same Node versions as the main workflow - node-version: [16, 18, 20, 22] + node-version: [18, 20, 22] steps: - name: Checkout code From 9837aab95774d4e19996b26dbb1e536588df66fd Mon Sep 17 00:00:00 2001 From: Jackson Weber Date: Thu, 22 May 2025 15:35:29 -0700 Subject: [PATCH 16/18] Try new approach for Windows ARM64 support. --- .github/workflows/node.js-windows-arm64.yml | 120 ++++++++++++-------- 1 file changed, 73 insertions(+), 47 deletions(-) diff --git a/.github/workflows/node.js-windows-arm64.yml b/.github/workflows/node.js-windows-arm64.yml index fe0bc0a10..0761f265d 100644 --- a/.github/workflows/node.js-windows-arm64.yml +++ b/.github/workflows/node.js-windows-arm64.yml @@ -1,55 +1,81 @@ -# name: Node.js CI (Windows ARM64) +name: Node.js CI (Windows ARM64) -# on: -# push: -# branches: [ main ] -# pull_request: -# branches: [ main ] +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] -# jobs: -# build: +jobs: + build: + # Use a standard Windows runner instead of requesting ARM64 hardware directly + runs-on: windows-latest -# runs-on: windows-latest-arm64 + strategy: + matrix: + # Using the same Node versions as the main workflow but without the .x suffix for Docker images + node-version: [18, 20, 22] -# strategy: -# matrix: -# # Using the same Node versions as the main workflow -# node-version: [16.x, 18.x, 20.x, 22.x] - -# steps: -# - uses: actions/checkout@v2 -# # For Windows, we'll need to use different commands to generate certificates -# - name: Generate SSL Certificate -# shell: pwsh -# run: | -# $cert = New-SelfSignedCertificate -Subject "CN=ca,OU=Test,O=Root,L=OpenTelemetryTest,ST=RM,C=CL" -NotAfter (Get-Date).AddDays(1) -# $certPath = ".\test\certs\server-cert.pem" -# $keyPath = ".\test\certs\server-key.pem" + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Docker + uses: docker/setup-buildx-action@v2 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + with: + platforms: arm64 + + # Generate certificates using PowerShell before running Docker + - name: Generate SSL Certificate + shell: pwsh + run: | + $certsDir = ".\test\certs" + if (-not (Test-Path $certsDir)) { + New-Item -ItemType Directory -Path $certsDir -Force + } -# $certsDir = ".\test\certs" -# if (-not (Test-Path $certsDir)) { -# New-Item -ItemType Directory -Path $certsDir -# } + $cert = New-SelfSignedCertificate -Subject "CN=ca,OU=Test,O=Root,L=OpenTelemetryTest,ST=RM,C=CL" -NotAfter (Get-Date).AddDays(1) + $certPath = ".\test\certs\server-cert.pem" + $keyPath = ".\test\certs\server-key.pem" -# # Export certificate to PEM format -# $certBytesExported = $cert.Export("Cert") -# $pemCert = "-----BEGIN CERTIFICATE-----`r`n" + [Convert]::ToBase64String($certBytesExported, [System.Base64FormattingOptions]::InsertLineBreaks) + "`r`n-----END CERTIFICATE-----" -# Set-Content -Path $certPath -Value $pemCert + # Export certificate to PEM format + $certBytesExported = $cert.Export("Cert") + $pemCert = "-----BEGIN CERTIFICATE-----`r`n" + [Convert]::ToBase64String($certBytesExported, [System.Base64FormattingOptions]::InsertLineBreaks) + "`r`n-----END CERTIFICATE-----" + Set-Content -Path $certPath -Value $pemCert -# # For the key, we'll output a placeholder PEM file -# # Using secure random bytes for the key content rather than hardcoded text -# $randomBytes = New-Object byte[] 32 -# [Security.Cryptography.RNGCryptoServiceProvider]::Create().GetBytes($randomBytes) -# $randomKeyContent = [Convert]::ToBase64String($randomBytes) -# Set-Content -Path $keyPath -Value "-----BEGIN PRIVATE KEY-----`r`n$randomKeyContent`r`n-----END PRIVATE KEY-----" + # For the key, we'll output a placeholder PEM file + # Using secure random bytes for the key content rather than hardcoded text + $randomBytes = New-Object byte[] 32 + [Security.Cryptography.RNGCryptoServiceProvider]::Create().GetBytes($randomBytes) + $randomKeyContent = [Convert]::ToBase64String($randomBytes) + Set-Content -Path $keyPath -Value "-----BEGIN PRIVATE KEY-----`r`n$randomKeyContent`r`n-----END PRIVATE KEY-----" -# - name: (Windows ARM64) on Node.js ${{ matrix.node-version }} -# uses: actions/setup-node@v1 -# with: -# node-version: ${{ matrix.node-version }} - -# - run: npm run clean -# - run: npm i -# - run: npm run build --if-present -# - run: npm run lint -# - run: npm test + - name: Run tests in ARM64 Docker container (Linux container with Windows mount) + shell: pwsh + run: | + # Enable Linux containers on Windows + $ErrorActionPreference = 'Continue' + + # Convert path format for Docker bind mount + $repoPath = "${{ github.workspace }}".Replace('\', '/').Replace('C:', '/c') + + # Ensure everyone has permissions to the directory + icacls . /grant Everyone:F /T + + # Run the tests in an ARM64 Linux Alpine container (not Windows container) + docker run --rm -v "${repoPath}:/app" -w /app --platform linux/arm64 node:${{ matrix.node-version }}-alpine sh -c ' + echo "Running tests for Node.js ${{ matrix.node-version }} on ARM64 emulation" + + # Install build dependencies for native modules + apk add --no-cache python3 make g++ + + # Run tests + npm run clean + npm i + npm run build --if-present + npm run lint + npm test + ' From cea8360bdcd5cf0aa8848749a80cdb446d913d29 Mon Sep 17 00:00:00 2001 From: Jackson Weber Date: Thu, 22 May 2025 15:41:48 -0700 Subject: [PATCH 17/18] Update node.js-windows-arm64.yml --- .github/workflows/node.js-windows-arm64.yml | 53 +++++---------------- 1 file changed, 13 insertions(+), 40 deletions(-) diff --git a/.github/workflows/node.js-windows-arm64.yml b/.github/workflows/node.js-windows-arm64.yml index 0761f265d..098b94adb 100644 --- a/.github/workflows/node.js-windows-arm64.yml +++ b/.github/workflows/node.js-windows-arm64.yml @@ -8,8 +8,8 @@ on: jobs: build: - # Use a standard Windows runner instead of requesting ARM64 hardware directly - runs-on: windows-latest + # Use the Linux runner instead as it has better Docker support + runs-on: ubuntu-latest strategy: matrix: @@ -20,54 +20,27 @@ jobs: - name: Checkout code uses: actions/checkout@v3 - - name: Set up Docker - uses: docker/setup-buildx-action@v2 - - name: Set up QEMU uses: docker/setup-qemu-action@v2 with: platforms: arm64 - - # Generate certificates using PowerShell before running Docker + # Generate certificates using Linux openssl command - name: Generate SSL Certificate - shell: pwsh run: | - $certsDir = ".\test\certs" - if (-not (Test-Path $certsDir)) { - New-Item -ItemType Directory -Path $certsDir -Force - } - - $cert = New-SelfSignedCertificate -Subject "CN=ca,OU=Test,O=Root,L=OpenTelemetryTest,ST=RM,C=CL" -NotAfter (Get-Date).AddDays(1) - $certPath = ".\test\certs\server-cert.pem" - $keyPath = ".\test\certs\server-key.pem" + # Create certificates directory + mkdir -p ./test/certs - # Export certificate to PEM format - $certBytesExported = $cert.Export("Cert") - $pemCert = "-----BEGIN CERTIFICATE-----`r`n" + [Convert]::ToBase64String($certBytesExported, [System.Base64FormattingOptions]::InsertLineBreaks) + "`r`n-----END CERTIFICATE-----" - Set-Content -Path $certPath -Value $pemCert + # Generate SSL certificates + 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" - # For the key, we'll output a placeholder PEM file - # Using secure random bytes for the key content rather than hardcoded text - $randomBytes = New-Object byte[] 32 - [Security.Cryptography.RNGCryptoServiceProvider]::Create().GetBytes($randomBytes) - $randomKeyContent = [Convert]::ToBase64String($randomBytes) - Set-Content -Path $keyPath -Value "-----BEGIN PRIVATE KEY-----`r`n$randomKeyContent`r`n-----END PRIVATE KEY-----" + # Set permissions + chmod -R 777 . - - name: Run tests in ARM64 Docker container (Linux container with Windows mount) - shell: pwsh + - name: Run Node.js ${{ matrix.node-version }} tests in ARM64 Docker container run: | - # Enable Linux containers on Windows - $ErrorActionPreference = 'Continue' - - # Convert path format for Docker bind mount - $repoPath = "${{ github.workspace }}".Replace('\', '/').Replace('C:', '/c') - - # Ensure everyone has permissions to the directory - icacls . /grant Everyone:F /T - - # Run the tests in an ARM64 Linux Alpine container (not Windows container) - docker run --rm -v "${repoPath}:/app" -w /app --platform linux/arm64 node:${{ matrix.node-version }}-alpine sh -c ' - echo "Running tests for Node.js ${{ matrix.node-version }} on ARM64 emulation" + # Run the tests in an ARM64 container + docker run --rm -v ${{ github.workspace }}:/app -w /app --platform linux/arm64 node:${{ matrix.node-version }}-alpine sh -c ' + echo "Running tests for Node.js ${{ matrix.node-version }} on ARM64 emulation (Windows-targeted tests)" # Install build dependencies for native modules apk add --no-cache python3 make g++ From be5e87dad1f574dafa4c969127ff2d0e2caf8961 Mon Sep 17 00:00:00 2001 From: Jackson Weber Date: Fri, 23 May 2025 14:26:21 -0700 Subject: [PATCH 18/18] Fix EtwWriter typo. --- test/unitTests/agent/appServicesLoader.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unitTests/agent/appServicesLoader.ts b/test/unitTests/agent/appServicesLoader.ts index e42259a1d..660995863 100644 --- a/test/unitTests/agent/appServicesLoader.ts +++ b/test/unitTests/agent/appServicesLoader.ts @@ -41,10 +41,10 @@ describe("agent/AppServicesLoader", () => { if (isWindows) { // Import EtwDiagnosticLogger for Windows testing const { EtwDiagnosticLogger } = require("../../../src/agent/diagnostics/etwDiagnosticLogger"); - const { EtwWritter } = require("../../../src/agent/diagnostics/writers/etwWritter"); + const { EtwWriter } = require("../../../src/agent/diagnostics/writers/etwWriter"); assert.ok(diagnosticLogger instanceof EtwDiagnosticLogger, "Wrong diagnosticLogger type for Windows"); - assert.ok(diagnosticLogger["_agentLogger"] instanceof EtwWritter, "Wrong diagnosticLogger agentLogger for Windows"); + assert.ok(diagnosticLogger["_agentLogger"] instanceof EtwWriter, "Wrong diagnosticLogger agentLogger for Windows"); } else { assert.ok(diagnosticLogger instanceof DiagnosticLogger, "Wrong diagnosticLogger type"); assert.ok(diagnosticLogger["_agentLogger"] instanceof FileWriter, "Wrong diagnosticLogger agentLogger");