@google-cloud/profiler
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -30,2 +30,3 @@ "use strict"; | ||
const gcpMetadata = require("gcp-metadata"); | ||
const pprof_1 = require("pprof"); | ||
const semver = require("semver"); | ||
@@ -35,3 +36,2 @@ const config_1 = require("./config"); | ||
const profiler_1 = require("./profiler"); | ||
const heapProfiler = require("./profilers/heap-profiler"); | ||
const pjson = require('../../package.json'); | ||
@@ -62,4 +62,4 @@ const serviceRegex = /^[a-z]([-a-z0-9_.]{0,253}[a-z0-9])?$/; | ||
serviceContext: { | ||
service: process.env.GAE_SERVICE, | ||
version: process.env.GAE_VERSION, | ||
service: process.env.GAE_SERVICE || process.env.K_SERVICE, | ||
version: process.env.GAE_VERSION || process.env.K_REVISION, | ||
} | ||
@@ -163,3 +163,3 @@ }; | ||
if (!profilerConfig.disableHeap) { | ||
heapProfiler.start(profilerConfig.heapIntervalBytes, profilerConfig.heapMaxStackDepth); | ||
pprof_1.heap.start(profilerConfig.heapIntervalBytes, profilerConfig.heapMaxStackDepth); | ||
} | ||
@@ -166,0 +166,0 @@ profilerConfig = yield initConfigMetadata(profilerConfig); |
@@ -18,3 +18,2 @@ /** | ||
import { ProfilerConfig } from './config'; | ||
import { TimeProfiler } from './profilers/time-profiler'; | ||
/** | ||
@@ -88,3 +87,2 @@ * Interface for deployment field of RequestProfile. Profiles with matching | ||
private sourceMapper; | ||
timeProfiler: TimeProfiler | undefined; | ||
config: ProfilerConfig; | ||
@@ -91,0 +89,0 @@ constructor(config: ProfilerConfig); |
@@ -28,2 +28,3 @@ "use strict"; | ||
const pify = require("pify"); | ||
const pprof_1 = require("pprof"); | ||
const msToStr = require("pretty-ms"); | ||
@@ -34,5 +35,2 @@ const teeny_request_1 = require("teeny-request"); | ||
const logger_1 = require("./logger"); | ||
const heapProfiler = require("./profilers/heap-profiler"); | ||
const time_profiler_1 = require("./profilers/time-profiler"); | ||
const sourcemapper_1 = require("./sourcemapper/sourcemapper"); | ||
const parseDuration = require('parse-duration'); | ||
@@ -73,11 +71,15 @@ const pjson = require('../../package.json'); | ||
*/ | ||
function getServerResponseBackoff(response, err) { | ||
// The response currently does not have field containing the server-specified | ||
// backoff. As a workaround, response body's message is parsed to get the | ||
// backoff. | ||
// TODO (issue #250): Remove this workaround and get the retry delay from | ||
// body.error.details. | ||
const message = getResponseErrorMessage(response, err); | ||
if (message) { | ||
return parseBackoffDuration(message); | ||
function getServerResponseBackoff(body) { | ||
// tslint:disable-next-line: no-any | ||
const b = body; | ||
if (b.error && b.error.details && Array.isArray(b.error.details)) { | ||
for (const item of b.error.details) { | ||
if (typeof item === 'object' && item.retryDelay && | ||
typeof item.retryDelay === 'string') { | ||
const backoffMillis = parseDuration(item.retryDelay); | ||
if (backoffMillis > 0) { | ||
return backoffMillis; | ||
} | ||
} | ||
} | ||
} | ||
@@ -192,7 +194,9 @@ return undefined; | ||
const message = getResponseErrorMessage(response, err); | ||
const delayMillis = getServerResponseBackoff(response, err); | ||
if (delayMillis) { | ||
throw new BackoffResponseError(message, delayMillis); | ||
if (body) { | ||
const delayMillis = getServerResponseBackoff(body); | ||
if (delayMillis) { | ||
throw new BackoffResponseError(message, delayMillis); | ||
} | ||
} | ||
throw new Error(response.statusMessage); | ||
throw new Error(message); | ||
} | ||
@@ -251,3 +255,2 @@ if (err) { | ||
this.profileTypes.push(ProfileTypes.Wall); | ||
this.timeProfiler = new time_profiler_1.TimeProfiler(this.config.timeIntervalMicros); | ||
} | ||
@@ -274,7 +277,7 @@ if (!this.config.disableHeap) { | ||
this.sourceMapper = | ||
yield sourcemapper_1.create(this.config.sourceMapSearchPath); | ||
yield pprof_1.SourceMapper.create(this.config.sourceMapSearchPath); | ||
} | ||
catch (err) { | ||
this.logger.error(`Failed to initialize source maps and start profiler: ${err}`); | ||
return; | ||
this.logger.error(`Failed to initialize SourceMapper. Source map support has been disabled: ${err}`); | ||
this.config.disableSourceMaps = true; | ||
} | ||
@@ -440,3 +443,3 @@ } | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!this.timeProfiler) { | ||
if (this.config.disableTime) { | ||
throw Error('Cannot collect time profile, time profiler not enabled.'); | ||
@@ -452,3 +455,8 @@ } | ||
} | ||
const p = yield this.timeProfiler.profile(durationMillis, this.sourceMapper); | ||
const options = { | ||
durationMillis, | ||
intervalMicros: this.config.timeIntervalMicros, | ||
sourceMapper: this.sourceMapper | ||
}; | ||
const p = yield pprof_1.time.profile(options); | ||
prof.profileBytes = yield profileBytes(p); | ||
@@ -469,3 +477,3 @@ return prof; | ||
} | ||
const p = heapProfiler.profile(this.config.ignoreHeapSamplesPath, this.sourceMapper); | ||
const p = pprof_1.heap.profile(this.config.ignoreHeapSamplesPath, this.sourceMapper); | ||
prof.profileBytes = yield profileBytes(p); | ||
@@ -472,0 +480,0 @@ return prof; |
{ | ||
"name": "@google-cloud/profiler", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Adds support for Stackdriver Profiler to Node.js applications", | ||
@@ -9,3 +9,2 @@ "repository": "googleapis/cloud-profiler-nodejs", | ||
"scripts": { | ||
"install": "node-pre-gyp install --fallback-to-build", | ||
"test": "nyc mocha out/test/test-*.js", | ||
@@ -25,3 +24,2 @@ "system-test": "nyc --no-clean mocha out/system-test/test-*.js --timeout=60000", | ||
"proto": "npm run proto:profile && npm run proto:profiler", | ||
"proto:profile": "mkdir -p proto && pbjs -t static-module -w commonjs -o proto/profile.js third_party/proto/profile.proto && pbts -o proto/profile.d.ts proto/profile.js", | ||
"proto:profiler": "mkdir -p proto && pbjs -t static-module -w commonjs -o proto/profiler.js third_party/googleapis/google/devtools/cloudprofiler/v2/profiler.proto && pbts -o proto/profiler.d.ts proto/profiler.js", | ||
@@ -47,7 +45,6 @@ "license-check": "jsgl --local .", | ||
"lodash.pickby": "^4.6.0", | ||
"nan": "^2.12.1", | ||
"node-pre-gyp": "^0.12.0", | ||
"p-limit": "^2.0.0", | ||
"parse-duration": "^0.1.1", | ||
"pify": "^4.0.0", | ||
"pprof": "^0.1.0", | ||
"pretty-ms": "^4.0.0", | ||
@@ -84,3 +81,2 @@ "protobufjs": "~6.8.6", | ||
"tmp": "0.0.33", | ||
"ts-mockito": "^2.2.5", | ||
"typescript": "~3.3.0", | ||
@@ -94,3 +90,2 @@ "linkinator": "^1.1.2" | ||
"proto", | ||
"binding.gyp", | ||
"package-lock.json", | ||
@@ -109,10 +104,3 @@ "package.json", | ||
"node": ">=6.12.3 <8.0.0 || >=8.9.4 <10.0.0 || >=10.4.1" | ||
}, | ||
"binary": { | ||
"module_name": "google_cloud_profiler", | ||
"module_path": "./build/{node_abi}-{platform}-{arch}-{libc}", | ||
"host": "https://storage.googleapis.com/cloud-profiler/nodejs/release", | ||
"remote_path": "v{version}", | ||
"package_name": "{node_abi}-{platform}-{arch}-{libc}.tar.gz" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code which could be a vector to obscure malicious code, and generally decrease the likelihood of reproducible or reliable installs.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
20
25
0
10
1
1207778
24
23928
+ Addedpprof@^0.1.0
+ Addedpprof@0.1.0(transitive)
- Removednan@^2.12.1
- Removednode-pre-gyp@^0.12.0