Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

296 lignes
10 KiB

  1. // Copyright 2018 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. // AUTO-GENERATED CODE. DO NOT EDIT.
  15. package errorreporting
  16. import (
  17. "math"
  18. "time"
  19. "cloud.google.com/go/internal/version"
  20. gax "github.com/googleapis/gax-go"
  21. "golang.org/x/net/context"
  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", version.Go()}, keyval...)
  107. kv = append(kv, "gapic", version.Repo, "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. it.InternalFetch = func(pageSize int, pageToken string) ([]*clouderrorreportingpb.ErrorGroupStats, string, error) {
  116. var resp *clouderrorreportingpb.ListGroupStatsResponse
  117. req.PageToken = pageToken
  118. if pageSize > math.MaxInt32 {
  119. req.PageSize = math.MaxInt32
  120. } else {
  121. req.PageSize = int32(pageSize)
  122. }
  123. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  124. var err error
  125. resp, err = c.errorStatsClient.ListGroupStats(ctx, req, settings.GRPC...)
  126. return err
  127. }, opts...)
  128. if err != nil {
  129. return nil, "", err
  130. }
  131. return resp.ErrorGroupStats, resp.NextPageToken, nil
  132. }
  133. fetch := func(pageSize int, pageToken string) (string, error) {
  134. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  135. if err != nil {
  136. return "", err
  137. }
  138. it.items = append(it.items, items...)
  139. return nextPageToken, nil
  140. }
  141. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  142. return it
  143. }
  144. // ListEvents lists the specified events.
  145. func (c *ErrorStatsClient) ListEvents(ctx context.Context, req *clouderrorreportingpb.ListEventsRequest, opts ...gax.CallOption) *ErrorEventIterator {
  146. ctx = insertMetadata(ctx, c.xGoogMetadata)
  147. opts = append(c.CallOptions.ListEvents[0:len(c.CallOptions.ListEvents):len(c.CallOptions.ListEvents)], opts...)
  148. it := &ErrorEventIterator{}
  149. it.InternalFetch = func(pageSize int, pageToken string) ([]*clouderrorreportingpb.ErrorEvent, string, error) {
  150. var resp *clouderrorreportingpb.ListEventsResponse
  151. req.PageToken = pageToken
  152. if pageSize > math.MaxInt32 {
  153. req.PageSize = math.MaxInt32
  154. } else {
  155. req.PageSize = int32(pageSize)
  156. }
  157. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  158. var err error
  159. resp, err = c.errorStatsClient.ListEvents(ctx, req, settings.GRPC...)
  160. return err
  161. }, opts...)
  162. if err != nil {
  163. return nil, "", err
  164. }
  165. return resp.ErrorEvents, resp.NextPageToken, nil
  166. }
  167. fetch := func(pageSize int, pageToken string) (string, error) {
  168. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  169. if err != nil {
  170. return "", err
  171. }
  172. it.items = append(it.items, items...)
  173. return nextPageToken, nil
  174. }
  175. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  176. return it
  177. }
  178. // DeleteEvents deletes all error events of a given project.
  179. func (c *ErrorStatsClient) DeleteEvents(ctx context.Context, req *clouderrorreportingpb.DeleteEventsRequest, opts ...gax.CallOption) (*clouderrorreportingpb.DeleteEventsResponse, error) {
  180. ctx = insertMetadata(ctx, c.xGoogMetadata)
  181. opts = append(c.CallOptions.DeleteEvents[0:len(c.CallOptions.DeleteEvents):len(c.CallOptions.DeleteEvents)], opts...)
  182. var resp *clouderrorreportingpb.DeleteEventsResponse
  183. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  184. var err error
  185. resp, err = c.errorStatsClient.DeleteEvents(ctx, req, settings.GRPC...)
  186. return err
  187. }, opts...)
  188. if err != nil {
  189. return nil, err
  190. }
  191. return resp, nil
  192. }
  193. // ErrorEventIterator manages a stream of *clouderrorreportingpb.ErrorEvent.
  194. type ErrorEventIterator struct {
  195. items []*clouderrorreportingpb.ErrorEvent
  196. pageInfo *iterator.PageInfo
  197. nextFunc func() error
  198. // InternalFetch is for use by the Google Cloud Libraries only.
  199. // It is not part of the stable interface of this package.
  200. //
  201. // InternalFetch returns results from a single call to the underlying RPC.
  202. // The number of results is no greater than pageSize.
  203. // If there are no more results, nextPageToken is empty and err is nil.
  204. InternalFetch func(pageSize int, pageToken string) (results []*clouderrorreportingpb.ErrorEvent, nextPageToken string, err error)
  205. }
  206. // PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
  207. func (it *ErrorEventIterator) PageInfo() *iterator.PageInfo {
  208. return it.pageInfo
  209. }
  210. // Next returns the next result. Its second return value is iterator.Done if there are no more
  211. // results. Once Next returns Done, all subsequent calls will return Done.
  212. func (it *ErrorEventIterator) Next() (*clouderrorreportingpb.ErrorEvent, error) {
  213. var item *clouderrorreportingpb.ErrorEvent
  214. if err := it.nextFunc(); err != nil {
  215. return item, err
  216. }
  217. item = it.items[0]
  218. it.items = it.items[1:]
  219. return item, nil
  220. }
  221. func (it *ErrorEventIterator) bufLen() int {
  222. return len(it.items)
  223. }
  224. func (it *ErrorEventIterator) takeBuf() interface{} {
  225. b := it.items
  226. it.items = nil
  227. return b
  228. }
  229. // ErrorGroupStatsIterator manages a stream of *clouderrorreportingpb.ErrorGroupStats.
  230. type ErrorGroupStatsIterator struct {
  231. items []*clouderrorreportingpb.ErrorGroupStats
  232. pageInfo *iterator.PageInfo
  233. nextFunc func() error
  234. // InternalFetch is for use by the Google Cloud Libraries only.
  235. // It is not part of the stable interface of this package.
  236. //
  237. // InternalFetch returns results from a single call to the underlying RPC.
  238. // The number of results is no greater than pageSize.
  239. // If there are no more results, nextPageToken is empty and err is nil.
  240. InternalFetch func(pageSize int, pageToken string) (results []*clouderrorreportingpb.ErrorGroupStats, nextPageToken string, err error)
  241. }
  242. // PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
  243. func (it *ErrorGroupStatsIterator) PageInfo() *iterator.PageInfo {
  244. return it.pageInfo
  245. }
  246. // Next returns the next result. Its second return value is iterator.Done if there are no more
  247. // results. Once Next returns Done, all subsequent calls will return Done.
  248. func (it *ErrorGroupStatsIterator) Next() (*clouderrorreportingpb.ErrorGroupStats, error) {
  249. var item *clouderrorreportingpb.ErrorGroupStats
  250. if err := it.nextFunc(); err != nil {
  251. return item, err
  252. }
  253. item = it.items[0]
  254. it.items = it.items[1:]
  255. return item, nil
  256. }
  257. func (it *ErrorGroupStatsIterator) bufLen() int {
  258. return len(it.items)
  259. }
  260. func (it *ErrorGroupStatsIterator) takeBuf() interface{} {
  261. b := it.items
  262. it.items = nil
  263. return b
  264. }