Skip to content
This repository has been archived by the owner on Dec 1, 2018. It is now read-only.

Commit

Permalink
Merge pull request #1943 from kawych/release-1.5
Browse files Browse the repository at this point in the history
Export correct cluster location in Stackdriver sink with new resource model
  • Loading branch information
kawych authored Jan 30, 2018
2 parents a5638ec + cdb2247 commit 552a986
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
39 changes: 25 additions & 14 deletions metrics/sinks/stackdriver/stackdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ const (

type StackdriverSink struct {
project string
cluster string
zone string
clusterName string
clusterLocation string
heapsterZone string
stackdriverClient *sd_api.MetricClient
minInterval time.Duration
lastExportTime time.Time
Expand Down Expand Up @@ -329,6 +330,8 @@ func CreateStackdriverSink(uri *url.URL) (core.DataSink, error) {
cluster_name := ""
if len(opts["cluster_name"]) >= 1 {
cluster_name = opts["cluster_name"][0]
} else {
glog.Warning("Cluster name required but not provided, using empty cluster name.")
}

minInterval := time.Nanosecond
Expand Down Expand Up @@ -365,12 +368,19 @@ func CreateStackdriverSink(uri *url.URL) (core.DataSink, error) {
return nil, err
}

// Detect zone
zone, err := gce.Zone()
// Detect zone for old resource model
heapsterZone, err := gce.Zone()
if err != nil {
return nil, err
}

clusterLocation := heapsterZone
if len(opts["cluster_location"]) >= 1 {
clusterLocation = opts["cluster_location"][0]
} else if useNewResourceModel {
glog.Warning("Cluster location required with new resource model but not provided. Falling back to the zone where Heapster runs.")
}

// Create Metric Client
stackdriverClient, err := sd_api.NewMetricClient(context.Background())
if err != nil {
Expand All @@ -379,8 +389,9 @@ func CreateStackdriverSink(uri *url.URL) (core.DataSink, error) {

sink := &StackdriverSink{
project: projectId,
cluster: cluster_name,
zone: zone,
clusterName: cluster_name,
clusterLocation: clusterLocation,
heapsterZone: heapsterZone,
stackdriverClient: stackdriverClient,
minInterval: minInterval,
batchExportTimeoutSec: batchExportTimeoutSec,
Expand Down Expand Up @@ -703,8 +714,8 @@ func (sink *StackdriverSink) TranslateMetric(timestamp time.Time, labels map[str
func (sink *StackdriverSink) legacyGetResourceLabels(labels map[string]string) map[string]string {
return map[string]string{
"project_id": sink.project,
"cluster_name": sink.cluster,
"zone": sink.zone, // TODO(kawych): revisit how the location is set
"cluster_name": sink.clusterName,
"zone": sink.heapsterZone,
"instance_id": labels[core.LabelHostID.Key],
"namespace_id": labels[core.LabelPodNamespaceUID.Key],
"pod_id": labels[core.LabelPodId.Key],
Expand All @@ -715,8 +726,8 @@ func (sink *StackdriverSink) legacyGetResourceLabels(labels map[string]string) m
func (sink *StackdriverSink) getContainerResourceLabels(labels map[string]string) map[string]string {
return map[string]string{
"project_id": sink.project,
"location": sink.zone, // TODO(kawych): revisit how the location is set
"cluster_name": sink.cluster,
"location": sink.clusterLocation,
"cluster_name": sink.clusterName,
"namespace_name": labels[core.LabelNamespaceName.Key],
"node_name": labels[core.LabelNodename.Key],
"pod_name": labels[core.LabelPodName.Key],
Expand All @@ -727,8 +738,8 @@ func (sink *StackdriverSink) getContainerResourceLabels(labels map[string]string
func (sink *StackdriverSink) getPodResourceLabels(labels map[string]string) map[string]string {
return map[string]string{
"project_id": sink.project,
"location": sink.zone, // TODO(kawych): revisit how the location is set
"cluster_name": sink.cluster,
"location": sink.clusterLocation,
"cluster_name": sink.clusterName,
"namespace_name": labels[core.LabelNamespaceName.Key],
"node_name": labels[core.LabelNodename.Key],
"pod_name": labels[core.LabelPodName.Key],
Expand All @@ -738,8 +749,8 @@ func (sink *StackdriverSink) getPodResourceLabels(labels map[string]string) map[
func (sink *StackdriverSink) getNodeResourceLabels(labels map[string]string) map[string]string {
return map[string]string{
"project_id": sink.project,
"location": sink.zone, // TODO(kawych): revisit how the location is set
"cluster_name": sink.cluster,
"location": sink.clusterLocation,
"cluster_name": sink.clusterName,
"node_name": labels[core.LabelNodename.Key],
}
}
Expand Down
2 changes: 1 addition & 1 deletion metrics/sinks/stackdriver/stackdriver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var (

sink = &StackdriverSink{
project: testProjectId,
zone: zone,
heapsterZone: zone,
stackdriverClient: nil,
}

Expand Down

0 comments on commit 552a986

Please sign in to comment.