Skip to content

Fixing logging prefect config #18666 #18670

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

chethanuk
Copy link

@chethanuk chethanuk commented Aug 7, 2025

AI Summary (@zzstoatzz i put this here)

This pull request improves how Prefect handles logging-related configuration overrides by introducing stricter validation for PREFECT_LOGGING_* settings and updating the settings system to support these overrides securely and consistently. The changes include a new shared validation module, updates to the CLI and settings profile logic, and comprehensive tests to ensure only safe logging override keys are accepted.

Validation and support for logging settings:

  • Added a new prefect.settings.validation module with utility functions (is_valid_logging_setting, is_setting_or_valid_logging, should_allow_string_key) to validate and distinguish PREFECT_LOGGING_* override keys, ensuring only safe, documented patterns are accepted.
  • Updated the CLI config set command to accept valid logging override keys using the new validation logic, and reject invalid or unsafe keys. [1] [2]

Settings profile and environment variable handling:

  • Modified the Profile settings logic to allow string keys for valid logging overrides, keep them as strings internally, and ensure they are correctly converted to environment variables. Only standard settings are validated through the model; logging overrides are passed through as-is. [1] [2]

Testing and validation coverage:

  • Added comprehensive tests for the new validation logic, including acceptance of valid logging override keys, rejection of invalid patterns, and correct storage and retrieval in profiles. [1] [2]
  • Imported the new validation helpers in relevant test and CLI modules to ensure consistent behavior.

These changes improve security and flexibility for logging configuration while maintaining backwards compatibility for user profiles and CLI workflows.

Copy link

codspeed-hq bot commented Aug 7, 2025

CodSpeed Performance Report

Merging #18670 will degrade performances by 12.32%

Comparing chethanuk:logging-config (69c3568) with main (250702a)

Summary

❌ 1 regressions
✅ 1 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
bench_import_prefect_flow 1.4 s 1.5 s -12.32%

Copy link
Collaborator

@zzstoatzz zzstoatzz left a comment

Choose a reason for hiding this comment

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

hi @chethanuk - thanks for the PR! this is making sense to me

cc @desertaxle for another set of eyes

Copy link
Member

@desertaxle desertaxle left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @chethanuk, but I think this still needs some more work. There are a couple of issues with this PR that make it so it doesn't solve the associated issue.

  1. If I use prefect config set to set a custom logging setting, then prefect config view breaks:
~/d/c/prefect ❯❯❯ uv run prefect config set PREFECT_LOGGING_HANDLER_CONSOLE_LEVEL=WARNING
Set 'PREFECT_LOGGING_HANDLER_CONSOLE_LEVEL' to 'WARNING'.
Updated profile 'local-pg'.
~/d/c/prefect ❯❯❯ uv run prefect config view                                        
PREFECT_PROFILE='local-pg'
Traceback (most recent call last):
  File "/Users/alexander/dev/chethanuk/prefect/src/prefect/cli/_utilities.py", line 44, in wrapper
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "/Users/alexander/dev/chethanuk/prefect/src/prefect/cli/config.py", line 290, in view
    if setting.name not in processed_settings:
       ^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'name'
  1. The current logic for loading logging configuration (load_logging_config in src/prefect/logging/configuration.py) won't pick up custom logging variables set via prefect config set because these custom logging settings aren't included when you call get_current_settings.

These are tricky problems to solve, but my recommendation is to update LoggingSettings in src/prefect/settings/models/logging.py to enable it to load these custom logging settings. That likely will require custom sources that are extended from our current sources in src/prefect/settings/sources.py.

This is definitely something that we want to fix, so let me know how we can best support you in fixing this issue!

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