From cd3988c63cd1f3f7370cca9104dc8e22809d6fe8 Mon Sep 17 00:00:00 2001 From: Rajendra Kadam <rkadam@gitlab.com> Date: Tue, 27 Jun 2023 16:15:29 +0000 Subject: [PATCH] Remove metric related unused routes from project file Update and fix specs related to routes Update specs using route path for metrics Update translations for strings Changelog: removed MR: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/124027 --- app/helpers/environment_helper.rb | 7 -- app/helpers/environments_helper.rb | 18 +---- .../alert_management/alert_presenter.rb | 12 --- app/serializers/environment_entity.rb | 8 -- app/serializers/environment_status_entity.rb | 4 - .../prometheus_alert_fired_email.html.haml | 4 - .../prometheus_alert_fired_email.text.erb | 4 - config/routes.rb | 1 - config/routes/project.rb | 8 -- .../dashboard_operations_project_entity.rb | 3 - .../controllers/operations_controller_spec.rb | 5 -- .../alert_management/payload/prometheus.rb | 12 --- .../stages/cluster_endpoint_inserter.rb | 45 ----------- lib/gitlab/metrics/dashboard/url.rb | 25 ------ locale/gitlab.pot | 15 ---- .../projects/clusters_controller_spec.rb | 12 --- .../metrics/dashboard/schemas/metrics.json | 60 +++++++++++--- .../dashboard_template_spec.js.snap | 2 - spec/helpers/environment_helper_spec.rb | 12 --- spec/helpers/environments_helper_spec.rb | 26 ------ .../payload/prometheus_spec.rb | 2 - spec/lib/gitlab/metrics/dashboard/url_spec.rb | 80 ------------------- spec/lib/gitlab/usage_data_spec.rb | 2 - spec/mailers/emails/projects_spec.rb | 3 - .../alert/metrics_dashboard_url_spec.rb | 6 -- spec/serializers/environment_entity_spec.rb | 26 ------ .../cluster_dashboard_service_spec.rb | 2 +- .../prometheus/alert_shared_context.rb | 11 --- .../metrics_dashboard_shared_examples.rb | 30 ------- 29 files changed, 50 insertions(+), 395 deletions(-) diff --git a/app/helpers/environment_helper.rb b/app/helpers/environment_helper.rb index 00109212934f2..8140ee9729189 100644 --- a/app/helpers/environment_helper.rb +++ b/app/helpers/environment_helper.rb @@ -79,7 +79,6 @@ def environments_detail_data(user, project, environment) can_destroy_environment: can_destroy_environment?(environment), can_stop_environment: can?(current_user, :stop_environment, environment), can_admin_environment: can?(current_user, :admin_environment, project), - **environment_metrics_path(project, environment), environments_fetch_path: project_environments_path(project, format: :json), environment_edit_path: edit_project_environment_path(project, environment), environment_stop_path: stop_project_environment_path(project, environment), @@ -96,10 +95,4 @@ def environments_detail_data(user, project, environment) def environments_detail_data_json(user, project, environment) environments_detail_data(user, project, environment).to_json end - - def environment_metrics_path(project, environment) - return {} if Feature.enabled?(:remove_monitor_metrics) - - { environment_metrics_path: project_metrics_dashboard_path(project, environment: environment) } - end end diff --git a/app/helpers/environments_helper.rb b/app/helpers/environments_helper.rb index 525fdd3e9f6af..f58e99bd6e8b7 100644 --- a/app/helpers/environments_helper.rb +++ b/app/helpers/environments_helper.rb @@ -26,7 +26,7 @@ def metrics_data(project, environment) metrics_data = {} metrics_data.merge!(project_metrics_data(project)) if project - metrics_data.merge!(environment_metrics_data(environment, project)) if environment + metrics_data.merge!(environment_metrics_data(environment)) if environment metrics_data.merge!(project_and_environment_metrics_data(project, environment)) if project && environment metrics_data.merge!(static_metrics_data) @@ -74,34 +74,20 @@ def project_metrics_data(project) } end - def environment_metrics_data(environment, project = nil) + def environment_metrics_data(environment) return {} unless environment { - 'metrics_dashboard_base_path' => metrics_dashboard_base_path(environment, project), 'current_environment_name' => environment.name, 'has_metrics' => environment.has_metrics?.to_s, 'environment_state' => environment.state.to_s } end - def metrics_dashboard_base_path(environment, project) - # This is needed to support our transition from environment scoped metric paths to project scoped. - if project - path = project_metrics_dashboard_path(project) - - return path if request.path.include?(path) - end - - project_metrics_dashboard_path(project, environment: environment) - end - def project_and_environment_metrics_data(project, environment) return {} unless project && environment { - 'metrics_endpoint' => additional_metrics_project_environment_path(project, environment, format: :json), - 'dashboard_endpoint' => metrics_dashboard_project_environment_path(project, environment, format: :json), 'deployments_endpoint' => project_environment_deployments_path(project, environment, format: :json), 'operations_settings_path' => project_settings_operations_path(project), 'can_access_operations_settings' => can?(current_user, :admin_operations, project).to_s, diff --git a/app/presenters/alert_management/alert_presenter.rb b/app/presenters/alert_management/alert_presenter.rb index 659e991e9d808..41831d50692a7 100644 --- a/app/presenters/alert_management/alert_presenter.rb +++ b/app/presenters/alert_management/alert_presenter.rb @@ -44,22 +44,10 @@ def show_incident_issues_link? project.incident_management_setting&.create_issue? end - def show_performance_dashboard_link? - prometheus_alert.present? - end - def incident_issues_link project_incidents_url(project) end - def performance_dashboard_link - if environment - metrics_project_environment_url(project, environment) - else - metrics_project_environments_url(project) - end - end - def email_title [environment&.name, query_title].compact.join(': ') end diff --git a/app/serializers/environment_entity.rb b/app/serializers/environment_entity.rb index 6457127d83129..0a3bf4c2a7bcf 100644 --- a/app/serializers/environment_entity.rb +++ b/app/serializers/environment_entity.rb @@ -27,10 +27,6 @@ class EnvironmentEntity < Grape::Entity ops.merge(except: UNNECESSARY_ENTRIES_FOR_UPCOMING_DEPLOYMENT)) end - expose :metrics_path, if: -> (*) { expose_metrics_path? } do |environment| - metrics_project_environment_path(environment.project, environment) - end - expose :environment_path do |environment| project_environment_path(environment.project, environment) end @@ -101,10 +97,6 @@ def deployment_platform def cluster deployment_platform.cluster end - - def expose_metrics_path? - !Feature.enabled?(:remove_monitor_metrics) && environment.has_metrics? - end end EnvironmentEntity.prepend_mod_with('EnvironmentEntity') diff --git a/app/serializers/environment_status_entity.rb b/app/serializers/environment_status_entity.rb index 9318e0c1de802..8865c030d94b9 100644 --- a/app/serializers/environment_status_entity.rb +++ b/app/serializers/environment_status_entity.rb @@ -15,10 +15,6 @@ class EnvironmentStatusEntity < Grape::Entity metrics_project_environment_deployment_path(es.project, es.environment, es.deployment) end - expose :metrics_monitoring_url, if: ->(*) { can_read_environment? } do |es| - project_metrics_dashboard_path(es.project, environment: es.environment) - end - expose :stop_url, if: ->(*) { can_stop_environment? } do |es| stop_project_environment_path(es.project, es.environment) end diff --git a/app/views/notify/prometheus_alert_fired_email.html.haml b/app/views/notify/prometheus_alert_fired_email.html.haml index cdc97d583dfed..25dc8e59073eb 100644 --- a/app/views/notify/prometheus_alert_fired_email.html.haml +++ b/app/views/notify/prometheus_alert_fired_email.html.haml @@ -25,7 +25,3 @@ - if @alert.show_incident_issues_link? %p = link_to(_('View incident issues.'), @alert.incident_issues_link) - -- if @alert.show_performance_dashboard_link? - %p - = link_to(_('View performance dashboard.'), @alert.performance_dashboard_link) diff --git a/app/views/notify/prometheus_alert_fired_email.text.erb b/app/views/notify/prometheus_alert_fired_email.text.erb index b23cd8b6cccdf..a9c1d98a39631 100644 --- a/app/views/notify/prometheus_alert_fired_email.text.erb +++ b/app/views/notify/prometheus_alert_fired_email.text.erb @@ -18,7 +18,3 @@ <% if @alert.show_incident_issues_link? %> <%= _('View incident issues.') %> <%= @alert.incident_issues_link %> <% end %> - -<% if @alert.show_performance_dashboard_link? %> -<%= _('View the performance dashboard at') %> <%= @alert.performance_dashboard_link %> -<% end %> diff --git a/config/routes.rb b/config/routes.rb index 3a9b6c1c0bf86..740911f2e3fba 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -246,7 +246,6 @@ end get :metrics_dashboard - get :'/prometheus/api/v1/*proxy_path', to: 'clusters#prometheus_proxy', as: :prometheus_api get :cluster_status, format: :json delete :clear_cache end diff --git a/config/routes/project.rb b/config/routes/project.rb index bf73f461629cc..d0d14bf80ff14 100644 --- a/config/routes/project.rb +++ b/config/routes/project.rb @@ -29,10 +29,6 @@ # Use this scope for all new project routes. scope '-' do get 'archive/*id', format: true, constraints: { format: Gitlab::PathRegex.archive_formats_regex, id: /.+?/ }, to: 'repositories#archive', as: 'archive' - get 'metrics(/:dashboard_path)', constraints: { dashboard_path: /.+\.yml/ }, - to: 'metrics_dashboard#show', as: :metrics_dashboard, format: false - get 'metrics(/:dashboard_path)/panel/new', constraints: { dashboard_path: /.+\.yml/ }, - to: 'metrics_dashboard#show', as: :new_metrics_dashboard, format: false namespace :metrics, module: :metrics do namespace :dashboards do @@ -330,9 +326,6 @@ post :stop post :cancel_auto_stop get :terminal - get :metrics - get :additional_metrics - get :metrics_dashboard # This route is also defined in gitlab-workhorse. Make sure to update accordingly. get '/terminal.ws/authorize', to: 'environments#terminal_websocket_authorize', format: false @@ -343,7 +336,6 @@ end collection do - get :metrics, action: :metrics_redirect get :folder, path: 'folders/*id', constraints: { format: /(html|json)/ } get :search end diff --git a/ee/app/serializers/dashboard_operations_project_entity.rb b/ee/app/serializers/dashboard_operations_project_entity.rb index 0063e74e56f19..8bb6447548029 100644 --- a/ee/app/serializers/dashboard_operations_project_entity.rb +++ b/ee/app/serializers/dashboard_operations_project_entity.rb @@ -24,9 +24,6 @@ class DashboardOperationsProjectEntity < Grape::Entity end expose :alert_count, if: -> (*) { !upgrade_required } - expose :alert_path, if: -> (*) { !upgrade_required && last_deployment } do |_| - metrics_project_environment_path(project, last_deployment.environment) - end expose :last_alert, using: PrometheusAlertEntity, if: -> (*) { !upgrade_required && last_alert? } private diff --git a/ee/spec/controllers/operations_controller_spec.rb b/ee/spec/controllers/operations_controller_spec.rb index bdd0d0dcf7084..9b05932d9d4f4 100644 --- a/ee/spec/controllers/operations_controller_spec.rb +++ b/ee/spec/controllers/operations_controller_spec.rb @@ -89,10 +89,6 @@ def get_index(format) let(:open_alerts) { alert_events.select(&:triggered?) + alert_events.select(&:acknowledged?) } let(:last_firing_alert) { open_alerts.last.prometheus_alert } - let(:alert_path) do - metrics_project_environment_path(project, environment) - end - let(:alert_json_path) do project_prometheus_alert_path( project, @@ -122,7 +118,6 @@ def get_index(format) .to eq(remove_operations_project_path(project_id: project.id)) expect(expected_project['last_deployment']['id']).to eq(deployment.id) expect(expected_project['alert_count']).to eq(open_alerts.size) - expect(expected_project['alert_path']).to eq(alert_path) expect(expected_project['last_alert']['id']).to eq(last_firing_alert.id) end diff --git a/lib/gitlab/alert_management/payload/prometheus.rb b/lib/gitlab/alert_management/payload/prometheus.rb index 76f3da8366b8f..cf6fe4493986f 100644 --- a/lib/gitlab/alert_management/payload/prometheus.rb +++ b/lib/gitlab/alert_management/payload/prometheus.rb @@ -78,18 +78,6 @@ def full_query rescue URI::InvalidURIError, KeyError end - def metrics_dashboard_url - return unless environment && full_query && title - - metrics_dashboard_project_environment_url( - project, - environment, - embed_json: dashboard_json, - embedded: true, - **alert_embed_window_params - ) - end - def has_required_attributes? project && title && starts_at_raw end diff --git a/lib/gitlab/metrics/dashboard/stages/cluster_endpoint_inserter.rb b/lib/gitlab/metrics/dashboard/stages/cluster_endpoint_inserter.rb index 31d7522597284..56a82d1df46cb 100644 --- a/lib/gitlab/metrics/dashboard/stages/cluster_endpoint_inserter.rb +++ b/lib/gitlab/metrics/dashboard/stages/cluster_endpoint_inserter.rb @@ -7,59 +7,14 @@ module Stages class ClusterEndpointInserter < BaseStage def transform! verify_params - - for_metrics do |metric| - metric[:prometheus_endpoint_path] = endpoint_for_metric(metric) - end end private - def admin_url(metric) - Gitlab::Routing.url_helpers.prometheus_api_admin_cluster_path( - params[:cluster], - proxy_path: query_type(metric), - query: query_for_metric(metric) - ) - end - - def endpoint_for_metric(metric) - case params[:cluster_type] - when :admin - admin_url(metric) - when :group - error!(_('Group is required when cluster_type is :group')) unless params[:group] - group_url(metric) - when :project - error!(_('Project is required when cluster_type is :project')) unless project - project_url(metric) - else - error!(_('Unrecognized cluster type')) - end - end - def error!(message) raise Errors::DashboardProcessingError, message end - def group_url(metric) - Gitlab::Routing.url_helpers.prometheus_api_group_cluster_path( - params[:group], - params[:cluster], - proxy_path: query_type(metric), - query: query_for_metric(metric) - ) - end - - def project_url(metric) - Gitlab::Routing.url_helpers.prometheus_api_project_cluster_path( - project, - params[:cluster], - proxy_path: query_type(metric), - query: query_for_metric(metric) - ) - end - def query_type(metric) metric[:query] ? :query : :query_range end diff --git a/lib/gitlab/metrics/dashboard/url.rb b/lib/gitlab/metrics/dashboard/url.rb index bdd2874413794..e7b901861ef77 100644 --- a/lib/gitlab/metrics/dashboard/url.rb +++ b/lib/gitlab/metrics/dashboard/url.rb @@ -12,26 +12,6 @@ class << self ANCHOR_PATTERN = '(?<anchor>\#[a-z0-9_-]+)?' DASH_PATTERN = '(?:/-)' - # Matches urls for a metrics dashboard. - # This regex needs to match the old metrics URL, the new metrics URL, - # and the dashboard URL (inline_metrics_redactor_filter.rb - # uses this regex to match against the dashboard URL.) - # - # EX - Old URL: https://<host>/<namespace>/<project>/environments/<env_id>/metrics - # OR - # New URL: https://<host>/<namespace>/<project>/-/metrics?environment=<env_id> - # OR - # dashboard URL: https://<host>/<namespace>/<project>/environments/<env_id>/metrics_dashboard - def metrics_regex - strong_memoize(:metrics_regex) do - regex_for_project_metrics( - %r{ - ( #{environment_metrics_regex} ) | ( #{non_environment_metrics_regex} ) - }x - ) - end - end - # Matches dashboard urls for a Grafana embed. # # EX - https://<host>/<namespace>/<project>/grafana/metrics_dashboard @@ -99,11 +79,6 @@ def parse_query(url) .symbolize_keys end - # Builds a metrics dashboard url based on the passed in arguments - def build_dashboard_url(...) - Gitlab::Routing.url_helpers.metrics_dashboard_namespace_project_environment_url(...) - end - private def environment_metrics_regex diff --git a/locale/gitlab.pot b/locale/gitlab.pot index 69b992e432b86..8b5ff9cbd178f 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -21403,9 +21403,6 @@ msgstr "" msgid "Group information" msgstr "" -msgid "Group is required when cluster_type is :group" -msgstr "" - msgid "Group jobs by" msgstr "" @@ -35575,9 +35572,6 @@ msgstr "" msgid "Project information" msgstr "" -msgid "Project is required when cluster_type is :project" -msgstr "" - msgid "Project members" msgstr "" @@ -48856,9 +48850,6 @@ msgstr "" msgid "Unrecognized approval status." msgstr "" -msgid "Unrecognized cluster type" -msgstr "" - msgid "Unresolve" msgstr "" @@ -50428,9 +50419,6 @@ msgstr "" msgid "View page @ " msgstr "" -msgid "View performance dashboard." -msgstr "" - msgid "View project in admin area" msgstr "" @@ -50460,9 +50448,6 @@ msgstr "" msgid "View the latest successful deployment to this environment" msgstr "" -msgid "View the performance dashboard at" -msgstr "" - msgid "View usage details" msgstr "" diff --git a/spec/controllers/projects/clusters_controller_spec.rb b/spec/controllers/projects/clusters_controller_spec.rb index bface88667401..15b7ddd85ea8e 100644 --- a/spec/controllers/projects/clusters_controller_spec.rb +++ b/spec/controllers/projects/clusters_controller_spec.rb @@ -113,18 +113,6 @@ def go(params = {}) end end - it_behaves_like 'GET #metrics_dashboard for dashboard', 'Cluster health' do - let(:cluster) { create(:cluster, :provided_by_gcp, projects: [project]) } - - let(:metrics_dashboard_req_params) do - { - id: cluster.id, - namespace_id: project.namespace.full_path, - project_id: project.path - } - end - end - describe 'POST create for existing cluster' do let(:params) do { diff --git a/spec/fixtures/lib/gitlab/metrics/dashboard/schemas/metrics.json b/spec/fixtures/lib/gitlab/metrics/dashboard/schemas/metrics.json index 8ee207b7ebfb7..79132c0d03915 100644 --- a/spec/fixtures/lib/gitlab/metrics/dashboard/schemas/metrics.json +++ b/spec/fixtures/lib/gitlab/metrics/dashboard/schemas/metrics.json @@ -2,23 +2,57 @@ "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "required": [ - "label", - "prometheus_endpoint_path" + "label" ], "oneOf": [ - { "required": ["query"] }, - { "required": ["query_range"] } + { + "required": [ + "query" + ] + }, + { + "required": [ + "query_range" + ] + } ], "properties": { - "id": { "type": "string" }, - "query_range": { "type": ["string", "number"] }, - "query": { "type": ["string", "number"] }, - "unit": { "type": "string" }, - "label": { "type": "string" }, - "track": { "type": "string" }, - "prometheus_endpoint_path": { "type": "string" }, - "metric_id": { "type": "number" }, - "edit_path": { "type": ["string", "null"] } + "id": { + "type": "string" + }, + "query_range": { + "type": [ + "string", + "number" + ] + }, + "query": { + "type": [ + "string", + "number" + ] + }, + "unit": { + "type": "string" + }, + "label": { + "type": "string" + }, + "track": { + "type": "string" + }, + "prometheus_endpoint_path": { + "type": "string" + }, + "metric_id": { + "type": "number" + }, + "edit_path": { + "type": [ + "string", + "null" + ] + } }, "additionalProperties": false } diff --git a/spec/frontend/monitoring/components/__snapshots__/dashboard_template_spec.js.snap b/spec/frontend/monitoring/components/__snapshots__/dashboard_template_spec.js.snap index 3b4554700b46d..b1eb666b5fd76 100644 --- a/spec/frontend/monitoring/components/__snapshots__/dashboard_template_spec.js.snap +++ b/spec/frontend/monitoring/components/__snapshots__/dashboard_template_spec.js.snap @@ -5,8 +5,6 @@ exports[`Dashboard template matches the default snapshot 1`] = ` class="prometheus-graphs" data-testid="prometheus-graphs" environmentstate="available" - metricsdashboardbasepath="/monitoring/monitor-project/-/metrics?environment=1" - metricsendpoint="/monitoring/monitor-project/-/environments/1/additional_metrics.json" > <div> <gl-alert-stub diff --git a/spec/helpers/environment_helper_spec.rb b/spec/helpers/environment_helper_spec.rb index 64735f8b23bf9..b9316e46d9d3e 100644 --- a/spec/helpers/environment_helper_spec.rb +++ b/spec/helpers/environment_helper_spec.rb @@ -68,17 +68,5 @@ graphql_etag_key: environment.etag_cache_key }.to_json) end - - context 'when metrics dashboard feature is available' do - before do - stub_feature_flags(remove_monitor_metrics: false) - end - - it 'includes metrics path' do - expect(Gitlab::Json.parse(subject)).to include( - 'environment_metrics_path' => project_metrics_dashboard_path(project, environment: environment) - ) - end - end end end diff --git a/spec/helpers/environments_helper_spec.rb b/spec/helpers/environments_helper_spec.rb index 0ebec3ed6d0a0..cb559ee365e48 100644 --- a/spec/helpers/environments_helper_spec.rb +++ b/spec/helpers/environments_helper_spec.rb @@ -22,7 +22,6 @@ expect(metrics_data).to include( 'settings_path' => edit_project_settings_integration_path(project, 'prometheus'), 'clusters_path' => project_clusters_path(project), - 'metrics_dashboard_base_path' => project_metrics_dashboard_path(project, environment: environment), 'current_environment_name' => environment.name, 'documentation_path' => help_page_path('administration/monitoring/prometheus/index.md'), 'add_dashboard_documentation_path' => help_page_path('operations/metrics/dashboards/index.md', anchor: 'add-a-new-dashboard-to-your-project'), @@ -30,7 +29,6 @@ 'empty_loading_svg_path' => match_asset_path('/assets/illustrations/monitoring/loading.svg'), 'empty_no_data_svg_path' => match_asset_path('/assets/illustrations/monitoring/no_data.svg'), 'empty_unable_to_connect_svg_path' => match_asset_path('/assets/illustrations/monitoring/unable_to_connect.svg'), - 'metrics_endpoint' => additional_metrics_project_environment_path(project, environment, format: :json), 'deployments_endpoint' => project_environment_deployments_path(project, environment, format: :json), 'default_branch' => 'master', 'project_path' => project_path(project), @@ -82,30 +80,6 @@ it { is_expected.to include('environment_state' => 'stopped') } end - context 'when request is from project scoped metrics path' do - let(:request) { double('request', path: path) } - - before do - allow(helper).to receive(:request).and_return(request) - end - - context '/:namespace/:project/-/metrics' do - let(:path) { project_metrics_dashboard_path(project) } - - it 'uses correct path for metrics_dashboard_base_path' do - expect(metrics_data['metrics_dashboard_base_path']).to eq(project_metrics_dashboard_path(project)) - end - end - - context '/:namespace/:project/-/metrics/some_custom_dashboard.yml' do - let(:path) { "#{project_metrics_dashboard_path(project)}/some_custom_dashboard.yml" } - - it 'uses correct path for metrics_dashboard_base_path' do - expect(metrics_data['metrics_dashboard_base_path']).to eq(project_metrics_dashboard_path(project)) - end - end - end - context 'when metrics dashboard feature is unavailable' do before do stub_feature_flags(remove_monitor_metrics: true) diff --git a/spec/lib/gitlab/alert_management/payload/prometheus_spec.rb b/spec/lib/gitlab/alert_management/payload/prometheus_spec.rb index 8ead292c27ae8..cf525801aa040 100644 --- a/spec/lib/gitlab/alert_management/payload/prometheus_spec.rb +++ b/spec/lib/gitlab/alert_management/payload/prometheus_spec.rb @@ -185,8 +185,6 @@ subject { parsed_payload.metrics_dashboard_url } - it { is_expected.to eq(dashboard_url_for_alert) } - context 'without environment' do let(:raw_payload) { payload.except('labels') } diff --git a/spec/lib/gitlab/metrics/dashboard/url_spec.rb b/spec/lib/gitlab/metrics/dashboard/url_spec.rb index d49200f87cc9f..4045d957b4417 100644 --- a/spec/lib/gitlab/metrics/dashboard/url_spec.rb +++ b/spec/lib/gitlab/metrics/dashboard/url_spec.rb @@ -5,78 +5,6 @@ RSpec.describe Gitlab::Metrics::Dashboard::Url do include Gitlab::Routing.url_helpers - describe '#metrics_regex' do - let(:environment_id) { 1 } - let(:url_params) do - [ - 'foo', - 'bar', - environment_id, - { - start: '2019-08-02T05:43:09.000Z', - dashboard: 'config/prometheus/common_metrics.yml', - group: 'awesome group', - anchor: 'title' - } - ] - end - - let(:expected_params) do - { - 'url' => url, - 'namespace' => 'foo', - 'project' => 'bar', - 'environment' => '1', - 'query' => '?dashboard=config%2Fprometheus%2Fcommon_metrics.yml&group=awesome+group&start=2019-08-02T05%3A43%3A09.000Z', - 'anchor' => '#title' - } - end - - subject { described_class.metrics_regex } - - context 'for /-/environments/:environment_id/metrics route' do - let(:url) { metrics_namespace_project_environment_url(*url_params) } - - it_behaves_like 'regex which matches url when expected' - end - - context 'for /-/metrics?environment=:environment_id route' do - let(:url) { namespace_project_metrics_dashboard_url(*url_params) } - let(:url_params) do - [ - 'namespace1', - 'project1', - { - environment: environment_id, - start: '2019-08-02T05:43:09.000Z', - dashboard: 'config/prometheus/common_metrics.yml', - group: 'awesome group', - anchor: 'title' - } - ] - end - - let(:expected_params) do - { - 'url' => url, - 'namespace' => 'namespace1', - 'project' => 'project1', - 'environment' => environment_id.to_s, - 'query' => "?dashboard=config%2Fprometheus%2Fcommon_metrics.yml&environment=#{environment_id}&group=awesome+group&start=2019-08-02T05%3A43%3A09.000Z", - 'anchor' => '#title' - } - end - - it_behaves_like 'regex which matches url when expected' - end - - context 'for metrics_dashboard route' do - let(:url) { metrics_dashboard_namespace_project_environment_url(*url_params) } - - it_behaves_like 'regex which matches url when expected' - end - end - describe '#clusters_regex' do let(:url) { Gitlab::Routing.url_helpers.namespace_project_cluster_url(*url_params) } let(:url_params) do @@ -202,12 +130,4 @@ end end end - - describe '#build_dashboard_url' do - it 'builds the url for the dashboard endpoint' do - url = described_class.build_dashboard_url('foo', 'bar', 1) - - expect(url).to match described_class.metrics_regex - end - end end diff --git a/spec/lib/gitlab/usage_data_spec.rb b/spec/lib/gitlab/usage_data_spec.rb index 9df869f880188..f7c81f93260e2 100644 --- a/spec/lib/gitlab/usage_data_spec.rb +++ b/spec/lib/gitlab/usage_data_spec.rb @@ -804,7 +804,6 @@ def omniauth_providers let(:project) { create(:project) } let(:description_with_embed) { "Some comment\n\nhttps://grafana.example.com/d/xvAk4q0Wk/go-processes?orgId=1&from=1573238522762&to=1573240322762&var-job=prometheus&var-interval=10m&panelId=1&fullscreen" } let(:description_with_unintegrated_embed) { "Some comment\n\nhttps://grafana.exp.com/d/xvAk4q0Wk/go-processes?orgId=1&from=1573238522762&to=1573240322762&var-job=prometheus&var-interval=10m&panelId=1&fullscreen" } - let(:description_with_non_grafana_inline_metric) { "Some comment\n\n#{Gitlab::Routing.url_helpers.metrics_namespace_project_environment_url(*['foo', 'bar', 12])}" } shared_examples "zero count" do it "does not count the issue" do @@ -824,7 +823,6 @@ def omniauth_providers create(:issue, project: project, description: description_with_embed) # In-Valid create(:issue, project: project, description: description_with_unintegrated_embed) - create(:issue, project: project, description: description_with_non_grafana_inline_metric) create(:issue, project: project, description: nil) create(:issue, project: project, description: '') create(:issue, project: project) diff --git a/spec/mailers/emails/projects_spec.rb b/spec/mailers/emails/projects_spec.rb index ef3c21b32cee0..1f0f09f7ca22d 100644 --- a/spec/mailers/emails/projects_spec.rb +++ b/spec/mailers/emails/projects_spec.rb @@ -104,7 +104,6 @@ let_it_be(:environment) { create(:environment, project: project) } let(:payload) { { 'gitlab_environment_name' => environment.name } } - let(:metrics_url) { metrics_project_environment_url(project, environment) } it_behaves_like 'an email sent from GitLab' it_behaves_like 'it should not have Gmail Actions links' @@ -131,7 +130,6 @@ let(:alert) { create(:alert_management_alert, :prometheus, :from_payload, payload: payload, project: project) } let(:title) { "#{prometheus_alert.title} #{prometheus_alert.computed_operator} #{prometheus_alert.threshold}" } - let(:metrics_url) { metrics_project_environment_url(project, environment) } before do payload['labels'] = { @@ -157,7 +155,6 @@ is_expected.to have_body_text(environment.name) is_expected.to have_body_text('Metric:') is_expected.to have_body_text(prometheus_alert.full_query) - is_expected.to have_body_text(metrics_url) is_expected.not_to have_body_text('Description:') end end diff --git a/spec/requests/api/graphql/project/alert_management/alert/metrics_dashboard_url_spec.rb b/spec/requests/api/graphql/project/alert_management/alert/metrics_dashboard_url_spec.rb index 3417f9529bdcb..2c49c9bc47be1 100644 --- a/spec/requests/api/graphql/project/alert_management/alert/metrics_dashboard_url_spec.rb +++ b/spec/requests/api/graphql/project/alert_management/alert/metrics_dashboard_url_spec.rb @@ -40,12 +40,6 @@ create(:alert_management_alert, :prometheus, project: project, payload: payload) end - it 'includes the correct metrics dashboard url' do - post_graphql(graphql_query, current_user: current_user) - - expect(first_alert).to include('metricsDashboardUrl' => dashboard_url_for_alert) - end - context 'when metrics dashboard feature is unavailable' do before do stub_feature_flags(remove_monitor_metrics: true) diff --git a/spec/serializers/environment_entity_spec.rb b/spec/serializers/environment_entity_spec.rb index c60bead12c2eb..551acd2860d89 100644 --- a/spec/serializers/environment_entity_spec.rb +++ b/spec/serializers/environment_entity_spec.rb @@ -83,32 +83,6 @@ end end - context 'when metrics dashboard feature is available' do - before do - stub_feature_flags(remove_monitor_metrics: false) - end - - context 'metrics disabled' do - before do - allow(environment).to receive(:has_metrics?).and_return(false) - end - - it "doesn't expose metrics path" do - expect(subject).not_to include(:metrics_path) - end - end - - context 'metrics enabled' do - before do - allow(environment).to receive(:has_metrics?).and_return(true) - end - - it 'exposes metrics path' do - expect(subject).to include(:metrics_path) - end - end - end - it "doesn't expose metrics path" do expect(subject).not_to include(:metrics_path) end diff --git a/spec/services/metrics/dashboard/cluster_dashboard_service_spec.rb b/spec/services/metrics/dashboard/cluster_dashboard_service_spec.rb index beed23a366fb4..53def716de31f 100644 --- a/spec/services/metrics/dashboard/cluster_dashboard_service_spec.rb +++ b/spec/services/metrics/dashboard/cluster_dashboard_service_spec.rb @@ -36,7 +36,7 @@ end describe '#get_dashboard' do - let(:service_params) { [project, user, { cluster: cluster, cluster_type: :project }] } + let(:service_params) { [project, user, { cluster: cluster, cluster_type: :admin }] } let(:service_call) { subject.get_dashboard } subject { described_class.new(*service_params) } diff --git a/spec/support/shared_contexts/prometheus/alert_shared_context.rb b/spec/support/shared_contexts/prometheus/alert_shared_context.rb index 932ab89927018..13e739680c84c 100644 --- a/spec/support/shared_contexts/prometheus/alert_shared_context.rb +++ b/spec/support/shared_contexts/prometheus/alert_shared_context.rb @@ -37,17 +37,6 @@ } } end - - let(:dashboard_url_for_alert) do - Gitlab::Routing.url_helpers.metrics_dashboard_project_environment_url( - project, - environment, - embed_json: embed_content, - embedded: true, - end: '2018-03-12T09:36:00Z', - start: '2018-03-12T08:36:00Z' - ) - end end RSpec.shared_context 'gitlab-managed prometheus alert attributes' do diff --git a/spec/support/shared_examples/controllers/metrics_dashboard_shared_examples.rb b/spec/support/shared_examples/controllers/metrics_dashboard_shared_examples.rb index 5b63ef10c854b..013d722a8c18f 100644 --- a/spec/support/shared_examples/controllers/metrics_dashboard_shared_examples.rb +++ b/spec/support/shared_examples/controllers/metrics_dashboard_shared_examples.rb @@ -12,33 +12,3 @@ expect(found_keys).to contain_exactly(*expected_keys) end end - -RSpec.shared_examples_for 'GET #metrics_dashboard for dashboard' do |dashboard_name| - let(:expected_keys) { %w(dashboard status metrics_data) } - let(:status_code) { :ok } - - before do - stub_feature_flags(remove_monitor_metrics: false) - end - - it_behaves_like 'GET #metrics_dashboard correctly formatted response' - - it 'returns correct dashboard' do - get :metrics_dashboard, params: metrics_dashboard_req_params, format: :json - - expect(json_response['dashboard']['dashboard']).to eq(dashboard_name) - end - - context 'when metrics dashboard feature is unavailable' do - before do - stub_feature_flags(remove_monitor_metrics: true) - end - - it 'returns 404 not found' do - get :metrics_dashboard, params: metrics_dashboard_req_params, format: :json - - expect(response).to have_gitlab_http_status(:not_found) - expect(response.body).to be_empty - end - end -end -- GitLab