mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 22:57:16 -04:00
Raise configuration error when invalid rates are set
This commit is contained in:
parent
0a5fcb7454
commit
74de9b6d32
2 changed files with 37 additions and 0 deletions
|
@ -142,6 +142,9 @@ class LogStash::Filters::Metrics < LogStash::Filters::Base
|
|||
@last_flush = 0 # how many seconds ago the metrics where flushed.
|
||||
@last_clear = 0 # how many seconds ago the metrics where cleared.
|
||||
@random_key_preffix = SecureRandom.hex
|
||||
unless (@rates - [1, 5, 15]).empty?
|
||||
raise LogStash::ConfigurationError, "Invalid rates configuration. possible rates are 1, 5, 15. Rates: #{rates}."
|
||||
end
|
||||
initialize_metrics
|
||||
end # def register
|
||||
|
||||
|
|
|
@ -58,6 +58,29 @@ describe LogStash::Filters::Metrics do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when custom rates and percentiles are selected" do
|
||||
context "on the first flush" do
|
||||
subject {
|
||||
config = {
|
||||
"meter" => ["http.%{response}"],
|
||||
"rates" => [1]
|
||||
}
|
||||
filter = LogStash::Filters::Metrics.new config
|
||||
filter.register
|
||||
filter.filter LogStash::Event.new({"response" => 200})
|
||||
filter.filter LogStash::Event.new({"response" => 200})
|
||||
filter.filter LogStash::Event.new({"response" => 404})
|
||||
filter.flush
|
||||
}
|
||||
|
||||
it "should include only the requested rates" do
|
||||
rate_fields = subject.first.to_hash.keys.select {|field| field.start_with?("http.200.rate") }
|
||||
insist { rate_fields.length } == 1
|
||||
insist { rate_fields }.include? "http.200.rate_1m"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "with multiple instances" do
|
||||
|
@ -175,4 +198,15 @@ describe LogStash::Filters::Metrics do
|
|||
insist { filter.flush }.nil? # 20s
|
||||
end
|
||||
end
|
||||
|
||||
context "when invalid rates are set" do
|
||||
subject {
|
||||
config = {"meter" => ["http.%{response}"], "rates" => [90]}
|
||||
filter = LogStash::Filters::Metrics.new config
|
||||
}
|
||||
|
||||
it "should raise an error" do
|
||||
insist {subject.register }.raises(LogStash::ConfigurationError)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue