Class: Stoplight::Domain::MetricsSnapshot Private

Inherits:
Data
  • Object
show all
Defined in:
lib/stoplight/domain/metrics_snapshot.rb,
lib/stoplight/domain/metrics_snapshot.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Request metrics over a given window.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#consecutive_errorsObject (readonly)

Returns the value of attribute consecutive_errors

Returns:

  • (Object)

    the current value of consecutive_errors



8
9
10
# File 'lib/stoplight/domain/metrics_snapshot.rb', line 8

def consecutive_errors
  @consecutive_errors
end

#consecutive_successesObject (readonly)

Returns the value of attribute consecutive_successes

Returns:

  • (Object)

    the current value of consecutive_successes



8
9
10
# File 'lib/stoplight/domain/metrics_snapshot.rb', line 8

def consecutive_successes
  @consecutive_successes
end

#errorsObject

A number of errors withing requested window. Zero for non-windowed metrics



8
9
10
# File 'lib/stoplight/domain/metrics_snapshot.rb', line 8

def errors
  @errors
end

#last_errorObject (readonly)

Returns the value of attribute last_error

Returns:

  • (Object)

    the current value of last_error



8
9
10
# File 'lib/stoplight/domain/metrics_snapshot.rb', line 8

def last_error
  @last_error
end

#last_success_atObject (readonly)

Returns the value of attribute last_success_at

Returns:

  • (Object)

    the current value of last_success_at



8
9
10
# File 'lib/stoplight/domain/metrics_snapshot.rb', line 8

def last_success_at
  @last_success_at
end

#successesObject

A number of successes withing requested window. Zero for non-windowed metrics



8
9
10
# File 'lib/stoplight/domain/metrics_snapshot.rb', line 8

def successes
  @successes
end

Instance Method Details

#error_rateFloat

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Calculates the error rate based on the number of successes and errors.

Returns:

  • (Float)


27
28
29
30
31
32
33
34
35
# File 'lib/stoplight/domain/metrics_snapshot.rb', line 27

def error_rate
  return unless requests # we effectively check if this is windowed metrics

  if (successes! + errors!).zero?
    0.0
  else
    errors!.fdiv(successes! + errors!)
  end
end

#errors!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



53
54
55
# File 'lib/stoplight/domain/metrics_snapshot.rb', line 53

def errors!
  errors or raise TypeError, "errors must not be nil"
end

#last_error_atTime?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Time, nil)


45
46
47
# File 'lib/stoplight/domain/metrics_snapshot.rb', line 45

def last_error_at
  last_error&.time
end

#requestsInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Integer)


38
39
40
41
42
# File 'lib/stoplight/domain/metrics_snapshot.rb', line 38

def requests
  if successes && errors # we effectively check if this is windowed metrics
    successes! + errors!
  end
end

#successes!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



49
50
51
# File 'lib/stoplight/domain/metrics_snapshot.rb', line 49

def successes!
  successes or raise TypeError, "success must not be nil"
end