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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e6d35bf9167d8e4847b5e54cc16e0f78dc41310d
4
- data.tar.gz: 3481166160940b98b9433cbe80811dfb71f98434
3
+ metadata.gz: 2e57b5b102aadda45f4cbcab3f47d4a01ee863cd
4
+ data.tar.gz: 16f62d33c58b8f6fef5385f7f8f0e4958b57de8d
5
5
  SHA512:
6
- metadata.gz: 0db9e3e069795d1965bbe72c49e2c7d9c8efce96087b099045dfb2308d21c55697bed09c6e6758aaab37d7ae267d1300970203df78f78db5a753f756b40717b9
7
- data.tar.gz: 6006bd9033b7d82aa7a720eb8c330f852487e03de9f2816e18795704df69cedfe362fe210741059fe83ca26bd5e61bf83a5499cb761bc154233e11f633cc1516
6
+ metadata.gz: d1b6ccd7dc730e086f26f09820a8ba32f32872fb746a9e514bef5ae0b03971548ddcab6663470ee89c9700add1b8d663eb59a6838abc67445d4a2e8a2dbd159e
7
+ data.tar.gz: a5dde71268839c39338e6257c29c3a77cebeea51c6b69c6ee0b56bb26fdeb4b8eb363197c508c36e34be4c237aef0baf6a908ec5358ac47ba35d7ea6e9aa3aaa
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fluent-plugin-google-cloud (0.4.7)
4
+ fluent-plugin-google-cloud (0.4.8)
5
5
  fluentd (>= 0.10)
6
6
  google-api-client (~> 0.8.6)
7
7
  googleauth (~> 0.4)
@@ -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.8'
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
- # If the record has been annotated by the kubernetes_metadata_filter
386
- # plugin, then use that metadata. Otherwise, rely on commonLabels
387
- # populated at the grouped_entries level from the group's tag.
388
- if @service_name == CONTAINER_SERVICE && record['kubernetes']
389
- handle_container_metadata(record, entry)
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(log_name(tag))
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 && record.key?('log')
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
- else
671
- # Add a prefix to VMEngines logs to prevent namespace collisions.
672
- return @running_on_managed_vm ? "#{APPENGINE_SERVICE}/#{tag}" : tag
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.8',
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
- CONTAINER_LOG_NAME = "kubernetes.#{CONTAINER_POD_NAME}_" \
177
- "#{CONTAINER_NAMESPACE_NAME}_#{CONTAINER_CONTAINER_NAME}"
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' => CONTAINER_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' => CONTAINER_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, CONTAINER_LOG_NAME)
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, CONTAINER_LOG_NAME)
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, CONTAINER_LOG_NAME)
880
- d.emit('message' => log_entry(0))
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, CONTAINER_LOG_NAME)
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('message' => log_entry(i)) }
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, CONTAINER_LOG_NAME)
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, 'structPayload') do |entry|
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['structPayload']['log'], 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, CONTAINER_LOG_NAME)
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, 'structPayload') do |entry|
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['structPayload']['log'], 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
- message: log_entry(i),
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
- assert entry.key?(payload_type)
1249
- if (payload_type == 'textPayload')
1250
- # Check the payload for textPayload, otherwise it is up to the caller.
1251
- assert_equal "test log entry #{i}", entry['textPayload'], batch
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.8
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-09-30 00:00:00.000000000 Z
12
+ date: 2015-10-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fluentd