operator: Write configuration for per-tenant retention (#7201)

pull/7203/head
Robert Jacob 3 years ago committed by GitHub
parent a5c1557d03
commit f1fbb7bb3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      operator/CHANGELOG.md
  2. 18
      operator/internal/manifests/config.go
  3. 107
      operator/internal/manifests/config_test.go
  4. 41
      operator/internal/manifests/internal/config/build_test.go
  5. 6
      operator/internal/manifests/internal/config/loki-config.yaml
  6. 11
      operator/internal/manifests/internal/config/loki-runtime-config.yaml
  7. 1
      operator/internal/manifests/internal/config/options.go

@ -1,5 +1,6 @@
## Main
- [7201](https://github.com/grafana/loki/pull/7201) **xperimental**: Write configuration for per-tenant retention
- [7037](https://github.com/grafana/loki/pull/7037) **xperimental**: Skip enforcing matcher for certain tenants on OpenShift
- [7106](https://github.com/grafana/loki/pull/7106) **xperimental**: Manage global stream-based retention
- [7092](https://github.com/grafana/loki/pull/7092) **aminesnow**: Configure kube-rbac-proxy sidecar to use Intermediate TLS security profile in OCP

@ -209,15 +209,25 @@ var deleteWorkerCountMap = map[lokiv1.LokiStackSizeType]uint{
}
func retentionConfig(ls *lokiv1.LokiStackSpec) config.RetentionOptions {
if ls.Limits == nil || ls.Limits.Global == nil || ls.Limits.Global.Retention == nil {
return config.RetentionOptions{
Enabled: false,
if ls.Limits == nil {
return config.RetentionOptions{}
}
globalRetention := ls.Limits.Global != nil && ls.Limits.Global.Retention != nil
tenantRetention := false
for _, t := range ls.Limits.Tenants {
if t.Retention != nil {
tenantRetention = true
break
}
}
if !globalRetention && !tenantRetention {
return config.RetentionOptions{}
}
return config.RetentionOptions{
Enabled: true,
DeleteWorkerCount: deleteWorkerCountMap[ls.Size],
Globals: ls.Limits.Global.Retention,
}
}

@ -8,6 +8,7 @@ import (
"github.com/google/uuid"
lokiv1 "github.com/grafana/loki/operator/apis/loki/v1"
"github.com/grafana/loki/operator/internal/manifests"
"github.com/grafana/loki/operator/internal/manifests/internal/config"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
@ -180,3 +181,109 @@ func randomConfigOptions() manifests.Options {
},
}
}
func TestConfigOptions_RetentionConfig(t *testing.T) {
tt := []struct {
desc string
spec lokiv1.LokiStackSpec
wantOptions config.RetentionOptions
}{
{
desc: "no retention",
spec: lokiv1.LokiStackSpec{},
wantOptions: config.RetentionOptions{
Enabled: false,
},
},
{
desc: "global retention, extra small",
spec: lokiv1.LokiStackSpec{
Size: lokiv1.SizeOneXExtraSmall,
Limits: &lokiv1.LimitsSpec{
Global: &lokiv1.LimitsTemplateSpec{
Retention: &lokiv1.RetentionLimitSpec{
Days: 14,
},
},
},
},
wantOptions: config.RetentionOptions{
Enabled: true,
DeleteWorkerCount: 10,
},
},
{
desc: "global and tenant retention, extra small",
spec: lokiv1.LokiStackSpec{
Size: lokiv1.SizeOneXExtraSmall,
Limits: &lokiv1.LimitsSpec{
Global: &lokiv1.LimitsTemplateSpec{
Retention: &lokiv1.RetentionLimitSpec{
Days: 14,
},
},
Tenants: map[string]lokiv1.LimitsTemplateSpec{
"development": {
Retention: &lokiv1.RetentionLimitSpec{
Days: 3,
},
},
},
},
},
wantOptions: config.RetentionOptions{
Enabled: true,
DeleteWorkerCount: 10,
},
},
{
desc: "tenant retention, extra small",
spec: lokiv1.LokiStackSpec{
Size: lokiv1.SizeOneXExtraSmall,
Limits: &lokiv1.LimitsSpec{
Tenants: map[string]lokiv1.LimitsTemplateSpec{
"development": {
Retention: &lokiv1.RetentionLimitSpec{
Days: 3,
},
},
},
},
},
wantOptions: config.RetentionOptions{
Enabled: true,
DeleteWorkerCount: 10,
},
},
{
desc: "global retention, medium",
spec: lokiv1.LokiStackSpec{
Size: lokiv1.SizeOneXMedium,
Limits: &lokiv1.LimitsSpec{
Global: &lokiv1.LimitsTemplateSpec{
Retention: &lokiv1.RetentionLimitSpec{
Days: 14,
},
},
},
},
wantOptions: config.RetentionOptions{
Enabled: true,
DeleteWorkerCount: 150,
},
},
}
for _, tc := range tt {
tc := tc
t.Run(tc.desc, func(t *testing.T) {
t.Parallel()
inOpt := manifests.Options{
Stack: tc.spec,
}
options := manifests.ConfigOptions(inOpt)
require.Equal(t, tc.wantOptions, options.Retention)
})
}
}

@ -1670,11 +1670,11 @@ limits_config:
max_query_series: 500
cardinality_limit: 100000
max_streams_matchers_per_query: 1000
retention_period: 7d
retention_period: 15d
retention_stream:
- selector: '{log_type="audit"}'
- selector: '{environment="development"}'
priority: 1
period: 14d
period: 3d
max_cache_freshness_per_query: 10m
per_stream_rate_limit: 3MB
per_stream_rate_limit_burst: 15MB
@ -1748,6 +1748,11 @@ overrides:
ingestion_burst_size_mb: 5
max_global_streams_per_user: 1
max_chunks_per_query: 1000000
retention_period: 7d
retention_stream:
- period: 15d
priority: 1
selector: "{environment=\"production\"}"
`
opts := Options{
Stack: lokiv1.LokiStackSpec{
@ -1768,6 +1773,16 @@ overrides:
MaxChunksPerQuery: 2000000,
MaxQuerySeries: 500,
},
Retention: &lokiv1.RetentionLimitSpec{
Days: 15,
Streams: []*lokiv1.RetentionStreamSpec{
{
Days: 3,
Priority: 1,
Selector: `{environment="development"}`,
},
},
},
},
Tenants: map[string]lokiv1.LimitsTemplateSpec{
"test-a": {
@ -1779,6 +1794,16 @@ overrides:
QueryLimits: &lokiv1.QueryLimitSpec{
MaxChunksPerQuery: 1000000,
},
Retention: &lokiv1.RetentionLimitSpec{
Days: 7,
Streams: []*lokiv1.RetentionStreamSpec{
{
Days: 15,
Priority: 1,
Selector: `{environment="production"}`,
},
},
},
},
},
},
@ -1829,16 +1854,6 @@ overrides:
Retention: RetentionOptions{
Enabled: true,
DeleteWorkerCount: 50,
Globals: &lokiv1.RetentionLimitSpec{
Days: 7,
Streams: []*lokiv1.RetentionStreamSpec{
{
Days: 14,
Priority: 1,
Selector: `{log_type="audit"}`,
},
},
},
},
}
cfg, rCfg, err := Build(opts)

@ -119,9 +119,9 @@ limits_config:
max_query_series: {{ .Stack.Limits.Global.QueryLimits.MaxQuerySeries }}
cardinality_limit: 100000
max_streams_matchers_per_query: 1000
{{- if .Retention.Enabled }}{{- with .Retention }}
retention_period: {{.Globals.Days}}d
{{- with .Globals.Streams }}
{{- if .Retention.Enabled }}{{- with .Stack.Limits.Global.Retention }}
retention_period: {{.Days}}d
{{- with .Streams }}
retention_stream:
{{- range . }}
- selector: '{{ .Selector }}'

@ -36,4 +36,15 @@ overrides:
max_query_series: {{ $spec.QueryLimits.MaxQuerySeries }}
{{- end -}}
{{- end -}}
{{- with $spec.Retention }}
retention_period: {{ .Days }}d
{{- with .Streams }}
retention_stream:
{{- range . }}
- selector: '{{ .Selector }}'
priority: {{ .Priority }}
period: {{ .Days }}d
{{- end }}
{{- end }}
{{- end }}
{{- end -}}

@ -162,5 +162,4 @@ func (w WriteAheadLog) ReplayMemoryCeiling() string {
type RetentionOptions struct {
Enabled bool
DeleteWorkerCount uint
Globals *lokiv1.RetentionLimitSpec
}

Loading…
Cancel
Save