Skip to content

Commit

Permalink
#163: Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
roma-glushko committed Mar 11, 2024
1 parent ba56d3f commit d48724d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
7 changes: 4 additions & 3 deletions pkg/providers/lang.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package providers

import (
"context"
"glide/pkg/routers/health"
"time"

"glide/pkg/routers/health"

"glide/pkg/api/schemas"
"glide/pkg/providers/clients"
"glide/pkg/routers/latency"
Expand Down Expand Up @@ -33,7 +34,7 @@ type LanguageModel struct {
modelID string
weight int
client LangProvider
healthTracker *health.HealthTracker
healthTracker *health.Tracker
chatLatency *latency.MovingAverage
chatStreamLatency *latency.MovingAverage
latencyUpdateInterval *time.Duration
Expand All @@ -43,7 +44,7 @@ func NewLangModel(modelID string, client LangProvider, budget health.ErrorBudget
return &LanguageModel{
modelID: modelID,
client: client,
healthTracker: health.NewHealthTracker(budget),
healthTracker: health.NewTracker(budget),
chatLatency: latency.NewMovingAverage(latencyConfig.Decay, latencyConfig.WarmupSamples),
chatStreamLatency: latency.NewMovingAverage(latencyConfig.Decay, latencyConfig.WarmupSamples),
latencyUpdateInterval: latencyConfig.UpdateInterval,
Expand Down
4 changes: 2 additions & 2 deletions pkg/providers/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ type LangModelMock struct {
weight int
}

func NewLangModelMock(ID string, healthy bool, avgLatency float64, weight int) *LangModelMock {
func NewLangModelMock(ID string, healthy bool, avgLatency float64, weight int) LangModelMock {
chatLatency := latency.NewMovingAverage(0.06, 3)

if avgLatency > 0.0 {
chatLatency.Set(avgLatency)
}

return &LangModelMock{
return LangModelMock{
modelID: ID,
healthy: healthy,
chatLatency: chatLatency,
Expand Down
12 changes: 7 additions & 5 deletions pkg/routers/health/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,28 @@ package health

import (
"errors"

"glide/pkg/providers/clients"
)

type HealthTracker struct {
// Tracker tracks errors and general health of model provider
type Tracker struct {
errBudget *TokenBucket
rateLimit *RateLimitTracker
}

func NewHealthTracker(budget ErrorBudget) *HealthTracker {
return &HealthTracker{
func NewTracker(budget ErrorBudget) *Tracker {
return &Tracker{
rateLimit: NewRateLimitTracker(),
errBudget: NewTokenBucket(budget.TimePerTokenMicro(), budget.Budget()),
}
}

func (t *HealthTracker) Healthy() bool {
func (t *Tracker) Healthy() bool {
return !t.rateLimit.Limited() && t.errBudget.HasTokens()
}

func (t *HealthTracker) TrackErr(err error) {
func (t *Tracker) TrackErr(err error) {
var rateLimitErr *clients.RateLimitError

if errors.As(err, &rateLimitErr) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/routers/routing/least_latency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ func TestLeastLatencyRouting_Routing(t *testing.T) {
}

routing := LeastLatencyRouting{
schedules: schedules,
latencyGetter: providers.ChatMockLatency,
schedules: schedules,
}

iterator := routing.Iterator()
Expand Down

0 comments on commit d48724d

Please sign in to comment.