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

Commit

Permalink
Fix resource assignment in GKE and GCE environment when using metrics…
Browse files Browse the repository at this point in the history
… exporter. (#139)

* Fix resource assignment in GKE ancd GCE environment.

* update with exporter resource only if metric doesn't have resource.

* update metric_test.go
  • Loading branch information
rghetia committed Apr 22, 2019
1 parent b39028f commit 433871b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (se *statsExporter) metricToMpbTs(ctx context.Context, metric *metricdata.M
return nil, errNilMetric
}

resource := metricRscToMpbRsc(metric.Resource)
resource := se.metricRscToMpbRsc(metric.Resource)

metricName := metric.Descriptor.Name
metricType, _ := se.metricTypeFromProto(metricName)
Expand Down Expand Up @@ -303,11 +303,15 @@ func metricDescriptorTypeToMetricKind(m *metricdata.Metric) (googlemetricpb.Metr
}
}

func metricRscToMpbRsc(rs *resource.Resource) *monitoredrespb.MonitoredResource {
func (se *statsExporter) metricRscToMpbRsc(rs *resource.Resource) *monitoredrespb.MonitoredResource {
if rs == nil {
return &monitoredrespb.MonitoredResource{
Type: "global",
resource := se.o.Resource
if resource == nil {
resource = &monitoredrespb.MonitoredResource{
Type: "global",
}
}
return resource
}
typ := rs.Type
if typ == "" {
Expand Down
2 changes: 1 addition & 1 deletion metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestMetricResourceToMonitoringResource(t *testing.T) {
}

for i, tt := range tests {
got := metricRscToMpbRsc(tt.in)
got := se.metricRscToMpbRsc(tt.in)
if diff := cmpResource(got, tt.want); diff != "" {
t.Fatalf("Test %d failed. Unexpected Resource -got +want: %s", i, diff)
}
Expand Down

0 comments on commit 433871b

Please sign in to comment.