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.
 
 
 

300 lines
10 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 errorreporting
  16. import (
  17. "context"
  18. "math"
  19. "time"
  20. "github.com/golang/protobuf/proto"
  21. gax "github.com/googleapis/gax-go/v2"
  22. "google.golang.org/api/iterator"
  23. "google.golang.org/api/option"
  24. "google.golang.org/api/transport"
  25. clouderrorreportingpb "google.golang.org/genproto/googleapis/devtools/clouderrorreporting/v1beta1"
  26. "google.golang.org/grpc"
  27. "google.golang.org/grpc/codes"
  28. "google.golang.org/grpc/metadata"
  29. )
  30. // ErrorStatsCallOptions contains the retry settings for each method of ErrorStatsClient.
  31. type ErrorStatsCallOptions struct {
  32. ListGroupStats []gax.CallOption
  33. ListEvents []gax.CallOption
  34. DeleteEvents []gax.CallOption
  35. }
  36. func defaultErrorStatsClientOptions() []option.ClientOption {
  37. return []option.ClientOption{
  38. option.WithEndpoint("clouderrorreporting.googleapis.com:443"),
  39. option.WithScopes(DefaultAuthScopes()...),
  40. }
  41. }
  42. func defaultErrorStatsCallOptions() *ErrorStatsCallOptions {
  43. retry := map[[2]string][]gax.CallOption{
  44. {"default", "idempotent"}: {
  45. gax.WithRetry(func() gax.Retryer {
  46. return gax.OnCodes([]codes.Code{
  47. codes.DeadlineExceeded,
  48. codes.Unavailable,
  49. }, gax.Backoff{
  50. Initial: 100 * time.Millisecond,
  51. Max: 60000 * time.Millisecond,
  52. Multiplier: 1.3,
  53. })
  54. }),
  55. },
  56. }
  57. return &ErrorStatsCallOptions{
  58. ListGroupStats: retry[[2]string{"default", "idempotent"}],
  59. ListEvents: retry[[2]string{"default", "idempotent"}],
  60. DeleteEvents: retry[[2]string{"default", "idempotent"}],
  61. }
  62. }
  63. // ErrorStatsClient is a client for interacting with Stackdriver Error Reporting API.
  64. //
  65. // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
  66. type ErrorStatsClient struct {
  67. // The connection to the service.
  68. conn *grpc.ClientConn
  69. // The gRPC API client.
  70. errorStatsClient clouderrorreportingpb.ErrorStatsServiceClient
  71. // The call options for this service.
  72. CallOptions *ErrorStatsCallOptions
  73. // The x-goog-* metadata to be sent with each request.
  74. xGoogMetadata metadata.MD
  75. }
  76. // NewErrorStatsClient creates a new error stats service client.
  77. //
  78. // An API for retrieving and managing error statistics as well as data for
  79. // individual events.
  80. func NewErrorStatsClient(ctx context.Context, opts ...option.ClientOption) (*ErrorStatsClient, error) {
  81. conn, err := transport.DialGRPC(ctx, append(defaultErrorStatsClientOptions(), opts...)...)
  82. if err != nil {
  83. return nil, err
  84. }
  85. c := &ErrorStatsClient{
  86. conn: conn,
  87. CallOptions: defaultErrorStatsCallOptions(),
  88. errorStatsClient: clouderrorreportingpb.NewErrorStatsServiceClient(conn),
  89. }
  90. c.SetGoogleClientInfo()
  91. return c, nil
  92. }
  93. // Connection returns the client's connection to the API service.
  94. func (c *ErrorStatsClient) Connection() *grpc.ClientConn {
  95. return c.conn
  96. }
  97. // Close closes the connection to the API service. The user should invoke this when
  98. // the client is no longer required.
  99. func (c *ErrorStatsClient) Close() error {
  100. return c.conn.Close()
  101. }
  102. // SetGoogleClientInfo sets the name and version of the application in
  103. // the `x-goog-api-client` header passed on each request. Intended for
  104. // use by Google-written clients.
  105. func (c *ErrorStatsClient) SetGoogleClientInfo(keyval ...string) {
  106. kv := append([]string{"gl-go", versionGo()}, keyval...)
  107. kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version)
  108. c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
  109. }
  110. // ListGroupStats lists the specified groups.
  111. func (c *ErrorStatsClient) ListGroupStats(ctx context.Context, req *clouderrorreportingpb.ListGroupStatsRequest, opts ...gax.CallOption) *ErrorGroupStatsIterator {
  112. ctx = insertMetadata(ctx, c.xGoogMetadata)
  113. opts = append(c.CallOptions.ListGroupStats[0:len(c.CallOptions.ListGroupStats):len(c.CallOptions.ListGroupStats)], opts...)
  114. it := &ErrorGroupStatsIterator{}
  115. req = proto.Clone(req).(*clouderrorreportingpb.ListGroupStatsRequest)
  116. it.InternalFetch = func(pageSize int, pageToken string) ([]*clouderrorreportingpb.ErrorGroupStats, string, error) {
  117. var resp *clouderrorreportingpb.ListGroupStatsResponse
  118. req.PageToken = pageToken
  119. if pageSize > math.MaxInt32 {
  120. req.PageSize = math.MaxInt32
  121. } else {
  122. req.PageSize = int32(pageSize)
  123. }
  124. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  125. var err error
  126. resp, err = c.errorStatsClient.ListGroupStats(ctx, req, settings.GRPC...)
  127. return err
  128. }, opts...)
  129. if err != nil {
  130. return nil, "", err
  131. }
  132. return resp.ErrorGroupStats, resp.NextPageToken, nil
  133. }
  134. fetch := func(pageSize int, pageToken string) (string, error) {
  135. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  136. if err != nil {
  137. return "", err
  138. }
  139. it.items = append(it.items, items...)
  140. return nextPageToken, nil
  141. }
  142. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  143. it.pageInfo.MaxSize = int(req.PageSize)
  144. return it
  145. }
  146. // ListEvents lists the specified events.
  147. func (c *ErrorStatsClient) ListEvents(ctx context.Context, req *clouderrorreportingpb.ListEventsRequest, opts ...gax.CallOption) *ErrorEventIterator {
  148. ctx = insertMetadata(ctx, c.xGoogMetadata)
  149. opts = append(c.CallOptions.ListEvents[0:len(c.CallOptions.ListEvents):len(c.CallOptions.ListEvents)], opts...)
  150. it := &ErrorEventIterator{}
  151. req = proto.Clone(req).(*clouderrorreportingpb.ListEventsRequest)
  152. it.InternalFetch = func(pageSize int, pageToken string) ([]*clouderrorreportingpb.ErrorEvent, string, error) {
  153. var resp *clouderrorreportingpb.ListEventsResponse
  154. req.PageToken = pageToken
  155. if pageSize > math.MaxInt32 {
  156. req.PageSize = math.MaxInt32
  157. } else {
  158. req.PageSize = int32(pageSize)
  159. }
  160. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  161. var err error
  162. resp, err = c.errorStatsClient.ListEvents(ctx, req, settings.GRPC...)
  163. return err
  164. }, opts...)
  165. if err != nil {
  166. return nil, "", err
  167. }
  168. return resp.ErrorEvents, resp.NextPageToken, nil
  169. }
  170. fetch := func(pageSize int, pageToken string) (string, error) {
  171. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  172. if err != nil {
  173. return "", err
  174. }
  175. it.items = append(it.items, items...)
  176. return nextPageToken, nil
  177. }
  178. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  179. it.pageInfo.MaxSize = int(req.PageSize)
  180. return it
  181. }
  182. // DeleteEvents deletes all error events of a given project.
  183. func (c *ErrorStatsClient) DeleteEvents(ctx context.Context, req *clouderrorreportingpb.DeleteEventsRequest, opts ...gax.CallOption) (*clouderrorreportingpb.DeleteEventsResponse, error) {
  184. ctx = insertMetadata(ctx, c.xGoogMetadata)
  185. opts = append(c.CallOptions.DeleteEvents[0:len(c.CallOptions.DeleteEvents):len(c.CallOptions.DeleteEvents)], opts...)
  186. var resp *clouderrorreportingpb.DeleteEventsResponse
  187. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  188. var err error
  189. resp, err = c.errorStatsClient.DeleteEvents(ctx, req, settings.GRPC...)
  190. return err
  191. }, opts...)
  192. if err != nil {
  193. return nil, err
  194. }
  195. return resp, nil
  196. }
  197. // ErrorEventIterator manages a stream of *clouderrorreportingpb.ErrorEvent.
  198. type ErrorEventIterator struct {
  199. items []*clouderrorreportingpb.ErrorEvent
  200. pageInfo *iterator.PageInfo
  201. nextFunc func() error
  202. // InternalFetch is for use by the Google Cloud Libraries only.
  203. // It is not part of the stable interface of this package.
  204. //
  205. // InternalFetch returns results from a single call to the underlying RPC.
  206. // The number of results is no greater than pageSize.
  207. // If there are no more results, nextPageToken is empty and err is nil.
  208. InternalFetch func(pageSize int, pageToken string) (results []*clouderrorreportingpb.ErrorEvent, nextPageToken string, err error)
  209. }
  210. // PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
  211. func (it *ErrorEventIterator) PageInfo() *iterator.PageInfo {
  212. return it.pageInfo
  213. }
  214. // Next returns the next result. Its second return value is iterator.Done if there are no more
  215. // results. Once Next returns Done, all subsequent calls will return Done.
  216. func (it *ErrorEventIterator) Next() (*clouderrorreportingpb.ErrorEvent, error) {
  217. var item *clouderrorreportingpb.ErrorEvent
  218. if err := it.nextFunc(); err != nil {
  219. return item, err
  220. }
  221. item = it.items[0]
  222. it.items = it.items[1:]
  223. return item, nil
  224. }
  225. func (it *ErrorEventIterator) bufLen() int {
  226. return len(it.items)
  227. }
  228. func (it *ErrorEventIterator) takeBuf() interface{} {
  229. b := it.items
  230. it.items = nil
  231. return b
  232. }
  233. // ErrorGroupStatsIterator manages a stream of *clouderrorreportingpb.ErrorGroupStats.
  234. type ErrorGroupStatsIterator struct {
  235. items []*clouderrorreportingpb.ErrorGroupStats
  236. pageInfo *iterator.PageInfo
  237. nextFunc func() error
  238. // InternalFetch is for use by the Google Cloud Libraries only.
  239. // It is not part of the stable interface of this package.
  240. //
  241. // InternalFetch returns results from a single call to the underlying RPC.
  242. // The number of results is no greater than pageSize.
  243. // If there are no more results, nextPageToken is empty and err is nil.
  244. InternalFetch func(pageSize int, pageToken string) (results []*clouderrorreportingpb.ErrorGroupStats, nextPageToken string, err error)
  245. }
  246. // PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
  247. func (it *ErrorGroupStatsIterator) PageInfo() *iterator.PageInfo {
  248. return it.pageInfo
  249. }
  250. // Next returns the next result. Its second return value is iterator.Done if there are no more
  251. // results. Once Next returns Done, all subsequent calls will return Done.
  252. func (it *ErrorGroupStatsIterator) Next() (*clouderrorreportingpb.ErrorGroupStats, error) {
  253. var item *clouderrorreportingpb.ErrorGroupStats
  254. if err := it.nextFunc(); err != nil {
  255. return item, err
  256. }
  257. item = it.items[0]
  258. it.items = it.items[1:]
  259. return item, nil
  260. }
  261. func (it *ErrorGroupStatsIterator) bufLen() int {
  262. return len(it.items)
  263. }
  264. func (it *ErrorGroupStatsIterator) takeBuf() interface{} {
  265. b := it.items
  266. it.items = nil
  267. return b
  268. }