Module: Legion::API::Routes::Traces

Defined in:
lib/legion/api/traces.rb

Class Method Summary collapse

Class Method Details

.register_anomalies(app) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/legion/api/traces.rb', line 36

def self.register_anomalies(app)
  app.get '/api/traces/anomalies' do
    require_trace_search!
    threshold = (params[:threshold] || 2.0).to_f
    result = Legion::TraceSearch.detect_anomalies(threshold: threshold)
    json_response(result)
  end
end

.register_search(app) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/legion/api/traces.rb', line 14

def self.register_search(app)
  app.post '/api/traces/search' do
    require_trace_search!
    body = parse_request_body
    halt 422, json_error('missing_field', 'query is required', status_code: 422) unless body[:query]

    result = Legion::TraceSearch.search(body[:query], limit: body[:limit] || 50)
    json_response(result)
  end
end

.register_summary(app) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/legion/api/traces.rb', line 25

def self.register_summary(app)
  app.post '/api/traces/summary' do
    require_trace_search!
    body = parse_request_body
    halt 422, json_error('missing_field', 'query is required', status_code: 422) unless body[:query]

    result = Legion::TraceSearch.summarize(body[:query])
    json_response(result)
  end
end

.register_trend(app) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/legion/api/traces.rb', line 45

def self.register_trend(app)
  app.get '/api/traces/trend' do
    require_trace_search!
    hours = (params[:hours] || 24).to_i.clamp(1, 168)
    buckets = (params[:buckets] || 12).to_i.clamp(2, 48)
    result = Legion::TraceSearch.trend(hours: hours, buckets: buckets)
    json_response(result)
  end
end

.registered(app) ⇒ Object



7
8
9
10
11
12
# File 'lib/legion/api/traces.rb', line 7

def self.registered(app)
  register_search(app)
  register_summary(app)
  register_anomalies(app)
  register_trend(app)
end