stackify-api-ruby 1.0.14 → 1.0.15
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 +5 -5
- data/Gemfile.lock +1 -1
- data/lib/stackify-api-ruby.rb +19 -17
- data/lib/stackify/authorization/authorizable.rb +0 -2
- data/lib/stackify/authorization/authorization_client.rb +1 -1
- data/lib/stackify/engine.rb +0 -1
- data/lib/stackify/http_client.rb +0 -1
- data/lib/stackify/logs_sender.rb +1 -1
- data/lib/stackify/metrics/metrics_client.rb +1 -0
- data/lib/stackify/msgs_queue.rb +17 -7
- data/lib/stackify/utils/configuration.rb +2 -1
- data/lib/stackify/utils/methods.rb +17 -8
- data/lib/stackify/version.rb +1 -1
- data/lib/stackify/workers/msgs_queue_worker.rb +1 -1
- data/lib/stackify/workers/worker.rb +1 -0
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cd19881ee793a2b23b9137218fd184427d9a9502efd1b81ba2064f23626d1228
|
4
|
+
data.tar.gz: 9c3757c006c8f013afb097cf8a0cb7e016f1b1314375dfacfe3bd2d87403a9c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bee61b9d0b9b18a3ad4db32dd6b7680b3e6c7db50979cdf1a8f9f222c97465c295474f05c757c734fa26b2082a4e5cbdf541083173c295d0bb48071bc64f04db
|
7
|
+
data.tar.gz: 87ac37dd7b3ec51fc91f79eadad7316c587e25ee2e55844a974437cd4ad731c9ece070178ff51366f6132696cc93bd21c2cdb5eaa8c92df46d8b586ef265415d
|
data/Gemfile.lock
CHANGED
data/lib/stackify-api-ruby.rb
CHANGED
@@ -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
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
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
|
-
|
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
|
|
@@ -22,7 +22,7 @@ module Stackify::Authorizable
|
|
22
22
|
end
|
23
23
|
}
|
24
24
|
Stackify::ScheduleTask.new properties do
|
25
|
-
Stackify.internal_log :debug, '
|
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
|
data/lib/stackify/engine.rb
CHANGED
data/lib/stackify/http_client.rb
CHANGED
data/lib/stackify/logs_sender.rb
CHANGED
@@ -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
|
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'
|
data/lib/stackify/msgs_queue.rb
CHANGED
@@ -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
|
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.
|
18
|
-
if
|
19
|
-
|
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
|
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
|
-
|
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
|
data/lib/stackify/version.rb
CHANGED
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.
|
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-
|
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
|
-
|
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
|