Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-06-18 14:18:50 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-06-18 14:18:50 +0300
commit8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch)
treea77e7fe7a93de11213032ed4ab1f33a3db51b738 /spec/services/prometheus
parent00b35af3db1abfe813a778f643dad221aad51fca (diff)
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'spec/services/prometheus')
-rw-r--r--spec/services/prometheus/create_default_alerts_service_spec.rb19
-rw-r--r--spec/services/prometheus/proxy_service_spec.rb39
-rw-r--r--spec/services/prometheus/proxy_variable_substitution_service_spec.rb14
3 files changed, 71 insertions, 1 deletions
diff --git a/spec/services/prometheus/create_default_alerts_service_spec.rb b/spec/services/prometheus/create_default_alerts_service_spec.rb
index 3382844c99a..a28c38491de 100644
--- a/spec/services/prometheus/create_default_alerts_service_spec.rb
+++ b/spec/services/prometheus/create_default_alerts_service_spec.rb
@@ -3,7 +3,7 @@
require 'spec_helper'
describe Prometheus::CreateDefaultAlertsService do
- let_it_be(:project) { create(:project) }
+ let_it_be(:project) { create(:project, :repository) }
let(:instance) { described_class.new(project: project) }
let(:expected_alerts) { described_class::DEFAULT_ALERTS }
@@ -45,6 +45,23 @@ describe Prometheus::CreateDefaultAlertsService do
.by(expected_alerts.size)
end
+ it 'does not schedule an update to prometheus' do
+ expect(::Clusters::Applications::ScheduleUpdateService).not_to receive(:new)
+ execute
+ end
+
+ context 'cluster with prometheus exists' do
+ let!(:cluster) { create(:cluster, :with_installed_prometheus, :provided_by_user, projects: [project]) }
+
+ it 'schedules an update to prometheus' do
+ expect_next_instance_of(::Clusters::Applications::ScheduleUpdateService) do |instance|
+ expect(instance).to receive(:execute)
+ end
+
+ execute
+ end
+ end
+
context 'multiple environments' do
let!(:production) { create(:environment, project: project, name: 'production') }
diff --git a/spec/services/prometheus/proxy_service_spec.rb b/spec/services/prometheus/proxy_service_spec.rb
index 656ccea10de..bd451ff00a1 100644
--- a/spec/services/prometheus/proxy_service_spec.rb
+++ b/spec/services/prometheus/proxy_service_spec.rb
@@ -41,6 +41,27 @@ describe Prometheus::ProxyService do
expect(result.params).to eq('query' => '1')
end
end
+
+ context 'with series method' do
+ let(:params) do
+ ActionController::Parameters.new(
+ match: ['1'],
+ start: "2020-06-11T10:15:51Z",
+ end: "2020-06-11T11:16:06Z",
+ unknown_param: 'val'
+ ).permit!
+ end
+
+ it 'allows match, start and end parameters' do
+ result = described_class.new(environment, 'GET', 'series', params)
+
+ expect(result.params).to eq(
+ 'match' => ['1'],
+ 'start' => "2020-06-11T10:15:51Z",
+ 'end' => "2020-06-11T11:16:06Z"
+ )
+ end
+ end
end
describe '#execute' do
@@ -182,6 +203,24 @@ describe Prometheus::ProxyService do
end
end
end
+
+ context 'with series API' do
+ let(:rest_client_response) { instance_double(RestClient::Response, code: 200, body: '') }
+
+ let(:params) do
+ ActionController::Parameters.new(match: ['1'], start: 1.hour.ago.rfc3339, end: Time.current.rfc3339).permit!
+ end
+
+ subject { described_class.new(environment, 'GET', 'series', params) }
+
+ it 'calls PrometheusClient with given parameters' do
+ expect(prometheus_client).to receive(:proxy)
+ .with('series', params.to_h)
+ .and_return(rest_client_response)
+
+ subject.execute
+ end
+ end
end
end
diff --git a/spec/services/prometheus/proxy_variable_substitution_service_spec.rb b/spec/services/prometheus/proxy_variable_substitution_service_spec.rb
index 5982dcbc404..2435dda07b4 100644
--- a/spec/services/prometheus/proxy_variable_substitution_service_spec.rb
+++ b/spec/services/prometheus/proxy_variable_substitution_service_spec.rb
@@ -186,5 +186,19 @@ describe Prometheus::ProxyVariableSubstitutionService do
end
end
end
+
+ context '__range' do
+ let(:params_keys) do
+ {
+ query: 'topk(5, sum by (method) (rate(rest_client_requests_total[{{__range}}])))',
+ start_time: '2020-05-29T08:19:07.142Z',
+ end_time: '2020-05-29T16:19:07.142Z'
+ }
+ end
+
+ it_behaves_like 'success' do
+ let(:expected_query) { "topk(5, sum by (method) (rate(rest_client_requests_total[#{8.hours.to_i}s])))" }
+ end
+ end
end
end