Skip to content

Commit

Permalink
googlecloudexporter: handle cloud.availability_zone semconv (#2893)
Browse files Browse the repository at this point in the history
  • Loading branch information
punya authored Mar 26, 2021
1 parent bc3a4cd commit 6011461
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
7 changes: 7 additions & 0 deletions exporter/googlecloudexporter/resource_mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ func (mr *resourceMapper) mapResource(res *resource.Resource) *monitoredrespb.Mo
return result
}

// cloud.zone was renamed to cloud.availability_zone in the semantic conventions.
// Accept either, for backwards compatibility.
availabilityZone, ok := res.Labels["cloud.availability_zone"]
if ok {
res.Labels["cloud.zone"] = availabilityZone
}

// Keep original behavior by default
return stackdriver.DefaultMapResource(res)
}
Expand Down
28 changes: 25 additions & 3 deletions exporter/googlecloudexporter/resource_mapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,38 @@ func TestResourceMapper(t *testing.T) {
Type: "source.resource3",
Labels: map[string]string{
"source.label1": "value1", // unknown label is dropped
"contrib.opencensus.io/exporter/stackdriver/project_id": "123",
"cloud.availability_zone": "zone1",
"contrib.opencensus.io/exporter/stackdriver/generic_task/namespace": "ns1",
"contrib.opencensus.io/exporter/stackdriver/generic_task/job": "job1",
"contrib.opencensus.io/exporter/stackdriver/generic_task/task_id": "task1",
},
},
// Resource without matching config should be converted via default implementation
wantResource: &monitoredres.MonitoredResource{
Type: "global",
// All labels are transformed by default function
Labels: map[string]string{
"project_id": "123",
"location": "zone1",
"namespace": "ns1",
"job": "job1",
"task_id": "task1",
},
},
},
{
name: "Handle cloud.zone for backcompat",
sourceResource: &resource.Resource{
Type: "source.resource3",
Labels: map[string]string{
"contrib.opencensus.io/exporter/stackdriver/project_id": "123",
// TODO: Change this to use `cloud.availability_zone` as per semantic conventions.
// Changes are required in dependency package.
"cloud.zone": "zone1",
"contrib.opencensus.io/exporter/stackdriver/generic_task/namespace": "ns1",
"contrib.opencensus.io/exporter/stackdriver/generic_task/job": "job1",
"contrib.opencensus.io/exporter/stackdriver/generic_task/task_id": "task1",
},
},
// Resource without matching config should be converted via default implementation
wantResource: &monitoredres.MonitoredResource{
Type: "global",
// All labels are transformed by default function
Expand Down

0 comments on commit 6011461

Please sign in to comment.