Skip to content

Commit 31213b9

Browse files
committed
K_SERVICE check modified
1 parent 26f4b86 commit 31213b9

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

lib/utilization/gcp-info.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,13 @@ function fetchGCPInfo(agent, callback) {
5050
data = null
5151
}
5252

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
53+
// Determine if we are in GCP Cloud Run by checking K_SERVICE.
54+
// If K_SERVICE is not set yet, fallback to checking for the presence of machineType and name.
55+
// If both are missing, assume Cloud Run (need only id and zone).
56+
const needAllKeys = process.env.K_SERVICE
57+
? false
58+
: !!(data.machineType && data.name)
59+
5760
const results = common.getKeys(data, ['id', 'zone', 'machineType', 'name'], needAllKeys)
5861
if (!results?.id || !results?.zone) {
5962
// id and zone are required

0 commit comments

Comments
 (0)