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

Add capability to set loglevel to trace during runtime #1171

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

arp-est
Copy link
Contributor

@arp-est arp-est commented Sep 19, 2024

Copy link
Member

@denis-tingaikin denis-tingaikin left a comment

Choose a reason for hiding this comment

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

It would be fantastic if we could move the common logic of changing the log level into SDK. then it can be reused in different components much easier.

@arp-est
Copy link
Contributor Author

arp-est commented Sep 25, 2024

You mean something like adding a function that encapsulates all this signal thing to the sdk, and just calling a single function from the cmds? It sounds awesome, I feared that I would have to copy paste the current pr to every cmd, but this makes it a lot easier, I'll look around.

main.go Outdated
Comment on lines 344 to 361
func handleLogChangeSignal(ctx context.Context, ch chan os.Signal, logLevel logrus.Level) {
OUT:
for {
select {
case <-ctx.Done():
break OUT
case sig := <-ch:
switch sig {
case syscall.SIGUSR1:
log.FromContext(ctx).Infof("Setting log level to %s", logrus.TraceLevel.String())
logrus.SetLevel(logrus.TraceLevel)
case syscall.SIGUSR2:
log.FromContext(ctx).Infof("Setting log level to %s", logLevel.String())
logrus.SetLevel(logLevel)
}
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Also, I wonder, does it make sense to run the pprof server in case of enabling trace level via signals?

cc @szvincze

Choose a reason for hiding this comment

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

@denis-tingaikin: Since the TRACE log level could have influence on the different profiles, like CPU and memory, I would not tie the log level and profiling together but keep them separately configurable. If someone needs both activated then configure them one by one.

@arp-est
Copy link
Contributor Author

arp-est commented Sep 26, 2024

Put the implementation here, not sure whether the log directory, or the logrus subdirectory would be preferred, but this way, I could just use function from the log module directly which was convenient.
networkservicemesh/sdk#1672

@arp-est arp-est force-pushed the arp_dyn_loglevel branch 2 times, most recently from 1a5faf0 to 94bfc9b Compare September 30, 2024 12:25
main.go Outdated
Comment on lines 138 to 141
logruslogger.SetupLevelChangeOnSignal(ctx, map[os.Signal]logrus.Level{
syscall.SIGUSR1: logrus.TraceLevel,
syscall.SIGUSR2: level,
})
Copy link
Member

Choose a reason for hiding this comment

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

I tihnk we can ignore it if current lelvel is trace.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure, I don't think its worth adding an extra 'if' statement to check against the config. It shouldn't matter that much the worst case would be having a few extra lines of log stating that the current level is trace.

Copy link
Member

Choose a reason for hiding this comment

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

I think adding a new 'if branch' is lesser evil than having extra goroutine and subscription on the signals.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay, you convinced me.

Copy link
Member

Choose a reason for hiding this comment

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

Also, I agree that it would be better to not add a new if branch; probably we could add a check on signal map size in the 'SetupLevelChangeOnSignal' and say if size is less than 2, then do nothing. Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

:'D how about we add it to the function in the sdk instead? :'D
run golangci-lint Running [/home/runner/golangci-lint-1.53.3-linux-amd64/golangci-lint run --out-format=github-actions --timeout 3m --verbose] in [] ... Error: cyclomatic complexity 16 of func main is high (> 15) (gocyclo)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, I agree that it would be better to not add a new if branch; probably we could add a check on signal map size in the 'SetupLevelChangeOnSignal' and say if size is less than 2, then do nothing. Thoughts?

Yeah sounds good

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I mean yeah in addition to checking if the original level is not trace, in addition to that it is a correct opinion to check the map's size too yeah.

Signed-off-by: Arpad Kiss <arpad.a.kiss@est.tech>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants