Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit 1cdca91

Browse files
jkohenrghetia
authored andcommitted
Use standard label name for location. (#241)
* Use standard label name for location. The location label is required. The resource type mappings defined in resource.go uniformly expect resourcekeys.CloudKeyZone, except the `generic_task`, but there is no good reason for that, as Stackdriver still requires a valid cloud location for `generic_task`. Therefore, use a cloud location everywhere. This makes the exporter work out-of-the-box in conjuction with `kubernetes-operator` and partially addresses census-ecosystem/kubernetes-operator#14 * Update stackdriver.go Added printfs that are useful for diagnosing resource discovery.
1 parent 59d068f commit 1cdca91

3 files changed

Lines changed: 6 additions & 4 deletions

File tree

resource.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
// Consider exposing these labels and a type identifier in the future to allow
2727
// for customization.
2828
const (
29-
stackdriverLocation = "contrib.opencensus.io/exporter/stackdriver/location"
3029
stackdriverProjectID = "contrib.opencensus.io/exporter/stackdriver/project_id"
3130
stackdriverGenericTaskNamespace = "contrib.opencensus.io/exporter/stackdriver/generic_task/namespace"
3231
stackdriverGenericTaskJob = "contrib.opencensus.io/exporter/stackdriver/generic_task/job"
@@ -74,7 +73,7 @@ var awsResourceMap = map[string]string{
7473
// Generic task resource.
7574
var genericResourceMap = map[string]string{
7675
"project_id": stackdriverProjectID,
77-
"location": stackdriverLocation,
76+
"location": resourcekeys.CloudKeyZone,
7877
"namespace": stackdriverGenericTaskNamespace,
7978
"job": stackdriverGenericTaskJob,
8079
"task_id": stackdriverGenericTaskID,

resource_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func TestDefaultMapResource(t *testing.T) {
164164
Type: "",
165165
Labels: map[string]string{
166166
stackdriverProjectID: "proj1",
167-
stackdriverLocation: "zone1",
167+
resourcekeys.CloudKeyZone: "zone1",
168168
stackdriverGenericTaskNamespace: "namespace1",
169169
stackdriverGenericTaskJob: "job1",
170170
stackdriverGenericTaskID: "task_id1",

stackdriver.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import (
6161
traceapi "cloud.google.com/go/trace/apiv2"
6262
"contrib.go.opencensus.io/exporter/stackdriver/monitoredresource"
6363
"go.opencensus.io/resource"
64+
"go.opencensus.io/resource/resourcekeys"
6465
"go.opencensus.io/stats/view"
6566
"go.opencensus.io/trace"
6667
"golang.org/x/oauth2/google"
@@ -347,12 +348,14 @@ func NewExporter(o Options) (*Exporter, error) {
347348
// Populate internal resource labels for defaulting project_id, location, and
348349
// generic resource labels of applicable monitored resources.
349350
res.Labels[stackdriverProjectID] = o.ProjectID
350-
res.Labels[stackdriverLocation] = o.Location
351+
res.Labels[resourcekeys.CloudKeyZone] = o.Location
351352
res.Labels[stackdriverGenericTaskNamespace] = "default"
352353
res.Labels[stackdriverGenericTaskJob] = path.Base(os.Args[0])
353354
res.Labels[stackdriverGenericTaskID] = getTaskValue()
355+
log.Printf("OpenCensus detected resource: %v", res)
354356

355357
o.Resource = o.MapResource(res)
358+
log.Printf("OpenCensus using monitored resource: %v", o.Resource)
356359
}
357360
if o.MetricPrefix != "" && !strings.HasSuffix(o.MetricPrefix, "/") {
358361
o.MetricPrefix = o.MetricPrefix + "/"

0 commit comments

Comments
 (0)