Skip to content

Commit c5bb061

Browse files
committed
Moved ReadLifecycler interface definition at the place of consumption
Signed-off-by: Marco Pracucci <marco@pracucci.com>
1 parent fbce9af commit c5bb061

File tree

4 files changed

+24
-31
lines changed

4 files changed

+24
-31
lines changed

pkg/distributor/ingestion_rate_strategy.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
package distributor
22

33
import (
4-
"github.com/cortexproject/cortex/pkg/ring"
54
"github.com/cortexproject/cortex/pkg/util/limiter"
65
"github.com/cortexproject/cortex/pkg/util/validation"
76
"golang.org/x/time/rate"
87
)
98

9+
// ReadLifecycler represents the read interface to the lifecycler.
10+
type ReadLifecycler interface {
11+
HealthyInstancesCount() int
12+
}
13+
1014
type localStrategy struct {
1115
limits *validation.Overrides
1216
}
@@ -27,10 +31,10 @@ func (s *localStrategy) Burst(tenantID string) int {
2731

2832
type globalStrategy struct {
2933
limits *validation.Overrides
30-
ring ring.ReadLifecycler
34+
ring ReadLifecycler
3135
}
3236

33-
func newGlobalIngestionRateStrategy(limits *validation.Overrides, ring ring.ReadLifecycler) limiter.RateLimiterStrategy {
37+
func newGlobalIngestionRateStrategy(limits *validation.Overrides, ring ReadLifecycler) limiter.RateLimiterStrategy {
3438
return &globalStrategy{
3539
limits: limits,
3640
ring: ring,

pkg/distributor/ingestion_rate_strategy_test.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ package distributor
33
import (
44
"testing"
55

6-
"github.com/cortexproject/cortex/pkg/ring"
76
"github.com/cortexproject/cortex/pkg/util/limiter"
87
"github.com/cortexproject/cortex/pkg/util/validation"
98
"github.com/stretchr/testify/assert"
9+
"github.com/stretchr/testify/mock"
1010
"github.com/stretchr/testify/require"
1111
"golang.org/x/time/rate"
1212
)
1313

1414
func TestIngestionRateStrategy(t *testing.T) {
1515
tests := map[string]struct {
1616
limits validation.Limits
17-
ring ring.ReadLifecycler
17+
ring ReadLifecycler
1818
expectedLimit float64
1919
expectedBurst int
2020
}{
@@ -34,8 +34,8 @@ func TestIngestionRateStrategy(t *testing.T) {
3434
IngestionRate: float64(1000),
3535
IngestionBurstSize: 10000,
3636
},
37-
ring: func() ring.ReadLifecycler {
38-
ring := ring.NewReadLifecyclerMock()
37+
ring: func() ReadLifecycler {
38+
ring := newReadLifecyclerMock()
3939
ring.On("HealthyInstancesCount").Return(2)
4040
return ring
4141
}(),
@@ -81,3 +81,16 @@ func TestIngestionRateStrategy(t *testing.T) {
8181
})
8282
}
8383
}
84+
85+
type readLifecyclerMock struct {
86+
mock.Mock
87+
}
88+
89+
func newReadLifecyclerMock() *readLifecyclerMock {
90+
return &readLifecyclerMock{}
91+
}
92+
93+
func (m *readLifecyclerMock) HealthyInstancesCount() int {
94+
args := m.Called()
95+
return args.Int(0)
96+
}

pkg/ring/lifecycler.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@ var (
3838
}, []string{"op", "status", "name"})
3939
)
4040

41-
// ReadLifecycler represents the read interface to the lifecycler.
42-
type ReadLifecycler interface {
43-
HealthyInstancesCount() int
44-
}
45-
4641
// LifecyclerConfig is the config to build a Lifecycler.
4742
type LifecyclerConfig struct {
4843
RingConfig Config `yaml:"ring,omitempty"`

pkg/ring/lifecycler_mock.go

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)