Skip to content

Commit

Permalink
Add DeletionEnabled method on mode
Browse files Browse the repository at this point in the history
Signed-off-by: Michel Hollands <[email protected]>
  • Loading branch information
MichelHollands committed Jun 22, 2022
1 parent 4f02c37 commit 100fc9d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 22 deletions.
21 changes: 8 additions & 13 deletions pkg/loki/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ func (t *Loki) initQueryFrontendTripperware() (_ services.Service, err error) {
}

func (t *Loki) cacheGenClient() (generationnumber.CacheGenClient, error) {
filteringEnabled, err := deletion.FilteringEnabled(t.Cfg.CompactorConfig.DeletionMode)
filteringEnabled, err := deletion.DeleteEnabled(t.Cfg.CompactorConfig.DeletionMode)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -879,16 +879,11 @@ func (t *Loki) initCompactor() (services.Service, error) {

t.Server.HTTP.Path("/compactor/ring").Methods("GET", "POST").Handler(t.compactor)

if t.Cfg.CompactorConfig.RetentionEnabled {
switch t.compactor.DeleteMode() {
case deletion.FilterOnly, deletion.FilterAndDelete:
t.Server.HTTP.Path("/loki/api/v1/delete").Methods("PUT", "POST").Handler(t.HTTPAuthMiddleware.Wrap(t.compactor.DeleteRequestsHandler.AddDeleteRequestHandler()))
t.Server.HTTP.Path("/loki/api/v1/delete").Methods("GET").Handler(t.HTTPAuthMiddleware.Wrap(t.compactor.DeleteRequestsHandler.GetAllDeleteRequestsHandler()))
t.Server.HTTP.Path("/loki/api/v1/delete").Methods("DELETE").Handler(t.HTTPAuthMiddleware.Wrap(t.compactor.DeleteRequestsHandler.CancelDeleteRequestHandler()))
t.Server.HTTP.Path("/loki/api/v1/cache/generation_numbers").Methods("GET").Handler(t.HTTPAuthMiddleware.Wrap(t.compactor.DeleteRequestsHandler.GetCacheGenerationNumberHandler()))
default:
break
}
if t.Cfg.CompactorConfig.RetentionEnabled && t.compactor.DeleteMode().DeleteEnabled() {
t.Server.HTTP.Path("/loki/api/v1/delete").Methods("PUT", "POST").Handler(t.HTTPAuthMiddleware.Wrap(t.compactor.DeleteRequestsHandler.AddDeleteRequestHandler()))
t.Server.HTTP.Path("/loki/api/v1/delete").Methods("GET").Handler(t.HTTPAuthMiddleware.Wrap(t.compactor.DeleteRequestsHandler.GetAllDeleteRequestsHandler()))
t.Server.HTTP.Path("/loki/api/v1/delete").Methods("DELETE").Handler(t.HTTPAuthMiddleware.Wrap(t.compactor.DeleteRequestsHandler.CancelDeleteRequestHandler()))
t.Server.HTTP.Path("/loki/api/v1/cache/generation_numbers").Methods("GET").Handler(t.HTTPAuthMiddleware.Wrap(t.compactor.DeleteRequestsHandler.GetCacheGenerationNumberHandler()))
}

return t.compactor, nil
Expand Down Expand Up @@ -992,12 +987,12 @@ func (t *Loki) deleteRequestsClient() (deletion.DeleteRequestsClient, error) {
return deletion.NewNoOpDeleteRequestsStore(), nil
}

filteringEnabled, err := deletion.FilteringEnabled(t.Cfg.CompactorConfig.DeletionMode)
deleteEnabled, err := deletion.DeleteEnabled(t.Cfg.CompactorConfig.DeletionMode)
if err != nil {
return nil, err
}

if !config.UsingBoltdbShipper(t.Cfg.SchemaConfig.Configs) || !filteringEnabled {
if !config.UsingBoltdbShipper(t.Cfg.SchemaConfig.Configs) || !deleteEnabled {
return deletion.NewNoOpDeleteRequestsStore(), nil
}

Expand Down
5 changes: 2 additions & 3 deletions pkg/storage/stores/shipper/compactor/compactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,11 @@ func (c *Compactor) init(storageConfig storage.Config, schemaConfig config.Schem
return err
}

switch c.deleteMode {
case deletion.FilterOnly, deletion.FilterAndDelete:
if c.deleteMode.DeleteEnabled() {
if err := c.initDeletes(r, limits); err != nil {
return err
}
default:
} else {
c.expirationChecker = newExpirationChecker(
retention.NewExpirationChecker(limits),
// This is a dummy deletion ExpirationChecker that never expires anything
Expand Down
8 changes: 6 additions & 2 deletions pkg/storage/stores/shipper/compactor/deletion/mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ func (m Mode) String() string {
return "unknown"
}

func (m Mode) DeleteEnabled() bool {
return m == FilterOnly || m == FilterAndDelete
}

func AllModes() []string {
return []string{Disabled.String(), FilterOnly.String(), FilterAndDelete.String()}
}
Expand All @@ -44,11 +48,11 @@ func ParseMode(in string) (Mode, error) {
return 0, errUnknownMode
}

func FilteringEnabled(in string) (bool, error) {
func DeleteEnabled(in string) (bool, error) {
deleteMode, err := ParseMode(in)
if err != nil {
return false, err
}

return deleteMode == FilterOnly || deleteMode == FilterAndDelete, nil
return deleteMode.DeleteEnabled(), nil
}
8 changes: 4 additions & 4 deletions pkg/storage/stores/shipper/compactor/deletion/mode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ func TestParseMode(t *testing.T) {
}

func TestFilteringEnabled(t *testing.T) {
enabled, err := FilteringEnabled("disabled")
enabled, err := DeleteEnabled("disabled")
require.NoError(t, err)
require.False(t, enabled)

enabled, err = FilteringEnabled("filter-only")
enabled, err = DeleteEnabled("filter-only")
require.NoError(t, err)
require.True(t, enabled)

enabled, err = FilteringEnabled("filter-and-delete")
enabled, err = DeleteEnabled("filter-and-delete")
require.NoError(t, err)
require.True(t, enabled)

enabled, err = FilteringEnabled("some other value")
enabled, err = DeleteEnabled("some other value")
require.Error(t, err)
require.False(t, enabled)
}

0 comments on commit 100fc9d

Please sign in to comment.