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 protobuf message 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.4'
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

Methods included from Authorizable

included

Class Attribute Details

.config=(value) ⇒ Object (writeonly)

Sets the attribute config

Parameters:

  • value

    the value to set the attribute config to.



48
49
50
# File 'lib/stackify-api-ruby.rb', line 48

def config=(value)
  @config = value
end

Class Method Details

.add_dependant_worker(worker) ⇒ Object



108
109
110
# File 'lib/stackify-api-ruby.rb', line 108

def add_dependant_worker worker
  @workers << worker
end

.agent_clientObject



77
78
79
# File 'lib/stackify-api-ruby.rb', line 77

def agent_client
  @agent_client ||= Stackify::AgentClient.new
end

.alive_adding_msg_workersObject



100
101
102
# File 'lib/stackify-api-ruby.rb', line 100

def alive_adding_msg_workers
  @workers.select{ |w| w.alive? && w.type == :add_msg }
end

.configurationObject



50
51
52
# File 'lib/stackify-api-ruby.rb', line 50

def configuration
  @config ||= Stackify::Configuration.new
end

.delete_worker(worker) ⇒ Object



104
105
106
# File 'lib/stackify-api-ruby.rb', line 104

def delete_worker worker
  @workers.delete worker
end

.get_transportObject



81
82
83
# File 'lib/stackify-api-ruby.rb', line 81

def get_transport
  @logger_client.get_transport
end

.internal_log(level, msg) ⇒ Object



120
121
122
# File 'lib/stackify-api-ruby.rb', line 120

def internal_log level, msg
  Stackify.logger.send(level.downcase.to_sym, Stackify::INTERNAL_LOG_PREFIX){ msg }
end

.is_valid?Boolean

Returns:

  • (Boolean)


183
184
185
# File 'lib/stackify-api-ruby.rb', line 183

def is_valid?
  configuration.is_valid?
end

.log_internal_error(msg) ⇒ Object



116
117
118
# File 'lib/stackify-api-ruby.rb', line 116

def log_internal_error msg
  Stackify.logger.error (::Stackify::INTERNAL_LOG_PREFIX){ msg }
end

.loggerObject



89
90
91
# File 'lib/stackify-api-ruby.rb', line 89

def logger
  self.configuration.logger
end

.logger_clientObject



73
74
75
# File 'lib/stackify-api-ruby.rb', line 73

def logger_client
  @logger_client ||= Stackify::LoggerClient.new
end

.make_remained_jobObject



178
179
180
181
# File 'lib/stackify-api-ruby.rb', line 178

def make_remained_job
  @status = STATUSES[:terminating]
  Stackify.msgs_queue.push_remained_msgs
end

.msgs_queueObject



69
70
71
# File 'lib/stackify-api-ruby.rb', line 69

def msgs_queue
  @msgs_queue ||= Stackify::MsgsQueue.new
end

.runObject



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
164
# File 'lib/stackify-api-ruby.rb', line 124

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?
      # check transport types
      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_socketObject



85
86
87
# File 'lib/stackify-api-ruby.rb', line 85

def send_unix_socket
  @unix_socket ||= Stackify::UnixSocketSender.new
end

.setup {|configuration| ... } ⇒ Object

Yields:



54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/stackify-api-ruby.rb', line 54

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



93
94
95
96
97
98
# File 'lib/stackify-api-ruby.rb', line 93

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_loggingObject



166
167
168
# File 'lib/stackify-api-ruby.rb', line 166

def start_logging
  msgs_queue
end

.start_metricsObject



170
171
172
# File 'lib/stackify-api-ruby.rb', line 170

def start_metrics
  Thread.new { Stackify::Metrics.metrics_client.start }
end

.statusObject



112
113
114
# File 'lib/stackify-api-ruby.rb', line 112

def status
  @status
end

.status=(status) ⇒ Object



199
200
201
202
203
204
205
# File 'lib/stackify-api-ruby.rb', line 199

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

Returns:

  • (Boolean)


191
192
193
# File 'lib/stackify-api-ruby.rb', line 191

def terminated?
  @status == STATUSES[:terminated]
end

.terminating?Boolean

Returns:

  • (Boolean)


187
188
189
# File 'lib/stackify-api-ruby.rb', line 187

def terminating?
  @status == STATUSES[:terminating]
end

.workersObject



174
175
176
# File 'lib/stackify-api-ruby.rb', line 174

def workers
  @workers
end

.working?Boolean

Returns:

  • (Boolean)


195
196
197
# File 'lib/stackify-api-ruby.rb', line 195

def working?
  @status == STATUSES[:working]
end