From cce8cf423561c56d98d1527c048ab36e99f2cbbc Mon Sep 17 00:00:00 2001 From: Baptiste Foy Date: Tue, 18 Feb 2025 15:11:46 +0100 Subject: [PATCH 1/2] upgrade(libdatadog-nodejs): Support library_config (#49) --- .github/actions/build-test-wasm/action.yaml | 31 ++++ .github/workflows/build.yml | 14 ++ .github/workflows/release.yml | 14 ++ Cargo.lock | 164 ++++++++++++++++-- Cargo.toml | 2 +- crates/crashtracker/Cargo.toml | 2 +- crates/library_config/Cargo.toml | 18 ++ crates/library_config/src/lib.rs | 137 +++++++++++++++ load.js | 17 +- package.json | 6 +- test.js | 4 +- test/wasm/library_config/.gitignore | 1 + test/wasm/library_config/README.md | 8 + .../library_config/config_local_phase1.yaml | 2 + .../library_config/config_local_phase2.yaml | 2 + .../library_config/config_managed_phase2.yaml | 9 + test/wasm/library_config/index.js | 57 ++++++ test_wasm.js | 10 ++ 18 files changed, 480 insertions(+), 18 deletions(-) create mode 100644 .github/actions/build-test-wasm/action.yaml create mode 100644 crates/library_config/Cargo.toml create mode 100644 crates/library_config/src/lib.rs create mode 100644 test/wasm/library_config/.gitignore create mode 100644 test/wasm/library_config/README.md create mode 100644 test/wasm/library_config/config_local_phase1.yaml create mode 100644 test/wasm/library_config/config_local_phase2.yaml create mode 100644 test/wasm/library_config/config_managed_phase2.yaml create mode 100644 test/wasm/library_config/index.js create mode 100644 test_wasm.js diff --git a/.github/actions/build-test-wasm/action.yaml b/.github/actions/build-test-wasm/action.yaml new file mode 100644 index 0000000..0effdc1 --- /dev/null +++ b/.github/actions/build-test-wasm/action.yaml @@ -0,0 +1,31 @@ +name: 'Build/Test WASM' +description: 'A simple composite GitHub Action sets-up WASM; then test & build relevant crates' +inputs: + cate: + description: 'The crate name. Must be in ./crates' + required: true +runs: + using: 'composite' + steps: + - uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 + - name: Setup Node.js + uses: actions/setup-node@v4 + - run: yarn install + shell: bash + - name: Install wasm-pack + run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh + shell: bash + - name: Build WASM + run: | + mkdir -p ./prebuilds/${{ inputs.crate }} + wasm-pack build --target nodejs ./crates/${{ inputs.crate }} --out-dir ../../prebuilds/${{ inputs.crate }} + shell: bash + - name: Test WASM + run: node test_wasm.js + shell: bash + - uses: actions/upload-artifact@v4 + with: + name: prebuilds-wasm + if-no-files-found: ignore + path: ./prebuilds/* diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1c85d4b..e534dc5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,8 +7,22 @@ on: - main jobs: + build-test-wasm: + runs-on: ubuntu-latest + strategy: + matrix: + crate: + - library_config + steps: + - uses: actions/checkout@v4 + - name: 'Use composite action' + uses: ./.github/actions/build-test-wasm + with: + crate: '${{ matrix.crate }}' + build: uses: Datadog/action-prebuildify/.github/workflows/build.yml@main + needs: build-test-wasm with: package-manager: 'yarn' cache: false diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9f2982b..d9b1a7a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -6,8 +6,22 @@ on: - v0.x jobs: + build-test-wasm: + runs-on: ubuntu-latest + strategy: + matrix: + crate: + - library_config + steps: + - uses: actions/checkout@v4 + - name: 'Use composite action' + uses: ./.github/actions/build-test-wasm + with: + crate: '${{ matrix.crate }}' + build: uses: Datadog/action-prebuildify/.github/workflows/build.yml@main + needs: build-test-wasm with: package-manager: 'yarn' cache: false diff --git a/Cargo.lock b/Cargo.lock index c042060..5e2ff17 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -267,6 +267,16 @@ dependencies = [ "tokio", ] +[[package]] +name = "console_error_panic_hook" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc" +dependencies = [ + "cfg-if", + "wasm-bindgen", +] + [[package]] name = "convert_case" version = "0.6.0" @@ -351,14 +361,14 @@ dependencies = [ [[package]] name = "datadog-crashtracker" -version = "14.3.1" -source = "git+https://github.com/DataDog/libdatadog.git?tag=v14.3.1#48240f2588665a03c2061879345566ec7e70fabf" +version = "15.0.0" +source = "git+https://github.com/DataDog/libdatadog.git?tag=v15.0.0#0ef49864317b0728648b2b7f26fe2f1deeeeebc4" dependencies = [ "anyhow", "backtrace", "blazesym", "chrono", - "ddcommon 14.3.1", + "ddcommon 15.0.0", "ddtelemetry", "http 0.2.12", "hyper 0.14.31", @@ -377,12 +387,22 @@ dependencies = [ [[package]] name = "datadog-ddsketch" -version = "14.3.1" -source = "git+https://github.com/DataDog/libdatadog.git?tag=v14.3.1#48240f2588665a03c2061879345566ec7e70fabf" +version = "15.0.0" +source = "git+https://github.com/DataDog/libdatadog.git?tag=v15.0.0#0ef49864317b0728648b2b7f26fe2f1deeeeebc4" dependencies = [ "prost", ] +[[package]] +name = "datadog-library-config" +version = "0.0.1" +source = "git+https://github.com/DataDog/libdatadog.git?tag=v16.0.3#ce8c536ddef78a49142fe4a6c77ab0a1263c1018" +dependencies = [ + "anyhow", + "serde", + "serde_yaml", +] + [[package]] name = "datadog-trace-normalization" version = "6.0.0" @@ -448,8 +468,8 @@ dependencies = [ [[package]] name = "ddcommon" -version = "14.3.1" -source = "git+https://github.com/DataDog/libdatadog.git?tag=v14.3.1#48240f2588665a03c2061879345566ec7e70fabf" +version = "15.0.0" +source = "git+https://github.com/DataDog/libdatadog.git?tag=v15.0.0#0ef49864317b0728648b2b7f26fe2f1deeeeebc4" dependencies = [ "anyhow", "cc", @@ -477,13 +497,13 @@ dependencies = [ [[package]] name = "ddtelemetry" -version = "14.3.1" -source = "git+https://github.com/DataDog/libdatadog.git?tag=v14.3.1#48240f2588665a03c2061879345566ec7e70fabf" +version = "15.0.0" +source = "git+https://github.com/DataDog/libdatadog.git?tag=v15.0.0#0ef49864317b0728648b2b7f26fe2f1deeeeebc4" dependencies = [ "anyhow", "base64 0.22.1", "datadog-ddsketch", - "ddcommon 14.3.1", + "ddcommon 15.0.0", "futures", "hashbrown 0.14.5", "http 0.2.12", @@ -979,6 +999,18 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "library-config" +version = "0.1.0" +dependencies = [ + "anyhow", + "datadog-library-config", + "serde", + "serde-wasm-bindgen", + "wasm-bindgen", + "wasm-bindgen-test", +] + [[package]] name = "linux-raw-sys" version = "0.4.14" @@ -1015,6 +1047,16 @@ dependencies = [ "autocfg", ] +[[package]] +name = "minicov" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f27fe9f1cc3c22e1687f9446c2083c4c5fc7f0bcf1c7a86bdbded14985895b4b" +dependencies = [ + "cc", + "walkdir", +] + [[package]] name = "minimal-lexical" version = "0.2.1" @@ -1556,6 +1598,15 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + [[package]] name = "schannel" version = "0.1.26" @@ -1589,6 +1640,12 @@ dependencies = [ "syn 2.0.87", ] +[[package]] +name = "scoped-tls" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" + [[package]] name = "sct" version = "0.7.1" @@ -1643,6 +1700,17 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "serde-wasm-bindgen" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3b4c031cd0d9014307d82b8abf653c0290fbdaeb4c02d00c63cf52f728628bf" +dependencies = [ + "js-sys", + "serde", + "wasm-bindgen", +] + [[package]] name = "serde_bytes" version = "0.11.15" @@ -1686,6 +1754,19 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_yaml" +version = "0.9.34+deprecated" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" +dependencies = [ + "indexmap", + "itoa", + "ryu", + "serde", + "unsafe-libyaml", +] + [[package]] name = "shlex" version = "1.3.0" @@ -1901,6 +1982,12 @@ version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" +[[package]] +name = "unsafe-libyaml" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" + [[package]] name = "untrusted" version = "0.7.1" @@ -1929,6 +2016,16 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + [[package]] name = "want" version = "0.3.1" @@ -1970,6 +2067,18 @@ dependencies = [ "wasm-bindgen-shared", ] +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc7ec4f8827a71586374db3e87abdb5a2bb3a15afed140221307c3ec06b1f63b" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "wasm-bindgen-macro" version = "0.2.95" @@ -1999,6 +2108,32 @@ version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d" +[[package]] +name = "wasm-bindgen-test" +version = "0.3.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d381749acb0943d357dcbd8f0b100640679883fcdeeef04def49daf8d33a5426" +dependencies = [ + "console_error_panic_hook", + "js-sys", + "minicov", + "scoped-tls", + "wasm-bindgen", + "wasm-bindgen-futures", + "wasm-bindgen-test-macro", +] + +[[package]] +name = "wasm-bindgen-test-macro" +version = "0.3.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c97b2ef2c8d627381e51c071c2ab328eac606d3f69dd82bcbca20a9e389d95f0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "web-sys" version = "0.3.72" @@ -2047,6 +2182,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" +dependencies = [ + "windows-sys 0.59.0", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" diff --git a/Cargo.toml b/Cargo.toml index 7731b6c..b8ba21e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ default-members = [ "crates/crashtracker" ] members = [ - "crates/*" + "crates/*", ] [profile.release] diff --git a/crates/crashtracker/Cargo.toml b/crates/crashtracker/Cargo.toml index b381f41..b63261f 100644 --- a/crates/crashtracker/Cargo.toml +++ b/crates/crashtracker/Cargo.toml @@ -14,7 +14,7 @@ path = "src/bin/receiver.rs" [dependencies] anyhow = "1" -datadog-crashtracker = { git = "https://github.com/DataDog/libdatadog.git", tag = "v14.3.1" } +datadog-crashtracker = { git = "https://github.com/DataDog/libdatadog.git", tag = "v15.0.0" } napi = { version = "2", features = ["serde-json"] } napi-derive = { version = "2", default-features = false } rustls = { version = "*", default-features = false, features = ["aws-lc-rs"] } diff --git a/crates/library_config/Cargo.toml b/crates/library_config/Cargo.toml new file mode 100644 index 0000000..94f0bad --- /dev/null +++ b/crates/library_config/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "library-config" +version = "0.1.0" +edition = "2018" + +[lib] +crate-type = ["cdylib", "rlib"] + +[dependencies] +anyhow = "1" +datadog-library-config = { git = "https://github.com/DataDog/libdatadog.git", tag = "v16.0.3" } + +wasm-bindgen = "0.2.84" +serde = { version = "1.0", features = ["derive"] } +serde-wasm-bindgen = "0.4" + +[dev-dependencies] +wasm-bindgen-test = "0.3.34" diff --git a/crates/library_config/src/lib.rs b/crates/library_config/src/lib.rs new file mode 100644 index 0000000..61c0712 --- /dev/null +++ b/crates/library_config/src/lib.rs @@ -0,0 +1,137 @@ +use wasm_bindgen::prelude::*; + +#[wasm_bindgen] +pub struct JsConfigurator { + configurator: Box, + envp: Vec, + args: Vec, +} + +#[wasm_bindgen] +pub struct ConfigEntry { + name: String, + value: String, + source: String, + config_id: String, +} + +#[wasm_bindgen] +impl ConfigEntry { + #[wasm_bindgen(constructor)] + pub fn new(name: String, value: String, source: String, config_id: String) -> ConfigEntry { + ConfigEntry { + name, + value, + source, + config_id, + } + } + #[wasm_bindgen(getter)] + pub fn name(&self) -> String { + self.name.clone() + } + #[wasm_bindgen(getter)] + pub fn value(&self) -> String { + self.value.clone() + } + #[wasm_bindgen(getter)] + pub fn source(&self) -> String { + self.source.clone() + } + #[wasm_bindgen(getter)] + pub fn config_id(&self) -> String { + self.config_id.clone() + } +} + +#[wasm_bindgen] +impl JsConfigurator { + #[wasm_bindgen(constructor)] + pub fn new() -> Self { + JsConfigurator { + configurator: Box::new(datadog_library_config::Configurator::new(false)), // No debug log as WASM can't write to stdout + envp: Vec::new(), + args: Vec::new(), + } + } + + #[wasm_bindgen] + pub fn set_envp(&mut self, envp: Box<[JsValue]>) -> Result<(), JsValue> { + self.envp = envp.iter().filter_map(|val| val.as_string()).collect(); + Ok(()) + } + + #[wasm_bindgen] + pub fn set_args(&mut self, args: Box<[JsValue]>) -> Result<(), JsValue> { + self.args = args.iter().filter_map(|val| val.as_string()).collect(); + Ok(()) + } + + #[wasm_bindgen] + pub fn get_config_local_path(&self, target: String) -> Result { + let target_enum = match target.as_str() { + "linux" => datadog_library_config::Target::Linux, + "win32" => datadog_library_config::Target::Windows, + "darwin" => datadog_library_config::Target::Macos, + _ => return Err(JsValue::from_str("Unsupported target")), + }; + Ok( + datadog_library_config::Configurator::local_stable_configuration_path(target_enum) + .to_string(), + ) + } + + #[wasm_bindgen] + pub fn get_config_managed_path(&self, target: String) -> Result { + let target_enum = match target.as_str() { + "linux" => datadog_library_config::Target::Linux, + "win32" => datadog_library_config::Target::Windows, + "darwin" => datadog_library_config::Target::Macos, + _ => return Err(JsValue::from_str("Unsupported target")), + }; + Ok( + datadog_library_config::Configurator::fleet_stable_configuration_path(target_enum) + .to_string(), + ) + } + + #[wasm_bindgen] + pub fn get_configuration( + &self, + config_string_local: String, + config_string_managed: String, + ) -> Result, JsValue> { + let envp: Vec> = self.envp.iter().map(|s| s.as_bytes().to_vec()).collect(); + + let args: Vec> = self.args.iter().map(|s| s.as_bytes().to_vec()).collect(); + + let res_config = self.configurator.get_config_from_bytes( + config_string_local.as_bytes(), + config_string_managed.as_bytes(), + datadog_library_config::ProcessInfo { + envp: envp, + args: args, + language: b"nodejs".to_vec(), + }, + ); + + match res_config { + Ok(config) => { + let config_entries: Vec = config + .into_iter() + .map(|c| ConfigEntry { + name: c.name.to_str().into(), + value: c.value, + source: c.source.to_str().into(), + config_id: c.config_id.unwrap_or_default(), + }) + .collect(); + Ok(config_entries) + } + Err(e) => Err(JsValue::from_str(&format!( + "Failed to get configuration: {:?}", + e + ))), + } + } +} diff --git a/load.js b/load.js index 6ce11fe..21970c3 100644 --- a/load.js +++ b/load.js @@ -24,12 +24,23 @@ function maybeLoad (name) { function load (name) { const filename = find(name) + const filenameWASM = findWASM(name) - if (!filename) { - throw new Error(`Could not find a ${name} binary for ${PLATFORM}${LIBC}-${ARCH}.`) + if (filename) { + return runtimeRequire(filename) + } else if (filenameWASM) { + return runtimeRequire(filenameWASM) } + throw new Error(`Could not find a ${name} binary for ${PLATFORM}${LIBC}-${ARCH} nor a ${name} WASM module.`) +} - return runtimeRequire(filename) +function findWASM (name) { + const root = __dirname + const prebuilds = path.join(root, 'prebuilds') + const folders = readdirSync(prebuilds) + if (folders.find(f => f === name)) { + return path.join(prebuilds, name, `${name}.js`) + } } function find (name, binary = false) { diff --git a/package.json b/package.json index 524de2d..8efb266 100644 --- a/package.json +++ b/package.json @@ -4,10 +4,12 @@ "description": "Node.js binding for libdatadog", "main": "index.js", "scripts": { - "build": "yarn -s build-debug", + "install-wasm-pack": "curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh", + "build": "yarn -s build-debug && yarn -s build-wasm", "build-debug": "mkdir -p target && yarn -s cargo-build > ./target/out.ndjson && yarn -s copy-artifacts", "build-release": "mkdir -p target && yarn -s cargo-build-release > ./target/out.ndjson && yarn -s copy-artifacts", - "build-all": "mkdir -p target && yarn -s cargo-build -- --workspace > ./target/out.ndjson && yarn -s copy-artifacts", + "build-all": "mkdir -p target && yarn -s cargo-build -- --workspace > ./target/out.ndjson && yarn -s copy-artifacts && yarn -s build-wasm", + "build-wasm": "yarn -s install-wasm-pack && wasm-pack build --target nodejs ./crates/library_config --out-dir ../../prebuilds/library_config", "cargo-build-release": "yarn -s cargo-build -- --release", "cargo-build": "cargo build --message-format=json-render-diagnostics", "copy-artifacts": "node ./scripts/copy-artifacts", diff --git a/test.js b/test.js index f451472..822f194 100644 --- a/test.js +++ b/test.js @@ -6,5 +6,7 @@ const { execSync } = require('child_process') fs.readdirSync('test') .filter(file => file.endsWith('.js') || !file.includes('.')) .forEach(file => { - require('./test/' + file) + if (!file.includes('wasm')) { + require('./test/' + file) + } }) diff --git a/test/wasm/library_config/.gitignore b/test/wasm/library_config/.gitignore new file mode 100644 index 0000000..5fff1d9 --- /dev/null +++ b/test/wasm/library_config/.gitignore @@ -0,0 +1 @@ +pkg diff --git a/test/wasm/library_config/README.md b/test/wasm/library_config/README.md new file mode 100644 index 0000000..ca98e96 --- /dev/null +++ b/test/wasm/library_config/README.md @@ -0,0 +1,8 @@ +# Libconfig example + +## How to run +From repository root +```bash +yarn build-wasm +node test/wasm/library_config/index.js +``` diff --git a/test/wasm/library_config/config_local_phase1.yaml b/test/wasm/library_config/config_local_phase1.yaml new file mode 100644 index 0000000..f9c6b62 --- /dev/null +++ b/test/wasm/library_config/config_local_phase1.yaml @@ -0,0 +1,2 @@ +apm_configuration_default: + DD_RUNTIME_METRICS_ENABLED: true diff --git a/test/wasm/library_config/config_local_phase2.yaml b/test/wasm/library_config/config_local_phase2.yaml new file mode 100644 index 0000000..f9c6b62 --- /dev/null +++ b/test/wasm/library_config/config_local_phase2.yaml @@ -0,0 +1,2 @@ +apm_configuration_default: + DD_RUNTIME_METRICS_ENABLED: true diff --git a/test/wasm/library_config/config_managed_phase2.yaml b/test/wasm/library_config/config_managed_phase2.yaml new file mode 100644 index 0000000..28c3302 --- /dev/null +++ b/test/wasm/library_config/config_managed_phase2.yaml @@ -0,0 +1,9 @@ +rules: + - selectors: + - origin: language + matches: + - nodejs + operator: equals + configuration: + DD_SERVICE: my-service_butremote +config_id: abc diff --git a/test/wasm/library_config/index.js b/test/wasm/library_config/index.js new file mode 100644 index 0000000..64a60f8 --- /dev/null +++ b/test/wasm/library_config/index.js @@ -0,0 +1,57 @@ +const path = require('path'); +const fs = require('fs'); +const loader = require('../../../load.js'); +const assert = require('assert'); + +const libconfig = loader.load('library_config'); +assert(libconfig !== undefined); + +// Test 1: phase 1 (host selection) +function test_host_wide() { + const rawConfigLocal = fs.readFileSync(path.join(__dirname, 'config_local_phase1.yaml')); + let configurator = new libconfig.JsConfigurator(); + + configurator.set_envp(Object.entries(process.env).map(([key, value]) => `${key}=${value}`)) + configurator.set_args(process.argv) + + let values = configurator.get_configuration(rawConfigLocal.toString(), "") + values.forEach((value, key, map) => { + console.log(`(phase 1) name: ${value.name}, value: ${value.value}, source: ${value.source}, config_id: ${value.config_id}`) + }); + + assert.strictEqual(values.length, 1) + assert.strictEqual(values[0].name, 'DD_RUNTIME_METRICS_ENABLED') + assert.strictEqual(values[0].value, 'true') + assert.strictEqual(values[0].source, 'local_stable_config') +} + +// Test 2: managed > local, phase 2 (service selection) +function test_service_selector() { + const rawConfigLocal = fs.readFileSync(path.join(__dirname, 'config_local_phase2.yaml')); + const rawConfigManaged = fs.readFileSync(path.join(__dirname, 'config_managed_phase2.yaml')); + let configurator = new libconfig.JsConfigurator(); + + configurator.set_envp(Object.entries(process.env).map(([key, value]) => `${key}=${value}`)) + configurator.set_args(process.argv) + + values = configurator.get_configuration(rawConfigLocal.toString(), rawConfigManaged.toString()) + values.forEach((value, key, map) => { + console.log(`(phase 2) name: ${value.name}, value: ${value.value}, source: ${value.source}, config_id: ${value.config_id}`) + }); + + assert.strictEqual(values.length, 2) + assert.strictEqual(values[0].name, 'DD_RUNTIME_METRICS_ENABLED') + assert.strictEqual(values[0].value, 'true') + assert.strictEqual(values[0].source, 'local_stable_config') + + if (process.platform == 'linux') { + assert.strictEqual(configurator.get_config_local_path(process.platform), "/etc/datadog-agent/application_monitoring.yaml"); + } else if (process.platform == 'darwin') { + assert.strictEqual(configurator.get_config_local_path(process.platform), "/opt/datadog-agent/etc/application_monitoring.yaml"); + } else if (process.platform == 'win32') { + assert.strictEqual(configurator.get_config_local_path(process.platform), "C:\\ProgramData\\Datadog\\application_monitoring.yaml"); + } +} + +test_host_wide(); +test_service_selector(); diff --git a/test_wasm.js b/test_wasm.js new file mode 100644 index 0000000..762dd03 --- /dev/null +++ b/test_wasm.js @@ -0,0 +1,10 @@ +'use strict' + +const fs = require('fs') +const { execSync } = require('child_process') + +fs.readdirSync('test/wasm') + .filter(file => file.endsWith('.js') || !file.includes('.')) + .forEach(file => { + require('./test/wasm/' + file) + }) From c58af3df64bd49189ddab94d62f0c0f468bac387 Mon Sep 17 00:00:00 2001 From: Baptiste Foy Date: Tue, 18 Feb 2025 15:13:00 +0100 Subject: [PATCH 2/2] v0.5.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8efb266..2f36f71 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@datadog/libdatadog", - "version": "0.4.0", + "version": "0.5.0", "description": "Node.js binding for libdatadog", "main": "index.js", "scripts": {