stackify-api-ruby 1.0.14 → 1.0.15

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
- SHA1:
3
- metadata.gz: 74e0dda02b7b3ac9e6df7975565aa43b4bab1442
4
- data.tar.gz: 39703a9d159e378cd44d404743e2fe1751686410
2
+ SHA256:
3
+ metadata.gz: cd19881ee793a2b23b9137218fd184427d9a9502efd1b81ba2064f23626d1228
4
+ data.tar.gz: 9c3757c006c8f013afb097cf8a0cb7e016f1b1314375dfacfe3bd2d87403a9c8
5
5
  SHA512:
6
- metadata.gz: 5766ba5b926b029bbf7a85124d89dd7d7e4a14bda5bdb65f063193c9a353102192824087439334ad63bd3b1ac26d569e8c264c13d6fae23793d389482075d605
7
- data.tar.gz: b65177fb1f2d277fa304a1084c3cf94b7cc5ff5577f8fdc77c1047e65ad28f21ea7e13ffb485d6e8711aa4fb410c9aa89fb4929bc4b0ed3d6c0aef442b5d8534
6
+ metadata.gz: bee61b9d0b9b18a3ad4db32dd6b7680b3e6c7db50979cdf1a8f9f222c97465c295474f05c757c734fa26b2082a4e5cbdf541083173c295d0bb48071bc64f04db
7
+ data.tar.gz: 87ac37dd7b3ec51fc91f79eadad7316c587e25ee2e55844a974437cd4ad731c9ece070178ff51366f6132696cc93bd21c2cdb5eaa8c92df46d8b586ef265415d
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stackify-api-ruby (1.0.14)
4
+ stackify-api-ruby (1.0.15)
5
5
  faraday (~> 0.8)
6
6
 
7
7
  GEM
@@ -103,25 +103,27 @@ module Stackify
103
103
  Stackify.logger.send(level.downcase.to_sym, Stackify::INTERNAL_LOG_PREFIX){ msg }
104
104
  end
105
105
 
106
- def run async = true
107
- if Stackify.is_valid?
108
- at_exit { make_remained_job }
109
- t1 = Thread.new { Stackify.authorize }
110
- case Stackify.configuration.mode
111
- when MODES[:both]
112
- t2 = start_logging
113
- t3 = start_metrics
114
- when MODES[:logging]
115
- t2 = start_logging
116
- when MODES[:metrics]
117
- t3 = start_metrics
118
- end
119
- unless async
106
+ def run
107
+ Stackify::Utils.is_api_enabled
108
+ if Stackify.configuration.api_enabled
109
+ if Stackify.is_valid?
110
+ at_exit { make_remained_job }
111
+ t1 = Thread.new { Stackify.authorize }
112
+ case Stackify.configuration.mode
113
+ when MODES[:both]
114
+ t2 = start_logging
115
+ t3 = start_metrics
116
+ when MODES[:logging]
117
+ t2 = start_logging
118
+ when MODES[:metrics]
119
+ t3 = start_metrics
120
+ end
121
+
120
122
  t1.join
121
- t2.join if t2
123
+ t3.join if t3
124
+ else
125
+ Stackify.log_internal_error "Stackify is not properly configured! Errors: #{Stackify.configuration.errors}"
122
126
  end
123
- else
124
- Stackify.log_internal_error "Stackify is not properly configured! Errors: #{Stackify.configuration.errors}"
125
127
  end
126
128
  end
127
129
 
@@ -56,7 +56,5 @@ module Stackify::Authorizable
56
56
  return '' if r.nil?
57
57
  "Status: #{r.try(:status)}, Message: '#{r.try(:body)}'"
58
58
  end
59
-
60
59
  end
61
-
62
60
  end
@@ -22,7 +22,7 @@ module Stackify::Authorizable
22
22
  end
23
23
  }
24
24
  Stackify::ScheduleTask.new properties do
25
- Stackify.internal_log :debug, 'AthorizationClient: trying to authorize...'
25
+ Stackify.internal_log :debug, '[AuthorizationClient] trying to authorize...'
26
26
  send_request BASE_URI, Stackify::EnvDetails.instance.auth_info.to_json
27
27
  end
28
28
  end
@@ -3,7 +3,6 @@ module Stackify
3
3
  class Engine < ::Rails::Engine
4
4
 
5
5
  if Rails.version > '3.1'
6
-
7
6
  initializer 'Stackify set up of logger', group: :all do
8
7
  ::Rails.logger = ::Stackify::LoggerProxy.new ::Rails.logger
9
8
  Stackify.run
@@ -31,6 +31,5 @@ module Stackify
31
31
  false
32
32
  end
33
33
  end
34
-
35
34
  end
36
35
  end
@@ -23,7 +23,7 @@ module Stackify
23
23
  Stackify::ScheduleTask.new properties do
24
24
  failure_msg = 'LogsSender: tried to send logs'
25
25
  Stackify.if_not_authorized failure_msg do
26
- Stackify.internal_log :info, 'LogsSender: trying to send logs to Stackify...'
26
+ Stackify.internal_log :info, '[LogsSender] trying to send logs to Stackify...'
27
27
  send_request LOGS_URI, gather_and_pack_data(msgs).to_json
28
28
  end
29
29
  end
@@ -13,6 +13,7 @@ module Stackify::Metrics
13
13
  end
14
14
 
15
15
  def start
16
+ Stackify.internal_log :debug, '[MetricClient]: start'
16
17
  if Stackify::Utils.is_mode_on? Stackify::MODES[:metrics]
17
18
  worker = Stackify::Worker.new 'Metrics client - processing of metrics'
18
19
  Stackify.internal_log :debug, 'Metrics client: processing of metrics is started'
@@ -2,6 +2,8 @@ module Stackify
2
2
  class MsgsQueue < SizedQueue
3
3
  include MonitorMixin
4
4
 
5
+ attr_accessor :worker
6
+
5
7
  CHUNK_MIN_WEIGHT = 50
6
8
  ERROR_SIZE = 10
7
9
  LOG_SIZE = 1
@@ -9,22 +11,27 @@ module Stackify
9
11
 
10
12
  def initialize
11
13
  super(Stackify.configuration.queue_max_size)
14
+ start_worker
15
+ end
16
+
17
+ alias :old_push :push
18
+
19
+ def start_worker
12
20
  if Stackify::Utils.is_mode_on? Stackify::MODES[:logging]
13
21
  @send_interval = ScheduleDelay.new
14
- worker = MsgsQueueWorker.new
22
+ @worker = MsgsQueueWorker.new
15
23
  task = update_send_interval_task
16
- worker.async_perform @send_interval, task
24
+ @worker.async_perform @send_interval, task
17
25
  else
18
26
  Stackify.internal_log :warn, '[MsgsQueue]: Logging is disabled at configuration!'
19
27
  end
20
28
  end
21
29
 
22
- alias :old_push :push
23
-
24
30
  def push_remained_msgs
31
+ Stackify.internal_log :debug, "[MsgsQueue] push_remained_msgs() alive? = #{@worker.alive?}"
25
32
  wait_until_all_workers_will_add_msgs
26
33
  self.synchronize do
27
- Stackify.internal_log :info, 'All remained logs are going to be sent'
34
+ Stackify.internal_log :info, '[MsgsQueue] All remained logs are going to be sent'
28
35
  Stackify.shutdown_all
29
36
  if self.length > 0
30
37
  Stackify.logs_sender.send_logs(pop_all)
@@ -34,6 +41,11 @@ module Stackify
34
41
  end
35
42
 
36
43
  def add_msg msg
44
+ Stackify.internal_log :debug, "[MsgsQueue] add_msg() Is worker <#{@worker.name}> alive? = #{@worker.alive?}"
45
+ if !@worker.alive?
46
+ start_worker
47
+ Stackify.internal_log :debug, "[MsgsQueue] add_msg() Newly created worker <#{@worker.name}>"
48
+ end
37
49
  self.synchronize do
38
50
  Stackify::Utils.do_only_if_authorized_and_mode_is_on Stackify::MODES[:logging] do
39
51
  old_push(msg)
@@ -73,7 +85,6 @@ module Stackify
73
85
  Stackify::ScheduleTask.new properties do
74
86
  processed_count = calculate_processed_msgs_count
75
87
  i = @send_interval.update_by_sent_num! processed_count
76
- Stackify.internal_log :debug, "MsgsQueue: send_interval is updated to #{i}"
77
88
  i
78
89
  end
79
90
  end
@@ -104,7 +115,6 @@ module Stackify
104
115
  break
105
116
  end
106
117
  end
107
-
108
118
  Stackify.logs_sender.send_logs(chunk) if chunk.length > 0
109
119
  chunk_weight
110
120
  end
@@ -3,7 +3,7 @@ module Stackify
3
3
  class Configuration
4
4
 
5
5
  attr_accessor :api_key, :app_name, :app_location, :env, :log_level, :logger,
6
- :proxy, :mode, :base_api_url
6
+ :proxy, :mode, :base_api_url, :api_enabled
7
7
 
8
8
  attr_reader :errors, :send_interval, :flood_limit, :queue_max_size
9
9
 
@@ -15,6 +15,7 @@ module Stackify
15
15
  @flood_limit = 100
16
16
  @queue_max_size = 10000
17
17
  @send_interval = 60
18
+ @api_enabled = true
18
19
  @log_level = :info
19
20
  @mode = MODES[:both]
20
21
  @logger = Logger.new(STDOUT)
@@ -10,18 +10,27 @@ module Stackify::Utils
10
10
  end
11
11
 
12
12
  def self.is_mode_on? mode
13
- Stackify.configuration.mode == Stackify::MODES[:both] || Stackify.configuration.mode == mode
13
+ Stackify.configuration.mode = mode || Stackify::MODES[:both]
14
14
  end
15
15
 
16
16
  def self.do_only_if_authorized_and_mode_is_on mode, &block
17
- if Stackify.authorized?
18
- if is_mode_on? mode
19
- yield
17
+ if Stackify.configuration.api_enabled
18
+ if Stackify.authorized?
19
+ if is_mode_on? mode
20
+ yield
21
+ else
22
+ Stackify.internal_log :warn, "#{caller[0]}: Skipped because mode - #{mode.to_s} is disabled at configuration"
23
+ end
20
24
  else
21
- Stackify.internal_log :warn, "#{caller[0]}: Skipped because mode - #{mode.to_s} is disabled at configuration"
25
+ Stackify.internal_log :warn, "#{caller[0]}: Skipped due to authorization failure"
22
26
  end
23
- else
24
- Stackify.internal_log :warn, "#{caller[0]}: Skipped due to authorization failure"
25
27
  end
26
28
  end
27
- end
29
+
30
+ def self.is_api_enabled
31
+ exclude = %w/rake rspec irb/
32
+ cmd = $PROGRAM_NAME.to_s.split('/').pop
33
+ found = exclude.select{|e| e =~ /#{cmd}/i}
34
+ Stackify.configuration.api_enabled = false if found.count > 0
35
+ end
36
+ end
@@ -1,3 +1,3 @@
1
1
  module Stackify
2
- VERSION = '1.0.14'
2
+ VERSION = '1.0.15'
3
3
  end
@@ -1,7 +1,7 @@
1
1
  module Stackify
2
2
  class MsgsQueueWorker < Worker
3
3
 
4
- def initialize name = 'MsgsQueue worker'
4
+ def initialize name = '[MsgsQueueWorker]'
5
5
  super
6
6
  @type = :send_msgs
7
7
  Stackify.internal_log :info, "#{@name}: started sending logs"
@@ -10,6 +10,7 @@ module Stackify
10
10
  @name = name ? name : generate_name
11
11
  @name += " ##{self.id}"
12
12
  @scheduler = Stackify::Scheduler.new
13
+ Stackify.internal_log :info, "[Worker] Created worker: #{@name}"
13
14
  Stackify.add_dependant_worker self
14
15
  end
15
16
 
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.14
4
+ version: 1.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stackify
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-19 00:00:00.000000000 Z
11
+ date: 2019-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -125,8 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  - !ruby/object:Gem::Version
126
126
  version: '0'
127
127
  requirements: []
128
- rubyforge_project:
129
- rubygems_version: 2.5.2.3
128
+ rubygems_version: 3.0.1
130
129
  signing_key:
131
130
  specification_version: 4
132
131
  summary: Stackify API for Ruby