Module: Stackify
- Includes:
- Authorizable
- Defined in:
- lib/stackify/unix_socket_sender.rb,
lib/stackify/error.rb,
lib/stackify/engine.rb,
lib/stackify/version.rb,
lib/stackify-api-ruby.rb,
lib/stackify/scheduler.rb,
lib/stackify/msgs_queue.rb,
lib/proto/stackify-agent.rb,
lib/stackify/env_details.rb,
lib/stackify/http_client.rb,
lib/stackify/logs_sender.rb,
lib/stackify/logger_proxy.rb,
lib/stackify/logger_client.rb,
lib/stackify/schedule_task.rb,
lib/stackify/schedule_delay.rb,
lib/stackify/workers/worker.rb,
lib/stackify/errors_governor.rb,
lib/stackify/metrics/metrics.rb,
lib/stackify/utils/msg_object.rb,
lib/stackify/transport_selector.rb,
lib/stackify/unix_socket_client.rb,
lib/stackify/rack/errors_catcher.rb,
lib/stackify/utils/configuration.rb,
lib/stackify/workers/auth_worker.rb,
lib/stackify/workers/add_msg_worker.rb,
lib/stackify/utils/protobuf_log_object.rb,
lib/stackify/workers/msgs_queue_worker.rb,
lib/stackify/workers/logs_sender_worker.rb
Overview
This class will handle the sending of protobuf message to unix domain socket
Defined Under Namespace
Modules: Authorizable, Backtrace, Metrics, Utils
Classes: AddMsgWorker, AuthWorker, Configuration, Engine, EnvDetails, ErrorsCatcher, ErrorsGovernor, HttpClient, LoggerClient, LoggerProxy, LogsSender, LogsSenderWorker, MsgObject, MsgsQueue, MsgsQueueWorker, ProtobufLogObject, ScheduleDelay, ScheduleTask, Scheduler, StackifiedError, StringException, TransportSelector, UnixSocketClient, UnixSocketSender, Worker
Constant Summary
collapse
- VERSION =
'1.1.0'
- INTERNAL_LOG_PREFIX =
'[Stackify]'.freeze
- STATUSES =
{ working: 'working', terminating: 'terminating', terminated: 'terminated'}
- MODES =
{ logging: :logging, metrics: :metrics, both: :both }
- TRANSPORT =
[DEFAULT = 'default', UNIX_SOCKET = 'agent_socket']
- LogGroup =
Google::Protobuf::DescriptorPool.generated_pool.lookup("stackify.LogGroup").msgclass
Class Attribute Summary collapse
Class Method Summary
collapse
included
Class Attribute Details
.config=(value) ⇒ Object
Sets the attribute config
46
47
48
|
# File 'lib/stackify-api-ruby.rb', line 46
def config=(value)
@config = value
end
|
Class Method Details
.add_dependant_worker(worker) ⇒ Object
106
107
108
|
# File 'lib/stackify-api-ruby.rb', line 106
def add_dependant_worker worker
@workers << worker
end
|
.alive_adding_msg_workers ⇒ Object
98
99
100
|
# File 'lib/stackify-api-ruby.rb', line 98
def alive_adding_msg_workers
@workers.select{ |w| w.alive? && w.type == :add_msg }
end
|
.configuration ⇒ Object
48
49
50
|
# File 'lib/stackify-api-ruby.rb', line 48
def configuration
@config ||= Stackify::Configuration.new
end
|
.delete_worker(worker) ⇒ Object
102
103
104
|
# File 'lib/stackify-api-ruby.rb', line 102
def delete_worker worker
@workers.delete worker
end
|
.get_transport ⇒ Object
79
80
81
|
# File 'lib/stackify-api-ruby.rb', line 79
def get_transport
@logger_client.get_transport
end
|
.internal_log(level, msg) ⇒ Object
118
119
120
|
# File 'lib/stackify-api-ruby.rb', line 118
def internal_log level, msg
Stackify.logger.send(level.downcase.to_sym, Stackify::INTERNAL_LOG_PREFIX){ msg }
end
|
.is_valid? ⇒ Boolean
182
183
184
|
# File 'lib/stackify-api-ruby.rb', line 182
def is_valid?
configuration.is_valid?
end
|
.log_internal_error(msg) ⇒ Object
114
115
116
|
# File 'lib/stackify-api-ruby.rb', line 114
def log_internal_error msg
Stackify.logger.error (::Stackify::INTERNAL_LOG_PREFIX){ msg }
end
|
87
88
89
|
# File 'lib/stackify-api-ruby.rb', line 87
def logger
self.configuration.logger
end
|
.logger_client ⇒ Object
71
72
73
|
# File 'lib/stackify-api-ruby.rb', line 71
def logger_client
@logger_client ||= Stackify::LoggerClient.new
end
|
.make_remained_job ⇒ Object
177
178
179
180
|
# File 'lib/stackify-api-ruby.rb', line 177
def make_remained_job
@status = STATUSES[:terminating]
Stackify.msgs_queue.push_remained_msgs
end
|
.msgs_queue ⇒ Object
67
68
69
|
# File 'lib/stackify-api-ruby.rb', line 67
def msgs_queue
@msgs_queue ||= Stackify::MsgsQueue.new
end
|
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
# File 'lib/stackify-api-ruby.rb', line 122
def run
Stackify::Utils.is_api_enabled
Stackify.internal_log :debug, "Stackify.run = #{Stackify.configuration.transport}"
if Stackify.configuration.api_enabled
if Stackify.is_valid?
case Stackify.configuration.transport
when Stackify::DEFAULT
if Stackify.is_valid?
at_exit { make_remained_job }
t1 = Thread.new { Stackify.authorize }
case Stackify.configuration.mode
when MODES[:both]
t2 = start_logging
t3 = start_metrics
when MODES[:logging]
t2 = start_logging
when MODES[:metrics]
t3 = start_metrics
end
t1.join
t3.join if t3
else
Stackify.log_internal_error "Stackify is not properly configured! Errors: #{Stackify.configuration.errors}"
end
when Stackify::UNIX_SOCKET
case Stackify.configuration.mode
when MODES[:logging]
start_logging
when MODES[:both]
start_logging
start_metrics
when MODES[:metrics]
start_metrics
end
else
Stackify.log_internal_error "Stackify is not properly configured! Errors: #{Stackify.configuration.errors}"
end
end
end
end
|
.send_unix_socket ⇒ Object
83
84
85
|
# File 'lib/stackify-api-ruby.rb', line 83
def send_unix_socket
@unix_socket ||= Stackify::UnixSocketSender.new
end
|
.setup {|configuration| ... } ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/stackify-api-ruby.rb', line 52
def setup
@workers = []
yield(configuration) if block_given?
configuration.validate_transport_type
if configuration.is_valid?
@status = STATUSES[:working]
else
msg = "Stackify's configuration is not valid!"
configuration.errors.each do |error_msg|
msg += "\n" + error_msg
end
raise msg
end
end
|
.shutdown_all(caller_obj = nil) ⇒ Object
91
92
93
94
95
96
|
# File 'lib/stackify-api-ruby.rb', line 91
def shutdown_all caller_obj=nil
Stackify.status = Stackify::STATUSES[:terminating]
@workers.each do |worker|
worker.shutdown! unless worker.equal? caller_obj
end
end
|
.start_logging ⇒ Object
165
166
167
|
# File 'lib/stackify-api-ruby.rb', line 165
def start_logging
msgs_queue
end
|
.start_metrics ⇒ Object
169
170
171
|
# File 'lib/stackify-api-ruby.rb', line 169
def start_metrics
Thread.new { Stackify::Metrics.metrics_client.start }
end
|
110
111
112
|
# File 'lib/stackify-api-ruby.rb', line 110
def status
@status
end
|
.status=(status) ⇒ Object
198
199
200
201
202
203
204
|
# File 'lib/stackify-api-ruby.rb', line 198
def status= status
if STATUSES.has_value? status
@status = status
else
raise "method 'status=' should get one of arguments #{STATUSES.values}, not a #{status}"
end
end
|
.terminated? ⇒ Boolean
190
191
192
|
# File 'lib/stackify-api-ruby.rb', line 190
def terminated?
@status == STATUSES[:terminated]
end
|
.terminating? ⇒ Boolean
186
187
188
|
# File 'lib/stackify-api-ruby.rb', line 186
def terminating?
@status == STATUSES[:terminating]
end
|
.unix_socket_client ⇒ Object
75
76
77
|
# File 'lib/stackify-api-ruby.rb', line 75
def unix_socket_client
@unix_socket_client ||= Stackify::UnixSocketClient.new
end
|
173
174
175
|
# File 'lib/stackify-api-ruby.rb', line 173
def workers
@workers
end
|
.working? ⇒ Boolean
194
195
196
|
# File 'lib/stackify-api-ruby.rb', line 194
def working?
@status == STATUSES[:working]
end
|