Skip to content

Commit

Permalink
Hardcode service.namespace label to cloud-run-managed per review
Browse files Browse the repository at this point in the history
discussion.
  • Loading branch information
yegle committed Nov 24, 2020
1 parent 9fcd4bd commit caefa6a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion detectors/gcp/cloud-run.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"go.opentelemetry.io/otel/semconv"
)

const serviceNamespace = "cloud-run-managed"

type metadataClient interface {
ProjectID() (string, error)
Get(string) (string, error)
Expand Down Expand Up @@ -60,6 +62,9 @@ func (c *CloudRun) setupForTest(mc metadataClient, ongce func() bool, getenv fun
}

// Detect detects associated resources when running on Cloud Run hosts.
// NOTE: the service.namespace label is currently hardcoded to be
// "cloud-run-managed". This may change in the future, please do not rely on
// this behavior yet.
func (c *CloudRun) Detect(ctx context.Context) (*resource.Resource, error) {
// .OnGCE is actually testing whether the metadata server is available.
// Metadata server is supported on Cloud Run.
Expand Down Expand Up @@ -99,7 +104,7 @@ func (c *CloudRun) Detect(ctx context.Context) (*resource.Resource, error) {
errInfo = append(errInfo, "envvar K_SERVICE contains empty string.")
} else {
labels = append(labels,
semconv.ServiceNamespaceKey.String(service),
semconv.ServiceNamespaceKey.String(serviceNamespace),
semconv.ServiceNameKey.String(service),
)
}
Expand Down
2 changes: 1 addition & 1 deletion detectors/gcp/cloud-run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func TestCloudRunDetectorExpectSuccess(t *testing.T) {
label.String("cloud.region", "utopia"),
label.String("service.instance.id", "bar"),
label.String("service.name", "x-service"),
label.String("service.namespace", "x-service"),
label.String("service.namespace", "cloud-run-managed"),
)
c := NewCloudRun()
c.setupForTest(&client{m: metadata}, onGCE, getenv(envvars))
Expand Down

0 comments on commit caefa6a

Please sign in to comment.