internal/dcensus: on GKE, export metrics to k8s_container resource
Use the appropriate resource for metrics when running on Kubernetes.
Trust: Jonathan Amsterdam
Run-TryBot: Jonathan Amsterdam
TryBot-Result: kokoro
@@ -153,9 +153,7 @@ func NewViewExporter(cfg *config.Config) (_ *stackdriver.Exporter, err error) {
// timeseries problems. Note that generic_task is used because the
// gae_instance resource type is not supported for metrics:
// https://cloud.google.com/monitoring/custom-metrics/creating-metrics#which-resource
- return stackdriver.NewExporter(stackdriver.Options{
- ProjectID: cfg.ProjectID,
- MonitoredResource: &monitoredResource{
+ mr := &monitoredResource{
Type: "generic_task",
Labels: map[string]string{
"project_id": cfg.ProjectID,
@@ -164,7 +162,13 @@ func NewViewExporter(cfg *config.Config) (_ *stackdriver.Exporter, err error) {
"namespace": "go-discovery",
"task_id": cfg.InstanceID,
},
- },
+ }
+ if cfg.OnGKE() {
+ mr = (*monitoredResource)(cfg.MonitoredResource)
+ }
+ return stackdriver.NewExporter(stackdriver.Options{
+ ProjectID: cfg.ProjectID,
+ MonitoredResource: mr,
DefaultMonitoringLabels: stackdriverLabels(cfg),
})
}
