1// Copyright 2021 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
17package monitoring
18
19import (
20	"context"
21	"fmt"
22	"math"
23	"net/url"
24	"time"
25
26	gax "github.com/googleapis/gax-go/v2"
27	"google.golang.org/api/iterator"
28	"google.golang.org/api/option"
29	"google.golang.org/api/option/internaloption"
30	gtransport "google.golang.org/api/transport/grpc"
31	monitoringpb "google.golang.org/genproto/googleapis/monitoring/v3"
32	"google.golang.org/grpc"
33	"google.golang.org/grpc/codes"
34	"google.golang.org/grpc/metadata"
35	"google.golang.org/protobuf/proto"
36)
37
38var newServiceMonitoringClientHook clientHook
39
40// ServiceMonitoringCallOptions contains the retry settings for each method of ServiceMonitoringClient.
41type ServiceMonitoringCallOptions struct {
42	CreateService               []gax.CallOption
43	GetService                  []gax.CallOption
44	ListServices                []gax.CallOption
45	UpdateService               []gax.CallOption
46	DeleteService               []gax.CallOption
47	CreateServiceLevelObjective []gax.CallOption
48	GetServiceLevelObjective    []gax.CallOption
49	ListServiceLevelObjectives  []gax.CallOption
50	UpdateServiceLevelObjective []gax.CallOption
51	DeleteServiceLevelObjective []gax.CallOption
52}
53
54func defaultServiceMonitoringGRPCClientOptions() []option.ClientOption {
55	return []option.ClientOption{
56		internaloption.WithDefaultEndpoint("monitoring.googleapis.com:443"),
57		internaloption.WithDefaultMTLSEndpoint("monitoring.mtls.googleapis.com:443"),
58		internaloption.WithDefaultAudience("https://monitoring.googleapis.com/"),
59		internaloption.WithDefaultScopes(DefaultAuthScopes()...),
60		internaloption.EnableJwtWithScope(),
61		option.WithGRPCDialOption(grpc.WithDisableServiceConfig()),
62		option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
63			grpc.MaxCallRecvMsgSize(math.MaxInt32))),
64	}
65}
66
67func defaultServiceMonitoringCallOptions() *ServiceMonitoringCallOptions {
68	return &ServiceMonitoringCallOptions{
69		CreateService: []gax.CallOption{},
70		GetService: []gax.CallOption{
71			gax.WithRetry(func() gax.Retryer {
72				return gax.OnCodes([]codes.Code{
73					codes.Unavailable,
74				}, gax.Backoff{
75					Initial:    100 * time.Millisecond,
76					Max:        30000 * time.Millisecond,
77					Multiplier: 1.30,
78				})
79			}),
80		},
81		ListServices: []gax.CallOption{
82			gax.WithRetry(func() gax.Retryer {
83				return gax.OnCodes([]codes.Code{
84					codes.Unavailable,
85				}, gax.Backoff{
86					Initial:    100 * time.Millisecond,
87					Max:        30000 * time.Millisecond,
88					Multiplier: 1.30,
89				})
90			}),
91		},
92		UpdateService: []gax.CallOption{},
93		DeleteService: []gax.CallOption{
94			gax.WithRetry(func() gax.Retryer {
95				return gax.OnCodes([]codes.Code{
96					codes.Unavailable,
97				}, gax.Backoff{
98					Initial:    100 * time.Millisecond,
99					Max:        30000 * time.Millisecond,
100					Multiplier: 1.30,
101				})
102			}),
103		},
104		CreateServiceLevelObjective: []gax.CallOption{},
105		GetServiceLevelObjective: []gax.CallOption{
106			gax.WithRetry(func() gax.Retryer {
107				return gax.OnCodes([]codes.Code{
108					codes.Unavailable,
109				}, gax.Backoff{
110					Initial:    100 * time.Millisecond,
111					Max:        30000 * time.Millisecond,
112					Multiplier: 1.30,
113				})
114			}),
115		},
116		ListServiceLevelObjectives: []gax.CallOption{
117			gax.WithRetry(func() gax.Retryer {
118				return gax.OnCodes([]codes.Code{
119					codes.Unavailable,
120				}, gax.Backoff{
121					Initial:    100 * time.Millisecond,
122					Max:        30000 * time.Millisecond,
123					Multiplier: 1.30,
124				})
125			}),
126		},
127		UpdateServiceLevelObjective: []gax.CallOption{},
128		DeleteServiceLevelObjective: []gax.CallOption{
129			gax.WithRetry(func() gax.Retryer {
130				return gax.OnCodes([]codes.Code{
131					codes.Unavailable,
132				}, gax.Backoff{
133					Initial:    100 * time.Millisecond,
134					Max:        30000 * time.Millisecond,
135					Multiplier: 1.30,
136				})
137			}),
138		},
139	}
140}
141
142// internalServiceMonitoringClient is an interface that defines the methods availaible from Cloud Monitoring API.
143type internalServiceMonitoringClient interface {
144	Close() error
145	setGoogleClientInfo(...string)
146	Connection() *grpc.ClientConn
147	CreateService(context.Context, *monitoringpb.CreateServiceRequest, ...gax.CallOption) (*monitoringpb.Service, error)
148	GetService(context.Context, *monitoringpb.GetServiceRequest, ...gax.CallOption) (*monitoringpb.Service, error)
149	ListServices(context.Context, *monitoringpb.ListServicesRequest, ...gax.CallOption) *ServiceIterator
150	UpdateService(context.Context, *monitoringpb.UpdateServiceRequest, ...gax.CallOption) (*monitoringpb.Service, error)
151	DeleteService(context.Context, *monitoringpb.DeleteServiceRequest, ...gax.CallOption) error
152	CreateServiceLevelObjective(context.Context, *monitoringpb.CreateServiceLevelObjectiveRequest, ...gax.CallOption) (*monitoringpb.ServiceLevelObjective, error)
153	GetServiceLevelObjective(context.Context, *monitoringpb.GetServiceLevelObjectiveRequest, ...gax.CallOption) (*monitoringpb.ServiceLevelObjective, error)
154	ListServiceLevelObjectives(context.Context, *monitoringpb.ListServiceLevelObjectivesRequest, ...gax.CallOption) *ServiceLevelObjectiveIterator
155	UpdateServiceLevelObjective(context.Context, *monitoringpb.UpdateServiceLevelObjectiveRequest, ...gax.CallOption) (*monitoringpb.ServiceLevelObjective, error)
156	DeleteServiceLevelObjective(context.Context, *monitoringpb.DeleteServiceLevelObjectiveRequest, ...gax.CallOption) error
157}
158
159// ServiceMonitoringClient is a client for interacting with Cloud Monitoring API.
160// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
161//
162// The Cloud Monitoring Service-Oriented Monitoring API has endpoints for
163// managing and querying aspects of a workspace’s services. These include the
164// Service's monitored resources, its Service-Level Objectives, and a taxonomy
165// of categorized Health Metrics.
166type ServiceMonitoringClient struct {
167	// The internal transport-dependent client.
168	internalClient internalServiceMonitoringClient
169
170	// The call options for this service.
171	CallOptions *ServiceMonitoringCallOptions
172}
173
174// Wrapper methods routed to the internal client.
175
176// Close closes the connection to the API service. The user should invoke this when
177// the client is no longer required.
178func (c *ServiceMonitoringClient) Close() error {
179	return c.internalClient.Close()
180}
181
182// setGoogleClientInfo sets the name and version of the application in
183// the `x-goog-api-client` header passed on each request. Intended for
184// use by Google-written clients.
185func (c *ServiceMonitoringClient) setGoogleClientInfo(keyval ...string) {
186	c.internalClient.setGoogleClientInfo(keyval...)
187}
188
189// Connection returns a connection to the API service.
190//
191// Deprecated.
192func (c *ServiceMonitoringClient) Connection() *grpc.ClientConn {
193	return c.internalClient.Connection()
194}
195
196// CreateService create a Service.
197func (c *ServiceMonitoringClient) CreateService(ctx context.Context, req *monitoringpb.CreateServiceRequest, opts ...gax.CallOption) (*monitoringpb.Service, error) {
198	return c.internalClient.CreateService(ctx, req, opts...)
199}
200
201// GetService get the named Service.
202func (c *ServiceMonitoringClient) GetService(ctx context.Context, req *monitoringpb.GetServiceRequest, opts ...gax.CallOption) (*monitoringpb.Service, error) {
203	return c.internalClient.GetService(ctx, req, opts...)
204}
205
206// ListServices list Services for this workspace.
207func (c *ServiceMonitoringClient) ListServices(ctx context.Context, req *monitoringpb.ListServicesRequest, opts ...gax.CallOption) *ServiceIterator {
208	return c.internalClient.ListServices(ctx, req, opts...)
209}
210
211// UpdateService update this Service.
212func (c *ServiceMonitoringClient) UpdateService(ctx context.Context, req *monitoringpb.UpdateServiceRequest, opts ...gax.CallOption) (*monitoringpb.Service, error) {
213	return c.internalClient.UpdateService(ctx, req, opts...)
214}
215
216// DeleteService soft delete this Service.
217func (c *ServiceMonitoringClient) DeleteService(ctx context.Context, req *monitoringpb.DeleteServiceRequest, opts ...gax.CallOption) error {
218	return c.internalClient.DeleteService(ctx, req, opts...)
219}
220
221// CreateServiceLevelObjective create a ServiceLevelObjective for the given Service.
222func (c *ServiceMonitoringClient) CreateServiceLevelObjective(ctx context.Context, req *monitoringpb.CreateServiceLevelObjectiveRequest, opts ...gax.CallOption) (*monitoringpb.ServiceLevelObjective, error) {
223	return c.internalClient.CreateServiceLevelObjective(ctx, req, opts...)
224}
225
226// GetServiceLevelObjective get a ServiceLevelObjective by name.
227func (c *ServiceMonitoringClient) GetServiceLevelObjective(ctx context.Context, req *monitoringpb.GetServiceLevelObjectiveRequest, opts ...gax.CallOption) (*monitoringpb.ServiceLevelObjective, error) {
228	return c.internalClient.GetServiceLevelObjective(ctx, req, opts...)
229}
230
231// ListServiceLevelObjectives list the ServiceLevelObjectives for the given Service.
232func (c *ServiceMonitoringClient) ListServiceLevelObjectives(ctx context.Context, req *monitoringpb.ListServiceLevelObjectivesRequest, opts ...gax.CallOption) *ServiceLevelObjectiveIterator {
233	return c.internalClient.ListServiceLevelObjectives(ctx, req, opts...)
234}
235
236// UpdateServiceLevelObjective update the given ServiceLevelObjective.
237func (c *ServiceMonitoringClient) UpdateServiceLevelObjective(ctx context.Context, req *monitoringpb.UpdateServiceLevelObjectiveRequest, opts ...gax.CallOption) (*monitoringpb.ServiceLevelObjective, error) {
238	return c.internalClient.UpdateServiceLevelObjective(ctx, req, opts...)
239}
240
241// DeleteServiceLevelObjective delete the given ServiceLevelObjective.
242func (c *ServiceMonitoringClient) DeleteServiceLevelObjective(ctx context.Context, req *monitoringpb.DeleteServiceLevelObjectiveRequest, opts ...gax.CallOption) error {
243	return c.internalClient.DeleteServiceLevelObjective(ctx, req, opts...)
244}
245
246// serviceMonitoringGRPCClient is a client for interacting with Cloud Monitoring API over gRPC transport.
247//
248// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
249type serviceMonitoringGRPCClient struct {
250	// Connection pool of gRPC connections to the service.
251	connPool gtransport.ConnPool
252
253	// flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE
254	disableDeadlines bool
255
256	// Points back to the CallOptions field of the containing ServiceMonitoringClient
257	CallOptions **ServiceMonitoringCallOptions
258
259	// The gRPC API client.
260	serviceMonitoringClient monitoringpb.ServiceMonitoringServiceClient
261
262	// The x-goog-* metadata to be sent with each request.
263	xGoogMetadata metadata.MD
264}
265
266// NewServiceMonitoringClient creates a new service monitoring service client based on gRPC.
267// The returned client must be Closed when it is done being used to clean up its underlying connections.
268//
269// The Cloud Monitoring Service-Oriented Monitoring API has endpoints for
270// managing and querying aspects of a workspace’s services. These include the
271// Service's monitored resources, its Service-Level Objectives, and a taxonomy
272// of categorized Health Metrics.
273func NewServiceMonitoringClient(ctx context.Context, opts ...option.ClientOption) (*ServiceMonitoringClient, error) {
274	clientOpts := defaultServiceMonitoringGRPCClientOptions()
275	if newServiceMonitoringClientHook != nil {
276		hookOpts, err := newServiceMonitoringClientHook(ctx, clientHookParams{})
277		if err != nil {
278			return nil, err
279		}
280		clientOpts = append(clientOpts, hookOpts...)
281	}
282
283	disableDeadlines, err := checkDisableDeadlines()
284	if err != nil {
285		return nil, err
286	}
287
288	connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
289	if err != nil {
290		return nil, err
291	}
292	client := ServiceMonitoringClient{CallOptions: defaultServiceMonitoringCallOptions()}
293
294	c := &serviceMonitoringGRPCClient{
295		connPool:                connPool,
296		disableDeadlines:        disableDeadlines,
297		serviceMonitoringClient: monitoringpb.NewServiceMonitoringServiceClient(connPool),
298		CallOptions:             &client.CallOptions,
299	}
300	c.setGoogleClientInfo()
301
302	client.internalClient = c
303
304	return &client, nil
305}
306
307// Connection returns a connection to the API service.
308//
309// Deprecated.
310func (c *serviceMonitoringGRPCClient) Connection() *grpc.ClientConn {
311	return c.connPool.Conn()
312}
313
314// setGoogleClientInfo sets the name and version of the application in
315// the `x-goog-api-client` header passed on each request. Intended for
316// use by Google-written clients.
317func (c *serviceMonitoringGRPCClient) setGoogleClientInfo(keyval ...string) {
318	kv := append([]string{"gl-go", versionGo()}, keyval...)
319	kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version)
320	c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
321}
322
323// Close closes the connection to the API service. The user should invoke this when
324// the client is no longer required.
325func (c *serviceMonitoringGRPCClient) Close() error {
326	return c.connPool.Close()
327}
328
329func (c *serviceMonitoringGRPCClient) CreateService(ctx context.Context, req *monitoringpb.CreateServiceRequest, opts ...gax.CallOption) (*monitoringpb.Service, error) {
330	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
331		cctx, cancel := context.WithTimeout(ctx, 30000*time.Millisecond)
332		defer cancel()
333		ctx = cctx
334	}
335	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent())))
336	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
337	opts = append((*c.CallOptions).CreateService[0:len((*c.CallOptions).CreateService):len((*c.CallOptions).CreateService)], opts...)
338	var resp *monitoringpb.Service
339	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
340		var err error
341		resp, err = c.serviceMonitoringClient.CreateService(ctx, req, settings.GRPC...)
342		return err
343	}, opts...)
344	if err != nil {
345		return nil, err
346	}
347	return resp, nil
348}
349
350func (c *serviceMonitoringGRPCClient) GetService(ctx context.Context, req *monitoringpb.GetServiceRequest, opts ...gax.CallOption) (*monitoringpb.Service, error) {
351	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
352		cctx, cancel := context.WithTimeout(ctx, 30000*time.Millisecond)
353		defer cancel()
354		ctx = cctx
355	}
356	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
357	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
358	opts = append((*c.CallOptions).GetService[0:len((*c.CallOptions).GetService):len((*c.CallOptions).GetService)], opts...)
359	var resp *monitoringpb.Service
360	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
361		var err error
362		resp, err = c.serviceMonitoringClient.GetService(ctx, req, settings.GRPC...)
363		return err
364	}, opts...)
365	if err != nil {
366		return nil, err
367	}
368	return resp, nil
369}
370
371func (c *serviceMonitoringGRPCClient) ListServices(ctx context.Context, req *monitoringpb.ListServicesRequest, opts ...gax.CallOption) *ServiceIterator {
372	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent())))
373	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
374	opts = append((*c.CallOptions).ListServices[0:len((*c.CallOptions).ListServices):len((*c.CallOptions).ListServices)], opts...)
375	it := &ServiceIterator{}
376	req = proto.Clone(req).(*monitoringpb.ListServicesRequest)
377	it.InternalFetch = func(pageSize int, pageToken string) ([]*monitoringpb.Service, string, error) {
378		resp := &monitoringpb.ListServicesResponse{}
379		if pageToken != "" {
380			req.PageToken = pageToken
381		}
382		if pageSize > math.MaxInt32 {
383			req.PageSize = math.MaxInt32
384		} else if pageSize != 0 {
385			req.PageSize = int32(pageSize)
386		}
387		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
388			var err error
389			resp, err = c.serviceMonitoringClient.ListServices(ctx, req, settings.GRPC...)
390			return err
391		}, opts...)
392		if err != nil {
393			return nil, "", err
394		}
395
396		it.Response = resp
397		return resp.GetServices(), resp.GetNextPageToken(), nil
398	}
399	fetch := func(pageSize int, pageToken string) (string, error) {
400		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
401		if err != nil {
402			return "", err
403		}
404		it.items = append(it.items, items...)
405		return nextPageToken, nil
406	}
407
408	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
409	it.pageInfo.MaxSize = int(req.GetPageSize())
410	it.pageInfo.Token = req.GetPageToken()
411
412	return it
413}
414
415func (c *serviceMonitoringGRPCClient) UpdateService(ctx context.Context, req *monitoringpb.UpdateServiceRequest, opts ...gax.CallOption) (*monitoringpb.Service, error) {
416	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
417		cctx, cancel := context.WithTimeout(ctx, 30000*time.Millisecond)
418		defer cancel()
419		ctx = cctx
420	}
421	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "service.name", url.QueryEscape(req.GetService().GetName())))
422	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
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
436func (c *serviceMonitoringGRPCClient) DeleteService(ctx context.Context, req *monitoringpb.DeleteServiceRequest, opts ...gax.CallOption) error {
437	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
438		cctx, cancel := context.WithTimeout(ctx, 30000*time.Millisecond)
439		defer cancel()
440		ctx = cctx
441	}
442	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
443	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
444	opts = append((*c.CallOptions).DeleteService[0:len((*c.CallOptions).DeleteService):len((*c.CallOptions).DeleteService)], opts...)
445	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
446		var err error
447		_, err = c.serviceMonitoringClient.DeleteService(ctx, req, settings.GRPC...)
448		return err
449	}, opts...)
450	return err
451}
452
453func (c *serviceMonitoringGRPCClient) CreateServiceLevelObjective(ctx context.Context, req *monitoringpb.CreateServiceLevelObjectiveRequest, opts ...gax.CallOption) (*monitoringpb.ServiceLevelObjective, error) {
454	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
455		cctx, cancel := context.WithTimeout(ctx, 30000*time.Millisecond)
456		defer cancel()
457		ctx = cctx
458	}
459	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent())))
460	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
461	opts = append((*c.CallOptions).CreateServiceLevelObjective[0:len((*c.CallOptions).CreateServiceLevelObjective):len((*c.CallOptions).CreateServiceLevelObjective)], opts...)
462	var resp *monitoringpb.ServiceLevelObjective
463	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
464		var err error
465		resp, err = c.serviceMonitoringClient.CreateServiceLevelObjective(ctx, req, settings.GRPC...)
466		return err
467	}, opts...)
468	if err != nil {
469		return nil, err
470	}
471	return resp, nil
472}
473
474func (c *serviceMonitoringGRPCClient) GetServiceLevelObjective(ctx context.Context, req *monitoringpb.GetServiceLevelObjectiveRequest, opts ...gax.CallOption) (*monitoringpb.ServiceLevelObjective, error) {
475	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
476		cctx, cancel := context.WithTimeout(ctx, 30000*time.Millisecond)
477		defer cancel()
478		ctx = cctx
479	}
480	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
481	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
482	opts = append((*c.CallOptions).GetServiceLevelObjective[0:len((*c.CallOptions).GetServiceLevelObjective):len((*c.CallOptions).GetServiceLevelObjective)], opts...)
483	var resp *monitoringpb.ServiceLevelObjective
484	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
485		var err error
486		resp, err = c.serviceMonitoringClient.GetServiceLevelObjective(ctx, req, settings.GRPC...)
487		return err
488	}, opts...)
489	if err != nil {
490		return nil, err
491	}
492	return resp, nil
493}
494
495func (c *serviceMonitoringGRPCClient) ListServiceLevelObjectives(ctx context.Context, req *monitoringpb.ListServiceLevelObjectivesRequest, opts ...gax.CallOption) *ServiceLevelObjectiveIterator {
496	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent())))
497	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
498	opts = append((*c.CallOptions).ListServiceLevelObjectives[0:len((*c.CallOptions).ListServiceLevelObjectives):len((*c.CallOptions).ListServiceLevelObjectives)], opts...)
499	it := &ServiceLevelObjectiveIterator{}
500	req = proto.Clone(req).(*monitoringpb.ListServiceLevelObjectivesRequest)
501	it.InternalFetch = func(pageSize int, pageToken string) ([]*monitoringpb.ServiceLevelObjective, string, error) {
502		resp := &monitoringpb.ListServiceLevelObjectivesResponse{}
503		if pageToken != "" {
504			req.PageToken = pageToken
505		}
506		if pageSize > math.MaxInt32 {
507			req.PageSize = math.MaxInt32
508		} else if pageSize != 0 {
509			req.PageSize = int32(pageSize)
510		}
511		err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
512			var err error
513			resp, err = c.serviceMonitoringClient.ListServiceLevelObjectives(ctx, req, settings.GRPC...)
514			return err
515		}, opts...)
516		if err != nil {
517			return nil, "", err
518		}
519
520		it.Response = resp
521		return resp.GetServiceLevelObjectives(), resp.GetNextPageToken(), nil
522	}
523	fetch := func(pageSize int, pageToken string) (string, error) {
524		items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
525		if err != nil {
526			return "", err
527		}
528		it.items = append(it.items, items...)
529		return nextPageToken, nil
530	}
531
532	it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
533	it.pageInfo.MaxSize = int(req.GetPageSize())
534	it.pageInfo.Token = req.GetPageToken()
535
536	return it
537}
538
539func (c *serviceMonitoringGRPCClient) UpdateServiceLevelObjective(ctx context.Context, req *monitoringpb.UpdateServiceLevelObjectiveRequest, opts ...gax.CallOption) (*monitoringpb.ServiceLevelObjective, error) {
540	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
541		cctx, cancel := context.WithTimeout(ctx, 30000*time.Millisecond)
542		defer cancel()
543		ctx = cctx
544	}
545	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "service_level_objective.name", url.QueryEscape(req.GetServiceLevelObjective().GetName())))
546	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
547	opts = append((*c.CallOptions).UpdateServiceLevelObjective[0:len((*c.CallOptions).UpdateServiceLevelObjective):len((*c.CallOptions).UpdateServiceLevelObjective)], opts...)
548	var resp *monitoringpb.ServiceLevelObjective
549	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
550		var err error
551		resp, err = c.serviceMonitoringClient.UpdateServiceLevelObjective(ctx, req, settings.GRPC...)
552		return err
553	}, opts...)
554	if err != nil {
555		return nil, err
556	}
557	return resp, nil
558}
559
560func (c *serviceMonitoringGRPCClient) DeleteServiceLevelObjective(ctx context.Context, req *monitoringpb.DeleteServiceLevelObjectiveRequest, opts ...gax.CallOption) error {
561	if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines {
562		cctx, cancel := context.WithTimeout(ctx, 30000*time.Millisecond)
563		defer cancel()
564		ctx = cctx
565	}
566	md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
567	ctx = insertMetadata(ctx, c.xGoogMetadata, md)
568	opts = append((*c.CallOptions).DeleteServiceLevelObjective[0:len((*c.CallOptions).DeleteServiceLevelObjective):len((*c.CallOptions).DeleteServiceLevelObjective)], opts...)
569	err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
570		var err error
571		_, err = c.serviceMonitoringClient.DeleteServiceLevelObjective(ctx, req, settings.GRPC...)
572		return err
573	}, opts...)
574	return err
575}
576
577// ServiceIterator manages a stream of *monitoringpb.Service.
578type ServiceIterator struct {
579	items    []*monitoringpb.Service
580	pageInfo *iterator.PageInfo
581	nextFunc func() error
582
583	// Response is the raw response for the current page.
584	// It must be cast to the RPC response type.
585	// Calling Next() or InternalFetch() updates this value.
586	Response interface{}
587
588	// InternalFetch is for use by the Google Cloud Libraries only.
589	// It is not part of the stable interface of this package.
590	//
591	// InternalFetch returns results from a single call to the underlying RPC.
592	// The number of results is no greater than pageSize.
593	// If there are no more results, nextPageToken is empty and err is nil.
594	InternalFetch func(pageSize int, pageToken string) (results []*monitoringpb.Service, nextPageToken string, err error)
595}
596
597// PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
598func (it *ServiceIterator) PageInfo() *iterator.PageInfo {
599	return it.pageInfo
600}
601
602// Next returns the next result. Its second return value is iterator.Done if there are no more
603// results. Once Next returns Done, all subsequent calls will return Done.
604func (it *ServiceIterator) Next() (*monitoringpb.Service, error) {
605	var item *monitoringpb.Service
606	if err := it.nextFunc(); err != nil {
607		return item, err
608	}
609	item = it.items[0]
610	it.items = it.items[1:]
611	return item, nil
612}
613
614func (it *ServiceIterator) bufLen() int {
615	return len(it.items)
616}
617
618func (it *ServiceIterator) takeBuf() interface{} {
619	b := it.items
620	it.items = nil
621	return b
622}
623
624// ServiceLevelObjectiveIterator manages a stream of *monitoringpb.ServiceLevelObjective.
625type ServiceLevelObjectiveIterator struct {
626	items    []*monitoringpb.ServiceLevelObjective
627	pageInfo *iterator.PageInfo
628	nextFunc func() error
629
630	// Response is the raw response for the current page.
631	// It must be cast to the RPC response type.
632	// Calling Next() or InternalFetch() updates this value.
633	Response interface{}
634
635	// InternalFetch is for use by the Google Cloud Libraries only.
636	// It is not part of the stable interface of this package.
637	//
638	// InternalFetch returns results from a single call to the underlying RPC.
639	// The number of results is no greater than pageSize.
640	// If there are no more results, nextPageToken is empty and err is nil.
641	InternalFetch func(pageSize int, pageToken string) (results []*monitoringpb.ServiceLevelObjective, nextPageToken string, err error)
642}
643
644// PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
645func (it *ServiceLevelObjectiveIterator) PageInfo() *iterator.PageInfo {
646	return it.pageInfo
647}
648
649// Next returns the next result. Its second return value is iterator.Done if there are no more
650// results. Once Next returns Done, all subsequent calls will return Done.
651func (it *ServiceLevelObjectiveIterator) Next() (*monitoringpb.ServiceLevelObjective, error) {
652	var item *monitoringpb.ServiceLevelObjective
653	if err := it.nextFunc(); err != nil {
654		return item, err
655	}
656	item = it.items[0]
657	it.items = it.items[1:]
658	return item, nil
659}
660
661func (it *ServiceLevelObjectiveIterator) bufLen() int {
662	return len(it.items)
663}
664
665func (it *ServiceLevelObjectiveIterator) takeBuf() interface{} {
666	b := it.items
667	it.items = nil
668	return b
669}
670