Class: Banzai::Filter::InlineGrafanaMetricsFilter
- Inherits:
-
InlineEmbedsFilter
- Object
- HTML::Pipeline::Filter
- InlineEmbedsFilter
- Banzai::Filter::InlineGrafanaMetricsFilter
- Defined in:
- lib/banzai/filter/inline_grafana_metrics_filter.rb
Overview
HTML filter that inserts a placeholder element for each reference to a grafana dashboard.
Instance Method Summary collapse
-
#create_element(params) ⇒ Object
Placeholder element for the frontend to use as an injection point for charts.
-
#embed_params(node) ⇒ Hash<Symbol, String>
With keys :grafana_url, :start, and :end.
-
#xpath_search ⇒ Object
Selects any links with an href contains the configured grafana domain for the project.
Methods inherited from InlineEmbedsFilter
#call, #element_to_embed, #gitlab_domain, #link_pattern, #query_params
Instance Method Details
#create_element(params) ⇒ Object
Placeholder element for the frontend to use as an injection point for charts.
10 11 12 13 14 |
# File 'lib/banzai/filter/inline_grafana_metrics_filter.rb', line 10 def create_element(params) begin_loading_dashboard(params[:url]) super end |
#embed_params(node) ⇒ Hash<Symbol, String>
Returns with keys :grafana_url, :start, and :end.
17 18 19 20 21 22 23 24 |
# File 'lib/banzai/filter/inline_grafana_metrics_filter.rb', line 17 def (node) query_params = Gitlab::Metrics::Dashboard::Url.parse_query(node['href']) time_window = Grafana::TimeWindow.new(query_params[:from], query_params[:to]) url = url_with_window(node['href'], query_params, time_window.in_milliseconds) { grafana_url: url }.merge(time_window.formatted) end |
#xpath_search ⇒ Object
Selects any links with an href contains the configured grafana domain for the project
28 29 30 31 32 |
# File 'lib/banzai/filter/inline_grafana_metrics_filter.rb', line 28 def xpath_search return unless grafana_url.present? %(descendant-or-self::a[starts-with(@href, '#{grafana_url}')]) end |