fluent-plugin-google-cloud 0.4.8 → 0.4.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/fluent-plugin-google-cloud.gemspec +1 -1
- data/lib/fluent/plugin/out_google_cloud.rb +27 -12
- data/test/plugin/test_out_google_cloud.rb +34 -25
- 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: 2e57b5b102aadda45f4cbcab3f47d4a01ee863cd
|
4
|
+
data.tar.gz: 16f62d33c58b8f6fef5385f7f8f0e4958b57de8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1b6ccd7dc730e086f26f09820a8ba32f32872fb746a9e514bef5ae0b03971548ddcab6663470ee89c9700add1b8d663eb59a6838abc67445d4a2e8a2dbd159e
|
7
|
+
data.tar.gz: a5dde71268839c39338e6257c29c3a77cebeea51c6b69c6ee0b56bb26fdeb4b8eb363197c508c36e34be4c237aef0baf6a908ec5358ac47ba35d7ea6e9aa3aaa
|
data/Gemfile.lock
CHANGED
@@ -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.4.
|
13
|
+
gem.version = '0.4.9'
|
14
14
|
gem.authors = ['Todd Derr', 'Alex Robinson']
|
15
15
|
gem.email = ['salty@google.com']
|
16
16
|
|
@@ -382,11 +382,16 @@ module Fluent
|
|
382
382
|
|
383
383
|
set_severity(record, entry)
|
384
384
|
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
385
|
+
if @service_name == CONTAINER_SERVICE
|
386
|
+
# Move the stdout/stderr annotation from the record into a label
|
387
|
+
field_to_label(record, 'stream', entry['metadata']['labels'],
|
388
|
+
"#{CONTAINER_SERVICE}/stream")
|
389
|
+
# If the record has been annotated by the kubernetes_metadata_filter
|
390
|
+
# plugin, then use that metadata. Otherwise, rely on commonLabels
|
391
|
+
# populated at the grouped_entries level from the group's tag.
|
392
|
+
if record.key?('kubernetes')
|
393
|
+
handle_container_metadata(record, entry)
|
394
|
+
end
|
390
395
|
end
|
391
396
|
|
392
397
|
# If a field is present in the label_map, send its value as a label
|
@@ -417,7 +422,8 @@ module Fluent
|
|
417
422
|
# Don't send an empty request if we rejected all the entries.
|
418
423
|
next if write_log_entries_request['entries'].empty?
|
419
424
|
|
420
|
-
log_name = CGI.escape(
|
425
|
+
log_name = CGI.escape(
|
426
|
+
log_name(tag, write_log_entries_request['commonLabels']))
|
421
427
|
url = 'https://logging.googleapis.com/v1beta3/projects/' \
|
422
428
|
"#{@project_id}/logs/#{log_name}/entries:write"
|
423
429
|
begin
|
@@ -655,7 +661,8 @@ module Fluent
|
|
655
661
|
# available, or if the only remainaing key is 'message'.
|
656
662
|
if @service_name == CLOUDFUNCTIONS_SERVICE && @cloudfunctions_log_match
|
657
663
|
entry['textPayload'] = @cloudfunctions_log_match['text']
|
658
|
-
elsif @service_name == CLOUDFUNCTIONS_SERVICE
|
664
|
+
elsif (@service_name == CLOUDFUNCTIONS_SERVICE ||
|
665
|
+
@service_name == CONTAINER_SERVICE) && record.key?('log')
|
659
666
|
entry['textPayload'] = record['log']
|
660
667
|
elsif record.size == 1 && record.key?('message')
|
661
668
|
entry['textPayload'] = record['message']
|
@@ -664,19 +671,27 @@ module Fluent
|
|
664
671
|
end
|
665
672
|
end
|
666
673
|
|
667
|
-
def log_name(tag)
|
674
|
+
def log_name(tag, commonLabels)
|
668
675
|
if @service_name == CLOUDFUNCTIONS_SERVICE
|
669
676
|
return 'cloud-functions'
|
670
|
-
|
671
|
-
# Add a prefix to
|
672
|
-
return
|
677
|
+
elsif @running_on_managed_vm
|
678
|
+
# Add a prefix to Managed VM logs to prevent namespace collisions.
|
679
|
+
return "#{APPENGINE_SERVICE}/#{tag}"
|
680
|
+
elsif @service_name == CONTAINER_SERVICE
|
681
|
+
# For Kubernetes logs, use just the container name as the log name
|
682
|
+
# if we have it.
|
683
|
+
container_name_key = "#{CONTAINER_SERVICE}/container_name"
|
684
|
+
if commonLabels && commonLabels.key?(container_name_key)
|
685
|
+
return commonLabels[container_name_key]
|
686
|
+
end
|
673
687
|
end
|
688
|
+
tag
|
674
689
|
end
|
675
690
|
|
676
691
|
def init_api_client
|
677
692
|
@client = Google::APIClient.new(
|
678
693
|
application_name: 'Fluentd Google Cloud Logging plugin',
|
679
|
-
application_version: '0.4.
|
694
|
+
application_version: '0.4.9',
|
680
695
|
retries: 1)
|
681
696
|
|
682
697
|
if @auth_method == 'private_key'
|
@@ -67,6 +67,7 @@ class GoogleCloudOutputTest < Test::Unit::TestCase
|
|
67
67
|
CONTAINER_POD_ID = 'cad3c3c4-4b9c-11e5-9d81-42010af0194c'
|
68
68
|
CONTAINER_POD_NAME = 'redis-master-c0l82.foo.bar'
|
69
69
|
CONTAINER_CONTAINER_NAME = 'redis'
|
70
|
+
CONTAINER_STREAM = 'stdout'
|
70
71
|
|
71
72
|
# Cloud Functions specific labels
|
72
73
|
CLOUDFUNCTIONS_FUNCTION_NAME = 'function-1'
|
@@ -173,12 +174,12 @@ class GoogleCloudOutputTest < Test::Unit::TestCase
|
|
173
174
|
}
|
174
175
|
}
|
175
176
|
|
176
|
-
|
177
|
-
|
177
|
+
CONTAINER_TAG = "kubernetes.#{CONTAINER_POD_NAME}_" \
|
178
|
+
"#{CONTAINER_NAMESPACE_NAME}_#{CONTAINER_CONTAINER_NAME}"
|
178
179
|
|
179
180
|
CONTAINER_FROM_METADATA_PARAMS = {
|
180
181
|
'service_name' => CONTAINER_SERVICE_NAME,
|
181
|
-
'log_name' =>
|
182
|
+
'log_name' => CONTAINER_CONTAINER_NAME,
|
182
183
|
'project_id' => PROJECT_ID,
|
183
184
|
'zone' => ZONE,
|
184
185
|
'labels' => {
|
@@ -189,6 +190,7 @@ class GoogleCloudOutputTest < Test::Unit::TestCase
|
|
189
190
|
"#{CONTAINER_SERVICE_NAME}/pod_name" => CONTAINER_POD_NAME,
|
190
191
|
"#{CONTAINER_SERVICE_NAME}/pod_id" => CONTAINER_POD_ID,
|
191
192
|
"#{CONTAINER_SERVICE_NAME}/container_name" => CONTAINER_CONTAINER_NAME,
|
193
|
+
"#{CONTAINER_SERVICE_NAME}/stream" => CONTAINER_STREAM,
|
192
194
|
"#{COMPUTE_SERVICE_NAME}/resource_type" => 'instance',
|
193
195
|
"#{COMPUTE_SERVICE_NAME}/resource_id" => VM_ID,
|
194
196
|
"#{COMPUTE_SERVICE_NAME}/resource_name" => HOSTNAME
|
@@ -198,7 +200,7 @@ class GoogleCloudOutputTest < Test::Unit::TestCase
|
|
198
200
|
# Almost the same as from metadata, but missing namespace_id and pod_id.
|
199
201
|
CONTAINER_FROM_TAG_PARAMS = {
|
200
202
|
'service_name' => CONTAINER_SERVICE_NAME,
|
201
|
-
'log_name' =>
|
203
|
+
'log_name' => CONTAINER_CONTAINER_NAME,
|
202
204
|
'project_id' => PROJECT_ID,
|
203
205
|
'zone' => ZONE,
|
204
206
|
'labels' => {
|
@@ -207,6 +209,7 @@ class GoogleCloudOutputTest < Test::Unit::TestCase
|
|
207
209
|
"#{CONTAINER_SERVICE_NAME}/namespace_name" => CONTAINER_NAMESPACE_NAME,
|
208
210
|
"#{CONTAINER_SERVICE_NAME}/pod_name" => CONTAINER_POD_NAME,
|
209
211
|
"#{CONTAINER_SERVICE_NAME}/container_name" => CONTAINER_CONTAINER_NAME,
|
212
|
+
"#{CONTAINER_SERVICE_NAME}/stream" => CONTAINER_STREAM,
|
210
213
|
"#{COMPUTE_SERVICE_NAME}/resource_type" => 'instance',
|
211
214
|
"#{COMPUTE_SERVICE_NAME}/resource_id" => VM_ID,
|
212
215
|
"#{COMPUTE_SERVICE_NAME}/resource_name" => HOSTNAME
|
@@ -850,7 +853,7 @@ class GoogleCloudOutputTest < Test::Unit::TestCase
|
|
850
853
|
setup_gce_metadata_stubs
|
851
854
|
setup_container_metadata_stubs
|
852
855
|
setup_logging_stubs
|
853
|
-
d = create_driver(APPLICATION_DEFAULT_CONFIG,
|
856
|
+
d = create_driver(APPLICATION_DEFAULT_CONFIG, CONTAINER_TAG)
|
854
857
|
d.emit(container_log_entry_with_metadata(0))
|
855
858
|
d.run
|
856
859
|
verify_log_entries(1, CONTAINER_FROM_METADATA_PARAMS)
|
@@ -860,7 +863,7 @@ class GoogleCloudOutputTest < Test::Unit::TestCase
|
|
860
863
|
setup_gce_metadata_stubs
|
861
864
|
setup_container_metadata_stubs
|
862
865
|
setup_logging_stubs
|
863
|
-
d = create_driver(APPLICATION_DEFAULT_CONFIG,
|
866
|
+
d = create_driver(APPLICATION_DEFAULT_CONFIG, CONTAINER_TAG)
|
864
867
|
[2, 3, 5, 11, 50].each do |n|
|
865
868
|
# The test driver doesn't clear its buffer of entries after running, so
|
866
869
|
# do it manually here.
|
@@ -876,8 +879,8 @@ class GoogleCloudOutputTest < Test::Unit::TestCase
|
|
876
879
|
setup_gce_metadata_stubs
|
877
880
|
setup_container_metadata_stubs
|
878
881
|
setup_logging_stubs
|
879
|
-
d = create_driver(APPLICATION_DEFAULT_CONFIG,
|
880
|
-
d.emit(
|
882
|
+
d = create_driver(APPLICATION_DEFAULT_CONFIG, CONTAINER_TAG)
|
883
|
+
d.emit(container_log_entry(0))
|
881
884
|
d.run
|
882
885
|
verify_log_entries(1, CONTAINER_FROM_TAG_PARAMS)
|
883
886
|
end
|
@@ -886,13 +889,13 @@ class GoogleCloudOutputTest < Test::Unit::TestCase
|
|
886
889
|
setup_gce_metadata_stubs
|
887
890
|
setup_container_metadata_stubs
|
888
891
|
setup_logging_stubs
|
889
|
-
d = create_driver(APPLICATION_DEFAULT_CONFIG,
|
892
|
+
d = create_driver(APPLICATION_DEFAULT_CONFIG, CONTAINER_TAG)
|
890
893
|
[2, 3, 5, 11, 50].each do |n|
|
891
894
|
# The test driver doesn't clear its buffer of entries after running, so
|
892
895
|
# do it manually here.
|
893
896
|
d.instance_variable_get('@entries').clear
|
894
897
|
@logs_sent = []
|
895
|
-
n.times { |i| d.emit(
|
898
|
+
n.times { |i| d.emit(container_log_entry(i)) }
|
896
899
|
d.run
|
897
900
|
verify_log_entries(n, CONTAINER_FROM_TAG_PARAMS)
|
898
901
|
end
|
@@ -962,14 +965,12 @@ class GoogleCloudOutputTest < Test::Unit::TestCase
|
|
962
965
|
setup_gce_metadata_stubs
|
963
966
|
setup_cloudfunctions_metadata_stubs
|
964
967
|
setup_logging_stubs
|
965
|
-
d = create_driver(APPLICATION_DEFAULT_CONFIG,
|
968
|
+
d = create_driver(APPLICATION_DEFAULT_CONFIG, CONTAINER_TAG)
|
966
969
|
d.emit(cloudfunctions_log_entry(0))
|
967
970
|
d.run
|
968
|
-
verify_log_entries(1, CONTAINER_FROM_TAG_PARAMS, '
|
969
|
-
assert_equal 2, entry['structPayload'].size, entry
|
971
|
+
verify_log_entries(1, CONTAINER_FROM_TAG_PARAMS, '') do |entry|
|
970
972
|
assert_equal '[D][2015-09-25T12:34:56.789Z][123-0] test log entry 0',
|
971
|
-
entry['
|
972
|
-
assert_equal 'stdout', entry['structPayload']['stream'], entry
|
973
|
+
entry['textPayload'], entry
|
973
974
|
end
|
974
975
|
end
|
975
976
|
|
@@ -977,7 +978,7 @@ class GoogleCloudOutputTest < Test::Unit::TestCase
|
|
977
978
|
setup_gce_metadata_stubs
|
978
979
|
setup_cloudfunctions_metadata_stubs
|
979
980
|
setup_logging_stubs
|
980
|
-
d = create_driver(APPLICATION_DEFAULT_CONFIG,
|
981
|
+
d = create_driver(APPLICATION_DEFAULT_CONFIG, CONTAINER_TAG)
|
981
982
|
[2, 3, 5, 11, 50].each do |n|
|
982
983
|
# The test driver doesn't clear its buffer of entries after running, so
|
983
984
|
# do it manually here.
|
@@ -987,11 +988,9 @@ class GoogleCloudOutputTest < Test::Unit::TestCase
|
|
987
988
|
d.run
|
988
989
|
i = 0
|
989
990
|
params = CONTAINER_FROM_TAG_PARAMS
|
990
|
-
verify_log_entries(n, params, '
|
991
|
-
assert_equal 2, entry['structPayload'].size, entry
|
991
|
+
verify_log_entries(n, params, '') do |entry|
|
992
992
|
assert_equal "[D][2015-09-25T12:34:56.789Z][123-0] test log entry #{i}",
|
993
|
-
entry['
|
994
|
-
assert_equal 'stdout', entry['structPayload']['stream'], entry
|
993
|
+
entry['textPayload'], entry
|
995
994
|
i += 1
|
996
995
|
end
|
997
996
|
end
|
@@ -1196,7 +1195,8 @@ class GoogleCloudOutputTest < Test::Unit::TestCase
|
|
1196
1195
|
|
1197
1196
|
def container_log_entry_with_metadata(i)
|
1198
1197
|
{
|
1199
|
-
|
1198
|
+
log: log_entry(i),
|
1199
|
+
stream: 'stdout',
|
1200
1200
|
kubernetes: {
|
1201
1201
|
namespace_id: CONTAINER_NAMESPACE_ID,
|
1202
1202
|
namespace_name: CONTAINER_NAMESPACE_NAME,
|
@@ -1207,6 +1207,13 @@ class GoogleCloudOutputTest < Test::Unit::TestCase
|
|
1207
1207
|
}
|
1208
1208
|
end
|
1209
1209
|
|
1210
|
+
def container_log_entry(i)
|
1211
|
+
{
|
1212
|
+
log: log_entry(i),
|
1213
|
+
stream: 'stdout'
|
1214
|
+
}
|
1215
|
+
end
|
1216
|
+
|
1210
1217
|
def cloudfunctions_log_entry(i)
|
1211
1218
|
{
|
1212
1219
|
stream: 'stdout',
|
@@ -1245,10 +1252,12 @@ class GoogleCloudOutputTest < Test::Unit::TestCase
|
|
1245
1252
|
i = 0
|
1246
1253
|
@logs_sent.each do |batch|
|
1247
1254
|
batch['entries'].each do |entry|
|
1248
|
-
|
1249
|
-
|
1250
|
-
# Check the payload for textPayload, otherwise it
|
1251
|
-
|
1255
|
+
unless payload_type.empty?
|
1256
|
+
assert entry.key?(payload_type)
|
1257
|
+
# Check the payload for textPayload, otherwise it's up to the caller.
|
1258
|
+
if (payload_type == 'textPayload')
|
1259
|
+
assert_equal "test log entry #{i}", entry['textPayload'], batch
|
1260
|
+
end
|
1252
1261
|
end
|
1253
1262
|
|
1254
1263
|
assert_equal params['zone'], entry['metadata']['zone']
|
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.4.
|
4
|
+
version: 0.4.9
|
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: 2015-
|
12
|
+
date: 2015-10-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fluentd
|