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.
 
 
 

358 lines
14 KiB

  1. // Copyright 2018 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. // AUTO-GENERATED CODE. DO NOT EDIT.
  15. package monitoring
  16. import (
  17. "math"
  18. "time"
  19. "cloud.google.com/go/internal/version"
  20. gax "github.com/googleapis/gax-go"
  21. "golang.org/x/net/context"
  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", version.Go()}, keyval...)
  119. kv = append(kv, "gapic", version.Repo, "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. it.InternalFetch = func(pageSize int, pageToken string) ([]*monitoringpb.UptimeCheckConfig, string, error) {
  129. var resp *monitoringpb.ListUptimeCheckConfigsResponse
  130. req.PageToken = pageToken
  131. if pageSize > math.MaxInt32 {
  132. req.PageSize = math.MaxInt32
  133. } else {
  134. req.PageSize = int32(pageSize)
  135. }
  136. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  137. var err error
  138. resp, err = c.uptimeCheckClient.ListUptimeCheckConfigs(ctx, req, settings.GRPC...)
  139. return err
  140. }, opts...)
  141. if err != nil {
  142. return nil, "", err
  143. }
  144. return resp.UptimeCheckConfigs, resp.NextPageToken, nil
  145. }
  146. fetch := func(pageSize int, pageToken string) (string, error) {
  147. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  148. if err != nil {
  149. return "", err
  150. }
  151. it.items = append(it.items, items...)
  152. return nextPageToken, nil
  153. }
  154. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  155. return it
  156. }
  157. // GetUptimeCheckConfig gets a single uptime check configuration.
  158. func (c *UptimeCheckClient) GetUptimeCheckConfig(ctx context.Context, req *monitoringpb.GetUptimeCheckConfigRequest, opts ...gax.CallOption) (*monitoringpb.UptimeCheckConfig, error) {
  159. ctx = insertMetadata(ctx, c.xGoogMetadata)
  160. opts = append(c.CallOptions.GetUptimeCheckConfig[0:len(c.CallOptions.GetUptimeCheckConfig):len(c.CallOptions.GetUptimeCheckConfig)], opts...)
  161. var resp *monitoringpb.UptimeCheckConfig
  162. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  163. var err error
  164. resp, err = c.uptimeCheckClient.GetUptimeCheckConfig(ctx, req, settings.GRPC...)
  165. return err
  166. }, opts...)
  167. if err != nil {
  168. return nil, err
  169. }
  170. return resp, nil
  171. }
  172. // CreateUptimeCheckConfig creates a new uptime check configuration.
  173. func (c *UptimeCheckClient) CreateUptimeCheckConfig(ctx context.Context, req *monitoringpb.CreateUptimeCheckConfigRequest, opts ...gax.CallOption) (*monitoringpb.UptimeCheckConfig, error) {
  174. ctx = insertMetadata(ctx, c.xGoogMetadata)
  175. opts = append(c.CallOptions.CreateUptimeCheckConfig[0:len(c.CallOptions.CreateUptimeCheckConfig):len(c.CallOptions.CreateUptimeCheckConfig)], opts...)
  176. var resp *monitoringpb.UptimeCheckConfig
  177. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  178. var err error
  179. resp, err = c.uptimeCheckClient.CreateUptimeCheckConfig(ctx, req, settings.GRPC...)
  180. return err
  181. }, opts...)
  182. if err != nil {
  183. return nil, err
  184. }
  185. return resp, nil
  186. }
  187. // UpdateUptimeCheckConfig updates an uptime check configuration. You can either replace the entire
  188. // configuration with a new one or replace only certain fields in the current
  189. // configuration by specifying the fields to be updated via "updateMask".
  190. // Returns the updated configuration.
  191. func (c *UptimeCheckClient) UpdateUptimeCheckConfig(ctx context.Context, req *monitoringpb.UpdateUptimeCheckConfigRequest, opts ...gax.CallOption) (*monitoringpb.UptimeCheckConfig, error) {
  192. ctx = insertMetadata(ctx, c.xGoogMetadata)
  193. opts = append(c.CallOptions.UpdateUptimeCheckConfig[0:len(c.CallOptions.UpdateUptimeCheckConfig):len(c.CallOptions.UpdateUptimeCheckConfig)], opts...)
  194. var resp *monitoringpb.UptimeCheckConfig
  195. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  196. var err error
  197. resp, err = c.uptimeCheckClient.UpdateUptimeCheckConfig(ctx, req, settings.GRPC...)
  198. return err
  199. }, opts...)
  200. if err != nil {
  201. return nil, err
  202. }
  203. return resp, nil
  204. }
  205. // DeleteUptimeCheckConfig deletes an uptime check configuration. Note that this method will fail
  206. // if the uptime check configuration is referenced by an alert policy or
  207. // other dependent configs that would be rendered invalid by the deletion.
  208. func (c *UptimeCheckClient) DeleteUptimeCheckConfig(ctx context.Context, req *monitoringpb.DeleteUptimeCheckConfigRequest, opts ...gax.CallOption) error {
  209. ctx = insertMetadata(ctx, c.xGoogMetadata)
  210. opts = append(c.CallOptions.DeleteUptimeCheckConfig[0:len(c.CallOptions.DeleteUptimeCheckConfig):len(c.CallOptions.DeleteUptimeCheckConfig)], opts...)
  211. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  212. var err error
  213. _, err = c.uptimeCheckClient.DeleteUptimeCheckConfig(ctx, req, settings.GRPC...)
  214. return err
  215. }, opts...)
  216. return err
  217. }
  218. // ListUptimeCheckIps returns the list of IPs that checkers run from
  219. func (c *UptimeCheckClient) ListUptimeCheckIps(ctx context.Context, req *monitoringpb.ListUptimeCheckIpsRequest, opts ...gax.CallOption) *UptimeCheckIpIterator {
  220. ctx = insertMetadata(ctx, c.xGoogMetadata)
  221. opts = append(c.CallOptions.ListUptimeCheckIps[0:len(c.CallOptions.ListUptimeCheckIps):len(c.CallOptions.ListUptimeCheckIps)], opts...)
  222. it := &UptimeCheckIpIterator{}
  223. it.InternalFetch = func(pageSize int, pageToken string) ([]*monitoringpb.UptimeCheckIp, string, error) {
  224. var resp *monitoringpb.ListUptimeCheckIpsResponse
  225. req.PageToken = pageToken
  226. if pageSize > math.MaxInt32 {
  227. req.PageSize = math.MaxInt32
  228. } else {
  229. req.PageSize = int32(pageSize)
  230. }
  231. err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
  232. var err error
  233. resp, err = c.uptimeCheckClient.ListUptimeCheckIps(ctx, req, settings.GRPC...)
  234. return err
  235. }, opts...)
  236. if err != nil {
  237. return nil, "", err
  238. }
  239. return resp.UptimeCheckIps, resp.NextPageToken, nil
  240. }
  241. fetch := func(pageSize int, pageToken string) (string, error) {
  242. items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
  243. if err != nil {
  244. return "", err
  245. }
  246. it.items = append(it.items, items...)
  247. return nextPageToken, nil
  248. }
  249. it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
  250. return it
  251. }
  252. // UptimeCheckConfigIterator manages a stream of *monitoringpb.UptimeCheckConfig.
  253. type UptimeCheckConfigIterator struct {
  254. items []*monitoringpb.UptimeCheckConfig
  255. pageInfo *iterator.PageInfo
  256. nextFunc func() error
  257. // InternalFetch is for use by the Google Cloud Libraries only.
  258. // It is not part of the stable interface of this package.
  259. //
  260. // InternalFetch returns results from a single call to the underlying RPC.
  261. // The number of results is no greater than pageSize.
  262. // If there are no more results, nextPageToken is empty and err is nil.
  263. InternalFetch func(pageSize int, pageToken string) (results []*monitoringpb.UptimeCheckConfig, nextPageToken string, err error)
  264. }
  265. // PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
  266. func (it *UptimeCheckConfigIterator) PageInfo() *iterator.PageInfo {
  267. return it.pageInfo
  268. }
  269. // Next returns the next result. Its second return value is iterator.Done if there are no more
  270. // results. Once Next returns Done, all subsequent calls will return Done.
  271. func (it *UptimeCheckConfigIterator) Next() (*monitoringpb.UptimeCheckConfig, error) {
  272. var item *monitoringpb.UptimeCheckConfig
  273. if err := it.nextFunc(); err != nil {
  274. return item, err
  275. }
  276. item = it.items[0]
  277. it.items = it.items[1:]
  278. return item, nil
  279. }
  280. func (it *UptimeCheckConfigIterator) bufLen() int {
  281. return len(it.items)
  282. }
  283. func (it *UptimeCheckConfigIterator) takeBuf() interface{} {
  284. b := it.items
  285. it.items = nil
  286. return b
  287. }
  288. // UptimeCheckIpIterator manages a stream of *monitoringpb.UptimeCheckIp.
  289. type UptimeCheckIpIterator struct {
  290. items []*monitoringpb.UptimeCheckIp
  291. pageInfo *iterator.PageInfo
  292. nextFunc func() error
  293. // InternalFetch is for use by the Google Cloud Libraries only.
  294. // It is not part of the stable interface of this package.
  295. //
  296. // InternalFetch returns results from a single call to the underlying RPC.
  297. // The number of results is no greater than pageSize.
  298. // If there are no more results, nextPageToken is empty and err is nil.
  299. InternalFetch func(pageSize int, pageToken string) (results []*monitoringpb.UptimeCheckIp, nextPageToken string, err error)
  300. }
  301. // PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
  302. func (it *UptimeCheckIpIterator) PageInfo() *iterator.PageInfo {
  303. return it.pageInfo
  304. }
  305. // Next returns the next result. Its second return value is iterator.Done if there are no more
  306. // results. Once Next returns Done, all subsequent calls will return Done.
  307. func (it *UptimeCheckIpIterator) Next() (*monitoringpb.UptimeCheckIp, error) {
  308. var item *monitoringpb.UptimeCheckIp
  309. if err := it.nextFunc(); err != nil {
  310. return item, err
  311. }
  312. item = it.items[0]
  313. it.items = it.items[1:]
  314. return item, nil
  315. }
  316. func (it *UptimeCheckIpIterator) bufLen() int {
  317. return len(it.items)
  318. }
  319. func (it *UptimeCheckIpIterator) takeBuf() interface{} {
  320. b := it.items
  321. it.items = nil
  322. return b
  323. }