daikon 0.7.6 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +23 -4
- data/daikon.gemspec +3 -2
- data/lib/daikon.rb +3 -1
- data/lib/daikon/client.rb +1 -1
- data/lib/daikon/configuration.rb +32 -9
- data/lib/daikon/daemons_hacks.rb +14 -0
- data/spec/client_spec.rb +15 -6
- data/spec/configuration_spec.rb +16 -14
- metadata +3 -2
data/README.rdoc
CHANGED
@@ -1,10 +1,29 @@
|
|
1
1
|
= daikon
|
2
2
|
|
3
|
-
|
3
|
+
Dig deep into Redis. This is a client daemon for http://radishapp.com.
|
4
4
|
|
5
|
-
|
5
|
+
== Setup
|
6
|
+
|
7
|
+
Hook up Radish to your Redis instance like so, this will start a daemon up in
|
8
|
+
your current directory:
|
9
|
+
|
10
|
+
daikon start -- -k 1234567890
|
11
|
+
|
12
|
+
If you want to just test it out and run in the foreground:
|
13
|
+
|
14
|
+
daikon run -- -k 1234567890
|
15
|
+
|
16
|
+
Your redis is on a different port, box, or has a password? No problem, use the
|
17
|
+
-u option that takes a standard Redis url:
|
18
|
+
|
19
|
+
daikon start -- -k 1234567890 -u redis://4.2.2.2:9999
|
20
|
+
|
21
|
+
== Issues
|
22
|
+
|
23
|
+
If you need to run more than one Daikon instance to monitor more than one
|
24
|
+
Redis, the current workaround is to `cd` into different directories and start
|
25
|
+
a Daikon for each instance. Patches welcome for this!
|
6
26
|
|
7
27
|
== Copyright
|
8
28
|
|
9
|
-
Copyright (c) 2010 Nick Quaranto. See LICENSE.txt for
|
10
|
-
further details.
|
29
|
+
Copyright (c) 2010-2011 thoughtbot, Nick Quaranto. See LICENSE.txt for further details.
|
data/daikon.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{daikon}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.8.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Nick Quaranto"]
|
12
|
-
s.date = %q{2011-03-
|
12
|
+
s.date = %q{2011-03-17}
|
13
13
|
s.default_executable = %q{daikon}
|
14
14
|
s.description = %q{daikon, a radishapp.com client}
|
15
15
|
s.email = %q{nick@quaran.to}
|
@@ -31,6 +31,7 @@ Gem::Specification.new do |s|
|
|
31
31
|
"lib/daikon/client.rb",
|
32
32
|
"lib/daikon/configuration.rb",
|
33
33
|
"lib/daikon/daemon.rb",
|
34
|
+
"lib/daikon/daemons_hacks.rb",
|
34
35
|
"lib/daikon/monitor.rb",
|
35
36
|
"lib/daikon/redis_hacks.rb",
|
36
37
|
"spec/client_spec.rb",
|
data/lib/daikon.rb
CHANGED
data/lib/daikon/client.rb
CHANGED
data/lib/daikon/configuration.rb
CHANGED
@@ -1,26 +1,49 @@
|
|
1
1
|
module Daikon
|
2
2
|
class Configuration
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
BLANK_KEY = "1234567890"
|
4
|
+
FLAGS = ["-u", "-k", "-s"]
|
5
|
+
OPTIONS = ["redis_url", "api_key", "server_prefix"]
|
6
|
+
DEFAULTS = ["redis://0.0.0.0:6379", BLANK_KEY, "https://radish.heroku.com"]
|
6
7
|
|
7
8
|
attr_accessor *OPTIONS
|
8
9
|
|
9
10
|
def initialize(argv = [])
|
11
|
+
@argv = argv
|
12
|
+
|
13
|
+
validate_deprecated_options
|
14
|
+
parse
|
15
|
+
validate_api_key
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def argv_matches?(regexp)
|
21
|
+
@argv.any? { |arg| arg =~ regexp }
|
22
|
+
end
|
23
|
+
|
24
|
+
def validate_deprecated_options
|
25
|
+
if argv_matches?(/\-h|\-p/)
|
26
|
+
abort "Please use '-u redis://127.0.0.1:6379' format instead to specify redis url"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def validate_api_key
|
31
|
+
if api_key == BLANK_KEY && argv_matches?(/start|run/)
|
32
|
+
abort "Must supply an api key to start the daemon.\nExample: daikon start #{FLAGS[2]} #{DEFAULTS[2]}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def parse
|
10
37
|
FLAGS.each_with_index do |flag, flag_index|
|
11
|
-
argv_index = argv.index(flag)
|
38
|
+
argv_index = @argv.index(flag)
|
12
39
|
value = if argv_index
|
13
|
-
argv[argv_index + 1]
|
40
|
+
@argv[argv_index + 1]
|
14
41
|
else
|
15
42
|
DEFAULTS[flag_index]
|
16
43
|
end
|
17
44
|
|
18
45
|
send "#{OPTIONS[flag_index]}=", value
|
19
46
|
end
|
20
|
-
|
21
|
-
if api_key == DEFAULTS[2] && argv.any? { |arg| arg =~ /start|run/ }
|
22
|
-
abort "Must supply an api key to start the daemon.\nExample: daikon start #{FLAGS[2]} #{DEFAULTS[2]}"
|
23
|
-
end
|
24
47
|
end
|
25
48
|
end
|
26
49
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# More terrible overrides since the Daemons gem offers no way to override how
|
2
|
+
# its output is formatted.
|
3
|
+
module Daemons
|
4
|
+
class Controller
|
5
|
+
def print_usage_with_daikon_options
|
6
|
+
print_usage_without_daikon_options
|
7
|
+
puts " -k 1234567890 radishapp.com api key"
|
8
|
+
puts " -u redis://0.0.0.0:6379 redis URL to monitor"
|
9
|
+
end
|
10
|
+
|
11
|
+
alias_method :print_usage_without_daikon_options, :print_usage
|
12
|
+
alias_method :print_usage, :print_usage_with_daikon_options
|
13
|
+
end
|
14
|
+
end
|
data/spec/client_spec.rb
CHANGED
@@ -6,19 +6,20 @@ describe Daikon::Client, "setup" do
|
|
6
6
|
let(:redis) { 'redis instance' }
|
7
7
|
|
8
8
|
before do
|
9
|
-
Redis.stubs(:
|
9
|
+
Redis.stubs(:connect => redis)
|
10
10
|
subject.stubs(:redis=)
|
11
11
|
end
|
12
12
|
|
13
13
|
context "with overrides" do
|
14
|
-
let(:
|
14
|
+
let(:url) { "redis://8.8.8.8:1234" }
|
15
|
+
let(:config) { Daikon::Configuration.new(["-u", url]) }
|
15
16
|
|
16
17
|
before do
|
17
18
|
subject.setup(config, logger)
|
18
19
|
end
|
19
20
|
|
20
21
|
it "sets redis to listen on the given port" do
|
21
|
-
Redis.should have_received(:
|
22
|
+
Redis.should have_received(:connect).with(:url => url).twice
|
22
23
|
subject.should have_received(:redis=).with(redis)
|
23
24
|
end
|
24
25
|
end
|
@@ -31,7 +32,7 @@ describe Daikon::Client, "setup" do
|
|
31
32
|
end
|
32
33
|
|
33
34
|
it "sets redis to listen on the given port" do
|
34
|
-
Redis.should have_received(:
|
35
|
+
Redis.should have_received(:connect).with(:url => "redis://0.0.0.0:6379").twice
|
35
36
|
subject.should have_received(:redis=).with(redis)
|
36
37
|
end
|
37
38
|
end
|
@@ -39,11 +40,15 @@ end
|
|
39
40
|
|
40
41
|
describe Daikon::Client, "when server is down" do
|
41
42
|
subject { Daikon::Client.new }
|
43
|
+
let(:redis) { stub("redis instance", :info => {}) }
|
44
|
+
|
42
45
|
before do
|
43
|
-
|
46
|
+
Redis.stubs(:connect => redis)
|
44
47
|
http = stub("http", :reset => nil)
|
45
48
|
http.stubs(:request).raises(Timeout::Error)
|
46
49
|
subject.stubs(:http => http)
|
50
|
+
|
51
|
+
subject.setup(Daikon::Configuration.new)
|
47
52
|
end
|
48
53
|
|
49
54
|
it "does not commit suicide" do
|
@@ -55,10 +60,14 @@ end
|
|
55
60
|
|
56
61
|
describe Daikon::Client, "when it returns bad json" do
|
57
62
|
subject { Daikon::Client.new }
|
63
|
+
let(:redis) { stub("redis instance", :info => {}) }
|
64
|
+
|
58
65
|
before do
|
59
|
-
|
66
|
+
Redis.stubs(:connect => redis)
|
60
67
|
http = stub("http", :request => Excon::Response.new(:body => "{'bad':'json}"), :reset => nil)
|
61
68
|
subject.stubs(:http => http)
|
69
|
+
|
70
|
+
subject.setup(Daikon::Configuration.new)
|
62
71
|
end
|
63
72
|
|
64
73
|
it "does not commit suicide" do
|
data/spec/configuration_spec.rb
CHANGED
@@ -2,13 +2,11 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Daikon::Configuration do
|
4
4
|
subject { Daikon::Configuration.new(flags) }
|
5
|
-
let(:flags) { %w[-
|
5
|
+
let(:flags) { %w[-u redis://4.2.2.2:9001 -k deadbeef -s localhost:9337] }
|
6
6
|
|
7
7
|
it "parses the given flags" do
|
8
|
-
subject.
|
9
|
-
subject.redis_port.should == "9001"
|
8
|
+
subject.redis_url.should == "redis://4.2.2.2:9001"
|
10
9
|
subject.api_key.should == "deadbeef"
|
11
|
-
subject.field_id.should == "1337"
|
12
10
|
subject.server_prefix == "localhost:9337"
|
13
11
|
end
|
14
12
|
end
|
@@ -17,10 +15,8 @@ describe Daikon::Configuration do
|
|
17
15
|
subject { Daikon::Configuration.new(%w[-k 1234567890]) }
|
18
16
|
|
19
17
|
it "uses the default keys" do
|
20
|
-
subject.
|
21
|
-
subject.redis_port.should == "6379"
|
18
|
+
subject.redis_url.should == "redis://0.0.0.0:6379"
|
22
19
|
subject.api_key.should == "1234567890"
|
23
|
-
subject.field_id.should == "1"
|
24
20
|
subject.server_prefix == "radish.heroku.com"
|
25
21
|
end
|
26
22
|
end
|
@@ -44,13 +40,19 @@ describe Daikon::Configuration do
|
|
44
40
|
end
|
45
41
|
|
46
42
|
describe Daikon::Configuration do
|
47
|
-
|
48
|
-
|
43
|
+
it "fails if -h option given" do
|
44
|
+
capture do
|
45
|
+
lambda {
|
46
|
+
Daikon::Configuration.new(%w[-h 8.8.8.8])
|
47
|
+
}.should raise_error(SystemExit)
|
48
|
+
end
|
49
|
+
end
|
49
50
|
|
50
|
-
it "
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
51
|
+
it "fails if -p option given" do
|
52
|
+
capture do
|
53
|
+
lambda {
|
54
|
+
Daikon::Configuration.new(%w[-p 6380])
|
55
|
+
}.should raise_error(SystemExit)
|
56
|
+
end
|
55
57
|
end
|
56
58
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: daikon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.8.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Nick Quaranto
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-03-
|
13
|
+
date: 2011-03-17 00:00:00 -06:00
|
14
14
|
default_executable: daikon
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -134,6 +134,7 @@ files:
|
|
134
134
|
- lib/daikon/client.rb
|
135
135
|
- lib/daikon/configuration.rb
|
136
136
|
- lib/daikon/daemon.rb
|
137
|
+
- lib/daikon/daemons_hacks.rb
|
137
138
|
- lib/daikon/monitor.rb
|
138
139
|
- lib/daikon/redis_hacks.rb
|
139
140
|
- spec/client_spec.rb
|