1// Copyright 2021 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 protoc-gen-go_gapic. DO NOT EDIT.
16
17package debugger
18
19import (
20	"context"
21	"fmt"
22	"math"
23	"net/url"
24	"time"
25
26	gax "github.com/googleapis/gax-go/v2"
27	"google.golang.org/api/option"
28	"google.golang.org/api/option/internaloption"
29	gtransport "google.golang.org/api/transport/grpc"
30	clouddebuggerpb "google.golang.org/genproto/googleapis/devtools/clouddebugger/v2"
31	"google.golang.org/grpc"
32	"google.golang.org/grpc/codes"
33	"google.golang.org/grpc/metadata"
34)
35
36var newDebugger2ClientHook clientHook
37
38// Debugger2CallOptions contains the retry settings for each method of Debugger2Client.
39type Debugger2CallOptions struct {
40	SetBreakpoint    []gax.CallOption
41	GetBreakpoint    []gax.CallOption
42	DeleteBreakpoint []gax.CallOption
43	ListBreakpoints  []gax.CallOption
44	ListDebuggees    []gax.CallOption
45}
46
47func defaultDebugger2GRPCClientOptions() []option.ClientOption {
48	return []option.ClientOption{
49		internaloption.WithDefaultEndpoint("clouddebugger.googleapis.com:443"),
50		internaloption.WithDefaultMTLSEndpoint("clouddebugger.mtls.googleapis.com:443"),
51		internaloption.WithDefaultAudience("https://clouddebugger.googleapis.com/"),
52		internaloption.WithDefaultScopes(DefaultAuthScopes()...),
53		internaloption.EnableJwtWithScope(),
54		option.WithGRPCDialOption(grpc.WithDisableServiceConfig()),
55		option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
56			grpc.MaxCallRecvMsgSize(math.MaxInt32))),
57	}
58}
59
60func defaultDebugger2CallOptions() *Debugger2CallOptions {
61	return &Debugger2CallOptions{
62		SetBreakpoint: []gax.CallOption{},
63		GetBreakpoint: []gax.CallOption{
64			gax.WithRetry(func() gax.Retryer {
65				return gax.OnCodes([]codes.Code{
66					codes.Unavailable,
67					codes.DeadlineExceeded,
68				}, gax.Backoff{
69					Initial:    100 * time.Millisecond,
70					Max:        60000 * time.Millisecond,
71					Multiplier: 1.30,
72				})
73			}),
74		},
75		DeleteBreakpoint: []gax.CallOption{
76			gax.WithRetry(func() gax.Retryer {
77				return gax.OnCodes([]codes.Code{
78					codes.Unavailable,
79					codes.DeadlineExceeded,
80				}, gax.Backoff{
81					Initial:    100 * time.Millisecond,
82					Max:        60000 * time.Millisecond,
83					Multiplier: 1.30,
84				})
85			}),
86		},
87		ListBreakpoints: []gax.CallOption{
88			gax.WithRetry(func() gax.Retryer {
89				return gax.OnCodes([]codes.Code{
90					codes.Unavailable,
91					codes.DeadlineExceeded,
92				}, gax.Backoff{
93					Initial:    100 * time.Millisecond,
94					Max:        60000 * time.Millisecond,
95					Multiplier: 1.30,
96				})
97			}),
98		},
99		ListDebuggees: []gax.CallOption{
100			gax.WithRetry(func() gax.Retryer {
101				return gax.OnCodes([]codes.Code{
102					codes.Unavailable,
103					codes.DeadlineExceeded,
104				}, gax.Backoff{
105					Initial:    100 * time.Millisecond,
106					Max:        60000 * time.Millisecond,
107					Multiplier: 1.30,
108				})
109			}),
110		},
111	}
112}
113
114// internalDebugger2Client is an interface that defines the methods availaible from Stackdriver Debugger API.
115type internalDebugger2Client interface {
116	Close() error
117	setGoogleClientInfo(...string)
118	Connection() *grpc.ClientConn
119	SetBreakpoint(context.Context, *clouddebuggerpb.SetBreakpointRequest, ...gax.CallOption) (*clouddebuggerpb.SetBreakpointResponse, error)
120	GetBreakpoint(context.Context, *clouddebuggerpb.GetBreakpointRequest, ...gax.CallOption) (*clouddebuggerpb.GetBreakpointResponse, error)
121	DeleteBreakpoint(context.Context, *clouddebuggerpb.DeleteBreakpointRequest, ...gax.CallOption) error
122	ListBreakpoints(context.Context, *clouddebuggerpb.ListBreakpointsRequest, ...gax.CallOption) (*clouddebuggerpb.ListBreakpointsResponse, error)
123	ListDebuggees(context.Context, *clouddebuggerpb.ListDebuggeesRequest, ...gax.CallOption) (*clouddebuggerpb.ListDebuggeesResponse, error)
124}
125
126// Debugger2Client is a client for interacting with Stackdriver Debugger API.
127// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
128//
129// The Debugger service provides the API that allows users to collect run-time
130// information from a running application, without stopping or slowing it down
131// and without modifying its state.  An application may include one or
132// more replicated processes performing the same work.
133//
134// A debugged application is represented using the Debuggee concept. The
135// Debugger service provides a way to query for available debuggees, but does
136// not provide a way to create one.  A debuggee is created using the Controller
137// service, usually by running a debugger agent with the application.
138//
139// The Debugger service enables the client to set one or more Breakpoints on a
140// Debuggee and collect the results of the set Breakpoints.
141type Debugger2Client struct {
142	// The internal transport-dependent client.
143	internalClient internalDebugger2Client
144
145	// The call options for this service.
146	CallOptions *Debugger2CallOptions
147}
148
149// Wrapper methods routed to the internal client.
150
151// Close closes the connection to the API service. The user should invoke this when
152// the client is no longer required.
153func (c *Debugger2Client) Close() error {
154	return c.internalClient.Close()
155}
156
157// setGoogleClientInfo sets the name and version of the application in
158// the `x-goog-api-client` header passed on each request. Intended for
159// use by Google-written clients.
160func (c *Debugger2Client) setGoogleClientInfo(keyval ...string) {
161	c.internalClient.setGoogleClientInfo(keyval...)
162}
163
164// Connection returns a connection to the API service.
165//
166// Deprecated.
167func (c *Debugger2Client) Connection() *grpc.ClientConn {
168	return c.internalClient.Connection()
169}
170
171// SetBreakpoint sets the breakpoint to the debuggee.
172func (c *Debugger2Client) SetBreakpoint(ctx context.Context, req *clouddebuggerpb.SetBreakpointRequest, opts ...gax.CallOption) (*clouddebuggerpb.SetBreakpointResponse, error) {
173	return c.internalClient.SetBreakpoint(ctx, req, opts...)
174}
175
176// GetBreakpoint gets breakpoint information.
177func (c *Debugger2Client) GetBreakpoint(ctx context.Context, req *clouddebuggerpb.GetBreakpointRequest, opts ...gax.CallOption) (*clouddebuggerpb.GetBreakpointResponse, error) {
178	return c.internalClient.GetBreakpoint(ctx, req, opts...)
179}
180
181// DeleteBreakpoint deletes the breakpoint from the debuggee.
182func (c *Debugger2Client) DeleteBreakpoint(ctx context.Context, req *clouddebuggerpb.DeleteBreakpointRequest, opts ...gax.CallOption) error {
183	return c.internalClient.DeleteBreakpoint(ctx, req, opts...)
184}
185
186// ListBreakpoints lists all breakpoints for the debuggee.
187func (c *Debugger2Client) ListBreakpoints(ctx context.Context, req *clouddebuggerpb.ListBreakpointsRequest, opts ...gax.CallOption) (*clouddebuggerpb.ListBreakpointsResponse, error) {
188	return c.internalClient.ListBreakpoints(ctx, req, opts...)
189}
190
191// ListDebuggees lists all the debuggees that the user has access to.
192func (c *Debugger2Client) ListDebuggees(ctx context.Context, req *clouddebuggerpb.ListDebuggeesRequest, opts ...gax.CallOption) (*clouddebuggerpb.ListDebuggeesResponse, error) {
193	return c.internalClient.ListDebuggees(ctx, req, opts...)
194}
195
196// debugger2GRPCClient is a client for interacting with Stackdriver Debugger API over gRPC transport.
197//
198// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
199type debugger2GRPCClient struct {
200	// Connection pool of gRPC connections to the service.
201	connPool gtransport.ConnPool
202
203	// flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE
204	disableDeadlines bool
205
206	// Points back to the CallOptions field of the containing Debugger2Client
207	CallOptions **Debugger2CallOptions
208
209	// The gRPC API client.
210	debugger2Client clouddebuggerpb.Debugger2Client
211
212	// The x-goog-* metadata to be sent with each request.
213	xGoogMetadata metadata.MD
214}
215
216// NewDebugger2Client creates a new debugger2 client based on gRPC.
217// The returned client must be Closed when it is done being used to clean up its underlying connections.
218//
219// The Debugger service provides the API that allows users to collect run-time
220// information from a running application, without stopping or slowing it down
221// and without modifying its state.  An application may include one or
222// more replicated processes performing the same work.
223//
224// A debugged application is represented using the Debuggee concept. The
225// Debugger service provides a way to query for available debuggees, but does
226// not provide a way to create one.  A debuggee is created using the Controller
227// service, usually by running a debugger agent with the application.
228//
229// The Debugger service enables the client to set one or more Breakpoints on a
230// Debuggee and collect the results of the set Breakpoints.
231func NewDebugger2Client(ctx context.Context, opts ...option.ClientOption) (*Debugger2Client, error) {
232	clientOpts := defaultDebugger2GRPCClientOptions()
233	if newDebugger2ClientHook != nil {
234		hookOpts, err := newDebugger2ClientHook(ctx, clientHookParams{})
235		if err != nil {
236			return nil, err
237		}
238		clientOpts = append(clientOpts, hookOpts...)
239	}
240
241	disableDeadlines, err := checkDisableDeadlines()
242	if err != nil {
243		return nil, err
244	}
245
246	connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
247	if err != nil {
248		return nil, err
249	}
250	client := Debugger2Client{CallOptions: defaultDebugger2CallOptions()}
251
252	c := &debugger2GRPCClient{
253		connPool:         connPool,
254		disableDeadlines: disableDeadlines,
255		debugger2Client:  clouddebuggerpb.NewDebugger2Client(connPool),
256		CallOptions:      &client.CallOptions,
257	}
258	c.setGoogleClientInfo()
259
260	client.internalClient = c
261
262	return &client, nil
263}
264
265// Connection returns a connection to the API service.
266//
267// Deprecated.
268func (c *debugger2GRPCClient) Connection() *grpc.ClientConn {
269	return c.connPool.Conn()
270}
271
272// setGoogleClientInfo sets the name and version of the application in
273// the `x-goog-api-client` header passed on each request. Intended for
274// use by Google-written clients.
275func (c *debugger2GRPCClient) setGoogleClientInfo(keyval ...string) {
276	kv := append([]string{"gl-go", versionGo()}, keyval...)
277	kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version)
278	c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
279}
280
281// Close closes the connection to the API service. The user should invoke this when
282// the client is no longer required.
283func (c *debugger2GRPCClient) Close() error {
284	return c.connPool.Close()
285}
286
287func (c *debugger2GRPCClient) SetBreakpoint(ctx context.Context, req *clouddebuggerpb.SetBreakpointRequest, opts ...gax.CallOption) (*clouddebuggerpb.SetBreakpointResponse, error) {
288	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
289		cctx, cancel := context.WithTimeout(ctx, 600000*time.Millisecond)
290		defer cancel()
291		ctx = cctx
292	}
293	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "debuggee_id", url.QueryEscape(req.GetDebuggeeId())))
294	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
295	opts = append((*c.CallOptions).SetBreakpoint[0:len((*c.CallOptions).SetBreakpoint):len((*c.CallOptions).SetBreakpoint)], opts...)
296	var resp *clouddebuggerpb.SetBreakpointResponse
297	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
298		var err error
299		resp, err = c.debugger2Client.SetBreakpoint(ctx, req, settings.GRPC...)
300		return err
301	}, opts...)
302	if err != nil {
303		return nil, err
304	}
305	return resp, nil
306}
307
308func (c *debugger2GRPCClient) GetBreakpoint(ctx context.Context, req *clouddebuggerpb.GetBreakpointRequest, opts ...gax.CallOption) (*clouddebuggerpb.GetBreakpointResponse, error) {
309	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
310		cctx, cancel := context.WithTimeout(ctx, 600000*time.Millisecond)
311		defer cancel()
312		ctx = cctx
313	}
314	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v&%s=%v", "debuggee_id", url.QueryEscape(req.GetDebuggeeId()), "breakpoint_id", url.QueryEscape(req.GetBreakpointId())))
315	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
316	opts = append((*c.CallOptions).GetBreakpoint[0:len((*c.CallOptions).GetBreakpoint):len((*c.CallOptions).GetBreakpoint)], opts...)
317	var resp *clouddebuggerpb.GetBreakpointResponse
318	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
319		var err error
320		resp, err = c.debugger2Client.GetBreakpoint(ctx, req, settings.GRPC...)
321		return err
322	}, opts...)
323	if err != nil {
324		return nil, err
325	}
326	return resp, nil
327}
328
329func (c *debugger2GRPCClient) DeleteBreakpoint(ctx context.Context, req *clouddebuggerpb.DeleteBreakpointRequest, opts ...gax.CallOption) error {
330	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
331		cctx, cancel := context.WithTimeout(ctx, 600000*time.Millisecond)
332		defer cancel()
333		ctx = cctx
334	}
335	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v&%s=%v", "debuggee_id", url.QueryEscape(req.GetDebuggeeId()), "breakpoint_id", url.QueryEscape(req.GetBreakpointId())))
336	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
337	opts = append((*c.CallOptions).DeleteBreakpoint[0:len((*c.CallOptions).DeleteBreakpoint):len((*c.CallOptions).DeleteBreakpoint)], opts...)
338	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
339		var err error
340		_, err = c.debugger2Client.DeleteBreakpoint(ctx, req, settings.GRPC...)
341		return err
342	}, opts...)
343	return err
344}
345
346func (c *debugger2GRPCClient) ListBreakpoints(ctx context.Context, req *clouddebuggerpb.ListBreakpointsRequest, opts ...gax.CallOption) (*clouddebuggerpb.ListBreakpointsResponse, error) {
347	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
348		cctx, cancel := context.WithTimeout(ctx, 600000*time.Millisecond)
349		defer cancel()
350		ctx = cctx
351	}
352	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "debuggee_id", url.QueryEscape(req.GetDebuggeeId())))
353	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
354	opts = append((*c.CallOptions).ListBreakpoints[0:len((*c.CallOptions).ListBreakpoints):len((*c.CallOptions).ListBreakpoints)], opts...)
355	var resp *clouddebuggerpb.ListBreakpointsResponse
356	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
357		var err error
358		resp, err = c.debugger2Client.ListBreakpoints(ctx, req, settings.GRPC...)
359		return err
360	}, opts...)
361	if err != nil {
362		return nil, err
363	}
364	return resp, nil
365}
366
367func (c *debugger2GRPCClient) ListDebuggees(ctx context.Context, req *clouddebuggerpb.ListDebuggeesRequest, opts ...gax.CallOption) (*clouddebuggerpb.ListDebuggeesResponse, error) {
368	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
369		cctx, cancel := context.WithTimeout(ctx, 600000*time.Millisecond)
370		defer cancel()
371		ctx = cctx
372	}
373	ctx = insertMetadata(ctx, c.xGoogMetadata)
374	opts = append((*c.CallOptions).ListDebuggees[0:len((*c.CallOptions).ListDebuggees):len((*c.CallOptions).ListDebuggees)], opts...)
375	var resp *clouddebuggerpb.ListDebuggeesResponse
376	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
377		var err error
378		resp, err = c.debugger2Client.ListDebuggees(ctx, req, settings.GRPC...)
379		return err
380	}, opts...)
381	if err != nil {
382		return nil, err
383	}
384	return resp, nil
385}
386