-
Notifications
You must be signed in to change notification settings - Fork 183
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
For ResponseMetrics
middleware, improve view
tag and add tests
#4746
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @jwhitlock for making changes that help us get more detailed data on responses. I've made some suggestions but are not required.
This uses the logic from whitenoise.middleware.WhiteNoiseMiddleware.__call__: | ||
https://github.com/evansd/whitenoise/blob/220a98894495d407424e80d85d49227a5cf97e1b/src/whitenoise/middleware.py#L117-L124 | ||
""" | ||
if self.autorefresh: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(suggestion, non-blocking): Since we are using data that can come from user input I recommend using shlex.quote
on path_info
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, that would change the logic from .__call__
and break the function. See https://github.com/evansd/whitenoise/blob/220a98894495d407424e80d85d49227a5cf97e1b/src/whitenoise/middleware.py#L117-L124.
|
||
|
||
MIDDLEWARE = _get_initial_middleware() | ||
MIDDLEWARE = ["privaterelay.middleware.ResponseMetrics"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(suggestion, non-blocking) I agree with more simple logic on initial list of middlewares but not sure if the ResponseMetrics
should be used in all environment. STATSD_ENABLED
is False
in local:
Lines 14 to 15 in 2d8973e
DJANGO_STATSD_ENABLED=False | |
STATSD_DEBUG=False |
MIDDLEWARE = ["privaterelay.middleware.ResponseMetrics"] | |
if RELAY_CHANNEL == "local": | |
MIDDLEWARE = [] | |
else: | |
MIDDLEWARE = ["privaterelay.middleware.ResponseMetrics"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I retained the spirit of the old logic by making the ResponseMetrics
middleware do nothing if STATSD_ENABLED
is False. This reminds me, I have a TODO to enable STATSD_DEBUG
locally..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review @say-yawn!
if not settings.STATSD_ENABLED: | ||
return self.get_response(request) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where the middleware is disabled at run-time, if STATSD_ENABLED
is False.
This uses the logic from whitenoise.middleware.WhiteNoiseMiddleware.__call__: | ||
https://github.com/evansd/whitenoise/blob/220a98894495d407424e80d85d49227a5cf97e1b/src/whitenoise/middleware.py#L117-L124 | ||
""" | ||
if self.autorefresh: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, that would change the logic from .__call__
and break the function. See https://github.com/evansd/whitenoise/blob/220a98894495d407424e80d85d49227a5cf97e1b/src/whitenoise/middleware.py#L117-L124.
|
||
|
||
MIDDLEWARE = _get_initial_middleware() | ||
MIDDLEWARE = ["privaterelay.middleware.ResponseMetrics"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I retained the spirit of the old logic by making the ResponseMetrics
middleware do nothing if STATSD_ENABLED
is False. This reminds me, I have a TODO to enable STATSD_DEBUG
locally..
The
ResponseMetrics
middleware emits the timing metricfx.private.relay.response
. This gives us the application's view of the response time, bucketed by the hour. We use theview
tag to segment by views, to determine trends over time and slow periods.This PR improve the tag
view
in a few cases:/api/v1/runtime_data
, other API view functions. - The tag wasapi.views.privaterelay.view
. This is nowapi.views.privaterelay.runtime_data
. Other API view functions also had '.view' for the last component, and now use their function name./__heartbeat__
, other Dockerflow views - The tag was<unknown_view>
, and is nowdockerflow.django.views.heartbeat
. Similar changes are made for/__version__
and/__lbheartbeat__
.<unknown_view>
, and is now<static_file>
.This PR also includes tests for
ResponseMetrics
.How to test