fluent-plugin-google-cloud 0.6.1 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4d8ff06da0025190972720ffd13b941d21f79329
4
- data.tar.gz: 5c6253b111461fca1d2435f835d6bff911c4241f
3
+ metadata.gz: 357b0cf2cba57aafc6011c911419b746cc7103b2
4
+ data.tar.gz: 91941e153f05ff927e8f83d342b651219075ebc8
5
5
  SHA512:
6
- metadata.gz: 38a1fe0c31f761690a9328ca4fc1d94c50a19f0701893fb74873db17456c65e15ca0dd159a6dde731705f151976565ed709719ff755c4ff516cea2fc821314cb
7
- data.tar.gz: ea3d462b54d1c1a3bf8a76526d77b2c4b0590a510a89f6b969c6ae36923a3d4ae2847f89e52e6b3287383e8b911ec691aac1c53c53fedcde51708ce51ecf868d
6
+ metadata.gz: 10cfc826b705a84b017571b34b759ee9013f416436e6fcd79c632b8e6daa7a016e87c1630a6d5e03a23b7627abb2e46bd32709957a7fdb7589c91af8b2b4f3bc
7
+ data.tar.gz: 915d378471e6b055f8eef48e73c7d27300d9fcadf420b2029efdf5a73e46eb83f674e3b631e1257986cae43e9e2603148d61707363ad53e4d3cdb81fe575f1ba
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fluent-plugin-google-cloud (0.6.1)
4
+ fluent-plugin-google-cloud (0.6.2)
5
5
  fluentd (~> 0.10)
6
6
  google-api-client (~> 0.9.0)
7
7
  google-cloud-logging (~> 0.23.2)
@@ -21,9 +21,9 @@ GEM
21
21
  cool.io (1.4.6)
22
22
  crack (0.4.3)
23
23
  safe_yaml (~> 1.0.0)
24
- faraday (0.12.0.1)
24
+ faraday (0.12.1)
25
25
  multipart-post (>= 1.2, < 3)
26
- fluentd (0.14.14)
26
+ fluentd (0.14.15)
27
27
  cool.io (~> 1.4.5)
28
28
  http_parser.rb (>= 0.5.1, < 0.7.0)
29
29
  msgpack (>= 0.7.0, < 2.0.0)
@@ -57,7 +57,7 @@ GEM
57
57
  googleauth (~> 0.5.1)
58
58
  grpc (~> 1.0)
59
59
  rly (~> 0.2.3)
60
- google-protobuf (3.2.0.2)
60
+ google-protobuf (3.3.0)
61
61
  googleapis-common-protos (1.3.5)
62
62
  google-protobuf (~> 3.2)
63
63
  grpc (~> 1.0)
@@ -69,10 +69,10 @@ GEM
69
69
  multi_json (~> 1.11)
70
70
  os (~> 0.9)
71
71
  signet (~> 0.7)
72
- grpc (1.2.2)
72
+ grpc (1.2.5)
73
73
  google-protobuf (~> 3.1)
74
74
  googleauth (~> 0.5.1)
75
- hashdiff (0.3.2)
75
+ hashdiff (0.3.4)
76
76
  http_parser.rb (0.6.0)
77
77
  httpclient (2.8.3)
78
78
  hurley (0.2)
@@ -96,10 +96,11 @@ GEM
96
96
  os (0.9.6)
97
97
  parser (2.4.0.0)
98
98
  ast (~> 2.2)
99
- power_assert (1.0.1)
99
+ power_assert (1.0.2)
100
100
  powerpack (0.1.1)
101
101
  public_suffix (2.0.5)
102
- rainbow (2.2.1)
102
+ rainbow (2.2.2)
103
+ rake
103
104
  rake (10.5.0)
104
105
  representable (2.3.0)
105
106
  uber (~> 0.0.7)
@@ -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.1'
13
+ gem.version = '0.6.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')
@@ -73,7 +73,7 @@ module Fluent
73
73
  Fluent::Plugin.register_output('google_cloud', self)
74
74
 
75
75
  PLUGIN_NAME = 'Fluentd Google Cloud Logging plugin'
76
- PLUGIN_VERSION = '0.6.1'
76
+ PLUGIN_VERSION = '0.6.2'
77
77
 
78
78
  # Name of the the Google cloud logging write scope.
79
79
  LOGGING_SCOPE = 'https://www.googleapis.com/auth/logging.write'
@@ -243,6 +243,8 @@ module Fluent
243
243
  (?:\[(?<execution_id>[^\]]+)\])?
244
244
  [ ](?<text>.*)$/x
245
245
 
246
+ @http_latency_regexp = /^\s*(?<seconds>\d+)(?<decimal>\.\d+)?\s*s\s*$/
247
+
246
248
  # set attributes from metadata (unless overriden by static config)
247
249
  @vm_name = Socket.gethostname if @vm_name.nil?
248
250
  @platform = detect_platform
@@ -927,6 +929,8 @@ module Fluent
927
929
  end
928
930
  end
929
931
 
932
+ NANOS_IN_A_SECOND = 1000 * 1000 * 1000
933
+
930
934
  def set_http_request(record, entry)
931
935
  return nil unless record['httpRequest'].is_a?(Hash)
932
936
  input = record['httpRequest']
@@ -961,6 +965,33 @@ module Fluent
961
965
  output.cache_validated_with_origin_server = \
962
966
  cache_validated_with_origin_server \
963
967
  unless cache_validated_with_origin_server.nil?
968
+
969
+ latency = input.delete('latency')
970
+ unless latency.nil?
971
+ # Parse latency. If no valid format is detected, skip setting latency.
972
+ # Format: whitespace (optional) + integer + point & decimal (optional)
973
+ # + whitespace (optional) + "s" + whitespace (optional)
974
+ # e.g.: "1.42 s"
975
+ match = @http_latency_regexp.match(latency)
976
+ if match
977
+ # Split the integer and decimal parts in order to calculate seconds
978
+ # and nanos.
979
+ latency_seconds = match['seconds'].to_i
980
+ latency_nanos = (match['decimal'].to_f * NANOS_IN_A_SECOND).round
981
+ if @use_grpc
982
+ output.latency = Google::Protobuf::Duration.new(
983
+ seconds: latency_seconds,
984
+ nanos: latency_nanos
985
+ )
986
+ else
987
+ output.latency = {
988
+ seconds: latency_seconds,
989
+ nanos: latency_nanos
990
+ }.delete_if { |_, v| v == 0 }
991
+ end
992
+ end
993
+ end
994
+
964
995
  record.delete('httpRequest') if input.empty?
965
996
  entry.http_request = output
966
997
  end
@@ -1368,6 +1368,43 @@ module BaseTest
1368
1368
  end
1369
1369
  end
1370
1370
 
1371
+ def test_http_request_with_latency
1372
+ setup_gce_metadata_stubs
1373
+ latency_conversion.each do |input, expected|
1374
+ setup_logging_stubs do
1375
+ d = create_driver
1376
+ @logs_sent = []
1377
+ d.emit('httpRequest' => HTTP_REQUEST_MESSAGE.merge('latency' => input))
1378
+ d.run
1379
+ end
1380
+ verify_log_entries(1, COMPUTE_PARAMS, 'httpRequest') do |entry|
1381
+ assert_equal HTTP_REQUEST_MESSAGE.merge('latency' => expected),
1382
+ entry['httpRequest'], entry
1383
+ assert_nil get_fields(entry['jsonPayload'])['httpRequest'], entry
1384
+ end
1385
+ end
1386
+ end
1387
+
1388
+ # Skip setting latency when the field is null or has invalid format.
1389
+ def test_http_request_skip_setting_latency
1390
+ setup_gce_metadata_stubs
1391
+ [
1392
+ '', ' ', nil, 'null', '123', '1.23 seconds',
1393
+ ' 123 s econds ', '1min', 'abc&^!$*('
1394
+ ].each do |input|
1395
+ setup_logging_stubs do
1396
+ d = create_driver
1397
+ @logs_sent = []
1398
+ d.emit('httpRequest' => HTTP_REQUEST_MESSAGE.merge('latency' => input))
1399
+ d.run
1400
+ end
1401
+ verify_log_entries(1, COMPUTE_PARAMS, 'httpRequest') do |entry|
1402
+ assert_equal HTTP_REQUEST_MESSAGE, entry['httpRequest'], entry
1403
+ assert_nil get_fields(entry['jsonPayload'])['httpRequest'], entry
1404
+ end
1405
+ end
1406
+ end
1407
+
1371
1408
  private
1372
1409
 
1373
1410
  def stub_metadata_request(metadata_path, response_body)
@@ -1592,6 +1629,27 @@ module BaseTest
1592
1629
  end
1593
1630
  end
1594
1631
 
1632
+ # The conversions from user input to output.
1633
+ def latency_conversion
1634
+ {
1635
+ '32 s' => { 'seconds' => 32 },
1636
+ '32s' => { 'seconds' => 32 },
1637
+ '0.32s' => { 'nanos' => 320_000_000 },
1638
+ ' 123 s ' => { 'seconds' => 123 },
1639
+ '1.3442 s' => { 'seconds' => 1, 'nanos' => 344_200_000 },
1640
+
1641
+ # Test whitespace.
1642
+ # \t: tab. \r: carriage return. \n: line break.
1643
+ # \v: vertical whitespace. \f: form feed.
1644
+ "\t123.5\ts\t" => { 'seconds' => 123, 'nanos' => 500_000_000 },
1645
+ "\r123.5\rs\r" => { 'seconds' => 123, 'nanos' => 500_000_000 },
1646
+ "\n123.5\ns\n" => { 'seconds' => 123, 'nanos' => 500_000_000 },
1647
+ "\v123.5\vs\v" => { 'seconds' => 123, 'nanos' => 500_000_000 },
1648
+ "\f123.5\fs\f" => { 'seconds' => 123, 'nanos' => 500_000_000 },
1649
+ "\r123.5\ts\f" => { 'seconds' => 123, 'nanos' => 500_000_000 }
1650
+ }
1651
+ end
1652
+
1595
1653
  # This module expects the methods below to be overridden.
1596
1654
 
1597
1655
  # Create a Fluentd output test driver with the Google Cloud Output plugin.
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.1
4
+ version: 0.6.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-04-18 00:00:00.000000000 Z
12
+ date: 2017-05-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fluentd
@@ -226,7 +226,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
226
226
  version: '0'
227
227
  requirements: []
228
228
  rubyforge_project:
229
- rubygems_version: 2.6.11
229
+ rubygems_version: 2.4.8
230
230
  signing_key:
231
231
  specification_version: 4
232
232
  summary: fluentd output plugin for the Stackdriver Logging API