fluent-plugin-google-cloud 0.5.5.pre.1 → 0.5.5.pre.2
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/Gemfile.lock +5 -5
- data/fluent-plugin-google-cloud.gemspec +1 -1
- data/lib/fluent/plugin/out_google_cloud.rb +37 -9
- data/test/plugin/base_test.rb +187 -2
- data/test/plugin/test_out_google_cloud.rb +8 -5
- data/test/plugin/test_out_google_cloud_grpc.rb +15 -5
- 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: 08888a8334b99ea4dfcf75f9cca5e4bd9c3adfb2
|
4
|
+
data.tar.gz: 3ad4733b6f10307039d813527044a3450443fe1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: adf57d8a4cf841974cf4992587134a0b335e86b2ca473bda6dc6edbf8cbc9f254e9a0699076d2a9e74f10969eadd07dce054e76bd5fd50fe6c62b2dce5f3c7d8
|
7
|
+
data.tar.gz: dea62f362060c090a560a5da926f90054c89874759c28cbe0b3b7bf523672184d5eaac738d98be55a0fa25e55d2e89251dd130bb5234ab76e84698a4bbd9335b
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
fluent-plugin-google-cloud (0.5.5.pre.
|
4
|
+
fluent-plugin-google-cloud (0.5.5.pre.2)
|
5
5
|
fluentd (~> 0.10)
|
6
6
|
google-api-client (> 0.9)
|
7
7
|
googleapis-common-protos (~> 1.3)
|
@@ -32,7 +32,7 @@ GEM
|
|
32
32
|
tzinfo (~> 1.0)
|
33
33
|
tzinfo-data (~> 1.0)
|
34
34
|
yajl-ruby (~> 1.0)
|
35
|
-
google-api-client (0.9.
|
35
|
+
google-api-client (0.9.28)
|
36
36
|
addressable (~> 2.3)
|
37
37
|
googleauth (~> 0.5)
|
38
38
|
httpclient (~> 2.7)
|
@@ -41,7 +41,7 @@ GEM
|
|
41
41
|
mime-types (>= 1.6)
|
42
42
|
representable (~> 2.3.0)
|
43
43
|
retriable (~> 2.0)
|
44
|
-
google-protobuf (3.0.2)
|
44
|
+
google-protobuf (3.0.2-x86_64-linux)
|
45
45
|
googleapis-common-protos (1.3.4)
|
46
46
|
google-protobuf (~> 3.0)
|
47
47
|
grpc (~> 1.0)
|
@@ -53,7 +53,7 @@ GEM
|
|
53
53
|
multi_json (~> 1.11)
|
54
54
|
os (~> 0.9)
|
55
55
|
signet (~> 0.7)
|
56
|
-
grpc (1.0.1)
|
56
|
+
grpc (1.0.1-x86_64-linux)
|
57
57
|
google-protobuf (~> 3.0.2)
|
58
58
|
googleauth (~> 0.5.1)
|
59
59
|
hashdiff (0.3.2)
|
@@ -77,7 +77,7 @@ GEM
|
|
77
77
|
multi_json (1.12.1)
|
78
78
|
multipart-post (2.0.0)
|
79
79
|
os (0.9.6)
|
80
|
-
parser (2.
|
80
|
+
parser (2.4.0.0)
|
81
81
|
ast (~> 2.2)
|
82
82
|
power_assert (1.0.1)
|
83
83
|
powerpack (0.1.1)
|
@@ -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.5.5.pre.
|
13
|
+
gem.version = '0.5.5.pre.2'
|
14
14
|
gem.authors = ['Todd Derr', 'Alex Robinson']
|
15
15
|
gem.email = ['salty@google.com']
|
16
16
|
gem.required_ruby_version = Gem::Requirement.new('>= 2.0')
|
@@ -39,7 +39,7 @@ module Fluent
|
|
39
39
|
Fluent::Plugin.register_output('google_cloud', self)
|
40
40
|
|
41
41
|
PLUGIN_NAME = 'Fluentd Google Cloud Logging plugin'
|
42
|
-
PLUGIN_VERSION = '0.5.5.pre.
|
42
|
+
PLUGIN_VERSION = '0.5.5.pre.2'
|
43
43
|
|
44
44
|
# Constants for service names.
|
45
45
|
APPENGINE_SERVICE = 'appengine.googleapis.com'
|
@@ -87,6 +87,11 @@ module Fluent
|
|
87
87
|
# The subservice_name overrides the subservice detection, if provided.
|
88
88
|
config_param :subservice_name, :string, :default => nil
|
89
89
|
|
90
|
+
# Whether to reject log entries with invalid tags. If this option is set to
|
91
|
+
# false, tags will be made valid by converting any non-string tag to a
|
92
|
+
# string, and sanitizing any non-utf8 or other invalid characters.
|
93
|
+
config_param :require_valid_tags, :bool, :default => false
|
94
|
+
|
90
95
|
# The regular expression to use on Kubernetes logs to extract some basic
|
91
96
|
# information about the log source. The regex must contain capture groups
|
92
97
|
# for pod_name, namespace_name, and container_name.
|
@@ -334,12 +339,32 @@ module Fluent
|
|
334
339
|
[tag, time, record].to_msgpack
|
335
340
|
end
|
336
341
|
|
342
|
+
# Given a tag, returns the corresponding valid tag if possible, or nil if
|
343
|
+
# the tag should be rejected. If 'require_valid_tags' is false, non-string
|
344
|
+
# tags are converted to strings, and invalid characters are sanitized;
|
345
|
+
# otherwise such tags are rejected.
|
346
|
+
def sanitize_tag(tag)
|
347
|
+
if @require_valid_tags &&
|
348
|
+
(!tag.is_a?(String) || tag == '' || convert_to_utf8(tag) != tag)
|
349
|
+
return nil
|
350
|
+
end
|
351
|
+
tag = convert_to_utf8(tag.to_s)
|
352
|
+
tag = '_' if tag == ''
|
353
|
+
tag
|
354
|
+
end
|
355
|
+
|
337
356
|
def write(chunk)
|
338
357
|
# Group the entries since we have to make one call per tag.
|
339
358
|
grouped_entries = {}
|
340
359
|
chunk.msgpack_each do |tag, *arr|
|
341
|
-
|
342
|
-
|
360
|
+
sanitized_tag = sanitize_tag(tag)
|
361
|
+
if sanitized_tag.nil?
|
362
|
+
@log.warn "Dropping log entries with invalid tag: '#{tag}'. " \
|
363
|
+
'A tag should be a string with utf8 characters.'
|
364
|
+
next
|
365
|
+
end
|
366
|
+
grouped_entries[sanitized_tag] ||= []
|
367
|
+
grouped_entries[sanitized_tag].push(arr)
|
343
368
|
end
|
344
369
|
|
345
370
|
grouped_entries.each do |tag, arr|
|
@@ -504,10 +529,9 @@ module Fluent
|
|
504
529
|
labels_utf8_pairs = labels.map do |k, v|
|
505
530
|
[k.encode('utf-8'), convert_to_utf8(v)]
|
506
531
|
end
|
507
|
-
utf8_log_name = convert_to_utf8(log_name)
|
508
532
|
|
509
533
|
write_request = Google::Logging::V1::WriteLogEntriesRequest.new(
|
510
|
-
log_name: "projects/#{@project_id}/logs/#{
|
534
|
+
log_name: "projects/#{@project_id}/logs/#{log_name}",
|
511
535
|
common_labels: Hash[labels_utf8_pairs],
|
512
536
|
entries: entries
|
513
537
|
)
|
@@ -986,7 +1010,7 @@ module Fluent
|
|
986
1010
|
|
987
1011
|
def field_to_label(record, field, labels, label)
|
988
1012
|
return unless record.key?(field)
|
989
|
-
labels[label] = record[field].to_s
|
1013
|
+
labels[label] = convert_to_utf8(record[field].to_s)
|
990
1014
|
record.delete(field)
|
991
1015
|
end
|
992
1016
|
|
@@ -1081,18 +1105,22 @@ module Fluent
|
|
1081
1105
|
|
1082
1106
|
def log_name(tag, common_labels)
|
1083
1107
|
if @service_name == CLOUDFUNCTIONS_SERVICE
|
1084
|
-
|
1108
|
+
tag = 'cloud-functions'
|
1085
1109
|
elsif @running_on_managed_vm
|
1086
1110
|
# Add a prefix to Managed VM logs to prevent namespace collisions.
|
1087
|
-
|
1111
|
+
tag = "#{APPENGINE_SERVICE}/#{tag}"
|
1088
1112
|
elsif @service_name == CONTAINER_SERVICE
|
1089
1113
|
# For Kubernetes logs, use just the container name as the log name
|
1090
1114
|
# if we have it.
|
1091
1115
|
container_name_key = "#{CONTAINER_SERVICE}/container_name"
|
1092
1116
|
if common_labels && common_labels.key?(container_name_key)
|
1093
|
-
|
1117
|
+
sanitized_log_name = sanitize_tag(common_labels[container_name_key])
|
1118
|
+
tag = sanitized_log_name unless sanitized_log_name.nil?
|
1094
1119
|
end
|
1095
1120
|
end
|
1121
|
+
# Only encode the log name for the grpc path, since the non-grpc client
|
1122
|
+
# lib already handles encoding.
|
1123
|
+
tag = ERB::Util.url_encode(tag) if @use_grpc
|
1096
1124
|
tag
|
1097
1125
|
end
|
1098
1126
|
|
data/test/plugin/base_test.rb
CHANGED
@@ -128,6 +128,10 @@ module BaseTest
|
|
128
128
|
)
|
129
129
|
# rubocop:enable Metrics/LineLength
|
130
130
|
|
131
|
+
REQUIRE_VALID_TAGS_CONFIG = %(
|
132
|
+
require_valid_tags true
|
133
|
+
)
|
134
|
+
|
131
135
|
NO_METADATA_SERVICE_CONFIG = %(
|
132
136
|
use_metadata_service false
|
133
137
|
)
|
@@ -320,6 +324,30 @@ module BaseTest
|
|
320
324
|
'cacheValidatedWithOriginServer' => true
|
321
325
|
}
|
322
326
|
|
327
|
+
# Tags and their sanitized and encoded version.
|
328
|
+
VALID_TAGS = {
|
329
|
+
'test' => 'test',
|
330
|
+
'germanß' => 'german%C3%9F',
|
331
|
+
'chinese中' => 'chinese%E4%B8%AD',
|
332
|
+
'specialCharacter/_-.' => 'specialCharacter%2F_-.',
|
333
|
+
'abc@&^$*' => 'abc%40%26%5E%24%2A',
|
334
|
+
'@&^$*' => '%40%26%5E%24%2A'
|
335
|
+
}
|
336
|
+
INVALID_TAGS = {
|
337
|
+
# Non-string tags.
|
338
|
+
123 => '123',
|
339
|
+
1.23 => '1.23',
|
340
|
+
[1, 2, 3] => '%5B1%2C%202%2C%203%5D',
|
341
|
+
{ key: 'value' } => '%7B%22key%22%3D%3E%22value%22%7D',
|
342
|
+
# Non-utf8 string tags.
|
343
|
+
"nonutf8#{[0x92].pack('C*')}" => 'nonutf8%20',
|
344
|
+
"abc#{[0x92].pack('C*')}" => 'abc%20',
|
345
|
+
"#{[0x92].pack('C*')}" => '%20',
|
346
|
+
# Empty string tag.
|
347
|
+
'' => '_'
|
348
|
+
}
|
349
|
+
ALL_TAGS = VALID_TAGS.merge(INVALID_TAGS)
|
350
|
+
|
323
351
|
# Shared tests.
|
324
352
|
|
325
353
|
def test_configure_service_account_application_default
|
@@ -626,6 +654,157 @@ module BaseTest
|
|
626
654
|
end
|
627
655
|
end
|
628
656
|
|
657
|
+
# Verify that we drop the log entries when 'require_valid_tags' is true and
|
658
|
+
# any non-string tags or tags with non-utf8 characters are detected.
|
659
|
+
def test_reject_invalid_tags_with_require_valid_tags_true
|
660
|
+
setup_gce_metadata_stubs
|
661
|
+
INVALID_TAGS.keys.each do |tag|
|
662
|
+
setup_logging_stubs do
|
663
|
+
@logs_sent = []
|
664
|
+
d = create_driver(REQUIRE_VALID_TAGS_CONFIG, tag)
|
665
|
+
d.emit('msg' => log_entry(0))
|
666
|
+
d.run
|
667
|
+
end
|
668
|
+
verify_log_entries(0, COMPUTE_PARAMS, 'structPayload')
|
669
|
+
end
|
670
|
+
end
|
671
|
+
|
672
|
+
# Verify that empty string container name should fail the kubernetes regex
|
673
|
+
# match, thus the original tag is used as the log name.
|
674
|
+
def test_handle_empty_container_name
|
675
|
+
setup_gce_metadata_stubs
|
676
|
+
setup_container_metadata_stubs
|
677
|
+
container_name = ''
|
678
|
+
# This tag will not match the kubernetes regex because it requires a
|
679
|
+
# non-empty container name.
|
680
|
+
tag = container_tag_with_container_name(container_name)
|
681
|
+
params = CONTAINER_FROM_METADATA_PARAMS.merge(
|
682
|
+
labels: CONTAINER_FROM_METADATA_PARAMS[:labels].merge(
|
683
|
+
"#{CONTAINER_SERVICE_NAME}/container_name" => container_name),
|
684
|
+
log_name: tag)
|
685
|
+
setup_logging_stubs([params]) do
|
686
|
+
@logs_sent = []
|
687
|
+
d = create_driver(REQUIRE_VALID_TAGS_CONFIG, tag)
|
688
|
+
d.emit(container_log_entry_with_metadata(log_entry(0), container_name))
|
689
|
+
d.run
|
690
|
+
end
|
691
|
+
verify_log_entries(1, params, 'textPayload')
|
692
|
+
assert_equal "projects/#{PROJECT_ID}/logs/#{tag}", @logs_sent[0]['logName']
|
693
|
+
end
|
694
|
+
|
695
|
+
# Verify that container names with non-utf8 characters should be rejected when
|
696
|
+
# 'require_valid_tags' is true.
|
697
|
+
def test_reject_non_utf8_container_name_with_require_valid_tags_true
|
698
|
+
setup_gce_metadata_stubs
|
699
|
+
setup_container_metadata_stubs
|
700
|
+
non_utf8_tags = INVALID_TAGS.select do |tag, _|
|
701
|
+
tag.is_a?(String) && !tag.empty?
|
702
|
+
end
|
703
|
+
non_utf8_tags.each do |container_name, encoded_name|
|
704
|
+
params = CONTAINER_FROM_METADATA_PARAMS.merge(
|
705
|
+
labels: CONTAINER_FROM_METADATA_PARAMS[:labels].merge(
|
706
|
+
"#{CONTAINER_SERVICE_NAME}/container_name" =>
|
707
|
+
URI.decode(encoded_name)),
|
708
|
+
log_name: encoded_name)
|
709
|
+
setup_logging_stubs([params]) do
|
710
|
+
@logs_sent = []
|
711
|
+
d = create_driver(REQUIRE_VALID_TAGS_CONFIG,
|
712
|
+
container_tag_with_container_name(container_name))
|
713
|
+
d.emit(container_log_entry_with_metadata(log_entry(0), container_name))
|
714
|
+
d.run
|
715
|
+
end
|
716
|
+
verify_log_entries(0, params, 'textPayload')
|
717
|
+
end
|
718
|
+
end
|
719
|
+
|
720
|
+
# Verify that tags are properly encoded. When 'require_valid_tags' is true, we
|
721
|
+
# only accept string tags with utf8 characters.
|
722
|
+
def test_encode_tags_with_require_valid_tags_true
|
723
|
+
setup_gce_metadata_stubs
|
724
|
+
VALID_TAGS.each do |tag, encoded_tag|
|
725
|
+
setup_logging_stubs([COMPUTE_PARAMS.merge(log_name: encoded_tag)]) do
|
726
|
+
@logs_sent = []
|
727
|
+
d = create_driver(REQUIRE_VALID_TAGS_CONFIG, tag)
|
728
|
+
d.emit('msg' => log_entry(0))
|
729
|
+
d.run
|
730
|
+
end
|
731
|
+
verify_log_entries(1, COMPUTE_PARAMS, 'structPayload')
|
732
|
+
assert_equal "projects/#{PROJECT_ID}/logs/#{encoded_tag}",
|
733
|
+
@logs_sent[0]['logName']
|
734
|
+
end
|
735
|
+
end
|
736
|
+
|
737
|
+
# Verify that tags extracted from container names are properly encoded.
|
738
|
+
def test_encode_tags_from_container_name_with_require_valid_tags_true
|
739
|
+
setup_gce_metadata_stubs
|
740
|
+
setup_container_metadata_stubs
|
741
|
+
VALID_TAGS.each do |tag, encoded_tag|
|
742
|
+
params = CONTAINER_FROM_METADATA_PARAMS.merge(
|
743
|
+
labels: CONTAINER_FROM_METADATA_PARAMS[:labels].merge(
|
744
|
+
"#{CONTAINER_SERVICE_NAME}/container_name" => tag),
|
745
|
+
log_name: encoded_tag)
|
746
|
+
setup_logging_stubs([params]) do
|
747
|
+
@logs_sent = []
|
748
|
+
d = create_driver(REQUIRE_VALID_TAGS_CONFIG,
|
749
|
+
container_tag_with_container_name(tag))
|
750
|
+
d.emit(container_log_entry_with_metadata(log_entry(0), tag))
|
751
|
+
d.run
|
752
|
+
end
|
753
|
+
verify_log_entries(1, params, 'textPayload')
|
754
|
+
assert_equal "projects/#{PROJECT_ID}/logs/#{encoded_tag}",
|
755
|
+
@logs_sent[0]['logName']
|
756
|
+
end
|
757
|
+
end
|
758
|
+
|
759
|
+
# Verify that tags are properly encoded and sanitized. When
|
760
|
+
# 'require_valid_tags' is false, we try to convert any non-string tags to
|
761
|
+
# strings, and replace non-utf8 characters with a replacement string.
|
762
|
+
def test_sanitize_tags_with_require_valid_tags_false
|
763
|
+
setup_gce_metadata_stubs
|
764
|
+
ALL_TAGS.each do |tag, sanitized_tag|
|
765
|
+
setup_logging_stubs([COMPUTE_PARAMS.merge(log_name: sanitized_tag)]) do
|
766
|
+
@logs_sent = []
|
767
|
+
d = create_driver(APPLICATION_DEFAULT_CONFIG, tag)
|
768
|
+
d.emit('msg' => log_entry(0))
|
769
|
+
d.run
|
770
|
+
end
|
771
|
+
verify_log_entries(1, COMPUTE_PARAMS, 'structPayload')
|
772
|
+
assert_equal "projects/#{PROJECT_ID}/logs/#{sanitized_tag}",
|
773
|
+
@logs_sent[0]['logName']
|
774
|
+
end
|
775
|
+
end
|
776
|
+
|
777
|
+
# Verify that tags extracted from container names are properly encoded and
|
778
|
+
# sanitized.
|
779
|
+
def test_sanitize_tags_from_container_name_with_require_valid_tags_false
|
780
|
+
setup_gce_metadata_stubs
|
781
|
+
setup_container_metadata_stubs
|
782
|
+
# Log names are derived from container names for containers. And container
|
783
|
+
# names are extracted from the tag based on a regex match pattern. As a
|
784
|
+
# prerequisite, the tag should already be a string, thus we only test
|
785
|
+
# non-empty string cases here.
|
786
|
+
string_tags = ALL_TAGS.select { |tag, _| tag.is_a?(String) && !tag.empty? }
|
787
|
+
string_tags.each do |container_name, encoded_container_name|
|
788
|
+
# Container name in the label is sanitized but not encoded, while the log
|
789
|
+
# name is encoded.
|
790
|
+
params = CONTAINER_FROM_METADATA_PARAMS.merge(
|
791
|
+
labels: CONTAINER_FROM_METADATA_PARAMS[:labels].merge(
|
792
|
+
"#{CONTAINER_SERVICE_NAME}/container_name" =>
|
793
|
+
URI.decode(encoded_container_name)),
|
794
|
+
log_name: encoded_container_name)
|
795
|
+
setup_logging_stubs([params]) do
|
796
|
+
@logs_sent = []
|
797
|
+
d = create_driver(APPLICATION_DEFAULT_CONFIG,
|
798
|
+
container_tag_with_container_name(container_name))
|
799
|
+
d.emit(container_log_entry_with_metadata(log_entry(0), container_name))
|
800
|
+
d.run
|
801
|
+
end
|
802
|
+
verify_log_entries(1, params, 'textPayload')
|
803
|
+
assert_equal "projects/#{PROJECT_ID}/logs/#{encoded_container_name}",
|
804
|
+
@logs_sent[0]['logName']
|
805
|
+
end
|
806
|
+
end
|
807
|
+
|
629
808
|
def test_timestamps
|
630
809
|
setup_gce_metadata_stubs
|
631
810
|
expected_ts = []
|
@@ -1196,7 +1375,13 @@ module BaseTest
|
|
1196
1375
|
CLOUDFUNCTIONS_REGION)
|
1197
1376
|
end
|
1198
1377
|
|
1199
|
-
def
|
1378
|
+
def container_tag_with_container_name(container_name)
|
1379
|
+
"kubernetes.#{CONTAINER_POD_NAME}_#{CONTAINER_NAMESPACE_NAME}_" \
|
1380
|
+
"#{container_name}"
|
1381
|
+
end
|
1382
|
+
|
1383
|
+
def container_log_entry_with_metadata(
|
1384
|
+
log, container_name = CONTAINER_CONTAINER_NAME)
|
1200
1385
|
{
|
1201
1386
|
log: log,
|
1202
1387
|
stream: CONTAINER_STREAM,
|
@@ -1206,7 +1391,7 @@ module BaseTest
|
|
1206
1391
|
namespace_name: CONTAINER_NAMESPACE_NAME,
|
1207
1392
|
pod_id: CONTAINER_POD_ID,
|
1208
1393
|
pod_name: CONTAINER_POD_NAME,
|
1209
|
-
container_name:
|
1394
|
+
container_name: container_name,
|
1210
1395
|
labels: {
|
1211
1396
|
CONTAINER_LABEL_KEY => CONTAINER_LABEL_VALUE
|
1212
1397
|
}
|
@@ -229,12 +229,15 @@ class GoogleCloudOutputTest < Test::Unit::TestCase
|
|
229
229
|
end
|
230
230
|
|
231
231
|
# Set up http stubs to mock the external calls.
|
232
|
-
def setup_logging_stubs
|
233
|
-
|
234
|
-
|
235
|
-
|
232
|
+
def setup_logging_stubs(override_stub_params = nil)
|
233
|
+
stub_params = override_stub_params || \
|
234
|
+
[COMPUTE_PARAMS, VMENGINE_PARAMS, CONTAINER_FROM_TAG_PARAMS,
|
235
|
+
CONTAINER_FROM_METADATA_PARAMS, CLOUDFUNCTIONS_PARAMS,
|
236
|
+
CUSTOM_PARAMS, EC2_PARAMS]
|
237
|
+
stub_params.each do |params|
|
236
238
|
stub_request(:post, uri_for_log(params)).to_return do |request|
|
237
|
-
|
239
|
+
log_name = "projects/#{params[:project_id]}/logs/#{params[:log_name]}"
|
240
|
+
@logs_sent << JSON.parse(request.body).merge('logName' => log_name)
|
238
241
|
{ body: '' }
|
239
242
|
end
|
240
243
|
end
|
@@ -31,7 +31,7 @@ class GoogleCloudOutputGRPCTest < Test::Unit::TestCase
|
|
31
31
|
{ 8 => 'ResourceExhausted',
|
32
32
|
12 => 'Unimplemented',
|
33
33
|
16 => 'Unauthenticated' }.each_with_index do |(code, message), index|
|
34
|
-
setup_logging_stubs(true, code, message) do
|
34
|
+
setup_logging_stubs(nil, true, code, message) do
|
35
35
|
d = create_driver(USE_GRPC_CONFIG, 'test',
|
36
36
|
GRPCLoggingMockFailingService.rpc_stub_class)
|
37
37
|
# The API Client should not retry this and the plugin should consume the
|
@@ -51,7 +51,7 @@ class GoogleCloudOutputGRPCTest < Test::Unit::TestCase
|
|
51
51
|
13 => 'Internal',
|
52
52
|
14 => 'Unavailable' }.each_with_index do |(code, message), index|
|
53
53
|
exception_count = 0
|
54
|
-
setup_logging_stubs(true, code, message) do
|
54
|
+
setup_logging_stubs(nil, true, code, message) do
|
55
55
|
d = create_driver(USE_GRPC_CONFIG, 'test',
|
56
56
|
GRPCLoggingMockFailingService.rpc_stub_class)
|
57
57
|
# The API client should retry this once, then throw an exception which
|
@@ -224,12 +224,17 @@ class GoogleCloudOutputGRPCTest < Test::Unit::TestCase
|
|
224
224
|
|
225
225
|
# GRPC logging mock that successfully logs the records.
|
226
226
|
class GRPCLoggingMockService < Google::Logging::V1::LoggingService::Service
|
227
|
-
def initialize(requests_received)
|
227
|
+
def initialize(stub_params, requests_received)
|
228
228
|
super()
|
229
229
|
@requests_received = requests_received
|
230
|
+
@expected_log_names = stub_params.map do |param|
|
231
|
+
"projects/#{param[:project_id]}/logs/#{param[:log_name]}"
|
232
|
+
end
|
230
233
|
end
|
231
234
|
|
232
235
|
def write_log_entries(request, _call)
|
236
|
+
fail GRPC::BadStatus.new(99, "Unexpected request: #{request.inspect}") \
|
237
|
+
unless @expected_log_names.include?(request.log_name)
|
233
238
|
@requests_received << request
|
234
239
|
WriteLogEntriesResponse.new
|
235
240
|
end
|
@@ -283,14 +288,19 @@ class GoogleCloudOutputGRPCTest < Test::Unit::TestCase
|
|
283
288
|
end
|
284
289
|
|
285
290
|
# Set up grpc stubs to mock the external calls.
|
286
|
-
def setup_logging_stubs(
|
291
|
+
def setup_logging_stubs(override_stub_params = nil, should_fail = false,
|
292
|
+
code = 0, message = 'Ok')
|
293
|
+
stub_params = override_stub_params || \
|
294
|
+
[COMPUTE_PARAMS, VMENGINE_PARAMS, CONTAINER_FROM_TAG_PARAMS,
|
295
|
+
CONTAINER_FROM_METADATA_PARAMS, CLOUDFUNCTIONS_PARAMS,
|
296
|
+
CUSTOM_PARAMS, EC2_PARAMS]
|
287
297
|
srv = GRPC::RpcServer.new
|
288
298
|
@failed_attempts = []
|
289
299
|
@requests_sent = []
|
290
300
|
if should_fail
|
291
301
|
grpc = GRPCLoggingMockFailingService.new(code, message, @failed_attempts)
|
292
302
|
else
|
293
|
-
grpc = GRPCLoggingMockService.new(@requests_sent)
|
303
|
+
grpc = GRPCLoggingMockService.new(stub_params, @requests_sent)
|
294
304
|
end
|
295
305
|
srv.handle(grpc)
|
296
306
|
srv.add_http2_port(GRPC_MOCK_HOST, :this_port_is_insecure)
|
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.5.5.pre.
|
4
|
+
version: 0.5.5.pre.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Todd Derr
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-02-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fluentd
|