Class: SolidObserver::Services::CacheStats::StabilityData::EventCounts

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEventCounts

Returns a new instance of EventCounts.



126
127
128
129
130
# File 'lib/solid_observer/services/cache_stats.rb', line 126

def initialize
  @error_count = 0
  @slow_count = 0
  @latest_recorded_at = nil
end

Instance Attribute Details

#error_countObject (readonly)

Returns the value of attribute error_count.



124
125
126
# File 'lib/solid_observer/services/cache_stats.rb', line 124

def error_count
  @error_count
end

#latest_recorded_atObject (readonly)

Returns the value of attribute latest_recorded_at.



124
125
126
# File 'lib/solid_observer/services/cache_stats.rb', line 124

def latest_recorded_at
  @latest_recorded_at
end

#slow_countObject (readonly)

Returns the value of attribute slow_count.



124
125
126
# File 'lib/solid_observer/services/cache_stats.rb', line 124

def slow_count
  @slow_count
end

Instance Method Details

#record(recorded_at:, error_class:, duration:) ⇒ Object



132
133
134
135
136
137
138
139
# File 'lib/solid_observer/services/cache_stats.rb', line 132

def record(recorded_at:, error_class:, duration:)
  kind = event_kind(error_class: error_class, duration: duration)
  return unless kind

  @latest_recorded_at = [latest_recorded_at, recorded_at].compact.max
  @error_count += 1 if kind == :error
  @slow_count += 1 if kind == :slow
end

#stateObject



141
142
143
144
145
146
# File 'lib/solid_observer/services/cache_stats.rb', line 141

def state
  return :critical if error_count.positive?
  return :degraded if slow_count.positive?

  :stable
end

#to_hObject



148
149
150
151
152
153
154
155
156
# File 'lib/solid_observer/services/cache_stats.rb', line 148

def to_h
  {
    available: true,
    state: state,
    error_count: error_count,
    slow_count: slow_count,
    latest_recorded_at: latest_recorded_at
  }
end