Newlines in Prometheus query strings in metrics dashboard YAML files cause error
Summary
(Summarize the bug encountered concisely)
If a newline is present in a Prometheus query string, it results in an error. This prevents users from using multiline strings in dashboard YAML files to make queries more readable.
Steps to reproduce
(How one can reproduce the issue - this is very important)
-
Create a project (you can clone the https://gitlab.com/joshlambert/autodevops-deploy/), add a K8s cluster and install the Helm and Prometheus managed apps.
-
Create a dashboard file in the project's repository under
.gitlab/dashboards/test_multiline_strings.yml
. Create the.gitlab/dashboards
folders if they don't exist. Put the following into the dashboard file:dashboard: 'Environment metrics' priority: 1 panel_groups: - group: System metrics (Kubernetes) priority: 15 panels: - title: "Memory Usage (Total)" type: "area-chart" y_label: "Total Memory Used (GB)" weight: 4 metrics: - id: system_metrics_kubernetes_container_memory_total query_range: >- avg ( sum ( container_memory_usage_bytes{ container_name!="POD", pod_name=~"^{{ci_environment_slug}}-(.*)",namespace="{{kube_namespace}}" } ) by (job) ) without (job) / 1024 / 1024 / 1024 label: Total (GB) unit: GB
-
Commit the dashboard file.
-
Open the metrics dashboard page (Operations > Metrics) and select the above dashboard.
-
Observe that the chart does not populate with data. If you open your browser's Network tab (in the developer console), you'll notice that the chart's requests for data keep returning 204. If you tail your GDK logs (
gdk tail rails-background-jobs
), you'll notice an exception gets raised (URI is invalid
).
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)
Newlines in queries result in error.
What is the expected correct behavior?
(What you should see instead)
Newlines should not cause errors.
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)
The error happens due to our UrlBlocker not allowing newlines in URLs.
We could get around this problem by removing newlines from query strings before attempting to send them to Prometheus.