whi-cassie 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/HISTORY.txt +6 -0
- data/README.md +8 -0
- data/VERSION +1 -1
- data/lib/cassie.rb +32 -5
- data/spec/cassie_spec.rb +27 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8392ef6b34920bdde8a689495610115ba637c300
|
4
|
+
data.tar.gz: ccf179a324199af0f1af5c81589634efc44f89a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 715926f6cead3063ea00a364c0b7f30f67c0cf81be18288a78dd16431d95d2496fa845d928afdfd3b206dea78efb6e9d45a41c943d332a138f47225066c4d5da
|
7
|
+
data.tar.gz: 2da40bc6fbc2c2c02594c76cc8c719c495db90a5b5983cf791e0b243bf47ce21e85d693c53398b051b4576479bb46c9467e25b60e5caac4d203266617c07ab18
|
data/HISTORY.txt
CHANGED
data/README.md
CHANGED
@@ -204,6 +204,14 @@ end
|
|
204
204
|
|
205
205
|
You'll need something similar on other web servers. In any case, you'll want to make sure that you call Cassie.instance.connect in an initializer. It can take several seconds to establish the connection so you really want the connection to created before your server starts accepting traffic.
|
206
206
|
|
207
|
+
### Instrumentation
|
208
|
+
|
209
|
+
You can add instrumentation via subscribers to the `Cassie.instance`. Subscribers must respond to the `call` method and take a single argument which will be a Cassie::Message object which has the `statement`, `options`, and `elapsed_time`.
|
210
|
+
|
211
|
+
```
|
212
|
+
Cassie.instance.subscribers << lambda{|message| logger.warn("CQL: #{message.statement.cql} with #{message.options} took #{message.elapsed_time}s") if message.elapsed_time > 0.5 && message.statement.cql}
|
213
|
+
```
|
214
|
+
|
207
215
|
### Limitations
|
208
216
|
|
209
217
|
Ruby 2.0 (or compatible) required.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.5
|
data/lib/cassie.rb
CHANGED
@@ -21,7 +21,20 @@ class Cassie
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
|
24
|
+
# Message passed to subscribers with the statement, options, and time for each statement
|
25
|
+
# to execute. Note that if statements are batched they will be packed into one message
|
26
|
+
# with a Cassandra::Statements::Batch statement and empty options.
|
27
|
+
class Message
|
28
|
+
attr_reader :statement, :options, :elapsed_time
|
29
|
+
|
30
|
+
def initialize(statement, options, elapsed_time)
|
31
|
+
@statement = statement
|
32
|
+
@options = options
|
33
|
+
@elapsed_time = elapsed_time
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
attr_reader :config, :subscribers
|
25
38
|
|
26
39
|
class << self
|
27
40
|
# A singleton instance that can be shared to communicate with a Cassandra cluster.
|
@@ -75,6 +88,7 @@ class Cassie
|
|
75
88
|
@session = nil
|
76
89
|
@prepared_statements = {}
|
77
90
|
@last_prepare_warning = Time.now
|
91
|
+
@subscribers = []
|
78
92
|
end
|
79
93
|
|
80
94
|
# Open a connection to the Cassandra cluster.
|
@@ -272,15 +286,15 @@ class Cassie
|
|
272
286
|
if default_consistency
|
273
287
|
options = (options ? options.reverse_merge(:consistency => default_consistency) : {:consistency => default_consistency})
|
274
288
|
end
|
275
|
-
|
289
|
+
|
276
290
|
session.execute(statement, options || {})
|
277
291
|
rescue Cassandra::Errors::IOError => e
|
278
292
|
disconnect
|
279
293
|
raise e
|
280
294
|
ensure
|
281
|
-
|
282
|
-
|
283
|
-
|
295
|
+
unless subscribers.empty?
|
296
|
+
payload = Message.new(statement, options, Time.now - start_time)
|
297
|
+
subscribers.each{|subscriber| subscriber.call(payload)}
|
284
298
|
end
|
285
299
|
end
|
286
300
|
end
|
@@ -321,4 +335,17 @@ class Cassie
|
|
321
335
|
end
|
322
336
|
[cql.join(' AND '), values]
|
323
337
|
end
|
338
|
+
|
339
|
+
# Extract the CQL from a statement
|
340
|
+
def statement_cql(statement, previous = nil)
|
341
|
+
cql = nil
|
342
|
+
if statement.respond_to?(:cql)
|
343
|
+
cql = statement.cql
|
344
|
+
elsif statement.respond_to?(:statements) && (previous.nil? || !previous.include?(statement))
|
345
|
+
previous ||= []
|
346
|
+
previous << statement
|
347
|
+
cql = statement.statements.collect{|s| statement_cql(s, previous)}.join('; ')
|
348
|
+
end
|
349
|
+
cql
|
350
|
+
end
|
324
351
|
end
|
data/spec/cassie_spec.rb
CHANGED
@@ -120,6 +120,33 @@ describe Cassie do
|
|
120
120
|
it "should prepare and execute a CQL statement when values are provided" do
|
121
121
|
instance.execute("SELECT owner, id, val FROM #{table} WHERE owner = ?", [1]).size.should == 1
|
122
122
|
end
|
123
|
+
|
124
|
+
it "should call subscribers with details about the call" do
|
125
|
+
instance.subscribers.clear
|
126
|
+
begin
|
127
|
+
messages = []
|
128
|
+
instance.subscribers << lambda{|details| messages << details}
|
129
|
+
|
130
|
+
instance.execute("SELECT owner, id, val FROM #{table} WHERE owner = ?", [1])
|
131
|
+
messages.size.should == 1
|
132
|
+
message = messages.shift
|
133
|
+
message.statement.should be_a(Cassandra::Statement)
|
134
|
+
message.options.should == {:arguments => [1]}
|
135
|
+
message.elapsed_time.should be_a(Float)
|
136
|
+
|
137
|
+
instance.batch do
|
138
|
+
instance.insert(table, :owner => 1, :id => 2, :val => 'foo')
|
139
|
+
instance.delete(table, :owner => 1)
|
140
|
+
end
|
141
|
+
messages.size.should == 1
|
142
|
+
message = messages.shift
|
143
|
+
message.statement.should be_a(Cassandra::Statements::Batch)
|
144
|
+
message.options.should == nil
|
145
|
+
message.elapsed_time.should be_a(Float)
|
146
|
+
ensure
|
147
|
+
instance.subscribers.clear
|
148
|
+
end
|
149
|
+
end
|
123
150
|
end
|
124
151
|
|
125
152
|
describe "consistency" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: whi-cassie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- We Heart It
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-05-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cassandra-driver
|