Skip to content

Commit

Permalink
update with new healthcheck based version detection
Browse files Browse the repository at this point in the history
  • Loading branch information
rochdev committed Jul 24, 2024
1 parent 349dd0c commit 9a170ea
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 26 deletions.
3 changes: 2 additions & 1 deletion docs/weblog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,8 @@ Returns a JSON dict, with those values :
"library": {
"language": "<language>", // one of cpp, dotnet, golang, java, nodejs, php, python, ruby
"version": "1.2.3", // version of the library
"libddwaf_version": "4.5.6" // version of libddwaf
"libddwaf_version": "4.5.6" // version of libddwaf,
"appsec_event_rules_version": "7.8.9" // version of appsec event rules
}
}
```
2 changes: 1 addition & 1 deletion utils/_context/_scenarios/parametric.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ def node_library_factory() -> APMLibraryTestServer:
volumes = {}

if os.path.exists("./binaries/nodejs-load-from-local"):
path = open("./binaries/nodejs-load-from-local").read().strip(' \r\n')
path = open("./binaries/nodejs-load-from-local").read().strip(" \r\n")
source = os.path.join(_get_base_directory(), path)
volumes[os.path.abspath(source)] = "/volumes/dd-trace-js"

Expand Down
9 changes: 5 additions & 4 deletions utils/_context/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ def __init__(
}

if os.path.exists("./binaries/nodejs-load-from-local"):
path = open("./binaries/nodejs-load-from-local").read().strip(' \r\n')
path = open("./binaries/nodejs-load-from-local").read().strip(" \r\n")
volumes[os.path.abspath(path)] = {
"bind": f"/volumes/dd-trace-js",
"mode": "ro",
Expand Down Expand Up @@ -695,10 +695,11 @@ def post_start(self):
# https://github.com/DataDog/system-tests/issues/2799
if self.library == "nodejs":
with open(self.healthcheck_log_file, mode="r", encoding="utf-8") as f:
data = json.load(f)
lib = json.load(f)["library"]

self._library = LibraryVersion(data["library"]["language"], data["library"]["version"])
self.libddwaf_version = LibraryVersion("libddwaf", data["library"]["libddwaf_version"]).version
self._library = LibraryVersion(lib["language"], lib["version"])
self.libddwaf_version = LibraryVersion("libddwaf", lib["libddwaf_version"]).version
self.appsec_rules_version = LibraryVersion("appsec_rules", lib["appsec_event_rules_version"]).version

logger.stdout(f"Library: {self.library}")

Expand Down
1 change: 1 addition & 0 deletions utils/build/docker/nodejs/express4-typescript/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
install-strategy = nested
3 changes: 2 additions & 1 deletion utils/build/docker/nodejs/express4-typescript/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ app.get('/healthcheck', (req: Request, res: Response) => {
library: {
language: 'nodejs',
version: require('dd-trace/package.json').version,
libddwaf_version: require('@datadog/native-appsec/package.json').libddwaf_version
libddwaf_version: require('dd-trace/node_modules/@datadog/native-appsec/package.json').libddwaf_version,
appsec_event_rules_version: require('dd-trace/packages/dd-trace/src/appsec/recommended.json').metadata.rules_version
}
});
})
Expand Down
2 changes: 1 addition & 1 deletion utils/build/docker/nodejs/express4/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"no-console": 0,
"prefer-const": 2,
"object-curly-spacing": [2, "always"],
"import/no-extraneous-dependencies": 2,
"import/no-extraneous-dependencies": false,
"standard/no-callback-literal": 0,
"no-prototype-builtins": 0,
"mocha/no-mocha-arrows": 0,
Expand Down
1 change: 1 addition & 0 deletions utils/build/docker/nodejs/express4/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
install-strategy = nested
3 changes: 2 additions & 1 deletion utils/build/docker/nodejs/express4/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ app.get('/healthcheck', (req, res) => {
library: {
language: 'nodejs',
version: require('dd-trace/package.json').version,
libddwaf_version: require('@datadog/native-appsec/package.json').libddwaf_version
libddwaf_version: require('dd-trace/node_modules/@datadog/native-appsec/package.json').libddwaf_version,
appsec_event_rules_version: require('dd-trace/packages/dd-trace/src/appsec/recommended.json').metadata.rules_version
}
})
})
Expand Down
19 changes: 5 additions & 14 deletions utils/build/docker/nodejs/install_ddtrace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ cd /usr/app

if [ -e /binaries/nodejs-load-from-local ]; then
echo "using local version that will be mounted at runtime"

echo "999.0.0" > SYSTEM_TESTS_LIBRARY_VERSION
echo "999.0.0" > SYSTEM_TESTS_LIBDDWAF_VERSION
echo "999.0.0" > SYSTEM_TESTS_APPSEC_EVENT_RULES_VERSION
else
if [ -e /binaries/nodejs-load-from-npm ]; then
target=$(</binaries/nodejs-load-from-npm)
Expand All @@ -24,15 +20,10 @@ else
echo "install from NPM"
fi

# nodejs uses the next API to get the library version. See https://github.com/DataDog/system-tests/issues/2799
echo "0.0.0" > SYSTEM_TESTS_LIBRARY_VERSION
echo "0.0.0" > SYSTEM_TESTS_LIBDDWAF_VERSION

# npm list --json | jq -r '.dependencies."dd-trace".version' > SYSTEM_TESTS_LIBRARY_VERSION
# npm explore @datadog/native-appsec -- cat package.json | jq -r '.libddwaf_version' > SYSTEM_TESTS_LIBDDWAF_VERSION
npm explore dd-trace -- cat packages/dd-trace/src/appsec/recommended.json | jq -r '.metadata.rules_version // "1.2.5"' > SYSTEM_TESTS_APPSEC_EVENT_RULES_VERSION
npm install $target
fi

# echo "dd-trace version: $(cat SYSTEM_TESTS_LIBRARY_VERSION)"
# echo "libddwaf version: $(cat SYSTEM_TESTS_LIBDDWAF_VERSION)"
echo "rules version: $(cat SYSTEM_TESTS_APPSEC_EVENT_RULES_VERSION)"
# nodejs uses the next API to get the library version. See https://github.com/DataDog/system-tests/issues/2799
echo "0.0.0" > SYSTEM_TESTS_LIBRARY_VERSION
echo "0.0.0" > SYSTEM_TESTS_LIBDDWAF_VERSION
echo "0.0.0" > SYSTEM_TESTS_APPSEC_EVENT_RULES_VERSION
1 change: 1 addition & 0 deletions utils/build/docker/nodejs/nextjs/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
install-strategy = nested
7 changes: 4 additions & 3 deletions utils/build/docker/nodejs/nextjs/src/app/healthcheck/route.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { NextResponse } from 'next/server'
import { version } from 'dd-trace/package.json'
// eslint-disable-next-line import/no-extraneous-dependencies
import { libddwaf_version as libddwafVersion } from '@datadog/native-appsec/package.json'
import { libddwaf_version as libddwafVersion } from 'dd-trace/node_modules/@datadog/native-appsec/package.json'
import { metadata } from 'dd-trace/packages/dd-trace/src/appsec/recommended.json'

export async function GET (request) {
return NextResponse.json({
status: 'ok',
library: {
language: 'nodejs',
version,
libddwaf_version: libddwafVersion
libddwaf_version: libddwafVersion,
appsec_event_rules_version: metadata.rules_version
}
}, {
status: 200
Expand Down
1 change: 1 addition & 0 deletions utils/build/docker/nodejs/parametric/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
install-strategy = nested
1 change: 1 addition & 0 deletions utils/build/docker/nodejs_otel/express4-otel/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
install-strategy = nested

0 comments on commit 9a170ea

Please sign in to comment.