Skip to content

Commit

Permalink
Remove unused tombstones loader and cache gen code (#5694)
Browse files Browse the repository at this point in the history
* remove unused tombstones loader and cache gen code

Signed-off-by: Ben Ye <[email protected]>

* fix tests

Signed-off-by: Ben Ye <[email protected]>

* cleanup unused modules

Signed-off-by: Ben Ye <[email protected]>

---------

Signed-off-by: Ben Ye <[email protected]>
  • Loading branch information
yeya24 authored Dec 8, 2023
1 parent ab3ca0a commit 83be88f
Show file tree
Hide file tree
Showing 19 changed files with 38 additions and 729 deletions.
1 change: 0 additions & 1 deletion integration/querier_tenant_federation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ func runQuerierTenantFederationTest(t *testing.T, cfg querierTenantFederationCon
require.NoError(t, queueComponent.WaitSumMetricsWithOptions(e2e.Equals(0), []string{queueMetricName}, e2e.WithLabelMatchers(
labels.MustNewMatcher(labels.MatchEqual, "user", strings.Join(tenantIDs, "|")))))

// TODO: check cache invalidation on tombstone cache gen increase
// TODO: check fairness in queryfrontend
}

Expand Down
6 changes: 1 addition & 5 deletions pkg/api/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/weaveworks/common/instrument"
"github.com/weaveworks/common/middleware"

"github.com/cortexproject/cortex/pkg/purger"
"github.com/cortexproject/cortex/pkg/querier"
"github.com/cortexproject/cortex/pkg/querier/stats"
"github.com/cortexproject/cortex/pkg/util"
Expand Down Expand Up @@ -162,7 +161,6 @@ func NewQuerierHandler(
exemplarQueryable storage.ExemplarQueryable,
engine v1.QueryEngine,
distributor Distributor,
tombstonesLoader purger.TombstonesLoader,
reg prometheus.Registerer,
logger log.Logger,
) http.Handler {
Expand Down Expand Up @@ -242,9 +240,7 @@ func NewQuerierHandler(
ResponseBodySize: sentMessageSize,
InflightRequests: inflightRequests,
}
cacheGenHeaderMiddleware := getHTTPCacheGenNumberHeaderSetterMiddleware(tombstonesLoader)
middlewares := middleware.Merge(inst, cacheGenHeaderMiddleware)
router.Use(middlewares.Wrap)
router.Use(inst.Wrap)

// Define the prefixes for all routes
prefix := path.Join(cfg.ServerPrefix, cfg.PrometheusHTTPPrefix)
Expand Down
4 changes: 1 addition & 3 deletions pkg/api/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/weaveworks/common/user"

"github.com/cortexproject/cortex/pkg/purger"
)

func TestIndexHandlerPrefix(t *testing.T) {
Expand Down Expand Up @@ -234,7 +232,7 @@ func TestBuildInfoAPI(t *testing.T) {
version.Version = tc.version
version.Branch = tc.branch
version.Revision = tc.revision
handler := NewQuerierHandler(cfg, nil, nil, nil, nil, purger.NewNoopTombstonesLoader(), nil, &FakeLogger{})
handler := NewQuerierHandler(cfg, nil, nil, nil, nil, nil, &FakeLogger{})
writer := httptest.NewRecorder()
req := httptest.NewRequest("GET", "/api/v1/status/buildinfo", nil)
req = req.WithContext(user.InjectOrgID(req.Context(), "test"))
Expand Down
23 changes: 0 additions & 23 deletions pkg/api/middlewares.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,9 @@ import (
"context"
"net/http"

"github.com/weaveworks/common/middleware"

"github.com/cortexproject/cortex/pkg/purger"
"github.com/cortexproject/cortex/pkg/querier/tripperware/queryrange"
"github.com/cortexproject/cortex/pkg/tenant"
util_log "github.com/cortexproject/cortex/pkg/util/log"
)

// middleware for setting cache gen header to let consumer of response know all previous responses could be invalid due to delete operation
func getHTTPCacheGenNumberHeaderSetterMiddleware(cacheGenNumbersLoader purger.TombstonesLoader) middleware.Interface {
return middleware.Func(func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
tenantIDs, err := tenant.TenantIDs(r.Context())
if err != nil {
http.Error(w, err.Error(), http.StatusUnauthorized)
return
}

cacheGenNumber := cacheGenNumbersLoader.GetResultsCacheGenNumber(tenantIDs)

w.Header().Set(queryrange.ResultsCacheGenNumberHeaderName, cacheGenNumber)
next.ServeHTTP(w, r)
})
})
}

// HTTPHeaderMiddleware adds specified HTTPHeaders to the request context
type HTTPHeaderMiddleware struct {
TargetHeaders []string
Expand Down
92 changes: 0 additions & 92 deletions pkg/chunk/cache/cache_gen.go

This file was deleted.

41 changes: 0 additions & 41 deletions pkg/chunk/cache/cache_gen_test.go

This file was deleted.

2 changes: 0 additions & 2 deletions pkg/cortex/cortex.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import (
frontendv1 "github.com/cortexproject/cortex/pkg/frontend/v1"
"github.com/cortexproject/cortex/pkg/ingester"
"github.com/cortexproject/cortex/pkg/ingester/client"
"github.com/cortexproject/cortex/pkg/purger"
"github.com/cortexproject/cortex/pkg/querier"
"github.com/cortexproject/cortex/pkg/querier/tenantfederation"
"github.com/cortexproject/cortex/pkg/querier/tripperware"
Expand Down Expand Up @@ -302,7 +301,6 @@ type Cortex struct {
Flusher *flusher.Flusher
Frontend *frontendv1.Frontend
RuntimeConfig *runtimeconfig.Manager
TombstonesLoader purger.TombstonesLoader
QuerierQueryable prom_storage.SampleAndChunkQueryable
ExemplarQueryable prom_storage.ExemplarQueryable
QuerierEngine v1.QueryEngine
Expand Down
30 changes: 10 additions & 20 deletions pkg/cortex/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ const (
StoreQueryable string = "store-queryable"
QueryFrontend string = "query-frontend"
QueryFrontendTripperware string = "query-frontend-tripperware"
DeleteRequestsStore string = "delete-requests-store"
RulerStorage string = "ruler-storage"
Ruler string = "ruler"
Configs string = "configs"
Expand Down Expand Up @@ -230,7 +229,7 @@ func (t *Cortex) initQueryable() (serv services.Service, err error) {
querierRegisterer := prometheus.WrapRegistererWith(prometheus.Labels{"engine": "querier"}, prometheus.DefaultRegisterer)

// Create a querier queryable and PromQL engine
t.QuerierQueryable, t.ExemplarQueryable, t.QuerierEngine = querier.New(t.Cfg.Querier, t.Overrides, t.Distributor, t.StoreQueryables, t.TombstonesLoader, querierRegisterer, util_log.Logger)
t.QuerierQueryable, t.ExemplarQueryable, t.QuerierEngine = querier.New(t.Cfg.Querier, t.Overrides, t.Distributor, t.StoreQueryables, querierRegisterer, util_log.Logger)

// Register the default endpoints that are always enabled for the querier module
t.API.RegisterQueryable(t.QuerierQueryable, t.Distributor)
Expand Down Expand Up @@ -308,7 +307,6 @@ func (t *Cortex) initQuerier() (serv services.Service, err error) {
t.ExemplarQueryable,
t.QuerierEngine,
t.Distributor,
t.TombstonesLoader,
prometheus.DefaultRegisterer,
util_log.Logger,
)
Expand Down Expand Up @@ -441,12 +439,6 @@ func (t *Cortex) initFlusher() (serv services.Service, err error) {
return t.Flusher, nil
}

func (t *Cortex) initDeleteRequestsStore() (serv services.Service, err error) {
// no-op while blocks store does not support series deletion
t.TombstonesLoader = purger.NewNoopTombstonesLoader()
return
}

// initQueryFrontendTripperware instantiates the tripperware used by the query frontend
// to optimize Prometheus query requests.
func (t *Cortex) initQueryFrontendTripperware() (serv services.Service, err error) {
Expand All @@ -462,7 +454,6 @@ func (t *Cortex) initQueryFrontendTripperware() (serv services.Service, err erro
t.Overrides,
queryrange.PrometheusResponseExtractor{},
prometheus.DefaultRegisterer,
t.TombstonesLoader,
queryAnalyzer,
prometheusCodec,
shardedPrometheusCodec,
Expand Down Expand Up @@ -591,7 +582,7 @@ func (t *Cortex) initRuler() (serv services.Service, err error) {
} else {
rulerRegisterer := prometheus.WrapRegistererWith(prometheus.Labels{"engine": "ruler"}, prometheus.DefaultRegisterer)
// TODO: Consider wrapping logger to differentiate from querier module logger
queryable, _, engine := querier.New(t.Cfg.Querier, t.Overrides, t.Distributor, t.StoreQueryables, t.TombstonesLoader, rulerRegisterer, util_log.Logger)
queryable, _, engine := querier.New(t.Cfg.Querier, t.Overrides, t.Distributor, t.StoreQueryables, rulerRegisterer, util_log.Logger)

managerFactory := ruler.DefaultTenantManagerFactory(t.Cfg.Ruler, t.Distributor, queryable, engine, t.Overrides, prometheus.DefaultRegisterer)
manager, err = ruler.NewDefaultMultiTenantManager(t.Cfg.Ruler, managerFactory, prometheus.DefaultRegisterer, util_log.Logger)
Expand Down Expand Up @@ -746,7 +737,6 @@ func (t *Cortex) setupModuleManager() error {
mm.RegisterModule(OverridesExporter, t.initOverridesExporter)
mm.RegisterModule(Distributor, t.initDistributor)
mm.RegisterModule(DistributorService, t.initDistributorService, modules.UserInvisibleModule)
mm.RegisterModule(DeleteRequestsStore, t.initDeleteRequestsStore, modules.UserInvisibleModule)
mm.RegisterModule(Ingester, t.initIngester)
mm.RegisterModule(IngesterService, t.initIngesterService, modules.UserInvisibleModule)
mm.RegisterModule(Flusher, t.initFlusher)
Expand Down Expand Up @@ -777,28 +767,28 @@ func (t *Cortex) setupModuleManager() error {
OverridesExporter: {RuntimeConfig},
Distributor: {DistributorService, API},
DistributorService: {Ring, Overrides},
Ingester: {IngesterService, Overrides, DeleteRequestsStore, API},
Ingester: {IngesterService, Overrides, API},
IngesterService: {Overrides, RuntimeConfig, MemberlistKV},
Flusher: {Overrides, DeleteRequestsStore, API},
Queryable: {Overrides, DistributorService, Overrides, DeleteRequestsStore, Ring, API, StoreQueryable, MemberlistKV},
Flusher: {Overrides, API},
Queryable: {Overrides, DistributorService, Overrides, Ring, API, StoreQueryable, MemberlistKV},
Querier: {TenantFederation},
StoreQueryable: {Overrides, Overrides, DeleteRequestsStore, MemberlistKV},
QueryFrontendTripperware: {API, Overrides, DeleteRequestsStore},
StoreQueryable: {Overrides, Overrides, MemberlistKV},
QueryFrontendTripperware: {API, Overrides},
QueryFrontend: {QueryFrontendTripperware},
QueryScheduler: {API, Overrides},
Ruler: {DistributorService, Overrides, DeleteRequestsStore, StoreQueryable, RulerStorage},
Ruler: {DistributorService, Overrides, StoreQueryable, RulerStorage},
RulerStorage: {Overrides},
Configs: {API},
AlertManager: {API, MemberlistKV, Overrides},
Compactor: {API, MemberlistKV, Overrides},
StoreGateway: {API, Overrides, MemberlistKV},
TenantDeletion: {API, Overrides, DeleteRequestsStore},
TenantDeletion: {API, Overrides},
Purger: {TenantDeletion},
TenantFederation: {Queryable},
All: {QueryFrontend, Querier, Ingester, Distributor, Purger, StoreGateway, Ruler},
}
if t.Cfg.ExternalPusher != nil && t.Cfg.ExternalQueryable != nil {
deps[Ruler] = []string{Overrides, DeleteRequestsStore, RulerStorage}
deps[Ruler] = []string{Overrides, RulerStorage}
}
for mod, targets := range deps {
if err := mm.AddDependency(mod, targets...); err != nil {
Expand Down
Loading

0 comments on commit 83be88f

Please sign in to comment.