Skip to content

Commit

Permalink
detectors/gcp: use CLOUD_RUN_TASK_INDEX
Browse files Browse the repository at this point in the history
Signed-off-by: Koichi Shiraishi <zchee.io@gmail.com>
  • Loading branch information
zchee committed Apr 10, 2023
1 parent afeb1ea commit e852ece
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 5 additions & 1 deletion detectors/gcp/faas.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package gcp

import (
"fmt"
"strings"
)

Expand All @@ -29,6 +30,7 @@ const (
faasServiceEnv = "K_SERVICE"
faasRevisionEnv = "K_REVISION"
jobsRevisionEnv = "CLOUD_RUN_EXECUTION"
jobsTaskIndexEnv = "CLOUD_RUN_TASK_INDEX"
regionMetadataAttr = "instance/region"
)

Expand Down Expand Up @@ -63,7 +65,9 @@ func (d *Detector) FaaSVersion() (string, error) {
return version, nil
}
if version, found := d.os.LookupEnv(jobsRevisionEnv); found {
return version, nil
if index, found := d.os.LookupEnv(jobsTaskIndexEnv); found {
return fmt.Sprintf("%s/%s", version, index), nil
}
}
return "", errEnvVarNotFound
}
Expand Down
5 changes: 3 additions & 2 deletions detectors/gcp/faas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,13 @@ func TestFaaSVersion(t *testing.T) {
func TestFaaSJobsVersion(t *testing.T) {
d := NewTestDetector(&FakeMetadataProvider{}, &FakeOSProvider{
Vars: map[string]string{
jobsRevisionEnv: "version-123",
jobsRevisionEnv: "version-123",
jobsTaskIndexEnv: "0",
},
})
version, err := d.FaaSVersion()
assert.NoError(t, err)
assert.Equal(t, version, "version-123")
assert.Equal(t, version, "version-123/0")
}

func TestFaaSVersionErr(t *testing.T) {
Expand Down

0 comments on commit e852ece

Please sign in to comment.