Skip to content

Commit cad9614

Browse files
authored
Merge pull request #328 from periklis/backport-pr-13463-5.9
[release-5.9] Backport PR grafana#13463
2 parents 74038d2 + 532be03 commit cad9614

File tree

6 files changed

+182
-29
lines changed

6 files changed

+182
-29
lines changed

operator/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Release 5.9.4
44

5+
- [13463](https://github.com/grafana/loki/pull/13463) **periklis**: fix(operator): Allow structured metadata only if V13 schema provided
56
- [13450](https://github.com/grafana/loki/pull/13450) **periklis**: fix(operator): Skip updating annotations for serviceaccounts
67
- [13430](https://github.com/grafana/loki/pull/13430) **periklis**: fix(operator): Support v3.1.0 in OpenShift dashboards
78
- [13422](https://github.com/grafana/loki/pull/13422) **periklis** feat(operator): Update Loki operand to v3.1.0

operator/internal/handlers/internal/storage/storage.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ func BuildOptions(ctx context.Context, k k8s.Client, stack *lokiv1.LokiStack, fg
4545
}
4646
}
4747

48+
now := time.Now().UTC()
4849
storageSchemas, err := storage.BuildSchemaConfig(
49-
time.Now().UTC(),
50+
now,
5051
stack.Spec.Storage,
5152
stack.Status.Storage,
5253
)
@@ -59,6 +60,7 @@ func BuildOptions(ctx context.Context, k k8s.Client, stack *lokiv1.LokiStack, fg
5960
}
6061

6162
objStore.Schemas = storageSchemas
63+
objStore.AllowStructuredMetadata = allowStructuredMetadata(storageSchemas, now)
6264

6365
if stack.Spec.Storage.TLS == nil {
6466
return objStore, nil
@@ -98,3 +100,16 @@ func BuildOptions(ctx context.Context, k k8s.Client, stack *lokiv1.LokiStack, fg
98100

99101
return objStore, nil
100102
}
103+
104+
func allowStructuredMetadata(schemas []lokiv1.ObjectStorageSchema, now time.Time) bool {
105+
activeVersion := lokiv1.ObjectStorageSchemaV11
106+
for _, s := range schemas {
107+
time, _ := s.EffectiveDate.UTCTime()
108+
if time.Before(now) {
109+
activeVersion = s.Version
110+
}
111+
}
112+
113+
return activeVersion != lokiv1.ObjectStorageSchemaV11 &&
114+
activeVersion != lokiv1.ObjectStorageSchemaV12
115+
}

operator/internal/handlers/internal/storage/storage_test.go

+122
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"testing"
7+
"time"
78

89
"github.com/stretchr/testify/require"
910
corev1 "k8s.io/api/core/v1"
@@ -560,3 +561,124 @@ func TestBuildOptions_WhenInvalidCAConfigMap_SetDegraded(t *testing.T) {
560561
require.Error(t, err)
561562
require.Equal(t, degradedErr, err)
562563
}
564+
565+
func TestAllowStructuredMetadata(t *testing.T) {
566+
testTime := time.Date(2024, 7, 1, 1, 0, 0, 0, time.UTC)
567+
tt := []struct {
568+
desc string
569+
schemas []lokiv1.ObjectStorageSchema
570+
wantAllow bool
571+
}{
572+
{
573+
desc: "disallow - no schemas",
574+
schemas: []lokiv1.ObjectStorageSchema{},
575+
wantAllow: false,
576+
},
577+
{
578+
desc: "disallow - only v12",
579+
schemas: []lokiv1.ObjectStorageSchema{
580+
{
581+
Version: lokiv1.ObjectStorageSchemaV12,
582+
EffectiveDate: "2024-07-01",
583+
},
584+
},
585+
wantAllow: false,
586+
},
587+
{
588+
desc: "allow - only v13",
589+
schemas: []lokiv1.ObjectStorageSchema{
590+
{
591+
Version: lokiv1.ObjectStorageSchemaV13,
592+
EffectiveDate: "2024-07-01",
593+
},
594+
},
595+
wantAllow: true,
596+
},
597+
{
598+
desc: "disallow - v13 in future",
599+
schemas: []lokiv1.ObjectStorageSchema{
600+
{
601+
Version: lokiv1.ObjectStorageSchemaV12,
602+
EffectiveDate: "2024-07-01",
603+
},
604+
{
605+
Version: lokiv1.ObjectStorageSchemaV13,
606+
EffectiveDate: "2024-07-02",
607+
},
608+
},
609+
wantAllow: false,
610+
},
611+
{
612+
desc: "disallow - v13 in past",
613+
schemas: []lokiv1.ObjectStorageSchema{
614+
{
615+
Version: lokiv1.ObjectStorageSchemaV13,
616+
EffectiveDate: "2024-06-01",
617+
},
618+
{
619+
Version: lokiv1.ObjectStorageSchemaV12,
620+
EffectiveDate: "2024-07-01",
621+
},
622+
},
623+
wantAllow: false,
624+
},
625+
{
626+
desc: "disallow - v13 in past and future",
627+
schemas: []lokiv1.ObjectStorageSchema{
628+
{
629+
Version: lokiv1.ObjectStorageSchemaV13,
630+
EffectiveDate: "2024-06-01",
631+
},
632+
{
633+
Version: lokiv1.ObjectStorageSchemaV12,
634+
EffectiveDate: "2024-07-01",
635+
},
636+
{
637+
Version: lokiv1.ObjectStorageSchemaV13,
638+
EffectiveDate: "2024-07-02",
639+
},
640+
},
641+
wantAllow: false,
642+
},
643+
{
644+
desc: "allow - v13 active",
645+
schemas: []lokiv1.ObjectStorageSchema{
646+
{
647+
Version: lokiv1.ObjectStorageSchemaV12,
648+
EffectiveDate: "2024-06-01",
649+
},
650+
{
651+
Version: lokiv1.ObjectStorageSchemaV13,
652+
EffectiveDate: "2024-07-01",
653+
},
654+
},
655+
wantAllow: true,
656+
},
657+
{
658+
desc: "allow - v13 active, v12 in future",
659+
schemas: []lokiv1.ObjectStorageSchema{
660+
{
661+
Version: lokiv1.ObjectStorageSchemaV13,
662+
EffectiveDate: "2024-07-01",
663+
},
664+
{
665+
Version: lokiv1.ObjectStorageSchemaV12,
666+
EffectiveDate: "2024-08-01",
667+
},
668+
},
669+
wantAllow: true,
670+
},
671+
}
672+
673+
for _, tc := range tt {
674+
tc := tc
675+
t.Run(tc.desc, func(t *testing.T) {
676+
t.Parallel()
677+
678+
allow := allowStructuredMetadata(tc.schemas, testTime)
679+
if allow != tc.wantAllow {
680+
t.Errorf("got %v, want %v", allow, tc.wantAllow)
681+
}
682+
})
683+
}
684+
}

0 commit comments

Comments
 (0)