...

Source file src/cloud.google.com/go/monitoring/apiv3/v2/service_monitoring_client.go

Documentation: cloud.google.com/go/monitoring/apiv3/v2

     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 monitoring
    18  
    19  import (
    20  	"context"
    21  	"fmt"
    22  	"math"
    23  	"net/url"
    24  	"time"
    25  
    26  	monitoringpb "cloud.google.com/go/monitoring/apiv3/v2/monitoringpb"
    27  	gax "github.com/googleapis/gax-go/v2"
    28  	"google.golang.org/api/iterator"
    29  	"google.golang.org/api/option"
    30  	"google.golang.org/api/option/internaloption"
    31  	gtransport "google.golang.org/api/transport/grpc"
    32  	"google.golang.org/grpc"
    33  	"google.golang.org/grpc/codes"
    34  	"google.golang.org/protobuf/proto"
    35  )
    36  
    37  var newServiceMonitoringClientHook clientHook
    38  
    39  // ServiceMonitoringCallOptions contains the retry settings for each method of ServiceMonitoringClient.
    40  type ServiceMonitoringCallOptions struct {
    41  	CreateService               []gax.CallOption
    42  	GetService                  []gax.CallOption
    43  	ListServices                []gax.CallOption
    44  	UpdateService               []gax.CallOption
    45  	DeleteService               []gax.CallOption
    46  	CreateServiceLevelObjective []gax.CallOption
    47  	GetServiceLevelObjective    []gax.CallOption
    48  	ListServiceLevelObjectives  []gax.CallOption
    49  	UpdateServiceLevelObjective []gax.CallOption
    50  	DeleteServiceLevelObjective []gax.CallOption
    51  }
    52  
    53  func defaultServiceMonitoringGRPCClientOptions() []option.ClientOption {
    54  	return []option.ClientOption{
    55  		internaloption.WithDefaultEndpoint("monitoring.googleapis.com:443"),
    56  		internaloption.WithDefaultEndpointTemplate("monitoring.UNIVERSE_DOMAIN:443"),
    57  		internaloption.WithDefaultMTLSEndpoint("monitoring.mtls.googleapis.com:443"),
    58  		internaloption.WithDefaultUniverseDomain("googleapis.com"),
    59  		internaloption.WithDefaultAudience("https://monitoring.googleapis.com/"),
    60  		internaloption.WithDefaultScopes(DefaultAuthScopes()...),
    61  		internaloption.EnableJwtWithScope(),
    62  		option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
    63  			grpc.MaxCallRecvMsgSize(math.MaxInt32))),
    64  	}
    65  }
    66  
    67  func defaultServiceMonitoringCallOptions() *ServiceMonitoringCallOptions {
    68  	return &ServiceMonitoringCallOptions{
    69  		CreateService: []gax.CallOption{
    70  			gax.WithTimeout(30000 * time.Millisecond),
    71  		},
    72  		GetService: []gax.CallOption{
    73  			gax.WithTimeout(30000 * time.Millisecond),
    74  			gax.WithRetry(func() gax.Retryer {
    75  				return gax.OnCodes([]codes.Code{
    76  					codes.Unavailable,
    77  				}, gax.Backoff{
    78  					Initial:    100 * time.Millisecond,
    79  					Max:        30000 * time.Millisecond,
    80  					Multiplier: 1.30,
    81  				})
    82  			}),
    83  		},
    84  		ListServices: []gax.CallOption{
    85  			gax.WithTimeout(30000 * time.Millisecond),
    86  			gax.WithRetry(func() gax.Retryer {
    87  				return gax.OnCodes([]codes.Code{
    88  					codes.Unavailable,
    89  				}, gax.Backoff{
    90  					Initial:    100 * time.Millisecond,
    91  					Max:        30000 * time.Millisecond,
    92  					Multiplier: 1.30,
    93  				})
    94  			}),
    95  		},
    96  		UpdateService: []gax.CallOption{
    97  			gax.WithTimeout(30000 * time.Millisecond),
    98  		},
    99  		DeleteService: []gax.CallOption{
   100  			gax.WithTimeout(30000 * time.Millisecond),
   101  			gax.WithRetry(func() gax.Retryer {
   102  				return gax.OnCodes([]codes.Code{
   103  					codes.Unavailable,
   104  				}, gax.Backoff{
   105  					Initial:    100 * time.Millisecond,
   106  					Max:        30000 * time.Millisecond,
   107  					Multiplier: 1.30,
   108  				})
   109  			}),
   110  		},
   111  		CreateServiceLevelObjective: []gax.CallOption{
   112  			gax.WithTimeout(30000 * time.Millisecond),
   113  		},
   114  		GetServiceLevelObjective: []gax.CallOption{
   115  			gax.WithTimeout(30000 * time.Millisecond),
   116  			gax.WithRetry(func() gax.Retryer {
   117  				return gax.OnCodes([]codes.Code{
   118  					codes.Unavailable,
   119  				}, gax.Backoff{
   120  					Initial:    100 * time.Millisecond,
   121  					Max:        30000 * time.Millisecond,
   122  					Multiplier: 1.30,
   123  				})
   124  			}),
   125  		},
   126  		ListServiceLevelObjectives: []gax.CallOption{
   127  			gax.WithTimeout(30000 * time.Millisecond),
   128  			gax.WithRetry(func() gax.Retryer {
   129  				return gax.OnCodes([]codes.Code{
   130  					codes.Unavailable,
   131  				}, gax.Backoff{
   132  					Initial:    100 * time.Millisecond,
   133  					Max:        30000 * time.Millisecond,
   134  					Multiplier: 1.30,
   135  				})
   136  			}),
   137  		},
   138  		UpdateServiceLevelObjective: []gax.CallOption{
   139  			gax.WithTimeout(30000 * time.Millisecond),
   140  		},
   141  		DeleteServiceLevelObjective: []gax.CallOption{
   142  			gax.WithTimeout(30000 * time.Millisecond),
   143  			gax.WithRetry(func() gax.Retryer {
   144  				return gax.OnCodes([]codes.Code{
   145  					codes.Unavailable,
   146  				}, gax.Backoff{
   147  					Initial:    100 * time.Millisecond,
   148  					Max:        30000 * time.Millisecond,
   149  					Multiplier: 1.30,
   150  				})
   151  			}),
   152  		},
   153  	}
   154  }
   155  
   156  // internalServiceMonitoringClient is an interface that defines the methods available from Cloud Monitoring API.
   157  type internalServiceMonitoringClient interface {
   158  	Close() error
   159  	setGoogleClientInfo(...string)
   160  	Connection() *grpc.ClientConn
   161  	CreateService(context.Context, *monitoringpb.CreateServiceRequest, ...gax.CallOption) (*monitoringpb.Service, error)
   162  	GetService(context.Context, *monitoringpb.GetServiceRequest, ...gax.CallOption) (*monitoringpb.Service, error)
   163  	ListServices(context.Context, *monitoringpb.ListServicesRequest, ...gax.CallOption) *ServiceIterator
   164  	UpdateService(context.Context, *monitoringpb.UpdateServiceRequest, ...gax.CallOption) (*monitoringpb.Service, error)
   165  	DeleteService(context.Context, *monitoringpb.DeleteServiceRequest, ...gax.CallOption) error
   166  	CreateServiceLevelObjective(context.Context, *monitoringpb.CreateServiceLevelObjectiveRequest, ...gax.CallOption) (*monitoringpb.ServiceLevelObjective, error)
   167  	GetServiceLevelObjective(context.Context, *monitoringpb.GetServiceLevelObjectiveRequest, ...gax.CallOption) (*monitoringpb.ServiceLevelObjective, error)
   168  	ListServiceLevelObjectives(context.Context, *monitoringpb.ListServiceLevelObjectivesRequest, ...gax.CallOption) *ServiceLevelObjectiveIterator
   169  	UpdateServiceLevelObjective(context.Context, *monitoringpb.UpdateServiceLevelObjectiveRequest, ...gax.CallOption) (*monitoringpb.ServiceLevelObjective, error)
   170  	DeleteServiceLevelObjective(context.Context, *monitoringpb.DeleteServiceLevelObjectiveRequest, ...gax.CallOption) error
   171  }
   172  
   173  // ServiceMonitoringClient is a client for interacting with Cloud Monitoring API.
   174  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   175  //
   176  // The Cloud Monitoring Service-Oriented Monitoring API has endpoints for
   177  // managing and querying aspects of a Metrics Scope’s services. These include
   178  // the Service's monitored resources, its Service-Level Objectives, and a
   179  // taxonomy of categorized Health Metrics.
   180  type ServiceMonitoringClient struct {
   181  	// The internal transport-dependent client.
   182  	internalClient internalServiceMonitoringClient
   183  
   184  	// The call options for this service.
   185  	CallOptions *ServiceMonitoringCallOptions
   186  }
   187  
   188  // Wrapper methods routed to the internal client.
   189  
   190  // Close closes the connection to the API service. The user should invoke this when
   191  // the client is no longer required.
   192  func (c *ServiceMonitoringClient) Close() error {
   193  	return c.internalClient.Close()
   194  }
   195  
   196  // setGoogleClientInfo sets the name and version of the application in
   197  // the `x-goog-api-client` header passed on each request. Intended for
   198  // use by Google-written clients.
   199  func (c *ServiceMonitoringClient) setGoogleClientInfo(keyval ...string) {
   200  	c.internalClient.setGoogleClientInfo(keyval...)
   201  }
   202  
   203  // Connection returns a connection to the API service.
   204  //
   205  // Deprecated: Connections are now pooled so this method does not always
   206  // return the same resource.
   207  func (c *ServiceMonitoringClient) Connection() *grpc.ClientConn {
   208  	return c.internalClient.Connection()
   209  }
   210  
   211  // CreateService create a Service.
   212  func (c *ServiceMonitoringClient) CreateService(ctx context.Context, req *monitoringpb.CreateServiceRequest, opts ...gax.CallOption) (*monitoringpb.Service, error) {
   213  	return c.internalClient.CreateService(ctx, req, opts...)
   214  }
   215  
   216  // GetService get the named Service.
   217  func (c *ServiceMonitoringClient) GetService(ctx context.Context, req *monitoringpb.GetServiceRequest, opts ...gax.CallOption) (*monitoringpb.Service, error) {
   218  	return c.internalClient.GetService(ctx, req, opts...)
   219  }
   220  
   221  // ListServices list Services for this Metrics Scope.
   222  func (c *ServiceMonitoringClient) ListServices(ctx context.Context, req *monitoringpb.ListServicesRequest, opts ...gax.CallOption) *ServiceIterator {
   223  	return c.internalClient.ListServices(ctx, req, opts...)
   224  }
   225  
   226  // UpdateService update this Service.
   227  func (c *ServiceMonitoringClient) UpdateService(ctx context.Context, req *monitoringpb.UpdateServiceRequest, opts ...gax.CallOption) (*monitoringpb.Service, error) {
   228  	return c.internalClient.UpdateService(ctx, req, opts...)
   229  }
   230  
   231  // DeleteService soft delete this Service.
   232  func (c *ServiceMonitoringClient) DeleteService(ctx context.Context, req *monitoringpb.DeleteServiceRequest, opts ...gax.CallOption) error {
   233  	return c.internalClient.DeleteService(ctx, req, opts...)
   234  }
   235  
   236  // CreateServiceLevelObjective create a ServiceLevelObjective for the given Service.
   237  func (c *ServiceMonitoringClient) CreateServiceLevelObjective(ctx context.Context, req *monitoringpb.CreateServiceLevelObjectiveRequest, opts ...gax.CallOption) (*monitoringpb.ServiceLevelObjective, error) {
   238  	return c.internalClient.CreateServiceLevelObjective(ctx, req, opts...)
   239  }
   240  
   241  // GetServiceLevelObjective get a ServiceLevelObjective by name.
   242  func (c *ServiceMonitoringClient) GetServiceLevelObjective(ctx context.Context, req *monitoringpb.GetServiceLevelObjectiveRequest, opts ...gax.CallOption) (*monitoringpb.ServiceLevelObjective, error) {
   243  	return c.internalClient.GetServiceLevelObjective(ctx, req, opts...)
   244  }
   245  
   246  // ListServiceLevelObjectives list the ServiceLevelObjectives for the given Service.
   247  func (c *ServiceMonitoringClient) ListServiceLevelObjectives(ctx context.Context, req *monitoringpb.ListServiceLevelObjectivesRequest, opts ...gax.CallOption) *ServiceLevelObjectiveIterator {
   248  	return c.internalClient.ListServiceLevelObjectives(ctx, req, opts...)
   249  }
   250  
   251  // UpdateServiceLevelObjective update the given ServiceLevelObjective.
   252  func (c *ServiceMonitoringClient) UpdateServiceLevelObjective(ctx context.Context, req *monitoringpb.UpdateServiceLevelObjectiveRequest, opts ...gax.CallOption) (*monitoringpb.ServiceLevelObjective, error) {
   253  	return c.internalClient.UpdateServiceLevelObjective(ctx, req, opts...)
   254  }
   255  
   256  // DeleteServiceLevelObjective delete the given ServiceLevelObjective.
   257  func (c *ServiceMonitoringClient) DeleteServiceLevelObjective(ctx context.Context, req *monitoringpb.DeleteServiceLevelObjectiveRequest, opts ...gax.CallOption) error {
   258  	return c.internalClient.DeleteServiceLevelObjective(ctx, req, opts...)
   259  }
   260  
   261  // serviceMonitoringGRPCClient is a client for interacting with Cloud Monitoring API over gRPC transport.
   262  //
   263  // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
   264  type serviceMonitoringGRPCClient struct {
   265  	// Connection pool of gRPC connections to the service.
   266  	connPool gtransport.ConnPool
   267  
   268  	// Points back to the CallOptions field of the containing ServiceMonitoringClient
   269  	CallOptions **ServiceMonitoringCallOptions
   270  
   271  	// The gRPC API client.
   272  	serviceMonitoringClient monitoringpb.ServiceMonitoringServiceClient
   273  
   274  	// The x-goog-* metadata to be sent with each request.
   275  	xGoogHeaders []string
   276  }
   277  
   278  // NewServiceMonitoringClient creates a new service monitoring service client based on gRPC.
   279  // The returned client must be Closed when it is done being used to clean up its underlying connections.
   280  //
   281  // The Cloud Monitoring Service-Oriented Monitoring API has endpoints for
   282  // managing and querying aspects of a Metrics Scope’s services. These include
   283  // the Service's monitored resources, its Service-Level Objectives, and a
   284  // taxonomy of categorized Health Metrics.
   285  func NewServiceMonitoringClient(ctx context.Context, opts ...option.ClientOption) (*ServiceMonitoringClient, error) {
   286  	clientOpts := defaultServiceMonitoringGRPCClientOptions()
   287  	if newServiceMonitoringClientHook != nil {
   288  		hookOpts, err := newServiceMonitoringClientHook(ctx, clientHookParams{})
   289  		if err != nil {
   290  			return nil, err
   291  		}
   292  		clientOpts = append(clientOpts, hookOpts...)
   293  	}
   294  
   295  	connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
   296  	if err != nil {
   297  		return nil, err
   298  	}
   299  	client := ServiceMonitoringClient{CallOptions: defaultServiceMonitoringCallOptions()}
   300  
   301  	c := &serviceMonitoringGRPCClient{
   302  		connPool:                connPool,
   303  		serviceMonitoringClient: monitoringpb.NewServiceMonitoringServiceClient(connPool),
   304  		CallOptions:             &client.CallOptions,
   305  	}
   306  	c.setGoogleClientInfo()
   307  
   308  	client.internalClient = c
   309  
   310  	return &client, nil
   311  }
   312  
   313  // Connection returns a connection to the API service.
   314  //
   315  // Deprecated: Connections are now pooled so this method does not always
   316  // return the same resource.
   317  func (c *serviceMonitoringGRPCClient) Connection() *grpc.ClientConn {
   318  	return c.connPool.Conn()
   319  }
   320  
   321  // setGoogleClientInfo sets the name and version of the application in
   322  // the `x-goog-api-client` header passed on each request. Intended for
   323  // use by Google-written clients.
   324  func (c *serviceMonitoringGRPCClient) setGoogleClientInfo(keyval ...string) {
   325  	kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
   326  	kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version)
   327  	c.xGoogHeaders = []string{"x-goog-api-client", gax.XGoogHeader(kv...)}
   328  }
   329  
   330  // Close closes the connection to the API service. The user should invoke this when
   331  // the client is no longer required.
   332  func (c *serviceMonitoringGRPCClient) Close() error {
   333  	return c.connPool.Close()
   334  }
   335  
   336  func (c *serviceMonitoringGRPCClient) CreateService(ctx context.Context, req *monitoringpb.CreateServiceRequest, opts ...gax.CallOption) (*monitoringpb.Service, error) {
   337  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
   338  
   339  	hds = append(c.xGoogHeaders, hds...)
   340  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   341  	opts = append((*c.CallOptions).CreateService[0:len((*c.CallOptions).CreateService):len((*c.CallOptions).CreateService)], opts...)
   342  	var resp *monitoringpb.Service
   343  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   344  		var err error
   345  		resp, err = c.serviceMonitoringClient.CreateService(ctx, req, settings.GRPC...)
   346  		return err
   347  	}, opts...)
   348  	if err != nil {
   349  		return nil, err
   350  	}
   351  	return resp, nil
   352  }
   353  
   354  func (c *serviceMonitoringGRPCClient) GetService(ctx context.Context, req *monitoringpb.GetServiceRequest, opts ...gax.CallOption) (*monitoringpb.Service, error) {
   355  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   356  
   357  	hds = append(c.xGoogHeaders, hds...)
   358  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   359  	opts = append((*c.CallOptions).GetService[0:len((*c.CallOptions).GetService):len((*c.CallOptions).GetService)], opts...)
   360  	var resp *monitoringpb.Service
   361  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   362  		var err error
   363  		resp, err = c.serviceMonitoringClient.GetService(ctx, req, settings.GRPC...)
   364  		return err
   365  	}, opts...)
   366  	if err != nil {
   367  		return nil, err
   368  	}
   369  	return resp, nil
   370  }
   371  
   372  func (c *serviceMonitoringGRPCClient) ListServices(ctx context.Context, req *monitoringpb.ListServicesRequest, opts ...gax.CallOption) *ServiceIterator {
   373  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
   374  
   375  	hds = append(c.xGoogHeaders, hds...)
   376  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   377  	opts = append((*c.CallOptions).ListServices[0:len((*c.CallOptions).ListServices):len((*c.CallOptions).ListServices)], opts...)
   378  	it := &ServiceIterator{}
   379  	req = proto.Clone(req).(*monitoringpb.ListServicesRequest)
   380  	it.InternalFetch = func(pageSize int, pageToken string) ([]*monitoringpb.Service, string, error) {
   381  		resp := &monitoringpb.ListServicesResponse{}
   382  		if pageToken != "" {
   383  			req.PageToken = pageToken
   384  		}
   385  		if pageSize > math.MaxInt32 {
   386  			req.PageSize = math.MaxInt32
   387  		} else if pageSize != 0 {
   388  			req.PageSize = int32(pageSize)
   389  		}
   390  		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   391  			var err error
   392  			resp, err = c.serviceMonitoringClient.ListServices(ctx, req, settings.GRPC...)
   393  			return err
   394  		}, opts...)
   395  		if err != nil {
   396  			return nil, "", err
   397  		}
   398  
   399  		it.Response = resp
   400  		return resp.GetServices(), resp.GetNextPageToken(), nil
   401  	}
   402  	fetch := func(pageSize int, pageToken string) (string, error) {
   403  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
   404  		if err != nil {
   405  			return "", err
   406  		}
   407  		it.items = append(it.items, items...)
   408  		return nextPageToken, nil
   409  	}
   410  
   411  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
   412  	it.pageInfo.MaxSize = int(req.GetPageSize())
   413  	it.pageInfo.Token = req.GetPageToken()
   414  
   415  	return it
   416  }
   417  
   418  func (c *serviceMonitoringGRPCClient) UpdateService(ctx context.Context, req *monitoringpb.UpdateServiceRequest, opts ...gax.CallOption) (*monitoringpb.Service, error) {
   419  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "service.name", url.QueryEscape(req.GetService().GetName()))}
   420  
   421  	hds = append(c.xGoogHeaders, hds...)
   422  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   423  	opts = append((*c.CallOptions).UpdateService[0:len((*c.CallOptions).UpdateService):len((*c.CallOptions).UpdateService)], opts...)
   424  	var resp *monitoringpb.Service
   425  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   426  		var err error
   427  		resp, err = c.serviceMonitoringClient.UpdateService(ctx, req, settings.GRPC...)
   428  		return err
   429  	}, opts...)
   430  	if err != nil {
   431  		return nil, err
   432  	}
   433  	return resp, nil
   434  }
   435  
   436  func (c *serviceMonitoringGRPCClient) DeleteService(ctx context.Context, req *monitoringpb.DeleteServiceRequest, opts ...gax.CallOption) error {
   437  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   438  
   439  	hds = append(c.xGoogHeaders, hds...)
   440  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   441  	opts = append((*c.CallOptions).DeleteService[0:len((*c.CallOptions).DeleteService):len((*c.CallOptions).DeleteService)], opts...)
   442  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   443  		var err error
   444  		_, err = c.serviceMonitoringClient.DeleteService(ctx, req, settings.GRPC...)
   445  		return err
   446  	}, opts...)
   447  	return err
   448  }
   449  
   450  func (c *serviceMonitoringGRPCClient) CreateServiceLevelObjective(ctx context.Context, req *monitoringpb.CreateServiceLevelObjectiveRequest, opts ...gax.CallOption) (*monitoringpb.ServiceLevelObjective, error) {
   451  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
   452  
   453  	hds = append(c.xGoogHeaders, hds...)
   454  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   455  	opts = append((*c.CallOptions).CreateServiceLevelObjective[0:len((*c.CallOptions).CreateServiceLevelObjective):len((*c.CallOptions).CreateServiceLevelObjective)], opts...)
   456  	var resp *monitoringpb.ServiceLevelObjective
   457  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   458  		var err error
   459  		resp, err = c.serviceMonitoringClient.CreateServiceLevelObjective(ctx, req, settings.GRPC...)
   460  		return err
   461  	}, opts...)
   462  	if err != nil {
   463  		return nil, err
   464  	}
   465  	return resp, nil
   466  }
   467  
   468  func (c *serviceMonitoringGRPCClient) GetServiceLevelObjective(ctx context.Context, req *monitoringpb.GetServiceLevelObjectiveRequest, opts ...gax.CallOption) (*monitoringpb.ServiceLevelObjective, error) {
   469  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   470  
   471  	hds = append(c.xGoogHeaders, hds...)
   472  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   473  	opts = append((*c.CallOptions).GetServiceLevelObjective[0:len((*c.CallOptions).GetServiceLevelObjective):len((*c.CallOptions).GetServiceLevelObjective)], opts...)
   474  	var resp *monitoringpb.ServiceLevelObjective
   475  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   476  		var err error
   477  		resp, err = c.serviceMonitoringClient.GetServiceLevelObjective(ctx, req, settings.GRPC...)
   478  		return err
   479  	}, opts...)
   480  	if err != nil {
   481  		return nil, err
   482  	}
   483  	return resp, nil
   484  }
   485  
   486  func (c *serviceMonitoringGRPCClient) ListServiceLevelObjectives(ctx context.Context, req *monitoringpb.ListServiceLevelObjectivesRequest, opts ...gax.CallOption) *ServiceLevelObjectiveIterator {
   487  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
   488  
   489  	hds = append(c.xGoogHeaders, hds...)
   490  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   491  	opts = append((*c.CallOptions).ListServiceLevelObjectives[0:len((*c.CallOptions).ListServiceLevelObjectives):len((*c.CallOptions).ListServiceLevelObjectives)], opts...)
   492  	it := &ServiceLevelObjectiveIterator{}
   493  	req = proto.Clone(req).(*monitoringpb.ListServiceLevelObjectivesRequest)
   494  	it.InternalFetch = func(pageSize int, pageToken string) ([]*monitoringpb.ServiceLevelObjective, string, error) {
   495  		resp := &monitoringpb.ListServiceLevelObjectivesResponse{}
   496  		if pageToken != "" {
   497  			req.PageToken = pageToken
   498  		}
   499  		if pageSize > math.MaxInt32 {
   500  			req.PageSize = math.MaxInt32
   501  		} else if pageSize != 0 {
   502  			req.PageSize = int32(pageSize)
   503  		}
   504  		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   505  			var err error
   506  			resp, err = c.serviceMonitoringClient.ListServiceLevelObjectives(ctx, req, settings.GRPC...)
   507  			return err
   508  		}, opts...)
   509  		if err != nil {
   510  			return nil, "", err
   511  		}
   512  
   513  		it.Response = resp
   514  		return resp.GetServiceLevelObjectives(), resp.GetNextPageToken(), nil
   515  	}
   516  	fetch := func(pageSize int, pageToken string) (string, error) {
   517  		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
   518  		if err != nil {
   519  			return "", err
   520  		}
   521  		it.items = append(it.items, items...)
   522  		return nextPageToken, nil
   523  	}
   524  
   525  	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
   526  	it.pageInfo.MaxSize = int(req.GetPageSize())
   527  	it.pageInfo.Token = req.GetPageToken()
   528  
   529  	return it
   530  }
   531  
   532  func (c *serviceMonitoringGRPCClient) UpdateServiceLevelObjective(ctx context.Context, req *monitoringpb.UpdateServiceLevelObjectiveRequest, opts ...gax.CallOption) (*monitoringpb.ServiceLevelObjective, error) {
   533  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "service_level_objective.name", url.QueryEscape(req.GetServiceLevelObjective().GetName()))}
   534  
   535  	hds = append(c.xGoogHeaders, hds...)
   536  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   537  	opts = append((*c.CallOptions).UpdateServiceLevelObjective[0:len((*c.CallOptions).UpdateServiceLevelObjective):len((*c.CallOptions).UpdateServiceLevelObjective)], opts...)
   538  	var resp *monitoringpb.ServiceLevelObjective
   539  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   540  		var err error
   541  		resp, err = c.serviceMonitoringClient.UpdateServiceLevelObjective(ctx, req, settings.GRPC...)
   542  		return err
   543  	}, opts...)
   544  	if err != nil {
   545  		return nil, err
   546  	}
   547  	return resp, nil
   548  }
   549  
   550  func (c *serviceMonitoringGRPCClient) DeleteServiceLevelObjective(ctx context.Context, req *monitoringpb.DeleteServiceLevelObjectiveRequest, opts ...gax.CallOption) error {
   551  	hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
   552  
   553  	hds = append(c.xGoogHeaders, hds...)
   554  	ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
   555  	opts = append((*c.CallOptions).DeleteServiceLevelObjective[0:len((*c.CallOptions).DeleteServiceLevelObjective):len((*c.CallOptions).DeleteServiceLevelObjective)], opts...)
   556  	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
   557  		var err error
   558  		_, err = c.serviceMonitoringClient.DeleteServiceLevelObjective(ctx, req, settings.GRPC...)
   559  		return err
   560  	}, opts...)
   561  	return err
   562  }
   563  

View as plain text