google-cloud-logging 1.10.7 → 2.2.0
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 +4 -4
- data/AUTHENTICATION.md +2 -1
- data/CHANGELOG.md +47 -0
- data/CONTRIBUTING.md +2 -2
- data/LOGGING.md +1 -1
- data/lib/google-cloud-logging.rb +15 -15
- data/lib/google/cloud/logging.rb +12 -13
- data/lib/google/cloud/logging/async_writer.rb +5 -4
- data/lib/google/cloud/logging/convert.rb +12 -7
- data/lib/google/cloud/logging/credentials.rb +2 -2
- data/lib/google/cloud/logging/entry.rb +5 -5
- data/lib/google/cloud/logging/entry/http_request.rb +5 -4
- data/lib/google/cloud/logging/entry/list.rb +4 -4
- data/lib/google/cloud/logging/entry/operation.rb +5 -4
- data/lib/google/cloud/logging/entry/source_location.rb +5 -4
- data/lib/google/cloud/logging/log/list.rb +4 -4
- data/lib/google/cloud/logging/logger.rb +7 -15
- data/lib/google/cloud/logging/metric.rb +2 -2
- data/lib/google/cloud/logging/metric/list.rb +4 -4
- data/lib/google/cloud/logging/middleware.rb +2 -2
- data/lib/google/cloud/logging/project.rb +1 -1
- data/lib/google/cloud/logging/rails.rb +7 -10
- data/lib/google/cloud/logging/resource_descriptor/list.rb +4 -4
- data/lib/google/cloud/logging/service.rb +73 -173
- data/lib/google/cloud/logging/sink.rb +2 -2
- data/lib/google/cloud/logging/sink/list.rb +4 -4
- data/lib/google/cloud/logging/version.rb +1 -1
- metadata +14 -84
- data/lib/google/cloud/logging/v2.rb +0 -18
- data/lib/google/cloud/logging/v2/config_service_v2_client.rb +0 -1368
- data/lib/google/cloud/logging/v2/config_service_v2_client_config.json +0 -106
- data/lib/google/cloud/logging/v2/credentials.rb +0 -39
- data/lib/google/cloud/logging/v2/doc/google/api/distribution.rb +0 -164
- data/lib/google/cloud/logging/v2/doc/google/api/label.rb +0 -42
- data/lib/google/cloud/logging/v2/doc/google/api/metric.rb +0 -233
- data/lib/google/cloud/logging/v2/doc/google/api/monitored_resource.rb +0 -85
- data/lib/google/cloud/logging/v2/doc/google/logging/type/http_request.rb +0 -86
- data/lib/google/cloud/logging/v2/doc/google/logging/v2/log_entry.rb +0 -179
- data/lib/google/cloud/logging/v2/doc/google/logging/v2/logging.rb +0 -238
- data/lib/google/cloud/logging/v2/doc/google/logging/v2/logging_config.rb +0 -660
- data/lib/google/cloud/logging/v2/doc/google/logging/v2/logging_metrics.rb +0 -220
- data/lib/google/cloud/logging/v2/doc/google/protobuf/any.rb +0 -131
- data/lib/google/cloud/logging/v2/doc/google/protobuf/duration.rb +0 -91
- data/lib/google/cloud/logging/v2/doc/google/protobuf/empty.rb +0 -29
- data/lib/google/cloud/logging/v2/doc/google/protobuf/field_mask.rb +0 -222
- data/lib/google/cloud/logging/v2/doc/google/protobuf/struct.rb +0 -74
- data/lib/google/cloud/logging/v2/doc/google/protobuf/timestamp.rb +0 -113
- data/lib/google/cloud/logging/v2/logging_service_v2_client.rb +0 -680
- data/lib/google/cloud/logging/v2/logging_service_v2_client_config.json +0 -61
- data/lib/google/cloud/logging/v2/metrics_service_v2_client.rb +0 -475
- data/lib/google/cloud/logging/v2/metrics_service_v2_client_config.json +0 -56
- data/lib/google/logging/v2/log_entry_pb.rb +0 -59
- data/lib/google/logging/v2/logging_config_pb.rb +0 -173
- data/lib/google/logging/v2/logging_config_services_pb.rb +0 -112
- data/lib/google/logging/v2/logging_metrics_pb.rb +0 -72
- data/lib/google/logging/v2/logging_metrics_services_pb.rb +0 -52
- data/lib/google/logging/v2/logging_pb.rb +0 -80
- data/lib/google/logging/v2/logging_services_pb.rb +0 -64
@@ -28,7 +28,8 @@ module Google
|
|
28
28
|
class SourceLocation
|
29
29
|
##
|
30
30
|
# @private Create an empty SourceLocation object.
|
31
|
-
def initialize
|
31
|
+
def initialize
|
32
|
+
end
|
32
33
|
|
33
34
|
##
|
34
35
|
# Source file name. Depending on the runtime environment, this might
|
@@ -57,10 +58,10 @@ module Google
|
|
57
58
|
|
58
59
|
##
|
59
60
|
# @private Exports the SourceLocation to a
|
60
|
-
# Google::Logging::V2::LogEntrySourceLocation object.
|
61
|
+
# Google::Cloud::Logging::V2::LogEntrySourceLocation object.
|
61
62
|
def to_grpc
|
62
63
|
return nil if empty?
|
63
|
-
Google::Logging::V2::LogEntrySourceLocation.new(
|
64
|
+
Google::Cloud::Logging::V2::LogEntrySourceLocation.new(
|
64
65
|
file: file.to_s,
|
65
66
|
line: line,
|
66
67
|
function: function.to_s
|
@@ -69,7 +70,7 @@ module Google
|
|
69
70
|
|
70
71
|
##
|
71
72
|
# @private New Google::Cloud::Logging::Entry::SourceLocation from a
|
72
|
-
# Google::Logging::V2::LogEntrySourceLocation object.
|
73
|
+
# Google::Cloud::Logging::V2::LogEntrySourceLocation object.
|
73
74
|
def self.from_grpc grpc
|
74
75
|
return new if grpc.nil?
|
75
76
|
new.tap do |o|
|
@@ -110,17 +110,17 @@ module Google
|
|
110
110
|
#
|
111
111
|
# logs.all(request_limit: 10) { |l| puts l }
|
112
112
|
#
|
113
|
-
def all request_limit: nil
|
113
|
+
def all request_limit: nil, &block
|
114
114
|
request_limit = request_limit.to_i if request_limit
|
115
115
|
unless block_given?
|
116
116
|
return enum_for :all, request_limit: request_limit
|
117
117
|
end
|
118
118
|
results = self
|
119
119
|
loop do
|
120
|
-
results.each
|
120
|
+
results.each(&block)
|
121
121
|
if request_limit
|
122
122
|
request_limit -= 1
|
123
|
-
break if request_limit
|
123
|
+
break if request_limit.negative?
|
124
124
|
end
|
125
125
|
break unless results.next?
|
126
126
|
results = results.next
|
@@ -129,7 +129,7 @@ module Google
|
|
129
129
|
|
130
130
|
##
|
131
131
|
# @private New Log::List from a
|
132
|
-
# Google::Logging::V2::ListLogsResponse object.
|
132
|
+
# Google::Cloud::Logging::V2::ListLogsResponse object.
|
133
133
|
def self.from_grpc grpc_list, service, resource: nil, max: nil
|
134
134
|
logs = new Array(grpc_list.log_names)
|
135
135
|
token = grpc_list.next_page_token
|
@@ -313,14 +313,8 @@ module Google
|
|
313
313
|
severity = derive_severity(severity) || ::Logger::UNKNOWN
|
314
314
|
return true if severity < @level
|
315
315
|
|
316
|
-
|
317
|
-
|
318
|
-
message = yield
|
319
|
-
else
|
320
|
-
message = progname
|
321
|
-
# progname = nil # TODO: Figure out what to do with the progname
|
322
|
-
end
|
323
|
-
end
|
316
|
+
message ||= block_given? ? yield : progname
|
317
|
+
# TODO: Figure out what to do with the progname
|
324
318
|
|
325
319
|
write_entry severity, message unless @closed
|
326
320
|
true
|
@@ -570,7 +564,7 @@ module Google
|
|
570
564
|
end
|
571
565
|
end
|
572
566
|
|
573
|
-
request_env = info
|
567
|
+
request_env = info&.env || {}
|
574
568
|
|
575
569
|
compute_labels(request_env).merge merged_labels
|
576
570
|
end
|
@@ -594,7 +588,7 @@ module Google
|
|
594
588
|
##
|
595
589
|
# @private Get Google Cloud deverity from logger level number.
|
596
590
|
def gcloud_severity severity_int
|
597
|
-
|
591
|
+
[:DEBUG, :INFO, :WARNING, :ERROR, :CRITICAL, :DEFAULT][severity_int]
|
598
592
|
rescue StandardError
|
599
593
|
:DEFAULT
|
600
594
|
end
|
@@ -610,11 +604,9 @@ module Google
|
|
610
604
|
##
|
611
605
|
# @private Compute values for labels
|
612
606
|
def compute_labels request_env
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
end
|
617
|
-
]
|
607
|
+
labels.to_h.transform_values do |value_or_proc|
|
608
|
+
compute_label_value request_env, value_or_proc
|
609
|
+
end
|
618
610
|
end
|
619
611
|
|
620
612
|
##
|
@@ -43,14 +43,14 @@ module Google
|
|
43
43
|
attr_accessor :service
|
44
44
|
|
45
45
|
##
|
46
|
-
# @private The gRPC Google::Logging::V2::LogMetric object.
|
46
|
+
# @private The gRPC Google::Cloud::Logging::V2::LogMetric object.
|
47
47
|
attr_accessor :grpc
|
48
48
|
|
49
49
|
##
|
50
50
|
# @private Create an empty Metric object.
|
51
51
|
def initialize
|
52
52
|
@service = nil
|
53
|
-
@grpc = Google::Logging::V2::LogMetric.new
|
53
|
+
@grpc = Google::Cloud::Logging::V2::LogMetric.new
|
54
54
|
end
|
55
55
|
|
56
56
|
##
|
@@ -123,17 +123,17 @@ module Google
|
|
123
123
|
# puts "#{metric.name}: #{metric.filter}"
|
124
124
|
# end
|
125
125
|
#
|
126
|
-
def all request_limit: nil
|
126
|
+
def all request_limit: nil, &block
|
127
127
|
request_limit = request_limit.to_i if request_limit
|
128
128
|
unless block_given?
|
129
129
|
return enum_for :all, request_limit: request_limit
|
130
130
|
end
|
131
131
|
results = self
|
132
132
|
loop do
|
133
|
-
results.each
|
133
|
+
results.each(&block)
|
134
134
|
if request_limit
|
135
135
|
request_limit -= 1
|
136
|
-
break if request_limit
|
136
|
+
break if request_limit.negative?
|
137
137
|
end
|
138
138
|
break unless results.next?
|
139
139
|
results = results.next
|
@@ -142,7 +142,7 @@ module Google
|
|
142
142
|
|
143
143
|
##
|
144
144
|
# @private New Metric::List from a
|
145
|
-
# Google::Logging::V2::ListLogMetricsResponse object.
|
145
|
+
# Google::Cloud::Logging::V2::ListLogMetricsResponse object.
|
146
146
|
def self.from_grpc grpc_list, service, max = nil
|
147
147
|
metrics = new(Array(grpc_list.metrics).map do |grpc_metric|
|
148
148
|
Metric.from_grpc grpc_metric, service
|
@@ -57,7 +57,7 @@ module Google
|
|
57
57
|
def initialize app, logger: nil, on_init: nil, **kwargs
|
58
58
|
@app = app
|
59
59
|
|
60
|
-
load_config
|
60
|
+
load_config(**kwargs)
|
61
61
|
|
62
62
|
logger ||= Middleware.logger
|
63
63
|
logger ||= begin
|
@@ -71,7 +71,7 @@ module Google
|
|
71
71
|
Middleware.logger = logging.logger log_name, resource
|
72
72
|
end
|
73
73
|
|
74
|
-
on_init
|
74
|
+
on_init&.call
|
75
75
|
|
76
76
|
@logger = logger
|
77
77
|
end
|
@@ -357,7 +357,7 @@ module Google
|
|
357
357
|
# resource: resource,
|
358
358
|
# labels: labels
|
359
359
|
#
|
360
|
-
def async_writer max_batch_count:
|
360
|
+
def async_writer max_batch_count: 10_000, max_batch_bytes: 10_000_000,
|
361
361
|
max_queue_size: 100, interval: 5, threads: 10,
|
362
362
|
partial_success: false
|
363
363
|
|
@@ -158,7 +158,7 @@ module Google
|
|
158
158
|
##
|
159
159
|
# @private Merge Rails configuration into Logging instrumentation
|
160
160
|
# configuration.
|
161
|
-
def self.merge_rails_config rails_config
|
161
|
+
def self.merge_rails_config rails_config
|
162
162
|
gcp_config = rails_config.google_cloud
|
163
163
|
log_config = gcp_config.logging
|
164
164
|
|
@@ -175,13 +175,10 @@ module Google
|
|
175
175
|
config.log_name ||= log_config.log_name
|
176
176
|
config.labels ||= log_config.labels
|
177
177
|
config.log_name_map ||= log_config.log_name_map
|
178
|
-
config.monitored_resource.type ||=
|
179
|
-
|
180
|
-
config.monitored_resource.labels ||=
|
181
|
-
log_config.monitored_resource.labels.to_h
|
178
|
+
config.monitored_resource.type ||= log_config.monitored_resource.type
|
179
|
+
config.monitored_resource.labels ||= log_config.monitored_resource.labels.to_h
|
182
180
|
if config.set_default_logger_on_rails_init.nil?
|
183
|
-
config.set_default_logger_on_rails_init =
|
184
|
-
log_config.set_default_logger_on_rails_init
|
181
|
+
config.set_default_logger_on_rails_init = log_config.set_default_logger_on_rails_init
|
185
182
|
end
|
186
183
|
end
|
187
184
|
end
|
@@ -206,15 +203,15 @@ module Google
|
|
206
203
|
# if credentials is not a Credentials object, create one
|
207
204
|
Logging::Credentials.new credentials
|
208
205
|
end
|
209
|
-
rescue Exception => e
|
210
|
-
|
206
|
+
rescue Exception => e # rubocop:disable Lint/RescueException
|
207
|
+
$stdout.puts "Note: Google::Cloud::Logging is disabled because " \
|
211
208
|
"it failed to authorize with the service. (#{e.message}) " \
|
212
209
|
"Falling back to the default Rails logger."
|
213
210
|
return false
|
214
211
|
end
|
215
212
|
|
216
213
|
if project_id.to_s.empty?
|
217
|
-
|
214
|
+
$stdout.puts "Note: Google::Cloud::Logging is disabled because " \
|
218
215
|
"the project ID could not be determined. " \
|
219
216
|
"Falling back to the default Rails logger."
|
220
217
|
return false
|
@@ -128,17 +128,17 @@ module Google
|
|
128
128
|
# puts rd.type
|
129
129
|
# end
|
130
130
|
#
|
131
|
-
def all request_limit: nil
|
131
|
+
def all request_limit: nil, &block
|
132
132
|
request_limit = request_limit.to_i if request_limit
|
133
133
|
unless block_given?
|
134
134
|
return enum_for :all, request_limit: request_limit
|
135
135
|
end
|
136
136
|
results = self
|
137
137
|
loop do
|
138
|
-
results.each
|
138
|
+
results.each(&block)
|
139
139
|
if request_limit
|
140
140
|
request_limit -= 1
|
141
|
-
break if request_limit
|
141
|
+
break if request_limit.negative?
|
142
142
|
end
|
143
143
|
break unless results.next?
|
144
144
|
results = results.next
|
@@ -147,7 +147,7 @@ module Google
|
|
147
147
|
|
148
148
|
##
|
149
149
|
# @private New ResourceDescriptor::List from a
|
150
|
-
# Google::Logging::V2::ListMonitoredResourceDescriptorsResponse
|
150
|
+
# Google::Cloud::Logging::V2::ListMonitoredResourceDescriptorsResponse
|
151
151
|
# object.
|
152
152
|
def self.from_grpc grpc_list, service, max = nil
|
153
153
|
rds = new(Array(grpc_list.resource_descriptors).map do |grpc|
|
@@ -16,7 +16,6 @@
|
|
16
16
|
require "google/cloud/errors"
|
17
17
|
require "google/cloud/logging/version"
|
18
18
|
require "google/cloud/logging/v2"
|
19
|
-
require "google/gax/errors"
|
20
19
|
require "uri"
|
21
20
|
|
22
21
|
module Google
|
@@ -26,61 +25,59 @@ module Google
|
|
26
25
|
# @private Represents the gRPC Logging service, including all the API
|
27
26
|
# methods.
|
28
27
|
class Service
|
29
|
-
attr_accessor :project
|
28
|
+
attr_accessor :project
|
29
|
+
attr_accessor :credentials
|
30
|
+
attr_accessor :timeout
|
31
|
+
attr_accessor :host
|
30
32
|
|
31
33
|
##
|
32
34
|
# Creates a new Service instance.
|
33
|
-
def initialize project, credentials, timeout: nil,
|
34
|
-
host: nil
|
35
|
+
def initialize project, credentials, timeout: nil, host: nil
|
35
36
|
@project = project
|
36
37
|
@credentials = credentials
|
37
38
|
@timeout = timeout
|
38
|
-
@
|
39
|
-
@host = host || V2::LoggingServiceV2Client::SERVICE_ADDRESS
|
39
|
+
@host = host
|
40
40
|
end
|
41
41
|
|
42
42
|
def logging
|
43
43
|
return mocked_logging if mocked_logging
|
44
44
|
@logging ||= \
|
45
|
-
V2::
|
46
|
-
credentials
|
47
|
-
timeout
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
)
|
45
|
+
V2::LoggingService::Client.new do |config|
|
46
|
+
config.credentials = credentials if credentials
|
47
|
+
config.timeout = timeout if timeout
|
48
|
+
config.endpoint = host if host
|
49
|
+
config.lib_name = "gccl"
|
50
|
+
config.lib_version = Google::Cloud::Logging::VERSION
|
51
|
+
config.metadata = { "google-cloud-resource-prefix" => "projects/#{@project}" }
|
52
|
+
end
|
54
53
|
end
|
55
54
|
attr_accessor :mocked_logging
|
56
55
|
|
57
56
|
def sinks
|
58
57
|
return mocked_sinks if mocked_sinks
|
59
58
|
@sinks ||= \
|
60
|
-
V2::
|
61
|
-
credentials
|
62
|
-
timeout
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
)
|
59
|
+
V2::ConfigService::Client.new do |config|
|
60
|
+
config.credentials = credentials if credentials
|
61
|
+
config.timeout = timeout if timeout
|
62
|
+
config.endpoint = host if host
|
63
|
+
config.lib_name = "gccl"
|
64
|
+
config.lib_version = Google::Cloud::Logging::VERSION
|
65
|
+
config.metadata = { "google-cloud-resource-prefix" => "projects/#{@project}" }
|
66
|
+
end
|
69
67
|
end
|
70
68
|
attr_accessor :mocked_sinks
|
71
69
|
|
72
70
|
def metrics
|
73
71
|
return mocked_metrics if mocked_metrics
|
74
72
|
@metrics ||= \
|
75
|
-
V2::
|
76
|
-
credentials
|
77
|
-
timeout
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
)
|
73
|
+
V2::MetricsService::Client.new do |config|
|
74
|
+
config.credentials = credentials if credentials
|
75
|
+
config.timeout = timeout if timeout
|
76
|
+
config.endpoint = host if host
|
77
|
+
config.lib_name = "gccl"
|
78
|
+
config.lib_version = Google::Cloud::Logging::VERSION
|
79
|
+
config.metadata = { "google-cloud-resource-prefix" => "projects/#{@project}" }
|
80
|
+
end
|
84
81
|
end
|
85
82
|
attr_accessor :mocked_metrics
|
86
83
|
|
@@ -90,20 +87,12 @@ module Google
|
|
90
87
|
project_ids = Array(projects).map { |p| "projects/#{p}" }
|
91
88
|
resource_names = Array(resources) + project_ids
|
92
89
|
resource_names = ["projects/#{@project}"] if resource_names.empty?
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
end
|
100
|
-
|
101
|
-
execute do
|
102
|
-
paged_enum = logging.list_log_entries \
|
103
|
-
resource_names, filter: filter, order_by: order, page_size: max,
|
104
|
-
options: call_opts
|
105
|
-
paged_enum.page.response
|
106
|
-
end
|
90
|
+
paged_enum = logging.list_log_entries resource_names: resource_names,
|
91
|
+
filter: filter,
|
92
|
+
order_by: order,
|
93
|
+
page_size: max,
|
94
|
+
page_token: token
|
95
|
+
paged_enum.response
|
107
96
|
end
|
108
97
|
|
109
98
|
def write_entries entries, log_name: nil, resource: nil, labels: nil,
|
@@ -114,157 +103,93 @@ module Google
|
|
114
103
|
end
|
115
104
|
resource = resource.to_grpc if resource
|
116
105
|
labels = Hash[labels.map { |k, v| [String(k), String(v)] }] if labels
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
partial_success: partial_success,
|
123
|
-
options: default_options
|
124
|
-
end
|
106
|
+
logging.write_log_entries entries: entries,
|
107
|
+
log_name: log_path(log_name),
|
108
|
+
resource: resource,
|
109
|
+
labels: labels,
|
110
|
+
partial_success: partial_success
|
125
111
|
end
|
126
112
|
|
127
113
|
def list_logs resource: nil, token: nil, max: nil
|
128
114
|
parent = resource || "projects/#{@project}"
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
page_token: token
|
134
|
-
)
|
135
|
-
end
|
136
|
-
|
137
|
-
execute do
|
138
|
-
paged_enum = logging.list_logs parent, page_size: max,
|
139
|
-
options: call_opts
|
140
|
-
paged_enum.page.response
|
141
|
-
end
|
115
|
+
paged_enum = logging.list_logs parent: parent,
|
116
|
+
page_size: max,
|
117
|
+
page_token: token
|
118
|
+
paged_enum.response
|
142
119
|
end
|
143
120
|
|
144
121
|
def delete_log name
|
145
|
-
|
146
|
-
logging.delete_log log_path(name), options: default_options
|
147
|
-
end
|
122
|
+
logging.delete_log log_name: log_path(name)
|
148
123
|
end
|
149
124
|
|
150
125
|
def list_resource_descriptors token: nil, max: nil
|
151
|
-
|
152
|
-
if token
|
153
|
-
call_opts = Google::Gax::CallOptions.new(
|
154
|
-
kwargs: default_headers,
|
155
|
-
page_token: token
|
156
|
-
)
|
157
|
-
end
|
158
|
-
|
159
|
-
execute do
|
160
|
-
logging.list_monitored_resource_descriptors \
|
161
|
-
page_size: max, options: call_opts
|
162
|
-
end
|
126
|
+
logging.list_monitored_resource_descriptors page_size: max, page_token: token
|
163
127
|
end
|
164
128
|
|
165
129
|
def list_sinks token: nil, max: nil
|
166
|
-
|
167
|
-
|
168
|
-
call_opts = Google::Gax::CallOptions.new(
|
169
|
-
kwargs: default_headers,
|
170
|
-
page_token: token
|
171
|
-
)
|
172
|
-
end
|
173
|
-
|
174
|
-
execute do
|
175
|
-
paged_enum = sinks.list_sinks \
|
176
|
-
project_path, page_size: max, options: call_opts
|
177
|
-
paged_enum.page.response
|
178
|
-
end
|
130
|
+
paged_enum = sinks.list_sinks parent: project_path, page_size: max, page_token: token
|
131
|
+
paged_enum.response
|
179
132
|
end
|
180
133
|
|
181
134
|
def create_sink name, destination, filter, unique_writer_identity: nil
|
182
|
-
sink = Google::Logging::V2::LogSink.new(
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
end
|
135
|
+
sink = Google::Cloud::Logging::V2::LogSink.new(
|
136
|
+
{
|
137
|
+
name: name, destination: destination, filter: filter
|
138
|
+
}.delete_if { |_, v| v.nil? }
|
139
|
+
)
|
140
|
+
sinks.create_sink parent: project_path,
|
141
|
+
sink: sink,
|
142
|
+
unique_writer_identity: unique_writer_identity
|
191
143
|
end
|
192
144
|
|
193
145
|
def get_sink name
|
194
|
-
|
146
|
+
sinks.get_sink sink_name: sink_path(name)
|
195
147
|
end
|
196
148
|
|
197
149
|
def update_sink name, destination, filter, unique_writer_identity: nil
|
198
|
-
sink = Google::Logging::V2::LogSink.new(
|
150
|
+
sink = Google::Cloud::Logging::V2::LogSink.new(
|
199
151
|
{
|
200
152
|
name: name, destination: destination, filter: filter
|
201
153
|
}.delete_if { |_, v| v.nil? }
|
202
154
|
)
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
unique_writer_identity: unique_writer_identity,
|
207
|
-
options: default_options
|
208
|
-
end
|
155
|
+
sinks.update_sink sink_name: sink_path(name),
|
156
|
+
sink: sink,
|
157
|
+
unique_writer_identity: unique_writer_identity
|
209
158
|
end
|
210
159
|
|
211
160
|
def delete_sink name
|
212
|
-
|
213
|
-
sinks.delete_sink sink_path(name), options: default_options
|
214
|
-
end
|
161
|
+
sinks.delete_sink sink_name: sink_path(name)
|
215
162
|
end
|
216
163
|
|
217
164
|
def list_metrics token: nil, max: nil
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
page_token: token
|
223
|
-
)
|
224
|
-
end
|
225
|
-
|
226
|
-
execute do
|
227
|
-
paged_enum = metrics.list_log_metrics \
|
228
|
-
project_path, page_size: max, options: call_opts
|
229
|
-
paged_enum.page.response
|
230
|
-
end
|
165
|
+
paged_enum = metrics.list_log_metrics parent: project_path,
|
166
|
+
page_size: max,
|
167
|
+
page_token: token
|
168
|
+
paged_enum.response
|
231
169
|
end
|
232
170
|
|
233
171
|
def create_metric name, filter, description
|
234
|
-
metric = Google::Logging::V2::LogMetric.new(
|
172
|
+
metric = Google::Cloud::Logging::V2::LogMetric.new(
|
235
173
|
{ name: name, description: description,
|
236
174
|
filter: filter }.delete_if { |_, v| v.nil? }
|
237
175
|
)
|
238
|
-
|
239
|
-
execute do
|
240
|
-
metrics.create_log_metric project_path, metric,
|
241
|
-
options: default_options
|
242
|
-
end
|
176
|
+
metrics.create_log_metric parent: project_path, metric: metric
|
243
177
|
end
|
244
178
|
|
245
179
|
def get_metric name
|
246
|
-
|
247
|
-
metrics.get_log_metric metric_path(name), options: default_options
|
248
|
-
end
|
180
|
+
metrics.get_log_metric metric_name: metric_path(name)
|
249
181
|
end
|
250
182
|
|
251
183
|
def update_metric name, description, filter
|
252
|
-
metric = Google::Logging::V2::LogMetric.new(
|
184
|
+
metric = Google::Cloud::Logging::V2::LogMetric.new(
|
253
185
|
{ name: name, description: description,
|
254
186
|
filter: filter }.delete_if { |_, v| v.nil? }
|
255
187
|
)
|
256
|
-
|
257
|
-
execute do
|
258
|
-
metrics.update_log_metric metric_path(name), metric,
|
259
|
-
options: default_options
|
260
|
-
end
|
188
|
+
metrics.update_log_metric metric_name: metric_path(name), metric: metric
|
261
189
|
end
|
262
190
|
|
263
191
|
def delete_metric name
|
264
|
-
|
265
|
-
metrics.delete_log_metric metric_path(name),
|
266
|
-
options: default_options
|
267
|
-
end
|
192
|
+
metrics.delete_log_metric metric_name: metric_path(name)
|
268
193
|
end
|
269
194
|
|
270
195
|
def log_path log_name
|
@@ -280,16 +205,6 @@ module Google
|
|
280
205
|
|
281
206
|
protected
|
282
207
|
|
283
|
-
def service_address
|
284
|
-
return nil if host.nil?
|
285
|
-
URI.parse("//#{host}").host
|
286
|
-
end
|
287
|
-
|
288
|
-
def service_port
|
289
|
-
return nil if host.nil?
|
290
|
-
URI.parse("//#{host}").port
|
291
|
-
end
|
292
|
-
|
293
208
|
def project_path
|
294
209
|
"projects/#{@project}"
|
295
210
|
end
|
@@ -304,14 +219,6 @@ module Google
|
|
304
219
|
"#{project_path}/metrics/#{metric_name}"
|
305
220
|
end
|
306
221
|
|
307
|
-
def default_headers
|
308
|
-
{ "google-cloud-resource-prefix" => "projects/#{@project}" }
|
309
|
-
end
|
310
|
-
|
311
|
-
def default_options
|
312
|
-
Google::Gax::CallOptions.new kwargs: default_headers
|
313
|
-
end
|
314
|
-
|
315
222
|
##
|
316
223
|
# @private Get a Google::Protobuf::Timestamp object from a Time object.
|
317
224
|
def time_to_timestamp time
|
@@ -329,13 +236,6 @@ module Google
|
|
329
236
|
# Time.at takes microseconds, so convert nano seconds to microseconds
|
330
237
|
Time.at timestamp.seconds, Rational(timestamp.nanos, 1000)
|
331
238
|
end
|
332
|
-
|
333
|
-
def execute
|
334
|
-
yield
|
335
|
-
rescue Google::Gax::GaxError => e
|
336
|
-
# GaxError wraps BadStatus, but exposes it as #cause
|
337
|
-
raise Google::Cloud::Error.from_error(e.cause)
|
338
|
-
end
|
339
239
|
end
|
340
240
|
end
|
341
241
|
end
|