@@ -4,10 +4,10 @@ import (
4
4
"context"
5
5
"fmt"
6
6
7
+ "github.com/go-kit/kit/log"
7
8
"github.com/go-kit/kit/log/level"
8
9
"github.com/pkg/errors"
9
10
10
- util_log "github.com/cortexproject/cortex/pkg/util/log"
11
11
"github.com/cortexproject/cortex/pkg/util/services"
12
12
)
13
13
@@ -18,6 +18,7 @@ type moduleService struct {
18
18
19
19
service services.Service
20
20
name string
21
+ logger log.Logger
21
22
22
23
// startDeps, stopDeps return map of service names to services
23
24
startDeps , stopDeps func (string ) map [string ]services.Service
@@ -26,9 +27,10 @@ type moduleService struct {
26
27
// NewModuleService wraps a module service, and makes sure that dependencies are started/stopped before module service starts or stops.
27
28
// If any dependency fails to start, this service fails as well.
28
29
// On stop, errors from failed dependencies are ignored.
29
- func NewModuleService (name string , service services.Service , startDeps , stopDeps func (string ) map [string ]services.Service ) services.Service {
30
+ func NewModuleService (name string , logger log. Logger , service services.Service , startDeps , stopDeps func (string ) map [string ]services.Service ) services.Service {
30
31
w := & moduleService {
31
32
name : name ,
33
+ logger : logger ,
32
34
service : service ,
33
35
startDeps : startDeps ,
34
36
stopDeps : stopDeps ,
@@ -46,7 +48,7 @@ func (w *moduleService) start(serviceContext context.Context) error {
46
48
continue
47
49
}
48
50
49
- level .Debug (util_log . Logger ).Log ("msg" , "module waiting for initialization" , "module" , w .name , "waiting_for" , m )
51
+ level .Debug (w . logger ).Log ("msg" , "module waiting for initialization" , "module" , w .name , "waiting_for" , m )
50
52
51
53
err := s .AwaitRunning (serviceContext )
52
54
if err != nil {
@@ -56,7 +58,7 @@ func (w *moduleService) start(serviceContext context.Context) error {
56
58
57
59
// we don't want to let this service to stop until all dependant services are stopped,
58
60
// so we use independent context here
59
- level .Info (util_log . Logger ).Log ("msg" , "initialising" , "module" , w .name )
61
+ level .Info (w . logger ).Log ("msg" , "initialising" , "module" , w .name )
60
62
err := w .service .StartAsync (context .Background ())
61
63
if err != nil {
62
64
return errors .Wrapf (err , "error starting module: %s" , w .name )
@@ -78,17 +80,17 @@ func (w *moduleService) stop(_ error) error {
78
80
// Only wait for other modules, if underlying service is still running.
79
81
w .waitForModulesToStop ()
80
82
81
- level .Debug (util_log . Logger ).Log ("msg" , "stopping" , "module" , w .name )
83
+ level .Debug (w . logger ).Log ("msg" , "stopping" , "module" , w .name )
82
84
83
85
err = services .StopAndAwaitTerminated (context .Background (), w .service )
84
86
} else {
85
87
err = w .service .FailureCase ()
86
88
}
87
89
88
90
if err != nil && err != ErrStopProcess {
89
- level .Warn (util_log . Logger ).Log ("msg" , "module failed with error" , "module" , w .name , "err" , err )
91
+ level .Warn (w . logger ).Log ("msg" , "module failed with error" , "module" , w .name , "err" , err )
90
92
} else {
91
- level .Info (util_log . Logger ).Log ("msg" , "module stopped" , "module" , w .name )
93
+ level .Info (w . logger ).Log ("msg" , "module stopped" , "module" , w .name )
92
94
}
93
95
return err
94
96
}
@@ -101,7 +103,7 @@ func (w *moduleService) waitForModulesToStop() {
101
103
continue
102
104
}
103
105
104
- level .Debug (util_log . Logger ).Log ("msg" , "module waiting for" , "module" , w .name , "waiting_for" , n )
106
+ level .Debug (w . logger ).Log ("msg" , "module waiting for" , "module" , w .name , "waiting_for" , n )
105
107
// Passed context isn't canceled, so we can only get error here, if service
106
108
// fails. But we don't care *how* service stops, as long as it is done.
107
109
_ = s .AwaitTerminated (context .Background ())
0 commit comments