ocean-rails 1.29.1 → 1.29.2

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: 3236195a6f9bc09b82f30b266134bdee733b6877
4
- data.tar.gz: da30535ec21331c8881a1762fa19ff7018cb5509
3
+ metadata.gz: 2ae893fab5ff15b722a770f78dc3a8cc5c3e2a85
4
+ data.tar.gz: 41be8d155e026f08656b3e9eec974c04d3e93522
5
5
  SHA512:
6
- metadata.gz: f9678c833b9e144b0b67f1feb0e184697972a513df86f1c299715ac927f435537fede88c1c95bef8ec8974603d34cd1559a7f900f65801f9915702c99d1c0881
7
- data.tar.gz: da707d98896f96f514c1d0b343a1ea5b08942458c66cc6d9b8778e6afdf4080ab7274e82c4002537c0f2280e600c65363a26526646eceae34f6a71c9c478c3e4
6
+ metadata.gz: 5dc70080114ec6aa9ec9812c1f6c7c3de720bbe1b3f265d2d9bb0367a5e6cc15720709bf5f8b3b7bd14fdca053a17b7a3df8952bb17752e51ca054008e01f7e3
7
+ data.tar.gz: 585963133384bc06788fb2fd5ee61646d98767c414bcc97f8ef33ec99ad4b3e675779baf1fbe625f7835b24231e7f9177dc84f7409034f15940ac1584382b83c
@@ -1,14 +1,5 @@
1
- # If we're running in production, assign another ZMQ logger here.
2
- # Another one is assigned in the app's config/application.rb - for some
3
- # reason, assigning one in config/environments/production.rb won't work.
4
- # Why this is so is an irritating mystery.
5
-
6
1
  if Rails.env == 'production' && ENV['NO_ZEROMQ_LOGGING'].blank?
7
2
 
8
- # Use a different logger for distributed setups
9
- Rails.logger = ZeromqLogger.new
10
- Rails.logger.level = Logger::INFO
11
-
12
3
  # Announce us
13
4
  Rails.logger.info "Initialising Rails process"
14
5
 
@@ -90,21 +90,16 @@ class OceanSetupGenerator < Rails::Generators::NamedBase #:nodoc: all
90
90
  git :init
91
91
  end
92
92
 
93
- def add_production_zeromq_logging
94
- inject_into_file 'config/application.rb', before: "module " do <<-'RUBY'
95
- # If we're running in production, assign the first ZMQ logger here
96
- # (another one is assigned by the ocean-rails gem in an initializer).
97
- # Why this has to be done in two distinct places is an irritating mystery.
98
- Rails.logger = ZeromqLogger.new if Rails.env == "production"
99
-
100
- RUBY
101
- end
102
- end
93
+ def add_zeromq_logging_in_production
94
+ prepend_to_file 'config/environments/production.rb',
95
+ "Rails.logger = ZeromqLogger.new\n\n"
96
+ end
103
97
 
104
98
  def turn_off_view_logging_in_production
105
99
  application(nil, env: "production") do
106
100
  "# We don't want to see view render lines in production.
107
- config.action_view.logger = nil"
101
+ config.action_view.logger = nil
102
+ "
108
103
  end
109
104
  end
110
105
 
data/lib/ocean/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ocean
2
- VERSION = "1.29.1"
2
+ VERSION = "1.29.2"
3
3
  end
@@ -1,6 +1,5 @@
1
1
  require 'ffi-rzmq'
2
2
 
3
-
4
3
  #
5
4
  # This is the class that provides the interface to ZeroMQ, both for sending log
6
5
  # data to a cluster of log servers, and for receiving it.
@@ -24,8 +23,8 @@ class ZeroLog
24
23
  # set up for the use of all threads in the process. A process exit
25
24
  # handler will be set up to terminate the context on exit.
26
25
  #
27
- def initialize
28
- super
26
+ def initialize(sub_push, log_hosts)
27
+ super()
29
28
  unless @@context
30
29
  #puts "Creating context"
31
30
  @@context = ZMQ::Context.new(1)
@@ -33,15 +32,18 @@ class ZeroLog
33
32
  at_exit { @@context.terminate
34
33
  #puts "Context terminated"
35
34
  }
35
+ #puts "Initialising the log data sender thread"
36
+ setup_sub_server(sub_push, log_hosts)
36
37
  end
37
- end
38
+ connect_to_sub_server(sub_push)
39
+ end
38
40
 
39
41
 
40
42
  #
41
43
  # This method returns the ZeroMQ Context object.
42
44
  #
43
45
  def context
44
- @@context
46
+ @@context
45
47
  end
46
48
 
47
49
 
@@ -75,7 +77,7 @@ class ZeroLog
75
77
  # all available +LOG_HOSTS+. ZeroMQ handles buffering, re-connection and multiplexing
76
78
  # (round-robin) to the +LOG_HOSTS+ +PULL+ servers.
77
79
  #
78
- def init_log_data_sender(sub_push="sub_push")
80
+ def setup_sub_server(sub_push="sub_push", log_hosts=[])
79
81
  # First create the server and let it bind, as this is required
80
82
  # when using inproc: bind must precede any connects.
81
83
  Thread.new(context) do |c|
@@ -87,7 +89,7 @@ class ZeroLog
87
89
  subscriber.setsockopt(ZMQ::SUBSCRIBE, "")
88
90
  # Set up the PUSH socket
89
91
  loggers = context.socket(ZMQ::PUSH)
90
- LOG_HOSTS.each do |host|
92
+ log_hosts.each do |host|
91
93
  #puts "Connecting to the PULL server #{host}"
92
94
  loggers.connect("tcp://#{host}:10000")
93
95
  end
@@ -100,9 +102,11 @@ class ZeroLog
100
102
  loggers.close
101
103
  #puts "Closed sockets in other thread"
102
104
  end
103
-
104
105
  sleep 0.1 # Brute force and primitive, but it works
106
+ end
107
+
105
108
 
109
+ def connect_to_sub_server(sub_push="sub_push")
106
110
  # Next create the PUB socket and connect it to the other thread
107
111
  #puts "Creating the PUB socket"
108
112
  $log_publisher = context.socket(ZMQ::PUB)
@@ -146,10 +150,10 @@ class ZeroLog
146
150
  # round-robin fashion to each PULL log worker on the machine.
147
151
  #
148
152
  def pull_server(address=PUSH_ADDRESS)
149
- #puts "Starting PULL server"
150
- puller = context.socket(ZMQ::PULL)
151
- #puts "Binding to the PULL socket"
152
- puller.bind("tcp://*:10000")
153
+ #puts "Starting PULL server"
154
+ puller = context.socket(ZMQ::PULL)
155
+ #puts "Binding to the PULL socket"
156
+ puller.bind("tcp://*:10000")
153
157
  # Set up the PUSH socket
154
158
  pusher = context.socket(ZMQ::PUSH)
155
159
  #puts "Binding to the PUSH socket"
@@ -167,17 +171,17 @@ class ZeroLog
167
171
  # processing (such as storing received log info in a database).
168
172
  #
169
173
  def pull_worker(address=PUSH_ADDRESS)
170
- #puts "Starting PULL worker"
171
- puller = context.socket(ZMQ::PULL)
172
- #puts "Connect to the PUSH socket"
174
+ #puts "Starting PULL worker"
175
+ puller = context.socket(ZMQ::PULL)
176
+ #puts "Connect to the PUSH socket"
173
177
  puller.connect(address)
174
178
  trap_int(puller)
175
179
 
176
- while true do
177
- s = ''
178
- puller.recv_string(s)
179
- puts "Received: #{s}"
180
- end
180
+ while true do
181
+ s = ''
182
+ puller.recv_string(s)
183
+ puts "Received: #{s}"
184
+ end
181
185
  end
182
186
 
183
187
 
@@ -9,7 +9,6 @@ require 'socket'
9
9
  class ZeromqLogger
10
10
 
11
11
  attr_accessor :level, :log_tags
12
- attr_accessor :formatter
13
12
 
14
13
  #
15
14
  # Obtains the IP of the current process, initialises the @logger object
@@ -20,10 +19,12 @@ class ZeromqLogger
20
19
  super
21
20
  # Get info about our environment
22
21
  @ip = Socket.ip_address_list.detect{|intf| intf.ipv4_private?}.getnameinfo[0]
22
+ # Find the log hosts
23
+ f = File.join(Rails.root, "config/config.yml")
24
+ cfg = YAML.load(ERB.new(File.read(f)).result)
25
+ @log_hosts = cfg['LOG_HOSTS'].blank? ? cfg['production']['LOG_HOSTS'] : cfg['LOG_HOSTS']
23
26
  # Set up the logger
24
- @logger = ZeroLog.new
25
- @logger.init_log_data_sender "/tmp/sub_push_#{Process.pid}"
26
- @formatter = ::Logger::Formatter.new
27
+ @logger = ZeroLog.new "/tmp/sub_push_#{Process.pid}", @log_hosts
27
28
  end
28
29
 
29
30
  #
@@ -70,11 +71,10 @@ class ZeromqLogger
70
71
  #
71
72
  # +msg+: The log message itself.
72
73
  #
73
- def add(level, msg, progname="")
74
+ def add(level, msg)
74
75
  return true if level < @level
75
- msg = progname if msg.blank?
76
76
  return true if msg.blank? # Don't send
77
- #puts "Adding #{level} #{msg} #{progname}"
77
+ #puts "Adding #{level} #{msg}"
78
78
  milliseconds = (Time.now.utc.to_f * 1000).to_i
79
79
  data = { timestamp: milliseconds,
80
80
  ip: @ip,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ocean-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.29.1
4
+ version: 1.29.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Bengtson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-04 00:00:00.000000000 Z
11
+ date: 2014-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday