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

Fix TimerWrapper + Add response size metric #9

Merged
merged 4 commits into from
Dec 15, 2016

Conversation

Monichev
Copy link

@Monichev Monichev commented Dec 6, 2016

No description provided.

Copy link

@volker48 volker48 left a comment

Choose a reason for hiding this comment

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

Thank you.

@@ -63,7 +64,8 @@ def init_app(self, app, config=None):
Available Flask-Datadog config settings:

DATADOG_CONFIGURE_MIDDLEWARE - whether or not to setup response timing middleware (default: True)
DATADOG_RESPONSE_METRIC_NAME - the name of the response time metric (default: 'flask.response.time')
DATADOG_RESPONSE_TIME_METRIC_NAME - the name of the response time metric (default: 'flask.response.time')
Copy link

Choose a reason for hiding this comment

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

I'm going to leave the old name in as well for backwards compatibility.

self.config['DATADOG_RESPONSE_SAMPLE_RATE'])

# Emit response size metric
size = len(response.data)

Choose a reason for hiding this comment

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

Instead you could do int(response.headers['content-length']) since it should already have been computed.

I am not sure under what conditions content-length is not available, so maybe something like this would be better?

if 'content-length' in response.headers:
    size = int(response.headers['content-length'])
    self.statsd.increment(...)

Copy link
Author

Choose a reason for hiding this comment

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

I used len(response.data) because of the bug in jsonify: pallets/flask#1877.
content-length should work best for the size metric. I'll add workaround for jsonify content-length issue in my view functions.

self.config['DATADOG_RESPONSE_SAMPLE_RATE'])

# Emit response size metric
size = len(response.data)
self.statsd.increment(self.config['DATADOG_RESPONSE_SIZE_METRIC_NAME'],

Choose a reason for hiding this comment

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

This might be better as self.statsd.histogram(), doing increment would mean that we would be tracking the total response bytes per time period, e.g. "bytes per second" as opposed to "request response size". Although, I can see the value in someone wanting both metrics.

Also, with histogram, we'll get the nice .count, .max, .avg, .95percentile, .median computed metrics as well.

Copy link

Choose a reason for hiding this comment

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

Yeah, I think histogram would be better. Good call.

@Monichev
Copy link
Author

Monichev commented Dec 7, 2016

Comments have taken into account

@Monichev
Copy link
Author

Hey! What about the PR?

@volker48 volker48 merged commit 03597bd into 50onRed:master Dec 15, 2016
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.

None yet

3 participants