@@ -46,8 +46,9 @@ const (
4646
4747type StackdriverSink struct {
4848 project string
49- cluster string
50- zone string
49+ clusterName string
50+ clusterLocation string
51+ heapsterZone string
5152 stackdriverClient * sd_api.MetricClient
5253 minInterval time.Duration
5354 lastExportTime time.Time
@@ -329,6 +330,8 @@ func CreateStackdriverSink(uri *url.URL) (core.DataSink, error) {
329330 cluster_name := ""
330331 if len (opts ["cluster_name" ]) >= 1 {
331332 cluster_name = opts ["cluster_name" ][0 ]
333+ } else {
334+ glog .Warning ("Cluster name required but not provided, using empty cluster name." )
332335 }
333336
334337 minInterval := time .Nanosecond
@@ -365,12 +368,19 @@ func CreateStackdriverSink(uri *url.URL) (core.DataSink, error) {
365368 return nil , err
366369 }
367370
368- // Detect zone
369- zone , err := gce .Zone ()
371+ // Detect zone for old resource model
372+ heapsterZone , err := gce .Zone ()
370373 if err != nil {
371374 return nil , err
372375 }
373376
377+ clusterLocation := heapsterZone
378+ if len (opts ["cluster_location" ]) >= 1 {
379+ clusterLocation = opts ["cluster_location" ][0 ]
380+ } else if useNewResourceModel {
381+ glog .Warning ("Cluster location required with new resource model but not provided. Falling back to the zone where Heapster runs." )
382+ }
383+
374384 // Create Metric Client
375385 stackdriverClient , err := sd_api .NewMetricClient (context .Background ())
376386 if err != nil {
@@ -379,8 +389,9 @@ func CreateStackdriverSink(uri *url.URL) (core.DataSink, error) {
379389
380390 sink := & StackdriverSink {
381391 project : projectId ,
382- cluster : cluster_name ,
383- zone : zone ,
392+ clusterName : cluster_name ,
393+ clusterLocation : clusterLocation ,
394+ heapsterZone : heapsterZone ,
384395 stackdriverClient : stackdriverClient ,
385396 minInterval : minInterval ,
386397 batchExportTimeoutSec : batchExportTimeoutSec ,
@@ -703,8 +714,8 @@ func (sink *StackdriverSink) TranslateMetric(timestamp time.Time, labels map[str
703714func (sink * StackdriverSink ) legacyGetResourceLabels (labels map [string ]string ) map [string ]string {
704715 return map [string ]string {
705716 "project_id" : sink .project ,
706- "cluster_name" : sink .cluster ,
707- "zone" : sink .zone , // TODO(kawych): revisit how the location is set
717+ "cluster_name" : sink .clusterName ,
718+ "zone" : sink .heapsterZone ,
708719 "instance_id" : labels [core .LabelHostID .Key ],
709720 "namespace_id" : labels [core .LabelPodNamespaceUID .Key ],
710721 "pod_id" : labels [core .LabelPodId .Key ],
@@ -715,8 +726,8 @@ func (sink *StackdriverSink) legacyGetResourceLabels(labels map[string]string) m
715726func (sink * StackdriverSink ) getContainerResourceLabels (labels map [string ]string ) map [string ]string {
716727 return map [string ]string {
717728 "project_id" : sink .project ,
718- "location" : sink .zone , // TODO(kawych): revisit how the location is set
719- "cluster_name" : sink .cluster ,
729+ "location" : sink .clusterLocation ,
730+ "cluster_name" : sink .clusterName ,
720731 "namespace_name" : labels [core .LabelNamespaceName .Key ],
721732 "node_name" : labels [core .LabelNodename .Key ],
722733 "pod_name" : labels [core .LabelPodName .Key ],
@@ -727,8 +738,8 @@ func (sink *StackdriverSink) getContainerResourceLabels(labels map[string]string
727738func (sink * StackdriverSink ) getPodResourceLabels (labels map [string ]string ) map [string ]string {
728739 return map [string ]string {
729740 "project_id" : sink .project ,
730- "location" : sink .zone , // TODO(kawych): revisit how the location is set
731- "cluster_name" : sink .cluster ,
741+ "location" : sink .clusterLocation ,
742+ "cluster_name" : sink .clusterName ,
732743 "namespace_name" : labels [core .LabelNamespaceName .Key ],
733744 "node_name" : labels [core .LabelNodename .Key ],
734745 "pod_name" : labels [core .LabelPodName .Key ],
@@ -738,8 +749,8 @@ func (sink *StackdriverSink) getPodResourceLabels(labels map[string]string) map[
738749func (sink * StackdriverSink ) getNodeResourceLabels (labels map [string ]string ) map [string ]string {
739750 return map [string ]string {
740751 "project_id" : sink .project ,
741- "location" : sink .zone , // TODO(kawych): revisit how the location is set
742- "cluster_name" : sink .cluster ,
752+ "location" : sink .clusterLocation ,
753+ "cluster_name" : sink .clusterName ,
743754 "node_name" : labels [core .LabelNodename .Key ],
744755 }
745756}
0 commit comments