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

Commit

Permalink
Remove outdated option GetMonitoredResource (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
songy23 authored Aug 29, 2019
1 parent a8e01fd commit b0cbe77
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 95 deletions.
16 changes: 0 additions & 16 deletions stackdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ import (
"contrib.go.opencensus.io/exporter/stackdriver/monitoredresource"
"go.opencensus.io/resource"
"go.opencensus.io/stats/view"
"go.opencensus.io/tag"
"go.opencensus.io/trace"
"golang.org/x/oauth2/google"
"google.golang.org/api/option"
Expand Down Expand Up @@ -242,21 +241,6 @@ type Options struct {
// Timeout for all API calls. If not set, defaults to 5 seconds.
Timeout time.Duration

// GetMonitoredResource may be provided to supply the details of the
// monitored resource dynamically based on the tags associated with each
// data point. Most users will not need to set this, but should instead
// set the MonitoredResource field.
//
// GetMonitoredResource may add or remove tags by returning a new set of
// tags. It is safe for the function to mutate its argument and return it.
//
// See the documentation on the MonitoredResource field for guidance on the
// interaction between monitored resources and labels.
//
// The MonitoredResource field is ignored if this field is set to a non-nil
// value.
GetMonitoredResource func(*view.View, []tag.Tag) ([]tag.Tag, monitoredresource.Interface)

// ReportingInterval sets the interval between reporting metrics.
// If it is set to zero then default value is used.
ReportingInterval time.Duration
Expand Down
4 changes: 0 additions & 4 deletions stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,6 @@ func (e *statsExporter) stopMetricsReader() {
}

func (e *statsExporter) getMonitoredResource(v *view.View, tags []tag.Tag) ([]tag.Tag, *monitoredrespb.MonitoredResource) {
if get := e.o.GetMonitoredResource; get != nil {
newTags, mr := get(v, tags)
return newTags, convertMonitoredResourceToPB(mr)
}
resource := e.o.Resource
if resource == nil {
resource = &monitoredrespb.MonitoredResource{
Expand Down
75 changes: 0 additions & 75 deletions stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1080,81 +1080,6 @@ func TestExporter_makeReq_withCustomMonitoredResource(t *testing.T) {
},
},
},
{
name: "GetMonitoredResource and labels",
opts: func() Options {
var labels Labels
labels.Set("pid", "1234", "Process identifier")
return Options{
GetMonitoredResource: func(v *view.View, t []tag.Tag) ([]tag.Tag, monitoredresource.Interface) {
return t, gceInst
},
DefaultMonitoringLabels: &labels,
}
}(),
vd: newTestViewData(v, start, end, count1, count2),
want: []*monitoringpb.CreateTimeSeriesRequest{
{
Name: monitoring.MetricProjectPath("proj-id"),
TimeSeries: []*monitoringpb.TimeSeries{
{
Metric: &metricpb.Metric{
Type: "custom.googleapis.com/opencensus/testview",
Labels: map[string]string{
"test_key": "test-value-1",
"pid": "1234",
},
},
Resource: resource,
Points: []*monitoringpb.Point{
{
Interval: &monitoringpb.TimeInterval{
StartTime: &timestamp.Timestamp{
Seconds: start.Unix(),
Nanos: int32(start.Nanosecond()),
},
EndTime: &timestamp.Timestamp{
Seconds: end.Unix(),
Nanos: int32(end.Nanosecond()),
},
},
Value: &monitoringpb.TypedValue{Value: &monitoringpb.TypedValue_Int64Value{
Int64Value: 10,
}},
},
},
},
{
Metric: &metricpb.Metric{
Type: "custom.googleapis.com/opencensus/testview",
Labels: map[string]string{
"test_key": "test-value-2",
"pid": "1234",
},
},
Resource: resource,
Points: []*monitoringpb.Point{
{
Interval: &monitoringpb.TimeInterval{
StartTime: &timestamp.Timestamp{
Seconds: start.Unix(),
Nanos: int32(start.Nanosecond()),
},
EndTime: &timestamp.Timestamp{
Seconds: end.Unix(),
Nanos: int32(end.Nanosecond()),
},
},
Value: &monitoringpb.TypedValue{Value: &monitoringpb.TypedValue_Int64Value{
Int64Value: 16,
}},
},
},
},
},
},
},
},
{
name: "custom default monitoring labels",
opts: func() Options {
Expand Down

5 comments on commit b0cbe77

@garron
Copy link

@garron garron commented on b0cbe77 Oct 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@songy23 Is there a recommended alternative or upgrade path for code that was making use of this option? Specifically, it's being used in the knative project:

https://github.com/knative/pkg/blob/6b1c5cf09af549d89344672045b7fe0e3280a820/metrics/stackdriver_exporter.go#L72

@songy23
Copy link
Contributor Author

@songy23 songy23 commented on b0cbe77 Oct 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using resource.Detector and removing resource labels from view.tags.

/cc @rghetia

@rghetia
Copy link
Contributor

@rghetia rghetia commented on b0cbe77 Oct 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@garron were you able to use resource.Detector to achieve the same result?

@garron
Copy link

@garron garron commented on b0cbe77 Oct 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestions! I haven't had a chance to try it out.

@yanweiguo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resource.Detector doesn't work for us. In our process, we could send metrics to different monitored resource types. The resource type is determined by the metric name currently. If the metric is a built-in metric, we send it with a non-global resource type. If not, we send it with global resource type as custom metrics.

Please sign in to comment.