Class: Kennel::Models::Dashboard
- Includes:
- OptionalValidations, TemplateVariables
- Defined in:
- lib/kennel/models/dashboard.rb
Constant Summary collapse
- API_LIST_INCOMPLETE =
true
- DASHBOARD_DEFAULTS =
{ template_variables: [] }.freeze
- READONLY_ATTRIBUTES =
superclass::READONLY_ATTRIBUTES + [ :author_handle, :author_name, :modified_at, :url, :is_read_only, :notify_list ]
- REQUEST_DEFAULTS =
{ style: { line_width: "normal", palette: "dog_classic", line_type: "solid" } }.freeze
- TIMESERIES_DEFAULTS =
{ show_legend: false, legend_size: "0" }.freeze
- SUPPORTED_DEFINITION_OPTIONS =
[:events, :markers, :precision].freeze
Constants inherited from Record
Constants inherited from Base
Base::SETTING_OVERRIDABLE_METHODS
Constants included from SettingsAsMethods
SettingsAsMethods::SETTING_OVERRIDABLE_METHODS
Instance Attribute Summary
Attributes inherited from Record
Class Method Summary collapse
Instance Method Summary collapse
Methods included from OptionalValidations
Methods included from TemplateVariables
Methods inherited from Record
#diff, #initialize, #tracking_id
Methods inherited from Base
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_resource ⇒ Object
29 30 31 |
# File 'lib/kennel/models/dashboard.rb', line 29 def api_resource "dashboard" end |
.normalize(expected, actual) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/kennel/models/dashboard.rb', line 33 def normalize(expected, actual) super (expected, actual).each do |pair| # datadog always adds 2 to slo widget height # need to check fir layout since some monitors have height/width in their definition pair[1].each do || if .dig(:definition, :type) == "slo" && .dig(:layout, :height) [:layout][:height] -= 2 end end # conditional_formats ordering is randomly changed by datadog, compare a stable ordering pair.each do || .each do || if formats = .dig(:definition, :conditional_formats) [:definition][:conditional_formats] = formats.sort_by(&:hash) end end end ignore_definition_defaults_for_type pair, "timeseries", TIMESERIES_DEFAULTS ignore_request_defaults(*pair) # ids are kinda random so we always discard them pair.each { || .each { |w| w.delete(:id) } } end end |
Instance Method Details
#as_json ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/kennel/models/dashboard.rb', line 103 def as_json return @json if @json = render_definitions + @json = { layout_type: layout_type, title: "#{title}#{LOCK}", description: description, template_variables: render_template_variables, widgets: } @json[:id] = id if id validate_json(@json) if validate @json end |
#resolve_linked_tracking_ids(id_map) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/kennel/models/dashboard.rb', line 127 def resolve_linked_tracking_ids(id_map) as_json[:widgets].each do || next unless definition = [:definition] case definition[:type] when "uptime" if ids = definition[:monitor_ids] definition[:monitor_ids] = ids.map do |id| tracking_id?(id) ? resolve_link(id, id_map) : id end end when "alert_graph" if (id = definition[:alert_id]) && tracking_id?(id) definition[:alert_id] = resolve_link(id, id_map).to_s end when "slo" if (id = definition[:slo_id]) && tracking_id?(id) definition[:slo_id] = resolve_link(id, id_map).to_s end end end end |
#url(id) ⇒ Object
123 124 125 |
# File 'lib/kennel/models/dashboard.rb', line 123 def url(id) Utils.path_to_url "/dashboard/#{id}" end |