NGINX /rails-metrics returns 404 when GitLab uses a relative URL
Summary
When external_url has a path, for example http://gitlab.example.com/gitlab, the NGINX location /rails-metrics returns HTTP 404. The location is on the NGINX status server (*:8060).
This defect is on master (8b3001a9). It is related to #9933 (closed), which is about the Prometheus scrape job. !9929 (merged) corrects the scrape job and does not change this location.
Cause
The template sends the request to /-/metrics without the relative URL:
nginx-gitlab-rails-metrics.conf.erbline 4:proxy_pass http://gitlab-workhorse/-/metrics;nginx.rblines 150-157 gives the template onlyoptions.
Workhorse does not send paths outside the relative URL to Puma. It returns 404.
Effect
/rails-metrics does not return the Rails metrics. The bundled Prometheus does not use this location, and the location accepts requests from 127.0.0.1 only. Thus, only an operator or a tool that reads this location directly sees the defect.
How to reproduce
-
Set
external_url 'http://gitlab.example.com/gitlab'and do a reconfigure operation. -
On the node, send these requests:
curl -s -o /dev/null -w '%{http_code}\n' http://127.0.0.1:8060/rails-metrics S=/var/opt/gitlab/gitlab-workhorse/sockets/socket curl -s -o /dev/null -w '%{http_code}\n' --unix-socket $S http://localhost/-/metrics curl -s -o /dev/null -w '%{http_code}\n' --unix-socket $S http://localhost/gitlab/-/metrics
Results on gitlab/gitlab-ee:19.3.0-ee.0:
nginx :8060 /rails-metrics -> 404 Not found "/-/metrics"
workhorse socket /-/metrics -> 404 Not found "/-/metrics"
workhorse socket /gitlab/-/metrics -> 200 # HELP action_cable_active_connections Multiprocess metricWith external_url 'http://gitlab.example.com', the same rendered file gives HTTP 200 at /rails-metrics.
Correction
Give the relative URL to the template from nginx.rb, and add it before /-/metrics in proxy_pass. nginx.rb already reads gitlab_rails['gitlab_relative_url'] for the other locations.
Tests
Add a ChefSpec example that renders this file with a relative URL and examines proxy_pass.