fluent-plugin-google-cloud 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
fluent-plugin-google-cloud (0.
|
4
|
+
fluent-plugin-google-cloud (0.4.1)
|
5
5
|
fluentd (>= 0.10)
|
6
6
|
google-api-client (>= 0.8)
|
7
7
|
googleauth (~> 0.4)
|
8
|
-
json (~> 1.8.
|
8
|
+
json (~> 1.8.2)
|
9
9
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
12
12
|
specs:
|
13
|
-
activesupport (4.2.
|
13
|
+
activesupport (4.2.3)
|
14
14
|
i18n (~> 0.7)
|
15
15
|
json (~> 1.7, >= 1.7.7)
|
16
16
|
minitest (~> 5.1)
|
@@ -27,7 +27,7 @@ GEM
|
|
27
27
|
extlib (0.9.16)
|
28
28
|
faraday (0.9.1)
|
29
29
|
multipart-post (>= 1.2, < 3)
|
30
|
-
fluentd (0.12.
|
30
|
+
fluentd (0.12.12)
|
31
31
|
cool.io (>= 1.2.2, < 2.0.0)
|
32
32
|
http_parser.rb (>= 0.5.1, < 0.7.0)
|
33
33
|
json (>= 1.4.3)
|
@@ -58,7 +58,7 @@ GEM
|
|
58
58
|
http_parser.rb (0.6.0)
|
59
59
|
i18n (0.7.0)
|
60
60
|
json (1.8.3)
|
61
|
-
jwt (1.5.
|
61
|
+
jwt (1.5.1)
|
62
62
|
launchy (2.4.3)
|
63
63
|
addressable (~> 2.3)
|
64
64
|
little-plugger (1.1.3)
|
@@ -90,7 +90,7 @@ GEM
|
|
90
90
|
thread_safe (0.3.5)
|
91
91
|
tzinfo (1.2.2)
|
92
92
|
thread_safe (~> 0.1)
|
93
|
-
tzinfo-data (1.2015.
|
93
|
+
tzinfo-data (1.2015.5)
|
94
94
|
tzinfo (>= 1.0.0)
|
95
95
|
webmock (1.21.0)
|
96
96
|
addressable (>= 2.3.6)
|
@@ -106,3 +106,6 @@ DEPENDENCIES
|
|
106
106
|
rake (>= 10.3.2)
|
107
107
|
test-unit (~> 3.0.2)
|
108
108
|
webmock (>= 1.17.0)
|
109
|
+
|
110
|
+
BUNDLED WITH
|
111
|
+
1.10.5
|
@@ -4,7 +4,7 @@ Gem::Specification.new do |gem|
|
|
4
4
|
gem.summary = %q{Fluentd plugin to stream logs to the Google Cloud Platform's logging API}
|
5
5
|
gem.homepage = 'https://github.com/GoogleCloudPlatform/fluent-plugin-google-cloud'
|
6
6
|
gem.license = 'Apache 2.0'
|
7
|
-
gem.version = '0.4.
|
7
|
+
gem.version = '0.4.2'
|
8
8
|
gem.authors = ['Todd Derr', 'Alex Robinson']
|
9
9
|
gem.email = ['salty@google.com']
|
10
10
|
|
@@ -54,6 +54,26 @@ module Fluent
|
|
54
54
|
config_param :zone, :string, :default => nil
|
55
55
|
config_param :vm_id, :string, :default => nil
|
56
56
|
|
57
|
+
# label_map (specified as a JSON object) is an unordered set of fluent
|
58
|
+
# field names whose values are sent as labels rather than as part of the
|
59
|
+
# struct payload.
|
60
|
+
#
|
61
|
+
# Each entry in the map is a {"field_name": "label_name"} pair. When
|
62
|
+
# the "field_name" (as parsed by the input plugin) is encountered, a label
|
63
|
+
# with the corresponding "label_name" is added to the log entry. The
|
64
|
+
# value of the field is used as the value of the label.
|
65
|
+
#
|
66
|
+
# The map gives the user additional flexibility in specifying label
|
67
|
+
# names, including the ability to use characters which would not be
|
68
|
+
# legal as part of fluent field names.
|
69
|
+
#
|
70
|
+
# Example:
|
71
|
+
# label_map {
|
72
|
+
# "field_name_1": "sent_label_name_1",
|
73
|
+
# "field_name_2": "some.prefix/sent_label_name_2"
|
74
|
+
# }
|
75
|
+
config_param :label_map, :hash, :default => nil
|
76
|
+
|
57
77
|
# TODO: Add a log_name config option rather than just using the tag?
|
58
78
|
|
59
79
|
# Expose attr_readers to make testing of metadata more direct than only
|
@@ -222,8 +242,9 @@ module Fluent
|
|
222
242
|
'entries' => [],
|
223
243
|
}
|
224
244
|
arr.each do |time, record|
|
225
|
-
next unless record.is_a?
|
245
|
+
next unless record.is_a?(Hash)
|
226
246
|
if (record.has_key?('timestamp') &&
|
247
|
+
record['timestamp'].is_a?(Hash) &&
|
227
248
|
record['timestamp'].has_key?('seconds') &&
|
228
249
|
record['timestamp'].has_key?('nanos'))
|
229
250
|
ts_secs = record['timestamp']['seconds']
|
@@ -270,6 +291,22 @@ module Fluent
|
|
270
291
|
entry['metadata']['severity'] = 'DEFAULT'
|
271
292
|
end
|
272
293
|
|
294
|
+
# If a field is present in the label_map, send its value as a label
|
295
|
+
# (mapping the field name to label name as specified in the config)
|
296
|
+
# and do not send that field as part of the payload.
|
297
|
+
if !label_map.nil?
|
298
|
+
labels = {}
|
299
|
+
@label_map.each do |field, label|
|
300
|
+
if record.has_key?(field)
|
301
|
+
labels[label] = record[field]
|
302
|
+
record.delete(field)
|
303
|
+
end
|
304
|
+
end
|
305
|
+
if !labels.empty?
|
306
|
+
entry['metadata']['labels'] = labels
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
273
310
|
# use textPayload if the only remainaing key is 'message',
|
274
311
|
# otherwise use a struct.
|
275
312
|
if (record.size == 1 && record.has_key?('message'))
|
@@ -461,7 +498,7 @@ module Fluent
|
|
461
498
|
def init_api_client
|
462
499
|
@client = Google::APIClient.new(
|
463
500
|
:application_name => 'Fluentd Google Cloud Logging plugin',
|
464
|
-
:application_version => '0.4.
|
501
|
+
:application_version => '0.4.2',
|
465
502
|
:retries => 1)
|
466
503
|
|
467
504
|
if @auth_method == 'private_key'
|
@@ -165,7 +165,7 @@ class GoogleCloudOutputTest < Test::Unit::TestCase
|
|
165
165
|
|
166
166
|
def create_driver(conf=APPLICATION_DEFAULT_CONFIG)
|
167
167
|
Fluent::Test::BufferedOutputTestDriver.new(
|
168
|
-
Fluent::GoogleCloudOutput).configure(conf)
|
168
|
+
Fluent::GoogleCloudOutput).configure(conf, use_v1_config: true)
|
169
169
|
end
|
170
170
|
|
171
171
|
def test_configure_service_account_application_default
|
@@ -459,6 +459,20 @@ class GoogleCloudOutputTest < Test::Unit::TestCase
|
|
459
459
|
end
|
460
460
|
end
|
461
461
|
|
462
|
+
def test_malformed_timestamp
|
463
|
+
setup_gce_metadata_stubs
|
464
|
+
setup_logging_stubs
|
465
|
+
d = create_driver()
|
466
|
+
# if timestamp is not a hash it is passed through to the struct payload.
|
467
|
+
d.emit({'message' => log_entry(0), 'timestamp' => 'not-a-hash'})
|
468
|
+
d.run
|
469
|
+
verify_index = 0
|
470
|
+
verify_log_entries(1, COMPUTE_PARAMS, 'structPayload') do |entry|
|
471
|
+
assert_equal 2, entry['structPayload'].size, entry
|
472
|
+
assert_equal "not-a-hash", entry['structPayload']['timestamp'], entry
|
473
|
+
end
|
474
|
+
end
|
475
|
+
|
462
476
|
def test_severities
|
463
477
|
setup_gce_metadata_stubs
|
464
478
|
setup_logging_stubs
|
@@ -481,6 +495,59 @@ class GoogleCloudOutputTest < Test::Unit::TestCase
|
|
481
495
|
end
|
482
496
|
end
|
483
497
|
|
498
|
+
def test_label_map_without_field_present
|
499
|
+
setup_gce_metadata_stubs
|
500
|
+
setup_logging_stubs
|
501
|
+
config = %[label_map { "label_field": "sent_label" }]
|
502
|
+
d = create_driver(config)
|
503
|
+
d.emit({'message' => log_entry(0)})
|
504
|
+
d.run
|
505
|
+
# No additional labels should be present
|
506
|
+
verify_log_entries(1, COMPUTE_PARAMS)
|
507
|
+
end
|
508
|
+
|
509
|
+
def test_label_map_with_field_present
|
510
|
+
setup_gce_metadata_stubs
|
511
|
+
setup_logging_stubs
|
512
|
+
config = %[label_map { "label_field": "sent_label" }]
|
513
|
+
d = create_driver(config)
|
514
|
+
d.emit({'message' => log_entry(0), 'label_field' => 'label_value'})
|
515
|
+
d.run
|
516
|
+
# make a deep copy of COMPUTE_PARAMS and add the parsed label.
|
517
|
+
params = Marshal.load(Marshal.dump(COMPUTE_PARAMS))
|
518
|
+
params['labels']['sent_label'] = 'label_value'
|
519
|
+
verify_log_entries(1, params)
|
520
|
+
end
|
521
|
+
|
522
|
+
def test_label_map_with_multiple_fields
|
523
|
+
setup_gce_metadata_stubs
|
524
|
+
setup_logging_stubs
|
525
|
+
config = %[
|
526
|
+
label_map {
|
527
|
+
"label1": "sent_label_1",
|
528
|
+
"label_number_two": "foo.googleapis.com/bar",
|
529
|
+
"label3": "label3"
|
530
|
+
}]
|
531
|
+
d = create_driver(config)
|
532
|
+
# not_a_label passes through to the struct payload
|
533
|
+
d.emit({'message' => log_entry(0),
|
534
|
+
'label1' => 'value1',
|
535
|
+
'label_number_two' => 'value2',
|
536
|
+
'not_a_label' => 'value4',
|
537
|
+
'label3' => 'value3'})
|
538
|
+
d.run
|
539
|
+
# make a deep copy of COMPUTE_PARAMS and add the parsed labels.
|
540
|
+
params = Marshal.load(Marshal.dump(COMPUTE_PARAMS))
|
541
|
+
params['labels']['sent_label_1'] = 'value1'
|
542
|
+
params['labels']['foo.googleapis.com/bar'] = 'value2'
|
543
|
+
params['labels']['label3'] = 'value3'
|
544
|
+
verify_log_entries(1, params, 'structPayload') do |entry|
|
545
|
+
assert_equal 2, entry['structPayload'].size, entry
|
546
|
+
assert_equal "test log entry 0", entry['structPayload']['message'], entry
|
547
|
+
assert_equal 'value4', entry['structPayload']['not_a_label'], entry
|
548
|
+
end
|
549
|
+
end
|
550
|
+
|
484
551
|
def test_multiple_logs
|
485
552
|
setup_gce_metadata_stubs
|
486
553
|
setup_logging_stubs
|
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.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-
|
13
|
+
date: 2015-07-08 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: fluentd
|
@@ -194,3 +194,4 @@ test_files:
|
|
194
194
|
- test/plugin/data/credentials.json
|
195
195
|
- test/plugin/data/invalid_credentials.json
|
196
196
|
- test/plugin/test_out_google_cloud.rb
|
197
|
+
has_rdoc:
|