Module: Stackify
- Includes:
- Authorizable
- Defined in:
- lib/stackify/agent_base_sender.rb,
lib/stackify/rum.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/agent_client.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/agent_http_sender.rb,
lib/stackify/transport_selector.rb,
lib/stackify/unix_socket_sender.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 log messages to unix domain socket
Defined Under Namespace
Modules: Authorizable, Backtrace, Metrics, Utils
Classes: AddMsgWorker, AgentBaseSender, AgentClient, AgentHTTPSender, AuthWorker, Configuration, Engine, EnvDetails, ErrorsCatcher, ErrorsGovernor, HttpClient, LoggerClient, LoggerProxy, LogsSender, LogsSenderWorker, MsgObject, MsgsQueue, MsgsQueueWorker, ProtobufLogObject, Rum, ScheduleDelay, ScheduleTask, Scheduler, StackifiedError, StringException, TransportSelector, UnixSocketSender, Worker
Constant Summary
collapse
- VERSION =
'2.0.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', AGENT_HTTP = 'agent_http']
- 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
110
111
112
|
# File 'lib/stackify-api-ruby.rb', line 110
def add_dependant_worker worker
@workers << worker
end
|
.agent_client ⇒ Object
79
80
81
|
# File 'lib/stackify-api-ruby.rb', line 79
def agent_client
@agent_client ||= Stackify::AgentClient.new
end
|
.alive_adding_msg_workers ⇒ Object
102
103
104
|
# File 'lib/stackify-api-ruby.rb', line 102
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
106
107
108
|
# File 'lib/stackify-api-ruby.rb', line 106
def delete_worker worker
@workers.delete worker
end
|
.get_transport ⇒ Object
83
84
85
|
# File 'lib/stackify-api-ruby.rb', line 83
def get_transport
@logger_client.get_transport
end
|
.internal_log(level, msg) ⇒ Object
122
123
124
|
# File 'lib/stackify-api-ruby.rb', line 122
def internal_log level, msg
Stackify.logger.send(level.downcase.to_sym, Stackify::INTERNAL_LOG_PREFIX){ msg }
end
|
.is_valid? ⇒ Boolean
185
186
187
|
# File 'lib/stackify-api-ruby.rb', line 185
def is_valid?
configuration.is_valid?
end
|
.log_internal_error(msg) ⇒ Object
118
119
120
|
# File 'lib/stackify-api-ruby.rb', line 118
def log_internal_error msg
Stackify.logger.error (::Stackify::INTERNAL_LOG_PREFIX){ msg }
end
|
91
92
93
|
# File 'lib/stackify-api-ruby.rb', line 91
def logger
self.configuration.logger
end
|
.logger_client ⇒ Object
75
76
77
|
# File 'lib/stackify-api-ruby.rb', line 75
def logger_client
@logger_client ||= Stackify::LoggerClient.new
end
|
.make_remained_job ⇒ Object
180
181
182
183
|
# File 'lib/stackify-api-ruby.rb', line 180
def make_remained_job
@status = STATUSES[:terminating]
Stackify.msgs_queue.push_remained_msgs
end
|
.msgs_queue ⇒ Object
71
72
73
|
# File 'lib/stackify-api-ruby.rb', line 71
def msgs_queue
@msgs_queue ||= Stackify::MsgsQueue.new
end
|
52
53
54
|
# File 'lib/stackify-api-ruby.rb', line 52
def rum
@rum ||= Stackify::Rum.new(configuration)
end
|
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
164
165
166
|
# File 'lib/stackify-api-ruby.rb', line 126
def run
Stackify::Utils.is_api_enabled
Stackify.internal_log :info, "Stackify.run() transportType: #{Stackify.configuration.transport} | API version: #{Stackify::VERSION} | Ruby version: #{RUBY_VERSION}"
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, Stackify::AGENT_HTTP
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
87
88
89
|
# File 'lib/stackify-api-ruby.rb', line 87
def send_unix_socket
@unix_socket ||= Stackify::UnixSocketSender.new
end
|
.setup {|configuration| ... } ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/stackify-api-ruby.rb', line 56
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
95
96
97
98
99
100
|
# File 'lib/stackify-api-ruby.rb', line 95
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
168
169
170
|
# File 'lib/stackify-api-ruby.rb', line 168
def start_logging
msgs_queue
end
|
.start_metrics ⇒ Object
172
173
174
|
# File 'lib/stackify-api-ruby.rb', line 172
def start_metrics
Thread.new { Stackify::Metrics.metrics_client.start }
end
|
114
115
116
|
# File 'lib/stackify-api-ruby.rb', line 114
def status
@status
end
|
.status=(status) ⇒ Object
201
202
203
204
205
206
207
|
# File 'lib/stackify-api-ruby.rb', line 201
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
193
194
195
|
# File 'lib/stackify-api-ruby.rb', line 193
def terminated?
@status == STATUSES[:terminated]
end
|
.terminating? ⇒ Boolean
189
190
191
|
# File 'lib/stackify-api-ruby.rb', line 189
def terminating?
@status == STATUSES[:terminating]
end
|
176
177
178
|
# File 'lib/stackify-api-ruby.rb', line 176
def workers
@workers
end
|
.working? ⇒ Boolean
197
198
199
|
# File 'lib/stackify-api-ruby.rb', line 197
def working?
@status == STATUSES[:working]
end
|