-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(google-cloud-run): detect Node.js version, use matching @instana/…
…google-cloud-run version
- Loading branch information
Showing
7 changed files
with
113 additions
and
34 deletions.
There are no files selected for viewing
21 changes: 18 additions & 3 deletions
21
packages/google-cloud-run/images/instana-google-cloud-run/Dockerfile-local
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,32 @@ | ||
FROM node:12.22.7-buster AS instana-google-cloud-run-build-nodejs | ||
|
||
ARG legacy_package_version_range="<2.0.0" | ||
|
||
# ---- @instana/[email protected] for Node.js < 10.x ---- | ||
WORKDIR /instana/legacy-1x | ||
COPY package.json.npm ./ | ||
RUN sed -e s/SELF_VERSION/1.0.0/g \ | ||
-e s/INSTANA_GOOGLE_CLOUD_RUN_VERSION/$legacy_package_version_range/g \ | ||
package.json.npm > package.json | ||
COPY .npmrc ./ | ||
RUN npm install --only=production | ||
RUN rm -f instana-*.tgz && \ | ||
rm -f package.json && \ | ||
rm -f package.json.npm && \ | ||
rm -f .npmrc | ||
|
||
# ---- @instana/google-cloud-run@latest for Node.js >= 10.x ---- | ||
WORKDIR /instana | ||
COPY package.json ./ | ||
COPY instana-*.tgz ./ | ||
COPY .npmrc ./ | ||
COPY setup.sh ./ | ||
|
||
RUN npm install --only=production | ||
|
||
RUN rm -f instana-*.tgz | ||
RUN rm -f package.json | ||
RUN rm -f .npmrc | ||
|
||
# ---- Start over from scratch and copy npm modules | ||
FROM scratch | ||
|
||
COPY --from=instana-google-cloud-run-build-nodejs /instana /instana | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,20 +2,36 @@ FROM node:12.22.7-buster AS instana-google-cloud-run-build-nodejs | |
|
||
ARG package_version | ||
|
||
ARG legacy_package_version_range="<2.0.0" | ||
|
||
# ---- @instana/[email protected] for Node.js < 10.x ---- | ||
WORKDIR /instana/legacy-1x | ||
COPY package.json.npm ./ | ||
RUN sed -e s/SELF_VERSION/$package_version/g \ | ||
-e s/INSTANA_GOOGLE_CLOUD_RUN_VERSION/$legacy_package_version_range/g \ | ||
package.json.npm > package.json | ||
COPY .npmrc ./ | ||
RUN npm install --only=production | ||
RUN rm -f instana-*.tgz && \ | ||
rm -f package.json && \ | ||
rm -f package.json.npm && \ | ||
rm -f .npmrc | ||
|
||
# ---- @instana/google-cloud-run@latest for Node.js >= 10.x ---- | ||
WORKDIR /instana | ||
COPY package.json.npm ./ | ||
RUN sed -e s/VERSION/$package_version/g package.json.npm > package.json | ||
RUN sed -e s/SELF_VERSION/$package_version/g \ | ||
-e s/INSTANA_GOOGLE_CLOUD_RUN_VERSION/$package_version/g \ | ||
package.json.npm > package.json | ||
COPY .npmrc ./ | ||
COPY setup.sh ./ | ||
|
||
RUN npm install --only=production | ||
|
||
RUN rm -f instana-*.tgz && \ | ||
rm -f package.json && \ | ||
rm -f package.json.npm && \ | ||
rm -f .npmrc | ||
|
||
# ---- Start over from scratch and copy npm modules | ||
FROM scratch | ||
|
||
COPY --from=instana-google-cloud-run-build-nodejs /instana /instana | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "instana-google-cloud-run-docker-image", | ||
"version": "VERSION", | ||
"version": "SELF_VERSION", | ||
"description": "Provides @instana/google-cloud-run as an image for multi stage Dockerfiles", | ||
"repository": { | ||
"type": "git", | ||
|
@@ -9,6 +9,6 @@ | |
"author": "Bastian Krol <[email protected]>", | ||
"license": "ISC", | ||
"dependencies": { | ||
"@instana/google-cloud-run": "VERSION" | ||
"@instana/google-cloud-run": "INSTANA_GOOGLE_CLOUD_RUN_VERSION" | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/google-cloud-run/images/instana-google-cloud-run/setup.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
####################################### | ||
# (c) Copyright IBM Corp. 2021 | ||
# (c) Copyright Instana Inc. and contributors 2020 | ||
####################################### | ||
cd /instana | ||
npm rebuild || echo "Warning: Rebuilding native add-ons for @instana/google-cloud-run failed. Monitoring the Cloud Run service revision instance will work nonetheless, but you will miss some Node.js metrics (GC metrics, event loop metrics, ...). See https://www.ibm.com/docs/de/obi/current?topic=agents-monitoring-google-cloud-run#build-dependencies-and-native-add-ons for details." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,44 @@ | ||
/* | ||
* (c) Copyright IBM Corp. 2021 | ||
* (c) Copyright Instana Inc. and contributors 2020 | ||
* (c) Copyright IBM Corp. 2022 | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const { isNodeJsTooOld, minimumNodeJsVersion } = require('@instana/core/src/util/nodeJsVersionCheck'); | ||
// MAINTENANCE NOTE: All code in this file needs to be compatible with all Node.js versions >= 6.0.0. | ||
|
||
if (isNodeJsTooOld()) { | ||
try { | ||
const nodeJsVersion = process.version; | ||
if (typeof nodeJsVersion !== 'string') { | ||
return; | ||
} | ||
const matchResult = /v(\d+)\.(\d+)\.(\d+)/.exec(nodeJsVersion); | ||
if (!matchResult || matchResult.length < 4) { | ||
return; | ||
} | ||
const majorVersion = parseInt(matchResult[1], 10); | ||
if (majorVersion == null || isNaN(majorVersion)) { | ||
return; | ||
} | ||
if (majorVersion >= 10) { | ||
module.exports = exports = require('./preactivate.js'); | ||
return; | ||
} else if (majorVersion >= 6 && majorVersion < 10) { | ||
// Maintenance note: As long as we do not backport the changes to index.js and the additional preactivate.js file to | ||
// the 1.x branch, this needs to point to: | ||
// /instana/legacy-1x/node_modules/@instana/google-cloud-run/src/index | ||
// Because in 1.x, src/index either delegates to src/activate or src/noop. | ||
// | ||
// If we ever include those changes into the 1.x version (which we should not), we would need to point to: | ||
// /instana/legacy-1x/node_modules/@instana/google-cloud-run/src/preactivate | ||
// Otherwise we would get into an endless require loop. | ||
// | ||
// eslint-disable-next-line instana/no-unsafe-require | ||
module.exports = exports = require('/instana/legacy-1x/node_modules/@instana/google-cloud-run/src/index'); | ||
return; | ||
} | ||
// Node.js versions < 6 are unsupported and will not be instrumented at all. | ||
} catch (e) { | ||
// ignore all runtime errors | ||
// eslint-disable-next-line no-console | ||
console.error( | ||
`The package @instana/google-cloud-run requires at least Node.js ${minimumNodeJsVersion} but this process is ` + | ||
`running on Node.js ${process.version}. This Google Cloud Run service will not be monitored by Instana.` | ||
); | ||
return; | ||
} | ||
|
||
const { util: coreUtil } = require('@instana/core'); | ||
const { environment: environmentUtil } = require('@instana/serverless'); | ||
|
||
const isExcludedFromInstrumentation = coreUtil.excludedFromInstrumentation && coreUtil.excludedFromInstrumentation(); | ||
|
||
if (!isExcludedFromInstrumentation) { | ||
environmentUtil.validate(); | ||
} | ||
|
||
if (!isExcludedFromInstrumentation && environmentUtil.isValid()) { | ||
module.exports = exports = require('./activate'); | ||
} else { | ||
module.exports = exports = require('./noop'); | ||
console.error(e); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* (c) Copyright IBM Corp. 2021 | ||
* (c) Copyright Instana Inc. and contributors 2020 | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const { isNodeJsTooOld, minimumNodeJsVersion } = require('@instana/core/src/util/nodeJsVersionCheck'); | ||
|
||
if (isNodeJsTooOld()) { | ||
// eslint-disable-next-line no-console | ||
console.error( | ||
`The package @instana/google-cloud-run requires at least Node.js ${minimumNodeJsVersion} but this process is ` + | ||
`running on Node.js ${process.version}. This Google Cloud Run service will not be monitored by Instana.` | ||
); | ||
return; | ||
} | ||
|
||
const { util: coreUtil } = require('@instana/core'); | ||
const { environment: environmentUtil } = require('@instana/serverless'); | ||
|
||
const isExcludedFromInstrumentation = coreUtil.excludedFromInstrumentation && coreUtil.excludedFromInstrumentation(); | ||
|
||
if (!isExcludedFromInstrumentation) { | ||
environmentUtil.validate(); | ||
} | ||
|
||
if (!isExcludedFromInstrumentation && environmentUtil.isValid()) { | ||
module.exports = exports = require('./activate'); | ||
} else { | ||
module.exports = exports = require('./noop'); | ||
} |