Skip to content

Commit

Permalink
update retry types
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Dittamo <[email protected]>
  • Loading branch information
pvditt committed Apr 9, 2024
1 parent e4694db commit cc3522d
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 6 deletions.
4 changes: 2 additions & 2 deletions flytepropeller/events/admin_eventsink.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ func initializeAdminClientFromConfig(ctx context.Context, config *Config) (clien
tracerProvider := otelutils.GetTracerProvider(otelutils.AdminClientTracer)

grpcOptions := []grpcRetry.CallOption{
grpcRetry.WithBackoff(grpcRetry.BackoffExponentialWithJitter(time.Duration(config.BackoffScalar)*time.Millisecond, config.BackoffJitter)),
grpcRetry.WithMax(config.MaxRetries),
grpcRetry.WithBackoff(grpcRetry.BackoffExponentialWithJitter(time.Duration(config.BackoffScalar)*time.Millisecond, config.GetBackoffJitter(ctx))),
grpcRetry.WithMax(uint(config.MaxRetries)),
}

opt := grpc.WithChainUnaryInterceptor(
Expand Down
27 changes: 23 additions & 4 deletions flytepropeller/events/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package events

import (
"context"
"strconv"

"github.com/flyteorg/flyte/flytestdlib/config"
"github.com/flyteorg/flyte/flytestdlib/logger"
Expand All @@ -25,9 +26,9 @@ type Config struct {
FilePath string `json:"file-path" pflag:",For file types, specify where the file should be located."`
Rate int64 `json:"rate" pflag:",Max rate at which events can be recorded per second."`
Capacity int `json:"capacity" pflag:",The max bucket size for event recording tokens."`
MaxRetries uint `json:"max-retries" pflag:",The max number of retries for event recording."`
MaxRetries int `json:"max-retries" pflag:",The max number of retries for event recording."`
BackoffScalar int `json:"base-scalar" pflag:",The base/scalar backoff duration in milliseconds for event recording retries."`
BackoffJitter float64 `json:"backoff-jitter" pflag:",The jitter factor for event recording retries."`
BackoffJitter string `json:"backoff-jitter" pflag:",A string representation of a floating point number between 0 and 1 specifying the jitter factor for event recording retries."`
}

var (
Expand All @@ -37,12 +38,30 @@ var (
Type: EventSinkAdmin,
MaxRetries: 5,
BackoffScalar: 100,
BackoffJitter: 0.1,
BackoffJitter: "0.1",
}

configSection = config.MustRegisterSection(configSectionKey, &defaultConfig)
configSection = config.MustRegisterSectionWithUpdates(configSectionKey, &defaultConfig, func(ctx context.Context, newValue config.Config) {
if newValue.(*Config).MaxRetries < 0 {
logger.Panicf(ctx, "Admin configuration given with negative gRPC retry value.")
}

if jitter, err := strconv.ParseFloat(newValue.(*Config).BackoffJitter, 64); err != nil || jitter < 0 || jitter > 1 {
logger.Panicf(ctx, "Invalid jitter value [%v]. Must be between 0 and 1.", jitter)
}
})
)

func (c Config) GetBackoffJitter(ctx context.Context) float64 {
jitter, err := strconv.ParseFloat(c.BackoffJitter, 64)
if err != nil {
logger.Warnf(ctx, "Failed to parse backoff jitter [%v]. Error: %v", c.BackoffJitter, err)
return 0.1
}

return jitter
}

// GetConfig Retrieves current global config for storage.
func GetConfig(ctx context.Context) *Config {
if c, ok := configSection.GetConfig().(*Config); ok {
Expand Down
3 changes: 3 additions & 0 deletions flytepropeller/events/config_flags.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions flytepropeller/events/config_flags_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cc3522d

Please sign in to comment.