You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

362 lines
14 KiB

  1. // Copyright 2019 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // https://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // Code generated by gapic-generator. DO NOT EDIT.
  15. package monitoring
  16. import (
  17. "context"
  18. "math"
  19. "time"
  20. "github.com/golang/protobuf/proto"
  21. gax "github.com/googleapis/gax-go/v2"
  22. "google.golang.org/api/iterator"
  23. "google.golang.org/api/option"
  24. "google.golang.org/api/transport"
  25. monitoringpb "google.golang.org/genproto/googleapis/monitoring/v3"
  26. "google.golang.org/grpc"
  27. "google.golang.org/grpc/codes"
  28. "google.golang.org/grpc/metadata"
  29. )
  30. // UptimeCheckCallOptions contains the retry settings for each method of UptimeCheckClient.
  31. type UptimeCheckCallOptions struct {
  32. ListUptimeCheckConfigs []gax.CallOption
  33. GetUptimeCheckConfig []gax.CallOption
  34. CreateUptimeCheckConfig []gax.CallOption
  35. UpdateUptimeCheckConfig []gax.CallOption
  36. DeleteUptimeCheckConfig []gax.CallOption
  37. ListUptimeCheckIps []gax.CallOption
  38. }
  39. func defaultUptimeCheckClientOptions() []option.ClientOption {
  40. return []option.ClientOption{
  41. option.WithEndpoint("monitoring.googleapis.com:443"),
  42. option.WithScopes(DefaultAuthScopes()...),
  43. }
  44. }
  45. func defaultUptimeCheckCallOptions() *UptimeCheckCallOptions {
  46. retry := map[[2]string][]gax.CallOption{
  47. {"default", "idempotent"}: {
  48. gax.WithRetry(func() gax.Retryer {
  49. return gax.OnCodes([]codes.Code{
  50. codes.DeadlineExceeded,
  51. codes.Unavailable,
  52. }, gax.Backoff{
  53. Initial: 100 * time.Millisecond,
  54. Max: 60000 * time.Millisecond,
  55. Multiplier: 1.3,
  56. })
  57. }),
  58. },
  59. }
  60. return &UptimeCheckCallOptions{
  61. ListUptimeCheckConfigs: retry[[2]string{"default", "idempotent"}],
  62. GetUptimeCheckConfig: retry[[2]string{"default", "idempotent"}],
  63. CreateUptimeCheckConfig: retry[[2]string{"default", "non_idempotent"}],
  64. UpdateUptimeCheckConfig: retry[[2]string{"default", "non_idempotent"}],
  65. DeleteUptimeCheckConfig: retry[[2]string{"default", "idempotent"}],
  66. ListUptimeCheckIps: retry[[2]string{"default", "idempotent"}],
  67. }
  68. }
  69. // UptimeCheckClient is a client for interacting with Stackdriver Monitoring API.
  70. //
  71. // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
  72. type UptimeCheckClient struct {
  73. // The connection to the service.
  74. conn *grpc.ClientConn
  75. // The gRPC API client.
  76. uptimeCheckClient monitoringpb.UptimeCheckServiceClient
  77. // The call options for this service.
  78. CallOptions *UptimeCheckCallOptions
  79. // The x-goog-* metadata to be sent with each request.
  80. xGoogMetadata metadata.MD
  81. }
  82. // NewUptimeCheckClient creates a new uptime check service client.
  83. //
  84. // The UptimeCheckService API is used to manage (list, create, delete, edit)
  85. // uptime check configurations in the Stackdriver Monitoring product. An uptime
  86. // check is a piece of configuration that determines which resources and
  87. // services to monitor for availability. These configurations can also be
  88. // configured interactively by navigating to the [Cloud Console]
  89. // (http://console.cloud.google.com), selecting the appropriate project,
  90. // clicking on "Monitoring" on the left-hand side to navigate to Stackdriver,
  91. // and then clicking on "Uptime".
  92. func NewUptimeCheckClient(ctx context.Context, opts ...option.ClientOption) (*UptimeCheckClient, error) {
  93. conn, err := transport.DialGRPC(ctx, append(defaultUptimeCheckClientOptions(), opts...)...)
  94. if err != nil {
  95. return nil, err
  96. }
  97. c := &UptimeCheckClient{
  98. conn: conn,
  99. CallOptions: defaultUptimeCheckCallOptions(),
  100. uptimeCheckClient: monitoringpb.NewUptimeCheckServiceClient(conn),
  101. }
  102. c.setGoogleClientInfo()
  103. return c, nil
  104. }
  105. // Connection returns the client's connection to the API service.
  106. func (c *UptimeCheckClient) Connection() *grpc.ClientConn {
  107. return c.conn
  108. }
  109. // Close closes the connection to the API service. The user should invoke this when
  110. // the client is no longer required.
  111. func (c *UptimeCheckClient) Close() error {
  112. return c.conn.Close()
  113. }
  114. // setGoogleClientInfo sets the name and version of the application in
  115. // the `x-goog-api-client` header passed on each request. Intended for
  116. // use by Google-written clients.
  117. func (c *UptimeCheckClient) setGoogleClientInfo(keyval ...string) {
  118. kv := append([]string{"gl-go", versionGo()}, keyval...)
  119. kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version)
  120. c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...))
  121. }
  122. // ListUptimeCheckConfigs lists the existing valid uptime check configurations for the project,
  123. // leaving out any invalid configurations.
  124. func (c *UptimeCheckClient) ListUptimeCheckConfigs(ctx context.Context, req *monitoringpb.ListUptimeCheckConfigsRequest, opts ...gax.CallOption) *UptimeCheckConfigIterator {
  125. ctx = insertMetadata(ctx, c.xGoogMetadata)
  126. opts = append(c.CallOptions.ListUptimeCheckConfigs[0:len(c.CallOptions.ListUptimeCheckConfigs):len(c.CallOptions.ListUptimeCheckConfigs)], opts...)
  127. it := &UptimeCheckConfigIterator{}
  128. req = proto.Clone(req).(*monitoringpb.ListUptimeCheckConfigsRequest)
  129. it.InternalFetch = func(pageSize int, pageToken string) ([]*monitoringpb.UptimeCheckConfig, string, error) {
  130. var resp *monitoringpb.ListUptimeCheckConfigsResponse
  131. req.PageToken = pageToken
  132. if pageSize > math.MaxInt32 {
  133. req.PageSize = math.MaxInt32
  134. } else {
  135. req.PageSize = int32(pageSize)
  136. }
  137. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  138. var err error
  139. resp, err = c.uptimeCheckClient.ListUptimeCheckConfigs(ctx, req, settings.GRPC...)
  140. return err
  141. }, opts...)
  142. if err != nil {
  143. return nil, "", err
  144. }
  145. return resp.UptimeCheckConfigs, resp.NextPageToken, nil
  146. }
  147. fetch := func(pageSize int, pageToken string) (string, error) {
  148. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  149. if err != nil {
  150. return "", err
  151. }
  152. it.items = append(it.items, items...)
  153. return nextPageToken, nil
  154. }
  155. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  156. it.pageInfo.MaxSize = int(req.PageSize)
  157. return it
  158. }
  159. // GetUptimeCheckConfig gets a single uptime check configuration.
  160. func (c *UptimeCheckClient) GetUptimeCheckConfig(ctx context.Context, req *monitoringpb.GetUptimeCheckConfigRequest, opts ...gax.CallOption) (*monitoringpb.UptimeCheckConfig, error) {
  161. ctx = insertMetadata(ctx, c.xGoogMetadata)
  162. opts = append(c.CallOptions.GetUptimeCheckConfig[0:len(c.CallOptions.GetUptimeCheckConfig):len(c.CallOptions.GetUptimeCheckConfig)], opts...)
  163. var resp *monitoringpb.UptimeCheckConfig
  164. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  165. var err error
  166. resp, err = c.uptimeCheckClient.GetUptimeCheckConfig(ctx, req, settings.GRPC...)
  167. return err
  168. }, opts...)
  169. if err != nil {
  170. return nil, err
  171. }
  172. return resp, nil
  173. }
  174. // CreateUptimeCheckConfig creates a new uptime check configuration.
  175. func (c *UptimeCheckClient) CreateUptimeCheckConfig(ctx context.Context, req *monitoringpb.CreateUptimeCheckConfigRequest, opts ...gax.CallOption) (*monitoringpb.UptimeCheckConfig, error) {
  176. ctx = insertMetadata(ctx, c.xGoogMetadata)
  177. opts = append(c.CallOptions.CreateUptimeCheckConfig[0:len(c.CallOptions.CreateUptimeCheckConfig):len(c.CallOptions.CreateUptimeCheckConfig)], opts...)
  178. var resp *monitoringpb.UptimeCheckConfig
  179. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  180. var err error
  181. resp, err = c.uptimeCheckClient.CreateUptimeCheckConfig(ctx, req, settings.GRPC...)
  182. return err
  183. }, opts...)
  184. if err != nil {
  185. return nil, err
  186. }
  187. return resp, nil
  188. }
  189. // UpdateUptimeCheckConfig updates an uptime check configuration. You can either replace the entire
  190. // configuration with a new one or replace only certain fields in the current
  191. // configuration by specifying the fields to be updated via "updateMask".
  192. // Returns the updated configuration.
  193. func (c *UptimeCheckClient) UpdateUptimeCheckConfig(ctx context.Context, req *monitoringpb.UpdateUptimeCheckConfigRequest, opts ...gax.CallOption) (*monitoringpb.UptimeCheckConfig, error) {
  194. ctx = insertMetadata(ctx, c.xGoogMetadata)
  195. opts = append(c.CallOptions.UpdateUptimeCheckConfig[0:len(c.CallOptions.UpdateUptimeCheckConfig):len(c.CallOptions.UpdateUptimeCheckConfig)], opts...)
  196. var resp *monitoringpb.UptimeCheckConfig
  197. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  198. var err error
  199. resp, err = c.uptimeCheckClient.UpdateUptimeCheckConfig(ctx, req, settings.GRPC...)
  200. return err
  201. }, opts...)
  202. if err != nil {
  203. return nil, err
  204. }
  205. return resp, nil
  206. }
  207. // DeleteUptimeCheckConfig deletes an uptime check configuration. Note that this method will fail
  208. // if the uptime check configuration is referenced by an alert policy or
  209. // other dependent configs that would be rendered invalid by the deletion.
  210. func (c *UptimeCheckClient) DeleteUptimeCheckConfig(ctx context.Context, req *monitoringpb.DeleteUptimeCheckConfigRequest, opts ...gax.CallOption) error {
  211. ctx = insertMetadata(ctx, c.xGoogMetadata)
  212. opts = append(c.CallOptions.DeleteUptimeCheckConfig[0:len(c.CallOptions.DeleteUptimeCheckConfig):len(c.CallOptions.DeleteUptimeCheckConfig)], opts...)
  213. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  214. var err error
  215. _, err = c.uptimeCheckClient.DeleteUptimeCheckConfig(ctx, req, settings.GRPC...)
  216. return err
  217. }, opts...)
  218. return err
  219. }
  220. // ListUptimeCheckIps returns the list of IPs that checkers run from
  221. func (c *UptimeCheckClient) ListUptimeCheckIps(ctx context.Context, req *monitoringpb.ListUptimeCheckIpsRequest, opts ...gax.CallOption) *UptimeCheckIpIterator {
  222. ctx = insertMetadata(ctx, c.xGoogMetadata)
  223. opts = append(c.CallOptions.ListUptimeCheckIps[0:len(c.CallOptions.ListUptimeCheckIps):len(c.CallOptions.ListUptimeCheckIps)], opts...)
  224. it := &UptimeCheckIpIterator{}
  225. req = proto.Clone(req).(*monitoringpb.ListUptimeCheckIpsRequest)
  226. it.InternalFetch = func(pageSize int, pageToken string) ([]*monitoringpb.UptimeCheckIp, string, error) {
  227. var resp *monitoringpb.ListUptimeCheckIpsResponse
  228. req.PageToken = pageToken
  229. if pageSize > math.MaxInt32 {
  230. req.PageSize = math.MaxInt32
  231. } else {
  232. req.PageSize = int32(pageSize)
  233. }
  234. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  235. var err error
  236. resp, err = c.uptimeCheckClient.ListUptimeCheckIps(ctx, req, settings.GRPC...)
  237. return err
  238. }, opts...)
  239. if err != nil {
  240. return nil, "", err
  241. }
  242. return resp.UptimeCheckIps, resp.NextPageToken, nil
  243. }
  244. fetch := func(pageSize int, pageToken string) (string, error) {
  245. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  246. if err != nil {
  247. return "", err
  248. }
  249. it.items = append(it.items, items...)
  250. return nextPageToken, nil
  251. }
  252. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  253. it.pageInfo.MaxSize = int(req.PageSize)
  254. return it
  255. }
  256. // UptimeCheckConfigIterator manages a stream of *monitoringpb.UptimeCheckConfig.
  257. type UptimeCheckConfigIterator struct {
  258. items []*monitoringpb.UptimeCheckConfig
  259. pageInfo *iterator.PageInfo
  260. nextFunc func() error
  261. // InternalFetch is for use by the Google Cloud Libraries only.
  262. // It is not part of the stable interface of this package.
  263. //
  264. // InternalFetch returns results from a single call to the underlying RPC.
  265. // The number of results is no greater than pageSize.
  266. // If there are no more results, nextPageToken is empty and err is nil.
  267. InternalFetch func(pageSize int, pageToken string) (results []*monitoringpb.UptimeCheckConfig, nextPageToken string, err error)
  268. }
  269. // PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
  270. func (it *UptimeCheckConfigIterator) PageInfo() *iterator.PageInfo {
  271. return it.pageInfo
  272. }
  273. // Next returns the next result. Its second return value is iterator.Done if there are no more
  274. // results. Once Next returns Done, all subsequent calls will return Done.
  275. func (it *UptimeCheckConfigIterator) Next() (*monitoringpb.UptimeCheckConfig, error) {
  276. var item *monitoringpb.UptimeCheckConfig
  277. if err := it.nextFunc(); err != nil {
  278. return item, err
  279. }
  280. item = it.items[0]
  281. it.items = it.items[1:]
  282. return item, nil
  283. }
  284. func (it *UptimeCheckConfigIterator) bufLen() int {
  285. return len(it.items)
  286. }
  287. func (it *UptimeCheckConfigIterator) takeBuf() interface{} {
  288. b := it.items
  289. it.items = nil
  290. return b
  291. }
  292. // UptimeCheckIpIterator manages a stream of *monitoringpb.UptimeCheckIp.
  293. type UptimeCheckIpIterator struct {
  294. items []*monitoringpb.UptimeCheckIp
  295. pageInfo *iterator.PageInfo
  296. nextFunc func() error
  297. // InternalFetch is for use by the Google Cloud Libraries only.
  298. // It is not part of the stable interface of this package.
  299. //
  300. // InternalFetch returns results from a single call to the underlying RPC.
  301. // The number of results is no greater than pageSize.
  302. // If there are no more results, nextPageToken is empty and err is nil.
  303. InternalFetch func(pageSize int, pageToken string) (results []*monitoringpb.UptimeCheckIp, nextPageToken string, err error)
  304. }
  305. // PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
  306. func (it *UptimeCheckIpIterator) PageInfo() *iterator.PageInfo {
  307. return it.pageInfo
  308. }
  309. // Next returns the next result. Its second return value is iterator.Done if there are no more
  310. // results. Once Next returns Done, all subsequent calls will return Done.
  311. func (it *UptimeCheckIpIterator) Next() (*monitoringpb.UptimeCheckIp, error) {
  312. var item *monitoringpb.UptimeCheckIp
  313. if err := it.nextFunc(); err != nil {
  314. return item, err
  315. }
  316. item = it.items[0]
  317. it.items = it.items[1:]
  318. return item, nil
  319. }
  320. func (it *UptimeCheckIpIterator) bufLen() int {
  321. return len(it.items)
  322. }
  323. func (it *UptimeCheckIpIterator) takeBuf() interface{} {
  324. b := it.items
  325. it.items = nil
  326. return b
  327. }