Module: Stackify
- Includes:
- Authorizable
- Defined in:
- lib/stackify/agent_base_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/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, ScheduleDelay, ScheduleTask, Scheduler, StackifiedError, StringException, TransportSelector, UnixSocketSender, Worker
Constant Summary
collapse
- VERSION =
'1.2.7'
- 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
45
46
47
|
# File 'lib/stackify-api-ruby.rb', line 45
def config=(value)
@config = value
end
|
Class Method Details
.add_dependant_worker(worker) ⇒ Object
105
106
107
|
# File 'lib/stackify-api-ruby.rb', line 105
def add_dependant_worker worker
@workers << worker
end
|
.agent_client ⇒ Object
74
75
76
|
# File 'lib/stackify-api-ruby.rb', line 74
def agent_client
@agent_client ||= Stackify::AgentClient.new
end
|
.alive_adding_msg_workers ⇒ Object
97
98
99
|
# File 'lib/stackify-api-ruby.rb', line 97
def alive_adding_msg_workers
@workers.select{ |w| w.alive? && w.type == :add_msg }
end
|
.configuration ⇒ Object
47
48
49
|
# File 'lib/stackify-api-ruby.rb', line 47
def configuration
@config ||= Stackify::Configuration.new
end
|
.delete_worker(worker) ⇒ Object
101
102
103
|
# File 'lib/stackify-api-ruby.rb', line 101
def delete_worker worker
@workers.delete worker
end
|
.get_transport ⇒ Object
78
79
80
|
# File 'lib/stackify-api-ruby.rb', line 78
def get_transport
@logger_client.get_transport
end
|
.internal_log(level, msg) ⇒ Object
117
118
119
|
# File 'lib/stackify-api-ruby.rb', line 117
def internal_log level, msg
Stackify.logger.send(level.downcase.to_sym, Stackify::INTERNAL_LOG_PREFIX){ msg }
end
|
.is_valid? ⇒ Boolean
180
181
182
|
# File 'lib/stackify-api-ruby.rb', line 180
def is_valid?
configuration.is_valid?
end
|
.log_internal_error(msg) ⇒ Object
113
114
115
|
# File 'lib/stackify-api-ruby.rb', line 113
def log_internal_error msg
Stackify.logger.error (::Stackify::INTERNAL_LOG_PREFIX){ msg }
end
|
86
87
88
|
# File 'lib/stackify-api-ruby.rb', line 86
def logger
self.configuration.logger
end
|
.logger_client ⇒ Object
70
71
72
|
# File 'lib/stackify-api-ruby.rb', line 70
def logger_client
@logger_client ||= Stackify::LoggerClient.new
end
|
.make_remained_job ⇒ Object
175
176
177
178
|
# File 'lib/stackify-api-ruby.rb', line 175
def make_remained_job
@status = STATUSES[:terminating]
Stackify.msgs_queue.push_remained_msgs
end
|
.msgs_queue ⇒ Object
66
67
68
|
# File 'lib/stackify-api-ruby.rb', line 66
def msgs_queue
@msgs_queue ||= Stackify::MsgsQueue.new
end
|
121
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
|
# File 'lib/stackify-api-ruby.rb', line 121
def run
Stackify::Utils.is_api_enabled
Stackify.internal_log :info, "Stackify.run() transportType = #{Stackify.configuration.transport} | API version: #{Stackify::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
82
83
84
|
# File 'lib/stackify-api-ruby.rb', line 82
def send_unix_socket
@unix_socket ||= Stackify::UnixSocketSender.new
end
|
.setup {|configuration| ... } ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/stackify-api-ruby.rb', line 51
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
90
91
92
93
94
95
|
# File 'lib/stackify-api-ruby.rb', line 90
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
163
164
165
|
# File 'lib/stackify-api-ruby.rb', line 163
def start_logging
msgs_queue
end
|
.start_metrics ⇒ Object
167
168
169
|
# File 'lib/stackify-api-ruby.rb', line 167
def start_metrics
Thread.new { Stackify::Metrics.metrics_client.start }
end
|
109
110
111
|
# File 'lib/stackify-api-ruby.rb', line 109
def status
@status
end
|
.status=(status) ⇒ Object
196
197
198
199
200
201
202
|
# File 'lib/stackify-api-ruby.rb', line 196
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
188
189
190
|
# File 'lib/stackify-api-ruby.rb', line 188
def terminated?
@status == STATUSES[:terminated]
end
|
.terminating? ⇒ Boolean
184
185
186
|
# File 'lib/stackify-api-ruby.rb', line 184
def terminating?
@status == STATUSES[:terminating]
end
|
171
172
173
|
# File 'lib/stackify-api-ruby.rb', line 171
def workers
@workers
end
|
.working? ⇒ Boolean
192
193
194
|
# File 'lib/stackify-api-ruby.rb', line 192
def working?
@status == STATUSES[:working]
end
|