google-cloud-logging 0.24.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -5
  3. data/lib/google/cloud/logging.rb +5 -6
  4. data/lib/google/cloud/logging/entry.rb +28 -2
  5. data/lib/google/cloud/logging/entry/list.rb +6 -6
  6. data/lib/google/cloud/logging/entry/operation.rb +1 -1
  7. data/lib/google/cloud/logging/entry/source_location.rb +86 -0
  8. data/lib/google/cloud/logging/log/list.rb +155 -0
  9. data/lib/google/cloud/logging/metric/list.rb +6 -6
  10. data/lib/google/cloud/logging/middleware.rb +27 -23
  11. data/lib/google/cloud/logging/project.rb +46 -3
  12. data/lib/google/cloud/logging/rails.rb +37 -20
  13. data/lib/google/cloud/logging/resource_descriptor/list.rb +6 -6
  14. data/lib/google/cloud/logging/service.rb +15 -0
  15. data/lib/google/cloud/logging/sink/list.rb +6 -6
  16. data/lib/google/cloud/logging/v2/config_service_v2_client.rb +24 -13
  17. data/lib/google/cloud/logging/v2/config_service_v2_client_config.json +3 -1
  18. data/lib/google/cloud/logging/v2/doc/google/logging/v2/log_entry.rb +12 -6
  19. data/lib/google/cloud/logging/v2/doc/google/logging/v2/logging.rb +26 -12
  20. data/lib/google/cloud/logging/v2/doc/google/logging/v2/logging_config.rb +23 -12
  21. data/lib/google/cloud/logging/v2/doc/google/protobuf/any.rb +13 -3
  22. data/lib/google/cloud/logging/v2/doc/google/protobuf/duration.rb +6 -0
  23. data/lib/google/cloud/logging/v2/doc/google/protobuf/timestamp.rb +3 -5
  24. data/lib/google/cloud/logging/v2/logging_service_v2_client.rb +43 -27
  25. data/lib/google/cloud/logging/v2/logging_service_v2_client_config.json +6 -4
  26. data/lib/google/cloud/logging/v2/metrics_service_v2_client.rb +3 -2
  27. data/lib/google/cloud/logging/v2/metrics_service_v2_client_config.json +3 -1
  28. data/lib/google/cloud/logging/version.rb +1 -1
  29. data/lib/google/logging/v2/logging_config_services_pb.rb +1 -1
  30. data/lib/google/logging/v2/logging_metrics_pb.rb +2 -0
  31. data/lib/google/logging/v2/logging_metrics_services_pb.rb +1 -1
  32. data/lib/google/logging/v2/logging_services_pb.rb +5 -4
  33. metadata +9 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d45a1ba9632dc323314bfe54cd33c915b0ee49b3
4
- data.tar.gz: 9679812393a50bf2add34272191477b4becc6313
3
+ metadata.gz: 3ed947d4ac0a7d053284364df99d1d27eb2dd013
4
+ data.tar.gz: 66c8792bbad62413185d1abfedb3e3e9692def55
5
5
  SHA512:
6
- metadata.gz: fde2ed6e950481674e70b3193f7e007f2ee2c97b7e4d2cab34e97ec157f2788a06897dfbb6515feaf5607d46e6f2836663f00e826193dc6e70debd29a3aed9ab
7
- data.tar.gz: 85ae2b82f29cd721a021408c8ee1083d5e548be252220d1b2207473355d5369b9dfefdf4a32ee279aaa8d8985d161a58de9f361250a3a310af2b518ed055be1d
6
+ metadata.gz: e49e794f719c33b0c7d5473610152544e0b17519da2bc04bf7543a6c973c931d56c336a5b9fee74bec6781f123ba5b72ee6be23ac2f78abbdea5e5fdefe1dfd7
7
+ data.tar.gz: a63f6b59880746e4898a9e5dd32b72dbbd866be2dcf0801fff66e9a151d7fe3b3c7d4edbc37b01ea634939bd34b07c6cadd7abb2648a11cf2f4eaf4a255829b1
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [Stackdriver Logging](https://cloud.google.com/logging/) ([docs](https://cloud.google.com/logging/docs/)) allows you to store, search, analyze, monitor, and alert on log data and events from Google Cloud Platform and Amazon Web Services (AWS). It supports ingestion of any custom log data from any source. Stackdriver Logging is a fully-managed service that performs at scale and can ingest application and system log data from thousands of VMs. Even better, you can analyze all that log data in real-time.
4
4
 
5
- - [google-cloud-logging API documentation](http://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-logging/master/google/cloud/logging)
5
+ - [google-cloud-logging API documentation](http://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-logging/latest)
6
6
  - [google-cloud-logging on RubyGems](https://rubygems.org/gems/google-cloud-logging)
7
7
  - [Stackdriver Logging documentation](https://cloud.google.com/logging/docs/)
8
8
 
@@ -46,7 +46,7 @@ logging.write_entries entry
46
46
 
47
47
  ## Rails Integration
48
48
 
49
- This library also provides a built in Railtie for Ruby on Rails integration. When enabled, it sets an instance of Google::Cloud::Logging::Logger as the default Rails logger. Then all consequent log entries will be submitted to the Stackdriver Logging service.
49
+ This library also provides a built in Railtie for Ruby on Rails integration. When enabled, it sets an instance of Google::Cloud::Logging::Logger as the default Rails logger. Then all consequent log entries will be submitted to the Stackdriver Logging service.
50
50
 
51
51
  To do this, simply add this line to config/application.rb:
52
52
  ```ruby
@@ -60,13 +60,13 @@ config.google_cloud.keyfile = "/path/to/gcp/secret.json"
60
60
  # Or more specificly for Logging
61
61
  config.google_cloud.logging.project_id = "gcp-project-id"
62
62
  config.google_cloud.logging.keyfile = "/path/to/gcp/sercret.json"
63
-
63
+
64
64
  # Explicitly enable or disable Logging
65
65
  config.google_cloud.use_logging = true
66
-
66
+
67
67
  # Set Stackdriver Logging log name
68
68
  config.google_cloud.logging.log_name = "my-app-log"
69
-
69
+
70
70
  # Override default monitored resource if needed. E.g. used on AWS
71
71
  config.google_cloud.logging.monitored_resource.type = "aws_ec2_instance"
72
72
  config.google_cloud.logging.monitored_resource.labels.instance_id = "ec2-instance-id"
@@ -84,7 +84,7 @@ module Google
84
84
  # require "google/cloud/logging"
85
85
  #
86
86
  # logging = Google::Cloud::Logging.new
87
- # entries = logging.entries filter: "log:syslog"
87
+ # entries = logging.entries filter: "logName:syslog"
88
88
  # entries.each do |e|
89
89
  # puts "[#{e.timestamp}] #{e.payload.inspect}"
90
90
  # end
@@ -98,7 +98,7 @@ module Google
98
98
  # logging = Google::Cloud::Logging.new
99
99
  # entries = logging.entries order: "timestamp desc"
100
100
  # entries.each do |e|
101
- # puts "[#{e.timestamp}] #{e.log_name} #{e.payload.inspect}"
101
+ # puts "[#{e.timestamp}] #{e.log_name}"
102
102
  # end
103
103
  # ```
104
104
  #
@@ -121,10 +121,11 @@ module Google
121
121
  #
122
122
  # Before creating the sink, ensure that you have granted
123
123
  # `cloud-logs@google.com` permission to write logs to the destination. See
124
- # [Permissions for writing exported
125
- # logs](https://cloud.google.com/logging/docs/export/configure_export#setting_product_name_short_permissions_for_writing_exported_logs).
124
+ # [Exporting Logs
125
+ # (V2)](https://cloud.google.com/logging/docs/export/configure_export_v2).
126
126
  #
127
127
  # ```ruby
128
+ # require "google/cloud/storage"
128
129
  # require "google/cloud/logging"
129
130
  #
130
131
  # storage = Google::Cloud::Storage.new
@@ -135,8 +136,6 @@ module Google
135
136
  # email = "cloud-logs@google.com"
136
137
  # bucket.acl.add_owner "group-#{email}"
137
138
  #
138
- # require "google/cloud/logging"
139
- #
140
139
  # logging = Google::Cloud::Logging.new
141
140
  #
142
141
  # sink = logging.create_sink "my-sink",
@@ -17,6 +17,7 @@ require "google/cloud/logging/convert"
17
17
  require "google/cloud/logging/resource"
18
18
  require "google/cloud/logging/entry/http_request"
19
19
  require "google/cloud/logging/entry/operation"
20
+ require "google/cloud/logging/entry/source_location"
20
21
  require "google/cloud/logging/entry/list"
21
22
 
22
23
  module Google
@@ -67,6 +68,7 @@ module Google
67
68
  @http_request = HttpRequest.new
68
69
  @operation = Operation.new
69
70
  @severity = :DEFAULT
71
+ @source_location = SourceLocation.new
70
72
  end
71
73
 
72
74
  ##
@@ -349,6 +351,21 @@ module Google
349
351
  # @return [Google::Cloud::Logging::Entry::Operation]
350
352
  attr_reader :operation
351
353
 
354
+ ##
355
+ # Resource name of the trace associated with the log entry, if any. If
356
+ # it contains a relative resource name, the name is assumed to be
357
+ # relative to `//tracing.googleapis.com`. Example:
358
+ # `projects/my-projectid/traces/06796866738c859f2f19b7cfb3214824`
359
+ # Optional.
360
+ # @return [String]
361
+ attr_accessor :trace
362
+
363
+ ##
364
+ # Source code location information associated with the log entry, if
365
+ # any.
366
+ # @return [Google::Cloud::Logging::Entry::SourceLocation]
367
+ attr_reader :source_location
368
+
352
369
  ##
353
370
  # @private Determines if the Entry has any data.
354
371
  def empty?
@@ -359,7 +376,9 @@ module Google
359
376
  payload.nil? &&
360
377
  resource.empty? &&
361
378
  http_request.empty? &&
362
- operation.empty?
379
+ operation.empty? &&
380
+ trace.nil? &&
381
+ source_location.empty?
363
382
  end
364
383
 
365
384
  ##
@@ -374,7 +393,9 @@ module Google
374
393
  labels: labels_grpc,
375
394
  resource: resource.to_grpc,
376
395
  http_request: http_request.to_grpc,
377
- operation: operation.to_grpc
396
+ operation: operation.to_grpc,
397
+ trace: trace.to_s,
398
+ source_location: source_location.to_grpc
378
399
  )
379
400
  # Add payload
380
401
  append_payload grpc
@@ -398,6 +419,11 @@ module Google
398
419
  HttpRequest.from_grpc(grpc.http_request)
399
420
  e.instance_variable_set "@operation",
400
421
  Operation.from_grpc(grpc.operation)
422
+ e.trace = grpc.trace
423
+ e.instance_variable_set "@source_location",
424
+ SourceLocation.from_grpc(
425
+ grpc.source_location
426
+ )
401
427
  end
402
428
  end
403
429
 
@@ -77,15 +77,15 @@ module Google
77
77
  end
78
78
 
79
79
  ##
80
- # Retrieves all log entries by repeatedly loading {#next} until
81
- # {#next?} returns `false`. Calls the given block once for each log
82
- # entry, which is passed as the parameter.
80
+ # Retrieves remaining results by repeatedly invoking {#next} until
81
+ # {#next?} returns `false`. Calls the given block once for each
82
+ # result, which is passed as the argument to the block.
83
83
  #
84
84
  # An Enumerator is returned if no block is given.
85
85
  #
86
- # This method may make several API calls until all log entries are
87
- # retrieved. Be sure to use as narrow a search criteria as possible.
88
- # Please use with caution.
86
+ # This method will make repeated API calls until all remaining results
87
+ # are retrieved. (Unlike `#each`, for example, which merely iterates
88
+ # over the results returned by a single API call.) Use with caution.
89
89
  #
90
90
  # @param [Integer] request_limit The upper limit of API requests to
91
91
  # make to load all log entries. Default is no limit.
@@ -74,7 +74,7 @@ module Google
74
74
  end
75
75
 
76
76
  ##
77
- # @private New HttpRequest from a
77
+ # @private New Google::Cloud::Logging::Entry::Operation from a
78
78
  # Google::Logging::V2::LogEntryOperation object.
79
79
  def self.from_grpc grpc
80
80
  return new if grpc.nil?
@@ -0,0 +1,86 @@
1
+ # Copyright 2017 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
+ module Google
17
+ module Cloud
18
+ module Logging
19
+ class Entry
20
+ ##
21
+ # # SourceLocation
22
+ #
23
+ # Additional information about the source code location that produced
24
+ # the log entry.
25
+ #
26
+ # See also {Google::Cloud::Logging::Entry#source_location}.
27
+ #
28
+ class SourceLocation
29
+ ##
30
+ # @private Create an empty SourceLocation object.
31
+ def initialize
32
+ end
33
+
34
+ ##
35
+ # Source file name. Depending on the runtime environment, this might
36
+ # be a simple name or a fully-qualified name. Optional.
37
+ attr_accessor :file
38
+
39
+ ##
40
+ # Line within the source file. 1-based; `0` indicates no line number
41
+ # available. Optional.
42
+ attr_accessor :line
43
+
44
+ ##
45
+ # Human-readable name of the function or method being invoked, with
46
+ # optional context such as the class or package name. This information
47
+ # may be used in contexts such as the logs viewer, where a file and
48
+ # line number are less meaningful. Optional.
49
+ attr_accessor :function
50
+
51
+ ##
52
+ # @private Determines if the SourceLocation has any data.
53
+ def empty?
54
+ file.nil? &&
55
+ line.nil? &&
56
+ function.nil?
57
+ end
58
+
59
+ ##
60
+ # @private Exports the SourceLocation to a
61
+ # Google::Logging::V2::LogEntrySourceLocation object.
62
+ def to_grpc
63
+ return nil if empty?
64
+ Google::Logging::V2::LogEntrySourceLocation.new(
65
+ file: file.to_s,
66
+ line: line,
67
+ function: function.to_s
68
+ )
69
+ end
70
+
71
+ ##
72
+ # @private New Google::Cloud::Logging::Entry::SourceLocation from a
73
+ # Google::Logging::V2::LogEntrySourceLocation object.
74
+ def self.from_grpc grpc
75
+ return new if grpc.nil?
76
+ new.tap do |o|
77
+ o.file = grpc.file
78
+ o.line = grpc.line
79
+ o.function = grpc.function
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,155 @@
1
+ # Copyright 2017 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 "delegate"
17
+
18
+ module Google
19
+ module Cloud
20
+ module Logging
21
+ class Log
22
+ ##
23
+ # Log::List is a special case Array with additional values.
24
+ class List < DelegateClass(::Array)
25
+ ##
26
+ # If not empty, indicates that there are more records that match
27
+ # the request and this value should be passed to continue.
28
+ attr_accessor :token
29
+
30
+ ##
31
+ # @private Create a new Log::List with an array of log names.
32
+ def initialize arr = []
33
+ super arr
34
+ end
35
+
36
+ ##
37
+ # Whether there is a next page of logs.
38
+ #
39
+ # @return [Boolean]
40
+ #
41
+ # @example
42
+ # require "google/cloud/logging"
43
+ #
44
+ # logging = Google::Cloud::Logging.new
45
+ #
46
+ # logs = logging.logs
47
+ # if logs.next?
48
+ # next_logs = logs.next
49
+ # end
50
+ #
51
+ def next?
52
+ !token.nil?
53
+ end
54
+
55
+ ##
56
+ # Retrieve the next page of logs.
57
+ #
58
+ # @return [Log::List]
59
+ #
60
+ # @example
61
+ # require "google/cloud/logging"
62
+ #
63
+ # logging = Google::Cloud::Logging.new
64
+ #
65
+ # logs = logging.logs
66
+ # if logs.next?
67
+ # next_logs = logs.next
68
+ # end
69
+ #
70
+ def next
71
+ return nil unless next?
72
+ ensure_service!
73
+ grpc = @service.list_logs token: token, resource: @resource,
74
+ max: @max
75
+ self.class.from_grpc grpc, @service
76
+ end
77
+
78
+ ##
79
+ # Retrieves remaining results by repeatedly invoking {#next} until
80
+ # {#next?} returns `false`. Calls the given block once for each
81
+ # result, which is passed as the argument to the block.
82
+ #
83
+ # An Enumerator is returned if no block is given.
84
+ #
85
+ # This method will make repeated API calls until all remaining results
86
+ # are retrieved. (Unlike `#each`, for example, which merely iterates
87
+ # over the results returned by a single API call.) Use with caution.
88
+ #
89
+ # @param [Integer] request_limit The upper limit of API requests to
90
+ # make to load all log names. Default is no limit.
91
+ # @yield [log] The block for accessing each log name.
92
+ # @yieldparam [String] log The log name.
93
+ #
94
+ # @return [Enumerator]
95
+ #
96
+ # @example Iterating each log name by passing a block:
97
+ # require "google/cloud/logging"
98
+ #
99
+ # logging = Google::Cloud::Logging.new
100
+ # logs = logging.logs
101
+ #
102
+ # logs.all { |l| puts l }
103
+ #
104
+ # @example Limit the number of API calls made:
105
+ # require "google/cloud/logging"
106
+ #
107
+ # logging = Google::Cloud::Logging.new
108
+ # logs = logging.logs
109
+ #
110
+ # logs.all(request_limit: 10) { |l| puts l }
111
+ #
112
+ def all request_limit: nil
113
+ request_limit = request_limit.to_i if request_limit
114
+ unless block_given?
115
+ return enum_for(:all, request_limit: request_limit)
116
+ end
117
+ results = self
118
+ loop do
119
+ results.each { |r| yield r }
120
+ if request_limit
121
+ request_limit -= 1
122
+ break if request_limit < 0
123
+ end
124
+ break unless results.next?
125
+ results = results.next
126
+ end
127
+ end
128
+
129
+ ##
130
+ # @private New Log::List from a
131
+ # Google::Logging::V2::ListLogsResponse object.
132
+ def self.from_grpc grpc_list, service, resource: nil, max: nil
133
+ logs = new(Array(grpc_list.log_names))
134
+ token = grpc_list.next_page_token
135
+ token = nil if token == ""
136
+ logs.instance_variable_set "@token", token
137
+ logs.instance_variable_set "@service", service
138
+ logs.instance_variable_set "@resource", resource
139
+ logs.instance_variable_set "@max", max
140
+ logs
141
+ end
142
+
143
+ protected
144
+
145
+ ##
146
+ # @private Raise an error unless an active connection to the service
147
+ # is available.
148
+ def ensure_service!
149
+ fail "Must have active connection to service" unless @service
150
+ end
151
+ end
152
+ end
153
+ end
154
+ end
155
+ end
@@ -76,15 +76,15 @@ module Google
76
76
  end
77
77
 
78
78
  ##
79
- # Retrieves all metrics by repeatedly loading {#next} until {#next?}
80
- # returns `false`. Calls the given block once for each metric, which
81
- # is passed as the parameter.
79
+ # Retrieves remaining results by repeatedly invoking {#next} until
80
+ # {#next?} returns `false`. Calls the given block once for each
81
+ # result, which is passed as the argument to the block.
82
82
  #
83
83
  # An Enumerator is returned if no block is given.
84
84
  #
85
- # This method may make several API calls until all metrics are
86
- # retrieved. Be sure to use as narrow a search criteria as possible.
87
- # Please use with caution.
85
+ # This method will make repeated API calls until all remaining results
86
+ # are retrieved. (Unlike `#each`, for example, which merely iterates
87
+ # over the results returned by a single API call.) Use with caution.
88
88
  #
89
89
  # @param [Integer] request_limit The upper limit of API requests to
90
90
  # make to load all metrics. Default is no limit.