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

Commit e191b7c

Browse files
authored
Make defaultMapResource function public to allow reusing it in custom functions (#255)
1 parent 1d104f7 commit e191b7c

5 files changed

Lines changed: 12 additions & 11 deletions

File tree

equivalence_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func TestStatsAndMetricsEquivalence(t *testing.T) {
8787
// Now perform some exporting.
8888
for i, metric := range metrics {
8989
se := &statsExporter{
90-
o: Options{ProjectID: "equivalence", MapResource: defaultMapResource},
90+
o: Options{ProjectID: "equivalence", MapResource: DefaultMapResource},
9191
}
9292

9393
ctx := context.Background()
@@ -148,7 +148,7 @@ func TestEquivalenceStatsVsMetricsUploads(t *testing.T) {
148148
// so that batching is performed deterministically and flushing is
149149
// fully controlled by us.
150150
BundleDelayThreshold: 2 * time.Hour,
151-
MapResource: defaultMapResource,
151+
MapResource: DefaultMapResource,
152152
}
153153
se, err := newStatsExporter(exporterOptions)
154154
if err != nil {

metrics_proto_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func TestExportTimeSeriesWithDifferentLabels(t *testing.T) {
5454

5555
// Set empty labels to avoid the opencensus-task
5656
DefaultMonitoringLabels: &Labels{},
57-
MapResource: defaultMapResource,
57+
MapResource: DefaultMapResource,
5858
}
5959
se, err := newStatsExporter(exporterOptions)
6060
if err != nil {
@@ -260,7 +260,7 @@ func TestProtoMetricToCreateTimeSeriesRequest(t *testing.T) {
260260
},
261261
},
262262
statsExporter: &statsExporter{
263-
o: Options{ProjectID: "foo", MapResource: defaultMapResource},
263+
o: Options{ProjectID: "foo", MapResource: DefaultMapResource},
264264
},
265265
want: []*monitoringpb.CreateTimeSeriesRequest{
266266
{
@@ -331,7 +331,7 @@ func TestProtoMetricToCreateTimeSeriesRequest(t *testing.T) {
331331
},
332332
},
333333
statsExporter: &statsExporter{
334-
o: Options{ProjectID: "foo", MapResource: defaultMapResource},
334+
o: Options{ProjectID: "foo", MapResource: DefaultMapResource},
335335
},
336336
want: []*monitoringpb.CreateTimeSeriesRequest{
337337
{
@@ -446,7 +446,7 @@ func TestProtoMetricWithDifferentResource(t *testing.T) {
446446
},
447447
},
448448
statsExporter: &statsExporter{
449-
o: Options{ProjectID: "foo", MapResource: defaultMapResource},
449+
o: Options{ProjectID: "foo", MapResource: DefaultMapResource},
450450
},
451451
want: []*monitoringpb.CreateTimeSeriesRequest{
452452
{
@@ -518,7 +518,7 @@ func TestProtoMetricWithDifferentResource(t *testing.T) {
518518
},
519519
},
520520
statsExporter: &statsExporter{
521-
o: Options{ProjectID: "foo", MapResource: defaultMapResource},
521+
o: Options{ProjectID: "foo", MapResource: DefaultMapResource},
522522
},
523523
want: []*monitoringpb.CreateTimeSeriesRequest{
524524
{

resource.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ func transformResource(match, input map[string]string) (map[string]string, bool)
181181
return output, false
182182
}
183183

184-
func defaultMapResource(res *resource.Resource) *monitoredrespb.MonitoredResource {
184+
// DefaultMapResource implements default resource mapping for well-known resource types
185+
func DefaultMapResource(res *resource.Resource) *monitoredrespb.MonitoredResource {
185186
match := genericResourceMap
186187
result := &monitoredrespb.MonitoredResource{
187188
Type: "global",

resource_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ func TestDefaultMapResource(t *testing.T) {
373373
autodetectFunc = func() gcp.Interface { return c.autoRes }
374374
}
375375

376-
got := defaultMapResource(c.input)
376+
got := DefaultMapResource(c.input)
377377
if diff := cmp.Diff(got, c.want); diff != "" {
378378
t.Errorf("Values differ -got +want: %s", diff)
379379
}

stackdriver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ type Options struct {
183183

184184
// MapResource converts a OpenCensus resource to a Stackdriver monitored resource.
185185
//
186-
// If this field is unset, defaultMapResource will be used which encodes a set of default
186+
// If this field is unset, DefaultMapResource will be used which encodes a set of default
187187
// conversions from auto-detected resources to well-known Stackdriver monitored resources.
188188
MapResource func(*resource.Resource) *monitoredrespb.MonitoredResource
189189

@@ -333,7 +333,7 @@ func NewExporter(o Options) (*Exporter, error) {
333333
o.Resource = convertMonitoredResourceToPB(o.MonitoredResource)
334334
}
335335
if o.MapResource == nil {
336-
o.MapResource = defaultMapResource
336+
o.MapResource = DefaultMapResource
337337
}
338338
if o.ResourceDetector != nil {
339339
// For backwards-compatibility we still respect the deprecated resource field.

0 commit comments

Comments
 (0)