Skip to content

Commit

Permalink
chore: add language to profile labels (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
nolanmar511 authored May 11, 2018
1 parent 595fdc0 commit a7b4828
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 46 deletions.
4 changes: 2 additions & 2 deletions ts/src/profiler.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit a7b4828

Please sign in to comment.