-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Invalidate caches when pipeline wrappers are disabled (#12903)
- Loading branch information
1 parent
db7c05c
commit a772ed7
Showing
3 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
pkg/storage/chunk/cache/resultscache/pipelinewrapper_keygen.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package resultscache | ||
|
||
import ( | ||
"context" | ||
"github.com/grafana/loki/v3/pkg/util/httpreq" | ||
) | ||
|
||
type PipelineWrapperKeyGenerator struct { | ||
inner KeyGenerator | ||
} | ||
|
||
func NewPipelineWrapperKeygen(inner KeyGenerator) KeyGenerator { | ||
return &PipelineWrapperKeyGenerator{inner: inner} | ||
} | ||
|
||
func (kg *PipelineWrapperKeyGenerator) GenerateCacheKey(ctx context.Context, userID string, r Request) string { | ||
innerKey := kg.inner.GenerateCacheKey(ctx, userID, r) | ||
|
||
if httpreq.ExtractHeader(ctx, httpreq.LokiDisablePipelineWrappersHeader) == "true" { | ||
return "pipeline-disabled:" + innerKey | ||
} | ||
return innerKey | ||
} |
32 changes: 32 additions & 0 deletions
32
pkg/storage/chunk/cache/resultscache/pipelinewrapper_keygen_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package resultscache | ||
|
||
import ( | ||
"context" | ||
"github.com/grafana/loki/v3/pkg/util/httpreq" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
) | ||
|
||
func TestPipelineWrapperKeygen(t *testing.T) { | ||
kg := &stubKeygen{key: "cache-key"} | ||
keygen := NewPipelineWrapperKeygen(kg) | ||
|
||
t.Run("it does nothing if pipeline wrappers aren't disabled", func(t *testing.T) { | ||
key := keygen.GenerateCacheKey(context.Background(), "", nil) | ||
require.Equal(t, "cache-key", key) | ||
}) | ||
|
||
t.Run("it changes the key when pipeline wrappers are disabled", func(t *testing.T) { | ||
ctx := httpreq.InjectHeader(context.Background(), httpreq.LokiDisablePipelineWrappersHeader, "true") | ||
key := keygen.GenerateCacheKey(ctx, "", nil) | ||
require.Equal(t, "pipeline-disabled:cache-key", key) | ||
}) | ||
} | ||
|
||
type stubKeygen struct { | ||
key string | ||
} | ||
|
||
func (k *stubKeygen) GenerateCacheKey(_ context.Context, _ string, _ Request) string { | ||
return k.key | ||
} |