cassie 1.0.0.beta.29 → 1.0.0.beta.30

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2c90b951d56530cc2918328a804cf6d8c5763f5b
4
- data.tar.gz: 6c780aee83ce4a01b70050e3f843de9dc9c144d2
3
+ metadata.gz: faffda9455104b05f68acd9313cbc3ba48ba0f47
4
+ data.tar.gz: 24bc30a2b15426d1ff225f23284b0683fc8de7b8
5
5
  SHA512:
6
- metadata.gz: 086fad192b6335fa9bef4dbb7e3969f6f96036cfb2003f9223548c87ba2e60e597d443f6063e6a9572a1a3d6dbb7cbe4836cf264d56cc48da56ac11ca6c92c4c
7
- data.tar.gz: b22ebc36e2c20273bb9bcfd464970bb4750c97307493b1be8ab8db65f7bc6a7b62500e7080144bbcf2096071ba83a5de27eb063fb1f77fbc87f91ef1cec882ab
6
+ metadata.gz: 5e7efbf49fbf44bb0f76694fc8d8fb600463fc3886872ba68d9806626cc96ff430c668fad6fcbe430dd14344d9d0055eb6dc82677c409d36e6435ac71f71fca0
7
+ data.tar.gz: 1c023dc9ef689426606452abdd438649635ad3078437f77b401b16d52a422affcd0072e8977b3f6efd378d9f29e54526b8bdc96199d2504aad51288a9ed09fe6
@@ -0,0 +1,15 @@
1
+ module Cassie::ConnectionHandler::Cluster
2
+ module Instrumentation
3
+
4
+ protected
5
+
6
+ def initialize_cluster
7
+ Cassie.instrumenter.instrument("cassie.cluster.connect") do |payload|
8
+ super.tap do |cluster|
9
+ payload[:hosts] = cluster.hosts
10
+ payload[:name] = cluster.name
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,5 +1,3 @@
1
- require 'benchmark'
2
-
3
1
  module Cassie::ConnectionHandler
4
2
  # ## Cassie::ConnectionHandler::Cluster
5
3
  #
@@ -8,22 +6,24 @@ module Cassie::ConnectionHandler
8
6
  # Include in any class or module that responds to `configuration` with
9
7
  # a cassandra cluster options hash.
10
8
  module Cluster
9
+ require_relative 'cluster/instrumentation'
10
+ extend ActiveSupport::Concern
11
+
12
+ included do
13
+ include Instrumentation
14
+ end
11
15
 
12
16
  def cluster
13
17
  # Cassandra::cluster parses suppored
14
18
  # options from the passed hash, no need
15
19
  # to validate/transform ourselves yet
16
- @cluster ||= begin
17
- _cluster = nil
18
- config = configuration.try(:symbolize_keys)
20
+ @cluster ||= initialize_cluster
21
+ end
19
22
 
20
- sec = Benchmark.realtime do
21
- _cluster = Cassandra.cluster(config)
22
- end
23
+ protected
23
24
 
24
- logger.info "(#{(sec*1000).round(2)}ms) Connected to Cassandra cluster #{config[:hosts]}"
25
- _cluster
26
- end
25
+ def initialize_cluster
26
+ Cassandra.cluster(configuration.try(:symbolize_keys))
27
27
  end
28
28
  end
29
29
  end
@@ -0,0 +1,31 @@
1
+ module Cassie::ConnectionHandler::Logging
2
+ class ClusterConnectEvent < ActiveSupport::Notifications::Event
3
+
4
+ def hosts
5
+ payload[:hosts] || []
6
+ end
7
+
8
+ def ips
9
+ hosts.map{ |h| h.ip.to_s }
10
+ end
11
+
12
+ def message
13
+ {
14
+ event: "cassie.cluster.connect",
15
+ duration: duration.round(1),
16
+ hosts: ips,
17
+ name: payload[:name]
18
+ }.extend(Inspector)
19
+ end
20
+
21
+ module Inspector
22
+ def inspect
23
+ "(#{fetch(:duration).round(1)}ms) Connected to Cassandra cluster. #{fetch(:name)}: #{fetch(:hosts)}"
24
+ end
25
+
26
+ def to_s
27
+ inspect
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,19 @@
1
+ require_relative 'cluster_connect_event'
2
+
3
+ module Cassie::ConnectionHandler::Logging
4
+ class ClusterConnectSubscriber
5
+
6
+ def call(*args)
7
+ # don't log if instrumentation failed
8
+ unless args.last[:exception]
9
+ logger.info(ClusterConnectEvent.new(*args).message)
10
+ end
11
+ end
12
+
13
+ def logger
14
+ Cassie::Statements.logger
15
+ end
16
+
17
+ ActiveSupport::Notifications.subscribe('cassie.cluster.connect', new)
18
+ end
19
+ end
@@ -0,0 +1,26 @@
1
+ module Cassie::ConnectionHandler::Logging
2
+ class SessionConnectEvent < ActiveSupport::Notifications::Event
3
+
4
+ def keyspace
5
+ payload[:keyspace] || "[none]"
6
+ end
7
+
8
+ def message
9
+ {
10
+ event: "cassie.session.connect",
11
+ duration: duration.round(1),
12
+ keyspace: keyspace
13
+ }.extend(Inspector)
14
+ end
15
+
16
+ module Inspector
17
+ def inspect
18
+ "(#{fetch(:duration).round(1)}ms) Session opened to Cassandra cluster. Keyspace: #{fetch(:keyspace)}"
19
+ end
20
+
21
+ def to_s
22
+ inspect
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,19 @@
1
+ require_relative 'session_connect_event'
2
+
3
+ module Cassie::ConnectionHandler::Logging
4
+ class SessionConnectSubscriber
5
+
6
+ def call(*args)
7
+ # don't log if instrumentation failed
8
+ unless args.last[:exception]
9
+ logger.info(SessionConnectEvent.new(*args).message)
10
+ end
11
+ end
12
+
13
+ def logger
14
+ Cassie::Statements.logger
15
+ end
16
+
17
+ ActiveSupport::Notifications.subscribe('cassie.session.connect', new)
18
+ end
19
+ end
@@ -0,0 +1,7 @@
1
+ module Cassie::ConnectionHandler
2
+ module Logging
3
+ require_relative 'logging/cluster_connect_subscriber'
4
+ require_relative 'logging/session_connect_subscriber'
5
+
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ module Cassie::ConnectionHandler::Sessions
2
+ module Instrumentation
3
+
4
+ protected
5
+
6
+ def initialize_session(*args)
7
+ Cassie.instrumenter.instrument("cassie.session.connect") do |payload|
8
+ super(*args)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,27 +1,24 @@
1
- require 'benchmark'
2
-
3
1
  module Cassie::ConnectionHandler
4
2
  module Sessions
3
+ require_relative 'sessions/instrumentation'
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ include Instrumentation
8
+ end
5
9
 
6
10
  def sessions
7
11
  @sessions ||= {}
8
12
  end
9
13
 
10
- def session(_keyspace=self.keyspace)
11
- sessions[_keyspace] || connect(_keyspace)
14
+ def session(keyspace=self.keyspace)
15
+ sessions[keyspace] || initialize_session(keyspace)
12
16
  end
13
17
 
14
18
  protected
15
19
 
16
- def connect(_keyspace)
17
- _session = nil
18
-
19
- sec = Benchmark.realtime do
20
- _session = cluster.connect(_keyspace)
21
- end
22
-
23
- logger.info "(#{(sec*1000).round(2)}ms) Session opened to Cassandra[#{_keyspace}]"
24
- @sessions[_keyspace] = _session
20
+ def initialize_session(keyspace)
21
+ @sessions[keyspace] = cluster.connect(keyspace)
25
22
  end
26
23
  end
27
24
  end
@@ -6,6 +6,7 @@ module Cassie
6
6
  module ConnectionHandler
7
7
  require_relative 'connection_handler/cluster'
8
8
  require_relative 'connection_handler/sessions'
9
+ require_relative 'connection_handler/logging'
9
10
 
10
11
  include Cluster
11
12
  include Sessions
@@ -1,5 +1,4 @@
1
- module Cassie::Statements
2
-
1
+ module Cassie
3
2
  def self.instrumenter
4
3
  @instrumenter ||= ActiveSupport::Notifications
5
4
  end
@@ -2,17 +2,13 @@ module Cassie::Statements::Execution
2
2
  module Instrumentation
3
3
 
4
4
  def execute
5
- instrumenter.instrument("cassie.cql.execution") do |payload|
5
+ Cassie.instrumenter.instrument("cassie.cql.execution") do |payload|
6
6
  execution_val = super #execution populates #result
7
7
 
8
8
  payload[:execution_info] = result.execution_info if result.respond_to?(:execution_info)
9
9
  execution_val
10
10
  end
11
11
  end
12
-
13
- def instrumenter
14
- Cassie::Statements.instrumenter
15
- end
16
12
  end
17
13
  end
18
14
 
@@ -2,12 +2,12 @@ require_relative 'simple_policy'
2
2
 
3
3
  module Cassie::Statements::Execution::PartitionLinking
4
4
  class CursoringPolicy < SimplePolicy
5
-
5
+
6
6
  def combine_rows(rows_a, rows_b)
7
7
  return super unless peeking_execution.since_cursor
8
8
  rows_b
9
9
  end
10
-
10
+
11
11
  def adjust_limit
12
12
  return super unless peeking_execution.since_cursor
13
13
  # leave the limit to return all results
@@ -17,18 +17,18 @@ module Cassie::Statements::Execution::PartitionLinking
17
17
  def seek_partition?
18
18
  return super unless peeking_execution.since_cursor
19
19
  raise "linking partitions only supported for descending orderings. Open an issue if you need this!" if ascending?
20
-
20
+
21
21
  # linking while cursoring with since
22
22
  # should return latest results
23
23
  current_key != last_key
24
24
  end
25
-
25
+
26
26
  def previous_key(current_key)
27
27
  return super unless peeking_execution.since_cursor
28
-
28
+
29
29
  # linking while cursoring with since
30
30
  # should return results from latest partition
31
- last_key
31
+ last_key
32
32
  end
33
33
  end
34
34
  end
@@ -4,15 +4,11 @@ module Cassie::Statements::Results
4
4
  protected
5
5
 
6
6
  def records
7
- instrumenter.instrument("cassie.deserialize") do |payload|
7
+ Cassie.instrumenter.instrument("cassie.deserialize") do |payload|
8
8
  records = super
9
9
  payload[:count] = records.count if records.respond_to?(:count)
10
10
  records
11
11
  end
12
12
  end
13
-
14
- def instrumenter
15
- Cassie::Statements.instrumenter
16
- end
17
13
  end
18
14
  end
@@ -3,7 +3,6 @@ module Cassie
3
3
  require_relative 'statements/core'
4
4
  require_relative 'statements/query'
5
5
  require_relative 'statements/modification'
6
- require_relative 'statements/instrumenting'
7
6
  require_relative 'statements/logging'
8
7
  end
9
8
  end
@@ -1,3 +1,3 @@
1
1
  module Cassie
2
- VERSION = "1.0.0.beta.29"
2
+ VERSION = "1.0.0.beta.30"
3
3
  end
data/lib/cassie.rb CHANGED
@@ -14,6 +14,7 @@ require 'cassandra'
14
14
  module Cassie
15
15
  require_relative 'cassie/support'
16
16
  require_relative 'cassie/logger'
17
+ require_relative 'cassie/instrumentation'
17
18
  require_relative 'cassie/configuration'
18
19
  require_relative 'cassie/connection_handler'
19
20
  require_relative 'cassie/connection'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cassie
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta.29
4
+ version: 1.0.0.beta.30
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Prothro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-15 00:00:00.000000000 Z
11
+ date: 2016-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cassandra-driver
@@ -100,8 +100,16 @@ files:
100
100
  - lib/cassie/connection_handler.rb
101
101
  - lib/cassie/connection_handler/README.md
102
102
  - lib/cassie/connection_handler/cluster.rb
103
+ - lib/cassie/connection_handler/cluster/instrumentation.rb
104
+ - lib/cassie/connection_handler/logging.rb
105
+ - lib/cassie/connection_handler/logging/cluster_connect_event.rb
106
+ - lib/cassie/connection_handler/logging/cluster_connect_subscriber.rb
107
+ - lib/cassie/connection_handler/logging/session_connect_event.rb
108
+ - lib/cassie/connection_handler/logging/session_connect_subscriber.rb
103
109
  - lib/cassie/connection_handler/sessions.rb
110
+ - lib/cassie/connection_handler/sessions/instrumentation.rb
104
111
  - lib/cassie/definition.rb
112
+ - lib/cassie/instrumentation.rb
105
113
  - lib/cassie/logger.rb
106
114
  - lib/cassie/migration.rb
107
115
  - lib/cassie/migration/README.md
@@ -144,7 +152,6 @@ files:
144
152
  - lib/cassie/statements/execution/results/query_result.rb
145
153
  - lib/cassie/statements/execution/results/querying.rb
146
154
  - lib/cassie/statements/execution/results/result.rb
147
- - lib/cassie/statements/instrumenting.rb
148
155
  - lib/cassie/statements/logging.rb
149
156
  - lib/cassie/statements/logging/deserialize_event.rb
150
157
  - lib/cassie/statements/logging/deserialize_subscriber.rb