-
Notifications
You must be signed in to change notification settings - Fork 193
Add a mechanism to silence noisy s3 simulator logs #2945
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
Open
G-D-Petrov
wants to merge
7
commits into
master
Choose a base branch
from
gpetrov/silence_s3_sim_logs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
782576c
Add a way to silence noisy s3 simulator logs
G-D-Petrov b73aac1
Restore mark file
G-D-Petrov d338177
Apply suggestions from code review
G-D-Petrov 8697186
Add contextlib import to s3.py for improved resource management
G-D-Petrov 9028893
Fix errors
G-D-Petrov c46a499
Refactor S3 server logging configuration to use strtobool for environ…
G-D-Petrov 18b9b3a
Apply suggestions from code review
G-D-Petrov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,11 +24,13 @@ | |
| from typing import Optional, Any, Type | ||
|
|
||
| import werkzeug | ||
| from werkzeug.serving import WSGIRequestHandler | ||
| import botocore.exceptions | ||
| from moto.server import DomainDispatcherApplication, create_backend_app | ||
|
|
||
| from arcticdb.storage_fixtures.azure import AzureStorageFixtureFactory | ||
| from arcticdb.util.logger import get_logger | ||
| from arcticdb.util.utils import strtobool | ||
|
|
||
| from .api import * | ||
| from .utils import ( | ||
|
|
@@ -56,6 +58,36 @@ | |
| logger = logging.getLogger("S3 Storage Fixture") | ||
|
|
||
|
|
||
| def _configure_moto_server_logging(verbose: bool) -> None: | ||
| if verbose: | ||
| return | ||
|
|
||
| werkzeug_logger = logging.getLogger("werkzeug") | ||
| werkzeug_logger.propagate = False | ||
| werkzeug_logger.setLevel(logging.ERROR) | ||
|
|
||
|
|
||
| def _suppress_moto_server_stdio(verbose: bool) -> None: | ||
| if verbose: | ||
| return | ||
|
|
||
| with open(os.devnull, "w") as devnull: | ||
| os.dup2(devnull.fileno(), sys.stdout.fileno()) | ||
| os.dup2(devnull.fileno(), sys.stderr.fileno()) | ||
|
|
||
|
|
||
| class _QuietMotoRequestHandler(WSGIRequestHandler): | ||
| def log(self, type, message, *args): | ||
| return | ||
|
|
||
| def log_request(self, code="-", size="-"): | ||
| return | ||
|
|
||
| def log_error(self, format, *args): | ||
| super().log_error(format, *args) | ||
| return | ||
|
|
||
|
|
||
| class Key: | ||
| def __init__(self, *, id: str, secret: str, user_name: str): | ||
| self.id = id | ||
|
|
@@ -769,22 +801,32 @@ def __call__(self, environ, start_response): | |
|
|
||
|
|
||
| def run_s3_server(port, key_file, cert_file): | ||
| verbose = strtobool("ARCTICDB_MOTO_VERBOSE") | ||
|
G-D-Petrov marked this conversation as resolved.
Outdated
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Claude is right about this one, strtobool only converts to true/false but does not read the env. So you'd have to os.environ.get first |
||
| _configure_moto_server_logging(verbose) | ||
|
G-D-Petrov marked this conversation as resolved.
|
||
| _suppress_moto_server_stdio(verbose) | ||
| request_handler = None if verbose else _QuietMotoRequestHandler | ||
| werkzeug.run_simple( | ||
| "0.0.0.0", | ||
| port, | ||
| HostDispatcherApplication(create_backend_app), | ||
| threaded=True, | ||
| ssl_context=(cert_file, key_file) if cert_file and key_file else None, | ||
| request_handler=request_handler, | ||
| ) | ||
|
|
||
|
|
||
| def run_gcp_server(port, key_file, cert_file): | ||
| verbose = strtobool("ARCTICDB_MOTO_VERBOSE") | ||
|
G-D-Petrov marked this conversation as resolved.
Outdated
|
||
| _configure_moto_server_logging(verbose) | ||
| _suppress_moto_server_stdio(verbose) | ||
| request_handler = None if verbose else _QuietMotoRequestHandler | ||
| werkzeug.run_simple( | ||
| "0.0.0.0", | ||
| port, | ||
| GcpHostDispatcherApplication(create_backend_app), | ||
| threaded=True, | ||
| ssl_context=(cert_file, key_file) if cert_file and key_file else None, | ||
| request_handler=request_handler, | ||
| ) | ||
|
|
||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.