Repository: census-ecosystem/opencensus-go-exporter-stackdriver (go)

Issue:
My gauge are always global and not K8S or GCE
This is my stackdriver config

```
	opt := stackdriver.Options{
		// MetricPrefix helps uniquely identify your metrics.
		//	ProjectID:    project,
		MetricPrefix: "backup",
		OnError: func(err error) {
			log.Printf("Failed to send metrics on stackdriver: %v", err.Error())
		},
		Context: cont,
		Timeout: 5 * time.Second,
		//MonitoredResource: monitoredresource.Autodetect(),
		ReportingInterval: 1 * time.Minute,
		ResourceDetector:  auto.Detect,
	}
```
When i run my app on GKE, all my gauge have resource type Global but not K8S_container

On debug i can't see everything to set them on this method: https://github.com/census-instrumentation/opencensus-go/blob/5ae9166f90ff989c557e45fcb9592ac59afa0fa0/metric/metricexport/reader.go#L183

Pull request description:
Fix resource assignment in GKE and GCE environment when using metrics exporter.
This fixes #133 if you use 
```go
MonitoredResource: monitoredresource.Autodetect(),
```
If you use 
```go
ResourceDetector:  auto.Detect,
```
then it only detects GCE and not GKE. This because auto.Detect doesn't support GKE. Opened #140 to track this.


Patch:
diff --git a/metrics.go b/metrics.go
index 00f94f3..a6f0d4b 100644
--- a/metrics.go
+++ b/metrics.go
@@ -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)
@@ -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 == "" {


Test patch:
diff --git a/metrics_test.go b/metrics_test.go
index e7e510d..fd4135b 100644
--- a/metrics_test.go
+++ b/metrics_test.go
@@ -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)
 		}