Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for time_slice slo #313

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/kennel/models/slo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Slo < Record
thresholds: []
}.freeze

settings :type, :description, :thresholds, :query, :tags, :monitor_ids, :monitor_tags, :name, :groups
settings :type, :description, :thresholds, :query, :tags, :monitor_ids, :monitor_tags, :name, :groups, :sliSpecification
kaarolch marked this conversation as resolved.
Show resolved Hide resolved

defaults(
tags: -> { @project.tags },
Expand All @@ -35,7 +35,9 @@ def build_json
type: type
)

if v = query
if type == 'time_slice' && v = sliSpecification
data[:sliSpecification] = v
kaarolch marked this conversation as resolved.
Show resolved Hide resolved
elsif v = query
data[:query] = v
end

Expand Down
37 changes: 34 additions & 3 deletions test/kennel/models/slo_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@ class TestSlo < Kennel::Models::Slo

def slo(options = {})
Kennel::Models::Slo.new(
# Determine the type from options or default to "metric"
kaarolch marked this conversation as resolved.
Show resolved Hide resolved
type = options[:type] || "metric"
options.delete(:project) || project,
{
type: -> { "metric" },
slo_options ={
type: -> { type },
name: -> { "Foo" },
kennel_id: -> { "m1" }
}.merge(options)
}
# Conditionally include sliSpecification if type is "time_slice"
kaarolch marked this conversation as resolved.
Show resolved Hide resolved
slo_options[:sliSpecification] = -> { options[:sliSpecification] } if type == "time_slice"
kaarolch marked this conversation as resolved.
Show resolved Hide resolved
Kennel::Models::Slo.new(project, slo_options.merge(options))
)
end

Expand Down Expand Up @@ -59,6 +64,32 @@ def slo(options = {})
)
end

it "includes sliSpecification for time slices" do
sli_spec = {
timeSlice: {
query: {
formula: {
formulaExpression: "query1"
},
queries: [{
metricQuery: {
name: "query1",
query: "ewma_7(avg:system_cpu{} by {env})"
}
}]
},
comparator: "<=",
threshold: 40
}
}

expected_basic_json[:sliSpecification] = sli_spec
assert_json_equal(
slo(type: "time_slice", sliSpecification: sli_spec).build_json,
expected_basic_json
)
end

it "sets id when updating by id" do
expected_basic_json[:id] = 123
assert_json_equal(
Expand Down