Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
grosser committed May 25, 2024
1 parent 3a00b85 commit 2980ef5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
13 changes: 8 additions & 5 deletions lib/kennel/importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@

module Kennel
class Importer
# title will have the lock symbol we need to remove when re-importing
TITLES = [:name, :title].freeze
SORT_ORDER = [*TITLES, :id, :kennel_id, :type, :tags, :query, :sli_specification, *Models::Record.subclasses.map { |k| k::TRACKING_FIELDS }, :template_variables].freeze

# bring important fields to the top
SORT_ORDER = [
*TITLES, :id, :kennel_id, :type, :tags, :query, :sli_specification,
*Models::Record.subclasses.flat_map { |k| k::TRACKING_FIELDS },
:template_variables
].freeze

def initialize(api)
@api = api
Expand All @@ -19,15 +26,11 @@ def import(resource, id)
raise(ArgumentError, "#{resource} is not supported")

data = @api.show(model.api_resource, id)
# get sli specification before normalization.
sli_specification = data[:sli_specification] || data.dig(:sli_specification, :time_slice)

id = data.fetch(:id) # keep native value
model.normalize({}, data) # removes id
data[:id] = id

data[:sli_specification] = sli_specification if sli_specification

title_field = TITLES.detect { |f| data[f] }
title = data.fetch(title_field)
title.tr!(Kennel::Models::Record::LOCK, "") # avoid double lock icon
Expand Down
9 changes: 6 additions & 3 deletions lib/kennel/models/slo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ module Models
class Slo < Record
include TagsValidation

READONLY_ATTRIBUTES = superclass::READONLY_ATTRIBUTES + [:type_id, :monitor_tags, :target_threshold, :timeframe, :warning_threshold]
READONLY_ATTRIBUTES = [
*superclass::READONLY_ATTRIBUTES,
:type_id, :monitor_tags, :target_threshold, :timeframe, :warning_threshold
].freeze
TRACKING_FIELD = :description
DEFAULTS = {
description: nil,
Expand Down Expand Up @@ -35,8 +38,8 @@ def build_json
type: type
)

if type == 'time_slice'
data[:sliSpecification] = :sli_specification
if type == "time_slice"
data[:sli_specification] = sli_specification
elsif v = query
data[:query] = v
end
Expand Down

0 comments on commit 2980ef5

Please sign in to comment.