mirror of
https://github.com/elastic/logstash.git
synced 2025-04-23 22:27:21 -04:00
Adding tests for the heap calculation, also changed the visibility
In retrospect, it just easier to expose the methods in the jvm spec monitoring to be able to test them in isolation. Fixes #6827
This commit is contained in:
parent
dee7c19746
commit
918f2bae21
2 changed files with 44 additions and 13 deletions
|
@ -34,6 +34,13 @@ module LogStash module Instrument module PeriodicPoller
|
|||
end
|
||||
end
|
||||
|
||||
MEMORY_TRANSPOSE_MAP = {
|
||||
"usage.used" => :used_in_bytes,
|
||||
"usage.committed" => :committed_in_bytes,
|
||||
"usage.max" => :max_in_bytes,
|
||||
"peak.max" => :peak_max_in_bytes,
|
||||
"peak.used" => :peak_used_in_bytes
|
||||
}
|
||||
|
||||
attr_reader :metric
|
||||
|
||||
|
@ -52,8 +59,6 @@ module LogStash module Instrument module PeriodicPoller
|
|||
collect_load_average
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def collect_gc_stats
|
||||
garbage_collectors = ManagementFactory.getGarbageCollectorMXBeans()
|
||||
|
||||
|
@ -141,7 +146,6 @@ module LogStash module Instrument module PeriodicPoller
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
def build_pools_metrics(data)
|
||||
heap = data["heap"]
|
||||
old = {}
|
||||
|
@ -161,19 +165,11 @@ module LogStash module Instrument module PeriodicPoller
|
|||
end
|
||||
|
||||
def aggregate_information_for(collection)
|
||||
transpose_map = {
|
||||
"usage.used" => :used_in_bytes,
|
||||
"usage.committed" => :committed_in_bytes,
|
||||
"usage.max" => :max_in_bytes,
|
||||
"peak.max" => :peak_max_in_bytes,
|
||||
"peak.used" => :peak_used_in_bytes
|
||||
|
||||
}
|
||||
collection.reduce(default_information_accumulator) do |m,e|
|
||||
e = { e[0] => e[1] } if e.is_a?(Array)
|
||||
e.each_pair do |k,v|
|
||||
if transpose_map.include?(k)
|
||||
transpose_key = transpose_map[k]
|
||||
if MEMORY_TRANSPOSE_MAP.include?(k)
|
||||
transpose_key = MEMORY_TRANSPOSE_MAP[k]
|
||||
m[transpose_key] += v
|
||||
end
|
||||
end
|
||||
|
|
|
@ -54,6 +54,41 @@ describe LogStash::Instrument::PeriodicPoller::JVM do
|
|||
end
|
||||
end
|
||||
|
||||
describe "aggregate heap information" do
|
||||
shared_examples "heap_information" do
|
||||
let(:data_set) do
|
||||
{
|
||||
"usage.used" => 5,
|
||||
"usage.committed" => 11,
|
||||
"usage.max" => 21,
|
||||
"peak.max" => 51,
|
||||
"peak.used" => 61
|
||||
}
|
||||
end
|
||||
let(:collection) { [data_set] }
|
||||
|
||||
it "return the right values" do
|
||||
expect(subject.aggregate_information_for(collection)).to match({
|
||||
:used_in_bytes => 5 * collection.size,
|
||||
:committed_in_bytes => 11 * collection.size,
|
||||
:max_in_bytes => 21 * collection.size,
|
||||
:peak_max_in_bytes => 51 * collection.size,
|
||||
:peak_used_in_bytes => 61 * collection.size
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
context "with only one data set in a collection" do
|
||||
include_examples "heap_information"
|
||||
end
|
||||
|
||||
context "with multiples data set in a collection" do
|
||||
include_examples "heap_information" do
|
||||
let(:collection) { ar = []; ar << data_set; ar << data_set; ar }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "collections" do
|
||||
subject(:collection) { jvm.collect }
|
||||
it "should run cleanly" do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue