1// Copyright 2019 Google LLC 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// https://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15// Code generated by gapic-generator. DO NOT EDIT. 16 17package debugger 18 19import ( 20 "context" 21 "fmt" 22 "time" 23 24 gax "github.com/googleapis/gax-go/v2" 25 "google.golang.org/api/option" 26 "google.golang.org/api/transport" 27 clouddebuggerpb "google.golang.org/genproto/googleapis/devtools/clouddebugger/v2" 28 "google.golang.org/grpc" 29 "google.golang.org/grpc/codes" 30 "google.golang.org/grpc/metadata" 31) 32 33// Debugger2CallOptions contains the retry settings for each method of Debugger2Client. 34type Debugger2CallOptions struct { 35 SetBreakpoint []gax.CallOption 36 GetBreakpoint []gax.CallOption 37 DeleteBreakpoint []gax.CallOption 38 ListBreakpoints []gax.CallOption 39 ListDebuggees []gax.CallOption 40} 41 42func defaultDebugger2ClientOptions() []option.ClientOption { 43 return []option.ClientOption{ 44 option.WithEndpoint("clouddebugger.googleapis.com:443"), 45 option.WithScopes(DefaultAuthScopes()...), 46 } 47} 48 49func defaultDebugger2CallOptions() *Debugger2CallOptions { 50 retry := map[[2]string][]gax.CallOption{ 51 {"default", "idempotent"}: { 52 gax.WithRetry(func() gax.Retryer { 53 return gax.OnCodes([]codes.Code{ 54 codes.DeadlineExceeded, 55 codes.Unavailable, 56 }, gax.Backoff{ 57 Initial: 100 * time.Millisecond, 58 Max: 60000 * time.Millisecond, 59 Multiplier: 1.3, 60 }) 61 }), 62 }, 63 } 64 return &Debugger2CallOptions{ 65 SetBreakpoint: retry[[2]string{"default", "non_idempotent"}], 66 GetBreakpoint: retry[[2]string{"default", "idempotent"}], 67 DeleteBreakpoint: retry[[2]string{"default", "idempotent"}], 68 ListBreakpoints: retry[[2]string{"default", "idempotent"}], 69 ListDebuggees: retry[[2]string{"default", "idempotent"}], 70 } 71} 72 73// Debugger2Client is a client for interacting with Stackdriver Debugger API. 74// 75// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 76type Debugger2Client struct { 77 // The connection to the service. 78 conn *grpc.ClientConn 79 80 // The gRPC API client. 81 debugger2Client clouddebuggerpb.Debugger2Client 82 83 // The call options for this service. 84 CallOptions *Debugger2CallOptions 85 86 // The x-goog-* metadata to be sent with each request. 87 xGoogMetadata metadata.MD 88} 89 90// NewDebugger2Client creates a new debugger2 client. 91// 92// The Debugger service provides the API that allows users to collect run-time 93// information from a running application, without stopping or slowing it down 94// and without modifying its state. An application may include one or 95// more replicated processes performing the same work. 96// 97// A debugged application is represented using the Debuggee concept. The 98// Debugger service provides a way to query for available debuggees, but does 99// not provide a way to create one. A debuggee is created using the Controller 100// service, usually by running a debugger agent with the application. 101// 102// The Debugger service enables the client to set one or more Breakpoints on a 103// Debuggee and collect the results of the set Breakpoints. 104func NewDebugger2Client(ctx context.Context, opts ...option.ClientOption) (*Debugger2Client, error) { 105 conn, err := transport.DialGRPC(ctx, append(defaultDebugger2ClientOptions(), opts...)...) 106 if err != nil { 107 return nil, err 108 } 109 c := &Debugger2Client{ 110 conn: conn, 111 CallOptions: defaultDebugger2CallOptions(), 112 113 debugger2Client: clouddebuggerpb.NewDebugger2Client(conn), 114 } 115 c.SetGoogleClientInfo() 116 return c, nil 117} 118 119// Connection returns the client's connection to the API service. 120func (c *Debugger2Client) Connection() *grpc.ClientConn { 121 return c.conn 122} 123 124// Close closes the connection to the API service. The user should invoke this when 125// the client is no longer required. 126func (c *Debugger2Client) Close() error { 127 return c.conn.Close() 128} 129 130// SetGoogleClientInfo sets the name and version of the application in 131// the `x-goog-api-client` header passed on each request. Intended for 132// use by Google-written clients. 133func (c *Debugger2Client) SetGoogleClientInfo(keyval ...string) { 134 kv := append([]string{"gl-go", versionGo()}, keyval...) 135 kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version) 136 c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) 137} 138 139// SetBreakpoint sets the breakpoint to the debuggee. 140func (c *Debugger2Client) SetBreakpoint(ctx context.Context, req *clouddebuggerpb.SetBreakpointRequest, opts ...gax.CallOption) (*clouddebuggerpb.SetBreakpointResponse, error) { 141 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "debuggee_id", req.GetDebuggeeId())) 142 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 143 opts = append(c.CallOptions.SetBreakpoint[0:len(c.CallOptions.SetBreakpoint):len(c.CallOptions.SetBreakpoint)], opts...) 144 var resp *clouddebuggerpb.SetBreakpointResponse 145 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 146 var err error 147 resp, err = c.debugger2Client.SetBreakpoint(ctx, req, settings.GRPC...) 148 return err 149 }, opts...) 150 if err != nil { 151 return nil, err 152 } 153 return resp, nil 154} 155 156// GetBreakpoint gets breakpoint information. 157func (c *Debugger2Client) GetBreakpoint(ctx context.Context, req *clouddebuggerpb.GetBreakpointRequest, opts ...gax.CallOption) (*clouddebuggerpb.GetBreakpointResponse, error) { 158 ctx = insertMetadata(ctx, c.xGoogMetadata) 159 opts = append(c.CallOptions.GetBreakpoint[0:len(c.CallOptions.GetBreakpoint):len(c.CallOptions.GetBreakpoint)], opts...) 160 var resp *clouddebuggerpb.GetBreakpointResponse 161 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 162 var err error 163 resp, err = c.debugger2Client.GetBreakpoint(ctx, req, settings.GRPC...) 164 return err 165 }, opts...) 166 if err != nil { 167 return nil, err 168 } 169 return resp, nil 170} 171 172// DeleteBreakpoint deletes the breakpoint from the debuggee. 173func (c *Debugger2Client) DeleteBreakpoint(ctx context.Context, req *clouddebuggerpb.DeleteBreakpointRequest, opts ...gax.CallOption) error { 174 ctx = insertMetadata(ctx, c.xGoogMetadata) 175 opts = append(c.CallOptions.DeleteBreakpoint[0:len(c.CallOptions.DeleteBreakpoint):len(c.CallOptions.DeleteBreakpoint)], opts...) 176 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 177 var err error 178 _, err = c.debugger2Client.DeleteBreakpoint(ctx, req, settings.GRPC...) 179 return err 180 }, opts...) 181 return err 182} 183 184// ListBreakpoints lists all breakpoints for the debuggee. 185func (c *Debugger2Client) ListBreakpoints(ctx context.Context, req *clouddebuggerpb.ListBreakpointsRequest, opts ...gax.CallOption) (*clouddebuggerpb.ListBreakpointsResponse, error) { 186 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "debuggee_id", req.GetDebuggeeId())) 187 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 188 opts = append(c.CallOptions.ListBreakpoints[0:len(c.CallOptions.ListBreakpoints):len(c.CallOptions.ListBreakpoints)], opts...) 189 var resp *clouddebuggerpb.ListBreakpointsResponse 190 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 191 var err error 192 resp, err = c.debugger2Client.ListBreakpoints(ctx, req, settings.GRPC...) 193 return err 194 }, opts...) 195 if err != nil { 196 return nil, err 197 } 198 return resp, nil 199} 200 201// ListDebuggees lists all the debuggees that the user has access to. 202func (c *Debugger2Client) ListDebuggees(ctx context.Context, req *clouddebuggerpb.ListDebuggeesRequest, opts ...gax.CallOption) (*clouddebuggerpb.ListDebuggeesResponse, error) { 203 ctx = insertMetadata(ctx, c.xGoogMetadata) 204 opts = append(c.CallOptions.ListDebuggees[0:len(c.CallOptions.ListDebuggees):len(c.CallOptions.ListDebuggees)], opts...) 205 var resp *clouddebuggerpb.ListDebuggeesResponse 206 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 207 var err error 208 resp, err = c.debugger2Client.ListDebuggees(ctx, req, settings.GRPC...) 209 return err 210 }, opts...) 211 if err != nil { 212 return nil, err 213 } 214 return resp, nil 215} 216