Commit 67a80b1b authored by allison.browne's avatar allison.browne

DRY create_element by moving to parent class

Move create_element to the parent class and expect the child
class to only define metric_dashboard. This is to ensure consistency
across classes
parent 21f616af
......@@ -6,17 +6,6 @@ module Banzai
# reference to an alert dashboard.
class InlineAlertMetricsFilter < ::Banzai::Filter::InlineEmbedsFilter
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
# simple checks is enough to boost performance without
# the cost of doing a full regex match.
......
......@@ -3,14 +3,6 @@
module Banzai
module Filter
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)
url = node['href']
......
......@@ -22,11 +22,18 @@ module Banzai
doc
end
# Implement in child class.
# Child class must provide the metrics_dashboard_url.
#
# 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)
doc.document.create_element(
'div',
class: 'js-render-metrics',
'data-dashboard-url': metrics_dashboard_url(params)
)
end
# Implement in child class unless overriding #embed_params
......@@ -71,6 +78,13 @@ module Banzai
Gitlab::Metrics::Dashboard::Url.parse_query(url)
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
......@@ -10,11 +10,7 @@ module Banzai
def create_element(params)
begin_loading_dashboard(params[:url])
doc.document.create_element(
'div',
class: 'js-render-metrics',
'data-dashboard-url': metrics_dashboard_url(params)
)
super
end
def embed_params(node)
......
......@@ -5,16 +5,6 @@ module Banzai
# HTML filter that inserts a placeholder element for each
# reference to a metrics dashboard.
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
# simple checks is enough to boost performance without
# 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