controller2_client.go 8.7 KB

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