google-cloud-monitoring 0.29.3 → 0.29.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b792e40ae869d39f4135020eb9c7bab809f82dfbc7428cb0053c745979d90bd5
4
- data.tar.gz: 80c0233b94b4e28111e3ad543e01fc7efdfd5ff9955f30c19fe3e09821c0dff8
3
+ metadata.gz: 441efddbf31ee031665e3cf1ad55dc495c83fbb4eda6e14921406b72cfa8b301
4
+ data.tar.gz: 2766134674f57e88798b27c4dbbd6384c17cf138b8d14c02392deaed60c35b76
5
5
  SHA512:
6
- metadata.gz: 99da32cacf20be0bef15fe42e761e49d1a19a8df6a566c6bbe698b808a3f845ddd898ad62217e867b3be7930ae1e1d6b13f79597442d9a519ac02158e187e562
7
- data.tar.gz: 9d3d18c4b1a2173c3aeeafdf0cd77a5e5624b4eef9269c9d4c8d6a6a3f29b41dc5dd557f0bc64c25704ecec142256952d289ebd2f0f01463cacd58b7808adee6
6
+ metadata.gz: 16bd2062fd76d895bdebb9d9a7ecb70a28d743e8589404ea4c6c4f3faf43caf478464af4784589ed9f051586513ac5e56a04c1888cb407710fac635b89202337
7
+ data.tar.gz: 706b996e2ff80685b5e12c6aa8905469a9269079300c3ab2374252914e88730e3c7fcf0bb19b2d6f0a6d41013b247a525687d59f3af8601fd3fe45343d650647
data/.yardopts CHANGED
@@ -7,3 +7,5 @@
7
7
  ./lib/**/*.rb
8
8
  -
9
9
  README.md
10
+ AUTHENTICATION.md
11
+ LICENSE
@@ -0,0 +1,199 @@
1
+ # Authentication
2
+
3
+ In general, the google-cloud-monitoring library uses [Service
4
+ Account](https://cloud.google.com/iam/docs/creating-managing-service-accounts)
5
+ credentials to connect to Google Cloud services. When running within [Google
6
+ Cloud Platform environments](#google-cloud-platform-environments)
7
+ the credentials will be discovered automatically. When running on other
8
+ environments, the Service Account credentials can be specified by providing the
9
+ path to the [JSON
10
+ keyfile](https://cloud.google.com/iam/docs/managing-service-account-keys) for
11
+ the account (or the JSON itself) in [environment
12
+ variables](#environment-variables). Additionally, Cloud SDK credentials can also
13
+ be discovered automatically, but this is only recommended during development.
14
+
15
+ ## Quickstart
16
+
17
+ 1. [Create a service account and credentials](#creating-a-service-account).
18
+ 2. Set the [environment variable](#environment-variables).
19
+
20
+ ```sh
21
+ export MONITORING_CREDENTIALS=/path/to/json`
22
+ ```
23
+
24
+ 3. Initialize the client.
25
+
26
+ ```ruby
27
+ require "google/cloud/monitoring"
28
+
29
+ client = Google::Cloud::Monitoring.new
30
+ ```
31
+
32
+ ## Project and Credential Lookup
33
+
34
+ The google-cloud-monitoring library aims to make authentication
35
+ as simple as possible, and provides several mechanisms to configure your system
36
+ without providing **Project ID** and **Service Account Credentials** directly in
37
+ code.
38
+
39
+ **Project ID** is discovered in the following order:
40
+
41
+ 1. Specify project ID in method arguments
42
+ 2. Specify project ID in configuration
43
+ 3. Discover project ID in environment variables
44
+ 4. Discover GCE project ID
45
+ 5. Discover project ID in credentials JSON
46
+
47
+ **Credentials** are discovered in the following order:
48
+
49
+ 1. Specify credentials in method arguments
50
+ 2. Specify credentials in configuration
51
+ 3. Discover credentials path in environment variables
52
+ 4. Discover credentials JSON in environment variables
53
+ 5. Discover credentials file in the Cloud SDK's path
54
+ 6. Discover GCE credentials
55
+
56
+ ### Google Cloud Platform environments
57
+
58
+ While running on Google Cloud Platform environments such as Google Compute
59
+ Engine, Google App Engine and Google Kubernetes Engine, no extra work is needed.
60
+ The **Project ID** and **Credentials** and are discovered automatically. Code
61
+ should be written as if already authenticated. Just be sure when you [set up the
62
+ GCE instance][gce-how-to], you add the correct scopes for the APIs you want to
63
+ access. For example:
64
+
65
+ * **All APIs**
66
+ * `https://www.googleapis.com/auth/cloud-platform`
67
+ * `https://www.googleapis.com/auth/cloud-platform.read-only`
68
+ * **BigQuery**
69
+ * `https://www.googleapis.com/auth/bigquery`
70
+ * `https://www.googleapis.com/auth/bigquery.insertdata`
71
+ * **Compute Engine**
72
+ * `https://www.googleapis.com/auth/compute`
73
+ * **Datastore**
74
+ * `https://www.googleapis.com/auth/datastore`
75
+ * `https://www.googleapis.com/auth/userinfo.email`
76
+ * **DNS**
77
+ * `https://www.googleapis.com/auth/ndev.clouddns.readwrite`
78
+ * **Pub/Sub**
79
+ * `https://www.googleapis.com/auth/pubsub`
80
+ * **Storage**
81
+ * `https://www.googleapis.com/auth/devstorage.full_control`
82
+ * `https://www.googleapis.com/auth/devstorage.read_only`
83
+ * `https://www.googleapis.com/auth/devstorage.read_write`
84
+
85
+ ### Environment Variables
86
+
87
+ The **Project ID** and **Credentials JSON** can be placed in environment
88
+ variables instead of declaring them directly in code. Each service has its own
89
+ environment variable, allowing for different service accounts to be used for
90
+ different services. (See the READMEs for the individual service gems for
91
+ details.) The path to the **Credentials JSON** file can be stored in the
92
+ environment variable, or the **Credentials JSON** itself can be stored for
93
+ environments such as Docker containers where writing files is difficult or not
94
+ encouraged.
95
+
96
+ The environment variables that google-cloud-monitoring checks for project ID are:
97
+
98
+ 1. `MONITORING_PROJECT`
99
+ 2. `GOOGLE_CLOUD_PROJECT`
100
+
101
+ The environment variables that google-cloud-monitoring checks for credentials are configured on {Google::Cloud::Monitoring::V3::Credentials}:
102
+
103
+ 1. `MONITORING_CREDENTIALS` - Path to JSON file, or JSON contents
104
+ 2. `MONITORING_KEYFILE` - Path to JSON file, or JSON contents
105
+ 3. `GOOGLE_CLOUD_CREDENTIALS` - Path to JSON file, or JSON contents
106
+ 4. `GOOGLE_CLOUD_KEYFILE` - Path to JSON file, or JSON contents
107
+ 5. `GOOGLE_APPLICATION_CREDENTIALS` - Path to JSON file
108
+
109
+ ```ruby
110
+ require "google/cloud/monitoring"
111
+
112
+ ENV["MONITORING_PROJECT"] = "my-project-id"
113
+ ENV["MONITORING_CREDENTIALS"] = "path/to/keyfile.json"
114
+
115
+ client = Google::Cloud::Monitoring.new
116
+ ```
117
+
118
+ ### Configuration
119
+
120
+ The **Project ID** and **Credentials JSON** can be configured instead of placing them in environment variables or providing them as arguments.
121
+
122
+ ```ruby
123
+ require "google/cloud/monitoring"
124
+
125
+ Google::Cloud::Monitoring.configure do |config|
126
+ config.project_id = "my-project-id"
127
+ config.credentials = "path/to/keyfile.json"
128
+ end
129
+
130
+ client = Google::Cloud::Monitoring.new
131
+ ```
132
+
133
+ ### Cloud SDK
134
+
135
+ This option allows for an easy way to authenticate during development. If
136
+ credentials are not provided in code or in environment variables, then Cloud SDK
137
+ credentials are discovered.
138
+
139
+ To configure your system for this, simply:
140
+
141
+ 1. [Download and install the Cloud SDK](https://cloud.google.com/sdk)
142
+ 2. Authenticate using OAuth 2.0 `$ gcloud auth login`
143
+ 3. Write code as if already authenticated.
144
+
145
+ **NOTE:** This is _not_ recommended for running in production. The Cloud SDK
146
+ *should* only be used during development.
147
+
148
+ [gce-how-to]: https://cloud.google.com/compute/docs/authentication#using
149
+ [dev-console]: https://console.cloud.google.com/project
150
+
151
+ [enable-apis]: https://raw.githubusercontent.com/GoogleCloudPlatform/gcloud-common/master/authentication/enable-apis.png
152
+
153
+ [create-new-service-account]: https://raw.githubusercontent.com/GoogleCloudPlatform/gcloud-common/master/authentication/create-new-service-account.png
154
+ [create-new-service-account-existing-keys]: https://raw.githubusercontent.com/GoogleCloudPlatform/gcloud-common/master/authentication/create-new-service-account-existing-keys.png
155
+ [reuse-service-account]: https://raw.githubusercontent.com/GoogleCloudPlatform/gcloud-common/master/authentication/reuse-service-account.png
156
+
157
+ ## Creating a Service Account
158
+
159
+ Google Cloud requires a **Project ID** and **Service Account Credentials** to
160
+ connect to the APIs. You will use the **Project ID** and **JSON key file** to
161
+ connect to most services with google-cloud-monitoring.
162
+
163
+ If you are not running this client within [Google Cloud Platform
164
+ environments](#google-cloud-platform-environments), you need a Google
165
+ Developers service account.
166
+
167
+ 1. Visit the [Google Developers Console][dev-console].
168
+ 1. Create a new project or click on an existing project.
169
+ 1. Activate the slide-out navigation tray and select **API Manager**. From
170
+ here, you will enable the APIs that your application requires.
171
+
172
+ ![Enable the APIs that your application requires][enable-apis]
173
+
174
+ *Note: You may need to enable billing in order to use these services.*
175
+
176
+ 1. Select **Credentials** from the side navigation.
177
+
178
+ You should see a screen like one of the following.
179
+
180
+ ![Create a new service account][create-new-service-account]
181
+
182
+ ![Create a new service account With Existing Keys][create-new-service-account-existing-keys]
183
+
184
+ Find the "Add credentials" drop down and select "Service account" to be
185
+ guided through downloading a new JSON key file.
186
+
187
+ If you want to re-use an existing service account, you can easily generate a
188
+ new key file. Just select the account you wish to re-use, and click "Generate
189
+ new JSON key":
190
+
191
+ ![Re-use an existing service account][reuse-service-account]
192
+
193
+ The key file you download will be used by this library to authenticate API
194
+ requests and should be stored in a secure location.
195
+
196
+ ## Troubleshooting
197
+
198
+ If you're having trouble authenticating you can ask for help by following the
199
+ {file:TROUBLESHOOTING.md Troubleshooting Guide}.
data/README.md CHANGED
@@ -26,16 +26,16 @@ $ gem install google-cloud-monitoring
26
26
  ```rb
27
27
  require "google/cloud/monitoring"
28
28
 
29
- metric_service_client = Google::Cloud::Monitoring::Metric.new
29
+ metric_client = Google::Cloud::Monitoring::Metric.new
30
30
  formatted_name = Google::Cloud::Monitoring::V3::MetricServiceClient.project_path(project_id)
31
31
 
32
32
  # Iterate over all results.
33
- metric_service_client.list_monitored_resource_descriptors(formatted_name).each do |element|
33
+ metric_client.list_monitored_resource_descriptors(formatted_name).each do |element|
34
34
  # Process element.
35
35
  end
36
36
 
37
37
  # Or iterate over results one page at a time.
38
- metric_service_client.list_monitored_resource_descriptors(formatted_name).each_page do |page|
38
+ metric_client.list_monitored_resource_descriptors(formatted_name).each_page do |page|
39
39
  # Process each page at a time.
40
40
  page.each do |element|
41
41
  # Process element.
@@ -48,16 +48,16 @@ module Google
48
48
  # ```rb
49
49
  # require "google/cloud/monitoring"
50
50
  #
51
- # metric_service_client = Google::Cloud::Monitoring::Metric.new
51
+ # metric_client = Google::Cloud::Monitoring::Metric.new
52
52
  # formatted_name = Google::Cloud::Monitoring::V3::MetricServiceClient.project_path(project_id)
53
53
  #
54
54
  # # Iterate over all results.
55
- # metric_service_client.list_monitored_resource_descriptors(formatted_name).each do |element|
55
+ # metric_client.list_monitored_resource_descriptors(formatted_name).each do |element|
56
56
  # # Process element.
57
57
  # end
58
58
  #
59
59
  # # Or iterate over results one page at a time.
60
- # metric_service_client.list_monitored_resource_descriptors(formatted_name).each_page do |page|
60
+ # metric_client.list_monitored_resource_descriptors(formatted_name).each_page do |page|
61
61
  # # Process each page at a time.
62
62
  # page.each do |element|
63
63
  # # Process element.
@@ -54,16 +54,16 @@ module Google
54
54
  # ```rb
55
55
  # require "google/cloud/monitoring"
56
56
  #
57
- # metric_service_client = Google::Cloud::Monitoring::Metric.new(version: :v3)
57
+ # metric_client = Google::Cloud::Monitoring::Metric.new(version: :v3)
58
58
  # formatted_name = Google::Cloud::Monitoring::V3::MetricServiceClient.project_path(project_id)
59
59
  #
60
60
  # # Iterate over all results.
61
- # metric_service_client.list_monitored_resource_descriptors(formatted_name).each do |element|
61
+ # metric_client.list_monitored_resource_descriptors(formatted_name).each do |element|
62
62
  # # Process element.
63
63
  # end
64
64
  #
65
65
  # # Or iterate over results one page at a time.
66
- # metric_service_client.list_monitored_resource_descriptors(formatted_name).each_page do |page|
66
+ # metric_client.list_monitored_resource_descriptors(formatted_name).each_page do |page|
67
67
  # # Process each page at a time.
68
68
  # page.each do |element|
69
69
  # # Process element.
@@ -78,12 +78,6 @@ module Google
78
78
  ].freeze
79
79
 
80
80
 
81
- PROJECT_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
82
- "projects/{project}"
83
- )
84
-
85
- private_constant :PROJECT_PATH_TEMPLATE
86
-
87
81
  ALERT_POLICY_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
88
82
  "projects/{project}/alertPolicies/{alert_policy}"
89
83
  )
@@ -96,14 +90,11 @@ module Google
96
90
 
97
91
  private_constant :ALERT_POLICY_CONDITION_PATH_TEMPLATE
98
92
 
99
- # Returns a fully-qualified project resource name string.
100
- # @param project [String]
101
- # @return [String]
102
- def self.project_path project
103
- PROJECT_PATH_TEMPLATE.render(
104
- :"project" => project
105
- )
106
- end
93
+ PROJECT_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
94
+ "projects/{project}"
95
+ )
96
+
97
+ private_constant :PROJECT_PATH_TEMPLATE
107
98
 
108
99
  # Returns a fully-qualified alert_policy resource name string.
109
100
  # @param project [String]
@@ -129,6 +120,15 @@ module Google
129
120
  )
130
121
  end
131
122
 
123
+ # Returns a fully-qualified project resource name string.
124
+ # @param project [String]
125
+ # @return [String]
126
+ def self.project_path project
127
+ PROJECT_PATH_TEMPLATE.render(
128
+ :"project" => project
129
+ )
130
+ end
131
+
132
132
  # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
133
133
  # Provides the means for authenticating requests made by the client. This parameter can
134
134
  # be many types.
@@ -235,27 +235,42 @@ module Google
235
235
  @list_alert_policies = Google::Gax.create_api_call(
236
236
  @alert_policy_service_stub.method(:list_alert_policies),
237
237
  defaults["list_alert_policies"],
238
- exception_transformer: exception_transformer
238
+ exception_transformer: exception_transformer,
239
+ params_extractor: proc do |request|
240
+ {'name' => request.name}
241
+ end
239
242
  )
240
243
  @get_alert_policy = Google::Gax.create_api_call(
241
244
  @alert_policy_service_stub.method(:get_alert_policy),
242
245
  defaults["get_alert_policy"],
243
- exception_transformer: exception_transformer
246
+ exception_transformer: exception_transformer,
247
+ params_extractor: proc do |request|
248
+ {'name' => request.name}
249
+ end
244
250
  )
245
251
  @create_alert_policy = Google::Gax.create_api_call(
246
252
  @alert_policy_service_stub.method(:create_alert_policy),
247
253
  defaults["create_alert_policy"],
248
- exception_transformer: exception_transformer
254
+ exception_transformer: exception_transformer,
255
+ params_extractor: proc do |request|
256
+ {'name' => request.name}
257
+ end
249
258
  )
250
259
  @delete_alert_policy = Google::Gax.create_api_call(
251
260
  @alert_policy_service_stub.method(:delete_alert_policy),
252
261
  defaults["delete_alert_policy"],
253
- exception_transformer: exception_transformer
262
+ exception_transformer: exception_transformer,
263
+ params_extractor: proc do |request|
264
+ {'name' => request.name}
265
+ end
254
266
  )
255
267
  @update_alert_policy = Google::Gax.create_api_call(
256
268
  @alert_policy_service_stub.method(:update_alert_policy),
257
269
  defaults["update_alert_policy"],
258
- exception_transformer: exception_transformer
270
+ exception_transformer: exception_transformer,
271
+ params_extractor: proc do |request|
272
+ {'alert_policy.name' => request.alert_policy.name}
273
+ end
259
274
  )
260
275
  end
261
276
 
@@ -307,16 +322,16 @@ module Google
307
322
  # @example
308
323
  # require "google/cloud/monitoring"
309
324
  #
310
- # alert_policy_service_client = Google::Cloud::Monitoring::AlertPolicy.new(version: :v3)
325
+ # alert_policy_client = Google::Cloud::Monitoring::AlertPolicy.new(version: :v3)
311
326
  # formatted_name = Google::Cloud::Monitoring::V3::AlertPolicyServiceClient.project_path("[PROJECT]")
312
327
  #
313
328
  # # Iterate over all results.
314
- # alert_policy_service_client.list_alert_policies(formatted_name).each do |element|
329
+ # alert_policy_client.list_alert_policies(formatted_name).each do |element|
315
330
  # # Process element.
316
331
  # end
317
332
  #
318
333
  # # Or iterate over results one page at a time.
319
- # alert_policy_service_client.list_alert_policies(formatted_name).each_page do |page|
334
+ # alert_policy_client.list_alert_policies(formatted_name).each_page do |page|
320
335
  # # Process each page at a time.
321
336
  # page.each do |element|
322
337
  # # Process element.
@@ -357,9 +372,9 @@ module Google
357
372
  # @example
358
373
  # require "google/cloud/monitoring"
359
374
  #
360
- # alert_policy_service_client = Google::Cloud::Monitoring::AlertPolicy.new(version: :v3)
375
+ # alert_policy_client = Google::Cloud::Monitoring::AlertPolicy.new(version: :v3)
361
376
  # formatted_name = Google::Cloud::Monitoring::V3::AlertPolicyServiceClient.alert_policy_path("[PROJECT]", "[ALERT_POLICY]")
362
- # response = alert_policy_service_client.get_alert_policy(formatted_name)
377
+ # response = alert_policy_client.get_alert_policy(formatted_name)
363
378
 
364
379
  def get_alert_policy \
365
380
  name,
@@ -400,12 +415,12 @@ module Google
400
415
  # @example
401
416
  # require "google/cloud/monitoring"
402
417
  #
403
- # alert_policy_service_client = Google::Cloud::Monitoring::AlertPolicy.new(version: :v3)
418
+ # alert_policy_client = Google::Cloud::Monitoring::AlertPolicy.new(version: :v3)
404
419
  # formatted_name = Google::Cloud::Monitoring::V3::AlertPolicyServiceClient.project_path("[PROJECT]")
405
420
  #
406
421
  # # TODO: Initialize `alert_policy`:
407
422
  # alert_policy = {}
408
- # response = alert_policy_service_client.create_alert_policy(formatted_name, alert_policy)
423
+ # response = alert_policy_client.create_alert_policy(formatted_name, alert_policy)
409
424
 
410
425
  def create_alert_policy \
411
426
  name,
@@ -438,9 +453,9 @@ module Google
438
453
  # @example
439
454
  # require "google/cloud/monitoring"
440
455
  #
441
- # alert_policy_service_client = Google::Cloud::Monitoring::AlertPolicy.new(version: :v3)
456
+ # alert_policy_client = Google::Cloud::Monitoring::AlertPolicy.new(version: :v3)
442
457
  # formatted_name = Google::Cloud::Monitoring::V3::AlertPolicyServiceClient.alert_policy_path("[PROJECT]", "[ALERT_POLICY]")
443
- # alert_policy_service_client.delete_alert_policy(formatted_name)
458
+ # alert_policy_client.delete_alert_policy(formatted_name)
444
459
 
445
460
  def delete_alert_policy \
446
461
  name,
@@ -501,11 +516,11 @@ module Google
501
516
  # @example
502
517
  # require "google/cloud/monitoring"
503
518
  #
504
- # alert_policy_service_client = Google::Cloud::Monitoring::AlertPolicy.new(version: :v3)
519
+ # alert_policy_client = Google::Cloud::Monitoring::AlertPolicy.new(version: :v3)
505
520
  #
506
521
  # # TODO: Initialize `alert_policy`:
507
522
  # alert_policy = {}
508
- # response = alert_policy_service_client.update_alert_policy(alert_policy)
523
+ # response = alert_policy_client.update_alert_policy(alert_policy)
509
524
 
510
525
  def update_alert_policy \
511
526
  alert_policy,
@@ -185,7 +185,7 @@ module Google
185
185
  # @return [Array<Google::Protobuf::Any>]
186
186
  # Contextual information about the example value. Examples are:
187
187
  #
188
- # Trace ID: type.googleapis.com/google.devtools.cloudtrace.v1.Trace
188
+ # Trace: type.googleapis.com/google.monitoring.v3.SpanContext
189
189
  #
190
190
  # Literal string: type.googleapis.com/google.protobuf.StringValue
191
191
  #