diff --git a/pkg/storage/stores/shipper/indexshipper/shipper.go b/pkg/storage/stores/shipper/indexshipper/shipper.go index 5b3037c45b08..2917b1fc7974 100644 --- a/pkg/storage/stores/shipper/indexshipper/shipper.go +++ b/pkg/storage/stores/shipper/indexshipper/shipper.go @@ -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" @@ -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) diff --git a/pkg/storage/stores/shipper/indexshipper/tsdb/store.go b/pkg/storage/stores/shipper/indexshipper/tsdb/store.go index 1ef58c32a1e5..cc972f9656ea 100644 --- a/pkg/storage/stores/shipper/indexshipper/tsdb/store.go +++ b/pkg/storage/stores/shipper/indexshipper/tsdb/store.go @@ -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" ) @@ -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 @@ -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 +}