Class: SolidObserver::Services::CacheStats

Inherits:
Object
  • Object
show all
Defined in:
lib/solid_observer/services/cache_stats.rb

Defined Under Namespace

Classes: StabilityData, TrendData

Constant Summary collapse

RANGES =
{
  "15m" => 15.minutes,
  "30m" => 30.minutes,
  "1h" => 1.hour,
  "7h" => 7.hours,
  "1d" => 1.day,
  "7d" => 7.days,
  "14d" => 14.days
}.freeze
DEFAULT_RANGE =
"15m"
ACTIVITY_TREND_EMPTY =
{
  available: false,
  hit_rate: [],
  operations: [],
  errors: []
}.freeze
STABILITY_EMPTY =
{
  available: false,
  state: :stable,
  error_count: 0,
  slow_count: 0,
  latest_recorded_at: nil
}.freeze
BUCKET_RULES =
[
  [2.hours.to_i, 1.minute.to_i],
  [1.day.to_i, 15.minutes.to_i],
  [7.days.to_i, 2.hours.to_i]
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(window:) ⇒ Object



213
214
215
# File 'lib/solid_observer/services/cache_stats.rb', line 213

def self.call(window:)
  new.call(window: window)
end

.parse_range(value, fallback: DEFAULT_RANGE) ⇒ Object



203
204
205
206
# File 'lib/solid_observer/services/cache_stats.rb', line 203

def parse_range(value, fallback: DEFAULT_RANGE)
  range_key = value.to_s
  RANGES.key?(range_key) ? range_key : fallback
end

.range_duration(value, fallback: DEFAULT_RANGE) ⇒ Object



208
209
210
# File 'lib/solid_observer/services/cache_stats.rb', line 208

def range_duration(value, fallback: DEFAULT_RANGE)
  RANGES.fetch(parse_range(value, fallback: fallback))
end

Instance Method Details

#call(window:) ⇒ Object



217
218
219
220
221
222
# File 'lib/solid_observer/services/cache_stats.rb', line 217

def call(window:)
  current_time = Time.current
  dashboard_response(window: window, current_time: current_time)
rescue => error
  error_response(error.message)
end