Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit 66073ac

Browse files
authored
chore: upgrade gcp-metadata to ^3.0.0 (#709)
* chore: upgrade gcp_metadata to ^3.0.0 * build fix: attempt 1 * build fix: attempt 2
1 parent 04888d2 commit 66073ac

File tree

4 files changed

+56
-11
lines changed

4 files changed

+56
-11
lines changed

packages/opencensus-exporter-stackdriver/test/nocks.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const HEADERS = {
2626
};
2727

2828
const HOST_ADDRESS = 'http://metadata.google.internal.';
29+
const SECONDARY_HOST_ADDRESS = 'http://169.254.169.254';
2930

3031
export function oauth2<T extends {} = {}>(
3132
validator?: (body: T) => boolean
@@ -61,6 +62,10 @@ export function noDetectResource() {
6162
.get('/computeMetadata/v1/instance')
6263
.once()
6364
.replyWithError({ code: 'ENOTFOUND' }),
65+
nock(SECONDARY_HOST_ADDRESS)
66+
.get('/computeMetadata/v1/instance')
67+
.once()
68+
.replyWithError({ code: 'ENOTFOUND' }),
6469
nock('http://169.254.169.254/latest/dynamic/instance-identity/document')
6570
.get('')
6671
.replyWithError({ code: 'ENOTFOUND' }),

packages/opencensus-resource-util/package-lock.json

Lines changed: 33 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/opencensus-resource-util/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@
6363
},
6464
"dependencies": {
6565
"@opencensus/core": "^0.0.18",
66-
"gcp-metadata": "^2.0.0"
66+
"gcp-metadata": "^3.0.0"
6767
}
6868
}

packages/opencensus-resource-util/test/test-detect-resource.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
HEADER_NAME,
2121
HEADER_VALUE,
2222
HOST_ADDRESS,
23+
SECONDARY_HOST_ADDRESS,
2324
} from 'gcp-metadata';
2425
import * as nock from 'nock';
2526
import * as resource from '../src';
@@ -164,7 +165,11 @@ describe('detectResource', () => {
164165
.reply(200, () => 'project/zone/my-zone', HEADERS)
165166
.get(INSTANCE_ID_PATH)
166167
.reply(200, () => 4520031799277581759, HEADERS);
168+
const scope1 = nock(SECONDARY_HOST_ADDRESS)
169+
.get(INSTANCE_PATH)
170+
.reply(200, {}, HEADERS);
167171
const { type, labels } = await resource.detectResource();
172+
scope1.done();
168173
scope.done();
169174

170175
assert.deepStrictEqual(type, resource.GCP_GCE_INSTANCE_TYPE);
@@ -177,7 +182,6 @@ describe('detectResource', () => {
177182
it('should retry if the initial request fails', async () => {
178183
const scope = nock(HOST_ADDRESS)
179184
.get(INSTANCE_PATH)
180-
.times(2)
181185
.reply(500)
182186
.get(INSTANCE_PATH)
183187
.reply(200, {}, HEADERS)
@@ -187,7 +191,11 @@ describe('detectResource', () => {
187191
.reply(200, () => 'project/zone/my-zone', HEADERS)
188192
.get(INSTANCE_ID_PATH)
189193
.reply(200, () => 4520031799277581759, HEADERS);
194+
const secondaryScope = nock(SECONDARY_HOST_ADDRESS)
195+
.get(INSTANCE_PATH)
196+
.reply(200, {}, HEADERS);
190197
const { type, labels } = await resource.detectResource();
198+
secondaryScope.done();
191199
scope.done();
192200

193201
assert.deepStrictEqual(type, resource.GCP_GCE_INSTANCE_TYPE);
@@ -207,7 +215,11 @@ describe('detectResource', () => {
207215
.reply(413)
208216
.get(INSTANCE_ID_PATH)
209217
.reply(400, undefined, HEADERS);
218+
const secondaryScope = nock(SECONDARY_HOST_ADDRESS)
219+
.get(INSTANCE_PATH)
220+
.reply(200, {}, HEADERS);
210221
const { type, labels } = await resource.detectResource();
222+
secondaryScope.done();
211223
scope.done();
212224

213225
assert.deepStrictEqual(type, resource.GCP_GCE_INSTANCE_TYPE);
@@ -226,7 +238,6 @@ describe('detectResource', () => {
226238
process.env.OC_RESOURCE_TYPE = 'global';
227239
process.env.OC_RESOURCE_LABELS = 'cloud.zone=zone1,user=user1,version=1.0';
228240
CoreResource.setup();
229-
230241
const scope = nock(HOST_ADDRESS)
231242
.get(INSTANCE_PATH)
232243
.reply(200, {}, HEADERS)
@@ -236,7 +247,11 @@ describe('detectResource', () => {
236247
.reply(200, () => 'project/zone/my-zone', HEADERS)
237248
.get(INSTANCE_ID_PATH)
238249
.reply(200, () => 4520031799277581759, HEADERS);
250+
const secondaryScope = nock(SECONDARY_HOST_ADDRESS)
251+
.get(INSTANCE_PATH)
252+
.reply(200, {}, HEADERS);
239253
const { type, labels } = await resource.detectResource();
254+
secondaryScope.done();
240255
scope.done();
241256

242257
assert.deepStrictEqual(type, 'global');

0 commit comments

Comments
 (0)