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

chore(logging): configure daemon/grpc loggers on initialization #6024

Merged
merged 1 commit into from
Jan 11, 2022

Conversation

rexledesma
Copy link
Contributor

@rexledesma rexledesma commented Dec 20, 2021

Summary

Because we configure loggers just in time instead of on application initialization, libraries that import
system level components from Dagster (e.g. the daemon) cannot override the logging format. If one attempts
to override the logging format by introducing a new handler on the root logger, the result is that you get
double logs.

To follow best practices around logging (see https://docs.python.org/3/howto/logging.html#configuring-logging-for-a-library),
we configure the logger on application initialization. Also, we allow overrides to the logging scheme by configuring a
null handler to allow the user to use their own logging configuration.

Test Plan

run locally, see logs are still formatted properly.
Allow overrides, and see log formatting is dictated by the application code logic, rather than the library code.
pytest

Checklist

  • My change requires a change to the documentation and I have updated the documentation accordingly.
  • I have added tests to cover my changes.

@vercel
Copy link

vercel bot commented Dec 20, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployments, click below or on the icon next to each commit.

dagit-storybook – ./js_modules/dagit/packages/core

🔍 Inspect: https://vercel.com/elementl/dagit-storybook/3BaNTdsjvSn2rxZHVvgFGUb1mCuZ
✅ Preview: Canceled

[Deployment for 54bea83 canceled]

dagster – ./docs/next

🔍 Inspect: https://vercel.com/elementl/dagster/CQViPrX2ZBnTFgbEsn1i3FeRaHuw
✅ Preview: Canceled

[Deployment for 54bea83 canceled]

@rexledesma
Copy link
Contributor Author

Current dependencies on/for this PR:

This comment was auto-generated by Graphite.

Copy link
Member

@gibsondan gibsondan left a comment

Choose a reason for hiding this comment

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

would love @OwenKephart to take a look too since he's been driving the logging stuff. A few questions inline about some of the specific names

python_modules/dagit/dagit/cli.py Outdated Show resolved Hide resolved
@@ -398,7 +399,8 @@ def grpc_command(
if not (port or socket and not (port and socket)):
raise click.UsageError("You must pass one and only one of --port/-p or --socket/-s.")

logger = default_system_logger("dagster-code-server", coerce_valid_log_level(log_level))
configure_loggers(log_level=coerce_valid_log_level(log_level))
logger = logging.getLogger("dagster.grpc.server")
Copy link
Member

Choose a reason for hiding this comment

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

I like dagster-code-server (or dagster.code-server or something) better than grpc.server personally - i've been thinking about doing a bigger push to stop calling them 'grpc servers' everywhere. (Similar to how dagit is called 'dagit' not 'the flask server' - grpc is an implementation detail)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it makes sense to send the log lines to the same logger as grpc.server, since the module is currently referenced that way. While I'd be in favor of renaming the module, its probably best to put that out of scope for this PR.

That brings up another point though that specifying the logger names literally might end up leaving easy to miss bugs for if(when) we do actually refactor. We could determine the logger path programmatically with something like logger = logging.getLogger(inspect.getmodule(DagsterGrpcServer).__name__)

The effect of this is that if the import path changed, we wouldn't need to change the string as well.

python_modules/dagster/dagster/utils/log.py Outdated Show resolved Hide resolved
@vercel vercel bot temporarily deployed to Preview – dagit-storybook January 10, 2022 18:01 Inactive
@vercel vercel bot temporarily deployed to Preview – dagster January 10, 2022 18:01 Inactive
@vercel vercel bot temporarily deployed to Preview – dagster January 10, 2022 18:07 Inactive
@vercel vercel bot temporarily deployed to Preview – dagit-storybook January 10, 2022 18:07 Inactive
Copy link
Contributor

@OwenKephart OwenKephart left a comment

Choose a reason for hiding this comment

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

This looks solid to me, other than the small comment on configure_loggers().


if handler == "default":
for logger in ["dagster", "dagit"]:
logging.getLogger(logger).handlers[0].formatter.formatTime = _mockable_formatTime
Copy link
Contributor

Choose a reason for hiding this comment

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

does this need to be done here rather than in the config dictionary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's a converter attribute, but unfortunately this can't be done in the config file.

@vercel vercel bot temporarily deployed to Preview – dagit-storybook January 10, 2022 21:46 Inactive
@vercel vercel bot temporarily deployed to Preview – dagster January 10, 2022 21:46 Inactive
@vercel vercel bot temporarily deployed to Preview – dagster January 10, 2022 22:07 Inactive
@vercel vercel bot temporarily deployed to Preview – dagit-storybook January 10, 2022 22:07 Inactive
@rexledesma rexledesma merged commit 091cc2a into master Jan 11, 2022
@rexledesma rexledesma deleted the rl/logging-please branch January 11, 2022 17:43
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.

4 participants