diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-12 15:09:01 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-12 15:09:01 +0300 |
commit | bd497e352ebd279536ae11855871162e82a3f88c (patch) | |
tree | 2241444d4be33e199d7011b872713071a8f8cd41 /lib/gitlab/metrics | |
parent | 0388886f9439fa93efea29a159522aec5643f7c8 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/metrics')
-rw-r--r-- | lib/gitlab/metrics/dashboard/url.rb | 58 |
1 files changed, 34 insertions, 24 deletions
diff --git a/lib/gitlab/metrics/dashboard/url.rb b/lib/gitlab/metrics/dashboard/url.rb index 712f769bbeb..b3cbfde828c 100644 --- a/lib/gitlab/metrics/dashboard/url.rb +++ b/lib/gitlab/metrics/dashboard/url.rb @@ -6,41 +6,36 @@ module Gitlab module Dashboard class Url class << self + include Gitlab::Utils::StrongMemoize # Matches urls for a metrics dashboard. This could be # either the /metrics endpoint or the /metrics_dashboard # endpoint. # # EX - https://<host>/<namespace>/<project>/environments/<env_id>/metrics - def regex - %r{ - (?<url> - #{gitlab_pattern} - #{project_pattern} - (?:\/\-)? - \/environments - \/(?<environment>\d+) - \/metrics - #{query_pattern} - #{anchor_pattern} + def metrics_regex + strong_memoize(:metrics_regex) do + regex_for_project_metrics( + %r{ + /environments + /(?<environment>\d+) + /metrics + }x ) - }x + end end # Matches dashboard urls for a Grafana embed. # # EX - https://<host>/<namespace>/<project>/grafana/metrics_dashboard def grafana_regex - %r{ - (?<url> - #{gitlab_pattern} - #{project_pattern} - (?:\/\-)? - \/grafana - \/metrics_dashboard - #{query_pattern} - #{anchor_pattern} + strong_memoize(:grafana_regex) do + regex_for_project_metrics( + %r{ + /grafana + /metrics_dashboard + }x ) - }x + end end # Parses query params out from full url string into hash. @@ -62,11 +57,24 @@ module Gitlab private - def gitlab_pattern + def regex_for_project_metrics(path_suffix_pattern) + %r{ + (?<url> + #{gitlab_host_pattern} + #{project_path_pattern} + (?:/-)? + #{path_suffix_pattern} + #{query_pattern} + #{anchor_pattern} + ) + }x + end + + def gitlab_host_pattern Regexp.escape(Gitlab.config.gitlab.url) end - def project_pattern + def project_path_pattern "\/#{Project.reference_pattern}" end @@ -82,3 +90,5 @@ module Gitlab end end end + +Gitlab::Metrics::Dashboard::Url.extend_if_ee('::EE::Gitlab::Metrics::Dashboard::Url') |