diff --git a/lib/stoplight/admin/views/_card.erb b/lib/stoplight/admin/views/_card.erb index e9ae5e79..8bd521aa 100644 --- a/lib/stoplight/admin/views/_card.erb +++ b/lib/stoplight/admin/views/_card.erb @@ -96,7 +96,7 @@ <% if light.latest_failure %>
- <%= Time.at(light.latest_failure.time).strftime("%T") %> + <%= light.latest_failure.time.strftime("%T") %>
<% end %> diff --git a/lib/stoplight/data_store/memory.rb b/lib/stoplight/data_store/memory.rb index 66e92b25..a9df4ea6 100644 --- a/lib/stoplight/data_store/memory.rb +++ b/lib/stoplight/data_store/memory.rb @@ -278,7 +278,7 @@ def transition_to_color(config, color) end private def current_time - Time.now + Time.now.utc end end end diff --git a/lib/stoplight/data_store/memory/sliding_window.rb b/lib/stoplight/data_store/memory/sliding_window.rb index 0c49558e..6e713286 100644 --- a/lib/stoplight/data_store/memory/sliding_window.rb +++ b/lib/stoplight/data_store/memory/sliding_window.rb @@ -65,7 +65,7 @@ def sum_in_window(window_start) end private def current_time - Time.now + Time.now.utc end def inspect diff --git a/lib/stoplight/data_store/redis.rb b/lib/stoplight/data_store/redis.rb index e972ac1c..3bbc5872 100644 --- a/lib/stoplight/data_store/redis.rb +++ b/lib/stoplight/data_store/redis.rb @@ -71,7 +71,7 @@ def bucket_key(light_name, metric:, time:) end KEY_SEPARATOR = ":" - KEY_PREFIX = %w[stoplight v5].join(KEY_SEPARATOR) + KEY_PREFIX = %w[stoplight v6].join(KEY_SEPARATOR) # @param redis [::Redis, ConnectionPool<::Redis>] # @param warn_on_clock_skew [Boolean] (true) Whether to warn about clock skew between Redis and @@ -439,7 +439,7 @@ def transition_to_color(config, color) end private def current_time - Time.now + Time.now.utc end end end diff --git a/lib/stoplight/failure.rb b/lib/stoplight/failure.rb index 113fb34d..ef616427 100644 --- a/lib/stoplight/failure.rb +++ b/lib/stoplight/failure.rb @@ -5,8 +5,6 @@ module Stoplight class Failure # rubocop:disable Style/Documentation - TIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%N%:z" - # @return [String] attr_reader :error_class # @return [String] @@ -16,7 +14,7 @@ class Failure # rubocop:disable Style/Documentation # @param error [Exception] # @return (see #initialize) - def self.from_error(error, time: Time.now) + def self.from_error(error, time: Time.now.utc) new(error.class.name, error.message, time) end @@ -30,7 +28,7 @@ def self.from_json(json) error_class = error_object["class"] error_message = error_object["message"] - time = Time.at(object["time"]) + time = Time.at(object["time"]).utc new(error_class, error_message, time) end @@ -41,7 +39,7 @@ def self.from_json(json) def initialize(error_class, error_message, time) @error_class = error_class @error_message = error_message - @time = Time.at(time.to_i) # truncate to seconds + @time = Time.at(time.to_i).utc # truncate to seconds end # @param other [Failure] diff --git a/lib/stoplight/metadata.rb b/lib/stoplight/metadata.rb index 7667c4e9..63e07921 100644 --- a/lib/stoplight/metadata.rb +++ b/lib/stoplight/metadata.rb @@ -20,7 +20,7 @@ module Stoplight :current_time ) do def initialize( - current_time: Time.now, + current_time: Time.now.utc, successes: 0, errors: 0, recovery_probe_successes: 0, @@ -41,16 +41,16 @@ def initialize( recovery_probe_errors: recovery_probe_errors.to_i, successes: successes.to_i, errors: errors.to_i, - last_error_at: (Time.at(Integer(last_error_at)) if last_error_at), - last_success_at: (Time.at(Integer(last_success_at)) if last_success_at), + last_error_at: (Time.at(Integer(last_error_at)).utc if last_error_at), + last_success_at: (Time.at(Integer(last_success_at)).utc if last_success_at), consecutive_errors: consecutive_errors.to_i, consecutive_successes: consecutive_successes.to_i, last_error:, - breached_at: (Time.at(Integer(breached_at)) if breached_at), + breached_at: (Time.at(Integer(breached_at)).utc if breached_at), locked_state: locked_state || State::UNLOCKED, - recovery_scheduled_after: (Time.at(Integer(recovery_scheduled_after)) if recovery_scheduled_after), - recovery_started_at: (Time.at(Integer(recovery_started_at)) if recovery_started_at), - recovered_at: (Time.at(Integer(recovered_at)) if recovered_at), + recovery_scheduled_after: (Time.at(Integer(recovery_scheduled_after)).utc if recovery_scheduled_after), + recovery_started_at: (Time.at(Integer(recovery_started_at)).utc if recovery_started_at), + recovered_at: (Time.at(Integer(recovered_at)).utc if recovered_at), current_time:, ) end @@ -62,7 +62,7 @@ def initialize( # @param kwargs [Hash{Symbol => Object}] # @return [Metadata] def with(**kwargs) - self.class.new(**to_h.merge(current_time: Time.now, **kwargs)) + self.class.new(**to_h.merge(current_time: Time.now.utc, **kwargs)) end # @return [String] one of +Color::GREEN+, +Color::RED+, or +Color::YELLOW+ diff --git a/spec/stoplight/data_store/redis_spec.rb b/spec/stoplight/data_store/redis_spec.rb index f6152c95..ad0dfddd 100644 --- a/spec/stoplight/data_store/redis_spec.rb +++ b/spec/stoplight/data_store/redis_spec.rb @@ -23,7 +23,7 @@ it "returns a single bucket key" do is_expected.to contain_exactly( - "stoplight:v5:metrics:test-light:failures:1696154400" + "stoplight:v6:metrics:test-light:failures:1696154400" ) end end @@ -34,10 +34,10 @@ it "returns all bucket keys within the window" do is_expected.to contain_exactly( - "stoplight:v5:metrics:test-light:failures:1696140000", - "stoplight:v5:metrics:test-light:failures:1696143600", - "stoplight:v5:metrics:test-light:failures:1696147200", - "stoplight:v5:metrics:test-light:failures:1696150800" + "stoplight:v6:metrics:test-light:failures:1696140000", + "stoplight:v6:metrics:test-light:failures:1696143600", + "stoplight:v6:metrics:test-light:failures:1696147200", + "stoplight:v6:metrics:test-light:failures:1696150800" ) end end @@ -48,7 +48,7 @@ it "returns the single bucket key" do is_expected.to contain_exactly( - "stoplight:v5:metrics:test-light:failures:1696150800" + "stoplight:v6:metrics:test-light:failures:1696150800" ) end end diff --git a/spec/stoplight/failure_spec.rb b/spec/stoplight/failure_spec.rb index 632d9285..87cc40b6 100644 --- a/spec/stoplight/failure_spec.rb +++ b/spec/stoplight/failure_spec.rb @@ -113,14 +113,4 @@ .to eql(json) end end - - describe "::TIME_FORMAT" do - it "is a string" do - expect(described_class::TIME_FORMAT).to be_a(String) - end - - it "is frozen" do - expect(described_class::TIME_FORMAT).to be_frozen - end - end end