Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disable healthcheck watcher log #122

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmd/ydbcp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"ydbcp/internal/server/services/operation"
"ydbcp/internal/types"
"ydbcp/internal/util/xlog"
"ydbcp/internal/watchers"
"ydbcp/internal/watchers/healthcheck"
"ydbcp/internal/watchers/schedule_watcher"
"ydbcp/internal/watchers/ttl_watcher"
Expand Down Expand Up @@ -190,7 +191,7 @@ func main() {
schedule_watcher.NewScheduleWatcher(ctx, &wg, dbConnector, backupScheduleHandler, clockwork.NewRealClock())
xlog.Info(ctx, "Created ScheduleWatcher")

healthcheck.NewHealthCheck(ctx, &wg)
healthcheck.NewHealthCheck(ctx, &wg, watchers.WithDisableLog())
xlog.Info(ctx, "Initialized Healthcheck")

xlog.Info(ctx, "YDBCP started")
Expand Down
17 changes: 14 additions & 3 deletions internal/watchers/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type WatcherImpl struct {
action WatcherAction
prefixName string
actionCompleted *chan struct{}
enableLog bool
}

type Option func(*WatcherImpl)
Expand All @@ -35,6 +36,12 @@ func WithActionCompletedChannel(actionCompleted *chan struct{}) Option {
}
}

func WithDisableLog() Option {
return func(o *WatcherImpl) {
o.enableLog = false
}
}

func NewWatcher(
ctx context.Context,
wg *sync.WaitGroup,
Expand All @@ -49,6 +56,7 @@ func NewWatcher(
tickerProvider: ticker.NewRealTicker,
action: action,
prefixName: prefixName,
enableLog: true,
}

for _, opt := range options {
Expand All @@ -71,10 +79,13 @@ func (o *WatcherImpl) run(wg *sync.WaitGroup) {
xlog.Debug(o.ctx, fmt.Sprintf("%s watcher stopped", o.prefixName))
return
case <-ticker.Chan():
xlog.Debug(o.ctx, fmt.Sprintf("Starting %s watcher action", o.prefixName))
if o.enableLog {
xlog.Debug(o.ctx, fmt.Sprintf("Starting %s watcher action", o.prefixName))
}
o.action(o.ctx, o.period)
xlog.Debug(o.ctx, fmt.Sprintf("%s watcher action was completed", o.prefixName))

if o.enableLog {
xlog.Debug(o.ctx, fmt.Sprintf("%s watcher action was completed", o.prefixName))
}
if o.actionCompleted != nil {
close(*o.actionCompleted)
}
Expand Down
Loading