Loading lib/labkit/user_experience_sli/experience.rb +2 −3 Original line number Diff line number Diff line Loading @@ -60,7 +60,6 @@ module Labkit # Start the User Experience. # # @yield [self] When a block is provided, the experience will be completed automatically. # @param start_time [Time] An optional Time object to set the start time. Defaults to Time.now. UTC enforced. # @param extra [Hash] Additional data to include in the log event # @return [self] # @raise [UserExperienceError] If the block raises an error. Loading @@ -76,8 +75,8 @@ module Labkit # experience.start # experience.checkpoint # experience.complete def start(start_time: Time.now.utc, **extra, &) @start_time = start_time.utc def start(**extra, &) @start_time = Time.now.utc checkpoint_counter.increment(checkpoint: "start", **base_labels) log_event("start", **extra) Loading spec/labkit/user_experience_sli/experience_spec.rb +2 −17 Original line number Diff line number Diff line Loading @@ -51,6 +51,7 @@ RSpec.describe Labkit::UserExperienceSli::Experience, :with_metrics_config do user_experience_id: 'malicious_experience', feature_category: 'malicious_category', urgency: 'malicious_urgency', start_time: 'yesterday', elapsed_time_s: '999', urgency_threshold_s: '888' } Loading @@ -61,6 +62,7 @@ RSpec.describe Labkit::UserExperienceSli::Experience, :with_metrics_config do user_experience_id: 'testing_sample', feature_category: 'source_code_management', urgency: 'sync_fast', start_time: be_a(String), elapsed_time_s: be_a(Numeric), urgency_threshold_s: 2, ) Loading Loading @@ -204,23 +206,6 @@ RSpec.describe Labkit::UserExperienceSli::Experience, :with_metrics_config do expect(Labkit::UserExperienceSli::Current.active_experiences).to have_key(experience.id) end it 'uses provided start_time converted to UTC' do non_utc_start_time = Time.new(2024, 1, 1, 10, 30, 45, '+05:30') experience.start(start_time: non_utc_start_time) expect(experience.start_time).to eq(non_utc_start_time.utc) end it 'uses current UTC time when start_time is not provided' do now_utc = Time.new(2024, 1, 1, 0, 0, 0, '+00:00') allow(Time).to receive(:now).and_return(now_utc) experience.start expect(experience.start_time).to eq(now_utc) end end end Loading Loading
lib/labkit/user_experience_sli/experience.rb +2 −3 Original line number Diff line number Diff line Loading @@ -60,7 +60,6 @@ module Labkit # Start the User Experience. # # @yield [self] When a block is provided, the experience will be completed automatically. # @param start_time [Time] An optional Time object to set the start time. Defaults to Time.now. UTC enforced. # @param extra [Hash] Additional data to include in the log event # @return [self] # @raise [UserExperienceError] If the block raises an error. Loading @@ -76,8 +75,8 @@ module Labkit # experience.start # experience.checkpoint # experience.complete def start(start_time: Time.now.utc, **extra, &) @start_time = start_time.utc def start(**extra, &) @start_time = Time.now.utc checkpoint_counter.increment(checkpoint: "start", **base_labels) log_event("start", **extra) Loading
spec/labkit/user_experience_sli/experience_spec.rb +2 −17 Original line number Diff line number Diff line Loading @@ -51,6 +51,7 @@ RSpec.describe Labkit::UserExperienceSli::Experience, :with_metrics_config do user_experience_id: 'malicious_experience', feature_category: 'malicious_category', urgency: 'malicious_urgency', start_time: 'yesterday', elapsed_time_s: '999', urgency_threshold_s: '888' } Loading @@ -61,6 +62,7 @@ RSpec.describe Labkit::UserExperienceSli::Experience, :with_metrics_config do user_experience_id: 'testing_sample', feature_category: 'source_code_management', urgency: 'sync_fast', start_time: be_a(String), elapsed_time_s: be_a(Numeric), urgency_threshold_s: 2, ) Loading Loading @@ -204,23 +206,6 @@ RSpec.describe Labkit::UserExperienceSli::Experience, :with_metrics_config do expect(Labkit::UserExperienceSli::Current.active_experiences).to have_key(experience.id) end it 'uses provided start_time converted to UTC' do non_utc_start_time = Time.new(2024, 1, 1, 10, 30, 45, '+05:30') experience.start(start_time: non_utc_start_time) expect(experience.start_time).to eq(non_utc_start_time.utc) end it 'uses current UTC time when start_time is not provided' do now_utc = Time.new(2024, 1, 1, 0, 0, 0, '+00:00') allow(Time).to receive(:now).and_return(now_utc) experience.start expect(experience.start_time).to eq(now_utc) end end end Loading