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

feat(logging)!: add client & worker option to pass a custom logger #1171

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
10 changes: 3 additions & 7 deletions api/v1/server/handlers/monitoring/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,15 @@ type stepOneOutput struct {

func (m *MonitoringService) run(ctx context.Context, cf clientconfig.ClientConfigFile, workflowName string, events chan<- string, stepChan chan<- string, errors chan<- error) (func(), error) {

c, err := client.NewFromConfigFile(
&cf, client.WithLogLevel(m.l.GetLevel().String()),
)
c, err := client.NewFromConfigFile(&cf, client.WithLogger(m.l))

if err != nil {
return nil, fmt.Errorf("error creating client: %w", err)
}

w, err := worker.NewWorker(

worker.WithClient(
c,
), worker.WithLogLevel(m.l.GetLevel().String()),
worker.WithClient(c),
worker.WithLogger(m.l),
)
if err != nil {
return nil, fmt.Errorf("error creating worker: %w", err)
Expand Down
14 changes: 2 additions & 12 deletions examples/loadtest/cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,12 @@ func getConcurrencyKey(ctx worker.HatchetContext) (string, error) {
}

func run(ctx context.Context, delay time.Duration, executions chan<- time.Duration, concurrency int) (int64, int64) {
c, err := client.New(
client.WithLogLevel("warn"),
)

c, err := client.New()
if err != nil {
panic(err)
}

w, err := worker.NewWorker(
worker.WithClient(
c,
),
worker.WithLogLevel("warn"),
worker.WithMaxRuns(200),
)

w, err := worker.NewWorker(worker.WithClient(c), worker.WithMaxRuns(200))
if err != nil {
panic(err)
}
Expand Down
14 changes: 2 additions & 12 deletions examples/loadtest/rampup/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,12 @@ func getConcurrencyKey(ctx worker.HatchetContext) (string, error) {
}

func run(ctx context.Context, delay time.Duration, concurrency int, maxAcceptableDuration time.Duration, hook chan<- time.Duration, executedCh chan<- int64) (int64, int64) {
c, err := client.New(
client.WithLogLevel("warn"),
)

c, err := client.New()
if err != nil {
panic(err)
}

w, err := worker.NewWorker(
worker.WithClient(
c,
),
worker.WithLogLevel("warn"),
worker.WithMaxRuns(200),
)

w, err := worker.NewWorker(worker.WithClient(c), worker.WithMaxRuns(200))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would definitely pass in a zerolog logger configured to log at a warn level -- otherwise this test becomes very noisy.

if err != nil {
panic(err)
}
Expand Down
11 changes: 2 additions & 9 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,9 @@ func defaultClientOpts(token *string, cf *client.ClientConfigFile) *ClientOpts {
}
}

func WithLogLevel(lvl string) ClientOpt {
func WithLogger(l *zerolog.Logger) ClientOpt {
return func(opts *ClientOpts) {
logger := logger.NewDefaultLogger("client")
lvl, err := zerolog.ParseLevel(lvl)

if err == nil {
logger = logger.Level(lvl)
}

opts.l = &logger
opts.l = l
}
}

Expand Down
11 changes: 3 additions & 8 deletions pkg/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,11 @@ func defaultWorkerOpts() *WorkerOpts {
}
}

func WithLogLevel(lvl string) WorkerOpt {
func WithLogger(l *zerolog.Logger) WorkerOpt {
return func(opts *WorkerOpts) {
logger := logger.NewDefaultLogger("worker")
lvl, err := zerolog.ParseLevel(lvl)

if err == nil {
logger = logger.Level(lvl)
if l != nil {
opts.l = l
}

opts.l = &logger
}
}

Expand Down