Module: RoundhouseUi::ObservabilityHelper

Defined in:
app/helpers/roundhouse_ui/observability_helper.rb

Overview

Links out to whatever APM the host configured. Four entry points — job or error, by historical call-site name — and exactly one appearance. They were four hand-rolled copies once, and only some got updated: two still emitted a literal ↗ after the rest moved to SVG. Later the split survived as two different shapes, a text link and a bordered box, which is not "one appearance" however the helper described itself.

Instance Method Summary collapse

Instance Method Details

#error_trace_icon(klass:, error: nil) ⇒ Object



21
22
23
# File 'app/helpers/roundhouse_ui/observability_helper.rb', line 21

def error_trace_icon(klass:, error: nil)
  trace_affordance(error_trace_url(klass: klass, error: error), as: :control, compact: true)
end


17
18
19
# File 'app/helpers/roundhouse_ui/observability_helper.rb', line 17

def error_trace_link(klass:, error: nil)
  trace_affordance(error_trace_url(klass: klass, error: error), as: :mark)
end

#trace_glyph(adapter) ⇒ Object

An adapter's own mark, when it supplies one. Three shapes are accepted, in descending order of how much we trust them:

:name      → one of Roundhouse's shipped icons
"<svg …>"  → the adapter's markup, rendered as-is
nil        → the default trace glyph

The markup case is not escaped, because escaping renders the tags as text and the feature does not work at all. That is the same trust level as the adapter object itself, which can already run arbitrary code. Anything that is neither markup nor a known name falls back rather than printing stray text into a table.



56
57
58
59
60
61
62
# File 'app/helpers/roundhouse_ui/observability_helper.rb', line 56

def trace_glyph(adapter)
  supplied = adapter.respond_to?(:icon) ? adapter.icon : nil
  return icon(:trace_out) if supplied.blank?
  return icon(supplied) if supplied.is_a?(Symbol)

  supplied.to_s.strip.start_with?("<") ? supplied.to_s.html_safe : icon(:trace_out)
end

#trace_icon(klass:, jid:, queue: nil) ⇒ Object



13
14
15
# File 'app/helpers/roundhouse_ui/observability_helper.rb', line 13

def trace_icon(klass:, jid:, queue: nil)
  trace_affordance(job_trace_url(klass: klass, jid: jid, queue: queue), as: :control)
end

#trace_legend(rows) ⇒ Object

Says once, above a table, where every row's trace glyph goes. Takes the rows it is describing, because a legend above an empty table explains a control that is not on the page — which is exactly what "Nothing scheduled" under "Traces open in Datadog" looked like.

Returns nil unless the adapter has a mark of its own, too: a plain adapter already labels every row, so there would be nothing to hoist.



32
33
34
35
36
37
38
39
40
41
42
# File 'app/helpers/roundhouse_ui/observability_helper.rb', line 32

def trace_legend(rows)
  return nil if rows.blank?

  adapter = RoundhouseUi.observability
  return nil unless wordmark?(adapter)
  return nil if adapter.job_url(klass: "Probe", jid: "probe").blank?

  (:div, class: "rh-trace-legend") do
    safe_join([ (:span, "Traces open in"), trace_glyph(adapter) ], " ")
  end
end


9
10
11
# File 'app/helpers/roundhouse_ui/observability_helper.rb', line 9

def trace_link(klass:, jid:, queue: nil)
  trace_affordance(job_trace_url(klass: klass, jid: jid, queue: queue), as: :mark)
end