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

Add wildcard tenant #589

Merged
merged 3 commits into from
Mar 12, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
7 changes: 7 additions & 0 deletions modules/overrides/overrides.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
// nil, if there are no tenant-specific limits.
type TenantLimits func(userID string) *Limits

const wildcardTenant = "*"

// perTenantOverrides represents the overrides config file
type perTenantOverrides struct {
TenantLimits map[string]*Limits `yaml:"overrides"`
Expand Down Expand Up @@ -165,6 +167,11 @@ func (o *Overrides) getOverridesForUser(userID string) *Limits {
if l != nil {
return l
}

l = o.tenantLimits(wildcardTenant)
if l != nil {
return l
}
}
return o.defaultLimits
}
Expand Down
37 changes: 36 additions & 1 deletion modules/overrides/overrides_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/cortexproject/cortex/pkg/util/services"
"github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v2"
Expand Down Expand Up @@ -42,7 +43,7 @@ func TestOverrides(t *testing.T) {
expectedIngestionRateSpans: map[string]int{"user1": 5, "user2": 5},
},
{
name: "basic override",
name: "basic overrides",
limits: Limits{
MaxGlobalTracesPerUser: 1,
MaxLocalTracesPerUser: 2,
Expand All @@ -67,6 +68,39 @@ func TestOverrides(t *testing.T) {
expectedIngestionBurstSpans: map[string]int{"user1": 9, "user2": 4},
expectedIngestionRateSpans: map[string]int{"user1": 10, "user2": 5},
},
{
name: "wildcard override",
limits: Limits{
MaxGlobalTracesPerUser: 1,
MaxLocalTracesPerUser: 2,
MaxSpansPerTrace: 3,
IngestionBurstSize: 4,
IngestionRateSpans: 5,
},
overrides: &perTenantOverrides{
TenantLimits: map[string]*Limits{
"user1": {
MaxGlobalTracesPerUser: 6,
MaxLocalTracesPerUser: 7,
MaxSpansPerTrace: 8,
IngestionBurstSize: 9,
IngestionRateSpans: 10,
},
"*": {
MaxGlobalTracesPerUser: 11,
MaxLocalTracesPerUser: 12,
MaxSpansPerTrace: 13,
IngestionBurstSize: 14,
IngestionRateSpans: 15,
},
},
},
expectedMaxGlobalTraces: map[string]int{"user1": 6, "user2": 11},
expectedMaxLocalTraces: map[string]int{"user1": 7, "user2": 12},
expectedMaxSpansPerTrace: map[string]int{"user1": 8, "user2": 13},
expectedIngestionBurstSpans: map[string]int{"user1": 9, "user2": 14},
expectedIngestionRateSpans: map[string]int{"user1": 10, "user2": 15},
},
}

for _, tt := range tests {
Expand All @@ -84,6 +118,7 @@ func TestOverrides(t *testing.T) {
tt.limits.PerTenantOverridePeriod = time.Hour
}

prometheus.DefaultRegisterer = prometheus.NewRegistry() // have to overwrite the registry or test panics with multiple metric reg
overrides, err := NewOverrides(tt.limits)
require.NoError(t, err)
err = services.StartAndAwaitRunning(context.TODO(), overrides)
Expand Down