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

Commit

Permalink
flush interval reader when stopping metric reader
Browse files Browse the repository at this point in the history
  • Loading branch information
quentin-cha committed Jan 31, 2021
1 parent 1996040 commit 72d9183
Show file tree
Hide file tree
Showing 8 changed files with 357 additions and 47 deletions.
35 changes: 18 additions & 17 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ module contrib.go.opencensus.io/exporter/stackdriver
go 1.12

require (
cloud.google.com/go v0.45.1
github.com/aws/aws-sdk-go v1.23.20
github.com/census-instrumentation/opencensus-proto v0.2.1
github.com/golang/protobuf v1.3.2
github.com/google/go-cmp v0.3.1
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024
go.opencensus.io v0.22.4
golang.org/x/lint v0.0.0-20190409202823-959b441ac422
golang.org/x/net v0.0.0-20190923162816-aa69164e4478
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e // indirect
golang.org/x/tools v0.0.0-20191010075000-0337d82405ff
google.golang.org/api v0.10.0
google.golang.org/appengine v1.6.2 // indirect
google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51
google.golang.org/grpc v1.23.1
honnef.co/go/tools v0.0.1-2019.2.3
cloud.google.com/go v0.75.0
github.com/aws/aws-sdk-go v1.37.0
github.com/census-instrumentation/opencensus-proto v0.3.0
github.com/golang/protobuf v1.4.3
github.com/google/go-cmp v0.5.4
github.com/jstemmer/go-junit-report v0.9.1
go.opencensus.io v0.22.6
golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5
golang.org/x/net v0.0.0-20210119194325-5f4716e94777
golang.org/x/oauth2 v0.0.0-20210126194326-f9ce19ea3013
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c // indirect
golang.org/x/text v0.3.5 // indirect
golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e
google.golang.org/api v0.37.0
google.golang.org/genproto v0.0.0-20210126160654-44e461bb6506
google.golang.org/grpc v1.35.0
google.golang.org/protobuf v1.25.0
honnef.co/go/tools v0.0.1-2020.1.4
)
336 changes: 322 additions & 14 deletions go.sum

Large diffs are not rendered by default.

10 changes: 3 additions & 7 deletions metrics_proto_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@ import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"

"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes/empty"
"github.com/golang/protobuf/ptypes/timestamp"
"google.golang.org/api/option"
"google.golang.org/protobuf/testing/protocmp"

labelpb "google.golang.org/genproto/googleapis/api/label"
googlemetricpb "google.golang.org/genproto/googleapis/api/metric"
monitoredrespb "google.golang.org/genproto/googleapis/api/monitoredres"
monitoringpb "google.golang.org/genproto/googleapis/monitoring/v3"
Expand Down Expand Up @@ -593,7 +591,7 @@ func requireTimeSeriesRequestEqual(t *testing.T, got, want []*monitoringpb.Creat
}
for i, g := range got {
w := want[i]
diff = cmp.Diff(g, w, cmpopts.IgnoreFields(timestamp.Timestamp{}, "XXX_sizecache"))
diff = cmp.Diff(g, w, protocmp.Transform())
if diff != "" {
return diff, i
}
Expand All @@ -610,9 +608,7 @@ func requireMetricDescriptorRequestEqual(t *testing.T, got, want []*monitoringpb
}
for i, g := range got {
w := want[i]
diff = cmp.Diff(g, w,
cmpopts.IgnoreFields(labelpb.LabelDescriptor{}, "XXX_sizecache"),
cmpopts.IgnoreFields(googlemetricpb.MetricDescriptor{}, "XXX_sizecache"))
diff = cmp.Diff(g, w, protocmp.Transform())
if diff != "" {
return diff, i
}
Expand Down
3 changes: 2 additions & 1 deletion metrics_proto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
monitoredrespb "google.golang.org/genproto/googleapis/api/monitoredres"
monitoringpb "google.golang.org/genproto/googleapis/monitoring/v3"
"google.golang.org/grpc"
"google.golang.org/protobuf/testing/protocmp"

metricspb "github.com/census-instrumentation/opencensus-proto/gen-go/metrics/v1"
"github.com/golang/protobuf/ptypes/wrappers"
Expand Down Expand Up @@ -995,7 +996,7 @@ func TestConvertSummaryMetrics(t *testing.T) {
se = new(statsExporter)
}
got := se.convertSummaryMetrics(tt.in)
if !cmp.Equal(got, tt.want) {
if !cmp.Equal(got, tt.want, protocmp.Transform()) {
t.Fatalf("conversion failed:\n got=%v\n want=%v\n", got, tt.want)
}
}
Expand Down
11 changes: 6 additions & 5 deletions metrics_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
googlemetricpb "google.golang.org/genproto/googleapis/api/metric"
monitoredrespb "google.golang.org/genproto/googleapis/api/monitoredres"
monitoringpb "google.golang.org/genproto/googleapis/monitoring/v3"
"google.golang.org/protobuf/testing/protocmp"
)

func cmpResource(got, want *monitoredrespb.MonitoredResource) string {
Expand All @@ -47,21 +48,21 @@ func requireTimeSeriesRequestEqual(t *testing.T, got, want []*monitoringpb.Creat
}

func cmpTSReqs(got, want []*monitoringpb.CreateTimeSeriesRequest) string {
return cmp.Diff(got, want, cmpopts.IgnoreUnexported(monitoringpb.CreateTimeSeriesRequest{}), cmpopts.IgnoreTypes(googlemetricpb.MetricDescriptor_METRIC_KIND_UNSPECIFIED, googlemetricpb.MetricDescriptor_VALUE_TYPE_UNSPECIFIED))
return cmp.Diff(got, want, protocmp.Transform(), protocmp.IgnoreEnums(googlemetricpb.MetricDescriptor_METRIC_KIND_UNSPECIFIED, googlemetricpb.MetricDescriptor_VALUE_TYPE_UNSPECIFIED))
}

func cmpMD(got, want *googlemetricpb.MetricDescriptor) string {
return cmp.Diff(got, want, cmpopts.IgnoreUnexported(googlemetricpb.MetricDescriptor{}))
return cmp.Diff(got, want, protocmp.Transform())
}

func cmpMDReq(got, want *monitoringpb.CreateMetricDescriptorRequest) string {
return cmp.Diff(got, want, cmpopts.IgnoreUnexported(monitoringpb.CreateMetricDescriptorRequest{}))
return cmp.Diff(got, want, protocmp.Transform())
}

func cmpMDReqs(got, want []*monitoringpb.CreateMetricDescriptorRequest) string {
return cmp.Diff(got, want, cmpopts.IgnoreUnexported(monitoringpb.CreateMetricDescriptorRequest{}))
return cmp.Diff(got, want, protocmp.Transform())
}

func cmpPoint(got, want *monitoringpb.Point) string {
return cmp.Diff(got, want, cmpopts.IgnoreUnexported(monitoringpb.Point{}))
return cmp.Diff(got, want, protocmp.Transform())
}
3 changes: 2 additions & 1 deletion resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"go.opencensus.io/resource"
"go.opencensus.io/resource/resourcekeys"
monitoredrespb "google.golang.org/genproto/googleapis/api/monitoredres"
"google.golang.org/protobuf/testing/protocmp"
)

func TestDefaultMapResource(t *testing.T) {
Expand Down Expand Up @@ -476,7 +477,7 @@ func TestDefaultMapResource(t *testing.T) {
}

got := DefaultMapResource(c.input)
if diff := cmp.Diff(got, c.want); diff != "" {
if diff := cmp.Diff(got, c.want, protocmp.Transform()); diff != "" {
t.Errorf("Values differ -got +want: %s", diff)
}
})
Expand Down
1 change: 1 addition & 0 deletions stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ func (e *statsExporter) startMetricsReader() error {
func (e *statsExporter) stopMetricsReader() {
if e.ir != nil {
e.ir.Stop()
e.ir.Flush()
}
}

Expand Down
5 changes: 3 additions & 2 deletions stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
monitoredrespb "google.golang.org/genproto/googleapis/api/monitoredres"
monitoringpb "google.golang.org/genproto/googleapis/monitoring/v3"
"google.golang.org/grpc"
"google.golang.org/protobuf/testing/protocmp"
)

var authOptions = []option.ClientOption{option.WithGRPCConn(&grpc.ClientConn{})}
Expand Down Expand Up @@ -487,7 +488,7 @@ func TestExporter_makeReq(t *testing.T) {
if len(tt.want) == 0 {
return
}
if diff := cmp.Diff(resps, tt.want); diff != "" {
if diff := cmp.Diff(resps, tt.want, protocmp.Transform()); diff != "" {
t.Errorf("Values differ -got +want: %s", diff)
}
})
Expand Down Expand Up @@ -1079,7 +1080,7 @@ func TestExporter_makeReq_withCustomMonitoredResource(t *testing.T) {
if len(tt.want) == 0 {
return
}
if diff := cmp.Diff(resps, tt.want); diff != "" {
if diff := cmp.Diff(resps, tt.want, protocmp.Transform()); diff != "" {
t.Errorf("Requests differ, -got +want: %s", diff)
}
})
Expand Down

0 comments on commit 72d9183

Please sign in to comment.