PrometheusDashboard model raises UnknownAttributeError for dashboard with templating
Summary
(Summarize the bug encountered concisely)
The graphql getEnvironments
and getAnnotations
APIs return 500 error when the dashboard contains the new templating
key.
Steps to reproduce
(How one can reproduce the issue - this is very important)
- Create a dashboard with a
templating
key.
Example dashboard
dashboard: 'Development metrics'
priority: 1
templating:
variables:
environment: ['coredns|production|kube|kube-controller', 'kube']
panel_groups:
- group: 'Usage Variation'
panels:
- type: anomaly-chart
title: "Memory Usage Rate Anomalies"
y_label: "Memory Usage Rate"
metrics:
- id: container_memory_usage_bytes
query_range: avg(sum(rate(container_memory_usage_bytes[15m]))) /1024
label: "Memory Usage Rate"
unit: "kB"
- id: container_memory_usage_bytes_upper
query_range: 80000
label: "Memory Usage Rate Lower Limit"
unit: "kB"
- id: container_memory_usage_bytes_lower
query_range: 50000
label: "Memory Usage Rate Upper Limit"
unit: "kB"
- group: System metrics (Kubernetes)
panels:
- title: 'Container CPU Usage by Environment (seconds)'
type: 'heatmap'
metrics:
- id: container_cpu_usage_by_env
query_range: 'sum(rate(container_cpu_usage_seconds_total{environment=~"{{ environment }}"}[1h])) by (environment)'
step: 3600
- title: 'Number of GitLab Runner requests by status'
type: 'heatmap'
metrics:
- id: number_of_runner_requests_by_status
query_range: 'sum(rate(gitlab_runner_api_request_statuses_total[60m])) by (status)'
step: 3600
- title: '95 percentile of request durations per handler (seconds)'
type: 'heatmap'
metrics:
- id: 95_percentile_of_request_durations_per_handler
query_range: 'histogram_quantile(0.95, sum(rate(prometheus_http_request_duration_seconds_bucket[1h])) by (handler,le))'
step: 3600
-
Create an annotation on that dashboard:
Metrics::Dashboard::Annotation.create(description: FFaker::Lorem.sentence, dashboard_path: "config/prometheus/common_metrics.yml", starting_at: Time.now, environment_id: <environment_id>)
-
Visit the dashboard. (Operations > Metrics > Choose dashboard from dropdown)
Example Project
(If possible, please create an example project here on GitLab.com that exhibits the problematic behavior, and link to it here in the bug report)
(If you are using an older version of GitLab, this will also determine whether the bug is fixed in a more recent version)
What is the current bug behavior?
(What actually happens)
What is the expected correct behavior?
(What you should see instead)
Relevant logs and/or screenshots
(Paste any relevant logs - please use code blocks (```) to format console output, logs, and code as it's tough to read otherwise.)
Output of checks
(If you are reporting a bug on GitLab.com, write: This bug happens on GitLab.com)
Results of GitLab environment info
Expand for output related to GitLab environment info
(For installations with omnibus-gitlab package run and paste the output of: `sudo gitlab-rake gitlab:env:info`) (For installations from source run and paste the output of: `sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)
Results of GitLab application Check
Expand for output related to the GitLab application check
(For installations with omnibus-gitlab package run and paste the output of:
sudo gitlab-rake gitlab:check SANITIZE=true
)(For installations from source run and paste the output of:
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true
)(we will only investigate if the tests are passing)
Possible fixes
(If you can, link to the line of code that might be responsible for the problem)