Commit 3cc58de4 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch '207439-follow-up-from-add-support-for-alert-based-metric-embeds-in-gfm' into 'master'

Move create_element to parent class for metric embeds

See merge request gitlab-org/gitlab!25938
parents 499151cd 67a80b1b
...@@ -6,17 +6,6 @@ module Banzai ...@@ -6,17 +6,6 @@ module Banzai
# reference to an alert dashboard. # reference to an alert dashboard.
class InlineAlertMetricsFilter < ::Banzai::Filter::InlineEmbedsFilter class InlineAlertMetricsFilter < ::Banzai::Filter::InlineEmbedsFilter
include ::Gitlab::Routing include ::Gitlab::Routing
# Placeholder element for the frontend to use as an
# injection point for charts.
def create_element(params)
doc.document.create_element(
'div',
class: 'js-render-metrics',
'data-dashboard-url': metrics_dashboard_url(params)
)
end
# Search params for selecting alert metrics links. A few # Search params for selecting alert metrics links. A few
# simple checks is enough to boost performance without # simple checks is enough to boost performance without
# the cost of doing a full regex match. # the cost of doing a full regex match.
......
...@@ -3,14 +3,6 @@ ...@@ -3,14 +3,6 @@
module Banzai module Banzai
module Filter module Filter
class InlineClusterMetricsFilter < ::Banzai::Filter::InlineEmbedsFilter class InlineClusterMetricsFilter < ::Banzai::Filter::InlineEmbedsFilter
def create_element(params)
doc.document.create_element(
'div',
class: 'js-render-metrics',
'data-dashboard-url': metrics_dashboard_url(params)
)
end
def embed_params(node) def embed_params(node)
url = node['href'] url = node['href']
......
...@@ -22,11 +22,18 @@ module Banzai ...@@ -22,11 +22,18 @@ module Banzai
doc doc
end end
# Implement in child class. # Child class must provide the metrics_dashboard_url.
# #
# Return a Nokogiri::XML::Element to embed in the # Return a Nokogiri::XML::Element to embed in the
# markdown. # markdown which provides a url to the metric_dashboard endpoint where
# data can be requested through a prometheus proxy. InlineMetricsRedactorFilter
# is responsible for premissions to see this div (and relies on the class 'js-render-metrics' ).
def create_element(params) def create_element(params)
doc.document.create_element(
'div',
class: 'js-render-metrics',
'data-dashboard-url': metrics_dashboard_url(params)
)
end end
# Implement in child class unless overriding #embed_params # Implement in child class unless overriding #embed_params
...@@ -71,6 +78,13 @@ module Banzai ...@@ -71,6 +78,13 @@ module Banzai
Gitlab::Metrics::Dashboard::Url.parse_query(url) Gitlab::Metrics::Dashboard::Url.parse_query(url)
end end
end end
# Implement in child class.
#
# Provides a full url to request the relevant panels of metric data.
def metrics_dashboard_url
raise NotImplementedError
end
end end
end end
end end
...@@ -10,11 +10,7 @@ module Banzai ...@@ -10,11 +10,7 @@ module Banzai
def create_element(params) def create_element(params)
begin_loading_dashboard(params[:url]) begin_loading_dashboard(params[:url])
doc.document.create_element( super
'div',
class: 'js-render-metrics',
'data-dashboard-url': metrics_dashboard_url(params)
)
end end
def embed_params(node) def embed_params(node)
......
...@@ -5,16 +5,6 @@ module Banzai ...@@ -5,16 +5,6 @@ module Banzai
# HTML filter that inserts a placeholder element for each # HTML filter that inserts a placeholder element for each
# reference to a metrics dashboard. # reference to a metrics dashboard.
class InlineMetricsFilter < Banzai::Filter::InlineEmbedsFilter class InlineMetricsFilter < Banzai::Filter::InlineEmbedsFilter
# Placeholder element for the frontend to use as an
# injection point for charts.
def create_element(params)
doc.document.create_element(
'div',
class: 'js-render-metrics',
'data-dashboard-url': metrics_dashboard_url(params)
)
end
# Search params for selecting metrics links. A few # Search params for selecting metrics links. A few
# simple checks is enough to boost performance without # simple checks is enough to boost performance without
# the cost of doing a full regex match. # the cost of doing a full regex match.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment