Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not attach empty 'node' metadata #54

Merged
merged 2 commits into from
Dec 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vendor
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def decorate_record(record)
service = @pods_to_services[pod_name] unless @pods_to_services.nil?
metadata['service'] = {'service' => service.sort!.join('_')} if !(service.nil? || service.empty?)

if @data_type == 'metrics' && (record['node'].nil? || record['node'] == "")
if @data_type == 'metrics' && (record['node'].nil? || record['node'] == "") && !metadata['node'].nil?
record['node'] = metadata['node']
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,25 @@ class EnhanceK8sMetadataFilterTest < Test::Unit::TestCase
driver = create_driver(conf)

input_record = get_test_record[2]
assert_nil input_record['node']
assert_false input_record.key?('node')
record = driver.filter('tag', 'time', input_record)

assert_equal 'ip-172-20-62-242.us-west-1.compute.internal', record['node']
end

test 'do not attach node metadata to metrics when not found' do
conf = %{
kubernetes_url http://localhost:8080
data_type metrics
}
driver = create_driver(conf)

input_record = get_test_record[3]
assert_false input_record.key?('node')
record = driver.filter('tag', 'time', input_record)

assert_false record.key?('node')
end
end

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
"@metric": "http_request_size_bytes_sum",
"@timestamp": 1550862304339,
"@value": 1619905.0
},
{
"pod": "nonexistent-pod",
"namespace": "non-exist"
}
]
}
}