diff options
author | syasonik <syasonik@gitlab.com> | 2019-03-15 19:20:59 +0800 |
---|---|---|
committer | syasonik <syasonik@gitlab.com> | 2019-04-03 17:21:56 +0800 |
commit | ab1e1b55a84ffc6b09233a6831be9bdc77c05115 (patch) | |
tree | dd59f2fd052b1112429580855536faa59855972a /spec/lib | |
parent | 478077747da82a3dfaafbebc1797b26b965b030f (diff) | |
download | gitlab-ce-ab1e1b55a84ffc6b09233a6831be9bdc77c05115.tar.gz |
Specify time window for additional metrics apisupport-time-windows-api
Adds support for start and end parameters in the #additional_metrics
endpoint of the EnvironmentsController. start and end are meant to be
unix timestamps, per the Prometheus API (as the consumer of this
endpoint will eventually be transitioned to a prometheus endpoint).
This functionality is behind the :metrics_time_window feature flag
for development.
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/prometheus/queries/additional_metrics_environment_query_spec.rb | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/spec/lib/gitlab/prometheus/queries/additional_metrics_environment_query_spec.rb b/spec/lib/gitlab/prometheus/queries/additional_metrics_environment_query_spec.rb index 5a88b23aa82..a6589f0c0a3 100644 --- a/spec/lib/gitlab/prometheus/queries/additional_metrics_environment_query_spec.rb +++ b/spec/lib/gitlab/prometheus/queries/additional_metrics_environment_query_spec.rb @@ -9,9 +9,35 @@ describe Gitlab::Prometheus::Queries::AdditionalMetricsEnvironmentQuery do let(:query_params) { [environment.id] } it 'queries using specific time' do - expect(client).to receive(:query_range).with(anything, start: 8.hours.ago.to_f, stop: Time.now.to_f) - + expect(client).to receive(:query_range) + .with(anything, start: 8.hours.ago.to_f, stop: Time.now.to_f) expect(query_result).not_to be_nil end + + context 'when start and end time parameters are provided' do + let(:query_params) { [environment.id, start_time, end_time] } + + context 'as unix timestamps' do + let(:start_time) { 4.hours.ago.to_f } + let(:end_time) { 2.hours.ago.to_f } + + it 'queries using the provided times' do + expect(client).to receive(:query_range) + .with(anything, start: start_time, stop: end_time) + expect(query_result).not_to be_nil + end + end + + context 'as Date/Time objects' do + let(:start_time) { 4.hours.ago } + let(:end_time) { 2.hours.ago } + + it 'queries using the provided times converted to unix' do + expect(client).to receive(:query_range) + .with(anything, start: start_time.to_f, stop: end_time.to_f) + expect(query_result).not_to be_nil + end + end + end end end |