Skip to content

Commit 26f4b86

Browse files
committed
don't modify cross agent tests
1 parent 3281245 commit 26f4b86

File tree

4 files changed

+19
-52
lines changed

4 files changed

+19
-52
lines changed

lib/collector/facts.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ async function facts(agent, callback, { logger = defaultLogger } = {}) {
3333

3434
let hostname = agent.config.getHostnameSafe()
3535
if (agent.config.gcp_cloud_run.use_instance_as_host && process.env.K_SERVICE) {
36+
// K_SERVICE is the name of the service in GCP Cloud Run
3637
hostname = systemInfo.vendors?.gcp?.id
3738
}
3839
const results = {

lib/utilization/gcp-info.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ function fetchGCPInfo(agent, callback) {
5050
data = null
5151
}
5252

53-
// Most GCP services have id, zone, machineType, name
54-
// GCP Cloud Run only has id and zone
55-
const results = common.getKeys(data, ['id', 'zone', 'machineType', 'name'], false)
53+
// Most GCP services have id, zone, machineType, and name,
54+
// but GCP Cloud Run only has id and zone.
55+
// If K_SERVICE is set, we are in GCP Cloud Run.
56+
const needAllKeys = !process.env.K_SERVICE
57+
const results = common.getKeys(data, ['id', 'zone', 'machineType', 'name'], needAllKeys)
5658
if (!results?.id || !results?.zone) {
5759
// id and zone are required
5860
logger.debug({ utilization: 'gcp' }, 'GCP metadata was invalid.')

test/lib/cross_agent_tests/utilization/utilization_json.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@
211211
"input_hostname": "myotherhost",
212212
"input_full_hostname": "myotherhost.com",
213213
"input_ip_address": ["1.2.3.4"],
214-
"input_gcp_id": null,
214+
"input_gcp_id": "3161347020215157123",
215215
"input_gcp_type": "projects/492690098729/machineTypes/custom-1-1024",
216216
"input_gcp_name": null,
217217
"input_gcp_zone": "projects/492690098729/zones/us-central1-c",

test/lib/cross_agent_tests/utilization_vendor_specific/gcp.json

Lines changed: 12 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,10 @@
5454
"timeout": false
5555
}
5656
},
57-
"expected_vendors_hash": {
58-
"gcp": {
59-
"id": "3161347020215157123",
60-
"name": "aef-default-20170501t160547-7gh8",
61-
"zone": "us-central1-c"
62-
}
63-
},
57+
"expected_vendors_hash": null,
6458
"expected_metrics": {
6559
"Supportability/utilization/gcp/error": {
66-
"call_count": 0
60+
"call_count": 1
6761
}
6862
}
6963
},
@@ -80,16 +74,10 @@
8074
"timeout": false
8175
}
8276
},
83-
"expected_vendors_hash": {
84-
"gcp": {
85-
"id": "3161347020215157123",
86-
"name": "aef-default-20170501t160547-7gh8",
87-
"zone": "us-central1-c"
88-
}
89-
},
77+
"expected_vendors_hash": null,
9078
"expected_metrics": {
9179
"Supportability/utilization/gcp/error": {
92-
"call_count": 0
80+
"call_count": 1
9381
}
9482
}
9583
},
@@ -186,16 +174,10 @@
186174
"timeout": false
187175
}
188176
},
189-
"expected_vendors_hash": {
190-
"gcp": {
191-
"id": "3161347020215157123",
192-
"machineType": "custom-1-1024",
193-
"zone": "us-central1-c"
194-
}
195-
},
177+
"expected_vendors_hash": null,
196178
"expected_metrics": {
197179
"Supportability/utilization/gcp/error": {
198-
"call_count": 0
180+
"call_count": 1
199181
}
200182
}
201183
},
@@ -212,16 +194,10 @@
212194
"timeout": false
213195
}
214196
},
215-
"expected_vendors_hash": {
216-
"gcp": {
217-
"id": "3161347020215157123",
218-
"machineType": "custom-1-1024",
219-
"zone": "us-central1-c"
220-
}
221-
},
197+
"expected_vendors_hash": null,
222198
"expected_metrics": {
223199
"Supportability/utilization/gcp/error": {
224-
"call_count": 0
200+
"call_count": 1
225201
}
226202
}
227203
},
@@ -260,16 +236,10 @@
260236
"timeout": false
261237
}
262238
},
263-
"expected_vendors_hash": {
264-
"gcp": {
265-
"id": "3161347020215157123",
266-
"machineType": "custom-1-1024",
267-
"zone": "us-central1-c"
268-
}
269-
},
239+
"expected_vendors_hash": null,
270240
"expected_metrics": {
271241
"Supportability/utilization/gcp/error": {
272-
"call_count": 0
242+
"call_count": 1
273243
}
274244
}
275245
},
@@ -286,16 +256,10 @@
286256
"timeout": false
287257
}
288258
},
289-
"expected_vendors_hash": {
290-
"gcp": {
291-
"id": "3161347020215157123",
292-
"machineType": "custom-1-1024",
293-
"zone": "us-central1-c"
294-
}
295-
},
259+
"expected_vendors_hash": null,
296260
"expected_metrics": {
297261
"Supportability/utilization/gcp/error": {
298-
"call_count": 0
262+
"call_count": 1
299263
}
300264
}
301265
},

0 commit comments

Comments
 (0)