Skip to content

Commit

Permalink
Increase azure fetcher timeout (#2628)
Browse files Browse the repository at this point in the history
* increase azure fetcher timeout

* add function

(cherry picked from commit b24534b)
  • Loading branch information
moukoublen authored and mergify[bot] committed Oct 22, 2024
1 parent 6c508ba commit cd0e301
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
16 changes: 15 additions & 1 deletion internal/flavors/benchmark/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"context"
"errors"
"fmt"
"math"
"time"

"github.com/elastic/elastic-agent-libs/logp"
Expand Down Expand Up @@ -50,7 +51,7 @@ func (a *Azure) NewBenchmark(ctx context.Context, log *logp.Logger, cfg *config.

return builder.New(
builder.WithBenchmarkDataProvider(bdp),
builder.WithManagerTimeout(20*time.Minute),
builder.WithManagerTimeout(calculateFetcherTimeout(cfg.Period)),
).Build(ctx, log, cfg, resourceCh, reg)
}

Expand Down Expand Up @@ -95,3 +96,16 @@ func (a *Azure) checkDependencies() error {
}
return nil
}

// calculateFetcherTimeout calculates the timeout for each fetcher based on period as ~70% of the period duration. If less than 3 hours, it returns 3 hours.
func calculateFetcherTimeout(period time.Duration) time.Duration {
roundedHours := math.Round(period.Hours() * 0.7)
to := time.Duration(roundedHours) * time.Hour

const min = 3 * time.Hour
if to < min {
return min
}

return to
}
45 changes: 45 additions & 0 deletions internal/flavors/benchmark/azure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ package benchmark
import (
"errors"
"testing"
"time"

"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

"github.com/elastic/cloudbeat/internal/config"
"github.com/elastic/cloudbeat/internal/resources/providers/azurelib"
Expand Down Expand Up @@ -119,3 +121,46 @@ func mockAzureInventoryInitializerService(err error) azurelib.ProviderInitialize
}
return initializer
}

func TestCalculateFetcherTimeout(t *testing.T) {
tests := map[string]struct {
inputPeriod time.Duration
expected time.Duration
}{
"48h": {
inputPeriod: 48 * time.Hour,
expected: 34 * time.Hour,
},
"24h": {
inputPeriod: 24 * time.Hour,
expected: 17 * time.Hour,
},
"3h": {
inputPeriod: 3 * time.Hour,
expected: 3 * time.Hour,
},
"30m": {
inputPeriod: 30 * time.Minute,
expected: 3 * time.Hour,
},
"0": {
inputPeriod: 0,
expected: 3 * time.Hour,
},
"-30m": {
inputPeriod: -30 * time.Minute,
expected: 3 * time.Hour,
},
"-3h": {
inputPeriod: -3 * time.Hour,
expected: 3 * time.Hour,
},
}

for name, tc := range tests {
t.Run(name, func(t *testing.T) {
got := calculateFetcherTimeout(tc.inputPeriod)
require.Equal(t, tc.expected, got)
})
}
}

0 comments on commit cd0e301

Please sign in to comment.