Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add language to profile labels #196

Merged
merged 1 commit into from May 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions ts/src/profiler.ts
Expand Up @@ -213,7 +213,7 @@ function responseToProfileOrError(
*/
export class Profiler extends ServiceObject {
private logger: Logger;
private profileLabels: {instance?: string};
private profileLabels: {instance?: string, language: string};
private deployment: Deployment;
private profileTypes: string[];
private retryer: Retryer;
Expand Down Expand Up @@ -250,7 +250,7 @@ export class Profiler extends ServiceObject {
labels
};

this.profileLabels = {};
this.profileLabels = {language: 'nodejs'};
if (this.config.instance) {
this.profileLabels.instance = this.config.instance;
}
Expand Down
66 changes: 22 additions & 44 deletions ts/test/test-profiler.ts
Expand Up @@ -293,6 +293,28 @@ describe('Profiler', () => {
uploaded.profileBytes = undefined;
assert.deepEqual(uploaded, requestProf);
});
it('should specify language is nodejs when uploading profile', async () => {
const config = extend(true, {}, testConfig);
const requestProf = {
name: 'projects/12345678901/test-projectId',
duration: '10s',
profileType: 'HEAP',
labels: {instance: 'test-instance'}
};
requestStub =
sinon.stub(common.ServiceObject.prototype, 'request')
.onCall(0)
.callsArgWith(1, undefined, undefined, {statusCode: 200});

const profiler = new Profiler(testConfig);
profiler.timeProfiler = instance(mockTimeProfiler);
await profiler.profileAndUpload(requestProf);
const gotUploadedProfile = requestStub.args[0][0];
assert.equal(
gotUploadedProfile.body.labels.language, 'nodejs',
`uploaded profile ${
gotUploadedProfile} does not specify language is nodejs`);
});
it('should send request to upload heap profile.', async () => {
const requestProf = {
name: 'projects/12345678901/test-projectId',
Expand Down Expand Up @@ -627,12 +649,6 @@ describe('Profiler', () => {
' and backoff specified',
async () => {
const config = extend(true, {}, testConfig);
const requestProfileResponseBody = {
name: 'projects/12345678901/test-projectId',
profileType: 'WALL',
duration: '10s',
labels: {version: config.serviceContext.version}
};
requestStub = sinon.stub(common.ServiceObject.prototype, 'request')
.onCall(0)
.callsArgWith(1, undefined, undefined, {
Expand All @@ -650,12 +666,6 @@ describe('Profiler', () => {
});
it('should throw error when response undefined', async () => {
const config = extend(true, {}, testConfig);
const requestProfileResponseBody = {
name: 'projects/12345678901/test-projectId',
profileType: 'WALL',
duration: '10s',
labels: {version: config.serviceContext.version}
};
requestStub = sinon.stub(common.ServiceObject.prototype, 'request')
.onCall(0)
.callsArgWith(1, undefined, undefined, {status: 200});
Expand Down Expand Up @@ -703,7 +713,6 @@ describe('Profiler', () => {
.onCall(1)
.callsArgWith(1, undefined, undefined, {statusCode: 200});


const profiler = new Profiler(testConfig);
profiler.timeProfiler = instance(mockTimeProfiler);
const delayMillis = await profiler.collectProfile();
Expand All @@ -714,12 +723,6 @@ describe('Profiler', () => {
' indicated',
async () => {
const config = extend(true, {}, testConfig);
const requestProfileResponseBody = {
name: 'projects/12345678901/test-projectId',
profileType: 'WALL',
duration: '10s',
labels: {version: config.serviceContext.version}
};
requestStub =
sinon.stub(common.ServiceObject.prototype, 'request')
.onCall(0)
Expand All @@ -732,13 +735,6 @@ describe('Profiler', () => {
});
it('should reset backoff after success', async () => {
const config = extend(true, {}, testConfig);
const requestProfileResponseBody = {
name: 'projects/12345678901/test-projectId',
profileType: 'WALL',
duration: '10s',
labels: {instance: config.instance}
};

const createProfileResponseBody = {
name: 'projects/12345678901/test-projectId',
profileType: 'WALL',
Expand Down Expand Up @@ -786,12 +782,6 @@ describe('Profiler', () => {
' specified',
async () => {
const config = extend(true, {}, testConfig);
const requestProfileResponseBody = {
name: 'projects/12345678901/test-projectId',
profileType: 'WALL',
duration: '10s',
labels: {instance: config.instance}
};
requestStub = sinon.stub(common.ServiceObject.prototype, 'request')
.onCall(0)
.callsArgWith(1, undefined, undefined, {
Expand All @@ -807,12 +797,6 @@ describe('Profiler', () => {
' specified',
async () => {
const config = extend(true, {}, testConfig);
const requestProfileResponseBody = {
name: 'projects/12345678901/test-projectId',
profileType: 'WALL',
duration: '10s',
labels: {instance: config.instance}
};
requestStub = sinon.stub(common.ServiceObject.prototype, 'request')
.onCall(0)
.callsArgWith(1, undefined, undefined, {
Expand All @@ -828,12 +812,6 @@ describe('Profiler', () => {
'then backoff limit',
async () => {
const config = extend(true, {}, testConfig);
const requestProfileResponseBody = {
name: 'projects/12345678901/test-projectId',
profileType: 'WALL',
duration: '10s',
labels: {version: config.serviceContext.version}
};
requestStub =
sinon.stub(common.ServiceObject.prototype, 'request')
.onCall(0)
Expand Down