From 42d14e333041091fe5d5ace336aac4eed9e3bbeb Mon Sep 17 00:00:00 2001 From: Alex Meijer Date: Wed, 9 Oct 2024 10:09:43 -0400 Subject: [PATCH] Atm/restructure testharness (#37) * use deploy key Signed-off-by: Alex Meijer * clean up, try out webhook Signed-off-by: Alex Meijer * bugfixes Signed-off-by: Alex Meijer * last round of tweaks Signed-off-by: Alex Meijer * [DATADOG] [ENG-2797] Improved Support for DBM costs Signed-off-by: Alex Meijer * bugfixes Signed-off-by: Alex Meijer * fix plugin validator Signed-off-by: Alex Meijer --------- Signed-off-by: Alex Meijer Signed-off-by: Alex Meijer --- .../datadog/cmd/validator/main/main.go | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/pkg/plugins/datadog/cmd/validator/main/main.go b/pkg/plugins/datadog/cmd/validator/main/main.go index 2bd9f39..515f421 100644 --- a/pkg/plugins/datadog/cmd/validator/main/main.go +++ b/pkg/plugins/datadog/cmd/validator/main/main.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "os" + "time" "github.com/hashicorp/go-multierror" "github.com/opencost/opencost/core/pkg/log" @@ -105,9 +106,17 @@ func validate(respDaily, respHourly []*pb.CustomCostResponse) bool { dbmCostsInRange := 0 //verify that the returned costs are non zero for _, resp := range respDaily { + if len(resp.Costs) == 0 && resp.Start.AsTime().After(time.Now().Truncate(24*time.Hour).Add(-1*time.Minute)) { + log.Debugf("today's daily costs returned by plugin datadog are empty, skipping: %v", resp) + continue + } var costSum float32 for _, cost := range resp.Costs { costSum += cost.GetListCost() + + if cost.GetListCost() == 0 { + log.Debugf("got zero cost for %v", cost) + } if cost.GetListCost() > 100 { log.Errorf("daily cost returned by plugin datadog for %v is greater than 100", cost) return false @@ -136,13 +145,16 @@ func validate(respDaily, respHourly []*pb.CustomCostResponse) bool { seenCosts := map[string]bool{} for _, resp := range respHourly { + var costSum float32 for _, cost := range resp.Costs { seenCosts[cost.GetResourceName()] = true - if cost.GetListCost() == 0 { - log.Errorf("hourly cost returned by plugin datadog is zero") - return false - } + costSum += cost.GetListCost() } + if costSum == 0 { + log.Errorf("hourly cost returned by plugin datadog is zero") + return false + } + } expectedCosts := []string{