Skip to content

Commit

Permalink
support id lookup on slo timeseries dashboard widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
smo921 committed May 13, 2024
1 parent 45a27a8 commit 68576db
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/kennel/models/dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,20 @@ 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"
if requests = definition[:requests]
requests.map do |request|
if queries = request[:queries]
queries.map do |query|
if query[:data_source] == 'slo'
if id = query[:slo_id]
query[:slo_id] = resolve(id, :slo, id_map, **args) || id
end
end
end
end
end
end
end
end
end
Expand Down
21 changes: 21 additions & 0 deletions test/kennel/models/dashboard_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,27 @@ 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: 'slo', slo_id: nil }]
}
end

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

it "resolves the slo widget with full id" do
definition[:requests].last[:queries].first[: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].first[:slo_id].must_equal "123"
end
end
end

describe "#diff" do
Expand Down

0 comments on commit 68576db

Please sign in to comment.