Skip to content

WIP: POC of metrics dashboard page without environments

Reuben Pereira requested to merge 213833-poc into master

What does this MR do?

Notes

  1. Alerts are tightly coupled with environments. If an environment is selected from the environment dropdown, full alert functionality is available on the metrics dashboard. However, if no environment is selected, "Alerts" will not appear in panel menus, and any existing alerts will not be displayed above each panel.

  2. Panels that use in built variables like ci_environment_slug will not show data until an environment is selected.

  3. Clusters can be scoped to particular environments. Or a cluster can be scoped to any environment. We select which Prometheus managed app to query based on the selected environment. When no environment is selected, we can use the Prometheus app of the cluster scoped to any environment. If no such cluster exists, the user needs to select an environment so that we know which Prometheus to query.

Preparatory changes

  • Prepare the dashboard services and stages for functioning without environment.

    • Add a guard to lib/gitlab/metrics/dashboard/stages/alerts_inserter.rb so that it doesn't return 500 status code if there is no params[:environment].
    • Do not return error from Metrics::Dashboard::BaseService when there is no environment. I think this can be done early and let each service & stage determine if they need an environment or not.
  • Change proxyable in app/services/prometheus/proxy_service.rb class to be an object that responds to .prometheus_client, rather than an object which responds to .prometheus_adapter. This is so that a PrometheusService or Clusters::Cluster object can be passed to ProxyService.

    • Change the app/controllers/concerns/metrics/dashboard/prometheus_api_proxy.rb file to pass environment to proxy_variable_substitution_service, rather than proxyable.
  • Miscellaneous

    • Change lib/gitlab/prometheus/query_variables.rb to return only the __range variable if environment is nil.

Create new routes, controllers, views, js, etc

Backend

  • Create controller and routes

    • Create new controller with actions for metrics and metrics_dashboard. Create new controller file or use app/controllers/projects/metrics_dashboard_controller.rb.

    • Add new routes for metrics and metrics_dashboard.

    • Create new helper file. Copy EnvironmentsHelper and modify methods to return the new metrics dashboard path.

  • Create new Prometheus proxy API that does not have environment_id as a path parameter. It can still take an environment_id as a query parameter.

Frontend

  • Create html, js and helper files.
    • Create new view file.
    • Create new js file and import the dashboard vue app.

Switch to using the new Prometheus proxy API

Backend

  • Update lib/gitlab/metrics/dashboard/stages/metric_endpoint_inserter.rb and lib/gitlab/metrics/dashboard/stages/variable_endpoint_inserter.rb to use the new Prometheus proxy API and not to raise error when params[:environment] is blank.

Frontend

  • Fix the dashboard vue app to work with the new and old routes.
    • Do not display error if hasMetrics is false in dashboard.vue.
    • If the environment_id URL parameter is passed to the metrics dashboard HTML page, add the URL parameter to the metrics_dashboard.json API call, and to the Prometheus proxy API calls.
    • this.graphData?.metrics[0].result can sometimes be null, which causes errors on the browser console. Investigate.

Switch to using the new metrics and metrics_dashboard routes

Frontend

  • Change the environment selector links to point to the new dashboard page.

Backend

  • Change dashboard embeds to work with the new and old routes.
  • Update the old metrics and metrics_dashboard routes to redirect to the new routes.
    • Change the Operations > Metrics sidebar link to point to the new dashboard page. We could change the metrics_redirect action in the EnvironmentsController to redirect to the new dashboard page.

Cleanup

Backend

  • Remove metrics dashboard related code from EnvironmentsHelper and EE::EnvironmentsHelper.
  • Remove old Prometheus API route and controller: app/controllers/projects/environments/prometheus_api_controller.rb.
  • Stop creating an environment in lib/gitlab/database_importers/self_monitoring/project/create_service.rb?

Frontend

  • Remove old view and js files.

Issue: #213833 (closed)

Testing

  • Project with environment and deployment.
    • Default dashboard.
      • Without environment selected, the custom metrics show up.
      • With environment selected, all metrics show up.
      • Alerts can be viewed/modified/deleted when environment is selected.
  • Project without an environment.
    • Default dashboard shows custom metrics.
  • Project with Prometheus manual configuration.
    • Default dashboard shows custom metrics.
  • Project with no cluster having environment_scope *, and no manually configured Prometheus.
    • Shows No prometheus server found.
    • If there is a cluster with environment_scope 'staging' and staging environment is selected, that cluster's Prometheus is used.
  • Dashboard with templating variables.
  • Link to logs in panel menu.
  • Dashboard embeds
  • Grafana proxy?

Todo

  • Fix embeds

Screenshots

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by Reuben Pereira

Merge request reports

Loading