Class: Stoplight::Infrastructure::Redis::Storage::Metrics

Inherits:
Object
  • Object
show all
Includes:
Domain::_MetricsStore
Defined in:
lib/stoplight/infrastructure/redis/storage/metrics.rb,
sig/_private/stoplight/infrastructure/redis/storage/metrics.rbs

Direct Known Subclasses

UnboundedMetrics, WindowMetrics

Instance Method Summary collapse

Methods included from Domain::_MetricsStore

#clear, #metrics_snapshot, #record_failure, #record_success

Instance Method Details

#deserialize_failure(failure_json) ⇒ Domain::Failure?

Parameters:

  • (String, nil)

Returns:



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/stoplight/infrastructure/redis/storage/metrics.rb', line 22

def deserialize_failure(failure_json)
  return if failure_json.nil?

  object = JSON.parse(failure_json)
  error_object = object["error"]

  error_class = error_object["class"]
  error_message = error_object["message"]
  time = Time.at(object["time"])

  Domain::Failure.new(error_class, error_message, time)
end

#serialize_exception(exception, timestamp:) ⇒ String

Parameters:

  • (StandardError)
  • timestamp: (Float)

Returns:

  • (String)


10
11
12
13
14
15
16
17
18
19
20
# File 'lib/stoplight/infrastructure/redis/storage/metrics.rb', line 10

def serialize_exception(exception, timestamp:)
  JSON.generate(
    {
      error: {
        class: exception.class.name,
        message: exception.message
      },
      time: timestamp
    }
  )
end