Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

max line lengths (component + tenant overrides) #1686

Merged
merged 10 commits into from
Feb 13, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
max line limits
  • Loading branch information
owen-d committed Feb 12, 2020
commit 7ba16f63881a08324f6c18f66d0d628db0930b76
24 changes: 24 additions & 0 deletions pkg/distributor/limits.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package distributor

// Limits controls the max line size
type Limits interface {
MaxLineSize(userID string) int
}

type constLimits int

func (c constLimits) MaxLineSize(userID string) int {
return int(c)
}

// PriorityLimits returns the first non-zero result from a set of []Limits
type PriorityLimits []Limits

func (ls PriorityLimits) MaxLineSize(userID string) (res int) {
for _, l := range ls {
if res = l.MaxLineSize(userID); res != 0 {
return res
}
}
return res
}
18 changes: 18 additions & 0 deletions pkg/distributor/limits_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package distributor

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestLimits(t *testing.T) {
require.Equal(t, 0, constLimits(0).MaxLineSize("a"))
require.Equal(t, 2, constLimits(2).MaxLineSize("a"))
require.Equal(t, 1,
PriorityLimits([]Limits{
constLimits(0),
constLimits(1),
}).MaxLineSize("a"),
)
}
2 changes: 1 addition & 1 deletion pkg/util/flagext/bytesize.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ func (bs *ByteSize) Set(s string) error {
}

func (bs ByteSize) Get() interface{} {
return uint64(bs)
return int(bs)
}
4 changes: 2 additions & 2 deletions pkg/util/flagext/bytesize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func Test_ByteSize(t *testing.T) {
for _, tc := range []struct {
in string
err bool
out uint64
out int
}{
{
in: "abc",
Expand Down Expand Up @@ -62,7 +62,7 @@ func Test_ByteSize(t *testing.T) {
require.NotNil(t, err)
} else {
require.Nil(t, err)
require.Equal(t, tc.out, bs.Get().(uint64))
require.Equal(t, tc.out, bs.Get().(int))
}

})
Expand Down