Skip to content

Commit

Permalink
indexshipper.ModeDisabled for explicit indexing operations
Browse files Browse the repository at this point in the history
Signed-off-by: Owen Diehl <[email protected]>
  • Loading branch information
owen-d committed Nov 13, 2024
1 parent 63f598a commit fd85fc6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/storage/stores/shipper/indexshipper/shipper.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ const (
ModeReadOnly = Mode("RO")
// ModeWriteOnly is to allow only write operations
ModeWriteOnly = Mode("WO")
// ModeDisabled is a no-op implementation which does nothing & does not error.
// It's used by the blockbuilder which handles index operations independently.
ModeDisabled = Mode("NO")

// FilesystemObjectStoreType holds the periodic config type for the filesystem store
FilesystemObjectStoreType = "filesystem"
Expand Down Expand Up @@ -142,6 +145,8 @@ type indexShipper struct {
func NewIndexShipper(prefix string, cfg Config, storageClient client.ObjectClient, limits downloads.Limits,
tenantFilter downloads.TenantFilter, open index.OpenIndexFileFunc, tableRangeToHandle config.TableRange, reg prometheus.Registerer, logger log.Logger) (IndexShipper, error) {
switch cfg.Mode {
case ModeDisabled:
return Noop{}, nil
case ModeReadOnly, ModeWriteOnly, ModeReadWrite:
default:
return nil, fmt.Errorf("invalid mode: %v", cfg.Mode)
Expand Down
14 changes: 14 additions & 0 deletions pkg/storage/stores/shipper/indexshipper/tsdb/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/grafana/loki/v3/pkg/storage/stores/index"
"github.com/grafana/loki/v3/pkg/storage/stores/shipper/indexshipper"
"github.com/grafana/loki/v3/pkg/storage/stores/shipper/indexshipper/downloads"
"github.com/grafana/loki/v3/pkg/storage/stores/shipper/indexshipper/tsdb"
tsdbindex "github.com/grafana/loki/v3/pkg/storage/stores/shipper/indexshipper/tsdb/index"
)

Expand Down Expand Up @@ -85,6 +86,13 @@ func (s *store) init(name, prefix string, indexShipperCfg indexshipper.Config, s
var indices []Index
opts := DefaultIndexClientOptions()

// early return in case index shipper is disabled.
if indexShipperCfg.Mode == indexshipper.ModeDisabled {
s.indexWriter = noopIndexWriter{}
s.Reader = NewIndexClient(tsdb.NoopIndex{}, opts, limits)
return nil
}

if indexShipperCfg.Mode == indexshipper.ModeWriteOnly {
// We disable bloom filters on write nodes
// for the Stats() methods as it's of relatively little
Expand Down Expand Up @@ -172,3 +180,9 @@ type failingIndexWriter struct{}
func (f failingIndexWriter) Append(_ string, _ labels.Labels, _ uint64, _ tsdbindex.ChunkMetas) error {
return fmt.Errorf("index writer is not initialized due to tsdb store being initialized in read-only mode")
}

type noopIndexWriter struct{}

func (f noopIndexWriter) Append(_ string, _ labels.Labels, _ uint64, _ tsdbindex.ChunkMetas) error {
return nil
}

0 comments on commit fd85fc6

Please sign in to comment.