Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/stoplight/admin/views/_card.erb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
</div>
<% if light.latest_failure %>
<div class="whitespace-nowrap">
<%= Time.at(light.latest_failure.time).strftime("%T") %>
<%= light.latest_failure.time.strftime("%T") %>
</div>
<% end %>
</div>
Expand Down
2 changes: 1 addition & 1 deletion lib/stoplight/data_store/memory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def transition_to_color(config, color)
end

private def current_time
Time.now
Time.now.utc
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/stoplight/data_store/memory/sliding_window.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def sum_in_window(window_start)
end

private def current_time
Time.now
Time.now.utc
end

def inspect
Expand Down
4 changes: 2 additions & 2 deletions lib/stoplight/data_store/redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -439,7 +439,7 @@ def transition_to_color(config, color)
end

private def current_time
Time.now
Time.now.utc
end
end
end
Expand Down
8 changes: 3 additions & 5 deletions lib/stoplight/failure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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]
Expand Down
16 changes: 8 additions & 8 deletions lib/stoplight/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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+
Expand Down
12 changes: 6 additions & 6 deletions spec/stoplight/data_store/redis_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
10 changes: 0 additions & 10 deletions spec/stoplight/failure_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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