ocean-rails 7.2.2 → 7.2.3

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
  SHA256:
3
- metadata.gz: 7d703c1b9eeb742809031eb05de80b67d9d1095605741b5846f1dfe3ec35ccdf
4
- data.tar.gz: 38ec1bbd1abe2ca487ac2beae2de3e28e65560d9489b8a892fd212bddeec59f6
3
+ metadata.gz: 5b60d92cbf6714865555d363a2f998bc41dcadf121749c522020c9def0b06cc9
4
+ data.tar.gz: 06c7bf20258981bc6b0614fbe795dad279a75be510478c00318ad1790eab198a
5
5
  SHA512:
6
- metadata.gz: d2dbfc032c6b1774136e3a86e8bd073a6a5c820f8808dd3ee3eee561e68d0b7f0e8db439e16906d0a5f02a6da7645911afb20ff6c7eff259503d1502dbd5bb70
7
- data.tar.gz: 9fbd5f15038821e33c3c2545a9738281cccaeb28b666616661212f75799ca54874722128adcb1c42c4657805f1e5ef2343e63a9f12efe2ed8508fa4eba6ef278
6
+ metadata.gz: 3ffb4b655ddcfac4444d1fe93515b616ad6865180d6a7605c570b4831321f361071670c362255b49afc952023483d2f2c664c3e170d34676a4b2e84cf0808921
7
+ data.tar.gz: 36f770a9f7fa754662e669e5cdda7aba1e42e0f60e31b5e49867f02dda5d22d563d0d78274a6fad6440f78498bfb5e54b4f95677edfe010e66631571c1856801
@@ -1,49 +1,36 @@
1
- # The is the example file
2
- ef = File.join(Rails.root, "config/config.yml.example")
1
+ f = File.join(Rails.root, "config/config.yml")
3
2
 
4
- # Only load config data if there is an example file
5
- if File.exists?(ef)
6
-
7
- # This is the tailored file, not under source control.
8
- f = File.join(Rails.root, "config/config.yml")
9
-
10
- # If the tailored file doesn't exist, and we're running under TeamCity,
11
- # use the example file as-is.
12
- unless File.exists?(f)
13
- f = ENV['OCEAN_API_HOST'] ? ef : false
14
- end
3
+ # If the tailored file doesn't exist, and we're running under TeamCity,
4
+ # use the example file as-is.
5
+ unless File.exists?(f)
6
+ f = ENV['OCEAN_API_HOST'] ? ef : false
7
+ end
15
8
 
16
- # If there is a file to process, do so
17
- if f
18
- cfg = YAML.load(ERB.new(File.read(f)).result)
19
- cfg.merge! cfg.fetch(Rails.env, {}) if cfg.fetch(Rails.env, {})
20
- cfg.each do |k, v|
21
- next if k =~ /[a-z]/
22
- override = ENV["OVERRIDE_#{k}"]
23
- if override && override != ""
24
- master, staging = override.split(',')
25
- if staging.present? && k == "API_PASSWORD"
26
- pw = (ENV['GIT_BRANCH'] == 'staging' ? staging : master)
27
- eval "#{k} = #{pw.inspect}"
28
- else
29
- eval "#{k} = #{override.inspect}"
30
- end
9
+ # If there is a file to process, do so
10
+ if f
11
+ cfg = YAML.load(ERB.new(File.read(f)).result)
12
+ cfg.merge! cfg.fetch(Rails.env, {}) if cfg.fetch(Rails.env, {})
13
+ cfg.each do |k, v|
14
+ next if k =~ /[a-z]/
15
+ override = ENV["OVERRIDE_#{k}"]
16
+ if override && override != ""
17
+ master, staging = override.split(',')
18
+ if staging.present? && k == "API_PASSWORD"
19
+ pw = (ENV['GIT_BRANCH'] == 'staging' ? staging : master)
20
+ eval "#{k} = #{pw.inspect}"
31
21
  else
32
- eval "#{k} = #{v.inspect}"
22
+ eval "#{k} = #{override.inspect}"
33
23
  end
24
+ else
25
+ eval "#{k} = #{v.inspect}"
34
26
  end
35
- else
36
- # Otherwise print an error message and abort.
37
- puts
38
- puts "-----------------------------------------------------------------------"
39
- puts "Constant definition file missing. Please copy config/config.yml.example"
40
- puts "to config/config.yml and tailor its contents to suit your dev setup."
41
- puts
42
- puts "NB: config.yml is excluded from git version control as it will contain"
43
- puts " data private to your Ocean system."
44
- puts "-----------------------------------------------------------------------"
45
- puts
46
- abort
47
27
  end
48
-
28
+ else
29
+ # Otherwise print an error message and abort.
30
+ puts
31
+ puts "-----------------------------------------------------------------------"
32
+ puts "Constant definition file missing."
33
+ puts "-----------------------------------------------------------------------"
34
+ puts
35
+ abort
49
36
  end
@@ -1,127 +1,127 @@
1
- if false # Rails.env == 'production'
2
-
3
- def remove_existing_log_subscriptions
4
- ActiveSupport::LogSubscriber.log_subscribers.each do |subscriber|
5
- case subscriber
6
- when ActionView::LogSubscriber
7
- unsubscribe(:action_view, subscriber)
8
- when ActionController::LogSubscriber
9
- unsubscribe(:action_controller, subscriber)
10
- end
11
- end
12
- end
13
-
14
- def unsubscribe(component, subscriber)
15
- events = subscriber.public_methods(false).reject{ |method| method.to_s == 'call' }
16
- events.each do |event|
17
- ActiveSupport::Notifications.notifier.listeners_for("#{event}.#{component}").each do |listener|
18
- if listener.instance_variable_get('@delegate') == subscriber
19
- ActiveSupport::Notifications.unsubscribe listener
20
- end
21
- end
22
- end
23
- end
24
-
25
- remove_existing_log_subscriptions
26
-
27
-
28
- INTERNAL_PARAMS = %w(controller action format _method only_path)
29
-
30
- ActiveSupport::Notifications.subscribe "process_action.action_controller" do |name, started, finished, unique_id, payload|
31
- path = payload[:path]
32
- if path != '/alive'
33
-
34
- runtime = finished - started
35
- param_method = payload[:params]['_method']
36
- method = param_method ? param_method.upcase : payload[:method]
37
- status = compute_status(payload)
38
- params = payload[:params].except(*INTERNAL_PARAMS)
39
-
40
- data = {
41
- timestamp: (started.utc.to_f * 1000).to_i,
42
- method: method,
43
- status: status,
44
- runtime: (runtime * 1000).round(0),
45
- view_runtime: (payload[:view_runtime] || 0).round(0),
46
- db_runtime: (payload[:db_runtime] || 0).round(0)
47
- }
48
- data[:params] = params if params.present?
49
- data[:filter] = Thread.current[:filter] if Thread.current[:filter]
50
- data[:token] = Thread.current[:x_api_token] if Thread.current[:x_api_token].present?
51
- data[:username] = Thread.current[:username] if Thread.current[:username].present?
52
- data[:metadata] = Thread.current[:metadata] if Thread.current[:metadata].present?
53
-
54
- Thread.current[:logdata] = data
55
- Thread.current[:filter] = nil
56
- Thread.current[:x_api_token] = nil
57
- Thread.current[:username] = nil
58
- Thread.current[:cache_control] = nil
59
- Thread.current[:metadata] = nil
60
- end
61
- end
62
-
63
- def compute_status payload
64
- status = payload[:status]
65
- if status.nil? && payload[:exception].present?
66
- exception_class_name = payload[:exception].first
67
- status = ActionDispatch::ExceptionWrapper.status_code_for_exception(exception_class_name)
68
- end
69
- status
70
- end
71
-
72
-
73
- ActiveSupport::Notifications.subscribe "halted_callback.action_controller" do |*args|
74
- data = args.extract_options!
75
- Thread.current[:filter] = data[:filter]
76
- end
77
-
78
-
79
- ActiveSupport::Notifications.subscribe 'request.action_dispatch' do |*args|
80
- x = args.extract_options!
81
- request = x[:request]
82
-
83
- data = Thread.current[:logdata] || {}
84
- data[:remote_ip] = request.remote_ip
85
- data[:path] = request.filtered_path
86
-
87
- if (ac = request.env["action_controller.instance"]) &&
88
- (response = ac.response) &&
89
- (body = response.body) &&
90
- body.present? &&
91
- body =~ /\A\{"_api_error"/
92
- data[:_api_error] = JSON.parse(body)['_api_error']
93
- end
94
-
95
- if response && response.headers['Cache-Control']
96
- data[:cache_control] = response.headers['Cache-Control']
97
- end
98
-
99
- ex = request.env["action_dispatch.exception"]
100
- if ex
101
- if data[:status] == 404
102
- data[:path] = request.env["REQUEST_PATH"]
103
- else
104
- # We might want to send an email here - exceptions in production
105
- # should be taken seriously
106
- data[:exception_message] = ex.message
107
- data[:exception_backtrace] = ex.backtrace.to_json
108
- end
109
- end
110
-
111
- if (data[:status] || 0) >= 500
112
- Rails.logger.fatal data
113
- elsif (data[:status] || 0) >= 400
114
- Rails.logger.error data
115
- else
116
- Rails.logger.info data
117
- end
118
- end
119
-
120
-
121
- # Announce us
122
- Rails.logger.info "Initialising Rails process"
123
-
124
- # Make sure we log our exit
125
- at_exit { Rails.logger.info "Exiting Rails process" }
126
-
127
- end
1
+ # if false # Rails.env == 'production'
2
+ #
3
+ # def remove_existing_log_subscriptions
4
+ # ActiveSupport::LogSubscriber.log_subscribers.each do |subscriber|
5
+ # case subscriber
6
+ # when ActionView::LogSubscriber
7
+ # unsubscribe(:action_view, subscriber)
8
+ # when ActionController::LogSubscriber
9
+ # unsubscribe(:action_controller, subscriber)
10
+ # end
11
+ # end
12
+ # end
13
+ #
14
+ # def unsubscribe(component, subscriber)
15
+ # events = subscriber.public_methods(false).reject{ |method| method.to_s == 'call' }
16
+ # events.each do |event|
17
+ # ActiveSupport::Notifications.notifier.listeners_for("#{event}.#{component}").each do |listener|
18
+ # if listener.instance_variable_get('@delegate') == subscriber
19
+ # ActiveSupport::Notifications.unsubscribe listener
20
+ # end
21
+ # end
22
+ # end
23
+ # end
24
+ #
25
+ # remove_existing_log_subscriptions
26
+ #
27
+ #
28
+ # INTERNAL_PARAMS = %w(controller action format _method only_path)
29
+ #
30
+ # ActiveSupport::Notifications.subscribe "process_action.action_controller" do |name, started, finished, unique_id, payload|
31
+ # path = payload[:path]
32
+ # if path != '/alive'
33
+ #
34
+ # runtime = finished - started
35
+ # param_method = payload[:params]['_method']
36
+ # method = param_method ? param_method.upcase : payload[:method]
37
+ # status = compute_status(payload)
38
+ # params = payload[:params].except(*INTERNAL_PARAMS)
39
+ #
40
+ # data = {
41
+ # timestamp: (started.utc.to_f * 1000).to_i,
42
+ # method: method,
43
+ # status: status,
44
+ # runtime: (runtime * 1000).round(0),
45
+ # view_runtime: (payload[:view_runtime] || 0).round(0),
46
+ # db_runtime: (payload[:db_runtime] || 0).round(0)
47
+ # }
48
+ # data[:params] = params if params.present?
49
+ # data[:filter] = Thread.current[:filter] if Thread.current[:filter]
50
+ # data[:token] = Thread.current[:x_api_token] if Thread.current[:x_api_token].present?
51
+ # data[:username] = Thread.current[:username] if Thread.current[:username].present?
52
+ # data[:metadata] = Thread.current[:metadata] if Thread.current[:metadata].present?
53
+ #
54
+ # Thread.current[:logdata] = data
55
+ # Thread.current[:filter] = nil
56
+ # Thread.current[:x_api_token] = nil
57
+ # Thread.current[:username] = nil
58
+ # Thread.current[:cache_control] = nil
59
+ # Thread.current[:metadata] = nil
60
+ # end
61
+ # end
62
+ #
63
+ # def compute_status payload
64
+ # status = payload[:status]
65
+ # if status.nil? && payload[:exception].present?
66
+ # exception_class_name = payload[:exception].first
67
+ # status = ActionDispatch::ExceptionWrapper.status_code_for_exception(exception_class_name)
68
+ # end
69
+ # status
70
+ # end
71
+ #
72
+ #
73
+ # ActiveSupport::Notifications.subscribe "halted_callback.action_controller" do |*args|
74
+ # data = args.extract_options!
75
+ # Thread.current[:filter] = data[:filter]
76
+ # end
77
+ #
78
+ #
79
+ # ActiveSupport::Notifications.subscribe 'request.action_dispatch' do |*args|
80
+ # x = args.extract_options!
81
+ # request = x[:request]
82
+ #
83
+ # data = Thread.current[:logdata] || {}
84
+ # data[:remote_ip] = request.remote_ip
85
+ # data[:path] = request.filtered_path
86
+ #
87
+ # if (ac = request.env["action_controller.instance"]) &&
88
+ # (response = ac.response) &&
89
+ # (body = response.body) &&
90
+ # body.present? &&
91
+ # body =~ /\A\{"_api_error"/
92
+ # data[:_api_error] = JSON.parse(body)['_api_error']
93
+ # end
94
+ #
95
+ # if response && response.headers['Cache-Control']
96
+ # data[:cache_control] = response.headers['Cache-Control']
97
+ # end
98
+ #
99
+ # ex = request.env["action_dispatch.exception"]
100
+ # if ex
101
+ # if data[:status] == 404
102
+ # data[:path] = request.env["REQUEST_PATH"]
103
+ # else
104
+ # # We might want to send an email here - exceptions in production
105
+ # # should be taken seriously
106
+ # data[:exception_message] = ex.message
107
+ # data[:exception_backtrace] = ex.backtrace.to_json
108
+ # end
109
+ # end
110
+ #
111
+ # if (data[:status] || 0) >= 500
112
+ # Rails.logger.fatal data
113
+ # elsif (data[:status] || 0) >= 400
114
+ # Rails.logger.error data
115
+ # else
116
+ # Rails.logger.info data
117
+ # end
118
+ # end
119
+ #
120
+ #
121
+ # # Announce us
122
+ # Rails.logger.info "Initialising Rails process"
123
+ #
124
+ # # Make sure we log our exit
125
+ # at_exit { Rails.logger.info "Exiting Rails process" }
126
+ #
127
+ # end
@@ -1,114 +1,114 @@
1
+ # #
2
+ # # This class is a drop-in replacement for the standard Rails logger. It
3
+ # # implements enough of the Logger interface to allow it to override the
4
+ # # standard logger.
5
+ # #
6
+ # class OceanLogger
1
7
  #
2
- # This class is a drop-in replacement for the standard Rails logger. It
3
- # implements enough of the Logger interface to allow it to override the
4
- # standard logger.
5
- #
6
- class OceanLogger
7
-
8
- attr_accessor :level, :formatter
9
-
10
- #
11
- # Obtains the IP of the current process, initialises the @logger object
12
- # by instantiating a ZeroLog object which then is used to set up the
13
- # log data sender.
14
- #
15
- def initialize
16
- super
17
- # Get info about our environment
18
- @ip = Socket.ip_address_list.detect{|intf| intf.ipv4_private?}.getnameinfo[0]
19
- # Set up the logger
20
- @logger = ZeroLog.new "/tmp/sub_push_#{Process.pid}", @log_hosts
21
- @formatter = ::Logger::Formatter.new
22
- end
23
-
24
- #
25
- # Utility function which returns true if the current log level is +DEBUG+ or lower.
26
- #
27
- def debug?() @level <= 0; end
28
-
29
- #
30
- # Utility function which returns true if the current log level is +INFO+ or lower.
31
- #
32
- def info?() @level <= 1; end
33
-
34
- #
35
- # Utility function which returns true if the current log level is +WARN+ or lower.
36
- #
37
- def warn?() @level <= 2; end
38
-
39
- #
40
- # Utility function which returns true if the current log level is +ERROR+ or lower.
41
- #
42
- def error?() @level <= 3; end
43
-
44
- #
45
- # Utility function which returns true if the current log level is +FATAL+ or lower.
46
- #
47
- def fatal?() @level <= 4; end
48
-
49
-
50
- #
51
- # This is the core method to add new log messages to the Rails log. It does nothing
52
- # if the level of the message is lower than the current log level, or if the message
53
- # is blank. Otherwise it creates a JSON log message as a hash, with data for the
54
- # following keys:
55
- #
56
- # +timestamp+: The time in milliseconds since the start of the Unix epoch.
57
- #
58
- # +ip+: The IP of the logging entity.
59
- #
60
- # +pid+: The Process ID of the logging process.
61
- #
62
- # +service+: The name of the service.
63
- #
64
- # +level+: The log level of the message (0=debug, 1=info, 2=warn, etc).
65
- #
66
- # +msg+: The log message itself.
67
- #
68
- def add(level, msg)
69
- return true if level < @level
70
- return true if msg.blank?
71
- # Compensate for bug in Rails 4.2.x
72
- return true if msg =~ /Couldn't find template for digesting/
73
- data = { ip: @ip,
74
- pid: Process.pid,
75
- service: APP_NAME,
76
- level: level
77
- }
78
- data[:token] = Thread.current[:x_api_token] if Thread.current[:x_api_token].present?
79
- data[:username] = Thread.current[:username] if Thread.current[:username].present?
80
- data[:msg] = msg if msg.is_a?(String)
81
- data[:timestamp] = (Time.now.utc.to_f * 1000).to_i unless data[:timestamp]
82
- data[:metadata] = Thread.current[:metadata] if Thread.current[:metadata].present?
83
- data = data.merge msg if msg.is_a?(Hash)
84
- @logger.log data
85
- true
86
- end
87
-
88
-
89
- def debug(*args)
90
- return if args.blank?
91
- add 0, *args
92
- end
93
-
94
- def info(*args)
95
- return if args.blank?
96
- add 1, *args
97
- end
98
-
99
- def warn(*args)
100
- return if args.blank?
101
- add 2, *args
102
- end
103
-
104
- def error(*args)
105
- return if args.blank?
106
- add 3, *args
107
- end
108
-
109
- def fatal(*args)
110
- return if args.blank?
111
- add 4, *args
112
- end
113
-
114
- end
8
+ # attr_accessor :level, :formatter
9
+ #
10
+ # #
11
+ # # Obtains the IP of the current process, initialises the @logger object
12
+ # # by instantiating a ZeroLog object which then is used to set up the
13
+ # # log data sender.
14
+ # #
15
+ # def initialize
16
+ # super
17
+ # # Get info about our environment
18
+ # @ip = Socket.ip_address_list.detect{|intf| intf.ipv4_private?}.getnameinfo[0]
19
+ # # Set up the logger
20
+ # @logger = ZeroLog.new "/tmp/sub_push_#{Process.pid}", @log_hosts
21
+ # @formatter = ::Logger::Formatter.new
22
+ # end
23
+ #
24
+ # #
25
+ # # Utility function which returns true if the current log level is +DEBUG+ or lower.
26
+ # #
27
+ # def debug?() @level <= 0; end
28
+ #
29
+ # #
30
+ # # Utility function which returns true if the current log level is +INFO+ or lower.
31
+ # #
32
+ # def info?() @level <= 1; end
33
+ #
34
+ # #
35
+ # # Utility function which returns true if the current log level is +WARN+ or lower.
36
+ # #
37
+ # def warn?() @level <= 2; end
38
+ #
39
+ # #
40
+ # # Utility function which returns true if the current log level is +ERROR+ or lower.
41
+ # #
42
+ # def error?() @level <= 3; end
43
+ #
44
+ # #
45
+ # # Utility function which returns true if the current log level is +FATAL+ or lower.
46
+ # #
47
+ # def fatal?() @level <= 4; end
48
+ #
49
+ #
50
+ # #
51
+ # # This is the core method to add new log messages to the Rails log. It does nothing
52
+ # # if the level of the message is lower than the current log level, or if the message
53
+ # # is blank. Otherwise it creates a JSON log message as a hash, with data for the
54
+ # # following keys:
55
+ # #
56
+ # # +timestamp+: The time in milliseconds since the start of the Unix epoch.
57
+ # #
58
+ # # +ip+: The IP of the logging entity.
59
+ # #
60
+ # # +pid+: The Process ID of the logging process.
61
+ # #
62
+ # # +service+: The name of the service.
63
+ # #
64
+ # # +level+: The log level of the message (0=debug, 1=info, 2=warn, etc).
65
+ # #
66
+ # # +msg+: The log message itself.
67
+ # #
68
+ # def add(level, msg)
69
+ # return true if level < @level
70
+ # return true if msg.blank?
71
+ # # Compensate for bug in Rails 4.2.x
72
+ # return true if msg =~ /Couldn't find template for digesting/
73
+ # data = { ip: @ip,
74
+ # pid: Process.pid,
75
+ # service: APP_NAME,
76
+ # level: level
77
+ # }
78
+ # data[:token] = Thread.current[:x_api_token] if Thread.current[:x_api_token].present?
79
+ # data[:username] = Thread.current[:username] if Thread.current[:username].present?
80
+ # data[:msg] = msg if msg.is_a?(String)
81
+ # data[:timestamp] = (Time.now.utc.to_f * 1000).to_i unless data[:timestamp]
82
+ # data[:metadata] = Thread.current[:metadata] if Thread.current[:metadata].present?
83
+ # data = data.merge msg if msg.is_a?(Hash)
84
+ # @logger.log data
85
+ # true
86
+ # end
87
+ #
88
+ #
89
+ # def debug(*args)
90
+ # return if args.blank?
91
+ # add 0, *args
92
+ # end
93
+ #
94
+ # def info(*args)
95
+ # return if args.blank?
96
+ # add 1, *args
97
+ # end
98
+ #
99
+ # def warn(*args)
100
+ # return if args.blank?
101
+ # add 2, *args
102
+ # end
103
+ #
104
+ # def error(*args)
105
+ # return if args.blank?
106
+ # add 3, *args
107
+ # end
108
+ #
109
+ # def fatal(*args)
110
+ # return if args.blank?
111
+ # add 4, *args
112
+ # end
113
+ #
114
+ # end