logging_client.go 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  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. monitoredrespb "google.golang.org/genproto/googleapis/api/monitoredres"
  30. "google.golang.org/grpc"
  31. "google.golang.org/grpc/codes"
  32. "google.golang.org/protobuf/proto"
  33. )
  34. var newClientHook clientHook
  35. // CallOptions contains the retry settings for each method of Client.
  36. type CallOptions struct {
  37. DeleteLog []gax.CallOption
  38. WriteLogEntries []gax.CallOption
  39. ListLogEntries []gax.CallOption
  40. ListMonitoredResourceDescriptors []gax.CallOption
  41. ListLogs []gax.CallOption
  42. TailLogEntries []gax.CallOption
  43. CancelOperation []gax.CallOption
  44. GetOperation []gax.CallOption
  45. ListOperations []gax.CallOption
  46. }
  47. func defaultGRPCClientOptions() []option.ClientOption {
  48. return []option.ClientOption{
  49. internaloption.WithDefaultEndpoint("logging.googleapis.com:443"),
  50. internaloption.WithDefaultMTLSEndpoint("logging.mtls.googleapis.com:443"),
  51. internaloption.WithDefaultAudience("https://logging.googleapis.com/"),
  52. internaloption.WithDefaultScopes(DefaultAuthScopes()...),
  53. internaloption.EnableJwtWithScope(),
  54. option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
  55. grpc.MaxCallRecvMsgSize(math.MaxInt32))),
  56. }
  57. }
  58. func defaultCallOptions() *CallOptions {
  59. return &CallOptions{
  60. DeleteLog: []gax.CallOption{
  61. gax.WithTimeout(60000 * time.Millisecond),
  62. gax.WithRetry(func() gax.Retryer {
  63. return gax.OnCodes([]codes.Code{
  64. codes.DeadlineExceeded,
  65. codes.Internal,
  66. codes.Unavailable,
  67. }, gax.Backoff{
  68. Initial: 100 * time.Millisecond,
  69. Max: 60000 * time.Millisecond,
  70. Multiplier: 1.30,
  71. })
  72. }),
  73. },
  74. WriteLogEntries: []gax.CallOption{
  75. gax.WithTimeout(60000 * time.Millisecond),
  76. gax.WithRetry(func() gax.Retryer {
  77. return gax.OnCodes([]codes.Code{
  78. codes.DeadlineExceeded,
  79. codes.Internal,
  80. codes.Unavailable,
  81. }, gax.Backoff{
  82. Initial: 100 * time.Millisecond,
  83. Max: 60000 * time.Millisecond,
  84. Multiplier: 1.30,
  85. })
  86. }),
  87. },
  88. ListLogEntries: []gax.CallOption{
  89. gax.WithTimeout(60000 * time.Millisecond),
  90. gax.WithRetry(func() gax.Retryer {
  91. return gax.OnCodes([]codes.Code{
  92. codes.DeadlineExceeded,
  93. codes.Internal,
  94. codes.Unavailable,
  95. }, gax.Backoff{
  96. Initial: 100 * time.Millisecond,
  97. Max: 60000 * time.Millisecond,
  98. Multiplier: 1.30,
  99. })
  100. }),
  101. },
  102. ListMonitoredResourceDescriptors: []gax.CallOption{
  103. gax.WithTimeout(60000 * time.Millisecond),
  104. gax.WithRetry(func() gax.Retryer {
  105. return gax.OnCodes([]codes.Code{
  106. codes.DeadlineExceeded,
  107. codes.Internal,
  108. codes.Unavailable,
  109. }, gax.Backoff{
  110. Initial: 100 * time.Millisecond,
  111. Max: 60000 * time.Millisecond,
  112. Multiplier: 1.30,
  113. })
  114. }),
  115. },
  116. ListLogs: []gax.CallOption{
  117. gax.WithTimeout(60000 * time.Millisecond),
  118. gax.WithRetry(func() gax.Retryer {
  119. return gax.OnCodes([]codes.Code{
  120. codes.DeadlineExceeded,
  121. codes.Internal,
  122. codes.Unavailable,
  123. }, gax.Backoff{
  124. Initial: 100 * time.Millisecond,
  125. Max: 60000 * time.Millisecond,
  126. Multiplier: 1.30,
  127. })
  128. }),
  129. },
  130. TailLogEntries: []gax.CallOption{
  131. gax.WithRetry(func() gax.Retryer {
  132. return gax.OnCodes([]codes.Code{
  133. codes.DeadlineExceeded,
  134. codes.Internal,
  135. codes.Unavailable,
  136. }, gax.Backoff{
  137. Initial: 100 * time.Millisecond,
  138. Max: 60000 * time.Millisecond,
  139. Multiplier: 1.30,
  140. })
  141. }),
  142. },
  143. CancelOperation: []gax.CallOption{},
  144. GetOperation: []gax.CallOption{},
  145. ListOperations: []gax.CallOption{},
  146. }
  147. }
  148. // internalClient is an interface that defines the methods available from Cloud Logging API.
  149. type internalClient interface {
  150. Close() error
  151. setGoogleClientInfo(...string)
  152. Connection() *grpc.ClientConn
  153. DeleteLog(context.Context, *loggingpb.DeleteLogRequest, ...gax.CallOption) error
  154. WriteLogEntries(context.Context, *loggingpb.WriteLogEntriesRequest, ...gax.CallOption) (*loggingpb.WriteLogEntriesResponse, error)
  155. ListLogEntries(context.Context, *loggingpb.ListLogEntriesRequest, ...gax.CallOption) *LogEntryIterator
  156. ListMonitoredResourceDescriptors(context.Context, *loggingpb.ListMonitoredResourceDescriptorsRequest, ...gax.CallOption) *MonitoredResourceDescriptorIterator
  157. ListLogs(context.Context, *loggingpb.ListLogsRequest, ...gax.CallOption) *StringIterator
  158. TailLogEntries(context.Context, ...gax.CallOption) (loggingpb.LoggingServiceV2_TailLogEntriesClient, error)
  159. CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error
  160. GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error)
  161. ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator
  162. }
  163. // Client is a client for interacting with Cloud Logging API.
  164. // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
  165. //
  166. // Service for ingesting and querying logs.
  167. type Client struct {
  168. // The internal transport-dependent client.
  169. internalClient internalClient
  170. // The call options for this service.
  171. CallOptions *CallOptions
  172. }
  173. // Wrapper methods routed to the internal client.
  174. // Close closes the connection to the API service. The user should invoke this when
  175. // the client is no longer required.
  176. func (c *Client) Close() error {
  177. return c.internalClient.Close()
  178. }
  179. // setGoogleClientInfo sets the name and version of the application in
  180. // the `x-goog-api-client` header passed on each request. Intended for
  181. // use by Google-written clients.
  182. func (c *Client) setGoogleClientInfo(keyval ...string) {
  183. c.internalClient.setGoogleClientInfo(keyval...)
  184. }
  185. // Connection returns a connection to the API service.
  186. //
  187. // Deprecated: Connections are now pooled so this method does not always
  188. // return the same resource.
  189. func (c *Client) Connection() *grpc.ClientConn {
  190. return c.internalClient.Connection()
  191. }
  192. // DeleteLog deletes all the log entries in a log for the _Default Log Bucket. The log
  193. // reappears if it receives new entries. Log entries written shortly before
  194. // the delete operation might not be deleted. Entries received after the
  195. // delete operation with a timestamp before the operation will be deleted.
  196. func (c *Client) DeleteLog(ctx context.Context, req *loggingpb.DeleteLogRequest, opts ...gax.CallOption) error {
  197. return c.internalClient.DeleteLog(ctx, req, opts...)
  198. }
  199. // WriteLogEntries writes log entries to Logging. This API method is the
  200. // only way to send log entries to Logging. This method
  201. // is used, directly or indirectly, by the Logging agent
  202. // (fluentd) and all logging libraries configured to use Logging.
  203. // A single request may contain log entries for a maximum of 1000
  204. // different resources (projects, organizations, billing accounts or
  205. // folders)
  206. func (c *Client) WriteLogEntries(ctx context.Context, req *loggingpb.WriteLogEntriesRequest, opts ...gax.CallOption) (*loggingpb.WriteLogEntriesResponse, error) {
  207. return c.internalClient.WriteLogEntries(ctx, req, opts...)
  208. }
  209. // ListLogEntries lists log entries. Use this method to retrieve log entries that originated
  210. // from a project/folder/organization/billing account. For ways to export log
  211. // entries, see Exporting
  212. // Logs (at https://cloud.google.com/logging/docs/export).
  213. func (c *Client) ListLogEntries(ctx context.Context, req *loggingpb.ListLogEntriesRequest, opts ...gax.CallOption) *LogEntryIterator {
  214. return c.internalClient.ListLogEntries(ctx, req, opts...)
  215. }
  216. // ListMonitoredResourceDescriptors lists the descriptors for monitored resource types used by Logging.
  217. func (c *Client) ListMonitoredResourceDescriptors(ctx context.Context, req *loggingpb.ListMonitoredResourceDescriptorsRequest, opts ...gax.CallOption) *MonitoredResourceDescriptorIterator {
  218. return c.internalClient.ListMonitoredResourceDescriptors(ctx, req, opts...)
  219. }
  220. // ListLogs lists the logs in projects, organizations, folders, or billing accounts.
  221. // Only logs that have entries are listed.
  222. func (c *Client) ListLogs(ctx context.Context, req *loggingpb.ListLogsRequest, opts ...gax.CallOption) *StringIterator {
  223. return c.internalClient.ListLogs(ctx, req, opts...)
  224. }
  225. // TailLogEntries streaming read of log entries as they are ingested. Until the stream is
  226. // terminated, it will continue reading logs.
  227. func (c *Client) TailLogEntries(ctx context.Context, opts ...gax.CallOption) (loggingpb.LoggingServiceV2_TailLogEntriesClient, error) {
  228. return c.internalClient.TailLogEntries(ctx, opts...)
  229. }
  230. // CancelOperation is a utility method from google.longrunning.Operations.
  231. func (c *Client) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
  232. return c.internalClient.CancelOperation(ctx, req, opts...)
  233. }
  234. // GetOperation is a utility method from google.longrunning.Operations.
  235. func (c *Client) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
  236. return c.internalClient.GetOperation(ctx, req, opts...)
  237. }
  238. // ListOperations is a utility method from google.longrunning.Operations.
  239. func (c *Client) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
  240. return c.internalClient.ListOperations(ctx, req, opts...)
  241. }
  242. // gRPCClient is a client for interacting with Cloud Logging API over gRPC transport.
  243. //
  244. // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
  245. type gRPCClient struct {
  246. // Connection pool of gRPC connections to the service.
  247. connPool gtransport.ConnPool
  248. // Points back to the CallOptions field of the containing Client
  249. CallOptions **CallOptions
  250. // The gRPC API client.
  251. client loggingpb.LoggingServiceV2Client
  252. operationsClient longrunningpb.OperationsClient
  253. // The x-goog-* metadata to be sent with each request.
  254. xGoogHeaders []string
  255. }
  256. // NewClient creates a new logging service v2 client based on gRPC.
  257. // The returned client must be Closed when it is done being used to clean up its underlying connections.
  258. //
  259. // Service for ingesting and querying logs.
  260. func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) {
  261. clientOpts := defaultGRPCClientOptions()
  262. if newClientHook != nil {
  263. hookOpts, err := newClientHook(ctx, clientHookParams{})
  264. if err != nil {
  265. return nil, err
  266. }
  267. clientOpts = append(clientOpts, hookOpts...)
  268. }
  269. connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
  270. if err != nil {
  271. return nil, err
  272. }
  273. client := Client{CallOptions: defaultCallOptions()}
  274. c := &gRPCClient{
  275. connPool: connPool,
  276. client: loggingpb.NewLoggingServiceV2Client(connPool),
  277. CallOptions: &client.CallOptions,
  278. operationsClient: longrunningpb.NewOperationsClient(connPool),
  279. }
  280. c.setGoogleClientInfo()
  281. client.internalClient = c
  282. return &client, nil
  283. }
  284. // Connection returns a connection to the API service.
  285. //
  286. // Deprecated: Connections are now pooled so this method does not always
  287. // return the same resource.
  288. func (c *gRPCClient) Connection() *grpc.ClientConn {
  289. return c.connPool.Conn()
  290. }
  291. // setGoogleClientInfo sets the name and version of the application in
  292. // the `x-goog-api-client` header passed on each request. Intended for
  293. // use by Google-written clients.
  294. func (c *gRPCClient) setGoogleClientInfo(keyval ...string) {
  295. kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
  296. kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version)
  297. c.xGoogHeaders = []string{"x-goog-api-client", gax.XGoogHeader(kv...)}
  298. }
  299. // Close closes the connection to the API service. The user should invoke this when
  300. // the client is no longer required.
  301. func (c *gRPCClient) Close() error {
  302. return c.connPool.Close()
  303. }
  304. func (c *gRPCClient) DeleteLog(ctx context.Context, req *loggingpb.DeleteLogRequest, opts ...gax.CallOption) error {
  305. hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "log_name", url.QueryEscape(req.GetLogName()))}
  306. hds = append(c.xGoogHeaders, hds...)
  307. ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  308. opts = append((*c.CallOptions).DeleteLog[0:len((*c.CallOptions).DeleteLog):len((*c.CallOptions).DeleteLog)], opts...)
  309. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  310. var err error
  311. _, err = c.client.DeleteLog(ctx, req, settings.GRPC...)
  312. return err
  313. }, opts...)
  314. return err
  315. }
  316. func (c *gRPCClient) WriteLogEntries(ctx context.Context, req *loggingpb.WriteLogEntriesRequest, opts ...gax.CallOption) (*loggingpb.WriteLogEntriesResponse, error) {
  317. ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
  318. opts = append((*c.CallOptions).WriteLogEntries[0:len((*c.CallOptions).WriteLogEntries):len((*c.CallOptions).WriteLogEntries)], opts...)
  319. var resp *loggingpb.WriteLogEntriesResponse
  320. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  321. var err error
  322. resp, err = c.client.WriteLogEntries(ctx, req, settings.GRPC...)
  323. return err
  324. }, opts...)
  325. if err != nil {
  326. return nil, err
  327. }
  328. return resp, nil
  329. }
  330. func (c *gRPCClient) ListLogEntries(ctx context.Context, req *loggingpb.ListLogEntriesRequest, opts ...gax.CallOption) *LogEntryIterator {
  331. ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
  332. opts = append((*c.CallOptions).ListLogEntries[0:len((*c.CallOptions).ListLogEntries):len((*c.CallOptions).ListLogEntries)], opts...)
  333. it := &LogEntryIterator{}
  334. req = proto.Clone(req).(*loggingpb.ListLogEntriesRequest)
  335. it.InternalFetch = func(pageSize int, pageToken string) ([]*loggingpb.LogEntry, string, error) {
  336. resp := &loggingpb.ListLogEntriesResponse{}
  337. if pageToken != "" {
  338. req.PageToken = pageToken
  339. }
  340. if pageSize > math.MaxInt32 {
  341. req.PageSize = math.MaxInt32
  342. } else if pageSize != 0 {
  343. req.PageSize = int32(pageSize)
  344. }
  345. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  346. var err error
  347. resp, err = c.client.ListLogEntries(ctx, req, settings.GRPC...)
  348. return err
  349. }, opts...)
  350. if err != nil {
  351. return nil, "", err
  352. }
  353. it.Response = resp
  354. return resp.GetEntries(), resp.GetNextPageToken(), nil
  355. }
  356. fetch := func(pageSize int, pageToken string) (string, error) {
  357. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  358. if err != nil {
  359. return "", err
  360. }
  361. it.items = append(it.items, items...)
  362. return nextPageToken, nil
  363. }
  364. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  365. it.pageInfo.MaxSize = int(req.GetPageSize())
  366. it.pageInfo.Token = req.GetPageToken()
  367. return it
  368. }
  369. func (c *gRPCClient) ListMonitoredResourceDescriptors(ctx context.Context, req *loggingpb.ListMonitoredResourceDescriptorsRequest, opts ...gax.CallOption) *MonitoredResourceDescriptorIterator {
  370. ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
  371. opts = append((*c.CallOptions).ListMonitoredResourceDescriptors[0:len((*c.CallOptions).ListMonitoredResourceDescriptors):len((*c.CallOptions).ListMonitoredResourceDescriptors)], opts...)
  372. it := &MonitoredResourceDescriptorIterator{}
  373. req = proto.Clone(req).(*loggingpb.ListMonitoredResourceDescriptorsRequest)
  374. it.InternalFetch = func(pageSize int, pageToken string) ([]*monitoredrespb.MonitoredResourceDescriptor, string, error) {
  375. resp := &loggingpb.ListMonitoredResourceDescriptorsResponse{}
  376. if pageToken != "" {
  377. req.PageToken = pageToken
  378. }
  379. if pageSize > math.MaxInt32 {
  380. req.PageSize = math.MaxInt32
  381. } else if pageSize != 0 {
  382. req.PageSize = int32(pageSize)
  383. }
  384. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  385. var err error
  386. resp, err = c.client.ListMonitoredResourceDescriptors(ctx, req, settings.GRPC...)
  387. return err
  388. }, opts...)
  389. if err != nil {
  390. return nil, "", err
  391. }
  392. it.Response = resp
  393. return resp.GetResourceDescriptors(), resp.GetNextPageToken(), nil
  394. }
  395. fetch := func(pageSize int, pageToken string) (string, error) {
  396. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  397. if err != nil {
  398. return "", err
  399. }
  400. it.items = append(it.items, items...)
  401. return nextPageToken, nil
  402. }
  403. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  404. it.pageInfo.MaxSize = int(req.GetPageSize())
  405. it.pageInfo.Token = req.GetPageToken()
  406. return it
  407. }
  408. func (c *gRPCClient) ListLogs(ctx context.Context, req *loggingpb.ListLogsRequest, opts ...gax.CallOption) *StringIterator {
  409. hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
  410. hds = append(c.xGoogHeaders, hds...)
  411. ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  412. opts = append((*c.CallOptions).ListLogs[0:len((*c.CallOptions).ListLogs):len((*c.CallOptions).ListLogs)], opts...)
  413. it := &StringIterator{}
  414. req = proto.Clone(req).(*loggingpb.ListLogsRequest)
  415. it.InternalFetch = func(pageSize int, pageToken string) ([]string, string, error) {
  416. resp := &loggingpb.ListLogsResponse{}
  417. if pageToken != "" {
  418. req.PageToken = pageToken
  419. }
  420. if pageSize > math.MaxInt32 {
  421. req.PageSize = math.MaxInt32
  422. } else if pageSize != 0 {
  423. req.PageSize = int32(pageSize)
  424. }
  425. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  426. var err error
  427. resp, err = c.client.ListLogs(ctx, req, settings.GRPC...)
  428. return err
  429. }, opts...)
  430. if err != nil {
  431. return nil, "", err
  432. }
  433. it.Response = resp
  434. return resp.GetLogNames(), resp.GetNextPageToken(), nil
  435. }
  436. fetch := func(pageSize int, pageToken string) (string, error) {
  437. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  438. if err != nil {
  439. return "", err
  440. }
  441. it.items = append(it.items, items...)
  442. return nextPageToken, nil
  443. }
  444. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  445. it.pageInfo.MaxSize = int(req.GetPageSize())
  446. it.pageInfo.Token = req.GetPageToken()
  447. return it
  448. }
  449. func (c *gRPCClient) TailLogEntries(ctx context.Context, opts ...gax.CallOption) (loggingpb.LoggingServiceV2_TailLogEntriesClient, error) {
  450. ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
  451. var resp loggingpb.LoggingServiceV2_TailLogEntriesClient
  452. opts = append((*c.CallOptions).TailLogEntries[0:len((*c.CallOptions).TailLogEntries):len((*c.CallOptions).TailLogEntries)], opts...)
  453. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  454. var err error
  455. resp, err = c.client.TailLogEntries(ctx, settings.GRPC...)
  456. return err
  457. }, opts...)
  458. if err != nil {
  459. return nil, err
  460. }
  461. return resp, nil
  462. }
  463. func (c *gRPCClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
  464. hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  465. hds = append(c.xGoogHeaders, hds...)
  466. ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  467. opts = append((*c.CallOptions).CancelOperation[0:len((*c.CallOptions).CancelOperation):len((*c.CallOptions).CancelOperation)], opts...)
  468. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  469. var err error
  470. _, err = c.operationsClient.CancelOperation(ctx, req, settings.GRPC...)
  471. return err
  472. }, opts...)
  473. return err
  474. }
  475. func (c *gRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
  476. hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  477. hds = append(c.xGoogHeaders, hds...)
  478. ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  479. opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
  480. var resp *longrunningpb.Operation
  481. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  482. var err error
  483. resp, err = c.operationsClient.GetOperation(ctx, req, settings.GRPC...)
  484. return err
  485. }, opts...)
  486. if err != nil {
  487. return nil, err
  488. }
  489. return resp, nil
  490. }
  491. func (c *gRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
  492. hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
  493. hds = append(c.xGoogHeaders, hds...)
  494. ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
  495. opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...)
  496. it := &OperationIterator{}
  497. req = proto.Clone(req).(*longrunningpb.ListOperationsRequest)
  498. it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
  499. resp := &longrunningpb.ListOperationsResponse{}
  500. if pageToken != "" {
  501. req.PageToken = pageToken
  502. }
  503. if pageSize > math.MaxInt32 {
  504. req.PageSize = math.MaxInt32
  505. } else if pageSize != 0 {
  506. req.PageSize = int32(pageSize)
  507. }
  508. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  509. var err error
  510. resp, err = c.operationsClient.ListOperations(ctx, req, settings.GRPC...)
  511. return err
  512. }, opts...)
  513. if err != nil {
  514. return nil, "", err
  515. }
  516. it.Response = resp
  517. return resp.GetOperations(), resp.GetNextPageToken(), nil
  518. }
  519. fetch := func(pageSize int, pageToken string) (string, error) {
  520. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  521. if err != nil {
  522. return "", err
  523. }
  524. it.items = append(it.items, items...)
  525. return nextPageToken, nil
  526. }
  527. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  528. it.pageInfo.MaxSize = int(req.GetPageSize())
  529. it.pageInfo.Token = req.GetPageToken()
  530. return it
  531. }
  532. // LogEntryIterator manages a stream of *loggingpb.LogEntry.
  533. type LogEntryIterator struct {
  534. items []*loggingpb.LogEntry
  535. pageInfo *iterator.PageInfo
  536. nextFunc func() error
  537. // Response is the raw response for the current page.
  538. // It must be cast to the RPC response type.
  539. // Calling Next() or InternalFetch() updates this value.
  540. Response interface{}
  541. // InternalFetch is for use by the Google Cloud Libraries only.
  542. // It is not part of the stable interface of this package.
  543. //
  544. // InternalFetch returns results from a single call to the underlying RPC.
  545. // The number of results is no greater than pageSize.
  546. // If there are no more results, nextPageToken is empty and err is nil.
  547. InternalFetch func(pageSize int, pageToken string) (results []*loggingpb.LogEntry, nextPageToken string, err error)
  548. }
  549. // PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
  550. func (it *LogEntryIterator) PageInfo() *iterator.PageInfo {
  551. return it.pageInfo
  552. }
  553. // Next returns the next result. Its second return value is iterator.Done if there are no more
  554. // results. Once Next returns Done, all subsequent calls will return Done.
  555. func (it *LogEntryIterator) Next() (*loggingpb.LogEntry, error) {
  556. var item *loggingpb.LogEntry
  557. if err := it.nextFunc(); err != nil {
  558. return item, err
  559. }
  560. item = it.items[0]
  561. it.items = it.items[1:]
  562. return item, nil
  563. }
  564. func (it *LogEntryIterator) bufLen() int {
  565. return len(it.items)
  566. }
  567. func (it *LogEntryIterator) takeBuf() interface{} {
  568. b := it.items
  569. it.items = nil
  570. return b
  571. }
  572. // MonitoredResourceDescriptorIterator manages a stream of *monitoredrespb.MonitoredResourceDescriptor.
  573. type MonitoredResourceDescriptorIterator struct {
  574. items []*monitoredrespb.MonitoredResourceDescriptor
  575. pageInfo *iterator.PageInfo
  576. nextFunc func() error
  577. // Response is the raw response for the current page.
  578. // It must be cast to the RPC response type.
  579. // Calling Next() or InternalFetch() updates this value.
  580. Response interface{}
  581. // InternalFetch is for use by the Google Cloud Libraries only.
  582. // It is not part of the stable interface of this package.
  583. //
  584. // InternalFetch returns results from a single call to the underlying RPC.
  585. // The number of results is no greater than pageSize.
  586. // If there are no more results, nextPageToken is empty and err is nil.
  587. InternalFetch func(pageSize int, pageToken string) (results []*monitoredrespb.MonitoredResourceDescriptor, nextPageToken string, err error)
  588. }
  589. // PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
  590. func (it *MonitoredResourceDescriptorIterator) PageInfo() *iterator.PageInfo {
  591. return it.pageInfo
  592. }
  593. // Next returns the next result. Its second return value is iterator.Done if there are no more
  594. // results. Once Next returns Done, all subsequent calls will return Done.
  595. func (it *MonitoredResourceDescriptorIterator) Next() (*monitoredrespb.MonitoredResourceDescriptor, error) {
  596. var item *monitoredrespb.MonitoredResourceDescriptor
  597. if err := it.nextFunc(); err != nil {
  598. return item, err
  599. }
  600. item = it.items[0]
  601. it.items = it.items[1:]
  602. return item, nil
  603. }
  604. func (it *MonitoredResourceDescriptorIterator) bufLen() int {
  605. return len(it.items)
  606. }
  607. func (it *MonitoredResourceDescriptorIterator) takeBuf() interface{} {
  608. b := it.items
  609. it.items = nil
  610. return b
  611. }
  612. // OperationIterator manages a stream of *longrunningpb.Operation.
  613. type OperationIterator struct {
  614. items []*longrunningpb.Operation
  615. pageInfo *iterator.PageInfo
  616. nextFunc func() error
  617. // Response is the raw response for the current page.
  618. // It must be cast to the RPC response type.
  619. // Calling Next() or InternalFetch() updates this value.
  620. Response interface{}
  621. // InternalFetch is for use by the Google Cloud Libraries only.
  622. // It is not part of the stable interface of this package.
  623. //
  624. // InternalFetch returns results from a single call to the underlying RPC.
  625. // The number of results is no greater than pageSize.
  626. // If there are no more results, nextPageToken is empty and err is nil.
  627. InternalFetch func(pageSize int, pageToken string) (results []*longrunningpb.Operation, nextPageToken string, err error)
  628. }
  629. // PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
  630. func (it *OperationIterator) PageInfo() *iterator.PageInfo {
  631. return it.pageInfo
  632. }
  633. // Next returns the next result. Its second return value is iterator.Done if there are no more
  634. // results. Once Next returns Done, all subsequent calls will return Done.
  635. func (it *OperationIterator) Next() (*longrunningpb.Operation, error) {
  636. var item *longrunningpb.Operation
  637. if err := it.nextFunc(); err != nil {
  638. return item, err
  639. }
  640. item = it.items[0]
  641. it.items = it.items[1:]
  642. return item, nil
  643. }
  644. func (it *OperationIterator) bufLen() int {
  645. return len(it.items)
  646. }
  647. func (it *OperationIterator) takeBuf() interface{} {
  648. b := it.items
  649. it.items = nil
  650. return b
  651. }
  652. // StringIterator manages a stream of string.
  653. type StringIterator struct {
  654. items []string
  655. pageInfo *iterator.PageInfo
  656. nextFunc func() error
  657. // Response is the raw response for the current page.
  658. // It must be cast to the RPC response type.
  659. // Calling Next() or InternalFetch() updates this value.
  660. Response interface{}
  661. // InternalFetch is for use by the Google Cloud Libraries only.
  662. // It is not part of the stable interface of this package.
  663. //
  664. // InternalFetch returns results from a single call to the underlying RPC.
  665. // The number of results is no greater than pageSize.
  666. // If there are no more results, nextPageToken is empty and err is nil.
  667. InternalFetch func(pageSize int, pageToken string) (results []string, nextPageToken string, err error)
  668. }
  669. // PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
  670. func (it *StringIterator) PageInfo() *iterator.PageInfo {
  671. return it.pageInfo
  672. }
  673. // Next returns the next result. Its second return value is iterator.Done if there are no more
  674. // results. Once Next returns Done, all subsequent calls will return Done.
  675. func (it *StringIterator) Next() (string, error) {
  676. var item string
  677. if err := it.nextFunc(); err != nil {
  678. return item, err
  679. }
  680. item = it.items[0]
  681. it.items = it.items[1:]
  682. return item, nil
  683. }
  684. func (it *StringIterator) bufLen() int {
  685. return len(it.items)
  686. }
  687. func (it *StringIterator) takeBuf() interface{} {
  688. b := it.items
  689. it.items = nil
  690. return b
  691. }