diff --git a/ts/src/profiler.ts b/ts/src/profiler.ts index bd930e3c..c9f0cc34 100644 --- a/ts/src/profiler.ts +++ b/ts/src/profiler.ts @@ -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; @@ -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; } diff --git a/ts/test/test-profiler.ts b/ts/test/test-profiler.ts index 4def4157..2a288e2c 100644 --- a/ts/test/test-profiler.ts +++ b/ts/test/test-profiler.ts @@ -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', @@ -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, { @@ -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}); @@ -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(); @@ -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) @@ -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', @@ -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, { @@ -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, { @@ -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)