grosser / kennel

Datadog monitors/dashboards/slos as code, avoid chaotic management via UI

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't resolve ID of not-yet-adopted item

zdrve opened this issue · comments

Example:

  • we have an SLO, which exists in datadog, but not in kennel
  • we prepare a PR to import that SLO into kennel
  • rake kennel:update_datadog PROJECT=my_project works, but doesn't add the tracking_id

This is all fine so far. But now comes the problem:

  • on the same PR, we add a widget to some dashboard, with slo_id: "my_project:my_new_slo"
  • rake kennel:update_datadog PROJECT=my_project fails, saying it can't resolve my_project:my_new_slo.

Very hacky fix:

diff --git a/lib/kennel/syncer.rb b/lib/kennel/syncer.rb
index fec037e..82eb87c 100644
--- a/lib/kennel/syncer.rb
+++ b/lib/kennel/syncer.rb
@@ -105,7 +105,15 @@ module Kennel
           # Refuse to "adopt" existing items into kennel while running with a filter (i.e. on a branch).
           # Without this, we'd adopt an item, then the next CI run would delete it
           # (instead of "unadopting" it).
-          e.add_tracking_id unless filter.filtering? && a.fetch(:tracking_id).nil?
+          if filter.filtering? && a.fetch(:tracking_id).nil?
+            # Eww!
+            a[:tracking_id] = e.tracking_id
+            resolver.add_actual([a])
+            a[:tracking_id] = nil
+          else
+            e.add_tracking_id
+          end
+
           id = a.fetch(:id)
           diff = e.diff(a)
           a[:id] = id

yeah good solution for an ugly edge-case :)