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

flush interval reader when stopping metric reader #282

Merged
merged 2 commits into from
Feb 3, 2021

Conversation

quentin-cha
Copy link
Contributor

Flush interval reader when stopping metric reader. Fixes unit test after update dependencies.

@google-cla google-cla bot added the cla: yes label Jan 31, 2021
Makefile Outdated
@@ -114,7 +114,7 @@ goimports:

.PHONY: staticcheck
staticcheck:
$(STATICCHECK) ./...
$(STATICCHECK) -checks "inherit,-SA1019" ./...
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this to bypass SA1019 because the following failure after dependency upgrade:

internal/testpb/test.pb.go:42:9: xxx_messageInfo_FooRequest.Unmarshal is deprecated: Do not use; this method existed for intenal-use only.  (SA1019)
internal/testpb/test.pb.go:45:9: xxx_messageInfo_FooRequest.Marshal is deprecated: Do not use; this method existed for intenal-use only.  (SA1019)
internal/testpb/test.pb.go:48:2: xxx_messageInfo_FooRequest.Merge is deprecated: Do not use; this method existed for intenal-use only.  (SA1019)
internal/testpb/test.pb.go:51:9: xxx_messageInfo_FooRequest.Size is deprecated: Do not use; this method existed for intenal-use only.  (SA1019)
internal/testpb/test.pb.go:54:2: xxx_messageInfo_FooRequest.DiscardUnknown is deprecated: Do not use; this method existed for intenal-use only.  (SA1019)
internal/testpb/test.pb.go:57:32: proto.InternalMessageInfo is deprecated: Do not use; this type existed for intenal-use only.  (SA1019)
internal/testpb/test.pb.go:87:9: xxx_messageInfo_FooResponse.Unmarshal is deprecated: Do not use; this method existed for intenal-use only.  (SA1019)
internal/testpb/test.pb.go:90:9: xxx_messageInfo_FooResponse.Marshal is deprecated: Do not use; this method existed for intenal-use only.  (SA1019)
internal/testpb/test.pb.go:93:2: xxx_messageInfo_FooResponse.Merge is deprecated: Do not use; this method existed for intenal-use only.  (SA1019)
internal/testpb/test.pb.go:96:9: xxx_messageInfo_FooResponse.Size is deprecated: Do not use; this method existed for intenal-use only.  (SA1019)
internal/testpb/test.pb.go:99:2: xxx_messageInfo_FooResponse.DiscardUnknown is deprecated: Do not use; this method existed for intenal-use only.  (SA1019)
internal/testpb/test.pb.go:102:33: proto.InternalMessageInfo is deprecated: Do not use; this type existed for intenal-use only.  (SA1019)
internal/testpb/test.pb.go:105:2: proto.RegisterType is deprecated: Use protoregistry.GlobalTypes.RegisterMessage instead.  (SA1019)
internal/testpb/test.pb.go:106:2: proto.RegisterType is deprecated: Use protoregistry.GlobalTypes.RegisterMessage instead.  (SA1019)
internal/testpb/test.pb.go:109:15: proto.RegisterFile is deprecated: Use protoregistry.GlobalFiles.RegisterFile instead.  (SA1019)
metrics.go:27:2: package github.com/golang/protobuf/proto is deprecated: Use the "google.golang.org/protobuf/proto" package instead.  (SA1019)
metrics_batcher.go:26:2: package cloud.google.com/go/monitoring/apiv3 is deprecated: Please use cloud.google.com/go/monitoring/apiv3/v2.  (SA1019)
metrics_batcher_test.go:23:2: package cloud.google.com/go/monitoring/apiv3 is deprecated: Please use cloud.google.com/go/monitoring/apiv3/v2.  (SA1019)
metrics_proto_api_test.go:27:2: package github.com/golang/protobuf/proto is deprecated: Use the "google.golang.org/protobuf/proto" package instead.  (SA1019)
metrics_test.go:23:2: package github.com/golang/protobuf/proto is deprecated: Use the "google.golang.org/protobuf/proto" package instead.  (SA1019)
metrics_utils_test.go:24:2: package github.com/golang/protobuf/proto is deprecated: Use the "google.golang.org/protobuf/proto" package instead.  (SA1019)
stats.go:34:2: package cloud.google.com/go/monitoring/apiv3 is deprecated: Please use cloud.google.com/go/monitoring/apiv3/v2.  (SA1019)
stats_test.go:23:2: package cloud.google.com/go/monitoring/apiv3 is deprecated: Please use cloud.google.com/go/monitoring/apiv3/v2.  (SA1019)
trace.go:25:2: package github.com/golang/protobuf/proto is deprecated: Use the "google.golang.org/protobuf/proto" package instead.  (SA1019)
trace_proto_test.go:27:2: package github.com/golang/protobuf/proto is deprecated: Use the "google.golang.org/protobuf/proto" package instead.  (SA1019)

Please let me know if this should be an issue or be fix as part of the PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer not disabling the deprecated notices. I might consider disabling specific files with //lint directives if the upgrade is problematic for some reason, but only if it isn't possible to use the new package easily.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I have fixed the staticcheck errors. I had to make quite a bit of changes. I did test it by deploying it into Knative cluster just to be sure both metrics and traces are being exported correctly. Please let me know what you think. Thanks again!

@@ -147,6 +145,7 @@ func (e *statsExporter) startMetricsReader() error {
func (e *statsExporter) stopMetricsReader() {
if e.ir != nil {
e.ir.Stop()
e.ir.Flush()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the actual change

@@ -324,10 +324,18 @@ func TestExportTrace(t *testing.T) {
if !reflect.DeepEqual(spbs, expectedSpans) {
var got, want []string
for _, s := range spbs {
got = append(got, proto.MarshalTextString(s))
bytes, err := prototext.Marshal(s)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

sample failure output:

=== RUN   TestExportTrace
    trace_proto_test.go:340: got spans:
        display_name:{value:"span0"}  attributes:{attribute_map:{key:"g.co/agent"  value:{string_value:{value:"opencensus-go 0.23.0; stackdriver-exporter 0.13.3"}}}}  same_process_as_parent_span:{}
        display_name:{value:"span1"}  attributes:{attribute_map:{key:"g.co/agent"  value:{string_value:{value:"opencensus-go 0.23.0; stackdriver-exporter 0.13.3"}}}}  same_process_as_parent_span:{value:true}
        display_name:{value:"span2"}  attributes:{attribute_map:{key:"g.co/agent"  value:{string_value:{value:"custom-agent"}}}  attribute_map:{key:"key1"  value:{int_value:100}}  attribute_map:{key:"key2"  value:{string_value:{value:"value2"}}}}  time_events:{time_event:{annotation:{description:{value:"in span2"}}}  time_event:{annotation:{description:{value:"1/2"}}}  time_event:{message_event:{type:SENT  id:291  uncompressed_size_bytes:1024  compressed_size_bytes:512}}}  same_process_as_parent_span:{value:true}
        display_name:{value:"span3"}  attributes:{attribute_map:{key:"g.co/agent"  value:{string_value:{value:"opencensus-go 0.23.0; stackdriver-exporter 0.13.3"}}}}  time_events:{time_event:{annotation:{description:{value:"in span3"}}}  time_event:{message_event:{type:RECEIVED  id:1110  uncompressed_size_bytes:2048  compressed_size_bytes:1536}}}  status:{code:14}  same_process_as_parent_span:{value:true}
        display_name:{value:"span4"}  attributes:{attribute_map:{key:"g.co/agent"  value:{string_value:{value:"opencensus-go 0.23.0; stackdriver-exporter 0.13.3"}}}}  time_events:{time_event:{annotation:{description:{value:"1/2"}  attributes:{attribute_map:{key:"k1"  value:{string_value:{value:"v1"}}}}}}  time_event:{annotation:{description:{value:"foo 42"}  attributes:{attribute_map:{key:"k2"  value:{string_value:{value:"v2"}}}}}}  time_event:{annotation:{description:{value:"in span4"}  attributes:{attribute_map:{key:"k3"  value:{string_value:{value:"v3"}}}}}}}  links:{link:{trace_id:"01020000000000000000000000000000"  span_id:"0300000000000000"  type:PARENT_LINKED_SPAN  attributes:{attribute_map:{key:"k4"  value:{string_value:{value:"v4"}}}}}}  same_process_as_parent_span:{value:true}
        want:
        display_name:{value:"span0"}  attributes:{attribute_map:{key:"g.co/agent"  value:{string_value:{value:"opencensus-go 0.23.0; stackdriver-exporter 0.13.3"}}}}  same_process_as_parent_span:{}
        display_name:{value:"span1"}  attributes:{attribute_map:{key:"g.co/agent"  value:{string_value:{value:"opencensus-go 0.23.0; stackdriver-exporter 0.13.3"}}}}  same_process_as_parent_span:{value:true}
        display_name:{value:"span2"}  attributes:{attribute_map:{key:"g.co/agent"  value:{string_value:{value:"custom-agent"}}}  attribute_map:{key:"key1"  value:{int_value:100}}  attribute_map:{key:"key2"  value:{string_value:{value:"value2"}}}}  time_events:{time_event:{annotation:{description:{value:"in span2"}}}  time_event:{annotation:{description:{value:"1/2"}}}  time_event:{message_event:{type:SENT  id:291  uncompressed_size_bytes:1024  compressed_size_bytes:512}}}  same_process_as_parent_span:{value:true}
        display_name:{value:"span3"}  attributes:{attribute_map:{key:"g.co/agent"  value:{string_value:{value:"opencensus-go 0.23.0; stackdriver-exporter 0.13.3"}}}}  time_events:{time_event:{annotation:{description:{value:"in span3"}}}  time_event:{message_event:{type:RECEIVED  id:1110  uncompressed_size_bytes:2048  compressed_size_bytes:1536}}}  status:{code:14}  same_process_as_parent_span:{value:true}
        display_name:{value:"span4"}  attributes:{attribute_map:{key:"g.co/agent"  value:{string_value:{value:"opencensus-go 0.23.0; stackdriver-exporter 0.13.3"}}}}  time_events:{time_event:{annotation:{description:{value:"1/2"}  attributes:{attribute_map:{key:"k1"  value:{string_value:{value:"v1"}}}}}}  time_event:{annotation:{description:{value:"foo 42"}  attributes:{attribute_map:{key:"k2"  value:{string_value:{value:"v2"}}}}}}  time_event:{annotation:{description:{value:"in span4"}  attributes:{attribute_map:{key:"k3"  value:{string_value:{value:"v3"}}}}}}}  links:{link:{trace_id:"01020000000000000000000000000000"  span_id:"0300000000000000"  type:PARENT_LINKED_SPAN  attributes:{attribute_map:{key:"k4"  value:{string_value:{value:"v4"}}}}}}  same_process_as_parent_span:{value:true}
--- FAIL: TestExportTrace (0.01s)

@quentin-cha quentin-cha requested a review from dashpole February 2, 2021 14:52
Copy link
Contributor

@dashpole dashpole left a comment

Choose a reason for hiding this comment

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

Thanks! Looks good after a few nits.

@@ -62,6 +62,8 @@ func (s *testServer) Multiple(stream Foo_MultipleServer) error {
}
}

func (*testServer) mustEmbedUnimplementedFooServer() {}
Copy link
Contributor

Choose a reason for hiding this comment

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

a comment explaining why this is needed would be useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -430,7 +428,8 @@ func readTestCaseFromFiles(t *testing.T, filename string) *testCases {
strMetrics := strings.Split(string(f), "---")
for _, strMetric := range strMetrics {
in := metricspb.Metric{}
err = proto.UnmarshalText(strMetric, &in)
//err = proto.UnmarshalText(strMetric, &in)
Copy link
Contributor

Choose a reason for hiding this comment

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

remove commented out code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops, done

@quentin-cha
Copy link
Contributor Author

Thanks again for helping me out!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants