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

Refactor logging architecture #81

Merged
merged 9 commits into from
Nov 13, 2024
Merged

Refactor logging architecture #81

merged 9 commits into from
Nov 13, 2024

Conversation

harshil21
Copy link
Member

@harshil21 harshil21 commented Nov 12, 2024

Changes:

  • LDP is now a TypedDict, because we were instantly destroying a class right after instantiation
  • Truncation now happens in logger process
  • Less code

Bug fix:

  • Predicted apogee is no longer logged with RawDataPackets

Performance:

Time to run test_integration.py:
On main: 19.42 seconds
This branch: 17.37 seconds

=> 10% faster

@harshil21 harshil21 added bug Something isn't working enhancement New feature or request labels Nov 12, 2024
@@ -158,61 +160,89 @@ def _log_the_buffer(self):
self._log_queue.put(buffered_message)
self._log_buffer.clear()

def _logging_loop(self) -> None:
def _truncate_decimal_place(self, obj_type: Any) -> str:
Copy link
Member

Choose a reason for hiding this comment

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

idk if I love this name but that's a nit, if you think of anything better, change it

This feels like it could be in utils, but if it's never going to be used anywhere else, make it a static method

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 think methods which will only be used by the logger should not be in utils.

But yeah I'm changing the name

return logged_data_packets

# ------------------------------- RUN IN A SEPARATE PROCESS -----------------------------------
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 here

Copy link
Member Author

Choose a reason for hiding this comment

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

it helps newcomers realize which methods run in a separate process

Copy link
Member

Choose a reason for hiding this comment

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

add this every other proceess then

airbrakes/data_handling/logger.py Show resolved Hide resolved
airbrakes/data_handling/logger.py Outdated Show resolved Hide resolved
writer.writeheader()

# Makes a queue to store log messages, basically it's a process-safe list that you add to
# the back and pop from front, meaning that things will be logged in the order they were
# added.
# Signals (like stop) are sent as strings, but data is sent as dictionaries
self._log_queue: multiprocessing.Queue[dict[str, str] | str] = multiprocessing.Queue()
self._log_queue: multiprocessing.Queue[LoggedDataPacket | Literal["STOP"]] = (
Copy link
Member

Choose a reason for hiding this comment

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

does it have to be "STOP"? Can this not be our stop signal constant?

Copy link
Member Author

Choose a reason for hiding this comment

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

not in a Literal type. It has to be an Enum, or a actual string like that.

@JacksonElia JacksonElia merged commit 1581c0b into main Nov 13, 2024
3 checks passed
@harshil21 harshil21 deleted the log-idp-in-ldp branch November 13, 2024 00:17
@harshil21 harshil21 mentioned this pull request Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants