diff options
author | James Lopez <james@gitlab.com> | 2019-04-04 15:38:37 +0000 |
---|---|---|
committer | James Lopez <james@gitlab.com> | 2019-04-04 15:38:37 +0000 |
commit | 94e6cc52bee1a67e830bc3f18aeb57930d0815a7 (patch) | |
tree | 4983f872121384e08f5d899367b1d32e84cbcec1 /spec | |
parent | c7f918aa691b1b9c6ee6a489ae28a094eacff72c (diff) | |
parent | 552d38861ad77bf6a64b1e61a91e36fcd26d057c (diff) | |
download | gitlab-ce-94e6cc52bee1a67e830bc3f18aeb57930d0815a7.tar.gz |
Merge branch '58839-automatically-set-prometheus-step-interval' into 'master'
Resolve "Automatically set Prometheus step interval"
Closes #58839
See merge request gitlab-org/gitlab-ce!26441
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/gitlab/prometheus_client_spec.rb | 28 | ||||
-rw-r--r-- | spec/support/helpers/prometheus_helpers.rb | 10 |
2 files changed, 35 insertions, 3 deletions
diff --git a/spec/lib/gitlab/prometheus_client_spec.rb b/spec/lib/gitlab/prometheus_client_spec.rb index 4c3b8deefb9..2517ee71f24 100644 --- a/spec/lib/gitlab/prometheus_client_spec.rb +++ b/spec/lib/gitlab/prometheus_client_spec.rb @@ -230,4 +230,32 @@ describe Gitlab::PrometheusClient do let(:execute_query) { subject.query_range(prometheus_query) } end end + + describe '.compute_step' do + using RSpec::Parameterized::TableSyntax + + let(:now) { Time.now.utc } + + subject { described_class.compute_step(start, stop) } + + where(:time_interval_in_seconds, :step) do + 0 | 60 + 10.hours | 60 + 10.hours + 1 | 61 + # frontend options + 30.minutes | 60 + 3.hours | 60 + 8.hours | 60 + 1.day | 144 + 3.days | 432 + 1.week | 1008 + end + + with_them do + let(:start) { now - time_interval_in_seconds } + let(:stop) { now } + + it { is_expected.to eq(step) } + end + end end diff --git a/spec/support/helpers/prometheus_helpers.rb b/spec/support/helpers/prometheus_helpers.rb index ce1f9fce10d..08d1d7a6059 100644 --- a/spec/support/helpers/prometheus_helpers.rb +++ b/spec/support/helpers/prometheus_helpers.rb @@ -25,12 +25,16 @@ module PrometheusHelpers "https://prometheus.example.com/api/v1/query?#{query}" end - def prometheus_query_range_url(prometheus_query, start: 8.hours.ago, stop: Time.now.to_f) + def prometheus_query_range_url(prometheus_query, start: 8.hours.ago, stop: Time.now, step: nil) + start = start.to_f + stop = stop.to_f + step ||= Gitlab::PrometheusClient.compute_step(start, stop) + query = { query: prometheus_query, - start: start.to_f, + start: start, end: stop, - step: 1.minute.to_i + step: step }.to_query "https://prometheus.example.com/api/v1/query_range?#{query}" |