Skip to content

Commit

Permalink
fix: add working test
Browse files Browse the repository at this point in the history
Signed-off-by: kaldorn <[email protected]>
  • Loading branch information
kaldorn committed Feb 9, 2023
1 parent 70c222d commit be1c892
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
6 changes: 4 additions & 2 deletions metricproviders/datadog/datadog.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
)

var unixNow = func() int64 { return timeutil.Now().Unix() }
var RetryMaxWait = time.Minute * 2
var RetryMax = 10

const (
//ProviderType indicates the provider is datadog
Expand Down Expand Up @@ -110,8 +112,8 @@ func (p *Provider) Run(run *v1alpha1.AnalysisRun, metric v1alpha1.Metric) v1alph
// Configure retryable HTTP Client that automatically retries on 429 status codes
// with exponential backoff.
retryClient := retryablehttp.NewClient()
retryClient.RetryMax = 10
retryClient.RetryWaitMax = time.Minute * 2
retryClient.RetryMax = RetryMax
retryClient.RetryWaitMax = RetryMaxWait
retryClient.HTTPClient.Timeout = time.Duration(10) * time.Second
httpClient := retryClient.StandardClient()

Expand Down
18 changes: 18 additions & 0 deletions metricproviders/datadog/datadog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"strconv"
"testing"
"time"

"github.com/argoproj/argo-rollouts/pkg/apis/rollouts/v1alpha1"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -126,6 +127,21 @@ func TestRunSuite(t *testing.T) {
useEnvVarForKeys: false,
},

// Error if ratelimit response
{
webServerStatus: 429,
webServerResponse: `{"errors":["Bad Request"]}`,
metric: v1alpha1.Metric{
Name: "foo",
SuccessCondition: "default(result, 1) < 0.05",
Provider: ddProviderIntervalDefault,
},
expectedIntervalSeconds: 300,
expectedPhase: v1alpha1.AnalysisPhaseError,
expectedErrorMessage: "giving up after 3 attempt(s)",
useEnvVarForKeys: false,
},

// Expect success with default() and data
{
webServerStatus: 200,
Expand Down Expand Up @@ -231,6 +247,8 @@ func TestRunSuite(t *testing.T) {

for _, test := range tests {
serverURL := test.serverURL
RetryMaxWait = time.Second * 5
RetryMax = 2

if serverURL == "" {
// Server setup with response
Expand Down

0 comments on commit be1c892

Please sign in to comment.