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

Commit

Permalink
Make defaultMapResource function public to allow reusing it in custom…
Browse files Browse the repository at this point in the history
… functions (#255)
  • Loading branch information
nilebox authored Apr 1, 2020
1 parent 1d104f7 commit e191b7c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions equivalence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestStatsAndMetricsEquivalence(t *testing.T) {
// Now perform some exporting.
for i, metric := range metrics {
se := &statsExporter{
o: Options{ProjectID: "equivalence", MapResource: defaultMapResource},
o: Options{ProjectID: "equivalence", MapResource: DefaultMapResource},
}

ctx := context.Background()
Expand Down Expand Up @@ -148,7 +148,7 @@ func TestEquivalenceStatsVsMetricsUploads(t *testing.T) {
// so that batching is performed deterministically and flushing is
// fully controlled by us.
BundleDelayThreshold: 2 * time.Hour,
MapResource: defaultMapResource,
MapResource: DefaultMapResource,
}
se, err := newStatsExporter(exporterOptions)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions metrics_proto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestExportTimeSeriesWithDifferentLabels(t *testing.T) {

// Set empty labels to avoid the opencensus-task
DefaultMonitoringLabels: &Labels{},
MapResource: defaultMapResource,
MapResource: DefaultMapResource,
}
se, err := newStatsExporter(exporterOptions)
if err != nil {
Expand Down Expand Up @@ -260,7 +260,7 @@ func TestProtoMetricToCreateTimeSeriesRequest(t *testing.T) {
},
},
statsExporter: &statsExporter{
o: Options{ProjectID: "foo", MapResource: defaultMapResource},
o: Options{ProjectID: "foo", MapResource: DefaultMapResource},
},
want: []*monitoringpb.CreateTimeSeriesRequest{
{
Expand Down Expand Up @@ -331,7 +331,7 @@ func TestProtoMetricToCreateTimeSeriesRequest(t *testing.T) {
},
},
statsExporter: &statsExporter{
o: Options{ProjectID: "foo", MapResource: defaultMapResource},
o: Options{ProjectID: "foo", MapResource: DefaultMapResource},
},
want: []*monitoringpb.CreateTimeSeriesRequest{
{
Expand Down Expand Up @@ -446,7 +446,7 @@ func TestProtoMetricWithDifferentResource(t *testing.T) {
},
},
statsExporter: &statsExporter{
o: Options{ProjectID: "foo", MapResource: defaultMapResource},
o: Options{ProjectID: "foo", MapResource: DefaultMapResource},
},
want: []*monitoringpb.CreateTimeSeriesRequest{
{
Expand Down Expand Up @@ -518,7 +518,7 @@ func TestProtoMetricWithDifferentResource(t *testing.T) {
},
},
statsExporter: &statsExporter{
o: Options{ProjectID: "foo", MapResource: defaultMapResource},
o: Options{ProjectID: "foo", MapResource: DefaultMapResource},
},
want: []*monitoringpb.CreateTimeSeriesRequest{
{
Expand Down
3 changes: 2 additions & 1 deletion resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ func transformResource(match, input map[string]string) (map[string]string, bool)
return output, false
}

func defaultMapResource(res *resource.Resource) *monitoredrespb.MonitoredResource {
// DefaultMapResource implements default resource mapping for well-known resource types
func DefaultMapResource(res *resource.Resource) *monitoredrespb.MonitoredResource {
match := genericResourceMap
result := &monitoredrespb.MonitoredResource{
Type: "global",
Expand Down
2 changes: 1 addition & 1 deletion resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ func TestDefaultMapResource(t *testing.T) {
autodetectFunc = func() gcp.Interface { return c.autoRes }
}

got := defaultMapResource(c.input)
got := DefaultMapResource(c.input)
if diff := cmp.Diff(got, c.want); diff != "" {
t.Errorf("Values differ -got +want: %s", diff)
}
Expand Down
4 changes: 2 additions & 2 deletions stackdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ type Options struct {

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

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

0 comments on commit e191b7c

Please sign in to comment.