Skip to content

Commit

Permalink
Atm/restructure testharness (#37)
Browse files Browse the repository at this point in the history
* use deploy key

Signed-off-by: Alex Meijer <[email protected]>

* clean up, try out webhook

Signed-off-by: Alex Meijer <[email protected]>

* bugfixes

Signed-off-by: Alex Meijer <[email protected]>

* last round of tweaks

Signed-off-by: Alex Meijer <[email protected]>

* [DATADOG] [ENG-2797] Improved Support for DBM costs

Signed-off-by: Alex Meijer <[email protected]>

* bugfixes

Signed-off-by: Alex Meijer <[email protected]>

* fix plugin validator

Signed-off-by: Alex Meijer <[email protected]>

---------

Signed-off-by: Alex Meijer <[email protected]>
Signed-off-by: Alex Meijer <[email protected]>
  • Loading branch information
ameijer authored Oct 9, 2024
1 parent 30e43a6 commit 42d14e3
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions pkg/plugins/datadog/cmd/validator/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"os"
"time"

"github.com/hashicorp/go-multierror"
"github.com/opencost/opencost/core/pkg/log"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 42d14e3

Please sign in to comment.