...

Source file src/cloud.google.com/go/logging/apiv2/logging_client.go

Documentation: cloud.google.com/go/logging/apiv2

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

View as plain text