From df4ec479958e07e529d8b0542e08f192527a2b41 Mon Sep 17 00:00:00 2001 From: Menghan Li Date: Thu, 23 Mar 2017 16:57:46 -0700 Subject: [PATCH] Add grpc.Version string and use it in the UA --- clientconn.go | 8 ++++++++ rpc_util.go | 3 +++ transport/http2_client.go | 6 +----- transport/http_util.go | 2 -- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/clientconn.go b/clientconn.go index 19f9a3798bf4..c3fa9770e00e 100644 --- a/clientconn.go +++ b/clientconn.go @@ -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) diff --git a/rpc_util.go b/rpc_util.go index 73c3a96655d3..bd21c4c04dfa 100644 --- a/rpc_util.go +++ b/rpc_util.go @@ -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" diff --git a/transport/http2_client.go b/transport/http2_client.go index e68c9fd615a6..550fe713d17d 100644 --- a/transport/http2_client.go +++ b/transport/http2_client.go @@ -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 { @@ -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(), diff --git a/transport/http_util.go b/transport/http_util.go index a3c68d4cac7e..6ce43c332e61 100644 --- a/transport/http_util.go +++ b/transport/http_util.go @@ -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