Skip to content

Commit e2390f9

Browse files
committed
removed dependency from ActiveSupport, fixed bugs
1 parent 1922953 commit e2390f9

21 files changed

Lines changed: 91 additions & 113 deletions

Gemfile.lock

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,12 @@
11
PATH
22
remote: .
33
specs:
4-
stackify-api-ruby (1.0.0)
5-
activesupport (~> 4.1, >= 4.1.1)
4+
stackify-api-ruby (1.0.2)
65

76
GEM
87
remote: https://rubygems.org/
98
specs:
10-
activesupport (4.1.4)
11-
i18n (~> 0.6, >= 0.6.9)
12-
json (~> 1.7, >= 1.7.7)
13-
minitest (~> 5.1)
14-
thread_safe (~> 0.1)
15-
tzinfo (~> 1.1)
16-
i18n (0.6.11)
17-
json (1.8.1)
18-
minitest (5.4.0)
199
rake (0.9.6)
20-
thread_safe (0.3.4)
21-
tzinfo (1.2.1)
22-
thread_safe (~> 0.1)
2310

2411
PLATFORMS
2512
ruby

README.md

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,13 @@ After you install stackify-api-ruby you need to run the generator:
2424

2525
$ rails g stackify --api_key=your_api_key
2626

27-
The generator creates a file under config/initializers/stackify.rb configuring stackify-api-ruby with your API key. You can change default settings there.
27+
The generator creates a file 'config/initializers/stackify.rb' configuring stackify-api-ruby with your API key. You can change default settings there.
2828

2929
Usage: Logging
3030
------------------
31-
3231
### Rails Environment
3332

34-
stackify-api-ruby starts working with start of Rails. Every occured error will be cought and sent to Stackify automatically. The same situation with logs - you just use the Rails logger as usual:
33+
stackify-api-ruby starts with start of Rails. Every error, which occurs within your application, will be caught and sent to Stackify automatically. The same situation with logs - you just use the Rails logger as usual:
3534

3635
Rails.logger.info "Some log message"
3736

@@ -46,8 +45,8 @@ After that you need to make base configuration:
4645
Stackify.setup do |config|
4746
config.api_key = "your_api_key"
4847
config.env = :development
49-
config.app_name = "Your's app name"
50-
config.app_location = "/somewhere/public"
48+
config.app_name = "Your app name"
49+
config.app_location = "/somewhere/public"
5150
end
5251

5352
"api_key" - it's you key for Stackify. "app-location" - it's location of your application for Nginx/Apache(for Nginx it's value of 'root', for Apache it's value of 'DocumentRoot' at config files).
@@ -61,31 +60,19 @@ You can set minimal level of logs, which should be caught by gem:
6160

6261
config.log_level = :error
6362

64-
By default, gem sends logs to Stackify every 60 seconds, you can increase this value to higher if need:
65-
66-
config.send_interval = 60 #value in seconds, could not be less than 60 seconds
67-
68-
All logs, errors, and metrics are queued within the gem and uploaded on a background thread. By default, the maximum amount of logs is 1,000 log items, you can decrease this value:
69-
70-
config.queue_max_size = 600
71-
72-
To help prevent flooding the system there is a parameter - max amount of the same error per minute:
73-
74-
config.flood_limit = 100
75-
76-
If you want to use proxy for sendig request, you can do it in such way:
63+
If you want to use proxy for sending request, you can do it in such way:
7764

7865
config.with_proxy = true
7966
config.proxy_host = "127.0.0.1"
8067
config.proxy_port = "8118"
8168
config.proxy_user = nil
8269
config.proxy_pass = nil
8370

84-
For logging own work stackify-api-rubystackify-api-rubygem uses such logger:
71+
For internal logging stackify-api-ruby uses such logger:
8572

8673
config.logger = Logger.new(File.join(Rails.root, "log", "stackify.log"))
8774

88-
After set up of logs you should wrap up your logger:
75+
After logs configuring you should wrap up your logger:
8976

9077
logger = Logger.new('mylog.log')
9178
logger = Stackify::LoggerProxy.new(logger)
@@ -124,7 +111,7 @@ There are four different types of metrics:
124111

125112
We can configure every metric with settings:
126113

127-
settings = MetricSettings.new
114+
settings = MetricSettings.new
128115
settings.autoreport_zero_if_nothing_reported = true
129116
# or
130117
settings.autoreport_last_value_if_nothing_reported = true

lib/core_ext/core_ext.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require 'json'
2+
require 'core_ext/object'
3+
require 'core_ext/fixnum'

lib/core_ext/fixnum.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Fixnum
2+
SECONDS_IN_MINUTE = 60
3+
SECONDS_IN_HOUR = 60 * SECONDS_IN_MINUTE
4+
SECONDS_IN_DAY = 24 * SECONDS_IN_HOUR
5+
6+
def days
7+
self * SECONDS_IN_DAY
8+
end
9+
10+
def minutes
11+
self * SECONDS_IN_MINUTE
12+
end
13+
14+
def ago
15+
Time.now - self
16+
end
17+
end

lib/core_ext/object.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Object
2+
def try(*a, &b)
3+
if a.empty? && block_given?
4+
yield self
5+
else
6+
public_send(*a, &b) if respond_to?(a.first)
7+
end
8+
end
9+
end

lib/generators/stackify/templates/stackify.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
Stackify.setup do |config|
22
config.api_key = '<%= options[:api_key] %>'
33
#config.mode = :both
4-
#config.app_name = "Your's app name"
4+
#config.app_name = "Your's app name"
55
#config.env = :development
6-
#config.flood_limit = 100
7-
#config.queue_max_size = 1000
8-
#config.send_interval = 60 #sec
96
#config.log_level = :error
107
#config.logger = Logger.new(File.join(Rails.root, 'log', 'stackify.log'))
118
#config.logger.level = Logger::INFO

lib/stackify-api-ruby.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require 'stackify/version'
22
require 'stackify/utils/methods'
3-
require 'active_support/core_ext' unless defined? Rails
3+
require 'core_ext/core_ext' unless defined? Rails
44

55
module Stackify
66

@@ -39,14 +39,14 @@ def configuration
3939
end
4040

4141
def setup
42+
@workers = []
4243
yield(configuration) if block_given?
4344
if configuration.is_valid?
4445
@status = STATUSES[:working]
45-
@workers = []
4646
else
4747
msg = "Stackify's configuration is not valid!"
4848
configuration.errors.each do |error_msg|
49-
msg += "\n"+error_msg
49+
msg += "\n" + error_msg
5050
end
5151
raise msg
5252
end
@@ -70,6 +70,7 @@ def logger
7070
end
7171

7272
def shutdown_all caller_obj=nil
73+
Stackify.status = Stackify::STATUSES[:terminating]
7374
@workers.each do |worker|
7475
worker.shutdown! unless worker.equal? caller_obj
7576
end
@@ -116,6 +117,8 @@ def run async = true
116117
t1.join
117118
t2.join if t2
118119
end
120+
else
121+
Stackify.log_internal_error "Stackify is not properly configured! Errors: #{Stackify.configuration.errors}"
119122
end
120123
end
121124

lib/stackify/authorization/authorizable.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module ClassMethods
99
@@authorized = false
1010
@@auth_lock = Mutex.new
1111
@@auth_client = nil
12-
12+
1313
def authorize attempts=3, delay_time = 20
1414
@@auth_lock.synchronize do
1515
return unless @@auth_client.nil?
@@ -19,7 +19,7 @@ def authorize attempts=3, delay_time = 20
1919
end
2020

2121
def authorized?
22-
@@auth_lock.synchronize do
22+
@@auth_lock.synchronize do
2323
@@authorized
2424
end
2525
end

lib/stackify/authorization/authorization_client.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
module Stackify::Authorizable
2-
32
class AuthorizationClient < Stackify::HttpClient
43

5-
BASE_URI = URI(Stackify.configuration.api_urls[:auth])
4+
BASE_URI = URI("#{Stackify.configuration.base_api_url}/Metrics/IdentifyApp")
65

76
def initialize
87
super

lib/stackify/env_details.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ class EnvDetails
99
def initialize
1010
rails_info = defined?(Rails) ? Rails::Info.properties.to_h : nil
1111
@info = rails_info || { 'Application root' => Dir.pwd, 'Environment' => 'development'}
12-
@request_details = nil
12+
@request_details = {}
1313
@app_name = app_name
1414
app_location = Stackify.configuration.app_location || @info['Application root']
1515
@details = {
1616
'DeviceName' => Socket.gethostname,
1717
'AppLocation' => app_location,
18-
'AppName' => @app_name,
18+
'AppName' => @app_name,
1919
'ConfiguredAppName' => @app_name,
2020
'ConfiguredEnvironmentName' =>@info['Environment']
2121
}
@@ -73,7 +73,7 @@ def app_location
7373
end
7474

7575
def cookies env
76-
env['action_dispatch.cookies'].to_h
76+
env['action_dispatch.cookies'].try(:to_h)
7777
end
7878

7979
def headers env

0 commit comments

Comments
 (0)