Skip to content

Commit 3374e33

Browse files
authored
services: add failure case to Stopping function (#2231)
Stopping function now takes failureCase error as parameter. This allows stopping function to react differently based on whether running function has failed or not. In this commit, all stopping functions simply ignore the passed parameter. Signed-off-by: Peter Štibraný <peter.stibrany@grafana.com>
1 parent 1e776c4 commit 3374e33

File tree

18 files changed

+46
-25
lines changed

18 files changed

+46
-25
lines changed

pkg/alertmanager/multitenant.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ func (am *MultitenantAlertmanager) iteration(ctx context.Context) error {
241241
}
242242

243243
// stopping runs when MultitenantAlertmanager transitions to Stopping state.
244-
func (am *MultitenantAlertmanager) stopping() error {
244+
func (am *MultitenantAlertmanager) stopping(_ error) error {
245245
am.alertmanagersMtx.Lock()
246246
for _, am := range am.alertmanagers {
247247
am.Stop()

pkg/chunk/purger/purger.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func (dp *DataPurger) init(ctx context.Context) error {
114114
}
115115

116116
// Stop waits until all background tasks stop.
117-
func (dp *DataPurger) stop() error {
117+
func (dp *DataPurger) stop(_ error) error {
118118
dp.wg.Wait()
119119
return nil
120120
}

pkg/chunk/table_manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ func (m *TableManager) starting(ctx context.Context) error {
190190
}
191191

192192
// Stop the TableManager
193-
func (m *TableManager) stopping() error {
193+
func (m *TableManager) stopping(_ error) error {
194194
if m.bucketRetentionLoop != nil {
195195
return services.StopAndAwaitTerminated(context.Background(), m.bucketRetentionLoop)
196196
}

pkg/compactor/compactor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ func (c *Compactor) starting(ctx context.Context) error {
198198
return errors.Wrap(err, "failed to initialize compactor objects")
199199
}
200200

201-
func (c *Compactor) stopping() error {
201+
func (c *Compactor) stopping(_ error) error {
202202
if c.subservices != nil {
203203
return services.StopManagerAndAwaitStopped(context.Background(), c.subservices)
204204
}

pkg/cortex/module_service_wrapper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func (w *moduleServiceWrapper) run(serviceContext context.Context) error {
7070
return w.service.FailureCase()
7171
}
7272

73-
func (w *moduleServiceWrapper) stop() error {
73+
func (w *moduleServiceWrapper) stop(_ error) error {
7474
// wait until all stopDeps have stopped
7575
for _, m := range w.stopDeps {
7676
s := w.serviceMap[m]

pkg/cortex/modules.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ func (t *Cortex) initQuerier(cfg *Config) (serv services.Service, err error) {
297297
// BUT this extra functionality is ONE OF THE REASONS to introduce entire "Services" concept into Cortex.
298298
// For now, only return service that stops the worker, and Querier will be used even before storeQueryable has finished starting.
299299

300-
return services.NewIdleService(nil, func() error {
300+
return services.NewIdleService(nil, func(_ error) error {
301301
t.worker.Stop()
302302
return nil
303303
}), nil
@@ -370,7 +370,7 @@ func (t *Cortex) initStore(cfg *Config) (serv services.Service, err error) {
370370
return
371371
}
372372

373-
return services.NewIdleService(nil, func() error {
373+
return services.NewIdleService(nil, func(_ error) error {
374374
t.store.Stop()
375375
return nil
376376
}), nil
@@ -415,7 +415,7 @@ func (t *Cortex) initQueryFrontend(cfg *Config) (serv services.Service, err erro
415415
t.frontend.Handler(),
416416
),
417417
)
418-
return services.NewIdleService(nil, func() error {
418+
return services.NewIdleService(nil, func(_ error) error {
419419
t.frontend.Close()
420420
if t.cache != nil {
421421
t.cache.Stop()
@@ -491,7 +491,7 @@ func (t *Cortex) initConfig(cfg *Config) (serv services.Service, err error) {
491491

492492
t.configAPI = api.New(t.configDB, cfg.Configs.API)
493493
t.configAPI.RegisterRoutes(t.server.HTTP)
494-
return services.NewIdleService(nil, func() error {
494+
return services.NewIdleService(nil, func(_ error) error {
495495
t.configDB.Close()
496496
return nil
497497
}), nil
@@ -532,7 +532,7 @@ func (t *Cortex) initMemberlistKV(cfg *Config) (services.Service, error) {
532532
}
533533
t.memberlistKVState = newMemberlistKVState(&cfg.MemberlistKV)
534534

535-
return services.NewIdleService(nil, func() error {
535+
return services.NewIdleService(nil, func(_ error) error {
536536
kv := t.memberlistKVState.kv
537537
if kv != nil {
538538
kv.Stop()

pkg/cortex/server_service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func NewServerService(cfg *Config, serv *server.Server, servicesToWaitFor func()
4141
}
4242
}
4343

44-
stoppingFn := func() error {
44+
stoppingFn := func(_ error) error {
4545
// wait until all modules are done, and then shutdown server.
4646
for _, s := range servicesToWaitFor() {
4747
_ = s.AwaitTerminated(context.Background())

pkg/distributor/distributor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func (d *Distributor) starting(ctx context.Context) error {
219219
}
220220

221221
// Called after distributor is asked to stop via StopAsync.
222-
func (d *Distributor) stopping() error {
222+
func (d *Distributor) stopping(_ error) error {
223223
return services.StopManagerAndAwaitStopped(context.Background(), d.subservices)
224224
}
225225

pkg/ingester/ingester.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ func (i *Ingester) loop(ctx context.Context) error {
239239
}
240240

241241
// stopping is run when ingester is asked to stop
242-
func (i *Ingester) stopping() error {
242+
func (i *Ingester) stopping(_ error) error {
243243
i.wal.Stop()
244244

245245
// This will prevent us accepting any more samples

pkg/ingester/ingester_v2.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func (i *Ingester) startingV2(ctx context.Context) error {
169169
}
170170

171171
// runs when V2 ingester is stopping
172-
func (i *Ingester) stoppingV2() error {
172+
func (i *Ingester) stoppingV2(_ error) error {
173173
// It's important to wait until shipper is finished,
174174
// because the blocks transfer should start only once it's guaranteed
175175
// there's no shipping on-going.

0 commit comments

Comments
 (0)