google-cloud-logging 0.20.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/google-cloud-logging.rb +119 -0
- data/lib/google/cloud/logging.rb +293 -0
- data/lib/google/cloud/logging/credentials.rb +31 -0
- data/lib/google/cloud/logging/entry.rb +469 -0
- data/lib/google/cloud/logging/entry/http_request.rb +145 -0
- data/lib/google/cloud/logging/entry/list.rb +180 -0
- data/lib/google/cloud/logging/entry/operation.rb +92 -0
- data/lib/google/cloud/logging/logger.rb +309 -0
- data/lib/google/cloud/logging/metric.rb +172 -0
- data/lib/google/cloud/logging/metric/list.rb +175 -0
- data/lib/google/cloud/logging/project.rb +650 -0
- data/lib/google/cloud/logging/resource.rb +86 -0
- data/lib/google/cloud/logging/resource_descriptor.rb +139 -0
- data/lib/google/cloud/logging/resource_descriptor/list.rb +179 -0
- data/lib/google/cloud/logging/service.rb +270 -0
- data/lib/google/cloud/logging/sink.rb +230 -0
- data/lib/google/cloud/logging/sink/list.rb +173 -0
- data/lib/google/cloud/logging/v2.rb +17 -0
- data/lib/google/cloud/logging/v2/config_service_v2_api.rb +331 -0
- data/lib/google/cloud/logging/v2/config_service_v2_client_config.json +53 -0
- data/lib/google/cloud/logging/v2/logging_service_v2_api.rb +351 -0
- data/lib/google/cloud/logging/v2/logging_service_v2_client_config.json +57 -0
- data/lib/google/cloud/logging/v2/metrics_service_v2_api.rb +330 -0
- data/lib/google/cloud/logging/v2/metrics_service_v2_client_config.json +53 -0
- data/lib/google/cloud/logging/version.rb +22 -0
- data/lib/google/logging/v2/log_entry_pb.rb +44 -0
- data/lib/google/logging/v2/logging_config_pb.rb +59 -0
- data/lib/google/logging/v2/logging_config_services_pb.rb +52 -0
- data/lib/google/logging/v2/logging_metrics_pb.rb +51 -0
- data/lib/google/logging/v2/logging_metrics_services_pb.rb +51 -0
- data/lib/google/logging/v2/logging_pb.rb +59 -0
- data/lib/google/logging/v2/logging_services_pb.rb +56 -0
- metadata +260 -0
@@ -0,0 +1,230 @@
|
|
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/sink/list"
|
17
|
+
|
18
|
+
module Google
|
19
|
+
module Cloud
|
20
|
+
module Logging
|
21
|
+
##
|
22
|
+
# # Sink
|
23
|
+
#
|
24
|
+
# Used to export log entries outside Stackdriver Logging. When you create
|
25
|
+
# a sink, new log entries are exported. Stackdriver Logging does not send
|
26
|
+
# previously-ingested log entries to the sink's destination.
|
27
|
+
#
|
28
|
+
# Before creating the sink, ensure that you have granted
|
29
|
+
# `cloud-logs@google.com` permission to write logs to the destination. See
|
30
|
+
# [Permissions for writing exported
|
31
|
+
# logs](https://cloud.google.com/logging/docs/export/configure_export#setting_product_name_short_permissions_for_writing_exported_logs).
|
32
|
+
#
|
33
|
+
# You can retrieve an existing sink with {Project#sink}.
|
34
|
+
#
|
35
|
+
# @see https://cloud.google.com/logging/docs/api/tasks/exporting-logs
|
36
|
+
# Exporting Logs With Sinks
|
37
|
+
# @see https://cloud.google.com/logging/docs/api/introduction_v2#kinds_of_log_sinks
|
38
|
+
# Kinds of log sinks (API V2)
|
39
|
+
# @see https://cloud.google.com/logging/docs/api/#sinks Sinks (API V1)
|
40
|
+
# @see https://cloud.google.com/logging/docs/export/configure_export#setting_product_name_short_permissions_for_writing_exported_logs
|
41
|
+
# Permissions for writing exported logs
|
42
|
+
#
|
43
|
+
# @example
|
44
|
+
# require "google/cloud"
|
45
|
+
#
|
46
|
+
# gcloud = Google::Cloud.new
|
47
|
+
# logging = gcloud.logging
|
48
|
+
# storage = gcloud.storage
|
49
|
+
#
|
50
|
+
# bucket = storage.create_bucket "my-logs-bucket"
|
51
|
+
#
|
52
|
+
# # Grant owner permission to Stackdriver Logging service
|
53
|
+
# email = "cloud-logs@google.com"
|
54
|
+
# bucket.acl.add_owner "group-#{email}"
|
55
|
+
#
|
56
|
+
# sink = logging.create_sink "my-sink",
|
57
|
+
# "storage.googleapis.com/#{bucket.id}"
|
58
|
+
#
|
59
|
+
class Sink
|
60
|
+
##
|
61
|
+
# @private The gRPC Service object.
|
62
|
+
attr_accessor :service
|
63
|
+
|
64
|
+
##
|
65
|
+
# @private The Google API Client object.
|
66
|
+
attr_accessor :grpc
|
67
|
+
|
68
|
+
##
|
69
|
+
# @private Create an empty Sink object.
|
70
|
+
def initialize
|
71
|
+
@service = nil
|
72
|
+
@grpc = Google::Logging::V2::LogSink.new
|
73
|
+
end
|
74
|
+
|
75
|
+
##
|
76
|
+
# The client-assigned sink identifier. Sink identifiers are limited to
|
77
|
+
# 1000 characters and can include only the following characters: `A-Z`,
|
78
|
+
# `a-z`, `0-9`, and the special characters `_-.`.
|
79
|
+
def name
|
80
|
+
@grpc.name
|
81
|
+
end
|
82
|
+
|
83
|
+
##
|
84
|
+
# The export destination. See [Exporting Logs With
|
85
|
+
# Sinks](https://cloud.google.com/logging/docs/api/tasks/exporting-logs).
|
86
|
+
def destination
|
87
|
+
@grpc.destination
|
88
|
+
end
|
89
|
+
|
90
|
+
##
|
91
|
+
# Updates the export destination. See [Exporting Logs With
|
92
|
+
# Sinks](https://cloud.google.com/logging/docs/api/tasks/exporting-logs).
|
93
|
+
def destination= destination
|
94
|
+
@grpc.destination = destination
|
95
|
+
end
|
96
|
+
|
97
|
+
##
|
98
|
+
# An [advanced logs
|
99
|
+
# filter](https://cloud.google.com/logging/docs/view/advanced_filters)
|
100
|
+
# that defines the log entries to be exported. The filter must be
|
101
|
+
# consistent with the log entry format designed by the `version`
|
102
|
+
# parameter, regardless of the format of the log entry that was
|
103
|
+
# originally written to Stackdriver Logging.
|
104
|
+
def filter
|
105
|
+
@grpc.filter
|
106
|
+
end
|
107
|
+
|
108
|
+
##
|
109
|
+
# Updates the [advanced logs
|
110
|
+
# filter](https://cloud.google.com/logging/docs/view/advanced_filters)
|
111
|
+
# that defines the log entries to be exported. The filter must be
|
112
|
+
# consistent with the log entry format designed by the `version`
|
113
|
+
# parameter, regardless of the format of the log entry that was
|
114
|
+
# originally written to Stackdriver Logging.
|
115
|
+
def filter= filter
|
116
|
+
@grpc.filter = filter
|
117
|
+
end
|
118
|
+
|
119
|
+
##
|
120
|
+
# The log entry version used when exporting log entries from this sink.
|
121
|
+
# This version does not have to correspond to the version of the log
|
122
|
+
# entry when it was written to Stackdriver Logging.
|
123
|
+
def version
|
124
|
+
@grpc.output_version_format
|
125
|
+
end
|
126
|
+
|
127
|
+
##
|
128
|
+
# Updates the log entry version used when exporting log entries from
|
129
|
+
# this sink. This version does not have to correspond to the version of
|
130
|
+
# the log entry when it was written to Stackdriver Logging. Accepted
|
131
|
+
# values are `:VERSION_FORMAT_UNSPECIFIED`, `:V2`, and `:V1`.
|
132
|
+
def version= version
|
133
|
+
@grpc.output_version_format = self.class.resolve_version(version)
|
134
|
+
end
|
135
|
+
|
136
|
+
##
|
137
|
+
# Helper to determine if the sink's version is
|
138
|
+
# `VERSION_FORMAT_UNSPECIFIED`.
|
139
|
+
def unspecified?
|
140
|
+
!(v1? || v2?)
|
141
|
+
end
|
142
|
+
|
143
|
+
##
|
144
|
+
# Helper to determine if the sink's version is `V2`.
|
145
|
+
def v2?
|
146
|
+
version == :V2
|
147
|
+
end
|
148
|
+
|
149
|
+
##
|
150
|
+
# Helper to determine if the sink's version is `V1`.
|
151
|
+
def v1?
|
152
|
+
version == :V1
|
153
|
+
end
|
154
|
+
|
155
|
+
##
|
156
|
+
# Updates the logs-based sink.
|
157
|
+
#
|
158
|
+
# @example
|
159
|
+
# require "google/cloud"
|
160
|
+
#
|
161
|
+
# gcloud = Google::Cloud.new
|
162
|
+
# logging = gcloud.logging
|
163
|
+
# sink = logging.sink "severe_errors"
|
164
|
+
# sink.filter = "logName:syslog AND severity>=ERROR"
|
165
|
+
# sink.save
|
166
|
+
#
|
167
|
+
def save
|
168
|
+
ensure_service!
|
169
|
+
@grpc = service.update_sink name, destination, filter, version
|
170
|
+
end
|
171
|
+
|
172
|
+
##
|
173
|
+
# Reloads the logs-based sink with current data from the Logging
|
174
|
+
# service.
|
175
|
+
def reload!
|
176
|
+
ensure_service!
|
177
|
+
@grpc = service.get_sink name
|
178
|
+
end
|
179
|
+
alias_method :refresh!, :reload!
|
180
|
+
|
181
|
+
##
|
182
|
+
# Permanently deletes the logs-based sink.
|
183
|
+
#
|
184
|
+
# @return [Boolean] Returns `true` if the sink was deleted.
|
185
|
+
#
|
186
|
+
# @example
|
187
|
+
# require "google/cloud"
|
188
|
+
#
|
189
|
+
# gcloud = Google::Cloud.new
|
190
|
+
# logging = gcloud.logging
|
191
|
+
# sink = logging.sink "severe_errors"
|
192
|
+
# sink.delete
|
193
|
+
#
|
194
|
+
def delete
|
195
|
+
ensure_service!
|
196
|
+
service.delete_sink name
|
197
|
+
true
|
198
|
+
end
|
199
|
+
|
200
|
+
##
|
201
|
+
# @private New Sink from a Google::Logging::V2::LogSink object.
|
202
|
+
def self.from_grpc grpc, service
|
203
|
+
new.tap do |f|
|
204
|
+
f.grpc = grpc
|
205
|
+
f.service = service
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
##
|
210
|
+
# @private Convert a version value to the gRPC enum value.
|
211
|
+
def self.resolve_version version
|
212
|
+
ver = version.to_s.upcase.to_sym
|
213
|
+
ver = Google::Logging::V2::LogSink::VersionFormat.resolve ver
|
214
|
+
return ver if ver
|
215
|
+
Google::Logging::V2::LogSink::VersionFormat:: \
|
216
|
+
VERSION_FORMAT_UNSPECIFIED
|
217
|
+
end
|
218
|
+
|
219
|
+
protected
|
220
|
+
|
221
|
+
##
|
222
|
+
# @private Raise an error unless an active connection to the service is
|
223
|
+
# available.
|
224
|
+
def ensure_service!
|
225
|
+
fail "Must have active connection to service" unless service
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
@@ -0,0 +1,173 @@
|
|
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 "delegate"
|
17
|
+
|
18
|
+
module Google
|
19
|
+
module Cloud
|
20
|
+
module Logging
|
21
|
+
class Sink
|
22
|
+
##
|
23
|
+
# Sink::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 Sink::List with an array of Sink instances.
|
32
|
+
def initialize arr = []
|
33
|
+
super arr
|
34
|
+
end
|
35
|
+
|
36
|
+
##
|
37
|
+
# Whether there is a next page of sinks.
|
38
|
+
#
|
39
|
+
# @return [Boolean]
|
40
|
+
#
|
41
|
+
# @example
|
42
|
+
# require "google/cloud"
|
43
|
+
#
|
44
|
+
# gcloud = Google::Cloud.new
|
45
|
+
# logging = gcloud.logging
|
46
|
+
#
|
47
|
+
# sinks = logging.sinks
|
48
|
+
# if sinks.next?
|
49
|
+
# next_sinks = sinks.next
|
50
|
+
# end
|
51
|
+
#
|
52
|
+
def next?
|
53
|
+
!token.nil?
|
54
|
+
end
|
55
|
+
|
56
|
+
##
|
57
|
+
# Retrieve the next page of sinks.
|
58
|
+
#
|
59
|
+
# @return [Sink::List]
|
60
|
+
#
|
61
|
+
# @example
|
62
|
+
# require "google/cloud"
|
63
|
+
#
|
64
|
+
# gcloud = Google::Cloud.new
|
65
|
+
# logging = gcloud.logging
|
66
|
+
#
|
67
|
+
# sinks = dataset.sinks
|
68
|
+
# if sinks.next?
|
69
|
+
# next_sinks = sinks.next
|
70
|
+
# end
|
71
|
+
#
|
72
|
+
def next
|
73
|
+
return nil unless next?
|
74
|
+
ensure_service!
|
75
|
+
list_grpc = @service.list_sinks token: token, max: @max
|
76
|
+
self.class.from_grpc list_grpc, @service
|
77
|
+
end
|
78
|
+
|
79
|
+
##
|
80
|
+
# Retrieves all sinks by repeatedly loading {#next} until {#next?}
|
81
|
+
# returns `false`. Calls the given block once for each sink, which is
|
82
|
+
# passed as the parameter.
|
83
|
+
#
|
84
|
+
# An Enumerator is returned if no block is given.
|
85
|
+
#
|
86
|
+
# This method may make several API calls until all sinks are
|
87
|
+
# retrieved. Be sure to use as narrow a search criteria as possible.
|
88
|
+
# Please use with caution.
|
89
|
+
#
|
90
|
+
# @param [Integer] request_limit The upper limit of API requests to
|
91
|
+
# make to load all sinks. Default is no limit.
|
92
|
+
# @yield [sink] The block for accessing each sink.
|
93
|
+
# @yieldparam [Sink] sink The sink object.
|
94
|
+
#
|
95
|
+
# @return [Enumerator]
|
96
|
+
#
|
97
|
+
# @example Iterating each sink by passing a block:
|
98
|
+
# require "google/cloud"
|
99
|
+
#
|
100
|
+
# gcloud = Google::Cloud.new
|
101
|
+
# logging = gcloud.logging
|
102
|
+
# sinks = logging.sinks
|
103
|
+
#
|
104
|
+
# sinks.all do |sink|
|
105
|
+
# puts "#{sink.name}: #{sink.filter} -> #{sink.destination}"
|
106
|
+
# end
|
107
|
+
#
|
108
|
+
# @example Using the enumerator by not passing a block:
|
109
|
+
# require "google/cloud"
|
110
|
+
#
|
111
|
+
# gcloud = Google::Cloud.new
|
112
|
+
# logging = gcloud.logging
|
113
|
+
# sinks = logging.sinks
|
114
|
+
#
|
115
|
+
# all_names = sinks.all.map do |sink|
|
116
|
+
# sink.name
|
117
|
+
# end
|
118
|
+
#
|
119
|
+
# @example Limit the number of API calls made:
|
120
|
+
# require "google/cloud"
|
121
|
+
#
|
122
|
+
# gcloud = Google::Cloud.new
|
123
|
+
# logging = gcloud.logging
|
124
|
+
# sinks = logging.sinks
|
125
|
+
#
|
126
|
+
# sinks.all(request_limit: 10) do |sink|
|
127
|
+
# puts "#{sink.name}: #{sink.filter} -> #{sink.destination}"
|
128
|
+
# end
|
129
|
+
#
|
130
|
+
def all request_limit: nil
|
131
|
+
request_limit = request_limit.to_i if request_limit
|
132
|
+
unless block_given?
|
133
|
+
return enum_for(:all, request_limit: request_limit)
|
134
|
+
end
|
135
|
+
results = self
|
136
|
+
loop do
|
137
|
+
results.each { |r| yield r }
|
138
|
+
if request_limit
|
139
|
+
request_limit -= 1
|
140
|
+
break if request_limit < 0
|
141
|
+
end
|
142
|
+
break unless results.next?
|
143
|
+
results = results.next
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
##
|
148
|
+
# @private New Sink::List from a
|
149
|
+
# Google::Logging::V2::ListSinksResponse object.
|
150
|
+
def self.from_grpc grpc_list, service, max = nil
|
151
|
+
sinks = new(Array(grpc_list.sinks).map do |grpc|
|
152
|
+
Sink.from_grpc grpc, service
|
153
|
+
end)
|
154
|
+
token = grpc_list.next_page_token
|
155
|
+
token = nil if token == ""
|
156
|
+
sinks.instance_variable_set "@token", token
|
157
|
+
sinks.instance_variable_set "@service", service
|
158
|
+
sinks.instance_variable_set "@max", max
|
159
|
+
sinks
|
160
|
+
end
|
161
|
+
|
162
|
+
protected
|
163
|
+
|
164
|
+
##
|
165
|
+
# Raise an error unless an active service is available.
|
166
|
+
def ensure_service!
|
167
|
+
fail "Must have active service" unless @service
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
@@ -0,0 +1,17 @@
|
|
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
|
+
require "google/cloud/logging/v2/config_service_v2_api"
|
16
|
+
require "google/cloud/logging/v2/logging_service_v2_api"
|
17
|
+
require "google/cloud/logging/v2/metrics_service_v2_api"
|
@@ -0,0 +1,331 @@
|
|
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
|
+
# EDITING INSTRUCTIONS
|
16
|
+
# This file was generated from the file
|
17
|
+
# https://github.com/googleapis/googleapis/blob/master/google/logging/v2/logging_config.proto,
|
18
|
+
# and updates to that file get reflected here through a refresh process.
|
19
|
+
# For the short term, the refresh process will only be runnable by Google
|
20
|
+
# engineers.
|
21
|
+
#
|
22
|
+
# The only allowed edits are to method and file documentation. A 3-way
|
23
|
+
# merge preserves those additions if the generated source changes.
|
24
|
+
|
25
|
+
require "json"
|
26
|
+
require "pathname"
|
27
|
+
|
28
|
+
require "google/gax"
|
29
|
+
require "google/logging/v2/logging_config_services_pb"
|
30
|
+
|
31
|
+
module Google
|
32
|
+
module Cloud
|
33
|
+
module Logging
|
34
|
+
module V2
|
35
|
+
# Service for configuring sinks used to export log entries outside Stackdriver
|
36
|
+
# Logging.
|
37
|
+
#
|
38
|
+
# @!attribute [r] stub
|
39
|
+
# @return [Google::Logging::V2::ConfigServiceV2::Stub]
|
40
|
+
class ConfigServiceV2Api
|
41
|
+
attr_reader :stub
|
42
|
+
|
43
|
+
# The default address of the service.
|
44
|
+
SERVICE_ADDRESS = "logging.googleapis.com".freeze
|
45
|
+
|
46
|
+
# The default port of the service.
|
47
|
+
DEFAULT_SERVICE_PORT = 443
|
48
|
+
|
49
|
+
CODE_GEN_NAME_VERSION = "gapic/0.1.0".freeze
|
50
|
+
|
51
|
+
DEFAULT_TIMEOUT = 30
|
52
|
+
|
53
|
+
PAGE_DESCRIPTORS = {
|
54
|
+
"list_sinks" => Google::Gax::PageDescriptor.new(
|
55
|
+
"page_token",
|
56
|
+
"next_page_token",
|
57
|
+
"sinks")
|
58
|
+
}.freeze
|
59
|
+
|
60
|
+
private_constant :PAGE_DESCRIPTORS
|
61
|
+
|
62
|
+
# The scopes needed to make gRPC calls to all of the methods defined in
|
63
|
+
# this service.
|
64
|
+
ALL_SCOPES = [
|
65
|
+
"https://www.googleapis.com/auth/cloud-platform",
|
66
|
+
"https://www.googleapis.com/auth/cloud-platform.read-only",
|
67
|
+
"https://www.googleapis.com/auth/logging.admin",
|
68
|
+
"https://www.googleapis.com/auth/logging.read",
|
69
|
+
"https://www.googleapis.com/auth/logging.write"
|
70
|
+
].freeze
|
71
|
+
|
72
|
+
PARENT_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
|
73
|
+
"projects/{project}"
|
74
|
+
)
|
75
|
+
|
76
|
+
private_constant :PARENT_PATH_TEMPLATE
|
77
|
+
|
78
|
+
SINK_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
|
79
|
+
"projects/{project}/sinks/{sink}"
|
80
|
+
)
|
81
|
+
|
82
|
+
private_constant :SINK_PATH_TEMPLATE
|
83
|
+
|
84
|
+
# Returns a fully-qualified parent resource name string.
|
85
|
+
# @param project [String]
|
86
|
+
# @return [String]
|
87
|
+
def self.parent_path project
|
88
|
+
PARENT_PATH_TEMPLATE.render(
|
89
|
+
:"project" => project
|
90
|
+
)
|
91
|
+
end
|
92
|
+
|
93
|
+
# Returns a fully-qualified sink resource name string.
|
94
|
+
# @param project [String]
|
95
|
+
# @param sink [String]
|
96
|
+
# @return [String]
|
97
|
+
def self.sink_path project, sink
|
98
|
+
SINK_PATH_TEMPLATE.render(
|
99
|
+
:"project" => project,
|
100
|
+
:"sink" => sink
|
101
|
+
)
|
102
|
+
end
|
103
|
+
|
104
|
+
# Parses the project from a parent resource.
|
105
|
+
# @param parent_name [String]
|
106
|
+
# @return [String]
|
107
|
+
def self.match_project_from_parent_name parent_name
|
108
|
+
PARENT_PATH_TEMPLATE.match(parent_name)["project"]
|
109
|
+
end
|
110
|
+
|
111
|
+
# Parses the project from a sink resource.
|
112
|
+
# @param sink_name [String]
|
113
|
+
# @return [String]
|
114
|
+
def self.match_project_from_sink_name sink_name
|
115
|
+
SINK_PATH_TEMPLATE.match(sink_name)["project"]
|
116
|
+
end
|
117
|
+
|
118
|
+
# Parses the sink from a sink resource.
|
119
|
+
# @param sink_name [String]
|
120
|
+
# @return [String]
|
121
|
+
def self.match_sink_from_sink_name sink_name
|
122
|
+
SINK_PATH_TEMPLATE.match(sink_name)["sink"]
|
123
|
+
end
|
124
|
+
|
125
|
+
# @param service_path [String]
|
126
|
+
# The domain name of the API remote host.
|
127
|
+
# @param port [Integer]
|
128
|
+
# The port on which to connect to the remote host.
|
129
|
+
# @param channel [Channel]
|
130
|
+
# A Channel object through which to make calls.
|
131
|
+
# @param chan_creds [Grpc::ChannelCredentials]
|
132
|
+
# A ChannelCredentials for the setting up the RPC client.
|
133
|
+
# @param client_config[Hash]
|
134
|
+
# A Hash for call options for each method. See
|
135
|
+
# Google::Gax#construct_settings for the structure of
|
136
|
+
# this data. Falls back to the default config if not specified
|
137
|
+
# or the specified config is missing data points.
|
138
|
+
# @param timeout [Numeric]
|
139
|
+
# The default timeout, in seconds, for calls made through this client.
|
140
|
+
# @param app_name [String]
|
141
|
+
# The codename of the calling service.
|
142
|
+
# @param app_version [String]
|
143
|
+
# The version of the calling service.
|
144
|
+
def initialize \
|
145
|
+
service_path: SERVICE_ADDRESS,
|
146
|
+
port: DEFAULT_SERVICE_PORT,
|
147
|
+
channel: nil,
|
148
|
+
chan_creds: nil,
|
149
|
+
scopes: ALL_SCOPES,
|
150
|
+
client_config: {},
|
151
|
+
timeout: DEFAULT_TIMEOUT,
|
152
|
+
app_name: "gax",
|
153
|
+
app_version: Google::Gax::VERSION
|
154
|
+
google_api_client = "#{app_name}/#{app_version} " \
|
155
|
+
"#{CODE_GEN_NAME_VERSION} ruby/#{RUBY_VERSION}".freeze
|
156
|
+
headers = { :"x-goog-api-client" => google_api_client }
|
157
|
+
client_config_file = Pathname.new(__dir__).join(
|
158
|
+
"config_service_v2_client_config.json"
|
159
|
+
)
|
160
|
+
defaults = client_config_file.open do |f|
|
161
|
+
Google::Gax.construct_settings(
|
162
|
+
"google.logging.v2.ConfigServiceV2",
|
163
|
+
JSON.parse(f.read),
|
164
|
+
client_config,
|
165
|
+
Google::Gax::Grpc::STATUS_CODE_NAMES,
|
166
|
+
timeout,
|
167
|
+
page_descriptors: PAGE_DESCRIPTORS,
|
168
|
+
errors: Google::Gax::Grpc::API_ERRORS,
|
169
|
+
kwargs: headers
|
170
|
+
)
|
171
|
+
end
|
172
|
+
@stub = Google::Gax::Grpc.create_stub(
|
173
|
+
service_path,
|
174
|
+
port,
|
175
|
+
chan_creds: chan_creds,
|
176
|
+
channel: channel,
|
177
|
+
scopes: scopes,
|
178
|
+
&Google::Logging::V2::ConfigServiceV2::Stub.method(:new)
|
179
|
+
)
|
180
|
+
|
181
|
+
@list_sinks = Google::Gax.create_api_call(
|
182
|
+
@stub.method(:list_sinks),
|
183
|
+
defaults["list_sinks"]
|
184
|
+
)
|
185
|
+
@get_sink = Google::Gax.create_api_call(
|
186
|
+
@stub.method(:get_sink),
|
187
|
+
defaults["get_sink"]
|
188
|
+
)
|
189
|
+
@create_sink = Google::Gax.create_api_call(
|
190
|
+
@stub.method(:create_sink),
|
191
|
+
defaults["create_sink"]
|
192
|
+
)
|
193
|
+
@update_sink = Google::Gax.create_api_call(
|
194
|
+
@stub.method(:update_sink),
|
195
|
+
defaults["update_sink"]
|
196
|
+
)
|
197
|
+
@delete_sink = Google::Gax.create_api_call(
|
198
|
+
@stub.method(:delete_sink),
|
199
|
+
defaults["delete_sink"]
|
200
|
+
)
|
201
|
+
end
|
202
|
+
|
203
|
+
# Service calls
|
204
|
+
|
205
|
+
# Lists sinks.
|
206
|
+
#
|
207
|
+
# @param parent [String]
|
208
|
+
# Required. The resource name containing the sinks.
|
209
|
+
# Example: +"projects/my-logging-project"+.
|
210
|
+
# @param page_size [Integer]
|
211
|
+
# The maximum number of resources contained in the underlying API
|
212
|
+
# response. If page streaming is performed per-resource, this
|
213
|
+
# parameter does not affect the return value. If page streaming is
|
214
|
+
# performed per-page, this determines the maximum number of
|
215
|
+
# resources in a page.
|
216
|
+
# @param options [Google::Gax::CallOptions]
|
217
|
+
# Overrides the default settings for this call, e.g, timeout,
|
218
|
+
# retries, etc.
|
219
|
+
# @return [Google::Gax::PagedEnumerable<Google::Logging::V2::LogSink>]
|
220
|
+
# An enumerable of Google::Logging::V2::LogSink instances.
|
221
|
+
# See Google::Gax::PagedEnumerable documentation for other
|
222
|
+
# operations such as per-page iteration or access to the response
|
223
|
+
# object.
|
224
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
225
|
+
def list_sinks \
|
226
|
+
parent,
|
227
|
+
page_size: nil,
|
228
|
+
options: nil
|
229
|
+
req = Google::Logging::V2::ListSinksRequest.new(
|
230
|
+
parent: parent
|
231
|
+
)
|
232
|
+
req.page_size = page_size unless page_size.nil?
|
233
|
+
@list_sinks.call(req, options)
|
234
|
+
end
|
235
|
+
|
236
|
+
# Gets a sink.
|
237
|
+
#
|
238
|
+
# @param sink_name [String]
|
239
|
+
# The resource name of the sink to return.
|
240
|
+
# Example: +"projects/my-project-id/sinks/my-sink-id"+.
|
241
|
+
# @param options [Google::Gax::CallOptions]
|
242
|
+
# Overrides the default settings for this call, e.g, timeout,
|
243
|
+
# retries, etc.
|
244
|
+
# @return [Google::Logging::V2::LogSink]
|
245
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
246
|
+
def get_sink \
|
247
|
+
sink_name,
|
248
|
+
options: nil
|
249
|
+
req = Google::Logging::V2::GetSinkRequest.new(
|
250
|
+
sink_name: sink_name
|
251
|
+
)
|
252
|
+
@get_sink.call(req, options)
|
253
|
+
end
|
254
|
+
|
255
|
+
# Creates a sink.
|
256
|
+
#
|
257
|
+
# @param parent [String]
|
258
|
+
# The resource in which to create the sink.
|
259
|
+
# Example: +"projects/my-project-id"+.
|
260
|
+
#
|
261
|
+
# The new sink must be provided in the request.
|
262
|
+
# @param sink [Google::Logging::V2::LogSink]
|
263
|
+
# The new sink, which must not have an identifier that already
|
264
|
+
# exists.
|
265
|
+
# @param options [Google::Gax::CallOptions]
|
266
|
+
# Overrides the default settings for this call, e.g, timeout,
|
267
|
+
# retries, etc.
|
268
|
+
# @return [Google::Logging::V2::LogSink]
|
269
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
270
|
+
def create_sink \
|
271
|
+
parent,
|
272
|
+
sink,
|
273
|
+
options: nil
|
274
|
+
req = Google::Logging::V2::CreateSinkRequest.new(
|
275
|
+
parent: parent,
|
276
|
+
sink: sink
|
277
|
+
)
|
278
|
+
@create_sink.call(req, options)
|
279
|
+
end
|
280
|
+
|
281
|
+
# Creates or updates a sink.
|
282
|
+
#
|
283
|
+
# @param sink_name [String]
|
284
|
+
# The resource name of the sink to update.
|
285
|
+
# Example: +"projects/my-project-id/sinks/my-sink-id"+.
|
286
|
+
#
|
287
|
+
# The updated sink must be provided in the request and have the
|
288
|
+
# same name that is specified in +sinkName+. If the sink does not
|
289
|
+
# exist, it is created.
|
290
|
+
# @param sink [Google::Logging::V2::LogSink]
|
291
|
+
# The updated sink, whose name must be the same as the sink
|
292
|
+
# identifier in +sinkName+. If +sinkName+ does not exist, then
|
293
|
+
# this method creates a new sink.
|
294
|
+
# @param options [Google::Gax::CallOptions]
|
295
|
+
# Overrides the default settings for this call, e.g, timeout,
|
296
|
+
# retries, etc.
|
297
|
+
# @return [Google::Logging::V2::LogSink]
|
298
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
299
|
+
def update_sink \
|
300
|
+
sink_name,
|
301
|
+
sink,
|
302
|
+
options: nil
|
303
|
+
req = Google::Logging::V2::UpdateSinkRequest.new(
|
304
|
+
sink_name: sink_name,
|
305
|
+
sink: sink
|
306
|
+
)
|
307
|
+
@update_sink.call(req, options)
|
308
|
+
end
|
309
|
+
|
310
|
+
# Deletes a sink.
|
311
|
+
#
|
312
|
+
# @param sink_name [String]
|
313
|
+
# The resource name of the sink to delete.
|
314
|
+
# Example: +"projects/my-project-id/sinks/my-sink-id"+.
|
315
|
+
# @param options [Google::Gax::CallOptions]
|
316
|
+
# Overrides the default settings for this call, e.g, timeout,
|
317
|
+
# retries, etc.
|
318
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
319
|
+
def delete_sink \
|
320
|
+
sink_name,
|
321
|
+
options: nil
|
322
|
+
req = Google::Logging::V2::DeleteSinkRequest.new(
|
323
|
+
sink_name: sink_name
|
324
|
+
)
|
325
|
+
@delete_sink.call(req, options)
|
326
|
+
end
|
327
|
+
end
|
328
|
+
end
|
329
|
+
end
|
330
|
+
end
|
331
|
+
end
|