Skip to content

Commit 14a6be4

Browse files
authored
Add grpc.Version string and use it in the UA (#1144)
1 parent 0a20758 commit 14a6be4

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

clientconn.go

+8
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,14 @@ func DialContext(ctx context.Context, target string, opts ...DialOption) (conn *
310310
for _, opt := range opts {
311311
opt(&cc.dopts)
312312
}
313+
314+
grpcUA := "grpc-go/" + Version
315+
if cc.dopts.copts.UserAgent != "" {
316+
cc.dopts.copts.UserAgent += " " + grpcUA
317+
} else {
318+
cc.dopts.copts.UserAgent = grpcUA
319+
}
320+
313321
if cc.dopts.timeout > 0 {
314322
var cancel context.CancelFunc
315323
ctx, cancel = context.WithTimeout(ctx, cc.dopts.timeout)

rpc_util.go

+3
Original file line numberDiff line numberDiff line change
@@ -527,3 +527,6 @@ type ServiceConfig struct {
527527
// requires a synchronised update of grpc-go and protoc-gen-go. This constant
528528
// should not be referenced from any other code.
529529
const SupportPackageIsVersion4 = true
530+
531+
// Version is the current grpc version.
532+
const Version = "1.3.0-dev"

transport/http2_client.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,6 @@ func newHTTP2Client(ctx context.Context, addr TargetInfo, opts ConnectOptions) (
187187
return nil, connectionErrorf(temp, err, "transport: %v", err)
188188
}
189189
}
190-
ua := primaryUA
191-
if opts.UserAgent != "" {
192-
ua = opts.UserAgent + " " + ua
193-
}
194190
kp := opts.KeepaliveParams
195191
// Validate keepalive parameters.
196192
if kp.Time == 0 {
@@ -203,7 +199,7 @@ func newHTTP2Client(ctx context.Context, addr TargetInfo, opts ConnectOptions) (
203199
t := &http2Client{
204200
ctx: ctx,
205201
target: addr.Addr,
206-
userAgent: ua,
202+
userAgent: opts.UserAgent,
207203
md: addr.Metadata,
208204
conn: conn,
209205
remoteAddr: conn.RemoteAddr(),

transport/http_util.go

-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ import (
5252
)
5353

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

0 commit comments

Comments
 (0)