diff options
author | syasonik <syasonik@gitlab.com> | 2019-06-05 14:43:50 +0100 |
---|---|---|
committer | syasonik <syasonik@gitlab.com> | 2019-06-06 11:43:50 +0100 |
commit | 54dd44030b052a1456c26e90742b227943d600be (patch) | |
tree | f3e03df0ec7506b8916e1114e30f74052c3f2e73 /spec | |
parent | b46b38ff9fb09692aa02efd377e44756e1caabf2 (diff) | |
download | gitlab-ce-54dd44030b052a1456c26e90742b227943d600be.tar.gz |
Expose prometheus endpoint per metric in dashboard
Adds a new stage to dashboard processesing step for the
EnvironmentsController::metrics_dashboard endpoint.
Allows the front end to avoid generating the endpoint
unitutive string mutations.
Diffstat (limited to 'spec')
5 files changed, 34 insertions, 7 deletions
diff --git a/spec/fixtures/lib/gitlab/metrics/dashboard/schemas/metrics.json b/spec/fixtures/lib/gitlab/metrics/dashboard/schemas/metrics.json index 2d0af57ec2c..33393805464 100644 --- a/spec/fixtures/lib/gitlab/metrics/dashboard/schemas/metrics.json +++ b/spec/fixtures/lib/gitlab/metrics/dashboard/schemas/metrics.json @@ -2,7 +2,8 @@ "type": "object", "required": [ "unit", - "label" + "label", + "prometheus_endpoint_path" ], "oneOf": [ { "required": ["query"] }, @@ -14,7 +15,8 @@ "query": { "type": "string" }, "unit": { "type": "string" }, "label": { "type": "string" }, - "track": { "type": "string" } + "track": { "type": "string" }, + "prometheus_endpoint_path": { "type": "string" } }, "additionalProperties": false } diff --git a/spec/lib/gitlab/metrics/dashboard/finder_spec.rb b/spec/lib/gitlab/metrics/dashboard/finder_spec.rb index e88eb140b35..0bfe6cb69d9 100644 --- a/spec/lib/gitlab/metrics/dashboard/finder_spec.rb +++ b/spec/lib/gitlab/metrics/dashboard/finder_spec.rb @@ -6,7 +6,7 @@ describe Gitlab::Metrics::Dashboard::Finder, :use_clean_rails_memory_store_cachi include MetricsDashboardHelpers set(:project) { build(:project) } - set(:environment) { build(:environment, project: project) } + set(:environment) { create(:environment, project: project) } let(:system_dashboard_path) { Gitlab::Metrics::Dashboard::SystemDashboardService::SYSTEM_DASHBOARD_PATH} describe '.find' do @@ -27,6 +27,17 @@ describe Gitlab::Metrics::Dashboard::Finder, :use_clean_rails_memory_store_cachi it_behaves_like 'misconfigured dashboard service response', :unprocessable_entity end + context 'when the dashboard contains a metric without a query' do + let(:project) do + project_with_dashboard( + dashboard_path, + { 'panel_groups' => [{ 'panels' => [{ 'metrics' => [{ 'id' => 'mock' }] }] }] }.to_yaml + ) + end + + it_behaves_like 'misconfigured dashboard service response', :unprocessable_entity + end + context 'when the system dashboard is specified' do let(:dashboard_path) { system_dashboard_path } diff --git a/spec/lib/gitlab/metrics/dashboard/processor_spec.rb b/spec/lib/gitlab/metrics/dashboard/processor_spec.rb index be3c1095bd7..f0256538c2e 100644 --- a/spec/lib/gitlab/metrics/dashboard/processor_spec.rb +++ b/spec/lib/gitlab/metrics/dashboard/processor_spec.rb @@ -4,13 +4,19 @@ require 'spec_helper' describe Gitlab::Metrics::Dashboard::Processor do let(:project) { build(:project) } - let(:environment) { build(:environment, project: project) } + let(:environment) { create(:environment, project: project) } let(:dashboard_yml) { YAML.load_file('spec/fixtures/lib/gitlab/metrics/dashboard/sample_dashboard.yml') } describe 'process' do let(:process_params) { [project, environment, dashboard_yml] } let(:dashboard) { described_class.new(*process_params).process(insert_project_metrics: true) } + it 'includes a path for the prometheus endpoint with each metric' do + all_metrics.each do |metric| + expect(metric).to include(prometheus_endpoint_path: prometheus_path(metric[:query_range])) + end + end + context 'when dashboard config corresponds to common metrics' do let!(:common_metric) { create(:prometheus_metric, :common, identifier: 'metric_a1') } @@ -99,7 +105,15 @@ describe Gitlab::Metrics::Dashboard::Processor do query_range: metric.query, unit: metric.unit, label: metric.legend, - metric_id: metric.id + metric_id: metric.id, + prometheus_endpoint_path: prometheus_path(metric.query) } end + + def prometheus_path(query) + "/#{project.namespace.path}" \ + "/#{project.name}/environments/" \ + "#{environment.id}/prometheus/api/v1" \ + "/query_range?query=#{CGI::escape query}" + end end diff --git a/spec/lib/gitlab/metrics/dashboard/project_dashboard_service_spec.rb b/spec/lib/gitlab/metrics/dashboard/project_dashboard_service_spec.rb index 162beb0268a..794ac5f109b 100644 --- a/spec/lib/gitlab/metrics/dashboard/project_dashboard_service_spec.rb +++ b/spec/lib/gitlab/metrics/dashboard/project_dashboard_service_spec.rb @@ -7,7 +7,7 @@ describe Gitlab::Metrics::Dashboard::ProjectDashboardService, :use_clean_rails_m set(:user) { build(:user) } set(:project) { build(:project) } - set(:environment) { build(:environment, project: project) } + set(:environment) { create(:environment, project: project) } before do project.add_maintainer(user) diff --git a/spec/lib/gitlab/metrics/dashboard/system_dashboard_service_spec.rb b/spec/lib/gitlab/metrics/dashboard/system_dashboard_service_spec.rb index e71ce2481a3..2648fe990de 100644 --- a/spec/lib/gitlab/metrics/dashboard/system_dashboard_service_spec.rb +++ b/spec/lib/gitlab/metrics/dashboard/system_dashboard_service_spec.rb @@ -6,7 +6,7 @@ describe Gitlab::Metrics::Dashboard::SystemDashboardService, :use_clean_rails_me include MetricsDashboardHelpers set(:project) { build(:project) } - set(:environment) { build(:environment, project: project) } + set(:environment) { create(:environment, project: project) } describe 'get_dashboard' do let(:dashboard_path) { described_class::SYSTEM_DASHBOARD_PATH } |