fluent-plugin-google-cloud 0.6.25.1 → 0.7.0.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +15 -24
- data/Rakefile +2 -1
- data/fluent-plugin-google-cloud.gemspec +8 -8
- data/lib/fluent/plugin/out_google_cloud.rb +33 -36
- data/test/plugin/base_test.rb +115 -223
- data/test/plugin/constants.rb +33 -33
- metadata +14 -16
- data/lib/fluent/plugin/filter_add_insert_ids.rb +0 -99
- data/test/plugin/test_filter_add_insert_ids.rb +0 -135
data/test/plugin/constants.rb
CHANGED
@@ -98,14 +98,6 @@ module Constants
|
|
98
98
|
MANAGED_VM_BACKEND_NAME = 'default'.freeze
|
99
99
|
MANAGED_VM_BACKEND_VERSION = 'guestbook2.0'.freeze
|
100
100
|
|
101
|
-
# LogEntry fields for extraction.
|
102
|
-
TRACE = 'projects/proj1/traces/1234567890abcdef1234567890abcdef'.freeze
|
103
|
-
TRACE2 = 'projects/proj1/traces/1234567890abcdef1234567890fedcba'.freeze
|
104
|
-
SPAN_ID = '000000000000004a'.freeze
|
105
|
-
SPAN_ID2 = '000000000000007e'.freeze
|
106
|
-
INSERT_ID = 'fah7yr7iw64tg857y'.freeze
|
107
|
-
INSERT_ID2 = 'fah7yr7iw64tgaeuf'.freeze
|
108
|
-
|
109
101
|
# Docker Container labels.
|
110
102
|
DOCKER_CONTAINER_ID =
|
111
103
|
'0d0f03ff8d3c42688692536d1af77a28cd135c0a5c531f25a31'.freeze
|
@@ -143,11 +135,20 @@ module Constants
|
|
143
135
|
".#{K8S_CONTAINER_NAME}".freeze
|
144
136
|
|
145
137
|
# Container Engine / Kubernetes specific labels.
|
138
|
+
CONTAINER_CLUSTER_NAME = 'cluster-1'.freeze
|
146
139
|
CONTAINER_NAMESPACE_ID = '898268c8-4a36-11e5-9d81-42010af0194c'.freeze
|
140
|
+
CONTAINER_NAMESPACE_NAME = 'kube-system'.freeze
|
147
141
|
CONTAINER_POD_ID = 'cad3c3c4-4b9c-11e5-9d81-42010af0194c'.freeze
|
142
|
+
CONTAINER_POD_NAME = 'redis-master-c0l82.foo.bar'.freeze
|
143
|
+
CONTAINER_CONTAINER_NAME = 'redis'.freeze
|
148
144
|
CONTAINER_LABEL_KEY = 'component'.freeze
|
149
145
|
CONTAINER_LABEL_VALUE = 'redis-component'.freeze
|
146
|
+
CONTAINER_STREAM = 'stdout'.freeze
|
150
147
|
CONTAINER_SEVERITY = 'INFO'.freeze
|
148
|
+
# Timestamp for 1234567890 seconds and 987654321 nanoseconds since epoch.
|
149
|
+
CONTAINER_TIMESTAMP = '2009-02-13T23:31:30.987654321Z'.freeze
|
150
|
+
CONTAINER_SECONDS_EPOCH = 1_234_567_890
|
151
|
+
CONTAINER_NANOS = 987_654_321
|
151
152
|
CONTAINER_LOCAL_RESOURCE_ID_PREFIX = 'gke_container'.freeze
|
152
153
|
|
153
154
|
# Cloud Functions specific labels.
|
@@ -399,27 +400,28 @@ module Constants
|
|
399
400
|
|
400
401
|
# GKE Container.
|
401
402
|
CONTAINER_TAG =
|
402
|
-
"kubernetes.#{
|
403
|
-
"#{
|
403
|
+
"kubernetes.#{CONTAINER_POD_NAME}_#{CONTAINER_NAMESPACE_NAME}_" \
|
404
|
+
"#{CONTAINER_CONTAINER_NAME}".freeze
|
404
405
|
|
405
406
|
CONTAINER_FROM_METADATA_PARAMS = {
|
406
407
|
resource: {
|
407
408
|
type: GKE_CONSTANTS[:resource_type],
|
408
409
|
labels: {
|
409
|
-
'cluster_name' =>
|
410
|
+
'cluster_name' => CONTAINER_CLUSTER_NAME,
|
410
411
|
'namespace_id' => CONTAINER_NAMESPACE_ID,
|
411
412
|
'instance_id' => VM_ID,
|
412
413
|
'pod_id' => CONTAINER_POD_ID,
|
413
|
-
'container_name' =>
|
414
|
+
'container_name' => CONTAINER_CONTAINER_NAME,
|
414
415
|
'zone' => ZONE
|
415
416
|
}
|
416
417
|
},
|
417
|
-
log_name:
|
418
|
+
log_name: CONTAINER_CONTAINER_NAME,
|
418
419
|
project_id: PROJECT_ID,
|
419
420
|
labels: {
|
420
|
-
"#{GKE_CONSTANTS[:service]}/namespace_name" =>
|
421
|
-
|
422
|
-
"#{GKE_CONSTANTS[:service]}/
|
421
|
+
"#{GKE_CONSTANTS[:service]}/namespace_name" =>
|
422
|
+
CONTAINER_NAMESPACE_NAME,
|
423
|
+
"#{GKE_CONSTANTS[:service]}/pod_name" => CONTAINER_POD_NAME,
|
424
|
+
"#{GKE_CONSTANTS[:service]}/stream" => CONTAINER_STREAM,
|
423
425
|
"label/#{CONTAINER_LABEL_KEY}" => CONTAINER_LABEL_VALUE,
|
424
426
|
"#{COMPUTE_CONSTANTS[:service]}/resource_name" => HOSTNAME
|
425
427
|
}
|
@@ -431,20 +433,21 @@ module Constants
|
|
431
433
|
resource: {
|
432
434
|
type: GKE_CONSTANTS[:resource_type],
|
433
435
|
labels: {
|
434
|
-
'cluster_name' =>
|
435
|
-
'namespace_id' =>
|
436
|
+
'cluster_name' => CONTAINER_CLUSTER_NAME,
|
437
|
+
'namespace_id' => CONTAINER_NAMESPACE_NAME,
|
436
438
|
'instance_id' => VM_ID,
|
437
|
-
'pod_id' =>
|
438
|
-
'container_name' =>
|
439
|
+
'pod_id' => CONTAINER_POD_NAME,
|
440
|
+
'container_name' => CONTAINER_CONTAINER_NAME,
|
439
441
|
'zone' => ZONE
|
440
442
|
}
|
441
443
|
},
|
442
|
-
log_name:
|
444
|
+
log_name: CONTAINER_CONTAINER_NAME,
|
443
445
|
project_id: PROJECT_ID,
|
444
446
|
labels: {
|
445
|
-
"#{GKE_CONSTANTS[:service]}/namespace_name" =>
|
446
|
-
|
447
|
-
"#{GKE_CONSTANTS[:service]}/
|
447
|
+
"#{GKE_CONSTANTS[:service]}/namespace_name" =>
|
448
|
+
CONTAINER_NAMESPACE_NAME,
|
449
|
+
"#{GKE_CONSTANTS[:service]}/pod_name" => CONTAINER_POD_NAME,
|
450
|
+
"#{GKE_CONSTANTS[:service]}/stream" => CONTAINER_STREAM,
|
448
451
|
"#{COMPUTE_CONSTANTS[:service]}/resource_name" => HOSTNAME
|
449
452
|
}
|
450
453
|
}.freeze
|
@@ -453,11 +456,11 @@ module Constants
|
|
453
456
|
resource: {
|
454
457
|
type: GKE_CONSTANTS[:resource_type],
|
455
458
|
labels: {
|
456
|
-
'cluster_name' =>
|
459
|
+
'cluster_name' => CONTAINER_CLUSTER_NAME,
|
457
460
|
'namespace_id' => CONTAINER_NAMESPACE_ID,
|
458
461
|
'instance_id' => VM_ID,
|
459
462
|
'pod_id' => CONTAINER_POD_ID,
|
460
|
-
'container_name' =>
|
463
|
+
'container_name' => CONTAINER_CONTAINER_NAME,
|
461
464
|
'zone' => ZONE
|
462
465
|
}
|
463
466
|
},
|
@@ -480,6 +483,7 @@ module Constants
|
|
480
483
|
'location' => K8S_LOCATION
|
481
484
|
}
|
482
485
|
},
|
486
|
+
log_name: 'test',
|
483
487
|
project_id: PROJECT_ID,
|
484
488
|
labels: {}
|
485
489
|
}.freeze
|
@@ -498,10 +502,6 @@ module Constants
|
|
498
502
|
)
|
499
503
|
)
|
500
504
|
).freeze
|
501
|
-
# Used in k8s fallback tests.
|
502
|
-
K8S_CONTAINER_PARAMS_FROM_FALLBACK = COMPUTE_PARAMS_NO_LOG_NAME.merge(
|
503
|
-
log_name: CONTAINER_TAG
|
504
|
-
).freeze
|
505
505
|
|
506
506
|
# K8s Node.
|
507
507
|
K8S_NODE_PARAMS = {
|
@@ -777,12 +777,12 @@ module Constants
|
|
777
777
|
}.to_json,
|
778
778
|
# GKE container logs.
|
779
779
|
"#{CONTAINER_LOCAL_RESOURCE_ID_PREFIX}.#{CONTAINER_NAMESPACE_ID}" \
|
780
|
-
".#{
|
780
|
+
".#{CONTAINER_POD_NAME}.#{CONTAINER_CONTAINER_NAME}" =>
|
781
781
|
{
|
782
782
|
'type' => GKE_CONSTANTS[:resource_type],
|
783
783
|
'labels' => {
|
784
|
-
'cluster_name' =>
|
785
|
-
'container_name' =>
|
784
|
+
'cluster_name' => CONTAINER_CLUSTER_NAME,
|
785
|
+
'container_name' => CONTAINER_CONTAINER_NAME,
|
786
786
|
'instance_id' => VM_ID,
|
787
787
|
'namespace_id' => CONTAINER_NAMESPACE_ID,
|
788
788
|
'pod_id' => CONTAINER_POD_ID,
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-google-cloud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0.pre.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Ling Huang
|
8
|
+
- Igor Peshansky
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2018-
|
12
|
+
date: 2018-08-24 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: fluentd
|
@@ -16,14 +17,14 @@ dependencies:
|
|
16
17
|
requirements:
|
17
18
|
- - "~>"
|
18
19
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
20
|
+
version: 1.2.5
|
20
21
|
type: :runtime
|
21
22
|
prerelease: false
|
22
23
|
version_requirements: !ruby/object:Gem::Requirement
|
23
24
|
requirements:
|
24
25
|
- - "~>"
|
25
26
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
27
|
+
version: 1.2.5
|
27
28
|
- !ruby/object:Gem::Dependency
|
28
29
|
name: googleapis-common-protos
|
29
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -106,14 +107,14 @@ dependencies:
|
|
106
107
|
requirements:
|
107
108
|
- - "~>"
|
108
109
|
- !ruby/object:Gem::Version
|
109
|
-
version: '
|
110
|
+
version: '1.8'
|
110
111
|
type: :runtime
|
111
112
|
prerelease: false
|
112
113
|
version_requirements: !ruby/object:Gem::Requirement
|
113
114
|
requirements:
|
114
115
|
- - "~>"
|
115
116
|
- !ruby/object:Gem::Version
|
116
|
-
version: '
|
117
|
+
version: '1.8'
|
117
118
|
- !ruby/object:Gem::Dependency
|
118
119
|
name: google-protobuf
|
119
120
|
requirement: !ruby/object:Gem::Requirement
|
@@ -219,9 +220,9 @@ dependencies:
|
|
219
220
|
- !ruby/object:Gem::Version
|
220
221
|
version: 0.7.1
|
221
222
|
description: |2
|
222
|
-
Fluentd
|
223
|
-
viewable in the
|
224
|
-
in Google Cloud Storage and/or BigQuery.
|
223
|
+
Fluentd output plugin for the Stackdriver Logging API, which will make
|
224
|
+
logs viewable in the Developer Console's log viewer and can optionally
|
225
|
+
store them in Google Cloud Storage and/or BigQuery.
|
225
226
|
This is an official Google Ruby gem.
|
226
227
|
email:
|
227
228
|
- stackdriver-agents@google.com
|
@@ -235,7 +236,6 @@ files:
|
|
235
236
|
- README.rdoc
|
236
237
|
- Rakefile
|
237
238
|
- fluent-plugin-google-cloud.gemspec
|
238
|
-
- lib/fluent/plugin/filter_add_insert_ids.rb
|
239
239
|
- lib/fluent/plugin/monitoring.rb
|
240
240
|
- lib/fluent/plugin/out_google_cloud.rb
|
241
241
|
- test/helper.rb
|
@@ -247,7 +247,6 @@ files:
|
|
247
247
|
- test/plugin/data/invalid_credentials.json
|
248
248
|
- test/plugin/data/new-style-credentials.json
|
249
249
|
- test/plugin/test_driver.rb
|
250
|
-
- test/plugin/test_filter_add_insert_ids.rb
|
251
250
|
- test/plugin/test_out_google_cloud.rb
|
252
251
|
- test/plugin/test_out_google_cloud_grpc.rb
|
253
252
|
homepage: https://github.com/GoogleCloudPlatform/fluent-plugin-google-cloud
|
@@ -265,15 +264,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
265
264
|
version: '2.2'
|
266
265
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
267
266
|
requirements:
|
268
|
-
- - "
|
267
|
+
- - ">"
|
269
268
|
- !ruby/object:Gem::Version
|
270
|
-
version:
|
269
|
+
version: 1.3.1
|
271
270
|
requirements: []
|
272
271
|
rubyforge_project:
|
273
272
|
rubygems_version: 2.6.14
|
274
273
|
signing_key:
|
275
274
|
specification_version: 4
|
276
|
-
summary: fluentd
|
275
|
+
summary: fluentd output plugin for the Stackdriver Logging API
|
277
276
|
test_files:
|
278
277
|
- test/helper.rb
|
279
278
|
- test/plugin/base_test.rb
|
@@ -284,6 +283,5 @@ test_files:
|
|
284
283
|
- test/plugin/data/invalid_credentials.json
|
285
284
|
- test/plugin/data/new-style-credentials.json
|
286
285
|
- test/plugin/test_driver.rb
|
287
|
-
- test/plugin/test_filter_add_insert_ids.rb
|
288
286
|
- test/plugin/test_out_google_cloud.rb
|
289
287
|
- test/plugin/test_out_google_cloud_grpc.rb
|
@@ -1,99 +0,0 @@
|
|
1
|
-
# Copyright 2018 Google Inc. All rights reserved.
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
module Fluent
|
16
|
-
# Fluentd filter plugin for adding insertIds to guarantee log entry order
|
17
|
-
# and uniqueness.
|
18
|
-
# Sample log entries enriched by this plugin:
|
19
|
-
# {
|
20
|
-
# "timestamp": "2017-08-22 13:35:28",
|
21
|
-
# "message": "1",
|
22
|
-
# "logging.googleapis.com/insertId": "aye7eakuf23h41aef0"
|
23
|
-
# }
|
24
|
-
# {
|
25
|
-
# "timestamp": "2017-08-22 13:35:28",
|
26
|
-
# "message": "2",
|
27
|
-
# "logging.googleapis.com/insertId": "aye7eakuf23h41aef1"
|
28
|
-
# }
|
29
|
-
# {
|
30
|
-
# "timestamp": "2017-08-22 13:35:28",
|
31
|
-
# "message": "3",
|
32
|
-
# "logging.googleapis.com/insertId": "aye7eakuf23h41aef2"
|
33
|
-
# }
|
34
|
-
class AddInsertIdsFilter < Filter
|
35
|
-
Fluent::Plugin.register_filter('add_insert_ids', self)
|
36
|
-
|
37
|
-
# Constants for configuration.
|
38
|
-
module ConfigConstants
|
39
|
-
# The default field name of insertIds in the log entry.
|
40
|
-
DEFAULT_INSERT_ID_KEY = 'logging.googleapis.com/insertId'.freeze
|
41
|
-
# The character size of the insertIds. This matches the setup in the
|
42
|
-
# Stackdriver Logging backend.
|
43
|
-
INSERT_ID_SIZE = 17
|
44
|
-
# The characters that are allowed in the insertIds. This matches the
|
45
|
-
# allowed collection by the Stackdriver Logging Backend.
|
46
|
-
ALLOWED_CHARS = (Array(0..9) + Array('a'..'z')).freeze
|
47
|
-
end
|
48
|
-
|
49
|
-
include self::ConfigConstants
|
50
|
-
|
51
|
-
desc 'The field name for insertIds in the log record.'
|
52
|
-
config_param :insert_id_key, :string, default: DEFAULT_INSERT_ID_KEY
|
53
|
-
|
54
|
-
# Expose attr_readers for testing.
|
55
|
-
attr_reader :insert_id_key
|
56
|
-
|
57
|
-
def start
|
58
|
-
super
|
59
|
-
@log = $log # rubocop:disable Style/GlobalVars
|
60
|
-
|
61
|
-
# Initialize the insertID.
|
62
|
-
@log.info "Started the add_insert_ids plugin with #{@insert_id_key}" \
|
63
|
-
' as the insert ID key.'
|
64
|
-
@insert_id = generate_initial_insert_id
|
65
|
-
@log.info "Initialized the insert ID key to #{@insert_id}."
|
66
|
-
end
|
67
|
-
|
68
|
-
def configure(conf)
|
69
|
-
super
|
70
|
-
end
|
71
|
-
|
72
|
-
def shutdown
|
73
|
-
super
|
74
|
-
end
|
75
|
-
|
76
|
-
# rubocop:disable Style/UnusedMethodArgument
|
77
|
-
def filter(tag, time, record)
|
78
|
-
# Only generate and add an insertId field if the record is a hash and
|
79
|
-
# the insert ID field is not already set (or set to an empty string).
|
80
|
-
if record.is_a?(Hash) && record[@insert_id_key].to_s.empty?
|
81
|
-
record[@insert_id_key] = increment_insert_id
|
82
|
-
end
|
83
|
-
record
|
84
|
-
end
|
85
|
-
# rubocop:enable Style/UnusedMethodArgument
|
86
|
-
|
87
|
-
private
|
88
|
-
|
89
|
-
# Generate a random string as the initial insertId.
|
90
|
-
def generate_initial_insert_id
|
91
|
-
Array.new(INSERT_ID_SIZE) { ALLOWED_CHARS.sample }.join
|
92
|
-
end
|
93
|
-
|
94
|
-
# Increment the insertId and return the new value.
|
95
|
-
def increment_insert_id
|
96
|
-
@insert_id = @insert_id.next
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
@@ -1,135 +0,0 @@
|
|
1
|
-
# Copyright 2018 Google Inc. All rights reserved.
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
require_relative '../helper'
|
16
|
-
|
17
|
-
require 'fluent/test/driver/filter'
|
18
|
-
require 'fluent/plugin/filter_add_insert_ids'
|
19
|
-
|
20
|
-
# Unit tests for filter_add_insert_ids plugin.
|
21
|
-
class FilterAddInsertIdsTest < Test::Unit::TestCase
|
22
|
-
include Fluent::AddInsertIdsFilter::ConfigConstants
|
23
|
-
|
24
|
-
CUSTOM_INSERT_ID_KEY = 'custom_insert_id_key'.freeze
|
25
|
-
INSERT_ID = 'aeyr82r92h249gh9h'.freeze
|
26
|
-
TEST_MESSAGE = 'test message for add_insert_ids plugin.'.freeze
|
27
|
-
APPLICATION_DEFAULT_CONFIG = ''.freeze
|
28
|
-
INSERT_ID_KEY_CONFIG = %(
|
29
|
-
insert_id_key #{CUSTOM_INSERT_ID_KEY}
|
30
|
-
).freeze
|
31
|
-
|
32
|
-
def setup
|
33
|
-
Fluent::Test.setup
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_configure_insert_id_key
|
37
|
-
{
|
38
|
-
APPLICATION_DEFAULT_CONFIG => DEFAULT_INSERT_ID_KEY,
|
39
|
-
INSERT_ID_KEY_CONFIG => CUSTOM_INSERT_ID_KEY
|
40
|
-
}.each do |config, insert_id_key|
|
41
|
-
d = create_driver(config)
|
42
|
-
assert_equal insert_id_key, d.instance.insert_id_key
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_add_insert_ids
|
47
|
-
total_entry_count = 1000
|
48
|
-
d = create_driver
|
49
|
-
d.run do
|
50
|
-
total_entry_count.times do |index|
|
51
|
-
d.emit(log_entry(index))
|
52
|
-
end
|
53
|
-
end
|
54
|
-
filtered_events = d.filtered_as_array
|
55
|
-
|
56
|
-
assert_equal total_entry_count, filtered_events.size,
|
57
|
-
"#{total_entry_count} log entries after filtering is" \
|
58
|
-
" expected. Only #{filtered_events.size} are detected."
|
59
|
-
# The expected insertId will be assigned as we scan the first log entry.
|
60
|
-
expected_insert_id = nil
|
61
|
-
unique_insert_ids = Set.new
|
62
|
-
filtered_events.each_with_index do |event, index|
|
63
|
-
assert_equal 3, event.size, "Index #{index} failed. Log event should" \
|
64
|
-
' include 3 elements: tag, time and record.'
|
65
|
-
record = event[2]
|
66
|
-
assert_true record.is_a?(Hash), "Index #{index} failed. Log record" \
|
67
|
-
" #{record} should be a hash."
|
68
|
-
assert_equal index, record['id'], "Index #{index} failed. Log entries" \
|
69
|
-
' should come in order.'
|
70
|
-
assert_equal TEST_MESSAGE, record['message'], "Index #{index} failed."
|
71
|
-
|
72
|
-
# Get the first insertID.
|
73
|
-
expected_insert_id = record[DEFAULT_INSERT_ID_KEY] if index == 0
|
74
|
-
insert_id = record[DEFAULT_INSERT_ID_KEY]
|
75
|
-
assert_equal expected_insert_id, insert_id, "Index #{index} failed."
|
76
|
-
expected_insert_id = expected_insert_id.next
|
77
|
-
assert_true insert_id < expected_insert_id,
|
78
|
-
"Index #{index} failed. #{insert_id}" \
|
79
|
-
" < #{expected_insert_id} is false."
|
80
|
-
unique_insert_ids << insert_id
|
81
|
-
end
|
82
|
-
assert_equal total_entry_count, unique_insert_ids.size,
|
83
|
-
"Expected #{total_entry_count} unique insertIds." \
|
84
|
-
" Only #{unique_insert_ids.size} found."
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_insert_ids_not_added_if_present
|
88
|
-
log_entry_with_empty_insert_id = log_entry(0).merge(
|
89
|
-
DEFAULT_INSERT_ID_KEY => '')
|
90
|
-
{
|
91
|
-
log_entry(0).merge(DEFAULT_INSERT_ID_KEY => INSERT_ID) => true,
|
92
|
-
# Still generate insertId if it's an empty string
|
93
|
-
log_entry_with_empty_insert_id => false
|
94
|
-
}.each do |test_data|
|
95
|
-
input_log_entry, retain_original_insert_id = test_data
|
96
|
-
# Make a copy because the log entry gets modified by the filter plugin.
|
97
|
-
log_entry = input_log_entry.dup
|
98
|
-
d = create_driver
|
99
|
-
d.run do
|
100
|
-
d.emit(log_entry)
|
101
|
-
end
|
102
|
-
filtered_events = d.filtered_as_array
|
103
|
-
|
104
|
-
assert_equal 1, filtered_events.size, 'Exact 1 log entry after' \
|
105
|
-
" filtering is expected. Test data: #{test_data}."
|
106
|
-
event = filtered_events[0]
|
107
|
-
assert_equal 3, event.size, 'Log event should include 3 elements: tag,' \
|
108
|
-
" time and record. Test data: #{test_data}."
|
109
|
-
record = event[2]
|
110
|
-
assert_true record.is_a?(Hash), "Log record #{record} should be a hash." \
|
111
|
-
" Test data: #{test_data}."
|
112
|
-
assert_equal 0, record['id'], "Test data: #{test_data}."
|
113
|
-
assert_equal TEST_MESSAGE, record['message'], "Test data: #{test_data}."
|
114
|
-
insert_id = record[DEFAULT_INSERT_ID_KEY]
|
115
|
-
assert_false insert_id.to_s.empty?, 'Insert ID should not be empty.' \
|
116
|
-
" Test data: #{test_data}."
|
117
|
-
assert_equal retain_original_insert_id,
|
118
|
-
input_log_entry[DEFAULT_INSERT_ID_KEY] == insert_id,
|
119
|
-
"Input value is #{input_log_entry[DEFAULT_INSERT_ID_KEY]}." \
|
120
|
-
" Output value is #{insert_id}. Test data: #{test_data}."
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
def create_driver(conf = APPLICATION_DEFAULT_CONFIG)
|
125
|
-
Fluent::Test::FilterTestDriver.new(
|
126
|
-
Fluent::AddInsertIdsFilter).configure(conf, true)
|
127
|
-
end
|
128
|
-
|
129
|
-
def log_entry(index)
|
130
|
-
{
|
131
|
-
'id' => index,
|
132
|
-
'message' => TEST_MESSAGE
|
133
|
-
}
|
134
|
-
end
|
135
|
-
end
|