Class: AlertManagement::Alert
- Inherits:
-
ApplicationRecord
show all
- Includes:
- AtomicInternalId, Gitlab::SQL::Pattern, Gitlab::Utils::StrongMemoize, IidRoutes, IncidentManagement::Escalatable, Mentionable, Noteable, Presentable, Referable, ShaAttribute, Sortable
- Defined in:
- app/models/alert_management/alert.rb
Constant Summary
collapse
- TITLE_MAX_LENGTH =
200
- DESCRIPTION_MAX_LENGTH =
1_000
- SERVICE_MAX_LENGTH =
100
- TOOL_MAX_LENGTH =
100
- HOSTS_MAX_LENGTH =
255
IncidentManagement::Escalatable::OPEN_STATUSES, IncidentManagement::Escalatable::STATUSES, IncidentManagement::Escalatable::STATUS_DESCRIPTIONS
Gitlab::SQL::Pattern::MIN_CHARS_FOR_PARTIAL_MATCHING, Gitlab::SQL::Pattern::REGEX_QUOTED_TERM
Constants included
from Noteable
Noteable::MAX_NOTES_LIMIT
AtomicInternalId::MissingValueError
ApplicationRecord::MAX_PLUCK
ResetOnUnionError::MAX_RESET_PERIOD
Instance Attribute Summary
Attributes included from Noteable
#system_note_timestamp
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Referable
#referable_inspect, #reference_link_text, #to_reference_base
#present
split_query_to_search_terms
#all_references, #create_cross_references!, #create_new_cross_references!, #directly_addressed_users, #extractors, #gfm_reference, #local_reference, #matches_cross_reference_regex?, #mentioned_users, #referenced_group_users, #referenced_groups, #referenced_mentionables, #referenced_project_users, #referenced_projects, #referenced_users, #user_mention_class, #user_mention_identifier
Methods included from Noteable
#after_note_created, #after_note_destroyed, #base_class_name, #broadcast_notes_changed, #capped_notes_count, #commenters, #creatable_note_email_address, #discussion_ids_relation, #discussion_notes, #discussion_root_note_ids, #discussions, #discussions_can_be_resolved_by?, #discussions_rendered_on_frontend?, #discussions_resolvable?, #discussions_resolved?, #discussions_to_be_resolved, #grouped_diff_discussions, #has_any_diff_note_positions?, #human_class_name, #lockable?, #noteable_target_type_name, #preloads_discussion_diff_highlighting?, #real_time_notes_enabled?, #resolvable_discussions, #supports_creating_notes_by_email?, #supports_discussions?, #supports_replying_to_individual_notes?, #supports_resolvable_notes?, #supports_suggestion?
group_init, #internal_id_read_scope, #internal_id_scope_attrs, #internal_id_scope_usage, namespace_init, project_init, scope_attrs, scope_usage
Methods included from IidRoutes
#to_param
cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order
#serializable_hash
Class Method Details
.counts_by_status ⇒ Object
101
102
103
|
# File 'app/models/alert_management/alert.rb', line 101
def self.counts_by_status
group(:status).count.transform_keys { |k| status_name(k) }
end
|
.find_unresolved_alert(project, fingerprint) ⇒ Object
122
123
124
|
# File 'app/models/alert_management/alert.rb', line 122
def self.find_unresolved_alert(project, fingerprint)
for_fingerprint(project, fingerprint).not_resolved.take
end
|
.last_prometheus_alert_by_project_id ⇒ Object
126
127
128
129
|
# File 'app/models/alert_management/alert.rb', line 126
def self.last_prometheus_alert_by_project_id
ids = select(arel_table[:id].maximum).group(:project_id)
with_prometheus_alert.where(id: ids)
end
|
.link_reference_pattern ⇒ Object
142
143
144
|
# File 'app/models/alert_management/alert.rb', line 142
def self.link_reference_pattern
@link_reference_pattern ||= compose_link_reference_pattern('alert_management', %r{(?<alert>\d+)/details(\#)?})
end
|
.reference_pattern ⇒ Object
135
136
137
138
139
140
|
# File 'app/models/alert_management/alert.rb', line 135
def self.reference_pattern
@reference_pattern ||= %r{
(#{Project.reference_pattern})?
#{Regexp.escape(reference_prefix)}(?<alert>\d+)
}x
end
|
.reference_prefix ⇒ Object
131
132
133
|
# File 'app/models/alert_management/alert.rb', line 131
def self.reference_prefix
'^alert#'
end
|
.reference_valid?(reference) ⇒ Boolean
146
147
148
|
# File 'app/models/alert_management/alert.rb', line 146
def self.reference_valid?(reference)
reference.to_i > 0 && reference.to_i <= Gitlab::Database::MAX_INT_VALUE
end
|
.sort_by_attribute(method) ⇒ Object
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'app/models/alert_management/alert.rb', line 105
def self.sort_by_attribute(method)
case method.to_s
when 'started_at_asc' then order_start_time(:asc)
when 'started_at_desc' then order_start_time(:desc)
when 'ended_at_asc' then order_end_time(:asc)
when 'ended_at_desc' then order_end_time(:desc)
when 'event_count_asc' then order_event_count(:asc)
when 'event_count_desc' then order_event_count(:desc)
when 'severity_asc' then order_severity(:asc)
when 'severity_desc' then order_severity(:desc)
when 'status_asc' then order_status(:asc)
when 'status_desc' then order_status(:desc)
else
order_by(method)
end
end
|
Instance Method Details
#execute_integrations ⇒ Object
164
165
166
167
168
|
# File 'app/models/alert_management/alert.rb', line 164
def execute_integrations
return unless project.has_active_integrations?(:alert_hooks)
project.execute_integrations(hook_data, :alert_hooks)
end
|
#parsed_payload ⇒ Object
Representation of the alert’s payload. Avoid accessing #payload attribute directly.
172
173
174
175
176
|
# File 'app/models/alert_management/alert.rb', line 172
def parsed_payload
strong_memoize(:parsed_payload) do
Gitlab::AlertManagement::Payload.parse(project, payload, monitoring_tool: monitoring_tool)
end
end
|
#register_new_event! ⇒ Object
154
155
156
|
# File 'app/models/alert_management/alert.rb', line 154
def register_new_event!
increment!(:events)
end
|
#to_ability_name ⇒ Object
178
179
180
|
# File 'app/models/alert_management/alert.rb', line 178
def to_ability_name
'alert_management_alert'
end
|
#to_reference(from = nil, full: false) ⇒ Object
158
159
160
161
162
|
# File 'app/models/alert_management/alert.rb', line 158
def to_reference(from = nil, full: false)
reference = "#{self.class.reference_prefix}#{iid}"
"#{project.to_reference_base(from, full: full)}#{reference}"
end
|