WIP: POC of metrics dashboard page without environments
What does this MR do?
Notes
-
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.
-
Panels that use in built variables like
ci_environment_slug
will not show data until an environment is selected. -
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 noparams[: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.
- Add a guard to
-
Change
proxyable
inapp/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 aPrometheusService
orClusters::Cluster
object can be passed toProxyService
.- Change the
app/controllers/concerns/metrics/dashboard/prometheus_api_proxy.rb
file to passenvironment
toproxy_variable_substitution_service
, rather thanproxyable
.
- Change the
-
Miscellaneous
- Change
lib/gitlab/prometheus/query_variables.rb
to return only the__range
variable ifenvironment
is nil.
- Change
Create new routes, controllers, views, js, etc
Backend
-
Create controller and routes
-
Create new controller with actions for
metrics
andmetrics_dashboard
. Create new controller file or useapp/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
andlib/gitlab/metrics/dashboard/stages/variable_endpoint_inserter.rb
to use the new Prometheus proxy API and not to raise error whenparams[: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 themetrics_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.
- Do not display error if
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.
- Change the Operations > Metrics sidebar link to point to the new dashboard page. We could change the
Cleanup
Backend
- Remove metrics dashboard related code from
EnvironmentsHelper
andEE::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
-
Changelog entry -
Documentation (if required) -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. -
Tested in all supported browsers -
Informed Infrastructure department of a default or new setting change, if applicable per definition of done
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