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 =
Base::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
- SUPPORTED_DEFINITION_OPTIONS =
[:events, :markers, :precision].freeze
Constants inherited from Base
Base::LOCK, Base::OVERRIDABLE_METHODS
Instance Attribute Summary collapse
-
#project ⇒ Object
readonly
Returns the value of attribute project.
Class Method Summary collapse
Instance Method Summary collapse
- #as_json ⇒ Object
-
#initialize(project, *args) ⇒ Dashboard
constructor
A new instance of Dashboard.
- #resolve_linked_tracking_ids(id_map) ⇒ Object
- #url(id) ⇒ Object
Methods included from OptionalValidations
Methods included from TemplateVariables
Methods inherited from Base
defaults, #diff, inherited, #kennel_id, #name, settings, #to_json, #tracking_id, validate_setting_exists
Methods included from SubclassTracking
#recursive_subclasses, #subclasses
Constructor Details
#initialize(project, *args) ⇒ Dashboard
Returns a new instance of Dashboard.
69 70 71 72 |
# File 'lib/kennel/models/dashboard.rb', line 69 def initialize(project, *args) @project = project super(*args) end |
Instance Attribute Details
#project ⇒ Object (readonly)
Returns the value of attribute project.
67 68 69 |
# File 'lib/kennel/models/dashboard.rb', line 67 def project @project end |
Class Method Details
.api_resource ⇒ Object
28 29 30 |
# File 'lib/kennel/models/dashboard.rb', line 28 def api_resource "dashboard" end |
.normalize(expected, actual) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/kennel/models/dashboard.rb', line 32 def normalize(expected, actual) super ignore_default expected, actual, DASHBOARD_DEFAULTS base_pairs(expected, actual).each do |pair| # conditional_formats ordering is randomly changed by datadog, compare a stable ordering pair.each do |b| b[:widgets]&.each do |w| if formats = w.dig(:definition, :conditional_formats) w[:definition][:conditional_formats] = formats.sort_by { |h| h[:value].to_f } end end end ignore_request_defaults(*pair, :widgets, :definition) pair.each { |dash| dash[:widgets]&.each { |w| w.delete(:id) } } end end |
Instance Method Details
#as_json ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/kennel/models/dashboard.rb', line 74 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
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/kennel/models/dashboard.rb', line 98 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 { |id| resolve_link(id, id_map) } end when "alert_graph" if id = definition[:alert_id] definition[:alert_id] = resolve_link(id, id_map).to_s end end end end |
#url(id) ⇒ Object
94 95 96 |
# File 'lib/kennel/models/dashboard.rb', line 94 def url(id) Utils.path_to_url "/dashboard/#{id}" end |