-
Notifications
You must be signed in to change notification settings - Fork 327
gRPC integration #12
gRPC integration #12
Conversation
…nly supportted in 1.8 and above
…e and aggregator. Also added equality as an interface to aggregationValue
…ains()... Also renamed some methods to be more succint and fixed some documentation issues
…ntually support conversions to other formats
…strumentation-go Resync fork to upstream/master
plugins/grpc/handlers.go
Outdated
package stats | ||
|
||
import ( | ||
"context" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gRPC-go still imports "golang.org/x/net/context"
(grpc/grpc-go#711).
It will be a massive incompatible API change for all users using <=go1.8 if we change that.
go treats func("context".Context)
and func("golang.org/x/net/context".Context)
as two different types, which means the stats handler here won't work (it doesn't compile, with <=go1.8).
go1.9 introduced a new feature called type alias, which makes "golang.org/x/net/context"
and "context"
the same type. So, this actually works fine with >=go1.9.
The solution I can think of right now is to import "golang.org/x/net/context"
in the stats package.
Or, if we decide that the stats package only supports users with >=go1.9, the current code will be fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is our first release, I think we should avoid creating unnecessary confusion and say that we support >= go1.9 if using stats with grpc.
Wondering if @rakyll have a different opinion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about it more. I think it is better to use "golang.org/x/net/context" so we can get more adoption and since once everybody moves beyond 1.8 it will be easy to move to "context".Context
plugins/grpc/stats/client_handler.go
Outdated
|
||
// ClientHandler is the type implementing the "google.golang.org/grpc/stats.Handler" | ||
// interface to process lifecycle events from the GRPC client. | ||
type ClientHandler struct{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unexport this and add an exported function instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I understand your comment. You mean adding an exported "constructor" for it: eg func NewClientHandler() stats.Handler {...}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
plugins/grpc/stats/client_handler.go
Outdated
ctx = metadata.NewOutgoingContext(ctx, metadata.Join(md, metadata.Pairs(tagsKey, string(encoded)))) | ||
|
||
tsb := tags.NewTagSetBuilder(ts) | ||
tsb.UpsertString(keyService, serviceName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this function return a TagSetBuilder
if it's called to update the builder?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make it easier to use the shortcut version when modifying multiple tags. It returns the same TagSetBuilder. It is just a syntactic sugar to allow for the short form:
tags.NewTagSetBuilder(ts).UpsertString(keyService, serviceName).UpsertString(key2, value2).AddString(key3, value3)...
@@ -0,0 +1,75 @@ | |||
// Copyright 2017, OpenCensus Authors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some files are Copyright 2017 Google Inc.
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Thank you. Fixed now.
plugins/grpc/stats/server_handler.go
Outdated
"github.com/golang/glog" | ||
"google.golang.org/grpc/metadata" | ||
"google.golang.org/grpc/stats" | ||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
plugins/grpc/stats/types.go
Outdated
// tagsKey is the metadata key used to identify both the stats tags in the GRPC | ||
// context metadata, as well as the RpcServerStats info sent back from the | ||
// server to the client in the GRPC context metadata. | ||
const tagsKey = "grpc-tags-bin" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metadata keys start with grpc-
are actually reserved, so we should avoid having a grpc-
prefixed key explicitly in the code...
To make this work, we added functions to set/get trace info: https://github.com/grpc/grpc-go/blob/master/stats/stats.go#L269.
Please use the new functions instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
stats/aggregation_value.go
Outdated
return &AggregationDistributionValue{ | ||
countPerBucket: countPerBucket, | ||
bounds: bounds, | ||
count: count, | ||
min: min, | ||
max: max, | ||
sum: sum, | ||
mean: mean, | ||
sumOfSquaredDeviation: sumOfSquaredDeviation, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not formatted correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
stats/aggregation_value.go
Outdated
ret.sum = ret.min | ||
ret.incrementBucketCount(ret.min) | ||
return ret | ||
ret := newAggregationDistributionValue(a.bounds) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you miss anything? Parameter fraction
is not used in this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is part of the interface signature: "type AggregationValue interface".
We decided that for this specific aggregation we will not use the "fraction" for simplicity
…for Go1.9 to integrate with libraries still using golang.org/x/net/context.Context. Fixed the license headings to refer to opencensus instead of google.
…ontext by golang.org/x/net/context and reduced the requirement to 1.8
…ggregationDistributionValue
…tingAggregationDistributionValue in server_handler_test.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two nits, otherwise LGTM.
README.md
Outdated
@@ -20,7 +20,8 @@ To install this package, you need to install Go and setup your Go workspace on y | |||
$ go get -u github.com/census-instrumentation/opencensus-go | |||
|
|||
## Prerequisites | |||
This requires Go 1.8 or later as it uses the convenience function sort.Slice(...) in few places. | |||
This requires Go 1.8 or later as it uses the convenience function sort.Slice(...) introduced in Go 1.8. | |||
It also uses "golang.org/x/net/context".Context introduced in Go 1.7 heavily. Therefore, in order to integrate with any library still using "golang.org/x/net/context".Context, Go 1.9 or higher is required to take advantage of type aliasing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to keep this line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No we don't. Deleted it.
plugins/grpc/stats/client_handler.go
Outdated
package stats | ||
|
||
import ( | ||
"golang.org/x/net/context" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
goimports
would complain about the order of the imported packages.
We do those checks on travis in gRPC: https://github.com/menghanl/grpc-go/blob/master/vet.sh#L51-L54
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Fixed.
Added grpc handlers.
Added sumOfSquaredDeviation to aggregation distribution (to mimic stackdriver) and simplified its implementation to always include the oldest bucket.