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

Convert messages to struct logs #6064

Merged
merged 37 commits into from
Oct 31, 2022
Merged

Convert messages to struct logs #6064

merged 37 commits into from
Oct 31, 2022

Conversation

emmyoop
Copy link
Member

@emmyoop emmyoop commented Oct 14, 2022

resolves #5957

Description

Convert msg to be built in struct logs

Checklist

@cla-bot cla-bot bot added the cla:yes label Oct 14, 2022
@emmyoop emmyoop changed the base branch from main to ct-1047-proto_structured_logging October 14, 2022 14:01
@github-actions
Copy link
Contributor

Thank you for your pull request! We could not find a changelog entry for this change. For details on how to document a change, see the contributing guide.

@emmyoop emmyoop added the Skip Changelog Skips GHA to check for changelog file label Oct 14, 2022
Comment on lines +1 to +16
import os
from typing import List
from dbt.constants import SECRET_ENV_PREFIX


def env_secrets() -> List[str]:
return [v for k, v in os.environ.items() if k.startswith(SECRET_ENV_PREFIX) and v.strip()]


def scrub_secrets(msg: str, secrets: List[str]) -> str:
scrubbed = msg

for secret in secrets:
scrubbed = scrubbed.replace(secret, "*****")

return scrubbed
Copy link
Member 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 love what I did here. These were moved out because of some circular dependency issues. I'm not sure they even belong in the /events dir since they're used in various places.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, but I can't think of a great place either. If a superior location emerges, we can move it.

@emmyoop emmyoop marked this pull request as ready for review October 14, 2022 16:03
@emmyoop emmyoop requested a review from a team as a code owner October 14, 2022 16:03
@emmyoop emmyoop requested a review from a team October 14, 2022 16:03
@emmyoop emmyoop requested review from a team as code owners October 14, 2022 16:03
@emmyoop
Copy link
Member Author

emmyoop commented Oct 14, 2022

Happy to wait on this until after the struct logging changes are merged in main - can change the target for the PR.

@emmyoop emmyoop requested review from peterallenwebb and removed request for a team, nathaniel-may and ChenyuLInx October 14, 2022 16:04
Base automatically changed from ct-1047-proto_structured_logging to main October 14, 2022 17:57
@gshank gshank requested a review from leahwicz as a code owner October 14, 2022 17:57
@emmyoop emmyoop force-pushed the er/ct-1267-convert-msg branch from 46511cb to d6c348e Compare October 14, 2022 19:28
Copy link
Contributor

@gshank gshank left a comment

Choose a reason for hiding this comment

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

This is a really good start. But I'd like us to handle the "warn_or_error" calls somewhat differently, and convert as many of the "GeneralWarningMsg" instances to specific events instead. So warn_or_error might look something like:

def warn_or_error(event, node):
    if flags.WARN_ERROR:
        from dbt.exceptions import raise_compiler_error

        raise_compiler_error(scrub_secrets(event.info.msg, env_secrets()), node)
    else:
        fire_event(event)

We're also going to be doing some work on handling and logging exceptions better too, so that "raise_compiler_error" is also likely to see some changes.

One thing people who consume our logs is asking for is being able to categorize the log events and exceptions, and that GeneralWarningMsg does not help.

@emmyoop emmyoop requested a review from gshank October 24, 2022 20:49
Copy link
Contributor

@gshank gshank 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 really good! It's so big it's possible I missed something, but I didn't see any issues.

Comment on lines +1 to +16
import os
from typing import List
from dbt.constants import SECRET_ENV_PREFIX


def env_secrets() -> List[str]:
return [v for k, v in os.environ.items() if k.startswith(SECRET_ENV_PREFIX) and v.strip()]


def scrub_secrets(msg: str, secrets: List[str]) -> str:
scrubbed = msg

for secret in secrets:
scrubbed = scrubbed.replace(secret, "*****")

return scrubbed
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, but I can't think of a great place either. If a superior location emerges, we can move it.

@@ -1327,7 +1327,7 @@ def catch_as_completed(
elif isinstance(exc, KeyboardInterrupt) or not isinstance(exc, Exception):
raise exc
else:
warn_or_error(f"Encountered an error while generating catalog: {str(exc)}")
warn_or_error(CatalogGenerationError(exc=str(exc)))
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: this paradigm of stringifying arguments to event types now has the option of adding this class as a subclass to the event class definition.

Copy link
Member Author

Choose a reason for hiding this comment

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

That class is super cool. However, it is causing some issues because protobuf requires us to define the type of each field being passed in in a very narrow scope (types cannot be classes ie Exception). So exc comes in as an Exception and then does become a string in the message but that's not enough since proto expects the field itself to be a string already.

@emmyoop
Copy link
Member Author

emmyoop commented Oct 31, 2022

Close and reopen to try to trigger tests to run.

@emmyoop emmyoop closed this Oct 31, 2022
@emmyoop emmyoop reopened this Oct 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla:yes Skip Changelog Skips GHA to check for changelog file
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CT-1267] Convert non-structured messages generated in exceptions.py to structured events
5 participants