mirror of https://github.com/grafana/loki
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
289 lines
8.0 KiB
289 lines
8.0 KiB
package manifests_test
|
|
|
|
import (
|
|
"encoding/json"
|
|
"math/rand"
|
|
"testing"
|
|
|
|
"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"
|
|
"k8s.io/utils/pointer"
|
|
)
|
|
|
|
func TestConfigMap_ReturnsSHA1OfBinaryContents(t *testing.T) {
|
|
opts := randomConfigOptions()
|
|
|
|
_, sha1C, err := manifests.LokiConfigMap(opts)
|
|
require.NoError(t, err)
|
|
require.NotEmpty(t, sha1C)
|
|
}
|
|
|
|
func TestConfigOptions_UserOptionsTakePrecedence(t *testing.T) {
|
|
// regardless of what is provided by the default sizing parameters we should always prefer
|
|
// the user-defined values. This creates an all-inclusive manifests.Options and then checks
|
|
// that every value is present in the result
|
|
opts := randomConfigOptions()
|
|
|
|
res := manifests.ConfigOptions(opts)
|
|
|
|
expected, err := json.Marshal(opts.Stack)
|
|
require.NoError(t, err)
|
|
|
|
actual, err := json.Marshal(res.Stack)
|
|
require.NoError(t, err)
|
|
|
|
assert.JSONEq(t, string(expected), string(actual))
|
|
}
|
|
|
|
func randomConfigOptions() manifests.Options {
|
|
return manifests.Options{
|
|
Name: uuid.New().String(),
|
|
Namespace: uuid.New().String(),
|
|
Image: uuid.New().String(),
|
|
Stack: lokiv1.LokiStackSpec{
|
|
Size: lokiv1.SizeOneXExtraSmall,
|
|
Storage: lokiv1.ObjectStorageSpec{},
|
|
StorageClassName: uuid.New().String(),
|
|
ReplicationFactor: rand.Int31(),
|
|
Limits: &lokiv1.LimitsSpec{
|
|
Global: &lokiv1.LimitsTemplateSpec{
|
|
IngestionLimits: &lokiv1.IngestionLimitSpec{
|
|
IngestionRate: rand.Int31(),
|
|
IngestionBurstSize: rand.Int31(),
|
|
MaxLabelNameLength: rand.Int31(),
|
|
MaxLabelValueLength: rand.Int31(),
|
|
MaxLabelNamesPerSeries: rand.Int31(),
|
|
MaxGlobalStreamsPerTenant: rand.Int31(),
|
|
MaxLineSize: rand.Int31(),
|
|
},
|
|
QueryLimits: &lokiv1.QueryLimitSpec{
|
|
MaxEntriesLimitPerQuery: rand.Int31(),
|
|
MaxChunksPerQuery: rand.Int31(),
|
|
MaxQuerySeries: rand.Int31(),
|
|
},
|
|
},
|
|
Tenants: map[string]lokiv1.LimitsTemplateSpec{
|
|
uuid.New().String(): {
|
|
IngestionLimits: &lokiv1.IngestionLimitSpec{
|
|
IngestionRate: rand.Int31(),
|
|
IngestionBurstSize: rand.Int31(),
|
|
MaxLabelNameLength: rand.Int31(),
|
|
MaxLabelValueLength: rand.Int31(),
|
|
MaxLabelNamesPerSeries: rand.Int31(),
|
|
MaxGlobalStreamsPerTenant: rand.Int31(),
|
|
MaxLineSize: rand.Int31(),
|
|
},
|
|
QueryLimits: &lokiv1.QueryLimitSpec{
|
|
MaxEntriesLimitPerQuery: rand.Int31(),
|
|
MaxChunksPerQuery: rand.Int31(),
|
|
MaxQuerySeries: rand.Int31(),
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Template: &lokiv1.LokiTemplateSpec{
|
|
Compactor: &lokiv1.LokiComponentSpec{
|
|
Replicas: 1,
|
|
NodeSelector: map[string]string{
|
|
uuid.New().String(): uuid.New().String(),
|
|
},
|
|
Tolerations: []corev1.Toleration{
|
|
{
|
|
Key: uuid.New().String(),
|
|
Operator: corev1.TolerationOpEqual,
|
|
Value: uuid.New().String(),
|
|
Effect: corev1.TaintEffectNoExecute,
|
|
TolerationSeconds: pointer.Int64Ptr(rand.Int63()),
|
|
},
|
|
},
|
|
},
|
|
Distributor: &lokiv1.LokiComponentSpec{
|
|
Replicas: rand.Int31(),
|
|
NodeSelector: map[string]string{
|
|
uuid.New().String(): uuid.New().String(),
|
|
},
|
|
Tolerations: []corev1.Toleration{
|
|
{
|
|
Key: uuid.New().String(),
|
|
Operator: corev1.TolerationOpEqual,
|
|
Value: uuid.New().String(),
|
|
Effect: corev1.TaintEffectNoExecute,
|
|
TolerationSeconds: pointer.Int64Ptr(rand.Int63()),
|
|
},
|
|
},
|
|
},
|
|
Ingester: &lokiv1.LokiComponentSpec{
|
|
Replicas: rand.Int31(),
|
|
NodeSelector: map[string]string{
|
|
uuid.New().String(): uuid.New().String(),
|
|
},
|
|
Tolerations: []corev1.Toleration{
|
|
{
|
|
Key: uuid.New().String(),
|
|
Operator: corev1.TolerationOpEqual,
|
|
Value: uuid.New().String(),
|
|
Effect: corev1.TaintEffectNoExecute,
|
|
TolerationSeconds: pointer.Int64Ptr(rand.Int63()),
|
|
},
|
|
},
|
|
},
|
|
Querier: &lokiv1.LokiComponentSpec{
|
|
Replicas: rand.Int31(),
|
|
NodeSelector: map[string]string{
|
|
uuid.New().String(): uuid.New().String(),
|
|
},
|
|
Tolerations: []corev1.Toleration{
|
|
{
|
|
Key: uuid.New().String(),
|
|
Operator: corev1.TolerationOpEqual,
|
|
Value: uuid.New().String(),
|
|
Effect: corev1.TaintEffectNoExecute,
|
|
TolerationSeconds: pointer.Int64Ptr(rand.Int63()),
|
|
},
|
|
},
|
|
},
|
|
QueryFrontend: &lokiv1.LokiComponentSpec{
|
|
Replicas: rand.Int31(),
|
|
NodeSelector: map[string]string{
|
|
uuid.New().String(): uuid.New().String(),
|
|
},
|
|
Tolerations: []corev1.Toleration{
|
|
{
|
|
Key: uuid.New().String(),
|
|
Operator: corev1.TolerationOpEqual,
|
|
Value: uuid.New().String(),
|
|
Effect: corev1.TaintEffectNoExecute,
|
|
TolerationSeconds: pointer.Int64Ptr(rand.Int63()),
|
|
},
|
|
},
|
|
},
|
|
IndexGateway: &lokiv1.LokiComponentSpec{
|
|
Replicas: rand.Int31(),
|
|
NodeSelector: map[string]string{
|
|
uuid.New().String(): uuid.New().String(),
|
|
},
|
|
Tolerations: []corev1.Toleration{
|
|
{
|
|
Key: uuid.New().String(),
|
|
Operator: corev1.TolerationOpEqual,
|
|
Value: uuid.New().String(),
|
|
Effect: corev1.TaintEffectNoExecute,
|
|
TolerationSeconds: pointer.Int64Ptr(rand.Int63()),
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
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)
|
|
})
|
|
}
|
|
}
|
|
|