Module: LogStash::Api::RackApp

Defined in:
lib/logstash/api/rack_app.rb

Defined Under Namespace

Classes: ApiErrorHandler, ApiLogger

Constant Summary collapse

METADATA_FIELDS =
[:request_method, :path_info, :query_string, :http_version, :http_accept].freeze

Class Method Summary collapse

Class Method Details

.app(logger, agent, environment) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/logstash/api/rack_app.rb', line 76

def self.app(logger, agent, environment)
  namespaces = rack_namespaces(agent)

  Rack::Builder.new do
    # Custom logger object. Rack CommonLogger does not work with cabin
    use ApiLogger, logger

    # In test env we want errors to propagate up the chain
    # so we get easy to understand test failures.
    # In production / dev we don't want a bad API endpoint
    # to crash the process
    if environment != "test"
      use ApiErrorHandler, logger
    end

    run LogStash::Api::Modules::Root.new(nil, agent)
    namespaces.each_pair do |namespace, app|
      map(namespace) do
        # Pass down a reference to the current agent
        # This allow the API to have direct access to the collector
        run app.new(nil, agent)
      end
    end
  end
end

.log_metadata(status, env) ⇒ Object



15
16
17
18
19
20
# File 'lib/logstash/api/rack_app.rb', line 15

def self.(status, env)
  METADATA_FIELDS.reduce({:status => status}) do |acc, field|
    acc[field] = env[field.to_s.upcase]
    acc
  end
end

.rack_namespaces(agent) ⇒ Object



102
103
104
105
106
107
108
109
110
# File 'lib/logstash/api/rack_app.rb', line 102

def self.rack_namespaces(agent)
  {
    "/_node" => LogStash::Api::Modules::Node,
    "/_stats" => LogStash::Api::Modules::Stats,
    "/_node/stats" => LogStash::Api::Modules::NodeStats,
    "/_node/plugins" => LogStash::Api::Modules::Plugins,
    "/_node/logging" => LogStash::Api::Modules::Logging
  }
end