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 codes to log events #4268

Closed
wants to merge 21 commits into from
Closed

add codes to log events #4268

wants to merge 21 commits into from

Conversation

nathaniel-may
Copy link
Contributor

@nathaniel-may nathaniel-may commented Nov 10, 2021

wait to merge into the feature branch till #4266 is in.

Description

Uses mypy to enforce codes that uniquely identify each log event. This allows consumers of structured logs to rely on these codes while giving developers the freedom to change class names.

The proposed format for codes is one capital letter followed by 3 digits:
aka ^[A-Z][0-9]{3} E.g. - A123, E003 etc.

The letter is determined by where the log line was fired. e.g. - parsing, node status, sql, adapter, deps etc.

TODO

  • get format approved by team
  • add concrete codes to each class
  • change base branch of PR back to feature/logging-phase2

Checklist

  • I have signed the CLA
  • I have run this code in development and it appears to resolve the stated issue
  • This PR includes tests, or tests are not required/relevant for this PR
  • I have updated the CHANGELOG.md and added information about my change

@cla-bot cla-bot bot added the cla:yes label Nov 10, 2021
@nathaniel-may nathaniel-may changed the title infrastructure for codes, with no actual codes add codes to log events Nov 10, 2021
@nathaniel-may nathaniel-may mentioned this pull request Nov 11, 2021
26 tasks
@nathaniel-may nathaniel-may force-pushed the logging-codes branch 2 times, most recently from c123e61 to 1236df8 Compare November 12, 2021 00:20
Copy link
Member

@emmyoop emmyoop left a comment

Choose a reason for hiding this comment

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

Is there a difference between code and returncode?

Comment on lines 269 to 272
code: int
returncode: int

def message(self) -> str:
return f"command return code={self.code}"
Copy link
Member

Choose a reason for hiding this comment

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

Should use the renamed version - self.returncode

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes! thank you.

@@ -266,7 +266,7 @@ def message(self) -> str:

@dataclass
class SystemReportReturnCode(DebugLevel, Cli, File):
code: int
returncode: int
Copy link
Member

Choose a reason for hiding this comment

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

Why is this an int instead of a string?

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 think I just guessed. I'll change it to a string. Mypy should tell us once we put all the concrete codes in place and satisfy those abstract method errors.

@nathaniel-may
Copy link
Contributor Author

nathaniel-may commented Nov 15, 2021

@emmyoop returncode is specific to the log event SystemReportReturnCode. code on the otherhand is a new field that mypy will enforce is on every log event to uniquely identify each event. I just had to resolve the name collision.

@nathaniel-may nathaniel-may force-pushed the logging-codes branch 2 times, most recently from 48f5a17 to eff0f6a Compare November 16, 2021 14:34
@nathaniel-may nathaniel-may changed the base branch from logging-cosmetics to main November 16, 2021 14:49
@iknox-fa
Copy link
Contributor

iknox-fa commented Nov 16, 2021

A proposal for event code prefixes:

Code Description
A Pre-project parsing
E DB adapter
I Project parsing
M Deps generation
Q Node processing
W Post processing
Z Misc

The basic idea is that the event code prefixes represent the usual flow through a end-user experience of running a dbt task. It has the benefit of being able to intuit how far things have gotten at the point of the event for the purposes of troubleshooting.

Comment on lines +63 to +64
def code(cls) -> str:
raise Exception("code() not implemented for event")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here's the abstract method that's doing the enforcement via mypy. I couldn't figure out how to make mypy check that subclasses have defined an abstract property even though the internet seems to think you can do that. You'll need to do one of two things to get this to work:

  1. figure out how to make an abstract property such that if you delete code from one of the concrete classes, mypy fails.
  2. change all the codes from fields to functions that override this one in each of the concrete classes.

Copy link
Contributor Author

@nathaniel-may nathaniel-may Nov 19, 2021

Choose a reason for hiding this comment

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

I just tried this by commenting out the code on one of the concrete tests and running mypy, and it worked. I'm not sure why though. @iknox-fa do you know why a @dataclass field named code in the concrete classes counts as overriding this abstract method??

Copy link
Contributor

Choose a reason for hiding this comment

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

Because it's now an abstract property.... and data fields are just automagic properties generated by an automagic __init__ method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

too implicit for my liking, but I'm glad it works.

#
# The basic idea is that event codes roughly translate to the natural order of running a dbt task

# can't use ABCs with @dataclass because of https://github.com/python/mypy/issues/5374
@dataclass
@dataclass # type: ignore
Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh wow I didn't even think of doing this. we can get rid of the comment that says we can't do this then.

@iknox-fa iknox-fa closed this Nov 22, 2021
iknox-fa added a commit that referenced this pull request Nov 22, 2021
iknox-fa added a commit that referenced this pull request Feb 8, 2022
* re-work of old branch

automatic commit by git-black, original commits:
  e1a2e8d
@iknox-fa iknox-fa deleted the logging-codes branch January 31, 2023 01:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants