Skip to content

Commit

Permalink
datadog: acceptance testing helper update for backoff retry
Browse files Browse the repository at this point in the history
  • Loading branch information
natemollica-nm committed Apr 12, 2024
1 parent 8a13734 commit e60a939
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions acceptance/framework/datadog/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"math"
"math/rand"
"net/http"
"regexp"
"testing"
"time"
)
Expand All @@ -23,10 +24,8 @@ func SearchMetricsAPIWithRetry(apiClient *DatadogClient, metricName string, maxR

// Log the error and response details
content, _ := json.MarshalIndent(response, "", " ")
fullContent, _ := json.MarshalIndent(fullResponse, "", " ")
logger.Logf(t, "Attempt %d: Error when calling MetricsApi.ListMetrics: %v", attempt+1, err)
logger.Logf(t, "Attempt %d: Response: %v", attempt+1, string(content))
logger.Logf(t, "Attempt %d: Full Response: %v", attempt+1, string(fullContent))

// Exponential backoff with jitter
waitTime := getBackoffDuration(attempt)
Expand All @@ -49,8 +48,9 @@ func getBackoffDuration(attempt int) time.Duration {
func responseContainsMetric(response datadogV1.MetricSearchResponse, metricName string) bool {
// Implement logic to check if `metricName` is present in `response`.
// This is a placeholder implementation. You'll need to adjust it based on how the response structure is defined and how the metrics are listed in it.
reg := regexp.MustCompile(".*" + metricName)
for _, metric := range response.Results.Metrics {
if metric == metricName {
if reg.MatchString(metric) {
return true
}
}
Expand Down

0 comments on commit e60a939

Please sign in to comment.