Skip to content

Commit

Permalink
Add grpc.Version string and use it in the UA (#1144)
Browse files Browse the repository at this point in the history
  • Loading branch information
menghanl authored Mar 24, 2017
1 parent 0a20758 commit 14a6be4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
8 changes: 8 additions & 0 deletions clientconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,14 @@ func DialContext(ctx context.Context, target string, opts ...DialOption) (conn *
for _, opt := range opts {
opt(&cc.dopts)
}

grpcUA := "grpc-go/" + Version
if cc.dopts.copts.UserAgent != "" {
cc.dopts.copts.UserAgent += " " + grpcUA
} else {
cc.dopts.copts.UserAgent = grpcUA
}

if cc.dopts.timeout > 0 {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(ctx, cc.dopts.timeout)
Expand Down
3 changes: 3 additions & 0 deletions rpc_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,3 +527,6 @@ type ServiceConfig struct {
// requires a synchronised update of grpc-go and protoc-gen-go. This constant
// should not be referenced from any other code.
const SupportPackageIsVersion4 = true

// Version is the current grpc version.
const Version = "1.3.0-dev"
6 changes: 1 addition & 5 deletions transport/http2_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,6 @@ func newHTTP2Client(ctx context.Context, addr TargetInfo, opts ConnectOptions) (
return nil, connectionErrorf(temp, err, "transport: %v", err)
}
}
ua := primaryUA
if opts.UserAgent != "" {
ua = opts.UserAgent + " " + ua
}
kp := opts.KeepaliveParams
// Validate keepalive parameters.
if kp.Time == 0 {
Expand All @@ -203,7 +199,7 @@ func newHTTP2Client(ctx context.Context, addr TargetInfo, opts ConnectOptions) (
t := &http2Client{
ctx: ctx,
target: addr.Addr,
userAgent: ua,
userAgent: opts.UserAgent,
md: addr.Metadata,
conn: conn,
remoteAddr: conn.RemoteAddr(),
Expand Down
2 changes: 0 additions & 2 deletions transport/http_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ import (
)

const (
// The primary user agent
primaryUA = "grpc-go/1.0"
// http2MaxFrameLen specifies the max length of a HTTP2 frame.
http2MaxFrameLen = 16384 // 16KB frame
// http://http2.github.io/http2-spec/#SettingValues
Expand Down

0 comments on commit 14a6be4

Please sign in to comment.