Skip to content

Commit

Permalink
[8.15](backport #2628) Increase azure fetcher timeout (#2629)
Browse files Browse the repository at this point in the history
Increase azure fetcher timeout (#2628)

* increase azure fetcher timeout

* add function

(cherry picked from commit b24534b)

Co-authored-by: Kostas Stamatakis <[email protected]>
  • Loading branch information
mergify[bot] and moukoublen authored Oct 23, 2024
1 parent b73c178 commit e5607bf
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 e5607bf

Please sign in to comment.