Skip to content

Commit

Permalink
regenerate toolkit client
Browse files Browse the repository at this point in the history
Fixes x-goog-api-client header.

Change-Id: Ie8f1e34936349c49ec565f4d87f3bafeb3ebdd21
Reviewed-on: https://code-review.googlesource.com/11391
Reviewed-by: kokoro <[email protected]>
Reviewed-by: Jonathan Amsterdam <[email protected]>
  • Loading branch information
pongad committed Mar 8, 2017
1 parent 960c768 commit df9740f
Show file tree
Hide file tree
Showing 24 changed files with 263 additions and 115 deletions.
39 changes: 22 additions & 17 deletions debugger/apiv2/controller2_client.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016, Google Inc. All rights reserved.
// Copyright 2017, Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -17,19 +17,16 @@
package debugger

import (
"fmt"
"runtime"
"strings"
"time"

"cloud.google.com/go/internal/version"
gax "github.com/googleapis/gax-go"
"golang.org/x/net/context"
"google.golang.org/api/option"
"google.golang.org/api/transport"
clouddebuggerpb "google.golang.org/genproto/googleapis/devtools/clouddebugger/v2"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
)

// Controller2CallOptions contains the retry settings for each method of Controller2Client.
Expand Down Expand Up @@ -63,6 +60,17 @@ func defaultController2CallOptions() *Controller2CallOptions {
})
}),
},
{"default", "non_idempotent"}: {
gax.WithRetry(func() gax.Retryer {
return gax.OnCodes([]codes.Code{
codes.Unavailable,
}, gax.Backoff{
Initial: 100 * time.Millisecond,
Max: 60000 * time.Millisecond,
Multiplier: 1.3,
})
}),
},
}
return &Controller2CallOptions{
RegisterDebuggee: retry[[2]string{"default", "non_idempotent"}],
Expand All @@ -83,7 +91,7 @@ type Controller2Client struct {
CallOptions *Controller2CallOptions

// The metadata to be sent with each request.
metadata metadata.MD
xGoogHeader string
}

// NewController2Client creates a new controller2 client.
Expand Down Expand Up @@ -119,7 +127,7 @@ func NewController2Client(ctx context.Context, opts ...option.ClientOption) (*Co

controller2Client: clouddebuggerpb.NewController2Client(conn),
}
c.SetGoogleClientInfo("gax", gax.Version)
c.SetGoogleClientInfo()
return c, nil
}

Expand All @@ -137,10 +145,10 @@ func (c *Controller2Client) Close() error {
// SetGoogleClientInfo sets the name and version of the application in
// the `x-goog-api-client` header passed on each request. Intended for
// use by Google-written clients.
func (c *Controller2Client) SetGoogleClientInfo(name, version string) {
goVersion := strings.Replace(runtime.Version(), " ", "_", -1)
v := fmt.Sprintf("%s/%s %s gax/%s go/%s", name, version, gapicNameVersion, gax.Version, goVersion)
c.metadata = metadata.Pairs("x-goog-api-client", v)
func (c *Controller2Client) SetGoogleClientInfo(keyval ...string) {
kv := append([]string{"gl-go", version.Go()}, keyval...)
kv = append(kv, "gapic", version.Repo, "gax", gax.Version, "grpc", "")
c.xGoogHeader = gax.XGoogHeader(kv...)
}

// RegisterDebuggee registers the debuggee with the controller service.
Expand All @@ -154,8 +162,7 @@ func (c *Controller2Client) SetGoogleClientInfo(name, version string) {
// data loss. If the debuggee is disabled by the server, the response will
// have `is_disabled` set to `true`.
func (c *Controller2Client) RegisterDebuggee(ctx context.Context, req *clouddebuggerpb.RegisterDebuggeeRequest) (*clouddebuggerpb.RegisterDebuggeeResponse, error) {
md, _ := metadata.FromContext(ctx)
ctx = metadata.NewContext(ctx, metadata.Join(md, c.metadata))
ctx = insertXGoog(ctx, c.xGoogHeader)
var resp *clouddebuggerpb.RegisterDebuggeeResponse
err := gax.Invoke(ctx, func(ctx context.Context) error {
var err error
Expand All @@ -182,8 +189,7 @@ func (c *Controller2Client) RegisterDebuggee(ctx context.Context, req *clouddebu
// until the controller removes them from the active list to avoid
// setting those breakpoints again.
func (c *Controller2Client) ListActiveBreakpoints(ctx context.Context, req *clouddebuggerpb.ListActiveBreakpointsRequest) (*clouddebuggerpb.ListActiveBreakpointsResponse, error) {
md, _ := metadata.FromContext(ctx)
ctx = metadata.NewContext(ctx, metadata.Join(md, c.metadata))
ctx = insertXGoog(ctx, c.xGoogHeader)
var resp *clouddebuggerpb.ListActiveBreakpointsResponse
err := gax.Invoke(ctx, func(ctx context.Context) error {
var err error
Expand All @@ -206,8 +212,7 @@ func (c *Controller2Client) ListActiveBreakpoints(ctx context.Context, req *clou
// semantics. These may only make changes such as canonicalizing a value
// or snapping the location to the correct line of code.
func (c *Controller2Client) UpdateActiveBreakpoint(ctx context.Context, req *clouddebuggerpb.UpdateActiveBreakpointRequest) (*clouddebuggerpb.UpdateActiveBreakpointResponse, error) {
md, _ := metadata.FromContext(ctx)
ctx = metadata.NewContext(ctx, metadata.Join(md, c.metadata))
ctx = insertXGoog(ctx, c.xGoogHeader)
var resp *clouddebuggerpb.UpdateActiveBreakpointResponse
err := gax.Invoke(ctx, func(ctx context.Context) error {
var err error
Expand Down
2 changes: 1 addition & 1 deletion debugger/apiv2/controller2_client_example_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016, Google Inc. All rights reserved.
// Copyright 2017, Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
45 changes: 24 additions & 21 deletions debugger/apiv2/debugger2_client.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016, Google Inc. All rights reserved.
// Copyright 2017, Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -17,19 +17,16 @@
package debugger

import (
"fmt"
"runtime"
"strings"
"time"

"cloud.google.com/go/internal/version"
gax "github.com/googleapis/gax-go"
"golang.org/x/net/context"
"google.golang.org/api/option"
"google.golang.org/api/transport"
clouddebuggerpb "google.golang.org/genproto/googleapis/devtools/clouddebugger/v2"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
)

// Debugger2CallOptions contains the retry settings for each method of Debugger2Client.
Expand Down Expand Up @@ -65,6 +62,17 @@ func defaultDebugger2CallOptions() *Debugger2CallOptions {
})
}),
},
{"default", "non_idempotent"}: {
gax.WithRetry(func() gax.Retryer {
return gax.OnCodes([]codes.Code{
codes.Unavailable,
}, gax.Backoff{
Initial: 100 * time.Millisecond,
Max: 60000 * time.Millisecond,
Multiplier: 1.3,
})
}),
},
}
return &Debugger2CallOptions{
SetBreakpoint: retry[[2]string{"default", "non_idempotent"}],
Expand All @@ -87,7 +95,7 @@ type Debugger2Client struct {
CallOptions *Debugger2CallOptions

// The metadata to be sent with each request.
metadata metadata.MD
xGoogHeader string
}

// NewDebugger2Client creates a new debugger2 client.
Expand Down Expand Up @@ -115,7 +123,7 @@ func NewDebugger2Client(ctx context.Context, opts ...option.ClientOption) (*Debu

debugger2Client: clouddebuggerpb.NewDebugger2Client(conn),
}
c.SetGoogleClientInfo("gax", gax.Version)
c.SetGoogleClientInfo()
return c, nil
}

Expand All @@ -133,16 +141,15 @@ func (c *Debugger2Client) Close() error {
// SetGoogleClientInfo sets the name and version of the application in
// the `x-goog-api-client` header passed on each request. Intended for
// use by Google-written clients.
func (c *Debugger2Client) SetGoogleClientInfo(name, version string) {
goVersion := strings.Replace(runtime.Version(), " ", "_", -1)
v := fmt.Sprintf("%s/%s %s gax/%s go/%s", name, version, gapicNameVersion, gax.Version, goVersion)
c.metadata = metadata.Pairs("x-goog-api-client", v)
func (c *Debugger2Client) SetGoogleClientInfo(keyval ...string) {
kv := append([]string{"gl-go", version.Go()}, keyval...)
kv = append(kv, "gapic", version.Repo, "gax", gax.Version, "grpc", "")
c.xGoogHeader = gax.XGoogHeader(kv...)
}

// SetBreakpoint sets the breakpoint to the debuggee.
func (c *Debugger2Client) SetBreakpoint(ctx context.Context, req *clouddebuggerpb.SetBreakpointRequest) (*clouddebuggerpb.SetBreakpointResponse, error) {
md, _ := metadata.FromContext(ctx)
ctx = metadata.NewContext(ctx, metadata.Join(md, c.metadata))
ctx = insertXGoog(ctx, c.xGoogHeader)
var resp *clouddebuggerpb.SetBreakpointResponse
err := gax.Invoke(ctx, func(ctx context.Context) error {
var err error
Expand All @@ -157,8 +164,7 @@ func (c *Debugger2Client) SetBreakpoint(ctx context.Context, req *clouddebuggerp

// GetBreakpoint gets breakpoint information.
func (c *Debugger2Client) GetBreakpoint(ctx context.Context, req *clouddebuggerpb.GetBreakpointRequest) (*clouddebuggerpb.GetBreakpointResponse, error) {
md, _ := metadata.FromContext(ctx)
ctx = metadata.NewContext(ctx, metadata.Join(md, c.metadata))
ctx = insertXGoog(ctx, c.xGoogHeader)
var resp *clouddebuggerpb.GetBreakpointResponse
err := gax.Invoke(ctx, func(ctx context.Context) error {
var err error
Expand All @@ -173,8 +179,7 @@ func (c *Debugger2Client) GetBreakpoint(ctx context.Context, req *clouddebuggerp

// DeleteBreakpoint deletes the breakpoint from the debuggee.
func (c *Debugger2Client) DeleteBreakpoint(ctx context.Context, req *clouddebuggerpb.DeleteBreakpointRequest) error {
md, _ := metadata.FromContext(ctx)
ctx = metadata.NewContext(ctx, metadata.Join(md, c.metadata))
ctx = insertXGoog(ctx, c.xGoogHeader)
err := gax.Invoke(ctx, func(ctx context.Context) error {
var err error
_, err = c.debugger2Client.DeleteBreakpoint(ctx, req)
Expand All @@ -185,8 +190,7 @@ func (c *Debugger2Client) DeleteBreakpoint(ctx context.Context, req *clouddebugg

// ListBreakpoints lists all breakpoints for the debuggee.
func (c *Debugger2Client) ListBreakpoints(ctx context.Context, req *clouddebuggerpb.ListBreakpointsRequest) (*clouddebuggerpb.ListBreakpointsResponse, error) {
md, _ := metadata.FromContext(ctx)
ctx = metadata.NewContext(ctx, metadata.Join(md, c.metadata))
ctx = insertXGoog(ctx, c.xGoogHeader)
var resp *clouddebuggerpb.ListBreakpointsResponse
err := gax.Invoke(ctx, func(ctx context.Context) error {
var err error
Expand All @@ -201,8 +205,7 @@ func (c *Debugger2Client) ListBreakpoints(ctx context.Context, req *clouddebugge

// ListDebuggees lists all the debuggees that the user can set breakpoints to.
func (c *Debugger2Client) ListDebuggees(ctx context.Context, req *clouddebuggerpb.ListDebuggeesRequest) (*clouddebuggerpb.ListDebuggeesResponse, error) {
md, _ := metadata.FromContext(ctx)
ctx = metadata.NewContext(ctx, metadata.Join(md, c.metadata))
ctx = insertXGoog(ctx, c.xGoogHeader)
var resp *clouddebuggerpb.ListDebuggeesResponse
err := gax.Invoke(ctx, func(ctx context.Context) error {
var err error
Expand Down
2 changes: 1 addition & 1 deletion debugger/apiv2/debugger2_client_example_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016, Google Inc. All rights reserved.
// Copyright 2017, Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
14 changes: 12 additions & 2 deletions debugger/apiv2/doc.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016, Google Inc. All rights reserved.
// Copyright 2017, Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -23,4 +23,14 @@
// Use the client at cloud.google.com/go/cmd/go-cloud-debug-agent in preference to this.
package debugger // import "cloud.google.com/go/debugger/apiv2"

const gapicNameVersion = "gapic/0.1.0"
import (
"golang.org/x/net/context"
"google.golang.org/grpc/metadata"
)

func insertXGoog(ctx context.Context, val string) context.Context {
md, _ := metadata.FromContext(ctx)
md = md.Copy()
md["x-goog-api-client"] = []string{val}
return metadata.NewContext(ctx, md)
}
2 changes: 1 addition & 1 deletion debugger/apiv2/mock_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016, Google Inc. All rights reserved.
// Copyright 2017, Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
9 changes: 5 additions & 4 deletions errorreporting/apiv1beta1/error_group_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package errorreporting

import (
"fmt"
"time"

"cloud.google.com/go/internal/version"
Expand Down Expand Up @@ -99,7 +98,7 @@ func NewErrorGroupClient(ctx context.Context, opts ...option.ClientOption) (*Err

errorGroupClient: clouderrorreportingpb.NewErrorGroupServiceClient(conn),
}
c.SetGoogleClientInfo("gapic", version.Repo)
c.SetGoogleClientInfo()
return c, nil
}

Expand All @@ -117,8 +116,10 @@ func (c *ErrorGroupClient) Close() error {
// SetGoogleClientInfo sets the name and version of the application in
// the `x-goog-api-client` header passed on each request. Intended for
// use by Google-written clients.
func (c *ErrorGroupClient) SetGoogleClientInfo(clientName, clientVersion string) {
c.xGoogHeader = fmt.Sprintf("gl-go/%s %s/%s gax/%s grpc/", version.Go(), clientName, clientVersion, gax.Version)
func (c *ErrorGroupClient) SetGoogleClientInfo(keyval ...string) {
kv := append([]string{"gl-go", version.Go()}, keyval...)
kv = append(kv, "gapic", version.Repo, "gax", gax.Version, "grpc", "")
c.xGoogHeader = gax.XGoogHeader(kv...)
}

// ErrorGroupGroupPath returns the path for the group resource.
Expand Down
9 changes: 5 additions & 4 deletions errorreporting/apiv1beta1/error_stats_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package errorreporting

import (
"fmt"
"math"
"time"

Expand Down Expand Up @@ -104,7 +103,7 @@ func NewErrorStatsClient(ctx context.Context, opts ...option.ClientOption) (*Err

errorStatsClient: clouderrorreportingpb.NewErrorStatsServiceClient(conn),
}
c.SetGoogleClientInfo("gapic", version.Repo)
c.SetGoogleClientInfo()
return c, nil
}

Expand All @@ -122,8 +121,10 @@ func (c *ErrorStatsClient) Close() error {
// SetGoogleClientInfo sets the name and version of the application in
// the `x-goog-api-client` header passed on each request. Intended for
// use by Google-written clients.
func (c *ErrorStatsClient) SetGoogleClientInfo(clientName, clientVersion string) {
c.xGoogHeader = fmt.Sprintf("gl-go/%s %s/%s gax/%s grpc/", version.Go(), clientName, clientVersion, gax.Version)
func (c *ErrorStatsClient) SetGoogleClientInfo(keyval ...string) {
kv := append([]string{"gl-go", version.Go()}, keyval...)
kv = append(kv, "gapic", version.Repo, "gax", gax.Version, "grpc", "")
c.xGoogHeader = gax.XGoogHeader(kv...)
}

// ErrorStatsProjectPath returns the path for the project resource.
Expand Down
25 changes: 20 additions & 5 deletions errorreporting/apiv1beta1/report_errors_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package errorreporting

import (
"fmt"
"time"

"cloud.google.com/go/internal/version"
gax "github.com/googleapis/gax-go"
Expand All @@ -26,6 +26,7 @@ import (
"google.golang.org/api/transport"
clouderrorreportingpb "google.golang.org/genproto/googleapis/devtools/clouderrorreporting/v1beta1"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
)

var (
Expand All @@ -47,7 +48,19 @@ func defaultReportErrorsClientOptions() []option.ClientOption {
}

func defaultReportErrorsCallOptions() *ReportErrorsCallOptions {
retry := map[[2]string][]gax.CallOption{}
retry := map[[2]string][]gax.CallOption{
{"default", "non_idempotent"}: {
gax.WithRetry(func() gax.Retryer {
return gax.OnCodes([]codes.Code{
codes.Unavailable,
}, gax.Backoff{
Initial: 100 * time.Millisecond,
Max: 60000 * time.Millisecond,
Multiplier: 1.3,
})
}),
},
}
return &ReportErrorsCallOptions{
ReportErrorEvent: retry[[2]string{"default", "non_idempotent"}],
}
Expand Down Expand Up @@ -82,7 +95,7 @@ func NewReportErrorsClient(ctx context.Context, opts ...option.ClientOption) (*R

reportErrorsClient: clouderrorreportingpb.NewReportErrorsServiceClient(conn),
}
c.SetGoogleClientInfo("gapic", version.Repo)
c.SetGoogleClientInfo()
return c, nil
}

Expand All @@ -100,8 +113,10 @@ func (c *ReportErrorsClient) Close() error {
// SetGoogleClientInfo sets the name and version of the application in
// the `x-goog-api-client` header passed on each request. Intended for
// use by Google-written clients.
func (c *ReportErrorsClient) SetGoogleClientInfo(clientName, clientVersion string) {
c.xGoogHeader = fmt.Sprintf("gl-go/%s %s/%s gax/%s grpc/", version.Go(), clientName, clientVersion, gax.Version)
func (c *ReportErrorsClient) SetGoogleClientInfo(keyval ...string) {
kv := append([]string{"gl-go", version.Go()}, keyval...)
kv = append(kv, "gapic", version.Repo, "gax", gax.Version, "grpc", "")
c.xGoogHeader = gax.XGoogHeader(kv...)
}

// ReportErrorsProjectPath returns the path for the project resource.
Expand Down
Loading

0 comments on commit df9740f

Please sign in to comment.