Skip to content

Commit

Permalink
Merge pull request #312 from smo921/smo921/slo_timeseries_id_lookup
Browse files Browse the repository at this point in the history
support id lookup on slo timeseries dashboard widgets
  • Loading branch information
grosser committed May 14, 2024
2 parents 45a27a8 + ea00dd3 commit 19c470b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ so they can be created in a single update and can be re-created if any of them i
|Dashboard|uptime|`monitor: {id: "foo:bar"}`|
|Dashboard|alert_graph|`alert_id: "foo:bar"`|
|Dashboard|slo|`slo_id: "foo:bar"`|
|Dashboard|timeseries|`queries: [{ data_source: "slo", slo_id: "foo:bar" }]`|
|Monitor|composite|`query: -> { "%{foo:bar} && %{foo:baz}" }`|
|Monitor|slo alert|`query: -> { "error_budget(\"%{foo:bar}\").over(\"7d\") > 123.0" }`|
|Slo|monitor|`monitor_ids: -> ["foo:bar"]`|
Expand Down
8 changes: 8 additions & 0 deletions lib/kennel/models/dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,14 @@ def resolve_linked_tracking_ids!(id_map, **args)
if id = definition[:slo_id]
definition[:slo_id] = resolve(id, :slo, id_map, **args) || id
end
when "timeseries"
definition[:requests]&.each do |request|
request[:queries]&.each do |query|
if query[:data_source] == "slo" && (slo_id = query[:slo_id])
query[:slo_id] = resolve(slo_id, :slo, id_map, **args) || slo_id
end
end
end
end
end
end
Expand Down
1 change: 1 addition & 0 deletions template/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ so they can be created in a single update and can be re-created if any of them i
|Dashboard|uptime|`monitor: {id: "foo:bar"}`|
|Dashboard|alert_graph|`alert_id: "foo:bar"`|
|Dashboard|slo|`slo_id: "foo:bar"`|
|Dashboard|timeseries|`query: -> { data_source: "slo", slo_id: "foo:bar" }`|
|Monitor|composite|`query: -> { "%{foo:bar} && %{foo:baz}" }`|
|Monitor|slo alert|`query: -> { "error_budget(\"%{foo:bar}\").over(\"7d\") > 123.0" }`|
|Slo|monitor|`monitor_ids: -> ["foo:bar"]`|
Expand Down
33 changes: 33 additions & 0 deletions test/kennel/models/dashboard_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ def resolve(force: false)
resolve.must_be_nil
end

it "ignores unknown widget types" do
definition[:type] = "unknown"
resolve.keys.must_equal [:requests, :type, :title]
end

describe "uptime" do
before { definition[:type] = "uptime" }

Expand Down Expand Up @@ -232,6 +237,34 @@ def resolve(force: false)
resolved[:widgets][0][:definition][:slo_id].must_equal "123"
end
end

describe "timeseries" do
before do
definition[:requests] << {
queries: [
{ data_source: "metrics", query: "avg:system.cpu.user{*}" },
{ data_source: "slo", slo_id: nil }
]
}
end

it "ignores missing ids" do
assert_nil resolve.dig(:requests, 0, :queries, 0, :slo_id)
end

it "does not modify regular ids" do
definition[:requests].last[:queries].last[:slo_id] = "abcdef1234567"
resolve[:requests].last[:queries].last[:slo_id].must_equal "abcdef1234567"
end

it "resolves the slo widget with full id" do
definition[:requests].last[:queries].last[:slo_id] = "#{project.kennel_id}:b"
id_map.set("slo", "a:c", "1")
id_map.set("slo", "#{project.kennel_id}:b", "123")
resolved = resolve
resolved[:requests].last[:queries].last[:slo_id].must_equal "123"
end
end
end

describe "#diff" do
Expand Down

0 comments on commit 19c470b

Please sign in to comment.