mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 22:57:16 -04:00
- fix range filter specs
This commit is contained in:
parent
e58845f34d
commit
2c950fb585
2 changed files with 38 additions and 60 deletions
|
@ -21,10 +21,10 @@ class LogStash::Filters::Range < LogStash::Filters::Base
|
|||
#
|
||||
# filter {
|
||||
# %PLUGIN% {
|
||||
# ranges => [ "@message", 0, 10, "tag:short",
|
||||
# "@message", 11, 100, "tag:medium",
|
||||
# "@message", 101, 1000, "tag:long",
|
||||
# "@message", 1001, 1e1000, "drop",
|
||||
# ranges => [ "message", 0, 10, "tag:short",
|
||||
# "message", 11, 100, "tag:medium",
|
||||
# "message", 101, 1000, "tag:long",
|
||||
# "message", 1001, 1e1000, "drop",
|
||||
# "duration", 0, 100, "field:latency:fast",
|
||||
# "duration", 101, 200, "field:latency:normal",
|
||||
# "duration", 201, 1000, "field:latency:slow",
|
||||
|
@ -120,7 +120,7 @@ class LogStash::Filters::Range < LogStash::Filters::Base
|
|||
when :add_tag
|
||||
@logger.debug? and @logger.debug("#{self.class.name}: adding tag due to range match",
|
||||
:event => event, :tag => range[:action][:tag] )
|
||||
event.tags << event.sprintf(range[:action][:tag])
|
||||
event.tag(event.sprintf(range[:action][:tag]))
|
||||
when :add_field
|
||||
@logger.debug? and @logger.debug("#{self.class.name}: adding field due to range match",
|
||||
:event => event, :field => range[:action][:field], :value => range[:action][:value])
|
||||
|
|
|
@ -14,11 +14,9 @@ describe LogStash::Filters::Range do
|
|||
}
|
||||
CONFIG
|
||||
|
||||
sample "@fields" => {
|
||||
"duration" => 50
|
||||
} do
|
||||
insist { subject["@tags"] }.include?("cool")
|
||||
reject { subject["@tags"] }.include?("boring")
|
||||
sample("duration" => 50) do
|
||||
insist { subject["tags"] }.include?("cool")
|
||||
reject { subject["tags"] }.include?("boring")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -32,11 +30,9 @@ describe LogStash::Filters::Range do
|
|||
}
|
||||
CONFIG
|
||||
|
||||
sample "@fields" => {
|
||||
"duration" => 50.0
|
||||
} do
|
||||
insist { subject["@tags"] }.include?("cool")
|
||||
reject { subject["@tags"] }.include?("boring")
|
||||
sample("duration" => 50.0) do
|
||||
insist { subject["tags"] }.include?("cool")
|
||||
reject { subject["tags"] }.include?("boring")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -50,11 +46,9 @@ describe LogStash::Filters::Range do
|
|||
}
|
||||
CONFIG
|
||||
|
||||
sample "@fields" => {
|
||||
"length" => "123456789"
|
||||
} do
|
||||
insist { subject["@tags"] }.include?("cool")
|
||||
reject { subject["@tags"] }.include?("boring")
|
||||
sample("length" => "123456789") do
|
||||
insist { subject["tags"] }.include?("cool")
|
||||
reject { subject["tags"] }.include?("boring")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -69,11 +63,9 @@ describe LogStash::Filters::Range do
|
|||
}
|
||||
CONFIG
|
||||
|
||||
sample "@fields" => {
|
||||
"length" => "123456789"
|
||||
} do
|
||||
reject { subject["@tags"] }.include?("cool")
|
||||
insist { subject["@tags"] }.include?("boring")
|
||||
sample("length" => "123456789") do
|
||||
reject { subject["tags"] }.include?("cool")
|
||||
insist { subject["tags"] }.include?("boring")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -86,9 +78,7 @@ describe LogStash::Filters::Range do
|
|||
}
|
||||
CONFIG
|
||||
|
||||
sample "@fields" => {
|
||||
"length" => "123456789"
|
||||
} do
|
||||
sample("length" => "123456789") do
|
||||
insist { subject }.nil?
|
||||
end
|
||||
end
|
||||
|
@ -103,12 +93,10 @@ describe LogStash::Filters::Range do
|
|||
}
|
||||
CONFIG
|
||||
|
||||
sample "@fields" => {
|
||||
"duration" => 50
|
||||
} do
|
||||
insist { subject["@fields"] }.include?("cool")
|
||||
insist { subject["@fields"]["cool"] } == "foo"
|
||||
reject { subject["@fields"] }.include?("boring")
|
||||
sample("duration" => 50) do
|
||||
insist { subject }.include?("cool")
|
||||
insist { subject["cool"] } == "foo"
|
||||
reject { subject }.include?("boring")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -122,12 +110,10 @@ describe LogStash::Filters::Range do
|
|||
}
|
||||
CONFIG
|
||||
|
||||
sample "@fields" => {
|
||||
"duration" => 50
|
||||
} do
|
||||
insist { subject["@fields"] }.include?("cool")
|
||||
insist { subject["@fields"]["cool"] } == 666
|
||||
reject { subject["@fields"] }.include?("boring")
|
||||
sample("duration" => 50) do
|
||||
insist { subject }.include?("cool")
|
||||
insist { subject["cool"] } == 666
|
||||
reject { subject }.include?("boring")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -141,12 +127,10 @@ describe LogStash::Filters::Range do
|
|||
}
|
||||
CONFIG
|
||||
|
||||
sample "@fields" => {
|
||||
"duration" => 50
|
||||
} do
|
||||
insist { subject["@fields"] }.include?("cool")
|
||||
insist { subject["@fields"]["cool"] } == 3.14
|
||||
reject { subject["@fields"] }.include?("boring")
|
||||
sample("duration" => 50) do
|
||||
insist { subject }.include?("cool")
|
||||
insist { subject["cool"] } == 3.14
|
||||
reject { subject }.include?("boring")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -160,12 +144,9 @@ describe LogStash::Filters::Range do
|
|||
}
|
||||
CONFIG
|
||||
|
||||
sample "@fields" => {
|
||||
"duration" => 50,
|
||||
"dynamic" => "and"
|
||||
} do
|
||||
insist { subject["@tags"] }.include?("cool_and_dynamic")
|
||||
reject { subject["@tags"] }.include?("boring_and_dynamic")
|
||||
sample("duration" => 50, "dynamic" => "and") do
|
||||
insist { subject["tags"] }.include?("cool_and_dynamic")
|
||||
reject { subject["tags"] }.include?("boring_and_dynamic")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -179,13 +160,10 @@ describe LogStash::Filters::Range do
|
|||
}
|
||||
CONFIG
|
||||
|
||||
sample "@fields" => {
|
||||
"duration" => 50,
|
||||
"dynamic" => "and"
|
||||
} do
|
||||
insist { subject["@fields"] }.include?("cool_and_dynamic")
|
||||
insist { subject["@fields"]["cool_and_dynamic"] } == "foo_and_bar"
|
||||
reject { subject["@fields"] }.include?("boring_and_dynamic")
|
||||
sample("duration" => 50, "dynamic" => "and") do
|
||||
insist { subject }.include?("cool_and_dynamic")
|
||||
insist { subject["cool_and_dynamic"] } == "foo_and_bar"
|
||||
reject { subject }.include?("boring_and_dynamic")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue