metrics_client.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. // Copyright 2023 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 protoc-gen-go_gapic. DO NOT EDIT.
  15. package logging
  16. import (
  17. "context"
  18. "fmt"
  19. "math"
  20. "net/url"
  21. "time"
  22. loggingpb "cloud.google.com/go/logging/apiv2/loggingpb"
  23. longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
  24. gax "github.com/googleapis/gax-go/v2"
  25. "google.golang.org/api/iterator"
  26. "google.golang.org/api/option"
  27. "google.golang.org/api/option/internaloption"
  28. gtransport "google.golang.org/api/transport/grpc"
  29. "google.golang.org/grpc"
  30. "google.golang.org/grpc/codes"
  31. "google.golang.org/protobuf/proto"
  32. )
  33. var newMetricsClientHook clientHook
  34. // MetricsCallOptions contains the retry settings for each method of MetricsClient.
  35. type MetricsCallOptions struct {
  36. ListLogMetrics []gax.CallOption
  37. GetLogMetric []gax.CallOption
  38. CreateLogMetric []gax.CallOption
  39. UpdateLogMetric []gax.CallOption
  40. DeleteLogMetric []gax.CallOption
  41. CancelOperation []gax.CallOption
  42. GetOperation []gax.CallOption
  43. ListOperations []gax.CallOption
  44. }
  45. func defaultMetricsGRPCClientOptions() []option.ClientOption {
  46. return []option.ClientOption{
  47. internaloption.WithDefaultEndpoint("logging.googleapis.com:443"),
  48. internaloption.WithDefaultMTLSEndpoint("logging.mtls.googleapis.com:443"),
  49. internaloption.WithDefaultAudience("https://logging.googleapis.com/"),
  50. internaloption.WithDefaultScopes(DefaultAuthScopes()...),
  51. internaloption.EnableJwtWithScope(),
  52. option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
  53. grpc.MaxCallRecvMsgSize(math.MaxInt32))),
  54. }
  55. }
  56. func defaultMetricsCallOptions() *MetricsCallOptions {
  57. return &MetricsCallOptions{
  58. ListLogMetrics: []gax.CallOption{
  59. gax.WithTimeout(60000 * time.Millisecond),
  60. gax.WithRetry(func() gax.Retryer {
  61. return gax.OnCodes([]codes.Code{
  62. codes.DeadlineExceeded,
  63. codes.Internal,
  64. codes.Unavailable,
  65. }, gax.Backoff{
  66. Initial: 100 * time.Millisecond,
  67. Max: 60000 * time.Millisecond,
  68. Multiplier: 1.30,
  69. })
  70. }),
  71. },
  72. GetLogMetric: []gax.CallOption{
  73. gax.WithTimeout(60000 * time.Millisecond),
  74. gax.WithRetry(func() gax.Retryer {
  75. return gax.OnCodes([]codes.Code{
  76. codes.DeadlineExceeded,
  77. codes.Internal,
  78. codes.Unavailable,
  79. }, gax.Backoff{
  80. Initial: 100 * time.Millisecond,
  81. Max: 60000 * time.Millisecond,
  82. Multiplier: 1.30,
  83. })
  84. }),
  85. },
  86. CreateLogMetric: []gax.CallOption{
  87. gax.WithTimeout(60000 * time.Millisecond),
  88. },
  89. UpdateLogMetric: []gax.CallOption{
  90. gax.WithTimeout(60000 * time.Millisecond),
  91. gax.WithRetry(func() gax.Retryer {
  92. return gax.OnCodes([]codes.Code{
  93. codes.DeadlineExceeded,
  94. codes.Internal,
  95. codes.Unavailable,
  96. }, gax.Backoff{
  97. Initial: 100 * time.Millisecond,
  98. Max: 60000 * time.Millisecond,
  99. Multiplier: 1.30,
  100. })
  101. }),
  102. },
  103. DeleteLogMetric: []gax.CallOption{
  104. gax.WithTimeout(60000 * time.Millisecond),
  105. gax.WithRetry(func() gax.Retryer {
  106. return gax.OnCodes([]codes.Code{
  107. codes.DeadlineExceeded,
  108. codes.Internal,
  109. codes.Unavailable,
  110. }, gax.Backoff{
  111. Initial: 100 * time.Millisecond,
  112. Max: 60000 * time.Millisecond,
  113. Multiplier: 1.30,
  114. })
  115. }),
  116. },
  117. CancelOperation: []gax.CallOption{},
  118. GetOperation: []gax.CallOption{},
  119. ListOperations: []gax.CallOption{},
  120. }
  121. }
  122. // internalMetricsClient is an interface that defines the methods available from Cloud Logging API.
  123. type internalMetricsClient interface {
  124. Close() error
  125. setGoogleClientInfo(...string)
  126. Connection() *grpc.ClientConn
  127. ListLogMetrics(context.Context, *loggingpb.ListLogMetricsRequest, ...gax.CallOption) *LogMetricIterator
  128. GetLogMetric(context.Context, *loggingpb.GetLogMetricRequest, ...gax.CallOption) (*loggingpb.LogMetric, error)
  129. CreateLogMetric(context.Context, *loggingpb.CreateLogMetricRequest, ...gax.CallOption) (*loggingpb.LogMetric, error)
  130. UpdateLogMetric(context.Context, *loggingpb.UpdateLogMetricRequest, ...gax.CallOption) (*loggingpb.LogMetric, error)
  131. DeleteLogMetric(context.Context, *loggingpb.DeleteLogMetricRequest, ...gax.CallOption) error
  132. CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error
  133. GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error)
  134. ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator
  135. }
  136. // MetricsClient is a client for interacting with Cloud Logging API.
  137. // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
  138. //
  139. // Service for configuring logs-based metrics.
  140. type MetricsClient struct {
  141. // The internal transport-dependent client.
  142. internalClient internalMetricsClient
  143. // The call options for this service.
  144. CallOptions *MetricsCallOptions
  145. }
  146. // Wrapper methods routed to the internal client.
  147. // Close closes the connection to the API service. The user should invoke this when
  148. // the client is no longer required.
  149. func (c *MetricsClient) Close() error {
  150. return c.internalClient.Close()
  151. }
  152. // setGoogleClientInfo sets the name and version of the application in
  153. // the `x-goog-api-client` header passed on each request. Intended for
  154. // use by Google-written clients.
  155. func (c *MetricsClient) setGoogleClientInfo(keyval ...string) {
  156. c.internalClient.setGoogleClientInfo(keyval...)
  157. }
  158. // Connection returns a connection to the API service.
  159. //
  160. // Deprecated: Connections are now pooled so this method does not always
  161. // return the same resource.
  162. func (c *MetricsClient) Connection() *grpc.ClientConn {
  163. return c.internalClient.Connection()
  164. }
  165. // ListLogMetrics lists logs-based metrics.
  166. func (c *MetricsClient) ListLogMetrics(ctx context.Context, req *loggingpb.ListLogMetricsRequest, opts ...gax.CallOption) *LogMetricIterator {
  167. return c.internalClient.ListLogMetrics(ctx, req, opts...)
  168. }
  169. // GetLogMetric gets a logs-based metric.
  170. func (c *MetricsClient) GetLogMetric(ctx context.Context, req *loggingpb.GetLogMetricRequest, opts ...gax.CallOption) (*loggingpb.LogMetric, error) {
  171. return c.internalClient.GetLogMetric(ctx, req, opts...)
  172. }
  173. // CreateLogMetric creates a logs-based metric.
  174. func (c *MetricsClient) CreateLogMetric(ctx context.Context, req *loggingpb.CreateLogMetricRequest, opts ...gax.CallOption) (*loggingpb.LogMetric, error) {
  175. return c.internalClient.CreateLogMetric(ctx, req, opts...)
  176. }
  177. // UpdateLogMetric creates or updates a logs-based metric.
  178. func (c *MetricsClient) UpdateLogMetric(ctx context.Context, req *loggingpb.UpdateLogMetricRequest, opts ...gax.CallOption) (*loggingpb.LogMetric, error) {
  179. return c.internalClient.UpdateLogMetric(ctx, req, opts...)
  180. }
  181. // DeleteLogMetric deletes a logs-based metric.
  182. func (c *MetricsClient) DeleteLogMetric(ctx context.Context, req *loggingpb.DeleteLogMetricRequest, opts ...gax.CallOption) error {
  183. return c.internalClient.DeleteLogMetric(ctx, req, opts...)
  184. }
  185. // CancelOperation is a utility method from google.longrunning.Operations.
  186. func (c *MetricsClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
  187. return c.internalClient.CancelOperation(ctx, req, opts...)
  188. }
  189. // GetOperation is a utility method from google.longrunning.Operations.
  190. func (c *MetricsClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
  191. return c.internalClient.GetOperation(ctx, req, opts...)
  192. }
  193. // ListOperations is a utility method from google.longrunning.Operations.
  194. func (c *MetricsClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
  195. return c.internalClient.ListOperations(ctx, req, opts...)
  196. }
  197. // metricsGRPCClient is a client for interacting with Cloud Logging API over gRPC transport.
  198. //
  199. // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
  200. type metricsGRPCClient struct {
  201. // Connection pool of gRPC connections to the service.
  202. connPool gtransport.ConnPool
  203. // Points back to the CallOptions field of the containing MetricsClient
  204. CallOptions **MetricsCallOptions
  205. // The gRPC API client.
  206. metricsClient loggingpb.MetricsServiceV2Client
  207. operationsClient longrunningpb.OperationsClient
  208. // The x-goog-* metadata to be sent with each request.
  209. xGoogHeaders []string
  210. }
  211. // NewMetricsClient creates a new metrics service v2 client based on gRPC.
  212. // The returned client must be Closed when it is done being used to clean up its underlying connections.
  213. //
  214. // Service for configuring logs-based metrics.
  215. func NewMetricsClient(ctx context.Context, opts ...option.ClientOption) (*MetricsClient, error) {
  216. clientOpts := defaultMetricsGRPCClientOptions()
  217. if newMetricsClientHook != nil {
  218. hookOpts, err := newMetricsClientHook(ctx, clientHookParams{})
  219. if err != nil {
  220. return nil, err
  221. }
  222. clientOpts = append(clientOpts, hookOpts...)
  223. }
  224. connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
  225. if err != nil {
  226. return nil, err
  227. }
  228. client := MetricsClient{CallOptions: defaultMetricsCallOptions()}
  229. c := &metricsGRPCClient{
  230. connPool: connPool,
  231. metricsClient: loggingpb.NewMetricsServiceV2Client(connPool),
  232. CallOptions: &client.CallOptions,
  233. operationsClient: longrunningpb.NewOperationsClient(connPool),
  234. }
  235. c.setGoogleClientInfo()
  236. client.internalClient = c
  237. return &client, nil
  238. }
  239. // Connection returns a connection to the API service.
  240. //
  241. // Deprecated: Connections are now pooled so this method does not always
  242. // return the same resource.
  243. func (c *metricsGRPCClient) Connection() *grpc.ClientConn {
  244. return c.connPool.Conn()
  245. }
  246. // setGoogleClientInfo sets the name and version of the application in
  247. // the `x-goog-api-client` header passed on each request. Intended for
  248. // use by Google-written clients.
  249. func (c *metricsGRPCClient) setGoogleClientInfo(keyval ...string) {
  250. kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
  251. kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version)
  252. c.xGoogHeaders = []string{"x-goog-api-client", gax.XGoogHeader(kv...)}
  253. }
  254. // Close closes the connection to the API service. The user should invoke this when
  255. // the client is no longer required.
  256. func (c *metricsGRPCClient) Close() error {
  257. return c.connPool.Close()
  258. }
  259. func (c *metricsGRPCClient) ListLogMetrics(ctx context.Context, req *loggingpb.ListLogMetricsRequest, opts ...gax.CallOption) *LogMetricIterator {
  260. hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
  261. hds = append(c.xGoogHeaders, hds...)
  262. ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  263. opts = append((*c.CallOptions).ListLogMetrics[0:len((*c.CallOptions).ListLogMetrics):len((*c.CallOptions).ListLogMetrics)], opts...)
  264. it := &LogMetricIterator{}
  265. req = proto.Clone(req).(*loggingpb.ListLogMetricsRequest)
  266. it.InternalFetch = func(pageSize int, pageToken string) ([]*loggingpb.LogMetric, string, error) {
  267. resp := &loggingpb.ListLogMetricsResponse{}
  268. if pageToken != "" {
  269. req.PageToken = pageToken
  270. }
  271. if pageSize > math.MaxInt32 {
  272. req.PageSize = math.MaxInt32
  273. } else if pageSize != 0 {
  274. req.PageSize = int32(pageSize)
  275. }
  276. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  277. var err error
  278. resp, err = c.metricsClient.ListLogMetrics(ctx, req, settings.GRPC...)
  279. return err
  280. }, opts...)
  281. if err != nil {
  282. return nil, "", err
  283. }
  284. it.Response = resp
  285. return resp.GetMetrics(), resp.GetNextPageToken(), nil
  286. }
  287. fetch := func(pageSize int, pageToken string) (string, error) {
  288. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  289. if err != nil {
  290. return "", err
  291. }
  292. it.items = append(it.items, items...)
  293. return nextPageToken, nil
  294. }
  295. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  296. it.pageInfo.MaxSize = int(req.GetPageSize())
  297. it.pageInfo.Token = req.GetPageToken()
  298. return it
  299. }
  300. func (c *metricsGRPCClient) GetLogMetric(ctx context.Context, req *loggingpb.GetLogMetricRequest, opts ...gax.CallOption) (*loggingpb.LogMetric, error) {
  301. hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "metric_name", url.QueryEscape(req.GetMetricName()))}
  302. hds = append(c.xGoogHeaders, hds...)
  303. ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  304. opts = append((*c.CallOptions).GetLogMetric[0:len((*c.CallOptions).GetLogMetric):len((*c.CallOptions).GetLogMetric)], opts...)
  305. var resp *loggingpb.LogMetric
  306. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  307. var err error
  308. resp, err = c.metricsClient.GetLogMetric(ctx, req, settings.GRPC...)
  309. return err
  310. }, opts...)
  311. if err != nil {
  312. return nil, err
  313. }
  314. return resp, nil
  315. }
  316. func (c *metricsGRPCClient) CreateLogMetric(ctx context.Context, req *loggingpb.CreateLogMetricRequest, opts ...gax.CallOption) (*loggingpb.LogMetric, error) {
  317. hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
  318. hds = append(c.xGoogHeaders, hds...)
  319. ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  320. opts = append((*c.CallOptions).CreateLogMetric[0:len((*c.CallOptions).CreateLogMetric):len((*c.CallOptions).CreateLogMetric)], opts...)
  321. var resp *loggingpb.LogMetric
  322. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  323. var err error
  324. resp, err = c.metricsClient.CreateLogMetric(ctx, req, settings.GRPC...)
  325. return err
  326. }, opts...)
  327. if err != nil {
  328. return nil, err
  329. }
  330. return resp, nil
  331. }
  332. func (c *metricsGRPCClient) UpdateLogMetric(ctx context.Context, req *loggingpb.UpdateLogMetricRequest, opts ...gax.CallOption) (*loggingpb.LogMetric, error) {
  333. hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "metric_name", url.QueryEscape(req.GetMetricName()))}
  334. hds = append(c.xGoogHeaders, hds...)
  335. ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  336. opts = append((*c.CallOptions).UpdateLogMetric[0:len((*c.CallOptions).UpdateLogMetric):len((*c.CallOptions).UpdateLogMetric)], opts...)
  337. var resp *loggingpb.LogMetric
  338. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  339. var err error
  340. resp, err = c.metricsClient.UpdateLogMetric(ctx, req, settings.GRPC...)
  341. return err
  342. }, opts...)
  343. if err != nil {
  344. return nil, err
  345. }
  346. return resp, nil
  347. }
  348. func (c *metricsGRPCClient) DeleteLogMetric(ctx context.Context, req *loggingpb.DeleteLogMetricRequest, opts ...gax.CallOption) error {
  349. hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "metric_name", url.QueryEscape(req.GetMetricName()))}
  350. hds = append(c.xGoogHeaders, hds...)
  351. ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  352. opts = append((*c.CallOptions).DeleteLogMetric[0:len((*c.CallOptions).DeleteLogMetric):len((*c.CallOptions).DeleteLogMetric)], opts...)
  353. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  354. var err error
  355. _, err = c.metricsClient.DeleteLogMetric(ctx, req, settings.GRPC...)
  356. return err
  357. }, opts...)
  358. return err
  359. }
  360. func (c *metricsGRPCClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
  361. hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  362. hds = append(c.xGoogHeaders, hds...)
  363. ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  364. opts = append((*c.CallOptions).CancelOperation[0:len((*c.CallOptions).CancelOperation):len((*c.CallOptions).CancelOperation)], opts...)
  365. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  366. var err error
  367. _, err = c.operationsClient.CancelOperation(ctx, req, settings.GRPC...)
  368. return err
  369. }, opts...)
  370. return err
  371. }
  372. func (c *metricsGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
  373. hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  374. hds = append(c.xGoogHeaders, hds...)
  375. ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  376. opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
  377. var resp *longrunningpb.Operation
  378. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  379. var err error
  380. resp, err = c.operationsClient.GetOperation(ctx, req, settings.GRPC...)
  381. return err
  382. }, opts...)
  383. if err != nil {
  384. return nil, err
  385. }
  386. return resp, nil
  387. }
  388. func (c *metricsGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
  389. hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  390. hds = append(c.xGoogHeaders, hds...)
  391. ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  392. opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...)
  393. it := &OperationIterator{}
  394. req = proto.Clone(req).(*longrunningpb.ListOperationsRequest)
  395. it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
  396. resp := &longrunningpb.ListOperationsResponse{}
  397. if pageToken != "" {
  398. req.PageToken = pageToken
  399. }
  400. if pageSize > math.MaxInt32 {
  401. req.PageSize = math.MaxInt32
  402. } else if pageSize != 0 {
  403. req.PageSize = int32(pageSize)
  404. }
  405. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  406. var err error
  407. resp, err = c.operationsClient.ListOperations(ctx, req, settings.GRPC...)
  408. return err
  409. }, opts...)
  410. if err != nil {
  411. return nil, "", err
  412. }
  413. it.Response = resp
  414. return resp.GetOperations(), resp.GetNextPageToken(), nil
  415. }
  416. fetch := func(pageSize int, pageToken string) (string, error) {
  417. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  418. if err != nil {
  419. return "", err
  420. }
  421. it.items = append(it.items, items...)
  422. return nextPageToken, nil
  423. }
  424. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  425. it.pageInfo.MaxSize = int(req.GetPageSize())
  426. it.pageInfo.Token = req.GetPageToken()
  427. return it
  428. }
  429. // LogMetricIterator manages a stream of *loggingpb.LogMetric.
  430. type LogMetricIterator struct {
  431. items []*loggingpb.LogMetric
  432. pageInfo *iterator.PageInfo
  433. nextFunc func() error
  434. // Response is the raw response for the current page.
  435. // It must be cast to the RPC response type.
  436. // Calling Next() or InternalFetch() updates this value.
  437. Response interface{}
  438. // InternalFetch is for use by the Google Cloud Libraries only.
  439. // It is not part of the stable interface of this package.
  440. //
  441. // InternalFetch returns results from a single call to the underlying RPC.
  442. // The number of results is no greater than pageSize.
  443. // If there are no more results, nextPageToken is empty and err is nil.
  444. InternalFetch func(pageSize int, pageToken string) (results []*loggingpb.LogMetric, nextPageToken string, err error)
  445. }
  446. // PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
  447. func (it *LogMetricIterator) PageInfo() *iterator.PageInfo {
  448. return it.pageInfo
  449. }
  450. // Next returns the next result. Its second return value is iterator.Done if there are no more
  451. // results. Once Next returns Done, all subsequent calls will return Done.
  452. func (it *LogMetricIterator) Next() (*loggingpb.LogMetric, error) {
  453. var item *loggingpb.LogMetric
  454. if err := it.nextFunc(); err != nil {
  455. return item, err
  456. }
  457. item = it.items[0]
  458. it.items = it.items[1:]
  459. return item, nil
  460. }
  461. func (it *LogMetricIterator) bufLen() int {
  462. return len(it.items)
  463. }
  464. func (it *LogMetricIterator) takeBuf() interface{} {
  465. b := it.items
  466. it.items = nil
  467. return b
  468. }