Class: SidekiqVigil::Check::ThroughputAnomaly

Inherits:
Base
  • Object
show all
Defined in:
lib/sidekiq_vigil/check/throughput_anomaly.rb

Constant Summary collapse

WINDOW_MINUTES =
60

Instance Attribute Summary

Attributes inherited from Base

#api, #clock, #logger, #options, #storage

Instance Method Summary collapse

Methods inherited from Base

#check_name, #execute, #initialize

Constructor Details

This class inherits a constructor from SidekiqVigil::Check::Base

Instance Method Details

#callObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/sidekiq_vigil/check/throughput_anomaly.rb', line 8

def call
  baseline = baseline_samples
  return insufficient_result(baseline.length) if baseline.length < options.fetch(:min_samples, 3)

  expected = median(baseline)
  current = window_total(clock.call)
  drop = expected.positive? ? 1 - current.fdiv(expected) : 0.0
  severity = drop >= options.fetch(:drop_pct, 0.5) ? :warn : :ok
  Result.new(
    check_name:,
    severity:,
    value: current,
    threshold: expected * (1 - options.fetch(:drop_pct, 0.5)),
    message: format(
      "%<current>d jobs vs %<expected>.1f baseline (%<drop>.1f%% drop)",
      current:,
      expected:,
      drop: drop * 100
    ),
    metadata: { baseline: expected, samples: baseline.length, drop_pct: drop }
  )
end