You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

217 lines
8.8 KiB

  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. // Code generated by gapic-generator. DO NOT EDIT.
  15. package debugger
  16. import (
  17. "context"
  18. "time"
  19. gax "github.com/googleapis/gax-go/v2"
  20. "google.golang.org/api/option"
  21. "google.golang.org/api/transport"
  22. clouddebuggerpb "google.golang.org/genproto/googleapis/devtools/clouddebugger/v2"
  23. "google.golang.org/grpc"
  24. "google.golang.org/grpc/codes"
  25. "google.golang.org/grpc/metadata"
  26. )
  27. // Controller2CallOptions contains the retry settings for each method of Controller2Client.
  28. type Controller2CallOptions struct {
  29. RegisterDebuggee []gax.CallOption
  30. ListActiveBreakpoints []gax.CallOption
  31. UpdateActiveBreakpoint []gax.CallOption
  32. }
  33. func defaultController2ClientOptions() []option.ClientOption {
  34. return []option.ClientOption{
  35. option.WithEndpoint("clouddebugger.googleapis.com:443"),
  36. option.WithScopes(DefaultAuthScopes()...),
  37. }
  38. }
  39. func defaultController2CallOptions() *Controller2CallOptions {
  40. retry := map[[2]string][]gax.CallOption{
  41. {"default", "idempotent"}: {
  42. gax.WithRetry(func() gax.Retryer {
  43. return gax.OnCodes([]codes.Code{
  44. codes.DeadlineExceeded,
  45. codes.Unavailable,
  46. }, gax.Backoff{
  47. Initial: 100 * time.Millisecond,
  48. Max: 60000 * time.Millisecond,
  49. Multiplier: 1.3,
  50. })
  51. }),
  52. },
  53. }
  54. return &Controller2CallOptions{
  55. RegisterDebuggee: retry[[2]string{"default", "non_idempotent"}],
  56. ListActiveBreakpoints: retry[[2]string{"default", "idempotent"}],
  57. UpdateActiveBreakpoint: retry[[2]string{"default", "idempotent"}],
  58. }
  59. }
  60. // Controller2Client is a client for interacting with Stackdriver Debugger API.
  61. //
  62. // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
  63. type Controller2Client struct {
  64. // The connection to the service.
  65. conn *grpc.ClientConn
  66. // The gRPC API client.
  67. controller2Client clouddebuggerpb.Controller2Client
  68. // The call options for this service.
  69. CallOptions *Controller2CallOptions
  70. // The x-goog-* metadata to be sent with each request.
  71. xGoogMetadata metadata.MD
  72. }
  73. // NewController2Client creates a new controller2 client.
  74. //
  75. // The Controller service provides the API for orchestrating a collection of
  76. // debugger agents to perform debugging tasks. These agents are each attached
  77. // to a process of an application which may include one or more replicas.
  78. //
  79. // The debugger agents register with the Controller to identify the application
  80. // being debugged, the Debuggee. All agents that register with the same data,
  81. // represent the same Debuggee, and are assigned the same debuggee_id.
  82. //
  83. // The debugger agents call the Controller to retrieve the list of active
  84. // Breakpoints. Agents with the same debuggee_id get the same breakpoints
  85. // list. An agent that can fulfill the breakpoint request updates the
  86. // Controller with the breakpoint result. The controller selects the first
  87. // result received and discards the rest of the results.
  88. // Agents that poll again for active breakpoints will no longer have
  89. // the completed breakpoint in the list and should remove that breakpoint from
  90. // their attached process.
  91. //
  92. // The Controller service does not provide a way to retrieve the results of
  93. // a completed breakpoint. This functionality is available using the Debugger
  94. // service.
  95. func NewController2Client(ctx context.Context, opts ...option.ClientOption) (*Controller2Client, error) {
  96. conn, err := transport.DialGRPC(ctx, append(defaultController2ClientOptions(), opts...)...)
  97. if err != nil {
  98. return nil, err
  99. }
  100. c := &Controller2Client{
  101. conn: conn,
  102. CallOptions: defaultController2CallOptions(),
  103. controller2Client: clouddebuggerpb.NewController2Client(conn),
  104. }
  105. c.SetGoogleClientInfo()
  106. return c, nil
  107. }
  108. // Connection returns the client's connection to the API service.
  109. func (c *Controller2Client) Connection() *grpc.ClientConn {
  110. return c.conn
  111. }
  112. // Close closes the connection to the API service. The user should invoke this when
  113. // the client is no longer required.
  114. func (c *Controller2Client) Close() error {
  115. return c.conn.Close()
  116. }
  117. // SetGoogleClientInfo sets the name and version of the application in
  118. // the `x-goog-api-client` header passed on each request. Intended for
  119. // use by Google-written clients.
  120. func (c *Controller2Client) SetGoogleClientInfo(keyval ...string) {
  121. kv := append([]string{"gl-go", versionGo()}, keyval...)
  122. kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version)
  123. c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
  124. }
  125. // RegisterDebuggee registers the debuggee with the controller service.
  126. //
  127. // All agents attached to the same application must call this method with
  128. // exactly the same request content to get back the same stable debuggee_id.
  129. // Agents should call this method again whenever google.rpc.Code.NOT_FOUND
  130. // is returned from any controller method.
  131. //
  132. // This protocol allows the controller service to disable debuggees, recover
  133. // from data loss, or change the debuggee_id format. Agents must handle
  134. // debuggee_id value changing upon re-registration.
  135. func (c *Controller2Client) RegisterDebuggee(ctx context.Context, req *clouddebuggerpb.RegisterDebuggeeRequest, opts ...gax.CallOption) (*clouddebuggerpb.RegisterDebuggeeResponse, error) {
  136. ctx = insertMetadata(ctx, c.xGoogMetadata)
  137. opts = append(c.CallOptions.RegisterDebuggee[0:len(c.CallOptions.RegisterDebuggee):len(c.CallOptions.RegisterDebuggee)], opts...)
  138. var resp *clouddebuggerpb.RegisterDebuggeeResponse
  139. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  140. var err error
  141. resp, err = c.controller2Client.RegisterDebuggee(ctx, req, settings.GRPC...)
  142. return err
  143. }, opts...)
  144. if err != nil {
  145. return nil, err
  146. }
  147. return resp, nil
  148. }
  149. // ListActiveBreakpoints returns the list of all active breakpoints for the debuggee.
  150. //
  151. // The breakpoint specification (location, condition, and expressions
  152. // fields) is semantically immutable, although the field values may
  153. // change. For example, an agent may update the location line number
  154. // to reflect the actual line where the breakpoint was set, but this
  155. // doesn't change the breakpoint semantics.
  156. //
  157. // This means that an agent does not need to check if a breakpoint has changed
  158. // when it encounters the same breakpoint on a successive call.
  159. // Moreover, an agent should remember the breakpoints that are completed
  160. // until the controller removes them from the active list to avoid
  161. // setting those breakpoints again.
  162. func (c *Controller2Client) ListActiveBreakpoints(ctx context.Context, req *clouddebuggerpb.ListActiveBreakpointsRequest, opts ...gax.CallOption) (*clouddebuggerpb.ListActiveBreakpointsResponse, error) {
  163. ctx = insertMetadata(ctx, c.xGoogMetadata)
  164. opts = append(c.CallOptions.ListActiveBreakpoints[0:len(c.CallOptions.ListActiveBreakpoints):len(c.CallOptions.ListActiveBreakpoints)], opts...)
  165. var resp *clouddebuggerpb.ListActiveBreakpointsResponse
  166. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  167. var err error
  168. resp, err = c.controller2Client.ListActiveBreakpoints(ctx, req, settings.GRPC...)
  169. return err
  170. }, opts...)
  171. if err != nil {
  172. return nil, err
  173. }
  174. return resp, nil
  175. }
  176. // UpdateActiveBreakpoint updates the breakpoint state or mutable fields.
  177. // The entire Breakpoint message must be sent back to the controller service.
  178. //
  179. // Updates to active breakpoint fields are only allowed if the new value
  180. // does not change the breakpoint specification. Updates to the location,
  181. // condition and expressions fields should not alter the breakpoint
  182. // semantics. These may only make changes such as canonicalizing a value
  183. // or snapping the location to the correct line of code.
  184. func (c *Controller2Client) UpdateActiveBreakpoint(ctx context.Context, req *clouddebuggerpb.UpdateActiveBreakpointRequest, opts ...gax.CallOption) (*clouddebuggerpb.UpdateActiveBreakpointResponse, error) {
  185. ctx = insertMetadata(ctx, c.xGoogMetadata)
  186. opts = append(c.CallOptions.UpdateActiveBreakpoint[0:len(c.CallOptions.UpdateActiveBreakpoint):len(c.CallOptions.UpdateActiveBreakpoint)], opts...)
  187. var resp *clouddebuggerpb.UpdateActiveBreakpointResponse
  188. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  189. var err error
  190. resp, err = c.controller2Client.UpdateActiveBreakpoint(ctx, req, settings.GRPC...)
  191. return err
  192. }, opts...)
  193. if err != nil {
  194. return nil, err
  195. }
  196. return resp, nil
  197. }