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

Commit

Permalink
Use standard label name for location. (#241)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
jkohen authored and rghetia committed Dec 3, 2019
1 parent 59d068f commit 1cdca91
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
3 changes: 1 addition & 2 deletions resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
// Consider exposing these labels and a type identifier in the future to allow
// for customization.
const (
stackdriverLocation = "contrib.opencensus.io/exporter/stackdriver/location"
stackdriverProjectID = "contrib.opencensus.io/exporter/stackdriver/project_id"
stackdriverGenericTaskNamespace = "contrib.opencensus.io/exporter/stackdriver/generic_task/namespace"
stackdriverGenericTaskJob = "contrib.opencensus.io/exporter/stackdriver/generic_task/job"
Expand Down Expand Up @@ -74,7 +73,7 @@ var awsResourceMap = map[string]string{
// Generic task resource.
var genericResourceMap = map[string]string{
"project_id": stackdriverProjectID,
"location": stackdriverLocation,
"location": resourcekeys.CloudKeyZone,
"namespace": stackdriverGenericTaskNamespace,
"job": stackdriverGenericTaskJob,
"task_id": stackdriverGenericTaskID,
Expand Down
2 changes: 1 addition & 1 deletion resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func TestDefaultMapResource(t *testing.T) {
Type: "",
Labels: map[string]string{
stackdriverProjectID: "proj1",
stackdriverLocation: "zone1",
resourcekeys.CloudKeyZone: "zone1",
stackdriverGenericTaskNamespace: "namespace1",
stackdriverGenericTaskJob: "job1",
stackdriverGenericTaskID: "task_id1",
Expand Down
5 changes: 4 additions & 1 deletion stackdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import (
traceapi "cloud.google.com/go/trace/apiv2"
"contrib.go.opencensus.io/exporter/stackdriver/monitoredresource"
"go.opencensus.io/resource"
"go.opencensus.io/resource/resourcekeys"
"go.opencensus.io/stats/view"
"go.opencensus.io/trace"
"golang.org/x/oauth2/google"
Expand Down Expand Up @@ -347,12 +348,14 @@ func NewExporter(o Options) (*Exporter, error) {
// Populate internal resource labels for defaulting project_id, location, and
// generic resource labels of applicable monitored resources.
res.Labels[stackdriverProjectID] = o.ProjectID
res.Labels[stackdriverLocation] = o.Location
res.Labels[resourcekeys.CloudKeyZone] = o.Location
res.Labels[stackdriverGenericTaskNamespace] = "default"
res.Labels[stackdriverGenericTaskJob] = path.Base(os.Args[0])
res.Labels[stackdriverGenericTaskID] = getTaskValue()
log.Printf("OpenCensus detected resource: %v", res)

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

0 comments on commit 1cdca91

Please sign in to comment.