stackify-api-ruby 1.0.0 → 1.0.1

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: 3058e14cea1be8ce39a5f5d8d76c6dd914421dba
4
- data.tar.gz: 95d0089689b0fc904b05ac1cc8dedd4f3be392cc
3
+ metadata.gz: efb9ae31688a8c3d49b8f246e92f060dee8d6197
4
+ data.tar.gz: 639356cd72dc686ed88d215de3c29c8de9bc8f26
5
5
  SHA512:
6
- metadata.gz: f0705aeca8ccfad2067d6ccb429a451a58f86e2d039f48d3de30fe9999f76746b8ce1f87e3ccedd85f9e1b16deaee50884ca47e124d69d96b26daec050b20854
7
- data.tar.gz: c0a6af825600cb6c52ac130bd14b9841ecea688be13c25779ccc65275329b564982ad322f014bb1db62b319402f4293b817eebcee9e94460713575a067b2797b
6
+ metadata.gz: 7e9358be11527f83d43d7d63c310b71f954c4aed97c6a83cdeccd8dc040e501c394e028eb662e08bc876a6710f395b185b9eecf96e8e92d06e97376f532674d5
7
+ data.tar.gz: 5287da9dc805e5bf78fddb3bb1c0d47b46cf4702b1be881fea00c8d319bde17b59c140d2544fc01d737e611849334acf56a542fe30d8ba50525410549d59c9b0
data/Gemfile.lock CHANGED
@@ -1,25 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stackify-api-ruby (1.0.0)
5
- activesupport (~> 4.1, >= 4.1.1)
4
+ stackify-api-ruby (1.0.1)
6
5
 
7
6
  GEM
8
7
  remote: https://rubygems.org/
9
8
  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)
19
9
  rake (0.9.6)
20
- thread_safe (0.3.4)
21
- tzinfo (1.2.1)
22
- thread_safe (~> 0.1)
23
10
 
24
11
  PLATFORMS
25
12
  ruby
data/README.md CHANGED
@@ -24,14 +24,13 @@ After you install stackify-api-ruby you need to run the generator:
24
24
 
25
25
  $ rails g stackify --api_key=your_api_key
26
26
 
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.
28
28
 
29
29
  Usage: Logging
30
30
  ------------------
31
-
32
31
  ### Rails Environment
33
32
 
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 cought and sent to Stackify automatically. The same situation with logs - you just use the Rails logger as usual:
35
34
 
36
35
  Rails.logger.info "Some log message"
37
36
 
@@ -46,8 +45,8 @@ After that you need to make base configuration:
46
45
  Stackify.setup do |config|
47
46
  config.api_key = "your_api_key"
48
47
  config.env = :development
49
- config.app_name = "Your's app name"
50
- config.app_location = "/somewhere/public"
48
+ config.app_name = "Your's app name"
49
+ config.app_location = "/somewhere/public"
51
50
  end
52
51
 
53
52
  "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,18 +60,6 @@ You can set minimal level of logs, which should be caught by gem:
61
60
 
62
61
  config.log_level = :error
63
62
 
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
63
  If you want to use proxy for sendig request, you can do it in such way:
77
64
 
78
65
  config.with_proxy = true
@@ -81,7 +68,7 @@ If you want to use proxy for sendig request, you can do it in such way:
81
68
  config.proxy_user = nil
82
69
  config.proxy_pass = nil
83
70
 
84
- For logging own work stackify-api-rubystackify-api-rubygem uses such logger:
71
+ For logging own work stackify-api-ruby uses such logger:
85
72
 
86
73
  config.logger = Logger.new(File.join(Rails.root, "log", "stackify.log"))
87
74
 
@@ -124,7 +111,7 @@ There are four different types of metrics:
124
111
 
125
112
  We can configure every metric with settings:
126
113
 
127
- settings = MetricSettings.new
114
+ settings = MetricSettings.new
128
115
  settings.autoreport_zero_if_nothing_reported = true
129
116
  # or
130
117
  settings.autoreport_last_value_if_nothing_reported = true
@@ -0,0 +1,3 @@
1
+ require 'json'
2
+ require 'core_ext/object'
3
+ require 'core_ext/fixnum'
@@ -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
@@ -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
@@ -1,11 +1,8 @@
1
1
  Stackify.setup do |config|
2
2
  config.api_key = '<%= options[:api_key] %>'
3
3
  #config.mode = :both
4
- #config.app_name = "Your's app name"
4
+ #config.app_name = "Your's app name"
5
5
  #config.env = :development
6
- #config.flood_limit = 100
7
- #config.queue_max_size = 1000
8
- #config.send_interval = 60 #sec
9
6
  #config.log_level = :error
10
7
  #config.logger = Logger.new(File.join(Rails.root, 'log', 'stackify.log'))
11
8
  #config.logger.level = Logger::INFO
@@ -1,6 +1,6 @@
1
1
  require 'stackify/version'
2
2
  require 'stackify/utils/methods'
3
- require 'active_support/core_ext' unless defined? Rails
3
+ require 'core_ext/core_ext' unless defined? Rails
4
4
 
5
5
  module Stackify
6
6
 
@@ -39,14 +39,14 @@ module Stackify
39
39
  end
40
40
 
41
41
  def setup
42
+ @workers = []
42
43
  yield(configuration) if block_given?
43
44
  if configuration.is_valid?
44
45
  @status = STATUSES[:working]
45
- @workers = []
46
46
  else
47
47
  msg = "Stackify's configuration is not valid!"
48
48
  configuration.errors.each do |error_msg|
49
- msg += "\n"+error_msg
49
+ msg += "\n" + error_msg
50
50
  end
51
51
  raise msg
52
52
  end
@@ -70,6 +70,7 @@ module Stackify
70
70
  end
71
71
 
72
72
  def shutdown_all caller_obj=nil
73
+ Stackify.status = Stackify::STATUSES[:terminating]
73
74
  @workers.each do |worker|
74
75
  worker.shutdown! unless worker.equal? caller_obj
75
76
  end
@@ -116,6 +117,8 @@ module Stackify
116
117
  t1.join
117
118
  t2.join if t2
118
119
  end
120
+ else
121
+ Stackify.log_internal_error "Stackify is not properly configured! Errors: #{Stackify.configuration.errors}"
119
122
  end
120
123
  end
121
124
 
@@ -9,7 +9,7 @@ module Stackify::Authorizable
9
9
  @@authorized = false
10
10
  @@auth_lock = Mutex.new
11
11
  @@auth_client = nil
12
-
12
+
13
13
  def authorize attempts=3, delay_time = 20
14
14
  @@auth_lock.synchronize do
15
15
  return unless @@auth_client.nil?
@@ -19,7 +19,7 @@ module Stackify::Authorizable
19
19
  end
20
20
 
21
21
  def authorized?
22
- @@auth_lock.synchronize do
22
+ @@auth_lock.synchronize do
23
23
  @@authorized
24
24
  end
25
25
  end
@@ -1,8 +1,7 @@
1
1
  module Stackify::Authorizable
2
-
3
2
  class AuthorizationClient < Stackify::HttpClient
4
3
 
5
- BASE_URI = URI('https://dev.stackify.com/api/Metrics/IdentifyApp')
4
+ BASE_URI = URI("#{Stackify.configuration.base_api_url}/Metrics/IdentifyApp")
6
5
 
7
6
  def initialize
8
7
  super
@@ -9,13 +9,13 @@ module Stackify
9
9
  def initialize
10
10
  rails_info = defined?(Rails) ? Rails::Info.properties.to_h : nil
11
11
  @info = rails_info || { 'Application root' => Dir.pwd, 'Environment' => 'development'}
12
- @request_details = nil
12
+ @request_details = {}
13
13
  @app_name = app_name
14
14
  app_location = Stackify.configuration.app_location || @info['Application root']
15
15
  @details = {
16
16
  'DeviceName' => Socket.gethostname,
17
17
  'AppLocation' => app_location,
18
- 'AppName' => @app_name,
18
+ 'AppName' => @app_name,
19
19
  'ConfiguredAppName' => @app_name,
20
20
  'ConfiguredEnvironmentName' =>@info['Environment']
21
21
  }
@@ -73,7 +73,7 @@ module Stackify
73
73
  end
74
74
 
75
75
  def cookies env
76
- env['action_dispatch.cookies'].to_h
76
+ env['action_dispatch.cookies'].try(:to_h)
77
77
  end
78
78
 
79
79
  def headers env
@@ -40,14 +40,14 @@ module Stackify
40
40
  'Message' => message,
41
41
  'ErrorType' => error_type.to_s,
42
42
  'ErrorTypeCode' => nil,
43
- 'Data' => { user_id: '1'},
43
+ 'Data' => {},
44
44
  'SourceMethod' => source_method,
45
45
  },
46
46
  'EnvironmentDetail' => env.auth_info,
47
- 'WebRequestDetail' => env.request_details.try{ |d| d['webrequest_details'] },
48
- 'ServerVariables' => env.request_details.try{ |d| d['server_variables'] },
47
+ 'WebRequestDetail' => env.request_details.try{ |d| d.fetch('webrequest_details', '') },
48
+ 'ServerVariables' => env.request_details.try{ |d| d.fetch('server_variables', '') },
49
49
  'CustomerName' => 'Customer',
50
- 'UserName' => @context['user']
50
+ 'UserName' => @context.fetch('user', '')
51
51
  }
52
52
  end
53
53
 
@@ -11,9 +11,6 @@ module Stackify
11
11
  }
12
12
  attr_reader :response, :errors
13
13
 
14
- def initialize
15
- end
16
-
17
14
  private
18
15
 
19
16
  def send_request uri, body, headers = HEADERS
@@ -7,23 +7,27 @@ module Stackify
7
7
  end
8
8
 
9
9
  def log level, msg
10
- if acceptable? level, msg && Stackify.working?
11
- worker = Stackify::AddMsgWorker.new
12
- task = log_message_task level, msg
13
- worker.async_perform PERIOD, task
10
+ Stackify::Utils.do_only_if_authorized_and_mode_is_on Stackify::MODES[:logging] do
11
+ if acceptable? level, msg && Stackify.working?
12
+ worker = Stackify::AddMsgWorker.new
13
+ task = log_message_task level, msg
14
+ worker.async_perform PERIOD, task
15
+ end
14
16
  end
15
17
  end
16
18
 
17
19
  def log_exception level= :error, ex
18
20
  if ex.is_a?(Stackify::StackifiedError)
19
- if acceptable? level, ex.message && Stackify.working?
20
- if @@errors_governor.can_send? ex
21
- worker = Stackify::AddMsgWorker.new
22
- task = log_exception_task level, ex
23
- worker.async_perform PERIOD, task
24
- else
25
- Stackify.internal_log :warn,
26
- "LoggerClient: logging of exception with message \"#{ex.message}\" is skipped - flood_limit is exceeded"
21
+ Stackify::Utils.do_only_if_authorized_and_mode_is_on Stackify::MODES[:logging] do
22
+ if acceptable? level, ex.message && Stackify.working?
23
+ if @@errors_governor.can_send? ex
24
+ worker = Stackify::AddMsgWorker.new
25
+ task = log_exception_task level, ex
26
+ worker.async_perform PERIOD, task
27
+ else
28
+ Stackify.internal_log :warn,
29
+ "LoggerClient: logging of exception with message \"#{ex.message}\" is skipped - flood_limit is exceeded"
30
+ end
27
31
  end
28
32
  end
29
33
  else
@@ -34,7 +38,9 @@ module Stackify
34
38
  private
35
39
 
36
40
  def acceptable? level, msg
37
- Stackify.is_valid? && is_correct_log_level?(level) && is_not_internal_log_message?(msg) && is_appropriate_env?
41
+ Stackify.is_valid? && is_correct_log_level?(level) &&
42
+ is_not_internal_log_message?(msg) &&
43
+ is_appropriate_env?
38
44
  end
39
45
 
40
46
  def is_not_internal_log_message? msg
@@ -27,7 +27,7 @@ module Stackify
27
27
  if block
28
28
  block.call
29
29
  else
30
- args[0]
30
+ args.flatten[0]
31
31
  end
32
32
  end
33
33
 
@@ -1,7 +1,7 @@
1
1
  module Stackify
2
2
  class LogsSender < HttpClient
3
3
 
4
- LOGS_URI = URI('https://dev.stackify.com/api/Log/Save')
4
+ LOGS_URI = URI("#{Stackify.configuration.base_api_url}/Log/Save")
5
5
 
6
6
  def start
7
7
  worker = Stackify::Worker.new 'Main sending thread'
@@ -67,7 +67,9 @@ module Stackify
67
67
  'Logger' => 'Rails logger',
68
68
  'AppName' => details['AppName'],
69
69
  'AppNameID' => details['AppNameID'],
70
+ 'Env' => details['Env'],
70
71
  'EnvID' => details['EnvID'],
72
+ 'AppEnvID' => details['AppEnvID'],
71
73
  'ServerName' => details['DeviceName'],
72
74
  'Msgs' => msgs,
73
75
  'AppLoc' => details['AppLocation'],
@@ -1,10 +1,7 @@
1
1
  module Stackify::Metrics
2
2
  class MetricsSender < Stackify::HttpClient
3
- SUBMIT_METRIS_URI = URI('https://dev.stackify.com/api/Metrics/SubmitMetricsByID')
4
- GET_METRIC_INFO_URI = URI('https://dev.stackify.com/api/Metrics/GetMetricInfo')
5
-
6
- def initialize
7
- end
3
+ SUBMIT_METRIS_URI = URI("#{Stackify.configuration.base_api_url}/Metrics/SubmitMetricsByID")
4
+ GET_METRIC_INFO_URI = URI("#{Stackify.configuration.base_api_url}/Metrics/GetMetricInfo")
8
5
 
9
6
  def monitor_info aggr_metric
10
7
  if Stackify.authorized?
@@ -26,8 +26,6 @@ module Stackify::Metrics
26
26
 
27
27
  class GetMetricResponse
28
28
  attr_accessor :monitor_id
29
- def initialize
30
- end
31
29
  end
32
30
 
33
31
 
@@ -33,8 +33,7 @@ module Stackify
33
33
  @current_chunk_weight += msg['Ex'].nil? ? LOG_SIZE : ERROR_SIZE
34
34
  @current_chunk << msg
35
35
  if @current_chunk_weight >= CHUNK_MIN_WEIGHT
36
- self.old_push(@current_chunk)
37
- reset_current_chunk
36
+ push_current_chunk
38
37
  end
39
38
  else
40
39
  Stackify.log_internal_error "MsgsQueue: add_msg should get hash, but not a #{msg.class}"
@@ -2,13 +2,13 @@ module Stackify
2
2
 
3
3
  class Configuration
4
4
 
5
- attr_accessor :api_key, :app_name, :app_location, :env, :log_level, :flood_limit,
6
- :queue_max_size, :logger, :send_interval, :with_proxy,
7
- :proxy_host, :proxy_port, :proxy_user, :proxy_pass, :mode
5
+ attr_accessor :api_key, :app_name, :app_location, :env, :log_level, :logger, :with_proxy,
6
+ :proxy_host, :proxy_port, :proxy_user, :proxy_pass, :mode, :base_api_url
8
7
 
9
- attr_reader :errors
8
+ attr_reader :errors, :send_interval, :flood_limit, :queue_max_size
10
9
 
11
10
  def initialize
11
+ @base_api_url = 'https://api.stackify.com'
12
12
  @errors = []
13
13
  @api_key = ''
14
14
  @env = :production
@@ -27,19 +27,14 @@ module Stackify
27
27
 
28
28
  def is_valid?
29
29
  @errors = []
30
- validate_send_interval && validate_mode if validate_config_types
30
+ validate_mode if validate_config_types
31
31
  @errors.empty?
32
32
  end
33
33
 
34
34
  private
35
- def validate_send_interval
36
- return true if 60 <= @send_interval && @send_interval <= 60000
37
- @errors << 'Send interval is not correct!'
38
- end
39
35
 
40
36
  def validate_config_types
41
37
  validate_api_key &&
42
- validate_flood_limit_queue_max_size_and_send_interval &&
43
38
  validate_log_level &&
44
39
  validate_mode_type
45
40
  end
@@ -50,19 +45,8 @@ module Stackify
50
45
  end
51
46
 
52
47
  def validate_api_key
53
- return true if @api_key.is_a? String
54
- @errors << 'API_KEY should be a String'
55
- end
56
-
57
- def validate_flood_limit_queue_max_size_and_send_interval
58
- answer = true
59
- { 'Flood limit' => @flood_limit, "Queue's max size" => @queue_max_size, 'Send interval' => @send_interval }.each_pair do |k, v|
60
- unless v.is_a? Integer
61
- answer = false
62
- @errors << "#{k} should be an Integer"
63
- end
64
- end
65
- answer
48
+ return true if @api_key.is_a?(String) && !@api_key.empty?
49
+ @errors << 'API_KEY should be a String and not empty'
66
50
  end
67
51
 
68
52
  def validate_log_level
@@ -1,3 +1,3 @@
1
1
  module Stackify
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
3
  end
@@ -5,7 +5,7 @@ require 'stackify/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'stackify-api-ruby'
8
- spec.version = '1.0.0'
8
+ spec.version = '1.0.1'
9
9
  spec.authors = ['Stackify']
10
10
  spec.email = ['support@stackify.com']
11
11
  spec.summary = 'Stackify API for Ruby'
@@ -18,8 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
- spec.add_development_dependency 'bundler', '~> 1.6'
21
+ spec.add_development_dependency 'bundler', '~> 1.6'
22
22
  spec.add_development_dependency 'rake', '~> 0'
23
- spec.add_runtime_dependency 'activesupport', '~> 4.1', '>= 4.1.1'
24
23
 
25
24
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stackify-api-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stackify
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-05 00:00:00.000000000 Z
11
+ date: 2014-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,26 +38,6 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: activesupport
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '4.1'
48
- - - ">="
49
- - !ruby/object:Gem::Version
50
- version: 4.1.1
51
- type: :runtime
52
- prerelease: false
53
- version_requirements: !ruby/object:Gem::Requirement
54
- requirements:
55
- - - "~>"
56
- - !ruby/object:Gem::Version
57
- version: '4.1'
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- version: 4.1.1
61
41
  description: Stackify Logs and Metrics API for Ruby
62
42
  email:
63
43
  - support@stackify.com
@@ -65,15 +45,13 @@ executables: []
65
45
  extensions: []
66
46
  extra_rdoc_files: []
67
47
  files:
68
- - ".gitignore"
69
- - ".rspec"
70
- - ".ruby-gemset"
71
- - ".ruby-version"
72
48
  - Gemfile
73
49
  - Gemfile.lock
74
- - LICENSE.txt
75
50
  - README.md
76
51
  - Rakefile
52
+ - lib/core_ext/core_ext.rb
53
+ - lib/core_ext/fixnum.rb
54
+ - lib/core_ext/object.rb
77
55
  - lib/generators/stackify/stackify_generator.rb
78
56
  - lib/generators/stackify/templates/stackify.rb
79
57
  - lib/stackify-api-ruby.rb
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --format documentation
data/LICENSE.txt DELETED
@@ -1,22 +0,0 @@
1
- Copyright (c) 2014 Dolgishev Victor
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.