sensu-redis 0.1.8 → 0.1.9

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: 2a5fe4263828e812171b362cc7a11a466839cc4b
4
- data.tar.gz: 78557360f3335c18cbc2e9d82ad9ebbaa880a1d8
3
+ metadata.gz: d9953079714c141b83f7e59b50a9d75fa0474bab
4
+ data.tar.gz: 96880d16d145c74b1769a8efb02805f7c04b5fee
5
5
  SHA512:
6
- metadata.gz: 71cc90ae64b3cd072fea5de5c56a91a45316bb9d0471f449652d26e60abe12ab6f37e42cb4aa43f87ae57eac8157004421f7bd2fc88a8d37f798089719c8b339
7
- data.tar.gz: 3db7761ab479b605a602af2aaf09a9bbb76a090d7d672866251d71e025e95e05a0e2a67f414a987016ed88a7e96132a5f5eca13b5f79d0c3069ed28013f4f074
6
+ metadata.gz: b0c05605ee8d75b1a1922942ef34df14669bac9ddaf319bad36afd29f8002ecd8a1051151139f9a397aa0f245d42739b69578d5d2b6725054958a26f26231515
7
+ data.tar.gz: f7b6d0486645d5170d41331a04fa198fbacd300c8690d93c1493a7945e7e3d415d363abd879c486416f3da8adf47a83ce4cbbb83e7cbd386b49dc0285fb4b701
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ dump.rdb
data/lib/sensu/redis.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "rubygems"
2
2
  require "sensu/redis/client"
3
+ require "sensu/redis/sentinel"
3
4
  require "eventmachine"
4
5
  require "uri"
5
6
 
@@ -19,16 +20,36 @@ module Sensu
19
20
  end
20
21
  end
21
22
 
22
- def connect(options={})
23
+ def connect_via_sentinel(options, &block)
24
+ sentinel = Sentinel.new(options)
25
+ sentinel.callback do
26
+ sentinel.resolve do |host, port|
27
+ block.call(EM.connect(host, port, Client, options))
28
+ end
29
+ end
30
+ sentinel.errback do
31
+ EM::Timer.new(3) do
32
+ connect_via_sentinel(options, &block)
33
+ end
34
+ end
35
+ end
36
+
37
+ def connect_direct(options, &block)
38
+ block.call(EM.connect(options[:host], options[:port], Client, options))
39
+ end
40
+
41
+ def connect(options={}, &block)
23
42
  case options
24
43
  when String
25
44
  options = parse_url(options)
26
45
  when nil
27
46
  options = {}
28
47
  end
29
- options[:host] ||= "127.0.0.1"
30
- options[:port] = (options[:port] || 6379).to_i
31
- EM.connect(options[:host], options[:port], Sensu::Redis::Client, options)
48
+ if options[:sentinels].is_a?(Array)
49
+ connect_via_sentinel(options, &block)
50
+ else
51
+ connect_direct(options, &block)
52
+ end
32
53
  end
33
54
  end
34
55
  end
@@ -11,9 +11,9 @@ module Sensu
11
11
  # and setting the default connection options and callbacks.
12
12
  def initialize(options={})
13
13
  create_command_methods!
14
- @host = options[:host]
15
- @port = options[:port]
16
- @db = (options[:db] || 0).to_i
14
+ @host = options[:host] || "127.0.0.1"
15
+ @port = options[:port] || 6379
16
+ @db = options[:db]
17
17
  @password = options[:password]
18
18
  @auto_reconnect = options.fetch(:auto_reconnect, true)
19
19
  @reconnect_on_error = options.fetch(:reconnect_on_error, true)
@@ -0,0 +1,48 @@
1
+ require "sensu/redis/client"
2
+ require "eventmachine"
3
+
4
+ module Sensu
5
+ module Redis
6
+ class Sentinel
7
+ include EM::Deferrable
8
+
9
+ def initialize(options={})
10
+ @options = options
11
+ @master_name = options[:host] || "mymaster"
12
+ @sentinels = connect_to_sentinels(@options[:sentinels])
13
+ end
14
+
15
+ def connect_to_sentinel(host, port)
16
+ connection = EM.connect(host, port, Client)
17
+ connection.callback do
18
+ succeed
19
+ end
20
+ end
21
+
22
+ def connect_to_sentinels(sentinels)
23
+ sentinels.map do |sentinel|
24
+ host = sentinel[:host] || "127.0.0.1"
25
+ port = sentinel[:port] || 26379
26
+ connect_to_sentinel(host, port)
27
+ end
28
+ end
29
+
30
+ def select_a_sentinel
31
+ @sentinels.select { |sentinel| sentinel.connected? }.shuffle.first
32
+ end
33
+
34
+ def resolve
35
+ sentinel = select_a_sentinel
36
+ if sentinel.nil?
37
+ fail
38
+ else
39
+ sentinel.callback do
40
+ sentinel.send_command("sentinel", "get-master-addr-by-name", @master_name) do |host, port|
41
+ yield(host, port)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
data/sensu-redis.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "sensu-redis"
5
- spec.version = "0.1.8"
5
+ spec.version = "0.1.9"
6
6
  spec.authors = ["Sean Porter"]
7
7
  spec.email = ["portertech@gmail.com"]
8
8
  spec.summary = "The Sensu Redis client library"
@@ -0,0 +1,145 @@
1
+ # port <sentinel-port>
2
+ # The port that this sentinel instance will run on
3
+ port 63800
4
+
5
+ # sentinel monitor <master-name> <ip> <redis-port> <quorum>
6
+ #
7
+ # Tells Sentinel to monitor this master, and to consider it in O_DOWN
8
+ # (Objectively Down) state only if at least <quorum> sentinels agree.
9
+ #
10
+ # Note that whatever is the ODOWN quorum, a Sentinel will require to
11
+ # be elected by the majority of the known Sentinels in order to
12
+ # start a failover, so no failover can be performed in minority.
13
+ #
14
+ # Note: master name should not include special characters or spaces.
15
+ # The valid charset is A-z 0-9 and the three characters ".-_".
16
+ sentinel monitor mymaster 127.0.0.1 6379 2
17
+
18
+ sentinel auth-pass mymaster secret
19
+ #
20
+ # Set the password to use to authenticate with the master and slaves.
21
+ # Useful if there is a password set in the Redis instances to monitor.
22
+ #
23
+ # Note that the master password is also used for slaves, so it is not
24
+ # possible to set a different password in masters and slaves instances
25
+ # if you want to be able to monitor these instances with Sentinel.
26
+ #
27
+ # However you can have Redis instances without the authentication enabled
28
+ # mixed with Redis instances requiring the authentication (as long as the
29
+ # password set is the same for all the instances requiring the password) as
30
+ # the AUTH command will have no effect in Redis instances with authentication
31
+ # switched off.
32
+ #
33
+ # Example:
34
+ #
35
+ # sentinel auth-pass mymaster MySUPER--secret-0123passw0rd
36
+
37
+ # sentinel down-after-milliseconds <master-name> <milliseconds>
38
+ #
39
+ # Number of milliseconds the master (or any attached slave or sentinel) should
40
+ # be unreachable (as in, not acceptable reply to PING, continuously, for the
41
+ # specified period) in order to consider it in S_DOWN state (Subjectively
42
+ # Down).
43
+ #
44
+ # Default is 30 seconds.
45
+ sentinel config-epoch mymaster 0
46
+
47
+ # sentinel parallel-syncs <master-name> <numslaves>
48
+ #
49
+ # How many slaves we can reconfigure to point to the new slave simultaneously
50
+ # during the failover. Use a low number if you use the slaves to serve query
51
+ # to avoid that all the slaves will be unreachable at about the same
52
+ # time while performing the synchronization with the master.
53
+ sentinel known-slave mymaster 127.0.0.1 6380
54
+
55
+ # sentinel failover-timeout <master-name> <milliseconds>
56
+ #
57
+ # Specifies the failover timeout in milliseconds. It is used in many ways:
58
+ #
59
+ # - The time needed to re-start a failover after a previous failover was
60
+ # already tried against the same master by a given Sentinel, is two
61
+ # times the failover timeout.
62
+ #
63
+ # - The time needed for a slave replicating to a wrong master according
64
+ # to a Sentinel current configuration, to be forced to replicate
65
+ # with the right master, is exactly the failover timeout (counting since
66
+ # the moment a Sentinel detected the misconfiguration).
67
+ #
68
+ # - The time needed to cancel a failover that is already in progress but
69
+ # did not produced any configuration change (SLAVEOF NO ONE yet not
70
+ # acknowledged by the promoted slave).
71
+ #
72
+ # - The maximum time a failover in progress waits for all the slaves to be
73
+ # reconfigured as slaves of the new master. However even after this time
74
+ # the slaves will be reconfigured by the Sentinels anyway, but not with
75
+ # the exact parallel-syncs progression as specified.
76
+ #
77
+ # Default is 3 minutes.
78
+ sentinel known-sentinel mymaster 127.0.0.1 63810 c0e485ef82e667ba43b7bffedd7b7c2f080248a8
79
+
80
+ # SCRIPTS EXECUTION
81
+ #
82
+ # sentinel notification-script and sentinel reconfig-script are used in order
83
+ # to configure scripts that are called to notify the system administrator
84
+ # or to reconfigure clients after a failover. The scripts are executed
85
+ # with the following rules for error handling:
86
+ #
87
+ # If script exists with "1" the execution is retried later (up to a maximum
88
+ # number of times currently set to 10).
89
+ #
90
+ # If script exists with "2" (or an higher value) the script execution is
91
+ # not retried.
92
+ #
93
+ # If script terminates because it receives a signal the behavior is the same
94
+ # as exit code 1.
95
+ #
96
+ # A script has a maximum running time of 60 seconds. After this limit is
97
+ # reached the script is terminated with a SIGKILL and the execution retried.
98
+
99
+ # NOTIFICATION SCRIPT
100
+ #
101
+ # sentinel notification-script <master-name> <script-path>
102
+ #
103
+ # Call the specified notification script for any sentinel event that is
104
+ # generated in the WARNING level (for instance -sdown, -odown, and so forth).
105
+ # This script should notify the system administrator via email, SMS, or any
106
+ # other messaging system, that there is something wrong with the monitored
107
+ # Redis systems.
108
+ #
109
+ # The script is called with just two arguments: the first is the event type
110
+ # and the second the event description.
111
+ #
112
+ # The script must exist and be executable in order for sentinel to start if
113
+ # this option is provided.
114
+ #
115
+ # Example:
116
+ #
117
+ # sentinel notification-script mymaster /var/redis/notify.sh
118
+
119
+ # CLIENTS RECONFIGURATION SCRIPT
120
+ #
121
+ # sentinel client-reconfig-script <master-name> <script-path>
122
+ #
123
+ # When the master changed because of a failover a script can be called in
124
+ # order to perform application-specific tasks to notify the clients that the
125
+ # configuration has changed and the master is at a different address.
126
+ #
127
+ # The following arguments are passed to the script:
128
+ #
129
+ # <master-name> <role> <state> <from-ip> <from-port> <to-ip> <to-port>
130
+ #
131
+ # <state> is currently always "failover"
132
+ # <role> is either "leader" or "observer"
133
+ #
134
+ # The arguments from-ip, from-port, to-ip, to-port are used to communicate
135
+ # the old address of the master and the new address of the elected slave
136
+ # (now a master).
137
+ #
138
+ # This script should be resistant to multiple invocations.
139
+ #
140
+ # Example:
141
+ #
142
+ # sentinel client-reconfig-script mymaster /var/redis/reconfig.sh
143
+ # Generated by CONFIG REWRITE
144
+ dir "/home/portertech/projects/sensu/sensu-redis/spec/configs"
145
+ sentinel known-sentinel mymaster 127.0.0.1 63790 092d28f730ac45be8f18569fefa12b0ebd7b230b
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-redis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Porter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-11 00:00:00.000000000 Z
11
+ date: 2016-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eventmachine
@@ -100,7 +100,9 @@ files:
100
100
  - lib/sensu/redis/client.rb
101
101
  - lib/sensu/redis/client/constants.rb
102
102
  - lib/sensu/redis/client/errors.rb
103
+ - lib/sensu/redis/sentinel.rb
103
104
  - sensu-redis.gemspec
105
+ - spec/configs/sentinel.conf
104
106
  homepage: https://github.com/sensu/sensu-redis
105
107
  licenses:
106
108
  - MIT
@@ -125,4 +127,5 @@ rubygems_version: 2.4.5.1
125
127
  signing_key:
126
128
  specification_version: 4
127
129
  summary: The Sensu Redis client library
128
- test_files: []
130
+ test_files:
131
+ - spec/configs/sentinel.conf