liquid-ext 3.0.0 → 3.1.0

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: 5b4739125c0f045cc43cf1d3dc7658d0d06f0b64
4
- data.tar.gz: e3bd9b7031b166c16c799c7064149bb2c2cc4499
3
+ metadata.gz: dfbcd20250a0066048dcab544302bca615d206dd
4
+ data.tar.gz: 8a243e57e1b841ad3d8332a7ddd40ec9d7644bdd
5
5
  SHA512:
6
- metadata.gz: 02a4e55a0fc87c47b2e2f994c2d6ae8fe056847b5bc60968e3d0751d1cc852770bd93fd36f9d13eb6f6f870d33c10d21bca067441ea3e4ee1a568c67f434a4db
7
- data.tar.gz: f732a993fc2509cbe4e89c73021d49170ec8776bd9a348a8d4fce366918c471a6577d52b3ce49e91bcabdcc0cda6175a410a5d0dd9a7e8f10e2e043e012b5990
6
+ metadata.gz: db62f25e0a6df2e7d7ed713f9835b5bb8167dcd03e64bf6cafdd386f6bcaaa036b8dfc04d1abcd07d798bc420b05cded59c827bda0e7a793d22d5ed0ec2e9c4e
7
+ data.tar.gz: ac739d492960eb506e17281fbd0548a8741c3e6f8c7495b633dfbe56bf438ed610f5451ee8e61e758b178951e481101dff8643f2963a6006de2463d34ccd038c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- liquid-ext (3.0.0)
4
+ liquid-ext (3.1.0)
5
5
  activesupport
6
6
  erubis
7
7
  mixlib-cli
@@ -16,7 +16,7 @@ GEM
16
16
  multi_json (~> 1.3)
17
17
  thread_safe (~> 0.1)
18
18
  tzinfo (~> 0.3.37)
19
- atomic (1.1.14-java)
19
+ atomic (1.1.15-java)
20
20
  awesome_print (1.2.0)
21
21
  bond (0.5.1-java)
22
22
  brice (0.2.9)
@@ -24,7 +24,6 @@ GEM
24
24
  cane (2.6.1)
25
25
  parallel
26
26
  coderay (1.1.0)
27
- columnize (0.3.6)
28
27
  diff-lcs (1.2.5)
29
28
  docile (1.1.3)
30
29
  erubis (2.7.0)
@@ -34,7 +33,7 @@ GEM
34
33
  ruby-progressbar (~> 1.3)
35
34
  hirb (0.7.1)
36
35
  i18n (0.6.9)
37
- liquid-development (0.2.0)
36
+ liquid-development (0.2.1)
38
37
  awesome_print
39
38
  bond
40
39
  brice
@@ -47,7 +46,6 @@ GEM
47
46
  rib
48
47
  ripl
49
48
  rspec
50
- ruby-debug
51
49
  simplecov
52
50
  tailor
53
51
  timecop
@@ -77,14 +75,10 @@ GEM
77
75
  rspec-core (~> 2.14.0)
78
76
  rspec-expectations (~> 2.14.0)
79
77
  rspec-mocks (~> 2.14.0)
80
- rspec-core (2.14.7)
78
+ rspec-core (2.14.8)
81
79
  rspec-expectations (2.14.5)
82
80
  diff-lcs (>= 1.1.3, < 2.0)
83
81
  rspec-mocks (2.14.6)
84
- ruby-debug (0.10.4)
85
- columnize (>= 0.1)
86
- ruby-debug-base (~> 0.10.4.0)
87
- ruby-debug-base (0.10.4-java)
88
82
  ruby-nuggets (0.9.6)
89
83
  ruby-progressbar (1.4.1)
90
84
  ruby2ruby (2.0.7)
@@ -110,8 +104,8 @@ GEM
110
104
  tins (~> 1.0)
111
105
  terminal-table (1.4.5)
112
106
  text-table (1.2.3)
113
- thread_safe (0.1.3-java)
114
- atomic
107
+ thread_safe (0.2.0-java)
108
+ atomic (>= 1.1.7, < 2)
115
109
  timecop (0.7.1)
116
110
  tins (1.0.0)
117
111
  tzinfo (0.3.38)
data/lib/liquid/boot.rb CHANGED
@@ -54,14 +54,16 @@ require 'liquid/environment'
54
54
  require 'liquid/from_file'
55
55
  require 'liquid/hash_helper'
56
56
  require 'liquid/metrics'
57
+ require 'liquid/server'
57
58
  require 'liquid/timing'
59
+ require 'liquid/tracker'
58
60
  require 'liquid/transaction_id'
59
61
  require 'liquid/zmq'
60
62
 
61
63
  # configuration callbacks
62
64
  require 'liquid/logger'
63
65
  reload_logger = ->(conf) do
64
- $log = Liquid::Logger.new("root")
66
+ $log ||= Liquid::Logger.new("root")
65
67
  end
66
68
 
67
69
  reload_mixins = ->(conf) do
@@ -88,6 +90,18 @@ $conf.mixin({
88
90
  level: :info,
89
91
  format: "%d{ISO8601} %-5p #{File.basename($0)}(#{Process.pid})[%t]: %m%n",
90
92
  },
93
+ tracker: {
94
+ dimensions: {},
95
+ kafka: {
96
+ enabled: false,
97
+ brokers: [
98
+ '0.0.0.0:9092'
99
+ ]
100
+ },
101
+ },
102
+ zmachine: {
103
+ debug: false,
104
+ },
91
105
  },
92
106
  production: {
93
107
  log: {
data/lib/liquid/logger.rb CHANGED
@@ -14,6 +14,7 @@ module Liquid
14
14
  @progname = progname || File.basename($0)
15
15
  @logger = LoggerFactory.getLogger(name)
16
16
  @exceptions = {}
17
+ @exception_handlers = [method(:_log_error_exception)]
17
18
  root = org.apache.log4j.Logger.getRootLogger
18
19
  appender = org.apache.log4j.ConsoleAppender.new
19
20
  appender.name = "console"
@@ -74,7 +75,17 @@ module Liquid
74
75
  @logger.error(format(*args))
75
76
  end
76
77
 
78
+ def add_exception_handler(&block)
79
+ @exception_handlers << block
80
+ end
81
+
77
82
  def exception(exc, message = nil, attribs = {})
83
+ @exception_handlers.each do |callback|
84
+ callback.call(exc, message, attribs)
85
+ end
86
+ end
87
+
88
+ def _log_error_exception(exc, message, attribs)
78
89
  ::Metrics.meter("exception:#{exc.class.to_s.tableize}").mark
79
90
  @exceptions[exc.class] ||= {}
80
91
  @exceptions[exc.class][exc.backtrace.first] ||= [System.nano_time, 1, 1]
@@ -0,0 +1,46 @@
1
+ require 'liquid/metrics'
2
+ require 'liquid/tracker'
3
+
4
+ module Liquid
5
+ class Server
6
+ def initialize
7
+ $log.info("#{self.class.name.downcase} #{RUBY_DESCRIPTION}")
8
+ $log.info("#{self.class.name.downcase}", env: Env.mode)
9
+ initialize_tracker
10
+ initialize_metrics
11
+ end
12
+
13
+ def initialize_tracker
14
+ if $conf.tracker.kafka.enabled
15
+ # http://kafka.apache.org/documentation.html#producerconfigs
16
+ properties = java.util.Properties.new
17
+ properties['metadata.broker.list'] = $conf.tracker.kafka.brokers.join(',')
18
+ properties['producer.type'] = 'async'
19
+ properties['serializer.class'] = 'kafka.serializer.StringEncoder'
20
+ $tracker = ::Tracker::KafkaTracker.new(properties, $conf.tracker.dimensions)
21
+ else
22
+ $tracker = ::Tracker::LoggerTracker.new($conf.tracker.dimensions)
23
+ end
24
+ Signal.register_shutdown_handler { $tracker.shutdown }
25
+ end
26
+
27
+ def initialize_metrics
28
+ ::Metrics.start
29
+ ::Metrics::TrackerReporter.new($tracker.with_topic('metrics'))
30
+ Signal.register_shutdown_handler { ::Metrics.stop }
31
+ end
32
+
33
+ def initialize_zmachine
34
+ ZMachine.logger = $log
35
+ ZMachine.debug = true if $conf.zmachine.debug
36
+ ZMachine.heartbeat_interval = 0.1
37
+ Signal.register_shutdown_handler { ZMachine.stop }
38
+ end
39
+
40
+ def run
41
+ # by default wait for all workers
42
+ Thread.join
43
+ end
44
+
45
+ end
46
+ end
@@ -2,25 +2,26 @@ require 'liquid/tracker/json_serializer'
2
2
 
3
3
  module Tracker
4
4
  class Base
5
- attr_accessor :serializer
5
+ attr_accessor :dimensions
6
6
 
7
7
  def initialize(dimensions = {})
8
- @serializer = JsonSerializer.new(dimensions)
8
+ @dimensions = dimensions
9
9
  end
10
10
 
11
- def with_topic(topic)
12
- Topic.new(topic, self)
11
+ def with_topic(topic, serializer = nil)
12
+ Topic.new(topic, self, serializer)
13
13
  end
14
14
  end
15
15
 
16
16
  class Topic
17
- def initialize(topic, tracker)
17
+ def initialize(topic, tracker, serializer = nil)
18
18
  @topic = topic
19
19
  @tracker = tracker
20
+ @serializer = (serializer || JsonSerializer).new(tracker.dimensions)
20
21
  end
21
22
 
22
23
  def event(obj)
23
- @tracker.event(obj, @topic)
24
+ @tracker.event(@topic, @serializer.dump(obj))
24
25
  end
25
26
  end
26
27
  end
@@ -2,7 +2,7 @@ require 'liquid/tracker/base'
2
2
 
3
3
  module Tracker
4
4
  class BlackholeTracker < Base
5
- def event(obj, topic)
5
+ def event(topic, data)
6
6
  end
7
7
 
8
8
  def down?
@@ -3,10 +3,10 @@ require 'liquid/tracker/base'
3
3
  module Tracker
4
4
  class FileTracker < Base
5
5
 
6
- def event(obj, topic)
6
+ def event(topic, data)
7
7
  file = File.open(File.join(ROOT, 'log', "tracker-#{topic}.log"), 'a')
8
8
  file.sync = true
9
- file.write(@serializer.dump(obj))
9
+ file.write(data)
10
10
  file.write("\n")
11
11
  file.close
12
12
  end
@@ -24,8 +24,8 @@ module Tracker
24
24
  false
25
25
  end
26
26
 
27
- def event(obj, topic)
28
- @producer.send(KeyedMessage.new(topic, @serializer.dump(obj)))
27
+ def event(topic, data)
28
+ @producer.send(KeyedMessage.new(topic, data))
29
29
  rescue => e
30
30
  # TODO: maybe fall back to FileTracker here
31
31
  $log.exception(e, "failed to log event=#{obj.inspect}")
@@ -3,8 +3,8 @@ require 'liquid/tracker/base'
3
3
 
4
4
  module Tracker
5
5
  class LoggerTracker < Base
6
- def event(obj, topic)
7
- $log.info("tracker:event:#{topic} #{@serializer.dump(obj)}")
6
+ def event(topic, data)
7
+ $log.info("tracker:event:#{topic} #{data}")
8
8
  end
9
9
 
10
10
  def down?
data/liquid-ext.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "liquid-ext"
5
- spec.version = "3.0.0"
5
+ spec.version = "3.1.0"
6
6
  spec.authors = ["LiquidM, Inc."]
7
7
  spec.email = ["opensource@liquidm.com"]
8
8
  spec.description = %q{Ruby core extensions and helper libraries}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: liquid-ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - LiquidM, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-25 00:00:00.000000000 Z
11
+ date: 2014-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -117,6 +117,7 @@ files:
117
117
  - lib/liquid/priority_selector.rb
118
118
  - lib/liquid/router.rb
119
119
  - lib/liquid/scala-library-2.10.3.jar
120
+ - lib/liquid/server.rb
120
121
  - lib/liquid/slf4j-api-1.7.6.jar
121
122
  - lib/liquid/slf4j-log4j12-1.7.6.jar
122
123
  - lib/liquid/snappy-java-1.1.1-M1.jar