feat: add x-goog-api-client headers for retry metrics#1920
feat: add x-goog-api-client headers for retry metrics#1920ddelgrosso1 merged 5 commits intogoogleapis:mainfrom
Conversation
| import {Readable, Writable} from 'stream'; | ||
| import retry = require('async-retry'); | ||
| import {RetryOptions, PreconditionOptions} from './storage'; | ||
| import * as packageJson from '../package.json'; |
There was a problem hiding this comment.
I didn't catch this line during our pairing, but I believe this may break package.json#files for consumers (via npm i @google-cloud/storage) as build/package.json wouldn't be included [npm docs].
We currently use this pattern for including package.json (a little messy):
Lines 617 to 625 in cbe2590
We have a few options:
- Perhaps we can add
build/package.jsontopackage.json#files. Drawback: some tooling may believebuildin itself is a separate package (aspackage.json) and may misbehave. - We can use the pattern found in
src/storage. Drawback: messy-looking.
CC: @bcoe - as I'm working on an easy package.json import proposal for Node.js.
| const CHUNK_SIZE_MULTIPLE = 2 ** 18; | ||
| const queryPath = '/?userProject=user-project-id'; | ||
| const X_GOOG_API_HEADER_REGEX = | ||
| /^gl-node\/[0-9]+\.[0-9]+\.[-.\w]+ gccl\/[0-9]+\.[0-9]+\.[-.\w]+ gccl-invocation-id\/[\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12}$/; |
There was a problem hiding this comment.
The gl-node/... and gccl/... portions may not match for tagged semver preview/beta releases.
Here's a suggestion:
| /^gl-node\/[0-9]+\.[0-9]+\.[-.\w]+ gccl\/[0-9]+\.[0-9]+\.[-.\w]+ gccl-invocation-id\/[\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12}$/; | |
| /^gl-node\/(?<nodeVersion>[^W]+) gccl\/(?<gccl>[^W]+) gccl-invocation-id\/(?<gcclInvocationId>[^W]+)$/ |
Which will allow easy access to named groups for testing:
const match = X_GOOG_API_HEADER_REGEX.exec(...);
assert(match);
// match.groups.nodeVersion
// match.groups.gccl
// match.groups.gcclInvocationIdThere was a problem hiding this comment.
^this suggestion is optional
| data: metadata, | ||
| headers: {}, | ||
| headers: { | ||
| 'x-goog-api-client': `gl-node/${process.versions.node} gccl/${packageJson.version} gccl-invocation-id/${this.currentInvocationId.uri}`, |
There was a problem hiding this comment.
Just to clarify-- I spoke with @frankyn and he mentioned that each request in a resumable upload should have its own invocation id (unless it is a retry of a request that failed). Is that reflective of what's happening here?
(Looks like it is from the test cases, but wanted to double check)
There was a problem hiding this comment.
Correct, that is what is happening here. The invocation ID is only changed after a successful response. If a failure case is hit the same ID will be used on the retry. Each request (create a URI, send a chunk, etc...) all utilize a new ID.
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
Fixes #<issue_number_goes_here> 🦕