From 00809062196b79ce354a5cdafaba1d6ed3f132f9 Mon Sep 17 00:00:00 2001 From: nik-kc <127428785+nik-kc@users.noreply.github.com> Date: Fri, 29 Mar 2024 19:52:17 -0500 Subject: [PATCH] Disabled DataDog queries for future dates. (#17) --- datadog/cmd/main/main.go | 6 ++++++ datadog/tests/datadog_test.go | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/datadog/cmd/main/main.go b/datadog/cmd/main/main.go index e1c7c68..95e7b6e 100644 --- a/datadog/cmd/main/main.go +++ b/datadog/cmd/main/main.go @@ -73,6 +73,12 @@ func (d *DatadogCostSource) GetCustomCosts(req *pb.CustomCostRequest) []*pb.Cust } for _, target := range targets { + // DataDog gets mad if we ask them to tell the future + if target.Start().After(time.Now().UTC()) { + log.Debugf("skipping future window %v", target) + continue + } + log.Debugf("fetching DD costs for window %v", target) result := d.getDDCostsForWindow(target, listPricing) results = append(results, result) diff --git a/datadog/tests/datadog_test.go b/datadog/tests/datadog_test.go index 9a0e9e6..5f3d9bf 100644 --- a/datadog/tests/datadog_test.go +++ b/datadog/tests/datadog_test.go @@ -70,6 +70,24 @@ func TestDDCostRetrievalListCost(t *testing.T) { } } +func TestFuturism(t *testing.T) { + // query for the future + windowStart := time.Now().UTC().Truncate(time.Hour).Add(time.Hour) + windowEnd := windowStart.Add(time.Hour) + + response := getResponse(t, windowStart, windowEnd, time.Hour) + + // when we query for data in the future, we expect to get back no data AND no errors + if len(response) > 0 { + t.Fatalf("got non-empty response") + } + for _, resp := range response { + if len(resp.Errors) > 0 { + t.Fatalf("got errors in response: %v", resp.Errors) + } + } +} + func TestDDCostRetrievalBilledCost(t *testing.T) { // query for qty 2 of 1 hour windows windowStart := time.Date(2024, 3, 16, 0, 0, 0, 0, time.UTC)