Class: Gitlab::AlertManagement::Payload::Prometheus

Inherits:
Base
  • Object
show all
Extended by:
Utils::Override
Defined in:
lib/gitlab/alert_management/payload/prometheus.rb

Overview

Attribute mapping for alerts via prometheus alerting integration.

Direct Known Subclasses

ManagedPrometheus

Constant Summary collapse

METRIC_TIME_WINDOW =
30.minutes
ADDITIONAL_SEVERITY_MAPPING =
{
  's1' => :critical,
  's2' => :high,
  's3' => :medium,
  's4' => :low,
  's5' => :info,
  'p1' => :critical,
  'p2' => :high,
  'p3' => :medium,
  'p4' => :low,
  'p5' => :info,
  'debug' => :info,
  'information' => :info,
  'notice' => :info,
  'warn' => :low,
  'warning' => :low,
  'minor' => :low,
  'error' => :medium,
  'major' => :high,
  'emergency' => :critical,
  'fatal' => :critical,
  'alert' => :medium,
  'page' => :high
}.freeze

Constants inherited from Base

Base::SEVERITY_MAPPING, Base::UNMAPPED_SEVERITY

Instance Attribute Summary

Attributes inherited from Base

#integration, #payload, #project

Instance Method Summary collapse

Methods included from Utils::Override

extended, extensions, included, method_added, override, prepended, queue_verification, verify!

Methods inherited from Base

#alert_params, attribute, #environment, #gitlab_fingerprint, #resolved?, #severity

Methods included from Routing

add_helpers, includes_helpers, redirect_legacy_paths, url_helpers

Methods included from Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Instance Method Details

#full_queryObject

Parses `g0.expr` from `generatorURL`.

Example: localhost:9090/graph?g0.expr=vector%281%29&g0.tab=1


72
73
74
75
76
77
78
79
# File 'lib/gitlab/alert_management/payload/prometheus.rb', line 72

def full_query
  return unless generator_url

  uri = URI(generator_url)

  Rack::Utils.parse_query(uri.query).fetch('g0.expr')
rescue URI::InvalidURIError, KeyError
end

#has_required_attributes?Boolean

Returns:

  • (Boolean)

93
94
95
# File 'lib/gitlab/alert_management/payload/prometheus.rb', line 93

def has_required_attributes?
  project && title && starts_at_raw
end

#metrics_dashboard_urlObject


81
82
83
84
85
86
87
88
89
90
91
# File 'lib/gitlab/alert_management/payload/prometheus.rb', line 81

def metrics_dashboard_url
  return unless environment && full_query && title

  metrics_dashboard_project_environment_url(
    project,
    environment,
    embed_json: dashboard_json,
    embedded: true,
    **alert_embed_window_params
  )
end

#monitoring_toolObject


65
66
67
# File 'lib/gitlab/alert_management/payload/prometheus.rb', line 65

def monitoring_tool
  Gitlab::AlertManagement::Payload::MONITORING_TOOLS[:prometheus]
end