diff --git a/.github/sync-repo-settings.yaml b/.github/sync-repo-settings.yaml index 679fc497..0be16649 100644 --- a/.github/sync-repo-settings.yaml +++ b/.github/sync-repo-settings.yaml @@ -34,7 +34,6 @@ branchProtectionRules: - "cla/google" - "docs" - "lint" - - "test (10)" - "test (12)" - "test (14)" - "test (16)" diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 244587e5..457c72c3 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -16,7 +16,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node: [10, 12, 14, 16] + node: [12, 14, 16] steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 diff --git a/.kokoro/continuous/node10/common.cfg b/.kokoro/continuous/node10/common.cfg deleted file mode 100644 index 44967882..00000000 --- a/.kokoro/continuous/node10/common.cfg +++ /dev/null @@ -1,34 +0,0 @@ -# Format: //devtools/kokoro/config/proto/build.proto - -# Build logs will be here -action { - define_artifacts { - regex: "**/*sponge_log.xml" - } -} - -# Bring in codecov.io token into the build as $KOKORO_KEYSTORE_DIR/73713_dpebot_codecov_token -before_action { - fetch_keystore { - keystore_resource { - keystore_config_id: 73713 - keyname: "dpebot_codecov_token" - } - } -} - -# Download trampoline resources. -gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" - -# Use the trampoline script to run in docker. -build_file: "cloud-profiler-nodejs/.kokoro/trampoline_v2.sh" - -# Configure the docker image for kokoro-trampoline. -env_vars: { - key: "TRAMPOLINE_IMAGE" - value: "gcr.io/cloud-devrel-kokoro-resources/node:10-user" -} -env_vars: { - key: "TRAMPOLINE_BUILD_FILE" - value: "github/cloud-profiler-nodejs/.kokoro/test.sh" -} diff --git a/.kokoro/continuous/node10/docs.cfg b/.kokoro/continuous/node10/docs.cfg deleted file mode 100644 index 59c1e9b8..00000000 --- a/.kokoro/continuous/node10/docs.cfg +++ /dev/null @@ -1,4 +0,0 @@ -env_vars: { - key: "TRAMPOLINE_BUILD_FILE" - value: "github/cloud-profiler-nodejs/.kokoro/docs.sh" -} diff --git a/.kokoro/continuous/node10/test.cfg b/.kokoro/continuous/node10/test.cfg deleted file mode 100644 index 609c0cf0..00000000 --- a/.kokoro/continuous/node10/test.cfg +++ /dev/null @@ -1,9 +0,0 @@ -# Bring in codecov.io token into the build as $KOKORO_KEYSTORE_DIR/73713_dpebot_codecov_token -before_action { - fetch_keystore { - keystore_resource { - keystore_config_id: 73713 - keyname: "dpebot_codecov_token" - } - } -} diff --git a/.kokoro/continuous/node8/common.cfg b/.kokoro/continuous/node8/common.cfg deleted file mode 100644 index e210785d..00000000 --- a/.kokoro/continuous/node8/common.cfg +++ /dev/null @@ -1,24 +0,0 @@ -# Format: //devtools/kokoro/config/proto/build.proto - -# Build logs will be here -action { - define_artifacts { - regex: "**/*sponge_log.xml" - } -} - -# Download trampoline resources. -gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" - -# Use the trampoline script to run in docker. -build_file: "cloud-profiler-nodejs/.kokoro/trampoline.sh" - -# Configure the docker image for kokoro-trampoline. -env_vars: { - key: "TRAMPOLINE_IMAGE" - value: "gcr.io/cloud-devrel-kokoro-resources/node:8-user" -} -env_vars: { - key: "TRAMPOLINE_BUILD_FILE" - value: "github/cloud-profiler-nodejs/.kokoro/test.sh" -} diff --git a/.kokoro/continuous/node8/docs.cfg b/.kokoro/continuous/node8/docs.cfg deleted file mode 100644 index 59c1e9b8..00000000 --- a/.kokoro/continuous/node8/docs.cfg +++ /dev/null @@ -1,4 +0,0 @@ -env_vars: { - key: "TRAMPOLINE_BUILD_FILE" - value: "github/cloud-profiler-nodejs/.kokoro/docs.sh" -} diff --git a/.kokoro/continuous/node8/lint.cfg b/.kokoro/continuous/node8/lint.cfg deleted file mode 100644 index 2c5b2bb0..00000000 --- a/.kokoro/continuous/node8/lint.cfg +++ /dev/null @@ -1,4 +0,0 @@ -env_vars: { - key: "TRAMPOLINE_BUILD_FILE" - value: "github/cloud-profiler-nodejs/.kokoro/lint.sh" -} diff --git a/.kokoro/continuous/node8/samples-test.cfg b/.kokoro/continuous/node8/samples-test.cfg deleted file mode 100644 index 1ebf12ab..00000000 --- a/.kokoro/continuous/node8/samples-test.cfg +++ /dev/null @@ -1,7 +0,0 @@ -# Download resources for system tests (service account key, etc.) -gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/google-cloud-nodejs" - -env_vars: { - key: "TRAMPOLINE_BUILD_FILE" - value: "github/cloud-profiler-nodejs/.kokoro/samples-test.sh" -} diff --git a/.kokoro/continuous/node8/system-test-grpcjs.cfg b/.kokoro/continuous/node8/system-test-grpcjs.cfg deleted file mode 100644 index 32bc7310..00000000 --- a/.kokoro/continuous/node8/system-test-grpcjs.cfg +++ /dev/null @@ -1,12 +0,0 @@ -# Download resources for system tests (service account key, etc.) -gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/google-cloud-nodejs" - -env_vars: { - key: "TRAMPOLINE_BUILD_FILE" - value: "github/cloud-profiler-nodejs/.kokoro/system-test.sh" -} - -env_vars: { - key: "GOOGLE_CLOUD_USE_GRPC_JS" - value: "1" -} diff --git a/.kokoro/continuous/node8/system-test.cfg b/.kokoro/continuous/node8/system-test.cfg deleted file mode 100644 index 68bdaa30..00000000 --- a/.kokoro/continuous/node8/system-test.cfg +++ /dev/null @@ -1,7 +0,0 @@ -# Download resources for system tests (service account key, etc.) -gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/google-cloud-nodejs" - -env_vars: { - key: "TRAMPOLINE_BUILD_FILE" - value: "github/cloud-profiler-nodejs/.kokoro/system-test.sh" -} diff --git a/.kokoro/continuous/node8/test.cfg b/.kokoro/continuous/node8/test.cfg deleted file mode 100644 index e69de29b..00000000 diff --git a/.kokoro/presubmit/node10/common.cfg b/.kokoro/presubmit/node10/common.cfg deleted file mode 100644 index 44967882..00000000 --- a/.kokoro/presubmit/node10/common.cfg +++ /dev/null @@ -1,34 +0,0 @@ -# Format: //devtools/kokoro/config/proto/build.proto - -# Build logs will be here -action { - define_artifacts { - regex: "**/*sponge_log.xml" - } -} - -# Bring in codecov.io token into the build as $KOKORO_KEYSTORE_DIR/73713_dpebot_codecov_token -before_action { - fetch_keystore { - keystore_resource { - keystore_config_id: 73713 - keyname: "dpebot_codecov_token" - } - } -} - -# Download trampoline resources. -gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" - -# Use the trampoline script to run in docker. -build_file: "cloud-profiler-nodejs/.kokoro/trampoline_v2.sh" - -# Configure the docker image for kokoro-trampoline. -env_vars: { - key: "TRAMPOLINE_IMAGE" - value: "gcr.io/cloud-devrel-kokoro-resources/node:10-user" -} -env_vars: { - key: "TRAMPOLINE_BUILD_FILE" - value: "github/cloud-profiler-nodejs/.kokoro/test.sh" -} diff --git a/.kokoro/presubmit/node10/docs.cfg b/.kokoro/presubmit/node10/docs.cfg deleted file mode 100644 index 59c1e9b8..00000000 --- a/.kokoro/presubmit/node10/docs.cfg +++ /dev/null @@ -1,4 +0,0 @@ -env_vars: { - key: "TRAMPOLINE_BUILD_FILE" - value: "github/cloud-profiler-nodejs/.kokoro/docs.sh" -} diff --git a/.kokoro/presubmit/node10/lint.cfg b/.kokoro/presubmit/node10/lint.cfg deleted file mode 100644 index 2c5b2bb0..00000000 --- a/.kokoro/presubmit/node10/lint.cfg +++ /dev/null @@ -1,4 +0,0 @@ -env_vars: { - key: "TRAMPOLINE_BUILD_FILE" - value: "github/cloud-profiler-nodejs/.kokoro/lint.sh" -} diff --git a/.kokoro/presubmit/node10/test.cfg b/.kokoro/presubmit/node10/test.cfg deleted file mode 100644 index e69de29b..00000000 diff --git a/package.json b/package.json index c0d66833..fab91f7d 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "pretty-ms": "^7.0.0", "protobufjs": "~6.11.0", "semver": "^7.0.0", - "teeny-request": "^7.0.0" + "teeny-request": "^8.0.0" }, "devDependencies": { "@types/extend": "^3.0.0", @@ -54,18 +54,18 @@ "@types/tmp": "0.2.3", "c8": "^7.0.0", "codecov": "^3.0.0", - "gts": "^2.0.0", + "gts": "^3.1.0", "js-green-licenses": "^3.0.0", "jsdoc": "^3.6.2", "jsdoc-fresh": "^1.0.1", "jsdoc-region-tag": "^1.0.2", "linkinator": "^2.0.0", - "mocha": "^8.0.0", + "mocha": "^9.2.2", "nock": "^13.0.0", "sinon": "^14.0.0", "source-map": "^0.7.0", "tmp": "0.2.1", - "typescript": "^3.8.3" + "typescript": "^4.7.2" }, "files": [ "build/src", @@ -81,6 +81,6 @@ ] }, "engines": { - "node": ">=10.4.1" + "node": ">=12.0.0" } } diff --git a/samples/package.json b/samples/package.json index 58311b51..2d2420db 100644 --- a/samples/package.json +++ b/samples/package.json @@ -8,7 +8,7 @@ "test": "echo 'no test yet'" }, "engines": { - "node": ">=10.4.1" + "node": ">=12.0.0" }, "repository": { "type": "git", diff --git a/src/profiler.ts b/src/profiler.ts index cadcd560..8e333422 100644 --- a/src/profiler.ts +++ b/src/profiler.ts @@ -196,7 +196,7 @@ async function profileBytes(p: perftools.profiles.IProfile): Promise { /** * Error constructed from HTTP server response which indicates backoff. */ -class BackoffResponseError extends Error { +export class BackoffResponseError extends Error { constructor(message: string | undefined, readonly backoffMillis: number) { super(message); } @@ -392,11 +392,16 @@ export class Profiler extends ServiceObject { try { prof = await this.createProfile(); } catch (err) { - if (isBackoffResponseError(err)) { + if (isBackoffResponseError(err as BackoffResponseError)) { this.logger.debug( - `Must wait ${msToStr(err.backoffMillis)} to create profile: ${err}` + `Must wait ${msToStr( + (err as BackoffResponseError).backoffMillis + )} to create profile: ${err}` + ); + return Math.min( + (err as BackoffResponseError).backoffMillis, + this.config.serverBackoffCapMillis ); - return Math.min(err.backoffMillis, this.config.serverBackoffCapMillis); } const backoff = this.retryer.getBackoff(); this.logger.warn( diff --git a/system-test/busybench/package.json b/system-test/busybench/package.json index 20dd71ea..dfb1e18a 100644 --- a/system-test/busybench/package.json +++ b/system-test/busybench/package.json @@ -1,5 +1,5 @@ { - "name": "", + "name": "system-test", "version": "0.0.0", "description": "", "main": "build/src/index.js", @@ -7,6 +7,9 @@ "files": [ "build/src" ], + "engines": { + "node": ">=12.0.0" + }, "license": "Apache-2.0", "keywords": [], "scripts": { @@ -20,5 +23,7 @@ "posttest": "npm run check" }, "devDependencies": {}, - "dependencies": {} + "dependencies": { + "@google-cloud/profiler": "^4.2.0" + } } diff --git a/system-test/integration_test.go b/system-test/integration_test.go index 6c357a97..d6c497d6 100644 --- a/system-test/integration_test.go +++ b/system-test/integration_test.go @@ -99,15 +99,14 @@ retry npm_install --nodedir="$NODEDIR" npm run compile npm pack --nodedir="$NODEDIR" >/dev/null VERSION=$(node -e "console.log(require('./package.json').version);") -PROFILER="$HOME/cloud-profiler-nodejs/google-cloud-profiler-$VERSION.tgz" TESTDIR="$HOME/test" mkdir -p "$TESTDIR" cp -r "system-test/busybench" "$TESTDIR" cd "$TESTDIR/busybench" -retry npm_install node-pre-gyp -retry npm_install --nodedir="$NODEDIR" "$PROFILER" typescript gts +retry npm_install @mapbox/node-pre-gyp --save +retry npm_install --nodedir="$NODEDIR" typescript gts; npm link ../../cloud-profiler-nodejs npm run compile @@ -261,19 +260,6 @@ func TestAgentIntegration(t *testing.T) { } testcases := []nodeGCETestCase{ - { - InstanceConfig: proftest.InstanceConfig{ - ProjectID: projectID, - Zone: zone, - Name: fmt.Sprintf("profiler-test-node10-%s", runID), - MachineType: "n1-standard-1", - }, - name: fmt.Sprintf("profiler-test-node10-%s-gce", runID), - wantProfiles: wantProfiles, - nodeVersion: "10", - timeout: gceTestTimeout, - benchDuration: gceBenchDuration, - }, { InstanceConfig: proftest.InstanceConfig{ ProjectID: projectID, diff --git a/test/test-init-config.ts b/test/test-init-config.ts index 393347a3..d14423fb 100644 --- a/test/test-init-config.ts +++ b/test/test-init-config.ts @@ -20,25 +20,30 @@ import * as sinon from 'sinon'; import {createProfiler, nodeVersionOkay} from '../src/index'; import {Profiler} from '../src/profiler'; +import * as packageJson from '../package.json'; describe('nodeVersionOkay', () => { + const version = parseInt(packageJson.engines.node.replace('>=', '')); it('should accept alpha versions', () => { - assert.strictEqual(true, nodeVersionOkay('v11.0.0-alpha.1')); + assert.strictEqual(true, nodeVersionOkay(`v${version}.0.0-alpha.1`)); }); it('should accept beta versions', () => { - assert.strictEqual(true, nodeVersionOkay('v12.9.10-beta.2')); + assert.strictEqual(true, nodeVersionOkay(`v${version}.9.10-beta.2`)); }); it('should accept nightly versions', () => { - assert.strictEqual(true, nodeVersionOkay('v11.0.0-nightly2018000000')); + assert.strictEqual( + true, + nodeVersionOkay(`v${version}.0.0-nightly2018000000`) + ); }); it('should accept pre-release versions', () => { - assert.strictEqual(true, nodeVersionOkay('v11.0.0-pre')); + assert.strictEqual(true, nodeVersionOkay(`v${version}.0.0-pre`)); }); - it('should accept v10.4.1', () => { - assert.strictEqual(true, nodeVersionOkay('v10.4.1')); + it('should accept v12.4.1', () => { + assert.strictEqual(true, nodeVersionOkay(`v${version}.4.1`)); }); - it('should not accept v10.4.0', () => { - assert.strictEqual(false, nodeVersionOkay('v10.4.0')); + it('should not accept v11.4.0', () => { + assert.strictEqual(false, nodeVersionOkay(`v${version - 1}.4.0`)); }); }); @@ -256,7 +261,7 @@ describe('createProfiler', () => { assert.fail('expected an error because invalid service was specified'); } catch (e) { assert.strictEqual( - e.message, + (e as Error).message, 'Service serviceName does not match regular expression "/^[a-z0-9]([-a-z0-9_.]{0,253}[a-z0-9])?$/"' ); } @@ -283,7 +288,7 @@ describe('createProfiler', () => { assert.fail('expected an error because invalid service was specified'); } catch (e) { assert.strictEqual( - e.message, + (e as Error).message, 'Project ID must be specified in the configuration' ); } @@ -335,7 +340,7 @@ describe('createProfiler', () => { assert.fail('expected an error because invalid service was specified'); } catch (e) { assert.strictEqual( - e.message, + (e as Error).message, 'serviceMapSearchPath is an empty array. Use disableSourceMaps ' + 'to disable source map support instead.' ); diff --git a/test/test-profiler.ts b/test/test-profiler.ts index 9251fb6d..44ebb3c3 100644 --- a/test/test-profiler.ts +++ b/test/test-profiler.ts @@ -28,7 +28,12 @@ import * as zlib from 'zlib'; import {perftools} from '../protos/profile'; import {ProfilerConfig} from '../src/config'; -import {parseBackoffDuration, Profiler, Retryer} from '../src/profiler'; +import { + parseBackoffDuration, + Profiler, + Retryer, + BackoffResponseError, +} from '../src/profiler'; import { decodedHeapProfile, @@ -163,7 +168,10 @@ describe('Profiler', () => { await profiler.profile(requestProf); assert.fail('Expected an error to be thrown,'); } catch (err) { - assert.strictEqual(err.message, 'Unexpected profile type UNKNOWN.'); + assert.strictEqual( + (err as Error).message, + 'Unexpected profile type UNKNOWN.' + ); } }); }); @@ -214,7 +222,7 @@ describe('Profiler', () => { assert.fail('expected error, no error thrown'); } catch (err) { assert.strictEqual( - err.message, + (err as Error).message, 'Cannot collect time profile, time profiler not enabled.' ); } @@ -265,7 +273,7 @@ describe('Profiler', () => { assert.fail('expected error, no error thrown'); } catch (err) { assert.strictEqual( - err.message, + (err as Error).message, 'Cannot collect heap profile, heap profiler not enabled.' ); } @@ -536,7 +544,7 @@ describe('Profiler', () => { assert.fail('expected error, no error thrown'); } catch (err) { assert.strictEqual( - err.message, + (err as Error).message, 'Profile not valid: ' + '{"name":"projects/12345678901/test-projectId"}.' ); @@ -662,7 +670,7 @@ describe('Profiler', () => { await profiler.createProfile(); assert.fail('expected error, no error thrown'); } catch (err) { - assert.strictEqual(err.message, 'Network error'); + assert.strictEqual((err as Error).message, 'Network error'); } }); it('should throw status message when response has non-200 status.', async () => { @@ -679,7 +687,7 @@ describe('Profiler', () => { await profiler.createProfile(); assert.fail('expected error, no error thrown'); } catch (err) { - assert.strictEqual(err.message, '500 status code'); + assert.strictEqual((err as Error).message, '500 status code'); } }); it( @@ -701,7 +709,10 @@ describe('Profiler', () => { await profiler.createProfile(); assert.fail('expected error, no error thrown'); } catch (err) { - assert.strictEqual(err.backoffMillis, 50000); + assert.strictEqual( + (err as BackoffResponseError).backoffMillis, + 50000 + ); } } ); @@ -716,7 +727,10 @@ describe('Profiler', () => { await profiler.createProfile(); assert.fail('expected error, no error thrown'); } catch (err) { - assert.strictEqual(err.message, 'Profile not valid: undefined.'); + assert.strictEqual( + (err as Error).message, + 'Profile not valid: undefined.' + ); } }); }); diff --git a/tsconfig.json b/tsconfig.json index b10ee498..c7d0241d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,9 @@ "extends": "./node_modules/gts/tsconfig-google.json", "compilerOptions": { "rootDir": ".", - "outDir": "build" + "outDir": "build", + "moduleResolution": "node", + "resolveJsonModule": true }, "include": [ "src/*.ts",