1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package monitoring
18
19 import (
20 "context"
21 "fmt"
22 "math"
23 "net/url"
24 "time"
25
26 "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 gtransport "google.golang.org/api/transport/grpc"
31 "google.golang.org/grpc"
32 "google.golang.org/grpc/codes"
33 "google.golang.org/grpc/metadata"
34 "google.golang.org/protobuf/proto"
35 )
36
37 var newNotificationChannelClientHook clientHook
38
39
40 type NotificationChannelCallOptions struct {
41 ListNotificationChannelDescriptors []gax.CallOption
42 GetNotificationChannelDescriptor []gax.CallOption
43 ListNotificationChannels []gax.CallOption
44 GetNotificationChannel []gax.CallOption
45 CreateNotificationChannel []gax.CallOption
46 UpdateNotificationChannel []gax.CallOption
47 DeleteNotificationChannel []gax.CallOption
48 SendNotificationChannelVerificationCode []gax.CallOption
49 GetNotificationChannelVerificationCode []gax.CallOption
50 VerifyNotificationChannel []gax.CallOption
51 }
52
53 func defaultNotificationChannelClientOptions() []option.ClientOption {
54 return []option.ClientOption{
55 option.WithEndpoint("monitoring.googleapis.com:443"),
56 option.WithGRPCDialOption(grpc.WithDisableServiceConfig()),
57 option.WithScopes(DefaultAuthScopes()...),
58 option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
59 grpc.MaxCallRecvMsgSize(math.MaxInt32))),
60 }
61 }
62
63 func defaultNotificationChannelCallOptions() *NotificationChannelCallOptions {
64 return &NotificationChannelCallOptions{
65 ListNotificationChannelDescriptors: []gax.CallOption{
66 gax.WithRetry(func() gax.Retryer {
67 return gax.OnCodes([]codes.Code{
68 codes.DeadlineExceeded,
69 codes.Unavailable,
70 }, gax.Backoff{
71 Initial: 100 * time.Millisecond,
72 Max: 30000 * time.Millisecond,
73 Multiplier: 1.30,
74 })
75 }),
76 },
77 GetNotificationChannelDescriptor: []gax.CallOption{
78 gax.WithRetry(func() gax.Retryer {
79 return gax.OnCodes([]codes.Code{
80 codes.DeadlineExceeded,
81 codes.Unavailable,
82 }, gax.Backoff{
83 Initial: 100 * time.Millisecond,
84 Max: 30000 * time.Millisecond,
85 Multiplier: 1.30,
86 })
87 }),
88 },
89 ListNotificationChannels: []gax.CallOption{
90 gax.WithRetry(func() gax.Retryer {
91 return gax.OnCodes([]codes.Code{
92 codes.DeadlineExceeded,
93 codes.Unavailable,
94 }, gax.Backoff{
95 Initial: 100 * time.Millisecond,
96 Max: 30000 * time.Millisecond,
97 Multiplier: 1.30,
98 })
99 }),
100 },
101 GetNotificationChannel: []gax.CallOption{
102 gax.WithRetry(func() gax.Retryer {
103 return gax.OnCodes([]codes.Code{
104 codes.DeadlineExceeded,
105 codes.Unavailable,
106 }, gax.Backoff{
107 Initial: 100 * time.Millisecond,
108 Max: 30000 * time.Millisecond,
109 Multiplier: 1.30,
110 })
111 }),
112 },
113 CreateNotificationChannel: []gax.CallOption{},
114 UpdateNotificationChannel: []gax.CallOption{},
115 DeleteNotificationChannel: []gax.CallOption{
116 gax.WithRetry(func() gax.Retryer {
117 return gax.OnCodes([]codes.Code{
118 codes.DeadlineExceeded,
119 codes.Unavailable,
120 }, gax.Backoff{
121 Initial: 100 * time.Millisecond,
122 Max: 30000 * time.Millisecond,
123 Multiplier: 1.30,
124 })
125 }),
126 },
127 SendNotificationChannelVerificationCode: []gax.CallOption{},
128 GetNotificationChannelVerificationCode: []gax.CallOption{
129 gax.WithRetry(func() gax.Retryer {
130 return gax.OnCodes([]codes.Code{
131 codes.DeadlineExceeded,
132 codes.Unavailable,
133 }, gax.Backoff{
134 Initial: 100 * time.Millisecond,
135 Max: 30000 * time.Millisecond,
136 Multiplier: 1.30,
137 })
138 }),
139 },
140 VerifyNotificationChannel: []gax.CallOption{
141 gax.WithRetry(func() gax.Retryer {
142 return gax.OnCodes([]codes.Code{
143 codes.DeadlineExceeded,
144 codes.Unavailable,
145 }, gax.Backoff{
146 Initial: 100 * time.Millisecond,
147 Max: 30000 * time.Millisecond,
148 Multiplier: 1.30,
149 })
150 }),
151 },
152 }
153 }
154
155
156
157
158 type NotificationChannelClient struct {
159
160 connPool gtransport.ConnPool
161
162
163 notificationChannelClient monitoringpb.NotificationChannelServiceClient
164
165
166 CallOptions *NotificationChannelCallOptions
167
168
169 xGoogMetadata metadata.MD
170 }
171
172
173
174
175
176 func NewNotificationChannelClient(ctx context.Context, opts ...option.ClientOption) (*NotificationChannelClient, error) {
177 clientOpts := defaultNotificationChannelClientOptions()
178
179 if newNotificationChannelClientHook != nil {
180 hookOpts, err := newNotificationChannelClientHook(ctx, clientHookParams{})
181 if err != nil {
182 return nil, err
183 }
184 clientOpts = append(clientOpts, hookOpts...)
185 }
186
187 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
188 if err != nil {
189 return nil, err
190 }
191 c := &NotificationChannelClient{
192 connPool: connPool,
193 CallOptions: defaultNotificationChannelCallOptions(),
194
195 notificationChannelClient: monitoringpb.NewNotificationChannelServiceClient(connPool),
196 }
197 c.setGoogleClientInfo()
198
199 return c, nil
200 }
201
202
203
204
205 func (c *NotificationChannelClient) Connection() *grpc.ClientConn {
206 return c.connPool.Conn()
207 }
208
209
210
211 func (c *NotificationChannelClient) Close() error {
212 return c.connPool.Close()
213 }
214
215
216
217
218 func (c *NotificationChannelClient) setGoogleClientInfo(keyval ...string) {
219 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
220 kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version)
221 c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
222 }
223
224
225
226 func (c *NotificationChannelClient) ListNotificationChannelDescriptors(ctx context.Context, req *monitoringpb.ListNotificationChannelDescriptorsRequest, opts ...gax.CallOption) *NotificationChannelDescriptorIterator {
227 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
228 ctx = insertMetadata(ctx, c.xGoogMetadata, md)
229 opts = append(c.CallOptions.ListNotificationChannelDescriptors[0:len(c.CallOptions.ListNotificationChannelDescriptors):len(c.CallOptions.ListNotificationChannelDescriptors)], opts...)
230 it := &NotificationChannelDescriptorIterator{}
231 req = proto.Clone(req).(*monitoringpb.ListNotificationChannelDescriptorsRequest)
232 it.InternalFetch = func(pageSize int, pageToken string) ([]*monitoringpb.NotificationChannelDescriptor, string, error) {
233 var resp *monitoringpb.ListNotificationChannelDescriptorsResponse
234 req.PageToken = pageToken
235 if pageSize > math.MaxInt32 {
236 req.PageSize = math.MaxInt32
237 } else {
238 req.PageSize = int32(pageSize)
239 }
240 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
241 var err error
242 resp, err = c.notificationChannelClient.ListNotificationChannelDescriptors(ctx, req, settings.GRPC...)
243 return err
244 }, opts...)
245 if err != nil {
246 return nil, "", err
247 }
248
249 it.Response = resp
250 return resp.ChannelDescriptors, resp.NextPageToken, nil
251 }
252 fetch := func(pageSize int, pageToken string) (string, error) {
253 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
254 if err != nil {
255 return "", err
256 }
257 it.items = append(it.items, items...)
258 return nextPageToken, nil
259 }
260 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
261 it.pageInfo.MaxSize = int(req.PageSize)
262 it.pageInfo.Token = req.PageToken
263 return it
264 }
265
266
267
268 func (c *NotificationChannelClient) GetNotificationChannelDescriptor(ctx context.Context, req *monitoringpb.GetNotificationChannelDescriptorRequest, opts ...gax.CallOption) (*monitoringpb.NotificationChannelDescriptor, error) {
269 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
270 ctx = insertMetadata(ctx, c.xGoogMetadata, md)
271 opts = append(c.CallOptions.GetNotificationChannelDescriptor[0:len(c.CallOptions.GetNotificationChannelDescriptor):len(c.CallOptions.GetNotificationChannelDescriptor)], opts...)
272 var resp *monitoringpb.NotificationChannelDescriptor
273 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
274 var err error
275 resp, err = c.notificationChannelClient.GetNotificationChannelDescriptor(ctx, req, settings.GRPC...)
276 return err
277 }, opts...)
278 if err != nil {
279 return nil, err
280 }
281 return resp, nil
282 }
283
284
285 func (c *NotificationChannelClient) ListNotificationChannels(ctx context.Context, req *monitoringpb.ListNotificationChannelsRequest, opts ...gax.CallOption) *NotificationChannelIterator {
286 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
287 ctx = insertMetadata(ctx, c.xGoogMetadata, md)
288 opts = append(c.CallOptions.ListNotificationChannels[0:len(c.CallOptions.ListNotificationChannels):len(c.CallOptions.ListNotificationChannels)], opts...)
289 it := &NotificationChannelIterator{}
290 req = proto.Clone(req).(*monitoringpb.ListNotificationChannelsRequest)
291 it.InternalFetch = func(pageSize int, pageToken string) ([]*monitoringpb.NotificationChannel, string, error) {
292 var resp *monitoringpb.ListNotificationChannelsResponse
293 req.PageToken = pageToken
294 if pageSize > math.MaxInt32 {
295 req.PageSize = math.MaxInt32
296 } else {
297 req.PageSize = int32(pageSize)
298 }
299 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
300 var err error
301 resp, err = c.notificationChannelClient.ListNotificationChannels(ctx, req, settings.GRPC...)
302 return err
303 }, opts...)
304 if err != nil {
305 return nil, "", err
306 }
307
308 it.Response = resp
309 return resp.NotificationChannels, resp.NextPageToken, nil
310 }
311 fetch := func(pageSize int, pageToken string) (string, error) {
312 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
313 if err != nil {
314 return "", err
315 }
316 it.items = append(it.items, items...)
317 return nextPageToken, nil
318 }
319 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
320 it.pageInfo.MaxSize = int(req.PageSize)
321 it.pageInfo.Token = req.PageToken
322 return it
323 }
324
325
326
327
328
329
330 func (c *NotificationChannelClient) GetNotificationChannel(ctx context.Context, req *monitoringpb.GetNotificationChannelRequest, opts ...gax.CallOption) (*monitoringpb.NotificationChannel, error) {
331 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
332 ctx = insertMetadata(ctx, c.xGoogMetadata, md)
333 opts = append(c.CallOptions.GetNotificationChannel[0:len(c.CallOptions.GetNotificationChannel):len(c.CallOptions.GetNotificationChannel)], opts...)
334 var resp *monitoringpb.NotificationChannel
335 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
336 var err error
337 resp, err = c.notificationChannelClient.GetNotificationChannel(ctx, req, settings.GRPC...)
338 return err
339 }, opts...)
340 if err != nil {
341 return nil, err
342 }
343 return resp, nil
344 }
345
346
347
348 func (c *NotificationChannelClient) CreateNotificationChannel(ctx context.Context, req *monitoringpb.CreateNotificationChannelRequest, opts ...gax.CallOption) (*monitoringpb.NotificationChannel, error) {
349 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
350 ctx = insertMetadata(ctx, c.xGoogMetadata, md)
351 opts = append(c.CallOptions.CreateNotificationChannel[0:len(c.CallOptions.CreateNotificationChannel):len(c.CallOptions.CreateNotificationChannel)], opts...)
352 var resp *monitoringpb.NotificationChannel
353 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
354 var err error
355 resp, err = c.notificationChannelClient.CreateNotificationChannel(ctx, req, settings.GRPC...)
356 return err
357 }, opts...)
358 if err != nil {
359 return nil, err
360 }
361 return resp, nil
362 }
363
364
365
366 func (c *NotificationChannelClient) UpdateNotificationChannel(ctx context.Context, req *monitoringpb.UpdateNotificationChannelRequest, opts ...gax.CallOption) (*monitoringpb.NotificationChannel, error) {
367 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "notification_channel.name", url.QueryEscape(req.GetNotificationChannel().GetName())))
368 ctx = insertMetadata(ctx, c.xGoogMetadata, md)
369 opts = append(c.CallOptions.UpdateNotificationChannel[0:len(c.CallOptions.UpdateNotificationChannel):len(c.CallOptions.UpdateNotificationChannel)], opts...)
370 var resp *monitoringpb.NotificationChannel
371 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
372 var err error
373 resp, err = c.notificationChannelClient.UpdateNotificationChannel(ctx, req, settings.GRPC...)
374 return err
375 }, opts...)
376 if err != nil {
377 return nil, err
378 }
379 return resp, nil
380 }
381
382
383 func (c *NotificationChannelClient) DeleteNotificationChannel(ctx context.Context, req *monitoringpb.DeleteNotificationChannelRequest, opts ...gax.CallOption) error {
384 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
385 ctx = insertMetadata(ctx, c.xGoogMetadata, md)
386 opts = append(c.CallOptions.DeleteNotificationChannel[0:len(c.CallOptions.DeleteNotificationChannel):len(c.CallOptions.DeleteNotificationChannel)], opts...)
387 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
388 var err error
389 _, err = c.notificationChannelClient.DeleteNotificationChannel(ctx, req, settings.GRPC...)
390 return err
391 }, opts...)
392 return err
393 }
394
395
396
397 func (c *NotificationChannelClient) SendNotificationChannelVerificationCode(ctx context.Context, req *monitoringpb.SendNotificationChannelVerificationCodeRequest, opts ...gax.CallOption) error {
398 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
399 ctx = insertMetadata(ctx, c.xGoogMetadata, md)
400 opts = append(c.CallOptions.SendNotificationChannelVerificationCode[0:len(c.CallOptions.SendNotificationChannelVerificationCode):len(c.CallOptions.SendNotificationChannelVerificationCode)], opts...)
401 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
402 var err error
403 _, err = c.notificationChannelClient.SendNotificationChannelVerificationCode(ctx, req, settings.GRPC...)
404 return err
405 }, opts...)
406 return err
407 }
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430 func (c *NotificationChannelClient) GetNotificationChannelVerificationCode(ctx context.Context, req *monitoringpb.GetNotificationChannelVerificationCodeRequest, opts ...gax.CallOption) (*monitoringpb.GetNotificationChannelVerificationCodeResponse, error) {
431 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
432 ctx = insertMetadata(ctx, c.xGoogMetadata, md)
433 opts = append(c.CallOptions.GetNotificationChannelVerificationCode[0:len(c.CallOptions.GetNotificationChannelVerificationCode):len(c.CallOptions.GetNotificationChannelVerificationCode)], opts...)
434 var resp *monitoringpb.GetNotificationChannelVerificationCodeResponse
435 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
436 var err error
437 resp, err = c.notificationChannelClient.GetNotificationChannelVerificationCode(ctx, req, settings.GRPC...)
438 return err
439 }, opts...)
440 if err != nil {
441 return nil, err
442 }
443 return resp, nil
444 }
445
446
447
448
449 func (c *NotificationChannelClient) VerifyNotificationChannel(ctx context.Context, req *monitoringpb.VerifyNotificationChannelRequest, opts ...gax.CallOption) (*monitoringpb.NotificationChannel, error) {
450 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName())))
451 ctx = insertMetadata(ctx, c.xGoogMetadata, md)
452 opts = append(c.CallOptions.VerifyNotificationChannel[0:len(c.CallOptions.VerifyNotificationChannel):len(c.CallOptions.VerifyNotificationChannel)], opts...)
453 var resp *monitoringpb.NotificationChannel
454 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
455 var err error
456 resp, err = c.notificationChannelClient.VerifyNotificationChannel(ctx, req, settings.GRPC...)
457 return err
458 }, opts...)
459 if err != nil {
460 return nil, err
461 }
462 return resp, nil
463 }
464
465
466 type NotificationChannelDescriptorIterator struct {
467 items []*monitoringpb.NotificationChannelDescriptor
468 pageInfo *iterator.PageInfo
469 nextFunc func() error
470
471
472
473
474 Response interface{}
475
476
477
478
479
480
481
482 InternalFetch func(pageSize int, pageToken string) (results []*monitoringpb.NotificationChannelDescriptor, nextPageToken string, err error)
483 }
484
485
486 func (it *NotificationChannelDescriptorIterator) PageInfo() *iterator.PageInfo {
487 return it.pageInfo
488 }
489
490
491
492 func (it *NotificationChannelDescriptorIterator) Next() (*monitoringpb.NotificationChannelDescriptor, error) {
493 var item *monitoringpb.NotificationChannelDescriptor
494 if err := it.nextFunc(); err != nil {
495 return item, err
496 }
497 item = it.items[0]
498 it.items = it.items[1:]
499 return item, nil
500 }
501
502 func (it *NotificationChannelDescriptorIterator) bufLen() int {
503 return len(it.items)
504 }
505
506 func (it *NotificationChannelDescriptorIterator) takeBuf() interface{} {
507 b := it.items
508 it.items = nil
509 return b
510 }
511
512
513 type NotificationChannelIterator struct {
514 items []*monitoringpb.NotificationChannel
515 pageInfo *iterator.PageInfo
516 nextFunc func() error
517
518
519
520
521 Response interface{}
522
523
524
525
526
527
528
529 InternalFetch func(pageSize int, pageToken string) (results []*monitoringpb.NotificationChannel, nextPageToken string, err error)
530 }
531
532
533 func (it *NotificationChannelIterator) PageInfo() *iterator.PageInfo {
534 return it.pageInfo
535 }
536
537
538
539 func (it *NotificationChannelIterator) Next() (*monitoringpb.NotificationChannel, error) {
540 var item *monitoringpb.NotificationChannel
541 if err := it.nextFunc(); err != nil {
542 return item, err
543 }
544 item = it.items[0]
545 it.items = it.items[1:]
546 return item, nil
547 }
548
549 func (it *NotificationChannelIterator) bufLen() int {
550 return len(it.items)
551 }
552
553 func (it *NotificationChannelIterator) takeBuf() interface{} {
554 b := it.items
555 it.items = nil
556 return b
557 }
558
View as plain text