Class: Kennel::Models::Slo

Inherits:
Record show all
Includes:
TagsValidation
Defined in:
lib/kennel/models/slo.rb

Constant Summary collapse

READONLY_ATTRIBUTES =
[
  *superclass::READONLY_ATTRIBUTES,
  :type_id, :monitor_tags, :target_threshold, :timeframe, :warning_threshold
].freeze
TRACKING_FIELD =
:description
DEFAULTS =
{
  description: nil,
  query: nil,
  groups: nil,
  monitor_ids: [],
  thresholds: []
}.freeze

Constants inherited from Record

Record::ALLOWED_KENNEL_ID_CHARS, Record::ALLOWED_KENNEL_ID_FULL, Record::ALLOWED_KENNEL_ID_REGEX, Record::ALLOWED_KENNEL_ID_SEGMENT, Record::LOCK, Record::MARKER_TEXT, Record::TITLE_FIELDS, Record::TRACKING_FIELDS

Constants included from OptionalValidations

OptionalValidations::UNIGNORABLE, OptionalValidations::UNUSED_IGNORES

Constants inherited from Base

Base::SETTING_OVERRIDABLE_METHODS

Constants included from SettingsAsMethods

SettingsAsMethods::AS_PROCS, SettingsAsMethods::SETTING_OVERRIDABLE_METHODS

Instance Attribute Summary

Attributes inherited from Record

#as_json, #project

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Record

#add_tracking_id, api_resource_map, #build, #diff, #initialize, #invalid_update!, parse_any_url, parse_tracking_id, #remove_tracking_id, remove_tracking_id, #safe_tracking_id, #tracking_id, #validate_update!

Methods included from OptionalValidations

filter_validation_errors, included, #initialize, #invalid!, valid?

Methods inherited from Base

#kennel_id, #name, #to_json

Methods included from SubclassTracking

#recursive_subclasses, #subclasses

Methods included from SettingsAsMethods

included, #initialize, #raise_with_location

Constructor Details

This class inherits a constructor from Kennel::Models::Record

Class Method Details

.api_resourceObject



54
55
56
# File 'lib/kennel/models/slo.rb', line 54

def self.api_resource
  "slo"
end

.normalize(expected, actual) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/kennel/models/slo.rb', line 73

def self.normalize(expected, actual)
  super

  # remove readonly values
  actual[:thresholds]&.each do |threshold|
    threshold.delete(:warning_display)
    threshold.delete(:target_display)
  end

  # tags come in a semi-random order and order is never updated
  expected[:tags]&.sort!
  actual[:tags].sort!

  ignore_default(expected, actual, DEFAULTS)
end

.parse_url(url) ⇒ Object



62
63
64
# File 'lib/kennel/models/slo.rb', line 62

def self.parse_url(url)
  url[/[?&]slo_id=([a-z\d]{10,})/, 1] || url[/\/slo\/([a-z\d]{10,})\/edit(\?|$)/, 1]
end

.url(id) ⇒ Object



58
59
60
# File 'lib/kennel/models/slo.rb', line 58

def self.url(id)
  Utils.path_to_url "/slo?slo_id=#{id}"
end

Instance Method Details

#build_jsonObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/kennel/models/slo.rb', line 31

def build_json
  data = super.merge(
    name: "#{name}#{LOCK}",
    description: description,
    thresholds: thresholds,
    monitor_ids: monitor_ids,
    tags: tags,
    type: type
  )

  if type == "time_slice"
    data[:sli_specification] = sli_specification
  elsif (v = query)
    data[:query] = v
  end

  if (v = groups)
    data[:groups] = v
  end

  data
end

#resolve_linked_tracking_ids!(id_map, **args) ⇒ Object



66
67
68
69
70
71
# File 'lib/kennel/models/slo.rb', line 66

def resolve_linked_tracking_ids!(id_map, **args)
  return unless (ids = as_json[:monitor_ids]) # ignore_default can remove it
  as_json[:monitor_ids] = ids.map do |id|
    resolve(id, :monitor, id_map, **args) || id
  end
end