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 tests #2

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Add tests #2

wants to merge 5 commits into from

Conversation

sheshtawy
Copy link
Contributor

No description provided.

@sheshtawy sheshtawy self-assigned this Nov 8, 2020
@sheshtawy sheshtawy changed the title WIP: Add tests Add tests Nov 8, 2020
Copy link

@arusahni arusahni left a comment

Choose a reason for hiding this comment

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

One more request (can't make it using the review tool because it hasn't been changed in this PR): Could we change the metrics_endpoint's default value to None (making it an Optional[str]? The current default reflects our internal convention (vs. something meaningful to Quart). Quart's default is None, so we should be able to punch that through.

quart_prometheus_logger.py Outdated Show resolved Hide resolved
app.register_error_handler(HTTPStatusException, abort_with_error)
app.before_request(
prometheus_before_request_callback,
prometheus_before_request_callback.__name__,

Choose a reason for hiding this comment

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

This parameter is not the name of the function (despite being called name). It is the name of the blueprint to which the handler is attached. Since this isn't attached to a specific blueprint, we shouldn't be providing a key.

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 understand. The reason I added a name, was to be able to test it and find it in the the before_request handlers, if I remove it, maybe I can adjust the unit tests to assert the count of handlers before and after registration?

quart_prometheus_logger.py Outdated Show resolved Hide resolved
@@ -66,14 +68,15 @@ def __init__(self, app: Optional[Quart] = None, metrics_endpoint: str = "root"):
self._collectors: Dict[str, MetricType] = {}
self._custom_labeler: Optional[Callable[["LocalProxy"], Dict[str, str]]] = None
self._custom_label_names: List[str] = []
self._registry = CollectorRegistry()

Choose a reason for hiding this comment

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

I'm fine with no longer using an explicitly-managed registry, but we should ensure this is identically instantiated. As of now, it is missing the auto_describe parameter.

Additionally, if folks want to manage it externally, I think it'd be useful to add this as an optional argument.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's a good idea

quart_prometheus_logger.py Show resolved Hide resolved
quart_prometheus_logger.py Outdated Show resolved Hide resolved
def custom_route_labeler(
self, labeler: Callable[["LocalProxy"], Dict[str, str]], label_names: List[str]
) -> None:
"""Add a handler for providing additional labels for a route.

This will reset all metrics. Conventionally it's called when the extension is first registered

:param labeler: The handler function to invoke. It must return a dict of key-value labels.
:param labeler: The handler function to invoke. It takes a Quart LocalProxy representing
the request, from which values for the custom label can be pulled. It must return

Choose a reason for hiding this comment

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

Instead of "pulled", maybe something a little more active like "constructed" or "generated"?

setup.py Outdated Show resolved Hide resolved
tests/test_quart_prometheus_logger.py Show resolved Hide resolved
tests/test_quart_prometheus_logger.py Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants