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 Slack functionality inside logger #2395

Merged
merged 6 commits into from
Jun 24, 2023

Conversation

Kerfred
Copy link
Contributor

@Kerfred Kerfred commented Jun 13, 2023

Fixes

Fixes #698 by @dhruvkb

Description

The slack logger is now handling the standard logging. Nomore need to add log.info(), log.error(), log.debug() when we are logging to slack.

Checklist

  • My pull request has a descriptive title (not a vague title likeUpdate index.md).
  • My pull request targets the default branch of the repository (main) or a parent feature branch.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible errors.
  • I ran the DAG documentation generator (if applicable).

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@Kerfred Kerfred requested a review from a team as a code owner June 13, 2023 08:49
@Kerfred Kerfred requested review from krysal and stacimc June 13, 2023 08:49
@openverse-bot openverse-bot added 🟩 priority: low Low priority and doesn't need to be rushed ✨ goal: improvement Improvement to an existing user-facing feature 💻 aspect: code Concerns the software code in the repository 🧱 stack: ingestion server Related to the ingestion/data refresh server labels Jun 13, 2023
@zackkrida
Copy link
Member

Hi @Kerfred this looks great! I've merged in the latest changes from main in an effort to fix our CI script and get all checks passing on your PR. There was a bug in our "PR Limit Reminders" CI check for which a fix was merged in #2396.

Maintainers should review your PR shortly.

@AetherUnbound AetherUnbound changed the title Add Slack functionality inside logger #698 Add Slack functionality inside logger Jun 15, 2023
Copy link
Collaborator

@AetherUnbound AetherUnbound left a comment

Choose a reason for hiding this comment

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

Thanks so much for your contribution @Kerfred! This PR just needs a few small changes then it should be ready 🙂

ingestion_server/ingestion_server/slack.py Show resolved Hide resolved
@@ -61,14 +61,17 @@ def _message(text: str, summary: str = None, level: Level = Level.INFO) -> None:


def verbose(text: str, summary: str = None) -> None:
log.debug(text)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This (and all other log calls in made by this PR) should have stacklevel=2 added to them:

Suggested change
log.debug(text)
log.debug(text, stacklevel=2)

This will ensure that when a log line is emitted from this module, it appears in the logs as if it came from the place where slack.verbose (or the other logging functions) were called. So rather than something like

DEBUG slack.py:63 - <the real message>

it'd say something like

DEBUG - indexer.py:102 - <the real message>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK

@Kerfred
Copy link
Contributor Author

Kerfred commented Jun 16, 2023

I have added stacklevel=2, commited and pushed again on the branch.

@AetherUnbound
Copy link
Collaborator

As I was testing this, I realized that because we're calling slack.info within slack.status, the stack level for stack.status calls will always show the log line within it. I think it might make the most sense to add stacklevel as a keyword argument to the other 3 slack module logging functions, with a default of 2. Then within slack.status, we can call info(text, None, stacklevel=3) so the logs show the line that slack.status was called from instead. Something like this:

diff --git a/ingestion_server/ingestion_server/slack.py b/ingestion_server/ingestion_server/slack.py
index 717f5dbda..f5246f353 100644
--- a/ingestion_server/ingestion_server/slack.py
+++ b/ingestion_server/ingestion_server/slack.py
@@ -65,8 +65,8 @@ def verbose(text: str, summary: str = None) -> None:
     _message(text, summary, level=Level.VERBOSE)
 
 
-def info(text: str, summary: str = None) -> None:
-    log.info(text, stacklevel=2)
+def info(text: str, summary: str = None, stacklevel: int = 2) -> None:
+    log.info(text, stacklevel=stacklevel)
     _message(text, summary, level=Level.INFO)
 
 
@@ -82,4 +82,4 @@ def status(model: str, text: str) -> None:
     Model is required an all messages get prepended with the model.
     """
     text = f"`{model}`: {text}"
-    info(text, None)
+    info(text, None, stacklevel=3)

What do you think?

fred added 3 commits June 21, 2023 07:45
Add stacklevel as an argument of the methods verbose(), info() and 
error()
@Kerfred
Copy link
Contributor Author

Kerfred commented Jun 21, 2023

As I was testing this, I realized that because we're calling slack.info within slack.status, the stack level for stack.status calls will always show the log line within it. I think it might make the most sense to add stacklevel as a keyword argument to the other 3 slack module logging functions, with a default of 2. Then within slack.status, we can call info(text, None, stacklevel=3) so the logs show the line that slack.status was called from instead. Something like this:

diff --git a/ingestion_server/ingestion_server/slack.py b/ingestion_server/ingestion_server/slack.py
index 717f5dbda..f5246f353 100644
--- a/ingestion_server/ingestion_server/slack.py
+++ b/ingestion_server/ingestion_server/slack.py
@@ -65,8 +65,8 @@ def verbose(text: str, summary: str = None) -> None:
     _message(text, summary, level=Level.VERBOSE)
 
 
-def info(text: str, summary: str = None) -> None:
-    log.info(text, stacklevel=2)
+def info(text: str, summary: str = None, stacklevel: int = 2) -> None:
+    log.info(text, stacklevel=stacklevel)
     _message(text, summary, level=Level.INFO)
 
 
@@ -82,4 +82,4 @@ def status(model: str, text: str) -> None:
     Model is required an all messages get prepended with the model.
     """
     text = f"`{model}`: {text}"
-    info(text, None)
+    info(text, None, stacklevel=3)

What do you think?

You are totally right. I have done the change.

Copy link
Collaborator

@stacimc stacimc 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 this @Kerfred! This looks great.

@openverse-bot
Copy link
Collaborator

Based on the low urgency of this PR, the following reviewers are being gently reminded to review this PR:

@krysal
This reminder is being automatically generated due to the urgency configuration.

Excluding weekend1 days, this PR was ready for review 7 day(s) ago. PRs labelled with low urgency are expected to be reviewed within 5 weekday(s)2.

@Kerfred, if this PR is not ready for a review, please draft it to prevent reviewers from getting further unnecessary pings.

Footnotes

  1. Specifically, Saturday and Sunday.

  2. For the purpose of these reminders we treat Monday - Friday as weekdays. Please note that the operation that generates these reminders runs at midnight UTC on Monday - Friday. This means that depending on your timezone, you may be pinged outside of the expected range.

Copy link
Collaborator

@AetherUnbound AetherUnbound left a comment

Choose a reason for hiding this comment

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

Tested this all locally and it worked perfectly! This is such an improvement, thanks a ton @Kerfred 😄

@AetherUnbound AetherUnbound merged commit 9dcb4e3 into WordPress:main Jun 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💻 aspect: code Concerns the software code in the repository ✨ goal: improvement Improvement to an existing user-facing feature 🟩 priority: low Low priority and doesn't need to be rushed 🧱 stack: ingestion server Related to the ingestion/data refresh server
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Add Slack functionality inside logger
5 participants