fluent-plugin-google-cloud 0.6.19 → 0.6.20
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/fluent-plugin-google-cloud.gemspec +1 -1
- data/lib/fluent/plugin/out_google_cloud.rb +18 -5
- data/test/plugin/base_test.rb +17 -7
- data/test/plugin/test_out_google_cloud_grpc.rb +30 -19
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38cbf8464d2ca792e5d134d1edd66a2a4f6654ca
|
4
|
+
data.tar.gz: 2d15be19df0ca83a865c0cea38a4199f6ef42b7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04eaab1746f9d66c14cd402fb6f7960affbc2e36ac79ccecc84eb00c8af19e5793f7c591d94cfa1765f7a3f0d8e1807ecd24238a4209f99d29635a61a4793e68
|
7
|
+
data.tar.gz: 6a692ee7e882ce8b36e119432229b4fcc3f7aa855c59f1e806943885c465165a10d664b0a42baac1577277039d94ddb0d8f05a7fa035196a55b894d8ad606d1c
|
@@ -10,7 +10,7 @@ eos
|
|
10
10
|
gem.homepage =
|
11
11
|
'https://github.com/GoogleCloudPlatform/fluent-plugin-google-cloud'
|
12
12
|
gem.license = 'Apache-2.0'
|
13
|
-
gem.version = '0.6.
|
13
|
+
gem.version = '0.6.20'
|
14
14
|
gem.authors = ['Ling Huang', 'Igor Peshansky']
|
15
15
|
gem.email = ['stackdriver-agents@google.com']
|
16
16
|
gem.required_ruby_version = Gem::Requirement.new('>= 2.2')
|
@@ -156,6 +156,7 @@ module Fluent
|
|
156
156
|
|
157
157
|
# Internal constants.
|
158
158
|
module InternalConstants
|
159
|
+
CREDENTIALS_PATH_ENV_VAR = 'GOOGLE_APPLICATION_CREDENTIALS'.freeze
|
159
160
|
DEFAULT_LOGGING_API_URL = 'https://logging.googleapis.com'.freeze
|
160
161
|
|
161
162
|
# The label name of local_resource_id in the json payload. When a record
|
@@ -226,7 +227,7 @@ module Fluent
|
|
226
227
|
Fluent::Plugin.register_output('google_cloud', self)
|
227
228
|
|
228
229
|
PLUGIN_NAME = 'Fluentd Google Cloud Logging plugin'.freeze
|
229
|
-
PLUGIN_VERSION = '0.6.
|
230
|
+
PLUGIN_VERSION = '0.6.20'.freeze
|
230
231
|
|
231
232
|
# Name of the the Google cloud logging write scope.
|
232
233
|
LOGGING_SCOPE = 'https://www.googleapis.com/auth/logging.write'.freeze
|
@@ -482,6 +483,12 @@ module Fluent
|
|
482
483
|
|
483
484
|
@platform = detect_platform
|
484
485
|
|
486
|
+
# Treat an empty setting of the credentials file path environment variable
|
487
|
+
# as unset. This way the googleauth lib could fetch the credentials
|
488
|
+
# following the fallback path.
|
489
|
+
ENV.delete(CREDENTIALS_PATH_ENV_VAR) if
|
490
|
+
ENV[CREDENTIALS_PATH_ENV_VAR] == ''
|
491
|
+
|
485
492
|
# Set required variables: @project_id, @vm_id, @vm_name and @zone.
|
486
493
|
set_required_metadata_variables
|
487
494
|
|
@@ -804,11 +811,16 @@ module Fluent
|
|
804
811
|
|
805
812
|
else
|
806
813
|
# Assume it's a problem with the request itself and don't retry.
|
807
|
-
|
808
|
-
|
809
|
-
|
814
|
+
error_code = if error.respond_to?(:code)
|
815
|
+
error.code
|
816
|
+
else
|
817
|
+
GRPC::Core::StatusCodes::UNKNOWN
|
818
|
+
end
|
819
|
+
increment_failed_requests_count(error_code)
|
820
|
+
increment_dropped_entries_count(entries_count, error_code)
|
821
|
+
@log.error "Unknown response code #{error_code} from the server," \
|
810
822
|
" dropping #{entries_count} log message(s)",
|
811
|
-
error: error.to_s, error_code:
|
823
|
+
error: error.to_s, error_code: error_code.to_s
|
812
824
|
end
|
813
825
|
|
814
826
|
# Got an unexpected error (not Google::Gax::GaxError) from the
|
@@ -1451,6 +1463,7 @@ module Fluent
|
|
1451
1463
|
end
|
1452
1464
|
rescue StandardError => e
|
1453
1465
|
@log.error "Error calling Metadata Agent at #{url}.", error: e
|
1466
|
+
nil
|
1454
1467
|
end
|
1455
1468
|
|
1456
1469
|
# TODO: This functionality should eventually be available in another
|
data/test/plugin/base_test.rb
CHANGED
@@ -27,7 +27,7 @@ module BaseTest
|
|
27
27
|
def setup
|
28
28
|
Fluent::Test.setup
|
29
29
|
# delete environment variables that googleauth uses to find credentials.
|
30
|
-
ENV.delete(
|
30
|
+
ENV.delete(CREDENTIALS_PATH_ENV_VAR)
|
31
31
|
# service account env.
|
32
32
|
ENV.delete('PRIVATE_KEY_VAR')
|
33
33
|
ENV.delete('CLIENT_EMAIL_VAR')
|
@@ -229,7 +229,7 @@ module BaseTest
|
|
229
229
|
send("setup_#{platform}_metadata_stubs")
|
230
230
|
[IAM_CREDENTIALS, NEW_STYLE_CREDENTIALS, LEGACY_CREDENTIALS].each \
|
231
231
|
do |creds|
|
232
|
-
ENV[
|
232
|
+
ENV[CREDENTIALS_PATH_ENV_VAR] = creds[:path]
|
233
233
|
d = create_driver
|
234
234
|
d.run
|
235
235
|
assert_equal creds[:project_id], d.instance.project_id
|
@@ -249,7 +249,7 @@ module BaseTest
|
|
249
249
|
|
250
250
|
def test_one_log_with_json_credentials
|
251
251
|
setup_gce_metadata_stubs
|
252
|
-
ENV[
|
252
|
+
ENV[CREDENTIALS_PATH_ENV_VAR] = IAM_CREDENTIALS[:path]
|
253
253
|
setup_logging_stubs do
|
254
254
|
d = create_driver
|
255
255
|
d.emit('message' => log_entry(0))
|
@@ -263,7 +263,7 @@ module BaseTest
|
|
263
263
|
%w(gce_metadata ec2_metadata no_metadata_service).each do |platform|
|
264
264
|
send("setup_#{platform}_stubs")
|
265
265
|
exception_count = 0
|
266
|
-
ENV[
|
266
|
+
ENV[CREDENTIALS_PATH_ENV_VAR] = INVALID_CREDENTIALS[:path]
|
267
267
|
begin
|
268
268
|
create_driver
|
269
269
|
rescue RuntimeError => error
|
@@ -274,11 +274,21 @@ module BaseTest
|
|
274
274
|
end
|
275
275
|
end
|
276
276
|
|
277
|
+
def test_unset_or_empty_credentials_path_env_var
|
278
|
+
# An empty string should be treated as if it's not set.
|
279
|
+
[nil, ''].each do |value|
|
280
|
+
ENV[CREDENTIALS_PATH_ENV_VAR] = value
|
281
|
+
setup_gce_metadata_stubs
|
282
|
+
create_driver
|
283
|
+
assert_nil ENV[CREDENTIALS_PATH_ENV_VAR]
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
277
287
|
def test_one_log_custom_metadata
|
278
288
|
# don't set up any metadata stubs, so the test will fail if we try to
|
279
289
|
# fetch metadata (and explicitly check this as well).
|
280
290
|
Fluent::GoogleCloudOutput.any_instance.expects(:fetch_metadata).never
|
281
|
-
ENV[
|
291
|
+
ENV[CREDENTIALS_PATH_ENV_VAR] = IAM_CREDENTIALS[:path]
|
282
292
|
setup_logging_stubs do
|
283
293
|
d = create_driver(NO_METADATA_SERVICE_CONFIG + CUSTOM_METADATA_CONFIG)
|
284
294
|
d.emit('message' => log_entry(0))
|
@@ -288,7 +298,7 @@ module BaseTest
|
|
288
298
|
end
|
289
299
|
|
290
300
|
def test_one_log_ec2
|
291
|
-
ENV[
|
301
|
+
ENV[CREDENTIALS_PATH_ENV_VAR] = IAM_CREDENTIALS[:path]
|
292
302
|
setup_ec2_metadata_stubs
|
293
303
|
setup_logging_stubs do
|
294
304
|
d = create_driver(CONFIG_EC2_PROJECT_ID)
|
@@ -299,7 +309,7 @@ module BaseTest
|
|
299
309
|
end
|
300
310
|
|
301
311
|
def test_one_log_ec2_region
|
302
|
-
ENV[
|
312
|
+
ENV[CREDENTIALS_PATH_ENV_VAR] = IAM_CREDENTIALS[:path]
|
303
313
|
setup_ec2_metadata_stubs
|
304
314
|
setup_logging_stubs do
|
305
315
|
d = create_driver(CONFIG_EC2_PROJECT_ID_USE_REGION)
|
@@ -40,7 +40,8 @@ class GoogleCloudOutputGRPCTest < Test::Unit::TestCase
|
|
40
40
|
GRPC::Core::StatusCodes::ABORTED => 'Aborted',
|
41
41
|
GRPC::Core::StatusCodes::UNAUTHENTICATED => 'Unauthenticated'
|
42
42
|
}.each_with_index do |(code, message), index|
|
43
|
-
setup_logging_stubs(
|
43
|
+
setup_logging_stubs(
|
44
|
+
GRPC::BadStatus.new_status_exception(code, message)) do
|
44
45
|
d = create_driver(USE_GRPC_CONFIG, 'test')
|
45
46
|
# The API Client should not retry this and the plugin should consume the
|
46
47
|
# exception.
|
@@ -51,12 +52,24 @@ class GoogleCloudOutputGRPCTest < Test::Unit::TestCase
|
|
51
52
|
end
|
52
53
|
end
|
53
54
|
|
55
|
+
def test_invalid_error
|
56
|
+
setup_gce_metadata_stubs
|
57
|
+
setup_logging_stubs(RuntimeError.new('Some non-gRPC error')) do
|
58
|
+
d = create_driver(USE_GRPC_CONFIG, 'test')
|
59
|
+
# The API Client should not retry this and the plugin should consume the
|
60
|
+
# exception.
|
61
|
+
d.emit('message' => log_entry(0))
|
62
|
+
d.run
|
63
|
+
end
|
64
|
+
assert_equal 1, @failed_attempts.size
|
65
|
+
end
|
66
|
+
|
54
67
|
def test_partial_success
|
55
68
|
setup_gce_metadata_stubs
|
56
69
|
setup_prometheus
|
57
70
|
setup_logging_stubs(
|
58
|
-
|
59
|
-
|
71
|
+
GRPC::PermissionDenied.new('User not authorized.',
|
72
|
+
PARTIAL_SUCCESS_GRPC_METADATA)) do
|
60
73
|
# The API Client should not retry this and the plugin should consume
|
61
74
|
# the exception.
|
62
75
|
d = create_driver(ENABLE_PROMETHEUS_CONFIG)
|
@@ -93,7 +106,8 @@ class GoogleCloudOutputGRPCTest < Test::Unit::TestCase
|
|
93
106
|
GRPC::Core::StatusCodes::UNAVAILABLE => 'Unavailable'
|
94
107
|
}.each_with_index do |(code, message), index|
|
95
108
|
exception_count = 0
|
96
|
-
setup_logging_stubs(
|
109
|
+
setup_logging_stubs(
|
110
|
+
GRPC::BadStatus.new_status_exception(code, message)) do
|
97
111
|
d = create_driver(USE_GRPC_CONFIG, 'test')
|
98
112
|
# The API client should retry this once, then throw an exception which
|
99
113
|
# gets propagated through the plugin
|
@@ -130,7 +144,10 @@ class GoogleCloudOutputGRPCTest < Test::Unit::TestCase
|
|
130
144
|
].each do |should_fail, code, request_count, entry_count, metric_values|
|
131
145
|
setup_prometheus
|
132
146
|
(1..request_count).each do
|
133
|
-
setup_logging_stubs(
|
147
|
+
setup_logging_stubs(
|
148
|
+
if should_fail
|
149
|
+
GRPC::BadStatus.new_status_exception(code, 'SomeMessage')
|
150
|
+
end) do
|
134
151
|
d = create_driver(USE_GRPC_CONFIG + ENABLE_PROMETHEUS_CONFIG, 'test')
|
135
152
|
(1..entry_count).each do |i|
|
136
153
|
d.emit('message' => log_entry(i.to_s))
|
@@ -311,10 +328,8 @@ class GoogleCloudOutputGRPCTest < Test::Unit::TestCase
|
|
311
328
|
# GRPC logging mock that fails and returns server side or client side errors.
|
312
329
|
class GRPCLoggingMockFailingService <
|
313
330
|
Google::Cloud::Logging::V2::LoggingServiceV2Client
|
314
|
-
def initialize(
|
315
|
-
@
|
316
|
-
@message = message
|
317
|
-
@metadata = metadata
|
331
|
+
def initialize(error, failed_attempts)
|
332
|
+
@error = error
|
318
333
|
@failed_attempts = failed_attempts
|
319
334
|
super()
|
320
335
|
end
|
@@ -327,7 +342,7 @@ class GoogleCloudOutputGRPCTest < Test::Unit::TestCase
|
|
327
342
|
partial_success: nil)
|
328
343
|
@failed_attempts << 1
|
329
344
|
begin
|
330
|
-
raise
|
345
|
+
raise @error
|
331
346
|
rescue
|
332
347
|
# Google::Gax::GaxError will wrap the latest thrown exception as @cause.
|
333
348
|
raise Google::Gax::GaxError, @message
|
@@ -337,17 +352,13 @@ class GoogleCloudOutputGRPCTest < Test::Unit::TestCase
|
|
337
352
|
end
|
338
353
|
|
339
354
|
# Set up grpc stubs to mock the external calls.
|
340
|
-
def setup_logging_stubs(
|
341
|
-
|
342
|
-
message = nil,
|
343
|
-
metadata = {})
|
344
|
-
if should_fail
|
345
|
-
@failed_attempts = []
|
346
|
-
@grpc_stub = GRPCLoggingMockFailingService.new(
|
347
|
-
code, message, metadata, @failed_attempts)
|
348
|
-
else
|
355
|
+
def setup_logging_stubs(error = nil)
|
356
|
+
if error.nil?
|
349
357
|
@requests_sent = []
|
350
358
|
@grpc_stub = GRPCLoggingMockService.new(@requests_sent)
|
359
|
+
else
|
360
|
+
@failed_attempts = []
|
361
|
+
@grpc_stub = GRPCLoggingMockFailingService.new(error, @failed_attempts)
|
351
362
|
end
|
352
363
|
yield
|
353
364
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-google-cloud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.20
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ling Huang
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-
|
12
|
+
date: 2018-06-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fluentd
|