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, Add GitHub Graph Backend #2131

Merged
merged 24 commits into from
Feb 13, 2024
Merged

Conversation

ytausch
Copy link
Contributor

@ytausch ytausch commented Feb 2, 2024

Important

This PR is an extension of #2139. #2139 should be reviewed and merged first.

As part of my work on #2123, this PR adds the following changes:

  • The logger config is now handled centrally in setup_logging instead of configuring each module-level logger individually
  • Add an --online CLI option that downloads missing dependency graph files from GitHub on demand (uses the new GithubLazyJsonBackend)
  • Added tests

@ytausch ytausch changed the title Refactor Logging, Add GitHub Graph Backend, Refactor Logging, Add GitHub Graph Backend Feb 2, 2024
Copy link

codecov bot commented Feb 2, 2024

Codecov Report

Attention: 22 lines in your changes are missing coverage. Please review.

Comparison is base (e9ad40f) 73.21% compared to head (774aff0) 73.93%.

Files Patch % Lines
conda_forge_tick/lazy_json_backends.py 86.60% 15 Missing ⚠️
conda_forge_tick/auto_tick.py 60.00% 2 Missing ⚠️
conda_forge_tick/cli.py 86.66% 2 Missing ⚠️
conda_forge_tick/deploy.py 50.00% 1 Missing ⚠️
conda_forge_tick/pypi_name_mapping.py 50.00% 1 Missing ⚠️
conda_forge_tick/update_prs.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2131      +/-   ##
==========================================
+ Coverage   73.21%   73.93%   +0.72%     
==========================================
  Files          96       97       +1     
  Lines        9265     9435     +170     
==========================================
+ Hits         6783     6976     +193     
+ Misses       2482     2459      -23     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@0xbe7a 0xbe7a left a comment

Choose a reason for hiding this comment

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

As mentioned below, I think supporting writes is pretty straightforward and would allow all changes to be diffed. Otherwise LGTM

README.md Outdated Show resolved Hide resolved
conda_forge_tick/lazy_json_backends.py Show resolved Hide resolved
@ytausch ytausch marked this pull request as draft February 2, 2024 15:08
@xhochy
Copy link
Member

xhochy commented Feb 2, 2024

@ytausch Can you please separate out the LOGGER/logger changes into a separate PR to uncluter this diff?

Copy link
Contributor

@beckermr beckermr left a comment

Choose a reason for hiding this comment

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

I am still going through the PR but here are some initial comments.

conda_forge_tick/utils.py Show resolved Hide resolved
conda_forge_tick/update_prs.py Outdated Show resolved Hide resolved
conda_forge_tick/make_graph.py Show resolved Hide resolved
tests/test_lazy_json_backends.py Outdated Show resolved Hide resolved
tests/test_lazy_json_backends.py Outdated Show resolved Hide resolved
@ytausch
Copy link
Contributor Author

ytausch commented Feb 2, 2024

@ytausch Can you please separate out the LOGGER/logger changes into a separate PR to uncluter this diff?

Done in #2132

@ytausch ytausch marked this pull request as ready for review February 2, 2024 18:29
@ytausch ytausch requested a review from beckermr February 2, 2024 18:29
Copy link
Contributor

@beckermr beckermr left a comment

Choose a reason for hiding this comment

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

More comments. Sorry they are coming bit by bit. This diff makes non-trivial changes in more than one spot. A few suggestions.

  1. It appears something like isort was run on some of the files? Can we add this to pre-commit in another PR?

  2. Can the changes to the versions code and the lazyjson stuff be in two separate PRs?

  3. Have you run this code live locally? There can be subtle issues with changes in how the code is structured causing new and destructive I/O patterns. Whenever you do any operation on the "payload" object (called "attrs" in much of the code), the lazy json backends will do things like download the json, read it into memory, make calls to a DB etc. So how those operations are structured in the code is pretty important.

conda_forge_tick/cli.py Outdated Show resolved Hide resolved
conda_forge_tick/cli.py Show resolved Hide resolved
conda_forge_tick/utils.py Outdated Show resolved Hide resolved
conda_forge_tick/lazy_json_backends.py Outdated Show resolved Hide resolved
conda_forge_tick/lazy_json_backends.py Outdated Show resolved Hide resolved
conda_forge_tick/lazy_json_backends.py Show resolved Hide resolved
conda_forge_tick/lazy_json_backends.py Show resolved Hide resolved
@@ -1,16 +1,28 @@
import networkx as nx
Copy link
Contributor

Choose a reason for hiding this comment

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

These changes are pretty extensive. Is there a way we can add what you need without all of the refactoring here? The bot test suite is not good enough to detect bugs in the new code and I am worried this is going to fail once we run it live.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This discussion now belongs to #2139 - but let me give a short reply here: Of course the refactoring is not necessary but my point is that the code is now more modular, more descriptive, generates more helpful debug output, and can also be tested rather well.

Also, I did not introduce big structural changes so it should be possible to verify the correctness of my changes in a code review. Unit tests now cover the entirety of my changes.

@ytausch
Copy link
Contributor Author

ytausch commented Feb 5, 2024

  1. It appears something like isort was run on some of the files? Can we add this to pre-commit in another PR?

Actually it was the automatic Optimize Imports functionality of PyCharm. Since I could not identify a consistent ordering of the imports, I did not pay much attention to it. I will create a new PR now that adds isort as pre-commit hook.

  1. Can the changes to the versions code and the lazyjson stuff be in two separate PRs?

Do you mean separating the logic for updating a single package into another PR? I can do that, sure. As an explanation: I think the GitHub LazyJSON backend only makes sense if used for updating one single package. This is why I introduced both changes at once.

  1. Have you run this code live locally? There can be subtle issues with changes in how the code is structured causing new and destructive I/O patterns. Whenever you do any operation on the "payload" object (called "attrs" in much of the code), the lazy json backends will do things like download the json, read it into memory, make calls to a DB etc. So how those operations are structured in the code is pretty important.

I did not test the code with the MongoDB backend, only with the file backend locally. I don't think my changes should break something if the MongoDB backend adheres to the LazyJsonBackend specification but I will test it nonetheless. It's understandable that you want to be extra-cautious to not break production.

@ytausch ytausch changed the title Refactor Logging, Add GitHub Graph Backend Refactor Logging, Add GitHub Graph Backend, Single Package Update Feb 9, 2024
@ytausch ytausch marked this pull request as draft February 9, 2024 19:36
@ytausch ytausch changed the title Refactor Logging, Add GitHub Graph Backend, Single Package Update Refactor Logging, Add GitHub Graph Backend Feb 12, 2024
@ytausch ytausch marked this pull request as ready for review February 12, 2024 15:32
@ytausch ytausch requested a review from beckermr February 12, 2024 15:33
@ytausch
Copy link
Contributor Author

ytausch commented Feb 12, 2024

@beckermr Please note that this now depends on #2139

@ytausch
Copy link
Contributor Author

ytausch commented Feb 12, 2024

A note about your comment "did you test this live locally": I will now look into the possibility to develop a basic integration test that ensures basic functionality for future changes. This will be a separate PR.

@ytausch
Copy link
Contributor Author

ytausch commented Feb 13, 2024

I ran this though mypy and verified manually that my changes do not introduce new type issues.

Copy link
Contributor

@beckermr beckermr left a comment

Choose a reason for hiding this comment

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

LGTM! Nice work on the github backend!

@beckermr beckermr merged commit 982e137 into regro:master Feb 13, 2024
5 checks passed
@ytausch ytausch deleted the local_upgrade branch February 14, 2024 10:33
Comment on lines -397 to +404
def setup_logger(logger: logging.Logger, level: str = "INFO") -> None:
"""Basic configuration for logging"""
logger.setLevel(level.upper())
ch = logging.StreamHandler()
ch.setLevel(level.upper())
ch.setFormatter(
logging.Formatter("%(asctime)-15s %(levelname)-8s %(name)s || %(message)s"),
def setup_logging(level: str = "INFO") -> None:
logging.basicConfig(
format="%(asctime)-15s %(levelname)-8s %(name)s || %(message)s",
level=level.upper(),
)
logger.addHandler(ch)
# this prevents duplicate logging messages
logger.propagate = False
logging.getLogger("urllib3").setLevel(logging.INFO)
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like this change broke the bot

ref: regro/cf-graph-countyfair#19 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

Bot is functioning fine. It broke ci tests on that repo which are there only to double check manual changes.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's fair. Wrote that kind of tersely

Am not seeing this function used in the org. Are we getting an old package?

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.

5 participants