observed 0.1.1 → 0.2.0.rc1
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.
- checksums.yaml +9 -9
- data/.travis.yml +4 -0
- data/README.md +53 -78
- data/examples/observed.rb +1 -1
- data/exe/observed-oneshot +3 -1
- data/features/explicit_routing.feature +33 -0
- data/features/oneshot.feature +4 -0
- data/features/test_in_single_ruby_source.feature +4 -0
- data/integrations/observed-clockwork/features/run_observed_inside_clockwork.feature +6 -7
- data/integrations/observed-clockwork/lib/observed/clockwork/version.rb +1 -1
- data/integrations/observed-clockwork/lib/observed/clockwork.rb +0 -1
- data/integrations/observed-clockwork/observed-clockwork.gemspec +1 -1
- data/integrations/observed-eventmachine/.gitignore +17 -0
- data/integrations/observed-eventmachine/Gemfile +8 -0
- data/integrations/observed-eventmachine/LICENSE.txt +22 -0
- data/integrations/observed-eventmachine/README.md +29 -0
- data/integrations/observed-eventmachine/Rakefile +1 -0
- data/integrations/observed-eventmachine/examples/observed.rb +30 -0
- data/integrations/observed-eventmachine/features/integration_via_single_ruby_source.feature +48 -0
- data/integrations/observed-eventmachine/features/support/env.rb +8 -0
- data/integrations/observed-eventmachine/lib/observed/eventmachine/version.rb +5 -0
- data/integrations/observed-eventmachine/lib/observed/eventmachine.rb +70 -0
- data/integrations/observed-eventmachine/observed-eventmachine.gemspec +28 -0
- data/lib/observed/application/oneshot.rb +14 -37
- data/lib/observed/builtin_plugins/file.rb +5 -14
- data/lib/observed/builtin_plugins/stdout.rb +7 -14
- data/lib/observed/config.rb +4 -4
- data/lib/observed/config_builder.rb +154 -87
- data/lib/observed/config_dsl.rb +2 -8
- data/lib/observed/configurable.rb +61 -3
- data/lib/observed/context.rb +90 -0
- data/lib/observed/default/observer.rb +2 -5
- data/lib/observed/default.rb +0 -1
- data/lib/observed/event_bus.rb +31 -0
- data/lib/observed/execution_job_factory.rb +95 -0
- data/lib/observed/job.rb +163 -0
- data/lib/observed/jobbed_event_bus.rb +33 -0
- data/lib/observed/logging.rb +40 -0
- data/lib/observed/observer.rb +1 -0
- data/lib/observed/observer_helpers/timer.rb +13 -5
- data/lib/observed/pluggable.rb +11 -0
- data/lib/observed/reporter/regexp_matching.rb +2 -1
- data/lib/observed/reporter/report_formatting.rb +57 -0
- data/lib/observed/reporter.rb +0 -2
- data/lib/observed/system.rb +11 -78
- data/lib/observed/translator.rb +22 -0
- data/lib/observed/version.rb +1 -1
- data/lib/observed.rb +10 -12
- data/omnibus-observed/.gitignore +9 -0
- data/omnibus-observed/Berksfile +3 -0
- data/omnibus-observed/Berksfile.lock +52 -0
- data/omnibus-observed/Gemfile +4 -0
- data/omnibus-observed/README.md +102 -0
- data/omnibus-observed/Vagrantfile +93 -0
- data/omnibus-observed/config/projects/observed.rb +20 -0
- data/omnibus-observed/config/software/observed.rb +19 -0
- data/omnibus-observed/package-scripts/observed/makeselfinst +27 -0
- data/omnibus-observed/package-scripts/observed/postinst +17 -0
- data/omnibus-observed/package-scripts/observed/postrm +9 -0
- data/plugins/observed-fluentd/lib/observed/fluentd/version.rb +1 -1
- data/plugins/observed-gauge/README.md +5 -0
- data/plugins/observed-gauge/lib/observed/gauge/version.rb +1 -1
- data/plugins/observed-gauge/lib/observed/gauge.rb +11 -13
- data/plugins/observed-gauge/observed-gauge.gemspec +1 -1
- data/plugins/observed-gauge/spec/gauge_spec.rb +7 -7
- data/plugins/observed-growl/Gemfile +6 -0
- data/plugins/observed-growl/lib/observed/growl.rb +80 -0
- data/plugins/observed-http/lib/observed/http/version.rb +1 -1
- data/plugins/observed-http/lib/observed/http.rb +10 -8
- data/plugins/observed-http/observed-http.gemspec +1 -1
- data/plugins/observed-http/spec/http_spec.rb +62 -7
- data/plugins/observed-http/spec/integration_spec.rb +14 -0
- data/plugins/observed-shell/Gemfile +5 -0
- data/plugins/observed-shell/lib/observed/shell.rb +54 -0
- data/run-integration-tests +81 -0
- data/spec/builtin_plugins/stdout_spec.rb +7 -3
- data/spec/config_builder_spec.rb +42 -59
- data/spec/config_dsl_spec.rb +4 -0
- data/spec/configurable_spec.rb +141 -31
- data/spec/event_bus_spec.rb +16 -0
- data/spec/execution_job_factory_spec.rb +35 -0
- data/spec/job_factory_spec.rb +16 -0
- data/spec/job_spec.rb +228 -0
- data/spec/jobbed_event_bus_spec.rb +38 -0
- data/spec/observed_spec.rb +203 -0
- data/spec/observer_helpers/timer_spec.rb +187 -0
- data/spec/oneshot_spec.rb +7 -2
- data/spec/system_spec.rb +5 -39
- metadata +55 -12
- data/lib/observed/default/reporter.rb +0 -17
- data/lib/observed/reader.rb +0 -14
- data/lib/observed/writer.rb +0 -14
- data/spec/reader_spec.rb +0 -15
- data/spec/writer_spec.rb +0 -16
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
require 'observed/gauge'
|
4
|
+
require 'observed/system'
|
4
5
|
|
5
6
|
shared_examples_for 'the observed-gauge plugin' do
|
6
7
|
|
@@ -20,14 +21,13 @@ shared_examples_for 'the observed-gauge plugin' do
|
|
20
21
|
|
21
22
|
it 'reports data with averaged values' do
|
22
23
|
subject.prepare_rrd(start: t - 120, rrd: rrd)
|
23
|
-
|
24
|
-
expect {
|
25
|
-
expect {
|
26
|
-
expect { subject.report('test.foo', t, data) }.to_not raise_error
|
24
|
+
expect(subject.translate(data, {tag: 'test.foo', time: t - 120})).to be_nil
|
25
|
+
expect(subject.translate(data, {tag: 'test.foo', time: t - 60})).to be_nil
|
26
|
+
expect(subject.translate(data, {tag: 'test.foo', time: t})).to eq(expected_data)
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'creates rrd files automatically on first report' do
|
30
|
-
expect { subject.
|
30
|
+
expect { subject.translate(data, {tag: 'test.foo', time: t}) }.to_not raise_error
|
31
31
|
|
32
32
|
expect { File.exist? rrd }.to be_true
|
33
33
|
end
|
@@ -64,7 +64,7 @@ describe Observed::Plugins::Gauge do
|
|
64
64
|
}
|
65
65
|
|
66
66
|
let(:system) {
|
67
|
-
sys =
|
67
|
+
sys = Observed::System.new
|
68
68
|
|
69
69
|
sys.stubs(:now).returns(t)
|
70
70
|
|
@@ -117,7 +117,7 @@ describe Observed::Plugins::Gauge do
|
|
117
117
|
}
|
118
118
|
|
119
119
|
it 'raise an error' do
|
120
|
-
expect { subject.
|
120
|
+
expect { subject.translate(data, {tag: 'test.foo', time: t}) }.to raise_error(/Unexpected type of key_path met/)
|
121
121
|
end
|
122
122
|
end
|
123
123
|
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'jsonpath'
|
2
|
+
require 'ruby_gntp'
|
3
|
+
|
4
|
+
require 'observed/reporter'
|
5
|
+
|
6
|
+
module Observed
|
7
|
+
module Plugins
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class Observed::Plugins::GrowlReporter < Observed::Reporter
|
12
|
+
plugin_name 'growl'
|
13
|
+
|
14
|
+
attribute :app_name
|
15
|
+
attribute :title
|
16
|
+
attribute :text
|
17
|
+
attribute :icon
|
18
|
+
attribute :app_name_path
|
19
|
+
attribute :title_path
|
20
|
+
attribute :text_path
|
21
|
+
attribute :icon_path
|
22
|
+
attribute :app_name_key, default: :app_name
|
23
|
+
attribute :title_key, default: :title
|
24
|
+
attribute :text_key, default: :text
|
25
|
+
attribute :icon_key, default: :icon
|
26
|
+
|
27
|
+
def report(data, options)
|
28
|
+
fetch_by_key = Fetcher.new(self, data)
|
29
|
+
fetch_by_path = JSONPathFetcher.new(self, data)
|
30
|
+
GNTP.notify({
|
31
|
+
:app_name => fetch_by_path[:app_name_path] || fetch_by_key[app_name_key] || '`app_name` not configured for observed-growl',
|
32
|
+
:title => fetch_by_path[:title_path] || fetch_by_key[title_key] || '`title` not configured for observed-growl',
|
33
|
+
:text => fetch_by_path[:text_path] || fetch_by_key[text_key] || '`text` not configured for observed-growl',
|
34
|
+
:icon => fetch_by_path[:icon_path] || fetch_by_key[icon_key] || ''
|
35
|
+
})
|
36
|
+
data
|
37
|
+
end
|
38
|
+
|
39
|
+
class JSONPathFetcher
|
40
|
+
def initialize(reporter, data)
|
41
|
+
@reporter = reporter
|
42
|
+
@data = data
|
43
|
+
end
|
44
|
+
def [](name)
|
45
|
+
path = @reporter.get_attribute_value(name)
|
46
|
+
if path
|
47
|
+
JsonPath.on(@data, path)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class Fetcher
|
53
|
+
def initialize(reporter, data)
|
54
|
+
@reporter = reporter
|
55
|
+
@data = data
|
56
|
+
end
|
57
|
+
def [](name)
|
58
|
+
@data[name] || @reporter.get_attribute_value(name)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
if __FILE__ == $0
|
64
|
+
require 'observed'
|
65
|
+
|
66
|
+
include Observed
|
67
|
+
|
68
|
+
class TestObserver < Observed::Observer
|
69
|
+
plugin_name 'test'
|
70
|
+
|
71
|
+
def observe
|
72
|
+
{foo: 'foo from observer', 'bar' => { 'baz' => 'bar.baz from observer' } }
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
test = (observe via: 'test')
|
77
|
+
.then(report via: 'growl', with: { text_key: :foo, title_path: 'bar.baz' })
|
78
|
+
|
79
|
+
test.now
|
80
|
+
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'observed/http/version'
|
2
|
+
require 'observed/observer'
|
2
3
|
require 'observed/observer_helpers/timer'
|
4
|
+
require 'observed/logging'
|
3
5
|
require 'timeout'
|
4
6
|
require 'net/http'
|
5
7
|
|
@@ -8,18 +10,22 @@ module Observed
|
|
8
10
|
class HTTP < Observed::Observer
|
9
11
|
|
10
12
|
include Observed::ObserverHelpers::Timer
|
13
|
+
include Observed::Logging
|
11
14
|
|
12
15
|
attribute :timeout_in_milliseconds, default: 5000
|
13
16
|
|
14
17
|
attribute :method
|
15
18
|
attribute :url
|
19
|
+
attribute :logger
|
16
20
|
|
17
21
|
def observe
|
18
|
-
|
22
|
+
method = get_attribute_value(:method)
|
23
|
+
|
24
|
+
log_debug "method: #{method}, url: #{url}"
|
19
25
|
|
20
26
|
uri = URI.parse(url)
|
21
27
|
|
22
|
-
|
28
|
+
log_debug "uri: #{uri}, uri.host: #{uri.host}, uri.port:#{uri.port}, uri.path: #{uri.path}"
|
23
29
|
|
24
30
|
http_method = method.capitalize
|
25
31
|
path = if uri.path.size == 0
|
@@ -36,23 +42,19 @@ module Observed
|
|
36
42
|
|
37
43
|
time_and_report(tag: self.tag, timeout_in_seconds: timeout_in_seconds) do
|
38
44
|
|
39
|
-
|
45
|
+
log_debug "Sending a HTTP request with the timeout of #{timeout_in_seconds} seconds"
|
40
46
|
|
41
47
|
body = Net::HTTP.start(uri.host, uri.port) {|http|
|
42
48
|
http.request(req)
|
43
49
|
}.body
|
44
50
|
|
45
|
-
|
51
|
+
log_debug "Response body: #{body}"
|
46
52
|
|
47
53
|
"#{http_method} #{uri}"
|
48
54
|
end
|
49
55
|
|
50
56
|
end
|
51
57
|
|
52
|
-
def logger
|
53
|
-
@logger ||= Logger.new(STDOUT)
|
54
|
-
end
|
55
|
-
|
56
58
|
plugin_name 'http'
|
57
59
|
|
58
60
|
end
|
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency "observed", "~> 0.
|
21
|
+
spec.add_dependency "observed", "~> 0.2.0.rc1"
|
22
22
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.3"
|
24
24
|
spec.add_development_dependency "rake"
|
@@ -1,14 +1,69 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
require 'observed/
|
3
|
+
require 'observed/http'
|
4
|
+
|
5
|
+
describe Observed::Plugins::HTTP do
|
4
6
|
|
5
|
-
describe Observed::Application::Oneshot do
|
6
7
|
subject {
|
7
|
-
Observed::
|
8
|
-
|
9
|
-
|
8
|
+
Observed::Plugins::HTTP.new
|
9
|
+
}
|
10
|
+
|
11
|
+
before {
|
12
|
+
subject.configure config
|
13
|
+
}
|
14
|
+
|
15
|
+
let(:config) {
|
16
|
+
{
|
17
|
+
timeout_in_milliseconds: 1000,
|
18
|
+
method: 'get',
|
19
|
+
url: 'http://google.com/',
|
20
|
+
tag: 'test',
|
21
|
+
system: sys
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
let(:sys) {
|
26
|
+
sys = mock('system')
|
27
|
+
sys.stubs(:now).returns(before).then.returns(after)
|
28
|
+
sys
|
29
|
+
}
|
30
|
+
|
31
|
+
let(:before) {
|
32
|
+
Time.now
|
33
|
+
}
|
34
|
+
|
35
|
+
let(:after) {
|
36
|
+
Time.now + 1
|
10
37
|
}
|
11
|
-
|
12
|
-
|
38
|
+
|
39
|
+
let(:response) {
|
40
|
+
res = stub('response')
|
41
|
+
res.stubs(body: 'the response body')
|
42
|
+
res
|
43
|
+
}
|
44
|
+
|
45
|
+
context 'when timed out' do
|
46
|
+
before {
|
47
|
+
Timeout.expects(:timeout).raises(Timeout::Error)
|
48
|
+
|
49
|
+
sys.expects(:report).with('test.error', {status: :error, error: {message: 'Timed out.'}, timed_out: true})
|
50
|
+
}
|
51
|
+
|
52
|
+
it 'reports an error' do
|
53
|
+
expect { subject.observe }.to_not raise_error
|
54
|
+
end
|
13
55
|
end
|
56
|
+
|
57
|
+
context 'when not timed out' do
|
58
|
+
before {
|
59
|
+
Timeout.expects(:timeout).returns({ status: :success, result: 'Get http://google.com/' })
|
60
|
+
|
61
|
+
sys.expects(:report).with('test.success', {status: :success, result: 'Get http://google.com/', elapsed_time: after - before})
|
62
|
+
}
|
63
|
+
|
64
|
+
it 'reports an success' do
|
65
|
+
expect { subject.observe }.to_not raise_error
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
14
69
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'observed/application/oneshot'
|
4
|
+
|
5
|
+
describe Observed::Application::Oneshot do
|
6
|
+
subject {
|
7
|
+
Observed::Application::Oneshot.create(
|
8
|
+
config_file: 'spec/fixtures/observed.conf'
|
9
|
+
)
|
10
|
+
}
|
11
|
+
it 'initializes' do
|
12
|
+
expect(subject.run.size).not_to eq(0)
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'mixlib/shellout'
|
2
|
+
|
3
|
+
require 'observed/observer'
|
4
|
+
require 'observed/reporter'
|
5
|
+
|
6
|
+
module Observed
|
7
|
+
module Plugins
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class Observed::Plugins::ShellObserver < Observed::Observer
|
12
|
+
plugin_name 'shell'
|
13
|
+
|
14
|
+
attribute :command
|
15
|
+
|
16
|
+
def observe
|
17
|
+
c = Mixlib::ShellOut.new(*command)
|
18
|
+
c.run_command
|
19
|
+
{ command: command, stdout: c.stdout, stderr: c.stderr }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class Observed::Plugins::ShellReporter < Observed::Reporter
|
24
|
+
plugin_name 'shell'
|
25
|
+
|
26
|
+
attribute :command
|
27
|
+
attribute :input_key
|
28
|
+
|
29
|
+
def report(data, options)
|
30
|
+
if command.is_a? Proc
|
31
|
+
num_params = command.parameters.size
|
32
|
+
args = [data, options].take(num_params)
|
33
|
+
result = command.call *args
|
34
|
+
command_line = result
|
35
|
+
else
|
36
|
+
command_line = command
|
37
|
+
end
|
38
|
+
c = Mixlib::ShellOut.new(*command_line, input: data[get_attribute_value(:input_key)])
|
39
|
+
c.run_command
|
40
|
+
#logger.debug %Q|[observed-shell] ShellReporter executed the command "#{command_line}", captured stdout is "#{c.stdout}", captured stderr is #{c.stderr}"|
|
41
|
+
data
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
if __FILE__ == $0
|
46
|
+
require 'observed'
|
47
|
+
|
48
|
+
include Observed
|
49
|
+
|
50
|
+
test = (observe via: 'shell', with: { command: 'echo foo' } )
|
51
|
+
.then(report via: 'shell', with: { command: -> d { "growlnotify -m #{d[:stdout]}" } } )
|
52
|
+
|
53
|
+
test.now
|
54
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
#!/bin/bash --login
|
2
|
+
|
3
|
+
# '--login' is needed to deal with the following warning otherwise emitted by rvm:
|
4
|
+
# You need to change your terminal emulator preferences to allow login shell.
|
5
|
+
# Sometimes it is required to use `/bin/bash --login` as the command.
|
6
|
+
# Please visit https://rvm.io/integration/gnome-terminal/ for a example.
|
7
|
+
|
8
|
+
rvm gemset create observed-test
|
9
|
+
rvm gemset use observed-test
|
10
|
+
|
11
|
+
observed_dir=`dirname $0`
|
12
|
+
|
13
|
+
cd $observed_dir
|
14
|
+
|
15
|
+
observed_dir=`pwd`
|
16
|
+
|
17
|
+
plugins_dir=$observed_dir/plugins
|
18
|
+
integrations_dir=$observed_dir/integrations
|
19
|
+
integrations="clockwork eventmachine"
|
20
|
+
plugins="http fluentd gauge"
|
21
|
+
|
22
|
+
#cd $observed_dir
|
23
|
+
|
24
|
+
dirs=$observed_dir
|
25
|
+
|
26
|
+
for integration in $integrations
|
27
|
+
do
|
28
|
+
dirs="$dirs $integrations_dir/observed-$integration"
|
29
|
+
done
|
30
|
+
|
31
|
+
for plugin in $plugins
|
32
|
+
do
|
33
|
+
dirs="$dirs $plugins_dir/observed-$plugin"
|
34
|
+
done
|
35
|
+
|
36
|
+
echo $dirs
|
37
|
+
|
38
|
+
function quit_on_failure {
|
39
|
+
if [[ $? -ne 0 ]]; then
|
40
|
+
quit 1
|
41
|
+
fi
|
42
|
+
}
|
43
|
+
|
44
|
+
function quit {
|
45
|
+
rvm --force gemset delete observed-test
|
46
|
+
if [[ $1 == "" ]]; then
|
47
|
+
exit 0
|
48
|
+
fi
|
49
|
+
exit $1
|
50
|
+
}
|
51
|
+
|
52
|
+
for target in $dirs
|
53
|
+
do
|
54
|
+
echo Target: $target
|
55
|
+
cd $target
|
56
|
+
echo Current directory: `pwd`
|
57
|
+
export BUNDLE_GEMFILE=$target/Gemfile
|
58
|
+
bundle install
|
59
|
+
if [[ $? -ne 0 ]]; then
|
60
|
+
bundle update
|
61
|
+
fi
|
62
|
+
if [ -d spec ]
|
63
|
+
then
|
64
|
+
bundle exec rspec
|
65
|
+
fi
|
66
|
+
quit_on_failure
|
67
|
+
|
68
|
+
if [ -d features ]
|
69
|
+
then
|
70
|
+
bundle exec cucumber
|
71
|
+
fi
|
72
|
+
quit_on_failure
|
73
|
+
|
74
|
+
rake install
|
75
|
+
if [[ $? -ne 0 ]]; then
|
76
|
+
gem install pkg/*.gem
|
77
|
+
fi
|
78
|
+
|
79
|
+
done
|
80
|
+
|
81
|
+
quit
|
@@ -11,7 +11,11 @@ describe Observed::BuiltinPlugins::Stdout do
|
|
11
11
|
}
|
12
12
|
|
13
13
|
let(:config) {
|
14
|
-
{ tag_pattern: /foo\..+/, format: formatter }
|
14
|
+
{ tag_pattern: /foo\..+/, format: formatter, output: output }
|
15
|
+
}
|
16
|
+
|
17
|
+
let(:output) {
|
18
|
+
mock('output')
|
15
19
|
}
|
16
20
|
|
17
21
|
context 'with a specific formatter' do
|
@@ -22,7 +26,7 @@ describe Observed::BuiltinPlugins::Stdout do
|
|
22
26
|
|
23
27
|
it 'reports the formatted data to the stdout' do
|
24
28
|
time = Time.now
|
25
|
-
|
29
|
+
output.expects(:puts).with("foo #{time.to_i} 1 2")
|
26
30
|
expect { subject.report('foo', time, {foo: 1, bar: {baz: 2}}) }.to_not raise_error
|
27
31
|
end
|
28
32
|
|
@@ -36,7 +40,7 @@ describe Observed::BuiltinPlugins::Stdout do
|
|
36
40
|
|
37
41
|
it 'reports the data formatted by the default formatter to the stdout' do
|
38
42
|
time = Time.now
|
39
|
-
|
43
|
+
output.expects(:puts).with("#{time.to_s} foo {:foo=>1}")
|
40
44
|
expect { subject.report('foo', time, {foo: 1}) }.to_not raise_error
|
41
45
|
end
|
42
46
|
|
data/spec/config_builder_spec.rb
CHANGED
@@ -7,14 +7,18 @@ describe Observed::ConfigBuilder do
|
|
7
7
|
|
8
8
|
subject {
|
9
9
|
Observed::ConfigBuilder.new(
|
10
|
-
|
11
|
-
reader_plugins: reader_plugins,
|
10
|
+
context: context,
|
12
11
|
observer_plugins: observer_plugins,
|
13
12
|
reporter_plugins: reporter_plugins,
|
13
|
+
translator_plugins: translator_plugins,
|
14
14
|
system: system
|
15
15
|
)
|
16
16
|
}
|
17
17
|
|
18
|
+
let(:context) {
|
19
|
+
Observed::Context.new
|
20
|
+
}
|
21
|
+
|
18
22
|
let(:system) {
|
19
23
|
mock('system')
|
20
24
|
}
|
@@ -27,7 +31,7 @@ describe Observed::ConfigBuilder do
|
|
27
31
|
content = File.open(path, 'r') do |f|
|
28
32
|
f.read
|
29
33
|
end
|
30
|
-
|
34
|
+
{ key => content }
|
31
35
|
end
|
32
36
|
end
|
33
37
|
{ 'my_file' => my_file }
|
@@ -58,54 +62,21 @@ describe Observed::ConfigBuilder do
|
|
58
62
|
{ 'stdout' => stdout }
|
59
63
|
}
|
60
64
|
|
61
|
-
let(:
|
62
|
-
|
63
|
-
attribute :
|
64
|
-
attribute :
|
65
|
-
def
|
66
|
-
|
67
|
-
|
68
|
-
end
|
69
|
-
{ key => content }
|
65
|
+
let(:translator_plugins) {
|
66
|
+
my_translator = Class.new(Observed::Translator) do
|
67
|
+
attribute :tag
|
68
|
+
attribute :format
|
69
|
+
def translate(tag, time, data)
|
70
|
+
formatted_data = format.call tag, time, data, Observed::Hash::Fetcher.new(data), Observed::Hash::Builder.new
|
71
|
+
{formatted:formatted_data}
|
70
72
|
end
|
73
|
+
plugin_name 'my_translator'
|
71
74
|
end
|
72
75
|
{
|
73
|
-
'
|
76
|
+
'my_translator' => my_translator
|
74
77
|
}
|
75
78
|
}
|
76
79
|
|
77
|
-
it 'creates writers' do
|
78
|
-
time = Time.now
|
79
|
-
subject.write to: 'stdout', with: {
|
80
|
-
format: -> tag, time, data, d { "value:#{d['foo.bar']}" }
|
81
|
-
}
|
82
|
-
STDOUT.expects(:puts).with('value:123')
|
83
|
-
expect { subject.build.writers.first.write('foo.bar', time, {foo:{bar:123}}) }.to_not raise_error
|
84
|
-
end
|
85
|
-
|
86
|
-
it 'creates readers' do
|
87
|
-
subject.read from: 'file', with: {
|
88
|
-
path: 'foo.txt',
|
89
|
-
key: 'content'
|
90
|
-
}
|
91
|
-
File.open('foo.txt', 'w') do |f|
|
92
|
-
f.write('file content')
|
93
|
-
end
|
94
|
-
expect(subject.build.readers.first.read).to eq({ 'content' => 'file content' })
|
95
|
-
end
|
96
|
-
|
97
|
-
it 'creates observers from reader plugins' do
|
98
|
-
subject.observe 'foo.bar', from: 'file', with: {
|
99
|
-
path: 'foo.txt',
|
100
|
-
key: 'content'
|
101
|
-
}
|
102
|
-
File.open('foo.txt', 'w') do |f|
|
103
|
-
f.write('file content')
|
104
|
-
end
|
105
|
-
system.expects(:report).with('foo.bar', { 'content' => 'file content' })
|
106
|
-
expect { subject.build.observers.first.observe }.to_not raise_error
|
107
|
-
end
|
108
|
-
|
109
80
|
it 'creates observers from observer plugins' do
|
110
81
|
subject.observe 'foo.bar', via: 'my_file', which: {
|
111
82
|
path: 'foo.txt',
|
@@ -114,22 +85,20 @@ describe Observed::ConfigBuilder do
|
|
114
85
|
File.open('foo.txt', 'w') do |f|
|
115
86
|
f.write('file content')
|
116
87
|
end
|
117
|
-
|
118
|
-
|
88
|
+
the_data = nil
|
89
|
+
subject.build.observers.first.now do |data, options|
|
90
|
+
the_data = data
|
91
|
+
end
|
92
|
+
expect(the_data).to eq({'content' => 'file content'})
|
119
93
|
end
|
120
94
|
|
121
|
-
it 'creates
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
reporter = subject.reporters.first
|
129
|
-
STDOUT.expects(:puts).with("foo.bar #{time} 123").once
|
130
|
-
expect(reporter.match(tag)).to be_true
|
131
|
-
expect { reporter.report(tag, time, { foo: { bar: 123 }}) }.to_not raise_error
|
132
|
-
end
|
95
|
+
#it 'creates default observers from poller plugins' do
|
96
|
+
# subject.observe 'foo.bar', via: 'poll', which: {
|
97
|
+
# result: 'result'
|
98
|
+
# }
|
99
|
+
# system.expects(:report).with('foo.bar', { 'content' => 'file content' })
|
100
|
+
# expect { subject.build.pollers.first.poll }.to_not raise_error
|
101
|
+
#end
|
133
102
|
|
134
103
|
it 'creates reporters from reporter plugins' do
|
135
104
|
tag = 'foo.bar'
|
@@ -143,4 +112,18 @@ describe Observed::ConfigBuilder do
|
|
143
112
|
expect(reporter.match(tag)).to be_true
|
144
113
|
expect { reporter.report(tag, time, { foo: { bar: 123 }}) }.to_not raise_error
|
145
114
|
end
|
115
|
+
|
116
|
+
it 'creates translator from translator plugins' do
|
117
|
+
time = Time.now
|
118
|
+
translator = subject.translate via: 'my_translator', with: {
|
119
|
+
tag: 'foo.baz',
|
120
|
+
format: -> tag, time, data, f, b { b['bar.baz'] = "foo.bar #{time} #{f[tag]}"; b.build }
|
121
|
+
}
|
122
|
+
|
123
|
+
result = {bar:{baz:"foo.bar #{time} 123"}}
|
124
|
+
|
125
|
+
translator.now({foo:{bar: 123}}, {tag: 'foo.bar', time: time}) do |data, options|
|
126
|
+
expect(data).to eq({formatted: result})
|
127
|
+
end
|
128
|
+
end
|
146
129
|
end
|
data/spec/config_dsl_spec.rb
CHANGED
@@ -8,11 +8,15 @@ require 'observed/config_builder'
|
|
8
8
|
describe Observed::ConfigDSL do
|
9
9
|
subject {
|
10
10
|
Observed::ConfigDSL.new(builder: Observed::ConfigBuilder.new(
|
11
|
+
context: context,
|
11
12
|
observer_plugins: observer_plugins,
|
12
13
|
reporter_plugins: reporter_plugins,
|
13
14
|
system: sys
|
14
15
|
))
|
15
16
|
}
|
17
|
+
let(:context) {
|
18
|
+
Observed::Context.new
|
19
|
+
}
|
16
20
|
let(:foo) {
|
17
21
|
Class.new(Observed::Observer) do
|
18
22
|
def observe
|