Class: Gitlab::Metrics::Dashboard::Url
- Inherits:
-
Object
- Object
- Gitlab::Metrics::Dashboard::Url
- Extended by:
- Utils::StrongMemoize
- Defined in:
- lib/gitlab/metrics/dashboard/url.rb
Constant Summary collapse
- QUERY_PATTERN =
'(?<query>\?[a-zA-Z0-9%.()+_=-]+(&[a-zA-Z0-9%.()+_=-]+)*)?'
- ANCHOR_PATTERN =
'(?<anchor>\#[a-z0-9_-]+)?'
- DASH_PATTERN =
'(?:/-)'
Class Method Summary collapse
-
.alert_regex ⇒ Object
Matches dashboard urls for a metric chart embed for a specifc firing GitLab alert.
-
.build_dashboard_url(*args) ⇒ Object
Builds a metrics dashboard url based on the passed in arguments.
-
.clusters_regex ⇒ Object
Matches dashboard urls for a metric chart embed for cluster metrics.
-
.grafana_regex ⇒ Object
Matches dashboard urls for a Grafana embed.
-
.metrics_regex ⇒ Object
Matches urls for a metrics dashboard.
-
.parse_query(url) ⇒ Object
Parses query params out from full url string into hash.
Methods included from Utils::StrongMemoize
clear_memoization, strong_memoize, strong_memoized?
Class Method Details
.alert_regex ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/gitlab/metrics/dashboard/url.rb', line 76 def alert_regex strong_memoize(:alert_regex) do regex_for_project_metrics( %r{ #{DASH_PATTERN}? /prometheus /alerts /(?<alert>\d+) /metrics_dashboard(\.json)? }x ) end end |
.build_dashboard_url(*args) ⇒ Object
Builds a metrics dashboard url based on the passed in arguments
103 104 105 |
# File 'lib/gitlab/metrics/dashboard/url.rb', line 103 def build_dashboard_url(*args) Gitlab::Routing.url_helpers.metrics_dashboard_namespace_project_environment_url(*args) end |
.clusters_regex ⇒ Object
Matches dashboard urls for a metric chart embed for cluster metrics. This regex needs to match the dashboard URL as well, not just the trigger URL. The inline_metrics_redactor_filter.rb uses this regex to match against the dashboard URL.
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/gitlab/metrics/dashboard/url.rb', line 58 def clusters_regex strong_memoize(:clusters_regex) do regex_for_project_metrics( %r{ #{DASH_PATTERN}? /clusters /(?<cluster_id>\d+) /? ( (/metrics) | ( /metrics_dashboard\.json ) )? }x ) end end |
.grafana_regex ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/gitlab/metrics/dashboard/url.rb', line 38 def grafana_regex strong_memoize(:grafana_regex) do regex_for_project_metrics( %r{ #{DASH_PATTERN}? /grafana /metrics_dashboard }x ) end end |
.metrics_regex ⇒ Object
Matches urls for a metrics dashboard. This regex needs to match the old metrics URL, the new metrics URL, and the dashboard URL (inline_metrics_redactor_filter.rb uses this regex to match against the dashboard URL.)
EX - Old URL: /
25 26 27 28 29 30 31 32 33 |
# File 'lib/gitlab/metrics/dashboard/url.rb', line 25 def metrics_regex strong_memoize(:metrics_regex) do regex_for_project_metrics( %r{ ( #{environment_metrics_regex} ) | ( #{non_environment_metrics_regex} ) }x ) end end |
.parse_query(url) ⇒ Object
Parses query params out from full url string into hash.
94 95 96 97 98 99 100 |
# File 'lib/gitlab/metrics/dashboard/url.rb', line 94 def parse_query(url) query_string = URI.parse(url).query.to_s CGI.parse(query_string) .transform_values { |value| value.first } .symbolize_keys end |