Class: Kennel::Models::Slo
Constant Summary
collapse
- READONLY_ATTRIBUTES =
superclass::READONLY_ATTRIBUTES + [:type_id, :monitor_tags]
- DEFAULTS =
{
description: nil,
query: nil,
groups: nil,
monitor_ids: [],
thresholds: []
}.freeze
Constants inherited
from Record
Record::LOCK
Constants inherited
from Base
Base::SETTING_OVERRIDABLE_METHODS
SettingsAsMethods::SETTING_OVERRIDABLE_METHODS
Instance Attribute Summary
Attributes inherited from Record
#project
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Record
api_resource_map, #diff, parse_any_url, #tracking_id
Methods inherited from Base
#kennel_id, #name, #to_json
#recursive_subclasses, #subclasses
included, #raise_with_location
Constructor Details
#initialize ⇒ Slo
26
27
28
29
30
31
|
# File 'lib/kennel/models/slo.rb', line 26
def initialize(*)
super
if thresholds.any? { |t| t[:warning] && t[:warning].to_f <= t[:critical].to_f }
raise ValidationError, "Threshold warning must be greater-than critical value"
end
end
|
Class Method Details
.api_resource ⇒ Object
57
58
59
|
# File 'lib/kennel/models/slo.rb', line 57
def self.api_resource
"slo"
end
|
.normalize(expected, actual) ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/kennel/models/slo.rb', line 76
def self.normalize(expected, actual)
super
actual[:thresholds]&.each do |threshold|
threshold.delete(:warning_display)
threshold.delete(:target_display)
end
expected[:tags]&.sort!
actual[:tags].sort!
ignore_default(expected, actual, DEFAULTS)
end
|
.parse_url(url) ⇒ Object
65
66
67
|
# File 'lib/kennel/models/slo.rb', line 65
def self.parse_url(url)
url[/\/slo\?.*slo_id=([a-z\d]+)/, 1]
end
|
.url(id) ⇒ Object
61
62
63
|
# File 'lib/kennel/models/slo.rb', line 61
def self.url(id)
Utils.path_to_url "/slo?slo_id=#{id}"
end
|
Instance Method Details
#as_json ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/kennel/models/slo.rb', line 33
def as_json
return @as_json if @as_json
data = {
name: "#{name}#{LOCK}",
description: description,
thresholds: thresholds,
monitor_ids: monitor_ids,
tags: tags.uniq,
type: type
}
if v = query
data[:query] = v
end
if v = id
data[:id] = v
end
if v = groups
data[:groups] = v
end
@as_json = data
end
|
#resolve_linked_tracking_ids!(id_map, **args) ⇒ Object
69
70
71
72
73
74
|
# File 'lib/kennel/models/slo.rb', line 69
def resolve_linked_tracking_ids!(id_map, **args)
return unless as_json[:monitor_ids]
as_json[:monitor_ids] = as_json[:monitor_ids].map do |id|
id.is_a?(String) ? (resolve_link(id, :monitor, id_map, **args) || id) : id
end
end
|