Skip to content

Commit

Permalink
#43 linting
Browse files Browse the repository at this point in the history
  • Loading branch information
roma-glushko committed Jan 8, 2024
1 parent 014d0cd commit 3cd26b5
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pkg/providers/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (c *LangModelConfig) ToModel(tel *telemetry.Telemetry) (*LangModel, error)
return nil, fmt.Errorf("error initing openai client: %v", err)
}

return NewLangModel(c.ID, client), nil
return NewLangModel(c.ID, client, c.ErrorBudget), nil
}

return nil, ErrProviderNotFound
Expand Down
4 changes: 2 additions & 2 deletions pkg/providers/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ type LangModel struct {
errorBudget *health.TokenBucket // TODO: centralize provider API health tracking in the registry
}

func NewLangModel(modelID string, client LangModelProvider) *LangModel {
func NewLangModel(modelID string, client LangModelProvider, budget health.ErrorBudget) *LangModel {
return &LangModel{
modelID: modelID,
client: client,
rateLimit: health.NewRateLimitTracker(),
errorBudget: health.NewTokenBucket(1, 10), // TODO: set from configs
errorBudget: health.NewTokenBucket(uint64(budget.RecoveryRate()), uint64(budget.Budget())),
}
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/routers/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ func DefaultLangRouterConfig() LangRouterConfig {
}
}

func (p *LangRouterConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
*p = DefaultLangRouterConfig()
func (c *LangRouterConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
*c = DefaultLangRouterConfig()

type plain LangRouterConfig // to avoid recursion

return unmarshal((*plain)(p))
return unmarshal((*plain)(c))
}
2 changes: 2 additions & 0 deletions pkg/routers/health/buckets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ func TestTokenBucket_TakeConcurrently(t *testing.T) {

for i := 0; i < 10; i++ {
wg.Add(1)

go func() {
defer wg.Done()

for k := 0; k < 10; k++ {
for bucket.Take(1) != nil {
time.Sleep(10 * time.Millisecond)
Expand Down
10 changes: 5 additions & 5 deletions pkg/routers/health/error_budget.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ func DefaultErrorBudget() ErrorBudget {
}

// Budget defines max allows number of errors per given time period
func (e *ErrorBudget) Budget() int {
return e.budget
func (b *ErrorBudget) Budget() int {
return b.budget
}

// RecoveryRate defines how much time do we need to wait to get one error token recovered (in microseconds)
func (e *ErrorBudget) RecoveryRate() int {
return e.budget / e.unitToMicro(e.unit)
func (b *ErrorBudget) RecoveryRate() int {
return b.budget / b.unitToMicro(b.unit)
}

// MarshalText implements the encoding.TextMarshaler interface.
Expand Down Expand Up @@ -62,7 +62,7 @@ func (b *ErrorBudget) UnmarshalText(text []byte) error {
return nil
}

func (e *ErrorBudget) unitToMicro(unit string) int {
func (b *ErrorBudget) unitToMicro(unit string) int {
switch unit {
case "ms":
return 1000 // 1 ms = 1000 microseconds
Expand Down
1 change: 1 addition & 0 deletions pkg/routers/retry/exp.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func (i *ExpRetryIterator) getNextWaitDuration(attempt int) time.Duration {
func (i *ExpRetryIterator) WaitNext(ctx context.Context) error {
t := time.NewTimer(i.getNextWaitDuration(i.attempt))
i.attempt++

defer t.Stop()

select {
Expand Down
1 change: 1 addition & 0 deletions pkg/routers/retry/exp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func TestExpRetry_RetryLoop(t *testing.T) {

for iterator.HasNext() {
idx++

require.NoError(t, iterator.WaitNext(ctx))
}

Expand Down
1 change: 1 addition & 0 deletions pkg/routers/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func (r *LangRouter) Chat(ctx context.Context, request *schemas.UnifiedChatReque
zap.String("provider", model.Provider()),
zap.Error(err),
)

continue
}

Expand Down
2 changes: 0 additions & 2 deletions pkg/routers/routing/priority.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ func (r PriorityIterator) Next() (*providers.LangModel, error) {
if model.Healthy() {
return model, nil
}

// otherwise, try to pick the next model on the list
}

return nil, ErrNoHealthyModels
Expand Down

0 comments on commit 3cd26b5

Please sign in to comment.