Skip to content

Commit 2581afa

Browse files
committed
Use error variables.
Signed-off-by: Peter Štibraný <[email protected]>
1 parent 6693661 commit 2581afa

File tree

4 files changed

+18
-51
lines changed

4 files changed

+18
-51
lines changed

pkg/ingester/ingester.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ func (i *Ingester) Push(ctx context.Context, req *cortexpb.WriteRequest) (*corte
466466
gl := i.getInstanceLimits()
467467
if gl != nil && gl.MaxInflightPushRequests > 0 {
468468
if inflight > gl.MaxInflightPushRequests {
469-
return nil, errTooManyInflightPushRequests{requests: inflight, limit: gl.MaxInflightPushRequests}
469+
return nil, errTooManyInflightPushRequests
470470
}
471471
}
472472

pkg/ingester/ingester_v2.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,7 @@ func (u *userTSDB) PreCreation(metric labels.Labels) error {
221221
gl := u.instanceLimitsFn()
222222
if gl != nil && gl.MaxInMemorySeries > 0 {
223223
if series := u.instanceSeriesCount.Load(); series >= gl.MaxInMemorySeries {
224-
return errMaxSeriesLimitReached{
225-
series: series,
226-
limit: gl.MaxInMemorySeries,
227-
}
224+
return errMaxSeriesLimitReached
228225
}
229226
}
230227

@@ -710,7 +707,7 @@ func (i *Ingester) v2Push(ctx context.Context, req *cortexpb.WriteRequest) (*cor
710707
il := i.getInstanceLimits()
711708
if il != nil && il.MaxIngestionRate > 0 {
712709
if rate := i.ingestionRate.rate(); rate >= il.MaxIngestionRate {
713-
return nil, errMaxSamplesPushRateLimitReached{rate: rate, limit: il.MaxIngestionRate}
710+
return nil, errMaxSamplesPushRateLimitReached
714711
}
715712
}
716713

@@ -1420,7 +1417,7 @@ func (i *Ingester) getOrCreateTSDB(userID string, force bool) (*userTSDB, error)
14201417
gl := i.getInstanceLimits()
14211418
if gl != nil && gl.MaxInMemoryTenants > 0 {
14221419
if users := int64(len(i.TSDBState.dbs)); users >= gl.MaxInMemoryTenants {
1423-
return nil, errMaxUsersLimitReached{users: users, limit: gl.MaxInMemoryTenants}
1420+
return nil, errMaxUsersLimitReached
14241421
}
14251422
}
14261423

pkg/ingester/ingester_v2_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -3414,7 +3414,7 @@ func TestIngester_v2PushInstanceLimits(t *testing.T) {
34143414
},
34153415
},
34163416

3417-
expectedErr: wrapWithUser(errMaxSeriesLimitReached{limit: 1, series: 1}, "test"),
3417+
expectedErr: wrapWithUser(errMaxSeriesLimitReached, "test"),
34183418
},
34193419

34203420
"should fail creating two users": {
@@ -3437,7 +3437,7 @@ func TestIngester_v2PushInstanceLimits(t *testing.T) {
34373437
cortexpb.API),
34383438
},
34393439
},
3440-
expectedErr: wrapWithUser(errMaxUsersLimitReached{users: 1, limit: 1}, "user2"),
3440+
expectedErr: wrapWithUser(errMaxUsersLimitReached, "user2"),
34413441
},
34423442

34433443
"should fail pushing samples in two requests due to rate limit": {
@@ -3458,7 +3458,7 @@ func TestIngester_v2PushInstanceLimits(t *testing.T) {
34583458
cortexpb.API),
34593459
},
34603460
},
3461-
expectedErrType: &errMaxSamplesPushRateLimitReached{},
3461+
expectedErr: errMaxSamplesPushRateLimitReached,
34623462
},
34633463
}
34643464

@@ -3630,7 +3630,7 @@ func TestIngester_inflightPushRequests(t *testing.T) {
36303630
req := generateSamplesForLabel(labels.FromStrings(labels.MetricName, "testcase"), 1024)
36313631

36323632
_, err := i.Push(ctx, req)
3633-
require.Equal(t, errTooManyInflightPushRequests{requests: 2, limit: 1}, err)
3633+
require.Equal(t, errTooManyInflightPushRequests, err)
36343634
return nil
36353635
})
36363636

pkg/ingester/instance_limits.go

+10-40
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
package ingester
22

3+
import "github.com/pkg/errors"
4+
5+
var (
6+
// We don't include values in the message to avoid leaking Cortex cluster configuration to users.
7+
errMaxSamplesPushRateLimitReached = errors.New("cannot push more samples: ingester's max samples push rate reached")
8+
errMaxUsersLimitReached = errors.New("cannot create TSDB: ingesters's max tenants limit reached")
9+
errMaxSeriesLimitReached = errors.New("cannot add series: ingesters's max series limit reached")
10+
errTooManyInflightPushRequests = errors.New("cannot push: too many inflight push requests")
11+
)
12+
313
// InstanceLimits describes limits used by ingester. Reaching any of these will result in Push method to return
414
// (internal) error.
515
type InstanceLimits struct {
@@ -20,43 +30,3 @@ func (l *InstanceLimits) UnmarshalYAML(unmarshal func(interface{}) error) error
2030
type plain InstanceLimits // type indirection to make sure we don't go into recursive loop
2131
return unmarshal((*plain)(l))
2232
}
23-
24-
type errMaxSamplesPushRateLimitReached struct {
25-
rate float64
26-
limit float64
27-
}
28-
29-
func (e errMaxSamplesPushRateLimitReached) Error() string {
30-
// We don't include values in the message to avoid leaking Cortex cluster configuration to users.
31-
return "cannot push more samples: ingester's max samples push rate reached"
32-
}
33-
34-
type errMaxUsersLimitReached struct {
35-
users int64
36-
limit int64
37-
}
38-
39-
func (e errMaxUsersLimitReached) Error() string {
40-
// We don't include values in the message to avoid leaking Cortex cluster configuration to users.
41-
return "cannot create TSDB: ingesters's max tenants limit reached"
42-
}
43-
44-
type errMaxSeriesLimitReached struct {
45-
series int64
46-
limit int64
47-
}
48-
49-
func (e errMaxSeriesLimitReached) Error() string {
50-
// We don't include values in the message to avoid leaking Cortex cluster configuration to users.
51-
return "cannot add series: ingesters's max series limit reached"
52-
}
53-
54-
type errTooManyInflightPushRequests struct {
55-
requests int64
56-
limit int64
57-
}
58-
59-
func (e errTooManyInflightPushRequests) Error() string {
60-
// We don't include values in the message to avoid leaking Cortex cluster configuration to users.
61-
return "cannot push: too many inflight push requests"
62-
}

0 commit comments

Comments
 (0)