google-cloud-logging 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +7 -0
  2. data/lib/google-cloud-logging.rb +119 -0
  3. data/lib/google/cloud/logging.rb +293 -0
  4. data/lib/google/cloud/logging/credentials.rb +31 -0
  5. data/lib/google/cloud/logging/entry.rb +469 -0
  6. data/lib/google/cloud/logging/entry/http_request.rb +145 -0
  7. data/lib/google/cloud/logging/entry/list.rb +180 -0
  8. data/lib/google/cloud/logging/entry/operation.rb +92 -0
  9. data/lib/google/cloud/logging/logger.rb +309 -0
  10. data/lib/google/cloud/logging/metric.rb +172 -0
  11. data/lib/google/cloud/logging/metric/list.rb +175 -0
  12. data/lib/google/cloud/logging/project.rb +650 -0
  13. data/lib/google/cloud/logging/resource.rb +86 -0
  14. data/lib/google/cloud/logging/resource_descriptor.rb +139 -0
  15. data/lib/google/cloud/logging/resource_descriptor/list.rb +179 -0
  16. data/lib/google/cloud/logging/service.rb +270 -0
  17. data/lib/google/cloud/logging/sink.rb +230 -0
  18. data/lib/google/cloud/logging/sink/list.rb +173 -0
  19. data/lib/google/cloud/logging/v2.rb +17 -0
  20. data/lib/google/cloud/logging/v2/config_service_v2_api.rb +331 -0
  21. data/lib/google/cloud/logging/v2/config_service_v2_client_config.json +53 -0
  22. data/lib/google/cloud/logging/v2/logging_service_v2_api.rb +351 -0
  23. data/lib/google/cloud/logging/v2/logging_service_v2_client_config.json +57 -0
  24. data/lib/google/cloud/logging/v2/metrics_service_v2_api.rb +330 -0
  25. data/lib/google/cloud/logging/v2/metrics_service_v2_client_config.json +53 -0
  26. data/lib/google/cloud/logging/version.rb +22 -0
  27. data/lib/google/logging/v2/log_entry_pb.rb +44 -0
  28. data/lib/google/logging/v2/logging_config_pb.rb +59 -0
  29. data/lib/google/logging/v2/logging_config_services_pb.rb +52 -0
  30. data/lib/google/logging/v2/logging_metrics_pb.rb +51 -0
  31. data/lib/google/logging/v2/logging_metrics_services_pb.rb +51 -0
  32. data/lib/google/logging/v2/logging_pb.rb +59 -0
  33. data/lib/google/logging/v2/logging_services_pb.rb +56 -0
  34. metadata +260 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 074bcffc02110ff018a97cb802e25ec17389e879
4
+ data.tar.gz: e6c42754a6065315cf4c8ef46fa720dbdd91039d
5
+ SHA512:
6
+ metadata.gz: b3bb599eba9d9e427a279cbf4164634a22fa5edca168fb09d201eb9c4bb66f2e8664c52ccdb18e984f44b875f3e15fa7edb0fd431fa8f83e7beea0a4f9c8e5a9
7
+ data.tar.gz: 68c959882e11d938965ba73f4f8d788c4413ea19d8404e7fa1a48a516d1f3805d2ba90ca7bda0fe14eeb6a7bc6be1a6e3438cc8aa4ecc9fc45aed1a3931ec208
@@ -0,0 +1,119 @@
1
+ # Copyright 2016 Google Inc. All rights reserved.
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
+ # http://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
+ ##
16
+ # This file is here to be autorequired by bundler, so that the .bigquery and
17
+ # #bigquery methods can be available, but the library and all dependencies won't
18
+ # be loaded until required and used.
19
+
20
+
21
+ gem "google-cloud-core"
22
+ require "google/cloud"
23
+
24
+ module Google
25
+ module Cloud
26
+ ##
27
+ # Creates a new object for connecting to the Stackdriver Logging service.
28
+ # Each call creates a new connection.
29
+ #
30
+ # For more information on connecting to Google Cloud see the [Authentication
31
+ # Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication).
32
+ #
33
+ # @param [String, Array<String>] scope The OAuth 2.0 scopes controlling the
34
+ # set of resources and operations that the connection can access. See
35
+ # [Using OAuth 2.0 to Access Google
36
+ # APIs](https://developers.google.com/identity/protocols/OAuth2).
37
+ #
38
+ # The default scope is:
39
+ #
40
+ # * `https://www.googleapis.com/auth/logging.admin`
41
+ # @param [Integer] retries Number of times to retry requests on server
42
+ # error. The default value is `3`. Optional.
43
+ # @param [Integer] timeout Default timeout to use in requests. Optional.
44
+ #
45
+ # @return [Google::Cloud::Logging::Project]
46
+ #
47
+ # @example
48
+ # require "google/cloud"
49
+ #
50
+ # gcloud = Google::Cloud.new
51
+ # logging = gcloud.logging
52
+ # # ...
53
+ #
54
+ # @example The default scope can be overridden with the `scope` option:
55
+ # require "google/cloud"
56
+ #
57
+ # gcloud = Google::Cloud.new
58
+ # platform_scope = "https://www.googleapis.com/auth/cloud-platform"
59
+ # logging = gcloud.logging scope: platform_scope
60
+ #
61
+ def logging scope: nil, retries: nil, timeout: nil
62
+ Google::Cloud.logging @project, @keyfile, scope: scope,
63
+ retries: (retries || @retries),
64
+ timeout: (timeout || @timeout)
65
+ end
66
+
67
+ ##
68
+ # Creates a new object for connecting to the Stackdriver Logging service.
69
+ # Each call creates a new connection.
70
+ #
71
+ # For more information on connecting to Google Cloud see the [Authentication
72
+ # Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication).
73
+ #
74
+ # @param [String] project Project identifier for the Stackdriver Logging
75
+ # service.
76
+ # @param [String, Hash] keyfile Keyfile downloaded from Google Cloud. If
77
+ # file path the file must be readable.
78
+ # @param [String, Array<String>] scope The OAuth 2.0 scopes controlling the
79
+ # set of resources and operations that the connection can access. See
80
+ # [Using OAuth 2.0 to Access Google
81
+ # APIs](https://developers.google.com/identity/protocols/OAuth2).
82
+ #
83
+ # The default scope is:
84
+ #
85
+ # * `https://www.googleapis.com/auth/logging.admin`
86
+ # @param [Integer] retries Number of times to retry requests on server
87
+ # error. The default value is `3`. Optional.
88
+ # @param [Integer] timeout Default timeout to use in requests. Optional.
89
+ #
90
+ # @return [Google::Cloud::Logging::Project]
91
+ #
92
+ # @example
93
+ # require "google/cloud/logging"
94
+ #
95
+ # gcloud = Google::Cloud.new
96
+ # logging = gcloud.logging
97
+ # # ...
98
+ #
99
+ def self.logging project = nil, keyfile = nil, scope: nil, retries: nil,
100
+ timeout: nil
101
+ require "google/cloud/logging"
102
+ project ||= Google::Cloud::Logging::Project.default_project
103
+ project = project.to_s # Always cast to a string
104
+ fail ArgumentError, "project is missing" if project.empty?
105
+
106
+ if keyfile.nil?
107
+ credentials = Google::Cloud::Logging::Credentials.default(
108
+ scope: scope)
109
+ else
110
+ credentials = Google::Cloud::Logging::Credentials.new(
111
+ keyfile, scope: scope)
112
+ end
113
+
114
+ Google::Cloud::Logging::Project.new(
115
+ Google::Cloud::Logging::Service.new(
116
+ project, credentials, retries: retries, timeout: timeout))
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,293 @@
1
+ # Copyright 2016 Google Inc. All rights reserved.
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
+ # http://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
+
16
+ require "google-cloud-logging"
17
+ require "google/cloud/logging/project"
18
+
19
+ module Google
20
+ module Cloud
21
+ ##
22
+ # # Stackdriver Logging
23
+ #
24
+ # The Stackdriver Logging service collects and stores logs from applications
25
+ # and services on the Google Cloud Platform, giving you fine-grained,
26
+ # programmatic control over your projects' logs. You can use the Stackdriver
27
+ # Logging API to:
28
+ #
29
+ # * [Read and filter log entries](#listing-log-entries)
30
+ # * [Export your log entries](#exporting-log-entries) to Cloud Storage,
31
+ # BigQuery, or Cloud Pub/Sub
32
+ # * [Create logs-based metrics](#creating-logs-based-metrics) for use in
33
+ # Cloud Monitoring
34
+ # * [Write log entries](#writing-log-entries)
35
+ #
36
+ # For general information about Stackdriver Logging, read [Stackdriver
37
+ # Logging Documentation](https://cloud.google.com/logging/docs/).
38
+ #
39
+ # The goal of google-cloud is to provide an API that is comfortable to
40
+ # Rubyists. Authentication is handled by {Google::Cloud#logging}. You can
41
+ # provide the project and credential information to connect to the
42
+ # Stackdriver Logging service, or if you are running on Google Compute
43
+ # Engine this configuration is taken care of for you. You can read more
44
+ # about the options for connecting in the [Authentication
45
+ # Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication).
46
+ #
47
+ # ## Listing log entries
48
+ #
49
+ # Stackdriver Logging gathers log entries from many services, including
50
+ # Google App Engine and Google Compute Engine. (See the [List of Log
51
+ # Types](https://cloud.google.com/logging/docs/view/logs_index).) In
52
+ # addition, you can write your own log entries to the service.
53
+ #
54
+ # {Google::Cloud::Logging::Project#entries} returns the
55
+ # {Google::Cloud::Logging::Entry} records belonging to your project:
56
+ #
57
+ # ```ruby
58
+ # require "google/cloud"
59
+ #
60
+ # gcloud = Google::Cloud.new
61
+ # logging = gcloud.logging
62
+ # entries = logging.entries
63
+ # entries.each do |e|
64
+ # puts "[#{e.timestamp}] #{e.log_name} #{e.payload.inspect}"
65
+ # end
66
+ # ```
67
+ #
68
+ # You can narrow the results to a single log using an [advanced logs
69
+ # filter](https://cloud.google.com/logging/docs/view/advanced_filters). A
70
+ # log is a named collection of entries. Logs can be produced by Google Cloud
71
+ # Platform services, by third-party services, or by your applications. For
72
+ # example, the log `compute.googleapis.com/activity_log` is produced by
73
+ # Google Compute Engine. Logs are simply referenced by name in google-cloud.
74
+ # There is no `Log` type in google-cloud or `Log` resource in the
75
+ # Stackdriver Logging API.
76
+ #
77
+ # ```ruby
78
+ # require "google/cloud"
79
+ #
80
+ # gcloud = Google::Cloud.new
81
+ # logging = gcloud.logging
82
+ # entries = logging.entries filter: "log:syslog"
83
+ # entries.each do |e|
84
+ # puts "[#{e.timestamp}] #{e.payload.inspect}"
85
+ # end
86
+ # ```
87
+ #
88
+ # You can also order the log entries by `timestamp`.
89
+ #
90
+ # ```ruby
91
+ # require "google/cloud"
92
+ #
93
+ # gcloud = Google::Cloud.new
94
+ # logging = gcloud.logging
95
+ # entries = logging.entries order: "timestamp desc"
96
+ # entries.each do |e|
97
+ # puts "[#{e.timestamp}] #{e.log_name} #{e.payload.inspect}"
98
+ # end
99
+ # ```
100
+ #
101
+ # ## Exporting log entries
102
+ #
103
+ # Stackdriver Logging lets you export log entries to destinations including
104
+ # Google Cloud Storage buckets (for long term log storage), Google BigQuery
105
+ # datasets (for log analysis), and Google Pub/Sub (for streaming to other
106
+ # applications).
107
+ #
108
+ # ### Creating sinks
109
+ #
110
+ # A {Google::Cloud::Logging::Sink} is an object that lets you to specify a
111
+ # set of log entries to export.
112
+ #
113
+ # In addition to the name of the sink and the export destination,
114
+ # {Google::Cloud::Logging::Project#create_sink} accepts an [advanced logs
115
+ # filter](https://cloud.google.com/logging/docs/view/advanced_filters) to
116
+ # narrow the collection.
117
+ #
118
+ # Before creating the sink, ensure that you have granted
119
+ # `cloud-logs@google.com` permission to write logs to the destination. See
120
+ # [Permissions for writing exported
121
+ # logs](https://cloud.google.com/logging/docs/export/configure_export#setting_product_name_short_permissions_for_writing_exported_logs).
122
+ #
123
+ # ```ruby
124
+ # require "google/cloud"
125
+ #
126
+ # gcloud = Google::Cloud.new
127
+ # logging = gcloud.logging
128
+ # storage = gcloud.storage
129
+ #
130
+ # bucket = storage.create_bucket "my-logs-bucket"
131
+ #
132
+ # # Grant owner permission to Stackdriver Logging service
133
+ # email = "cloud-logs@google.com"
134
+ # bucket.acl.add_owner "group-#{email}"
135
+ #
136
+ # sink = logging.create_sink "my-sink",
137
+ # "storage.googleapis.com/#{bucket.id}"
138
+ # ```
139
+ #
140
+ # When you create a sink, only new log entries are exported. Stackdriver
141
+ # Logging does not send previously-ingested log entries to the sink's
142
+ # destination.
143
+ #
144
+ # ### Listing sinks
145
+ #
146
+ # You can also list the sinks belonging to your project with
147
+ # {Google::Cloud::Logging::Project#sinks}.
148
+ #
149
+ # ```ruby
150
+ # require "google/cloud"
151
+ #
152
+ # gcloud = Google::Cloud.new
153
+ # logging = gcloud.logging
154
+ # sinks = logging.sinks
155
+ # sinks.each do |s|
156
+ # puts "#{s.name}: #{s.filter} -> #{s.destination}"
157
+ # end
158
+ # ```
159
+ #
160
+ # ## Creating logs-based metrics
161
+ #
162
+ # You can use log entries in your project as the basis for [Google Cloud
163
+ # Monitoring](https://cloud.google.com/monitoring/docs) metrics. These
164
+ # metrics can then be used to produce Cloud Monitoring reports and alerts.
165
+ #
166
+ # ### Creating metrics
167
+ #
168
+ # A metric is a measured value that can be used to assess a system. Use
169
+ # {Google::Cloud::Logging::Project#create_metric} to configure a
170
+ # {Google::Cloud::Logging::Metric} based on a collection of log entries
171
+ # matching an [advanced logs
172
+ # filter](https://cloud.google.com/logging/docs/view/advanced_filters).
173
+ #
174
+ # ```ruby
175
+ # require "google/cloud"
176
+ #
177
+ # gcloud = Google::Cloud.new
178
+ # logging = gcloud.logging
179
+ # metric = logging.create_metric "errors", "severity>=ERROR"
180
+ # ```
181
+ #
182
+ # ### Listing metrics
183
+ #
184
+ # You can also list the metrics belonging to your project with
185
+ # {Google::Cloud::Logging::Project#metrics}.
186
+ #
187
+ # ```ruby
188
+ # require "google/cloud"
189
+ #
190
+ # gcloud = Google::Cloud.new
191
+ # logging = gcloud.logging
192
+ # metrics = logging.metrics
193
+ # metrics.each do |m|
194
+ # puts "#{m.name}: #{m.filter}"
195
+ # end
196
+ # ```
197
+ #
198
+ # ## Writing log entries
199
+ #
200
+ # An {Google::Cloud::Logging::Entry} is composed of metadata and a payload.
201
+ # The payload is traditionally a message string, but in Stackdriver Logging
202
+ # it can also be a JSON or protocol buffer object. A single log can have
203
+ # entries with different payload types. In addition to the payload, your
204
+ # argument(s) to {Google::Cloud::Logging::Project#write_entries} must also
205
+ # contain a log name and a resource.
206
+ #
207
+ # ```ruby
208
+ # require "google/cloud"
209
+ #
210
+ # gcloud = Google::Cloud.new
211
+ # logging = gcloud.logging
212
+ #
213
+ # entry = logging.entry
214
+ # entry.payload = "Job started."
215
+ # entry.log_name = "my_app_log"
216
+ # entry.resource.type = "gae_app"
217
+ # entry.resource.labels[:module_id] = "1"
218
+ # entry.resource.labels[:version_id] = "20150925t173233"
219
+ #
220
+ # logging.write_entries entry
221
+ # ```
222
+ #
223
+ # If you write a collection of log entries, you can provide the log name,
224
+ # resource, and/or labels hash to be used for all of the entries, and omit
225
+ # these values from the individual entries.
226
+ #
227
+ # ```ruby
228
+ # require "google/cloud"
229
+ #
230
+ # gcloud = Google::Cloud.new
231
+ # logging = gcloud.logging
232
+ #
233
+ # entry1 = logging.entry
234
+ # entry1.payload = "Job started."
235
+ # entry2 = logging.entry
236
+ # entry2.payload = "Job completed."
237
+ # labels = { job_size: "large", job_code: "red" }
238
+ #
239
+ # resource = logging.resource "gae_app",
240
+ # "module_id" => "1",
241
+ # "version_id" => "20150925t173233"
242
+ #
243
+ # logging.write_entries [entry1, entry2],
244
+ # log_name: "my_app_log",
245
+ # resource: resource,
246
+ # labels: labels
247
+ # ```
248
+ #
249
+ # ### Creating a Ruby Logger implementation
250
+ #
251
+ # If your environment requires a logger instance that is API-compatible with
252
+ # Ruby's standard library
253
+ # [Logger](http://ruby-doc.org/stdlib/libdoc/logger/rdoc), you can use
254
+ # {Google::Cloud::Logging::Project#logger} to create one.
255
+ #
256
+ # ```ruby
257
+ # require "google/cloud"
258
+ #
259
+ # gcloud = Google::Cloud.new
260
+ # logging = gcloud.logging
261
+ #
262
+ # resource = logging.resource "gae_app",
263
+ # module_id: "1",
264
+ # version_id: "20150925t173233"
265
+ #
266
+ # logger = logging.logger "my_app_log", resource, env: :production
267
+ # logger.info "Job started."
268
+ # ```
269
+ #
270
+ # ## Configuring retries and timeout
271
+ #
272
+ # You can configure how many times API requests may be automatically
273
+ # retried. When an API request fails, the response will be inspected to see
274
+ # if the request meets criteria indicating that it may succeed on retry,
275
+ # such as `500` and `503` status codes or a specific internal error code
276
+ # such as `rateLimitExceeded`. If it meets the criteria, the request will be
277
+ # retried after a delay. If another error occurs, the delay will be
278
+ # increased before a subsequent attempt, until the `retries` limit is
279
+ # reached.
280
+ #
281
+ # You can also set the request `timeout` value in seconds.
282
+ #
283
+ # ```ruby
284
+ # require "google/cloud"
285
+ #
286
+ # gcloud = Google::Cloud.new
287
+ # logging = gcloud.logging retries: 10, timeout: 120
288
+ # ```
289
+ #
290
+ module Logging
291
+ end
292
+ end
293
+ end
@@ -0,0 +1,31 @@
1
+ # Copyright 2016 Google Inc. All rights reserved.
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
+ # http://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
+
16
+ require "google/cloud/credentials"
17
+
18
+ module Google
19
+ module Cloud
20
+ module Logging
21
+ ##
22
+ # @private Represents the OAuth 2.0 signing logic for Logging.
23
+ class Credentials < Google::Cloud::Credentials
24
+ SCOPE = ["https://www.googleapis.com/auth/logging.admin"]
25
+ PATH_ENV_VARS = %w(LOGGING_KEYFILE GOOGLE_CLOUD_KEYFILE GCLOUD_KEYFILE)
26
+ JSON_ENV_VARS = %w(LOGGING_KEYFILE_JSON GOOGLE_CLOUD_KEYFILE_JSON
27
+ GCLOUD_KEYFILE_JSON)
28
+ end
29
+ end
30
+ end
31
+ end