eye-patch 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a4fd5387a724ebe2a8206f632a0bd82ebbcbdbb2
4
- data.tar.gz: 136ce649ba422aa607a6a72b44d3d856a6ba87e8
3
+ metadata.gz: a8281021f4db405a7011e70f5ea0f01aa0b1afc3
4
+ data.tar.gz: 4ac4ff0e9c9b16f55912ffe1a885af3d424e6819
5
5
  SHA512:
6
- metadata.gz: 97f7c12413d6d8099385be3252a121a704499e651b1ea4238b08a49fa90029d625d8afff803cbe1469292ca1ed2905fd7fd96ee6105ed958fa20d01963f09ed2
7
- data.tar.gz: bfd5dd4a330ab8053c07583ddbd6346e3e78dea17482fdae0cdd80304b7ba15f53640d17721c8546cbfef38e2014956186ae74b5ade09611787c96dfb10c877b
6
+ metadata.gz: 9f58bfc30efef715e657c4c76611f9eda3040fa7ae8ebba0ca0c3b5f84ec997ddc65be39bf80ecb101ae2983f215a087106a8ee04c9e144df1daa6715bdf29a6
7
+ data.tar.gz: 667974afe57844d67faadc9ecc7bcd4926b19d982285d525f92c181224ef081c012a208da434dad5a2afea309dd6b4689371ce0f6faa9fc17972fc653cdebefa
data/README.md CHANGED
@@ -71,6 +71,22 @@ Note that memory and duration values are written in plain english. See `lib/eye/
71
71
 
72
72
  Processes will inherit all configurations from the main application. All process options supported by `eye` are available by using the appropriate key in the `config` block.
73
73
 
74
+ ##### Checks and Triggers
75
+
76
+ You can define per-process checks and triggers by defining a `checks` or `triggers` block within the process definition.
77
+
78
+ processes:
79
+ - name: my-process
80
+ checks:
81
+ - name: memory
82
+ config:
83
+ times: 3
84
+ every: 10 seconds
85
+ below: 52 megabytes
86
+ ...
87
+
88
+ Any check or trigger already defined at the application level will be overwritten with the new configuration. Application-level checks and triggers which are not redefined for the process will be persisted.
89
+
74
90
  ##### Grouping
75
91
 
76
92
  Rather than using the `eye` DSL's nesting approaching to setting up processes within groups, `Eye::Patch` simply needs a `group` attribute to be added to the process definition.
@@ -180,5 +196,4 @@ See `lib/eye/patch/capistrano.rb` for a list of available configuration options.
180
196
 
181
197
  ## Coming Soon
182
198
 
183
- - Proper support for per-process triggers and checks.
184
199
  - Process templates for commonly-used libraries (unicorn, sidekiq, delayed_jobs).
data/eye-patch.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.test_files = spec.files.grep(%r{^test/})
22
22
  spec.require_paths = ["lib"]
23
23
 
24
- spec.add_dependency "eye"
24
+ spec.add_dependency "eye", "~> 0.5"
25
25
  spec.add_dependency "chronic_duration"
26
26
 
27
27
  spec.add_development_dependency "bundler", "~> 1.3"
@@ -21,7 +21,7 @@ module Eye::Patch
21
21
  end
22
22
 
23
23
  def parse_configuration
24
- @config = (@settings[:application] || {}).merge(
24
+ @config = @settings.fetch(:application, {}).merge(
25
25
  name: @settings[:name],
26
26
  notify: notifications,
27
27
  triggers: triggers,
@@ -15,7 +15,7 @@ Capistrano::Configuration.instance.load do
15
15
 
16
16
  desc "Start eye with the desired configuration file"
17
17
  task :load_config, roles: -> { fetch(:eye_roles) } do
18
- run "cd #{current_path} && #{fetch(:eye_bin)} l #{fetch(:eye_config)}"
18
+ run "cd #{current_path} && #{fetch(:eye_bin)} q && #{fetch(:eye_bin)} l #{fetch(:eye_config)}"
19
19
  end
20
20
 
21
21
  desc "Stop eye and all of its monitored tasks"
@@ -17,6 +17,7 @@ namespace :eye do
17
17
  task :load_config do
18
18
  on roles(fetch(:eye_roles)) do
19
19
  within current_path do
20
+ execute fetch(:eye_bin), "q"
20
21
  execute fetch(:eye_bin), "l #{fetch(:eye_config)}"
21
22
  end
22
23
  end
@@ -16,22 +16,31 @@ module Eye::Patch
16
16
  if process[:count]
17
17
  parse_process_cluster(process)
18
18
  else
19
- parse_single_process(process[:name], process[:config])
19
+ parse_single_process(
20
+ process[:name],
21
+ process[:config],
22
+ process_monitors(process))
20
23
  end
21
24
  end
22
25
 
23
26
  def parse_process_cluster(process)
24
27
  process[:count].times do |index|
25
28
  name = "#{process[:name]}-#{index}"
26
- parse_single_process(name, indexed_config(process[:config], index))
29
+ parse_single_process(
30
+ name,
31
+ indexed_config(process[:config], index),
32
+ process_monitors(process))
27
33
  end
28
34
  end
29
35
 
30
- def parse_single_process(name, config)
36
+ def parse_single_process(name, config, monitors)
31
37
  self[name] = @group
32
38
  .merge(stdout: config[:stdall], stderr: config[:stdall])
33
39
  .merge(config)
34
40
  .merge(name: name, group: @group[:name])
41
+
42
+ self[name][:triggers] = self[name][:triggers].merge(monitors[:triggers])
43
+ self[name][:checks] = self[name][:checks].merge(monitors[:checks])
35
44
  end
36
45
 
37
46
  def indexed_config(config, index)
@@ -39,5 +48,10 @@ module Eye::Patch
39
48
  result[key] = value.is_a?(String) ? value.gsub("{ID}", index.to_s) : value
40
49
  end
41
50
  end
51
+
52
+ def process_monitors(config)
53
+ { triggers: OptionSet.new(Eye::Trigger, config[:triggers]),
54
+ checks: OptionSet.new(Eye::Checker, config[:checks]) }
55
+ end
42
56
  end
43
57
  end
@@ -1,15 +1,15 @@
1
+ require "erb"
2
+ require "forwardable"
1
3
  require_relative "value_parser"
2
4
 
3
5
  module Eye::Patch
4
6
 
5
7
  class Settings
8
+ extend Forwardable
9
+ def_delegators :parsed, :[], :fetch
6
10
 
7
11
  def initialize(filename)
8
- @settings = YAML.load(File.open(filename))
9
- end
10
-
11
- def [](value)
12
- parsed[value]
12
+ @settings = YAML.load(ERB.new(File.read(filename)).result)
13
13
  end
14
14
 
15
15
  private
@@ -11,6 +11,8 @@ module Eye::Patch
11
11
  size: SIZE_MATCHER }.freeze
12
12
 
13
13
  def self.parse(value)
14
+ return value unless value.is_a?(String)
15
+
14
16
  result = MATCHERS.detect do |match_type, matcher|
15
17
  break send(:"parse_#{match_type}", value) if value.match(matcher)
16
18
  end
@@ -1,5 +1,5 @@
1
1
  module Eye
2
2
  module Patch
3
- VERSION = "0.1.4"
3
+ VERSION = "0.1.5"
4
4
  end
5
5
  end
@@ -0,0 +1,39 @@
1
+ name: Test Application With Per-Process Overrides
2
+
3
+ config:
4
+ logger: /path/to/log/eye.log
5
+
6
+ application:
7
+ working_dir: /path/to/application
8
+
9
+ triggers:
10
+ - name: flapping
11
+ config:
12
+ times: 10
13
+ within: 1 minute
14
+
15
+ checks:
16
+ - name: memory
17
+ config:
18
+ times: 3
19
+ every: 20 seconds
20
+ below: 1.5 gigabytes
21
+
22
+ processes:
23
+ - name: my-process
24
+ triggers:
25
+ - name: flapping
26
+ config:
27
+ times: 6
28
+ within: 40 seconds
29
+ checks:
30
+ - name: memory
31
+ config:
32
+ times: 2
33
+ every: 15 seconds
34
+ below: 1.2 megabytes
35
+ config:
36
+ start_timeout: 25 seconds
37
+ start_command: bundle exec my-process
38
+ pid_file: tmp/pids/my-process.pid
39
+ stdall: log/my-process.log
@@ -0,0 +1,15 @@
1
+ require_relative "../../../test_helper"
2
+ require "tempfile"
3
+
4
+ module Eye
5
+ module Patch
6
+ describe Settings do
7
+ it "evaluates the yaml as ERB" do
8
+ file = Tempfile.new("yaml")
9
+ file.write("sum: <%= 1 + 2 %>")
10
+ file.close
11
+ assert_equal 3, Settings.new(file.path)[:sum]
12
+ end
13
+ end
14
+ end
15
+ end
@@ -2,13 +2,13 @@ require_relative "../../test_helper"
2
2
 
3
3
  describe Eye::Patch do
4
4
  before do
5
- @fixture = File.expand_path(File.join(File.dirname(__FILE__), %w[.. .. fixtures test.yml]))
6
- @original = YAML.load(File.open(@fixture))
5
+ Eye::Config.any_instance.stubs(:validate!)
7
6
  end
8
7
 
9
8
  describe ".parse" do
10
9
  before do
11
- Eye::Config.any_instance.stubs(:validate!)
10
+ @fixture = File.expand_path(File.join(File.dirname(__FILE__), %w[.. .. fixtures test.yml]))
11
+ @original = YAML.load(File.open(@fixture))
12
12
  @parsed = Eye::Patch.parse(@fixture)
13
13
 
14
14
  @settings = @parsed.settings
@@ -37,17 +37,18 @@ describe Eye::Patch do
37
37
  trigger = @original["triggers"].first
38
38
  parsed_trigger = @application[:triggers][trigger["name"].to_sym]
39
39
 
40
- assert_equal trigger["config"]["times"], parsed_trigger[:times]
41
- assert_equal Eye::Patch::ValueParser.parse(trigger["config"]["within"]), parsed_trigger[:within]
40
+ %w(times within).each do |setting|
41
+ assert_equal Eye::Patch::ValueParser.parse(trigger["config"][setting]), parsed_trigger[setting.to_sym]
42
+ end
42
43
  end
43
44
 
44
45
  it "parses checks" do
45
46
  check = @original["checks"].first
46
47
  parsed_check = @application[:checks][check["name"].to_sym]
47
48
 
48
- assert_equal check["config"]["times"], parsed_check[:times]
49
- assert_equal Eye::Patch::ValueParser.parse(check["config"]["every"]), parsed_check[:every]
50
- assert_equal Eye::Patch::ValueParser.parse(check["config"]["below"]), parsed_check[:below]
49
+ %w(times every below).each do |setting|
50
+ assert_equal Eye::Patch::ValueParser.parse(check["config"][setting]), parsed_check[setting.to_sym]
51
+ end
51
52
  end
52
53
 
53
54
  it "splits processes into groups" do
@@ -88,4 +89,36 @@ describe Eye::Patch do
88
89
  assert_equal process["config"]["stdall"], parsed_process[:stderr]
89
90
  end
90
91
  end
92
+
93
+ describe ".parse with per-process overrides" do
94
+ before do
95
+ @fixture = File.expand_path(File.join(File.dirname(__FILE__), %w[.. .. fixtures overrides.yml]))
96
+ @original = YAML.load(File.open(@fixture))
97
+ @parsed = Eye::Patch.parse(@fixture)
98
+
99
+ @settings = @parsed.settings
100
+ @applications = @parsed.applications
101
+ @application = @applications.values.first
102
+ end
103
+
104
+ it "loads per-process triggers" do
105
+ process = @application[:groups]["__default__"][:processes].values.first
106
+ trigger = @original["processes"].detect { |p| p["name"] == process[:name] }["triggers"].first
107
+ parsed_trigger = process[:triggers][trigger["name"].to_sym]
108
+
109
+ %w(times within).each do |setting|
110
+ assert_equal Eye::Patch::ValueParser.parse(trigger["config"][setting]), parsed_trigger[setting.to_sym]
111
+ end
112
+ end
113
+
114
+ it "loads per-process checks" do
115
+ process = @application[:groups]["__default__"][:processes].values.first
116
+ check = @original["processes"].detect { |p| p["name"] == process[:name] }["checks"].first
117
+ parsed_check = process[:checks][check["name"].to_sym]
118
+
119
+ %w(times every below).each do |setting|
120
+ assert_equal Eye::Patch::ValueParser.parse(check["config"][setting]), parsed_check[setting.to_sym]
121
+ end
122
+ end
123
+ end
91
124
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eye-patch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Horner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-21 00:00:00.000000000 Z
11
+ date: 2014-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eye
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '0.5'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '0.5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: chronic_duration
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -110,7 +110,9 @@ files:
110
110
  - lib/eye/patch/settings.rb
111
111
  - lib/eye/patch/value_parser.rb
112
112
  - lib/eye/patch/version.rb
113
+ - test/fixtures/overrides.yml
113
114
  - test/fixtures/test.yml
115
+ - test/lib/eye/patch/settings_test.rb
114
116
  - test/lib/eye/patch/value_parser_test.rb
115
117
  - test/lib/eye/patch/version_test.rb
116
118
  - test/lib/eye/patch_test.rb
@@ -135,13 +137,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
137
  version: '0'
136
138
  requirements: []
137
139
  rubyforge_project:
138
- rubygems_version: 2.1.11
140
+ rubygems_version: 2.2.2
139
141
  signing_key:
140
142
  specification_version: 4
141
143
  summary: Eye::Patch abstracts out the Eye DSL to allow you to load your configuration
142
144
  from a structured YAML file, rather than relying on Eye's built-in DSL.
143
145
  test_files:
146
+ - test/fixtures/overrides.yml
144
147
  - test/fixtures/test.yml
148
+ - test/lib/eye/patch/settings_test.rb
145
149
  - test/lib/eye/patch/value_parser_test.rb
146
150
  - test/lib/eye/patch/version_test.rb
147
151
  - test/lib/eye/patch_test.rb