Skip to content

Commit

Permalink
start working on tests for recipes
Browse files Browse the repository at this point in the history
  • Loading branch information
jordansissel committed Oct 27, 2012
1 parent 0e93090 commit fee99b2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
15 changes: 8 additions & 7 deletions recipes/mysql/mysql-slow.conf
@@ -1,16 +1,17 @@
filter { filter {
grok { grok {
type => "mysql-slow" type => "mysql-slow"
singles => true
pattern => [ pattern => [
"^# User@Host: %{USER:user}\[[^\]]+\] @ %{HOST:host} \[%{IP:ip}]", "^# User@Host: %{USER:user}(?>\[[^\]]+\])? @ %{HOST:host} \[%{IP:ip}?\]",
"^# Query_time: %{NUMBER:duration:float} Lock_time: %{NUMBER:lock_wait:float} Rows_sent: %{NUMBER:results:int} \s*Rows_examined: %{NUMBER:scanned:int}", "^# Query_time: %{NUMBER:duration:float} Lock_time: %{NUMBER:lock_wait:float} Rows_sent: %{NUMBER:results:int} \s*Rows_examined: %{NUMBER:scanned:int}",
"^SET timestamp=%{NUMBER:timestamp};" "^SET timestamp=%{NUMBER:timestamp};"
] ]
} }


multiline { multiline {
type => "mysql-slow" type => "mysql-slow"
match => "^# Time: " pattern => "^# Time: "
what => next what => next
} }


Expand All @@ -23,11 +24,11 @@ filter {


date { date {
type => "mysql-slow" type => "mysql-slow"
timestamp => UNIXEPOCH timestamp => UNIX
} }


mutate { #mutate {
type => "mysql-slow" #type => "mysql-slow"
remove => "timestamp" #remove => "timestamp"
} #}
} }
38 changes: 38 additions & 0 deletions recipes/mysql/test.rb
@@ -0,0 +1,38 @@
require "ap"
describe "mysql logs" do
extend LogStash::RSpec

describe "slow query log" do
# The logstash config goes here.
# At this time, only filters are supported.
config File.read("mysql-slow.conf")

data = File.open(__FILE__)
data.each { |line| break if line == "__END__\n" }

events = data.collect do |line|
LogStash::Event.new("@message" => line.chomp, "@type" => "mysql-slow")
end

sample events do
event = subject.first
#ap event.to_hash
insist { subject["user"] } == "amavis"
insist { subject["host"] } == "randomhost.local"
insist { subject["ip"] } == "10.1.22.33"
insist { subject["duration"] } == 114
insist { subject["lock_wait"] } == 0
insist { subject["results"] } == 25856
insist { subject["scanned"] } == 10864578
insist { subject.timestamp } == "2012-10-25T15:40:26.000Z"
end
end
end

__END__
# Time: 121025 15:40:26
# User@Host: amavis[amavis] @ [10.3.67.54]
# Query_time: 114 Lock_time: 0 Rows_sent: 25856 Rows_examined: 10864578
SET timestamp=1351204826;
/* amavis cleanquarantine N:D:S:Amavis 175 */ select msg_headers.id, filename from msg_headers, users where (users.id=msg_headers.user_id) and (date_add(storetime, interval retention day) < now());

0 comments on commit fee99b2

Please sign in to comment.