2013-09-20 01:00:54 +08:00
|
|
|
# Copyright (c) 2010-2011 OpenStack Foundation
|
2012-05-24 21:15:51 -07:00
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
|
|
# implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
import unittest
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
from logging.handlers import SysLogHandler
|
2015-05-27 18:01:37 +02:00
|
|
|
|
2013-11-22 16:59:09 -05:00
|
|
|
import mock
|
2015-05-27 18:01:37 +02:00
|
|
|
from six import BytesIO
|
2015-10-08 15:03:52 +02:00
|
|
|
from six.moves.urllib.parse import unquote
|
2012-05-24 21:15:51 -07:00
|
|
|
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
from test.unit import FakeLogger
|
2015-07-09 23:10:05 -04:00
|
|
|
from swift.common.utils import get_logger, split_path
|
2012-05-24 21:15:51 -07:00
|
|
|
from swift.common.middleware import proxy_logging
|
Invert which proxy logging middleware instance logs
Prior to this patch the proxy_logging middleware always prepared to
read the response and process it for access logging, where the
proxy_logging instance first to handle the response bytes marked the
request as "logged".
This meant that the proxy_logging instance immediately before the
proxy-server app (right most in the pipeline, if properly setup) would
always log the responses for all the client requests, regardless if
middleware to the left of it still had processing to do for the
response. This would break SLO, where the slo middleware passed along
the GET of the manifest, unchanged from the client, so that the right
most proxy logging middleware would log the sponse for just the
manifest, but then the slo middleware would fetch all the segments of
the manifest, feeding them out in the response to the client, the
request now marked as "logged" so that the left most proxy logging
middleware would not log it.
This patch inverts this behavior so that now the first proxy_logging
middleware instance to receive a request in the pipeline marks that
request as handling it. So now, the left most proxy_logging middleware
handles logging for all client reaquests, and the right most
proxy_logging middleware handles all other requests initiated from
within the pipeline to its left.
Closes bug: 1297438
Change-Id: Ia3561523db76c693e4e0b2c38f461544dfcee086
2014-03-25 15:56:44 -04:00
|
|
|
from swift.common.swob import Request, Response
|
2014-05-20 17:28:19 -07:00
|
|
|
from swift.common import constraints
|
2015-07-09 23:10:05 -04:00
|
|
|
from swift.common.storage_policy import StoragePolicy
|
|
|
|
from test.unit import patch_policies
|
2016-06-07 13:41:55 +01:00
|
|
|
from test.unit.common.middleware.helpers import FakeAppThatExcepts
|
2012-05-24 21:15:51 -07:00
|
|
|
|
|
|
|
|
|
|
|
class FakeApp(object):
|
2013-08-31 23:42:43 -04:00
|
|
|
|
2015-07-09 23:10:05 -04:00
|
|
|
def __init__(self, body=None, response_str='200 OK', policy_idx='0'):
|
2014-05-10 05:15:12 -05:00
|
|
|
if body is None:
|
|
|
|
body = ['FAKE APP']
|
|
|
|
|
2012-05-24 21:15:51 -07:00
|
|
|
self.body = body
|
2013-01-19 10:57:14 -08:00
|
|
|
self.response_str = response_str
|
2015-07-09 23:10:05 -04:00
|
|
|
self.policy_idx = policy_idx
|
2012-05-24 21:15:51 -07:00
|
|
|
|
|
|
|
def __call__(self, env, start_response):
|
2015-07-09 23:10:05 -04:00
|
|
|
try:
|
|
|
|
# /v1/a/c or /v1/a/c/o
|
|
|
|
split_path(env['PATH_INFO'], 3, 4, True)
|
|
|
|
is_container_or_object_req = True
|
|
|
|
except ValueError:
|
|
|
|
is_container_or_object_req = False
|
|
|
|
|
|
|
|
headers = [('Content-Type', 'text/plain'),
|
|
|
|
('Content-Length', str(sum(map(len, self.body))))]
|
|
|
|
if is_container_or_object_req and self.policy_idx is not None:
|
|
|
|
headers.append(('X-Backend-Storage-Policy-Index',
|
|
|
|
str(self.policy_idx)))
|
|
|
|
|
|
|
|
start_response(self.response_str, headers)
|
2012-05-24 21:15:51 -07:00
|
|
|
while env['wsgi.input'].read(5):
|
|
|
|
pass
|
|
|
|
return self.body
|
|
|
|
|
|
|
|
|
2012-06-13 00:40:44 +00:00
|
|
|
class FakeAppNoContentLengthNoTransferEncoding(object):
|
2013-08-31 23:42:43 -04:00
|
|
|
|
2014-05-10 05:15:12 -05:00
|
|
|
def __init__(self, body=None):
|
|
|
|
if body is None:
|
|
|
|
body = ['FAKE APP']
|
|
|
|
|
2012-06-13 00:40:44 +00:00
|
|
|
self.body = body
|
|
|
|
|
|
|
|
def __call__(self, env, start_response):
|
|
|
|
start_response('200 OK', [('Content-Type', 'text/plain')])
|
|
|
|
while env['wsgi.input'].read(5):
|
|
|
|
pass
|
|
|
|
return self.body
|
|
|
|
|
|
|
|
|
2012-05-24 21:15:51 -07:00
|
|
|
class FileLikeExceptor(object):
|
2013-08-31 23:42:43 -04:00
|
|
|
|
2012-05-24 21:15:51 -07:00
|
|
|
def __init__(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def read(self, len):
|
|
|
|
raise IOError('of some sort')
|
|
|
|
|
|
|
|
def readline(self, len=1024):
|
|
|
|
raise IOError('of some sort')
|
|
|
|
|
|
|
|
|
|
|
|
class FakeAppReadline(object):
|
2013-08-31 23:42:43 -04:00
|
|
|
|
2012-05-24 21:15:51 -07:00
|
|
|
def __call__(self, env, start_response):
|
2012-06-01 15:59:07 +00:00
|
|
|
start_response('200 OK', [('Content-Type', 'text/plain'),
|
2013-08-31 23:42:43 -04:00
|
|
|
('Content-Length', '8')])
|
2013-03-26 20:42:26 +00:00
|
|
|
env['wsgi.input'].readline()
|
2012-05-24 21:15:51 -07:00
|
|
|
return ["FAKE APP"]
|
|
|
|
|
|
|
|
|
|
|
|
def start_response(*args):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2015-07-09 23:10:05 -04:00
|
|
|
@patch_policies([StoragePolicy(0, 'zero', False)])
|
2012-05-24 21:15:51 -07:00
|
|
|
class TestProxyLogging(unittest.TestCase):
|
2013-01-19 10:57:14 -08:00
|
|
|
def _log_parts(self, app, should_be_empty=False):
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
info_calls = app.access_logger.log_dict['info']
|
2013-01-19 10:57:14 -08:00
|
|
|
if should_be_empty:
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual([], info_calls)
|
2013-01-19 10:57:14 -08:00
|
|
|
else:
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual(1, len(info_calls))
|
2013-01-19 10:57:14 -08:00
|
|
|
return info_calls[0][0][0].split(' ')
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
|
|
|
|
def assertTiming(self, exp_metric, app, exp_timing=None):
|
|
|
|
timing_calls = app.access_logger.log_dict['timing']
|
2013-01-19 10:57:14 -08:00
|
|
|
found = False
|
|
|
|
for timing_call in timing_calls:
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual({}, timing_call[1])
|
|
|
|
self.assertEqual(2, len(timing_call[0]))
|
2013-01-19 10:57:14 -08:00
|
|
|
if timing_call[0][0] == exp_metric:
|
|
|
|
found = True
|
|
|
|
if exp_timing is not None:
|
|
|
|
self.assertAlmostEqual(exp_timing, timing_call[0][1],
|
|
|
|
places=4)
|
|
|
|
if not found:
|
2017-06-21 11:58:20 +02:00
|
|
|
self.fail('assertTiming: %s not found in %r' % (
|
2013-01-19 10:57:14 -08:00
|
|
|
exp_metric, timing_calls))
|
|
|
|
|
|
|
|
def assertTimingSince(self, exp_metric, app, exp_start=None):
|
|
|
|
timing_calls = app.access_logger.log_dict['timing_since']
|
|
|
|
found = False
|
|
|
|
for timing_call in timing_calls:
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual({}, timing_call[1])
|
|
|
|
self.assertEqual(2, len(timing_call[0]))
|
2013-01-19 10:57:14 -08:00
|
|
|
if timing_call[0][0] == exp_metric:
|
|
|
|
found = True
|
|
|
|
if exp_start is not None:
|
|
|
|
self.assertAlmostEqual(exp_start, timing_call[0][1],
|
|
|
|
places=4)
|
|
|
|
if not found:
|
2017-06-21 11:58:20 +02:00
|
|
|
self.fail('assertTimingSince: %s not found in %r' % (
|
2013-01-19 10:57:14 -08:00
|
|
|
exp_metric, timing_calls))
|
|
|
|
|
|
|
|
def assertNotTiming(self, not_exp_metric, app):
|
|
|
|
timing_calls = app.access_logger.log_dict['timing']
|
|
|
|
for timing_call in timing_calls:
|
|
|
|
self.assertNotEqual(not_exp_metric, timing_call[0][0])
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
|
2015-07-09 23:10:05 -04:00
|
|
|
def assertUpdateStats(self, exp_metrics_and_values, app):
|
|
|
|
update_stats_calls = sorted(app.access_logger.log_dict['update_stats'])
|
|
|
|
got_metrics_values_and_kwargs = [(usc[0][0], usc[0][1], usc[1])
|
|
|
|
for usc in update_stats_calls]
|
|
|
|
exp_metrics_values_and_kwargs = [(emv[0], emv[1], {})
|
|
|
|
for emv in exp_metrics_and_values]
|
|
|
|
self.assertEqual(got_metrics_values_and_kwargs,
|
|
|
|
exp_metrics_values_and_kwargs)
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
|
|
|
|
def test_log_request_statsd_invalid_stats_types(self):
|
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(FakeApp(), {})
|
|
|
|
app.access_logger = FakeLogger()
|
|
|
|
for url in ['/', '/foo', '/foo/bar', '/v1']:
|
|
|
|
req = Request.blank(url, environ={'REQUEST_METHOD': 'GET'})
|
|
|
|
resp = app(req.environ, start_response)
|
2013-03-26 20:42:26 +00:00
|
|
|
# get body
|
|
|
|
''.join(resp)
|
2013-01-19 10:57:14 -08:00
|
|
|
self.assertEqual([], app.access_logger.log_dict['timing'])
|
|
|
|
self.assertEqual([], app.access_logger.log_dict['update_stats'])
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
|
|
|
|
def test_log_request_stat_type_bad(self):
|
|
|
|
for bad_path in ['', '/', '/bad', '/baddy/mc_badderson', '/v1',
|
|
|
|
'/v1/']:
|
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(FakeApp(), {})
|
|
|
|
app.access_logger = FakeLogger()
|
|
|
|
req = Request.blank(bad_path, environ={'REQUEST_METHOD': 'GET'})
|
2013-09-19 16:56:07 -04:00
|
|
|
now = 10000.0
|
|
|
|
app.log_request(req, 123, 7, 13, now, now + 2.71828182846)
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
self.assertEqual([], app.access_logger.log_dict['timing'])
|
|
|
|
self.assertEqual([], app.access_logger.log_dict['update_stats'])
|
|
|
|
|
|
|
|
def test_log_request_stat_type_good(self):
|
2013-01-19 10:57:14 -08:00
|
|
|
"""
|
|
|
|
log_request() should send timing and byte-count counters for GET
|
|
|
|
requests. Also, __call__()'s iter_response() function should
|
|
|
|
statsd-log time to first byte (calling the passed-in start_response
|
|
|
|
function), but only for GET requests.
|
|
|
|
"""
|
|
|
|
stub_times = []
|
2013-08-31 23:42:43 -04:00
|
|
|
|
2013-01-19 10:57:14 -08:00
|
|
|
def stub_time():
|
|
|
|
return stub_times.pop(0)
|
|
|
|
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
path_types = {
|
|
|
|
'/v1/a': 'account',
|
|
|
|
'/v1/a/': 'account',
|
|
|
|
'/v1/a/c': 'container',
|
|
|
|
'/v1/a/c/': 'container',
|
|
|
|
'/v1/a/c/o': 'object',
|
|
|
|
'/v1/a/c/o/': 'object',
|
|
|
|
'/v1/a/c/o/p': 'object',
|
|
|
|
'/v1/a/c/o/p/': 'object',
|
|
|
|
'/v1/a/c/o/p/p2': 'object',
|
|
|
|
}
|
2013-11-22 16:59:09 -05:00
|
|
|
with mock.patch("time.time", stub_time):
|
2015-06-24 09:36:37 +02:00
|
|
|
for path, exp_type in path_types.items():
|
2013-01-19 10:57:14 -08:00
|
|
|
# GET
|
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(
|
|
|
|
FakeApp(body='7654321', response_str='321 Fubar'), {})
|
|
|
|
app.access_logger = FakeLogger()
|
|
|
|
req = Request.blank(path, environ={
|
|
|
|
'REQUEST_METHOD': 'GET',
|
2015-05-27 18:01:37 +02:00
|
|
|
'wsgi.input': BytesIO(b'4321')})
|
2013-01-19 10:57:14 -08:00
|
|
|
stub_times = [18.0, 20.71828182846]
|
|
|
|
iter_response = app(req.environ, lambda *_: None)
|
2015-07-09 23:10:05 -04:00
|
|
|
|
2013-01-19 10:57:14 -08:00
|
|
|
self.assertEqual('7654321', ''.join(iter_response))
|
|
|
|
self.assertTiming('%s.GET.321.timing' % exp_type, app,
|
|
|
|
exp_timing=2.71828182846 * 1000)
|
|
|
|
self.assertTimingSince(
|
|
|
|
'%s.GET.321.first-byte.timing' % exp_type, app,
|
|
|
|
exp_start=18.0)
|
2015-07-09 23:10:05 -04:00
|
|
|
if exp_type == 'object':
|
|
|
|
# Object operations also return stats by policy
|
|
|
|
# In this case, the value needs to match the timing for GET
|
|
|
|
self.assertTiming('%s.policy.0.GET.321.timing' % exp_type,
|
|
|
|
app, exp_timing=2.71828182846 * 1000)
|
|
|
|
self.assertUpdateStats([('%s.GET.321.xfer' % exp_type,
|
|
|
|
4 + 7),
|
|
|
|
('object.policy.0.GET.321.xfer',
|
|
|
|
4 + 7)],
|
|
|
|
app)
|
|
|
|
else:
|
|
|
|
self.assertUpdateStats([('%s.GET.321.xfer' % exp_type,
|
|
|
|
4 + 7)],
|
|
|
|
app)
|
|
|
|
|
|
|
|
# GET Repeat the test above, but with a non-existent policy
|
|
|
|
# Do this only for object types
|
|
|
|
if exp_type == 'object':
|
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(
|
|
|
|
FakeApp(body='7654321', response_str='321 Fubar',
|
|
|
|
policy_idx='-1'), {})
|
|
|
|
app.access_logger = FakeLogger()
|
|
|
|
req = Request.blank(path, environ={
|
|
|
|
'REQUEST_METHOD': 'GET',
|
|
|
|
'wsgi.input': BytesIO(b'4321')})
|
|
|
|
stub_times = [18.0, 20.71828182846]
|
|
|
|
iter_response = app(req.environ, lambda *_: None)
|
|
|
|
|
|
|
|
self.assertEqual('7654321', ''.join(iter_response))
|
|
|
|
self.assertTiming('%s.GET.321.timing' % exp_type, app,
|
|
|
|
exp_timing=2.71828182846 * 1000)
|
|
|
|
self.assertTimingSince(
|
|
|
|
'%s.GET.321.first-byte.timing' % exp_type, app,
|
|
|
|
exp_start=18.0)
|
|
|
|
# No results returned for the non-existent policy
|
|
|
|
self.assertUpdateStats([('%s.GET.321.xfer' % exp_type,
|
|
|
|
4 + 7)],
|
|
|
|
app)
|
2013-01-19 10:57:14 -08:00
|
|
|
|
|
|
|
# GET with swift.proxy_access_log_made already set
|
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(
|
|
|
|
FakeApp(body='7654321', response_str='321 Fubar'), {})
|
|
|
|
app.access_logger = FakeLogger()
|
|
|
|
req = Request.blank(path, environ={
|
|
|
|
'REQUEST_METHOD': 'GET',
|
|
|
|
'swift.proxy_access_log_made': True,
|
2015-05-27 18:01:37 +02:00
|
|
|
'wsgi.input': BytesIO(b'4321')})
|
2013-01-19 10:57:14 -08:00
|
|
|
stub_times = [18.0, 20.71828182846]
|
|
|
|
iter_response = app(req.environ, lambda *_: None)
|
|
|
|
self.assertEqual('7654321', ''.join(iter_response))
|
|
|
|
self.assertEqual([], app.access_logger.log_dict['timing'])
|
2013-08-31 23:42:43 -04:00
|
|
|
self.assertEqual([],
|
|
|
|
app.access_logger.log_dict['timing_since'])
|
|
|
|
self.assertEqual([],
|
|
|
|
app.access_logger.log_dict['update_stats'])
|
2013-01-19 10:57:14 -08:00
|
|
|
|
|
|
|
# PUT (no first-byte timing!)
|
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(
|
|
|
|
FakeApp(body='87654321', response_str='314 PiTown'), {})
|
|
|
|
app.access_logger = FakeLogger()
|
|
|
|
req = Request.blank(path, environ={
|
|
|
|
'REQUEST_METHOD': 'PUT',
|
2015-05-27 18:01:37 +02:00
|
|
|
'wsgi.input': BytesIO(b'654321')})
|
2013-01-19 10:57:14 -08:00
|
|
|
# (it's not a GET, so time() doesn't have a 2nd call)
|
|
|
|
stub_times = [58.2, 58.2 + 7.3321]
|
|
|
|
iter_response = app(req.environ, lambda *_: None)
|
|
|
|
self.assertEqual('87654321', ''.join(iter_response))
|
|
|
|
self.assertTiming('%s.PUT.314.timing' % exp_type, app,
|
|
|
|
exp_timing=7.3321 * 1000)
|
|
|
|
self.assertNotTiming(
|
|
|
|
'%s.GET.314.first-byte.timing' % exp_type, app)
|
|
|
|
self.assertNotTiming(
|
|
|
|
'%s.PUT.314.first-byte.timing' % exp_type, app)
|
2015-07-09 23:10:05 -04:00
|
|
|
if exp_type == 'object':
|
|
|
|
# Object operations also return stats by policy In this
|
|
|
|
# case, the value needs to match the timing for PUT.
|
|
|
|
self.assertTiming('%s.policy.0.PUT.314.timing' %
|
|
|
|
exp_type, app,
|
|
|
|
exp_timing=7.3321 * 1000)
|
|
|
|
self.assertUpdateStats(
|
|
|
|
[('object.PUT.314.xfer', 6 + 8),
|
|
|
|
('object.policy.0.PUT.314.xfer', 6 + 8)], app)
|
|
|
|
else:
|
|
|
|
self.assertUpdateStats(
|
|
|
|
[('%s.PUT.314.xfer' % exp_type, 6 + 8)], app)
|
|
|
|
|
|
|
|
# PUT Repeat the test above, but with a non-existent policy
|
|
|
|
# Do this only for object types
|
|
|
|
if exp_type == 'object':
|
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(
|
|
|
|
FakeApp(body='87654321', response_str='314 PiTown',
|
|
|
|
policy_idx='-1'), {})
|
|
|
|
app.access_logger = FakeLogger()
|
|
|
|
req = Request.blank(path, environ={
|
|
|
|
'REQUEST_METHOD': 'PUT',
|
|
|
|
'wsgi.input': BytesIO(b'654321')})
|
|
|
|
# (it's not a GET, so time() doesn't have a 2nd call)
|
|
|
|
stub_times = [58.2, 58.2 + 7.3321]
|
|
|
|
iter_response = app(req.environ, lambda *_: None)
|
|
|
|
self.assertEqual('87654321', ''.join(iter_response))
|
|
|
|
self.assertTiming('%s.PUT.314.timing' % exp_type, app,
|
|
|
|
exp_timing=7.3321 * 1000)
|
|
|
|
self.assertNotTiming(
|
|
|
|
'%s.GET.314.first-byte.timing' % exp_type, app)
|
|
|
|
self.assertNotTiming(
|
|
|
|
'%s.PUT.314.first-byte.timing' % exp_type, app)
|
|
|
|
# No results returned for the non-existent policy
|
|
|
|
self.assertUpdateStats([('object.PUT.314.xfer', 6 + 8)],
|
|
|
|
app)
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
|
|
|
|
def test_log_request_stat_method_filtering_default(self):
|
|
|
|
method_map = {
|
|
|
|
'foo': 'BAD_METHOD',
|
|
|
|
'': 'BAD_METHOD',
|
|
|
|
'PUTT': 'BAD_METHOD',
|
|
|
|
'SPECIAL': 'BAD_METHOD',
|
|
|
|
'GET': 'GET',
|
|
|
|
'PUT': 'PUT',
|
|
|
|
'COPY': 'COPY',
|
|
|
|
'HEAD': 'HEAD',
|
|
|
|
'POST': 'POST',
|
|
|
|
'DELETE': 'DELETE',
|
2012-11-06 15:13:01 -08:00
|
|
|
'OPTIONS': 'OPTIONS',
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
}
|
2015-06-24 09:36:37 +02:00
|
|
|
for method, exp_method in method_map.items():
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(FakeApp(), {})
|
|
|
|
app.access_logger = FakeLogger()
|
|
|
|
req = Request.blank('/v1/a/', environ={'REQUEST_METHOD': method})
|
2013-09-19 16:56:07 -04:00
|
|
|
now = 10000.0
|
|
|
|
app.log_request(req, 299, 11, 3, now, now + 1.17)
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
self.assertTiming('account.%s.299.timing' % exp_method, app,
|
|
|
|
exp_timing=1.17 * 1000)
|
2015-07-09 23:10:05 -04:00
|
|
|
self.assertUpdateStats([('account.%s.299.xfer' % exp_method,
|
|
|
|
11 + 3)], app)
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
|
|
|
|
def test_log_request_stat_method_filtering_custom(self):
|
|
|
|
method_map = {
|
|
|
|
'foo': 'BAD_METHOD',
|
|
|
|
'': 'BAD_METHOD',
|
|
|
|
'PUTT': 'BAD_METHOD',
|
|
|
|
'SPECIAL': 'SPECIAL', # will be configured
|
|
|
|
'GET': 'GET',
|
|
|
|
'PUT': 'PUT',
|
|
|
|
'COPY': 'BAD_METHOD', # prove no one's special
|
|
|
|
}
|
|
|
|
# this conf var supports optional leading access_
|
|
|
|
for conf_key in ['access_log_statsd_valid_http_methods',
|
|
|
|
'log_statsd_valid_http_methods']:
|
2015-06-24 09:36:37 +02:00
|
|
|
for method, exp_method in method_map.items():
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(FakeApp(), {
|
|
|
|
conf_key: 'SPECIAL, GET,PUT ', # crazy spaces ok
|
|
|
|
})
|
|
|
|
app.access_logger = FakeLogger()
|
2013-08-31 23:42:43 -04:00
|
|
|
req = Request.blank('/v1/a/c',
|
|
|
|
environ={'REQUEST_METHOD': method})
|
2013-09-19 16:56:07 -04:00
|
|
|
now = 10000.0
|
|
|
|
app.log_request(req, 911, 4, 43, now, now + 1.01)
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
self.assertTiming('container.%s.911.timing' % exp_method, app,
|
2013-08-31 23:42:43 -04:00
|
|
|
exp_timing=1.01 * 1000)
|
2015-07-09 23:10:05 -04:00
|
|
|
self.assertUpdateStats([('container.%s.911.xfer' % exp_method,
|
|
|
|
4 + 43)], app)
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
|
2012-05-24 21:15:51 -07:00
|
|
|
def test_basic_req(self):
|
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(FakeApp(), {})
|
|
|
|
app.access_logger = FakeLogger()
|
|
|
|
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'})
|
|
|
|
resp = app(req.environ, start_response)
|
|
|
|
resp_body = ''.join(resp)
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
log_parts = self._log_parts(app)
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual(log_parts[3], 'GET')
|
|
|
|
self.assertEqual(log_parts[4], '/')
|
|
|
|
self.assertEqual(log_parts[5], 'HTTP/1.0')
|
|
|
|
self.assertEqual(log_parts[6], '200')
|
|
|
|
self.assertEqual(resp_body, 'FAKE APP')
|
|
|
|
self.assertEqual(log_parts[11], str(len(resp_body)))
|
2012-05-24 21:15:51 -07:00
|
|
|
|
2013-01-19 10:57:14 -08:00
|
|
|
def test_basic_req_second_time(self):
|
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(FakeApp(), {})
|
|
|
|
app.access_logger = FakeLogger()
|
|
|
|
req = Request.blank('/', environ={
|
|
|
|
'swift.proxy_access_log_made': True,
|
|
|
|
'REQUEST_METHOD': 'GET'})
|
|
|
|
resp = app(req.environ, start_response)
|
|
|
|
resp_body = ''.join(resp)
|
2013-03-26 20:42:26 +00:00
|
|
|
self._log_parts(app, should_be_empty=True)
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual(resp_body, 'FAKE APP')
|
2013-01-19 10:57:14 -08:00
|
|
|
|
2012-05-24 21:15:51 -07:00
|
|
|
def test_multi_segment_resp(self):
|
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(FakeApp(
|
|
|
|
['some', 'chunks', 'of data']), {})
|
|
|
|
app.access_logger = FakeLogger()
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET',
|
|
|
|
'swift.source': 'SOS'})
|
2012-05-24 21:15:51 -07:00
|
|
|
resp = app(req.environ, start_response)
|
|
|
|
resp_body = ''.join(resp)
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
log_parts = self._log_parts(app)
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual(log_parts[3], 'GET')
|
|
|
|
self.assertEqual(log_parts[4], '/')
|
|
|
|
self.assertEqual(log_parts[5], 'HTTP/1.0')
|
|
|
|
self.assertEqual(log_parts[6], '200')
|
|
|
|
self.assertEqual(resp_body, 'somechunksof data')
|
|
|
|
self.assertEqual(log_parts[11], str(len(resp_body)))
|
2015-07-09 23:10:05 -04:00
|
|
|
self.assertUpdateStats([('SOS.GET.200.xfer', len(resp_body))], app)
|
2012-05-24 21:15:51 -07:00
|
|
|
|
|
|
|
def test_log_headers(self):
|
2013-11-22 16:59:09 -05:00
|
|
|
for conf_key in ['access_log_headers', 'log_headers']:
|
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(FakeApp(),
|
|
|
|
{conf_key: 'yes'})
|
|
|
|
app.access_logger = FakeLogger()
|
|
|
|
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'})
|
|
|
|
resp = app(req.environ, start_response)
|
|
|
|
# exhaust generator
|
|
|
|
[x for x in resp]
|
|
|
|
log_parts = self._log_parts(app)
|
|
|
|
headers = unquote(log_parts[14]).split('\n')
|
2015-07-21 19:23:00 +05:30
|
|
|
self.assertTrue('Host: localhost:80' in headers)
|
2012-05-24 21:15:51 -07:00
|
|
|
|
2013-12-29 16:41:58 +00:00
|
|
|
def test_access_log_headers_only(self):
|
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(
|
|
|
|
FakeApp(), {'log_headers': 'yes',
|
|
|
|
'access_log_headers_only': 'FIRST, seCond'})
|
|
|
|
app.access_logger = FakeLogger()
|
|
|
|
req = Request.blank('/',
|
|
|
|
environ={'REQUEST_METHOD': 'GET'},
|
|
|
|
headers={'First': '1',
|
|
|
|
'Second': '2',
|
|
|
|
'Third': '3'})
|
|
|
|
resp = app(req.environ, start_response)
|
|
|
|
# exhaust generator
|
|
|
|
[x for x in resp]
|
|
|
|
log_parts = self._log_parts(app)
|
|
|
|
headers = unquote(log_parts[14]).split('\n')
|
2016-12-12 11:58:01 -08:00
|
|
|
self.assertIn('First: 1', headers)
|
|
|
|
self.assertIn('Second: 2', headers)
|
2016-12-12 15:18:52 +07:00
|
|
|
self.assertNotIn('Third: 3', headers)
|
|
|
|
self.assertNotIn('Host: localhost:80', headers)
|
2013-12-29 16:41:58 +00:00
|
|
|
|
2012-05-24 21:15:51 -07:00
|
|
|
def test_upload_size(self):
|
2015-07-09 23:10:05 -04:00
|
|
|
# Using default policy
|
2012-05-24 21:15:51 -07:00
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(FakeApp(),
|
2013-08-31 23:42:43 -04:00
|
|
|
{'log_headers': 'yes'})
|
2012-05-24 21:15:51 -07:00
|
|
|
app.access_logger = FakeLogger()
|
2013-08-31 23:42:43 -04:00
|
|
|
req = Request.blank(
|
|
|
|
'/v1/a/c/o/foo',
|
|
|
|
environ={'REQUEST_METHOD': 'PUT',
|
2015-05-27 18:01:37 +02:00
|
|
|
'wsgi.input': BytesIO(b'some stuff')})
|
2012-05-24 21:15:51 -07:00
|
|
|
resp = app(req.environ, start_response)
|
2013-03-26 20:42:26 +00:00
|
|
|
# exhaust generator
|
|
|
|
[x for x in resp]
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
log_parts = self._log_parts(app)
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual(log_parts[11], str(len('FAKE APP')))
|
|
|
|
self.assertEqual(log_parts[10], str(len('some stuff')))
|
2015-07-09 23:10:05 -04:00
|
|
|
self.assertUpdateStats([('object.PUT.200.xfer',
|
|
|
|
len('some stuff') + len('FAKE APP')),
|
|
|
|
('object.policy.0.PUT.200.xfer',
|
|
|
|
len('some stuff') + len('FAKE APP'))],
|
|
|
|
app)
|
|
|
|
|
|
|
|
# Using a non-existent policy
|
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(FakeApp(policy_idx='-1'),
|
|
|
|
{'log_headers': 'yes'})
|
|
|
|
app.access_logger = FakeLogger()
|
|
|
|
req = Request.blank(
|
|
|
|
'/v1/a/c/o/foo',
|
|
|
|
environ={'REQUEST_METHOD': 'PUT',
|
|
|
|
'wsgi.input': BytesIO(b'some stuff')})
|
|
|
|
resp = app(req.environ, start_response)
|
|
|
|
# exhaust generator
|
|
|
|
[x for x in resp]
|
|
|
|
log_parts = self._log_parts(app)
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual(log_parts[11], str(len('FAKE APP')))
|
|
|
|
self.assertEqual(log_parts[10], str(len('some stuff')))
|
2015-07-09 23:10:05 -04:00
|
|
|
self.assertUpdateStats([('object.PUT.200.xfer',
|
|
|
|
len('some stuff') + len('FAKE APP'))],
|
|
|
|
app)
|
|
|
|
|
|
|
|
def test_upload_size_no_policy(self):
|
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(FakeApp(policy_idx=None),
|
|
|
|
{'log_headers': 'yes'})
|
|
|
|
app.access_logger = FakeLogger()
|
|
|
|
req = Request.blank(
|
|
|
|
'/v1/a/c/o/foo',
|
|
|
|
environ={'REQUEST_METHOD': 'PUT',
|
|
|
|
'wsgi.input': BytesIO(b'some stuff')})
|
|
|
|
resp = app(req.environ, start_response)
|
|
|
|
# exhaust generator
|
|
|
|
[x for x in resp]
|
|
|
|
log_parts = self._log_parts(app)
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual(log_parts[11], str(len('FAKE APP')))
|
|
|
|
self.assertEqual(log_parts[10], str(len('some stuff')))
|
2015-07-09 23:10:05 -04:00
|
|
|
self.assertUpdateStats([('object.PUT.200.xfer',
|
|
|
|
len('some stuff') + len('FAKE APP'))],
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
app)
|
2012-05-24 21:15:51 -07:00
|
|
|
|
|
|
|
def test_upload_line(self):
|
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(FakeAppReadline(),
|
2013-08-31 23:42:43 -04:00
|
|
|
{'log_headers': 'yes'})
|
2012-05-24 21:15:51 -07:00
|
|
|
app.access_logger = FakeLogger()
|
2013-08-31 23:42:43 -04:00
|
|
|
req = Request.blank(
|
|
|
|
'/v1/a/c',
|
|
|
|
environ={'REQUEST_METHOD': 'POST',
|
2015-05-27 18:01:37 +02:00
|
|
|
'wsgi.input': BytesIO(b'some stuff\nsome other stuff\n')})
|
2012-05-24 21:15:51 -07:00
|
|
|
resp = app(req.environ, start_response)
|
2013-03-26 20:42:26 +00:00
|
|
|
# exhaust generator
|
|
|
|
[x for x in resp]
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
log_parts = self._log_parts(app)
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual(log_parts[11], str(len('FAKE APP')))
|
|
|
|
self.assertEqual(log_parts[10], str(len('some stuff\n')))
|
2015-07-09 23:10:05 -04:00
|
|
|
self.assertUpdateStats([('container.POST.200.xfer',
|
|
|
|
len('some stuff\n') + len('FAKE APP'))],
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
app)
|
2012-05-24 21:15:51 -07:00
|
|
|
|
|
|
|
def test_log_query_string(self):
|
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(FakeApp(), {})
|
|
|
|
app.access_logger = FakeLogger()
|
|
|
|
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET',
|
2013-08-31 23:42:43 -04:00
|
|
|
'QUERY_STRING': 'x=3'})
|
2012-05-24 21:15:51 -07:00
|
|
|
resp = app(req.environ, start_response)
|
2013-03-26 20:42:26 +00:00
|
|
|
# exhaust generator
|
|
|
|
[x for x in resp]
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
log_parts = self._log_parts(app)
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual(unquote(log_parts[4]), '/?x=3')
|
2012-05-24 21:15:51 -07:00
|
|
|
|
|
|
|
def test_client_logging(self):
|
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(FakeApp(), {})
|
|
|
|
app.access_logger = FakeLogger()
|
|
|
|
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET',
|
2013-08-31 23:42:43 -04:00
|
|
|
'REMOTE_ADDR': '1.2.3.4'})
|
2012-05-24 21:15:51 -07:00
|
|
|
resp = app(req.environ, start_response)
|
2013-03-26 20:42:26 +00:00
|
|
|
# exhaust generator
|
|
|
|
[x for x in resp]
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
log_parts = self._log_parts(app)
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual(log_parts[0], '1.2.3.4') # client ip
|
|
|
|
self.assertEqual(log_parts[1], '1.2.3.4') # remote addr
|
2012-05-24 21:15:51 -07:00
|
|
|
|
2015-02-20 11:04:24 -08:00
|
|
|
def test_iterator_closing(self):
|
|
|
|
|
|
|
|
class CloseableBody(object):
|
|
|
|
def __init__(self):
|
|
|
|
self.closed = False
|
|
|
|
|
|
|
|
def close(self):
|
|
|
|
self.closed = True
|
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
return iter(["CloseableBody"])
|
|
|
|
|
|
|
|
body = CloseableBody()
|
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(FakeApp(body), {})
|
|
|
|
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET',
|
|
|
|
'REMOTE_ADDR': '1.2.3.4'})
|
|
|
|
resp = app(req.environ, start_response)
|
|
|
|
# exhaust generator
|
|
|
|
[x for x in resp]
|
|
|
|
self.assertTrue(body.closed)
|
|
|
|
|
2012-05-24 21:15:51 -07:00
|
|
|
def test_proxy_client_logging(self):
|
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(FakeApp(), {})
|
|
|
|
app.access_logger = FakeLogger()
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
req = Request.blank('/', environ={
|
|
|
|
'REQUEST_METHOD': 'GET',
|
|
|
|
'REMOTE_ADDR': '1.2.3.4',
|
|
|
|
'HTTP_X_FORWARDED_FOR': '4.5.6.7,8.9.10.11'})
|
2012-05-24 21:15:51 -07:00
|
|
|
resp = app(req.environ, start_response)
|
2013-03-26 20:42:26 +00:00
|
|
|
# exhaust generator
|
|
|
|
[x for x in resp]
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
log_parts = self._log_parts(app)
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual(log_parts[0], '4.5.6.7') # client ip
|
|
|
|
self.assertEqual(log_parts[1], '1.2.3.4') # remote addr
|
2012-05-24 21:15:51 -07:00
|
|
|
|
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(FakeApp(), {})
|
|
|
|
app.access_logger = FakeLogger()
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
req = Request.blank('/', environ={
|
|
|
|
'REQUEST_METHOD': 'GET',
|
|
|
|
'REMOTE_ADDR': '1.2.3.4',
|
|
|
|
'HTTP_X_CLUSTER_CLIENT_IP': '4.5.6.7'})
|
2012-05-24 21:15:51 -07:00
|
|
|
resp = app(req.environ, start_response)
|
2013-03-26 20:42:26 +00:00
|
|
|
# exhaust generator
|
|
|
|
[x for x in resp]
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
log_parts = self._log_parts(app)
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual(log_parts[0], '4.5.6.7') # client ip
|
|
|
|
self.assertEqual(log_parts[1], '1.2.3.4') # remote addr
|
2012-05-24 21:15:51 -07:00
|
|
|
|
|
|
|
def test_facility(self):
|
2013-08-31 23:42:43 -04:00
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(
|
|
|
|
FakeApp(),
|
|
|
|
{'log_headers': 'yes',
|
|
|
|
'access_log_facility': 'LOG_LOCAL7'})
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
handler = get_logger.handler4logger[app.access_logger.logger]
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual(SysLogHandler.LOG_LOCAL7, handler.facility)
|
2012-05-24 21:15:51 -07:00
|
|
|
|
|
|
|
def test_filter(self):
|
|
|
|
factory = proxy_logging.filter_factory({})
|
2015-07-21 19:23:00 +05:30
|
|
|
self.assertTrue(callable(factory))
|
|
|
|
self.assertTrue(callable(factory(FakeApp())))
|
2012-05-24 21:15:51 -07:00
|
|
|
|
|
|
|
def test_unread_body(self):
|
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
FakeApp(['some', 'stuff']), {})
|
2012-05-24 21:15:51 -07:00
|
|
|
app.access_logger = FakeLogger()
|
|
|
|
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'})
|
|
|
|
resp = app(req.environ, start_response)
|
2013-03-26 20:42:26 +00:00
|
|
|
# read first chunk
|
|
|
|
next(resp)
|
2012-05-24 21:15:51 -07:00
|
|
|
resp.close() # raise a GeneratorExit in middleware app_iter loop
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
log_parts = self._log_parts(app)
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual(log_parts[6], '499')
|
|
|
|
self.assertEqual(log_parts[11], '4') # write length
|
2012-05-24 21:15:51 -07:00
|
|
|
|
|
|
|
def test_disconnect_on_readline(self):
|
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(FakeAppReadline(), {})
|
|
|
|
app.access_logger = FakeLogger()
|
|
|
|
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET',
|
2013-08-31 23:42:43 -04:00
|
|
|
'wsgi.input': FileLikeExceptor()})
|
2012-05-24 21:15:51 -07:00
|
|
|
try:
|
|
|
|
resp = app(req.environ, start_response)
|
2013-03-26 20:42:26 +00:00
|
|
|
# read body
|
|
|
|
''.join(resp)
|
2013-01-19 10:57:14 -08:00
|
|
|
except IOError:
|
2012-05-24 21:15:51 -07:00
|
|
|
pass
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
log_parts = self._log_parts(app)
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual(log_parts[6], '499')
|
|
|
|
self.assertEqual(log_parts[10], '-') # read length
|
2012-05-24 21:15:51 -07:00
|
|
|
|
|
|
|
def test_disconnect_on_read(self):
|
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
FakeApp(['some', 'stuff']), {})
|
2012-05-24 21:15:51 -07:00
|
|
|
app.access_logger = FakeLogger()
|
|
|
|
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET',
|
2013-08-31 23:42:43 -04:00
|
|
|
'wsgi.input': FileLikeExceptor()})
|
2012-05-24 21:15:51 -07:00
|
|
|
try:
|
|
|
|
resp = app(req.environ, start_response)
|
2013-03-26 20:42:26 +00:00
|
|
|
# read body
|
|
|
|
''.join(resp)
|
2013-01-19 10:57:14 -08:00
|
|
|
except IOError:
|
2012-05-24 21:15:51 -07:00
|
|
|
pass
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
log_parts = self._log_parts(app)
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual(log_parts[6], '499')
|
|
|
|
self.assertEqual(log_parts[10], '-') # read length
|
2012-05-24 21:15:51 -07:00
|
|
|
|
2013-11-22 16:59:09 -05:00
|
|
|
def test_app_exception(self):
|
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(
|
|
|
|
FakeAppThatExcepts(), {})
|
|
|
|
app.access_logger = FakeLogger()
|
|
|
|
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'})
|
|
|
|
try:
|
|
|
|
app(req.environ, start_response)
|
|
|
|
except Exception:
|
|
|
|
pass
|
|
|
|
log_parts = self._log_parts(app)
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual(log_parts[6], '500')
|
|
|
|
self.assertEqual(log_parts[10], '-') # read length
|
2013-11-22 16:59:09 -05:00
|
|
|
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
def test_no_content_length_no_transfer_encoding_with_list_body(self):
|
2012-06-13 00:40:44 +00:00
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
FakeAppNoContentLengthNoTransferEncoding(
|
2015-06-15 22:10:45 +05:30
|
|
|
# test the "while not chunk: chunk = next(iterator)"
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
body=['', '', 'line1\n', 'line2\n'],
|
|
|
|
), {})
|
2012-06-13 00:40:44 +00:00
|
|
|
app.access_logger = FakeLogger()
|
|
|
|
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'})
|
|
|
|
resp = app(req.environ, start_response)
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
resp_body = ''.join(resp)
|
|
|
|
log_parts = self._log_parts(app)
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual(log_parts[3], 'GET')
|
|
|
|
self.assertEqual(log_parts[4], '/')
|
|
|
|
self.assertEqual(log_parts[5], 'HTTP/1.0')
|
|
|
|
self.assertEqual(log_parts[6], '200')
|
|
|
|
self.assertEqual(resp_body, 'line1\nline2\n')
|
|
|
|
self.assertEqual(log_parts[11], str(len(resp_body)))
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
|
|
|
|
def test_no_content_length_no_transfer_encoding_with_empty_strings(self):
|
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(
|
|
|
|
FakeAppNoContentLengthNoTransferEncoding(
|
2015-06-15 22:10:45 +05:30
|
|
|
# test the "while not chunk: chunk = next(iterator)"
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
body=['', '', ''],
|
|
|
|
), {})
|
|
|
|
app.access_logger = FakeLogger()
|
|
|
|
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'})
|
|
|
|
resp = app(req.environ, start_response)
|
|
|
|
resp_body = ''.join(resp)
|
|
|
|
log_parts = self._log_parts(app)
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual(log_parts[3], 'GET')
|
|
|
|
self.assertEqual(log_parts[4], '/')
|
|
|
|
self.assertEqual(log_parts[5], 'HTTP/1.0')
|
|
|
|
self.assertEqual(log_parts[6], '200')
|
|
|
|
self.assertEqual(resp_body, '')
|
|
|
|
self.assertEqual(log_parts[11], '-')
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
|
2013-11-22 16:59:09 -05:00
|
|
|
def test_no_content_length_no_transfer_encoding_with_generator(self):
|
|
|
|
|
|
|
|
class BodyGen(object):
|
|
|
|
def __init__(self, data):
|
|
|
|
self.data = data
|
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
yield self.data
|
|
|
|
|
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(
|
|
|
|
FakeAppNoContentLengthNoTransferEncoding(
|
|
|
|
body=BodyGen('abc'),
|
|
|
|
), {})
|
|
|
|
app.access_logger = FakeLogger()
|
|
|
|
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'})
|
|
|
|
resp = app(req.environ, start_response)
|
|
|
|
resp_body = ''.join(resp)
|
|
|
|
log_parts = self._log_parts(app)
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual(log_parts[3], 'GET')
|
|
|
|
self.assertEqual(log_parts[4], '/')
|
|
|
|
self.assertEqual(log_parts[5], 'HTTP/1.0')
|
|
|
|
self.assertEqual(log_parts[6], '200')
|
|
|
|
self.assertEqual(resp_body, 'abc')
|
|
|
|
self.assertEqual(log_parts[11], '3')
|
2013-11-22 16:59:09 -05:00
|
|
|
|
2012-08-01 00:16:12 +00:00
|
|
|
def test_req_path_info_popping(self):
|
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(FakeApp(), {})
|
|
|
|
app.access_logger = FakeLogger()
|
|
|
|
req = Request.blank('/v1/something', environ={'REQUEST_METHOD': 'GET'})
|
|
|
|
req.path_info_pop()
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual(req.environ['PATH_INFO'], '/something')
|
2012-08-01 00:16:12 +00:00
|
|
|
resp = app(req.environ, start_response)
|
|
|
|
resp_body = ''.join(resp)
|
Upating proxy-server StatsD logging.
Removed many StatsD logging calls in proxy-server and added
swift-informant-style catch-all logging in the proxy-logger middleware.
Many errors previously rolled into the "proxy-server.<type>.errors"
counter will now appear broken down by response code and with timing
data at: "proxy-server.<type>.<verb>.<status>.timing". Also, bytes
transferred (sum of in + out) will be at:
"proxy-server.<type>.<verb>.<status>.xfer". The proxy-logging
middleware can get its StatsD config from standard vars in [DEFAULT] or
from access_log_statsd_* config vars in its config section.
Similarly to Swift Informant, request methods ("verbs") are filtered
using the new proxy-logging config var, "log_statsd_valid_http_methods"
which defaults to GET, HEAD, POST, PUT, DELETE, and COPY. Requests with
methods not in this list use "BAD_METHOD" for <verb> in the metric name.
To avoid user error, access_log_statsd_valid_http_methods is also
accepted.
Previously, proxy-server metrics used "Account", "Container", and
"Object" for the <type>, but these are now all lowercase.
Updated the admin guide's StatsD docs to reflect the above changes and
also include the "proxy-server.<type>.handoff_count" and
"proxy-server.<type>.handoff_all_count" metrics.
The proxy server now saves off the original req.method and proxy_logging
will use this if it can (both for request logging and as the "<verb>" in
the statsd timing metric). This fixes bug 1025433.
Removed some stale access_log_* related code in proxy/server.py. Also
removed the BaseApplication/Application distinction as it's no longer
necessary.
Fixed up the sample config files a bit (logging lines, mostly).
Fixed typo in SAIO development guide.
Got proxy_logging.py test coverage to 100%.
Fixed proxy_logging.py for PEP8 v1.3.2.
Enhanced test.unit.FakeLogger to track more calls to enable testing
StatsD metric calls.
Change-Id: I45d94cb76450be96d66fcfab56359bdfdc3a2576
2012-08-19 17:44:43 -07:00
|
|
|
log_parts = self._log_parts(app)
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual(log_parts[3], 'GET')
|
|
|
|
self.assertEqual(log_parts[4], '/v1/something')
|
|
|
|
self.assertEqual(log_parts[5], 'HTTP/1.0')
|
|
|
|
self.assertEqual(log_parts[6], '200')
|
|
|
|
self.assertEqual(resp_body, 'FAKE APP')
|
|
|
|
self.assertEqual(log_parts[11], str(len(resp_body)))
|
2012-08-01 00:16:12 +00:00
|
|
|
|
2013-04-20 04:16:57 +00:00
|
|
|
def test_ipv6(self):
|
|
|
|
ipv6addr = '2001:db8:85a3:8d3:1319:8a2e:370:7348'
|
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(FakeApp(), {})
|
|
|
|
app.access_logger = FakeLogger()
|
|
|
|
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'})
|
|
|
|
req.remote_addr = ipv6addr
|
|
|
|
resp = app(req.environ, start_response)
|
|
|
|
resp_body = ''.join(resp)
|
|
|
|
log_parts = self._log_parts(app)
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual(log_parts[0], ipv6addr)
|
|
|
|
self.assertEqual(log_parts[1], ipv6addr)
|
|
|
|
self.assertEqual(log_parts[3], 'GET')
|
|
|
|
self.assertEqual(log_parts[4], '/')
|
|
|
|
self.assertEqual(log_parts[5], 'HTTP/1.0')
|
|
|
|
self.assertEqual(log_parts[6], '200')
|
|
|
|
self.assertEqual(resp_body, 'FAKE APP')
|
|
|
|
self.assertEqual(log_parts[11], str(len(resp_body)))
|
2013-04-20 04:16:57 +00:00
|
|
|
|
2013-06-13 15:14:35 +00:00
|
|
|
def test_log_info_none(self):
|
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(FakeApp(), {})
|
|
|
|
app.access_logger = FakeLogger()
|
|
|
|
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'})
|
2013-07-23 16:41:45 -07:00
|
|
|
list(app(req.environ, start_response))
|
2013-06-13 15:14:35 +00:00
|
|
|
log_parts = self._log_parts(app)
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual(log_parts[17], '-')
|
2013-06-13 15:14:35 +00:00
|
|
|
|
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(FakeApp(), {})
|
|
|
|
app.access_logger = FakeLogger()
|
|
|
|
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'})
|
|
|
|
req.environ['swift.log_info'] = []
|
2013-07-23 16:41:45 -07:00
|
|
|
list(app(req.environ, start_response))
|
2013-06-13 15:14:35 +00:00
|
|
|
log_parts = self._log_parts(app)
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual(log_parts[17], '-')
|
2013-06-13 15:14:35 +00:00
|
|
|
|
|
|
|
def test_log_info_single(self):
|
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(FakeApp(), {})
|
|
|
|
app.access_logger = FakeLogger()
|
|
|
|
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'})
|
|
|
|
req.environ['swift.log_info'] = ['one']
|
2013-07-23 16:41:45 -07:00
|
|
|
list(app(req.environ, start_response))
|
2013-06-13 15:14:35 +00:00
|
|
|
log_parts = self._log_parts(app)
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual(log_parts[17], 'one')
|
2013-06-13 15:14:35 +00:00
|
|
|
|
|
|
|
def test_log_info_multiple(self):
|
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(FakeApp(), {})
|
|
|
|
app.access_logger = FakeLogger()
|
|
|
|
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'})
|
|
|
|
req.environ['swift.log_info'] = ['one', 'and two']
|
2013-07-23 16:41:45 -07:00
|
|
|
list(app(req.environ, start_response))
|
2013-06-13 15:14:35 +00:00
|
|
|
log_parts = self._log_parts(app)
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual(log_parts[17], 'one%2Cand%20two')
|
2013-06-13 15:14:35 +00:00
|
|
|
|
2013-07-23 15:10:09 +01:00
|
|
|
def test_log_auth_token(self):
|
|
|
|
auth_token = 'b05bf940-0464-4c0e-8c70-87717d2d73e8'
|
|
|
|
|
2014-05-20 17:28:19 -07:00
|
|
|
# Default - reveal_sensitive_prefix is 16
|
2013-07-23 15:10:09 +01:00
|
|
|
# No x-auth-token header
|
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(FakeApp(), {})
|
|
|
|
app.access_logger = FakeLogger()
|
|
|
|
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'})
|
|
|
|
resp = app(req.environ, start_response)
|
|
|
|
resp_body = ''.join(resp)
|
|
|
|
log_parts = self._log_parts(app)
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual(log_parts[9], '-')
|
2013-07-23 15:10:09 +01:00
|
|
|
# Has x-auth-token header
|
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(FakeApp(), {})
|
|
|
|
app.access_logger = FakeLogger()
|
|
|
|
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET',
|
|
|
|
'HTTP_X_AUTH_TOKEN': auth_token})
|
|
|
|
resp = app(req.environ, start_response)
|
|
|
|
resp_body = ''.join(resp)
|
|
|
|
log_parts = self._log_parts(app)
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual(log_parts[9], 'b05bf940-0464-4c...')
|
2013-07-23 15:10:09 +01:00
|
|
|
|
|
|
|
# Truncate to first 8 characters
|
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(FakeApp(), {
|
|
|
|
'reveal_sensitive_prefix': '8'})
|
|
|
|
app.access_logger = FakeLogger()
|
|
|
|
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'})
|
|
|
|
resp = app(req.environ, start_response)
|
|
|
|
resp_body = ''.join(resp)
|
|
|
|
log_parts = self._log_parts(app)
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual(log_parts[9], '-')
|
2013-07-23 15:10:09 +01:00
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(FakeApp(), {
|
|
|
|
'reveal_sensitive_prefix': '8'})
|
|
|
|
app.access_logger = FakeLogger()
|
|
|
|
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET',
|
|
|
|
'HTTP_X_AUTH_TOKEN': auth_token})
|
|
|
|
resp = app(req.environ, start_response)
|
|
|
|
resp_body = ''.join(resp)
|
|
|
|
log_parts = self._log_parts(app)
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual(log_parts[9], 'b05bf940...')
|
2013-07-23 15:10:09 +01:00
|
|
|
|
|
|
|
# Token length and reveal_sensitive_prefix are same (no truncate)
|
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(FakeApp(), {
|
|
|
|
'reveal_sensitive_prefix': str(len(auth_token))})
|
|
|
|
app.access_logger = FakeLogger()
|
|
|
|
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET',
|
|
|
|
'HTTP_X_AUTH_TOKEN': auth_token})
|
|
|
|
resp = app(req.environ, start_response)
|
|
|
|
resp_body = ''.join(resp)
|
|
|
|
log_parts = self._log_parts(app)
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual(log_parts[9], auth_token)
|
2013-07-23 15:10:09 +01:00
|
|
|
|
2014-05-20 17:28:19 -07:00
|
|
|
# No effective limit on auth token
|
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(FakeApp(), {
|
|
|
|
'reveal_sensitive_prefix': constraints.MAX_HEADER_SIZE})
|
|
|
|
app.access_logger = FakeLogger()
|
|
|
|
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET',
|
|
|
|
'HTTP_X_AUTH_TOKEN': auth_token})
|
|
|
|
resp = app(req.environ, start_response)
|
|
|
|
resp_body = ''.join(resp)
|
|
|
|
log_parts = self._log_parts(app)
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual(log_parts[9], auth_token)
|
2014-05-20 17:28:19 -07:00
|
|
|
|
2013-07-23 15:10:09 +01:00
|
|
|
# Don't log x-auth-token
|
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(FakeApp(), {
|
|
|
|
'reveal_sensitive_prefix': '0'})
|
|
|
|
app.access_logger = FakeLogger()
|
|
|
|
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'})
|
|
|
|
resp = app(req.environ, start_response)
|
|
|
|
resp_body = ''.join(resp)
|
|
|
|
log_parts = self._log_parts(app)
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual(log_parts[9], '-')
|
2013-07-23 15:10:09 +01:00
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(FakeApp(), {
|
|
|
|
'reveal_sensitive_prefix': '0'})
|
|
|
|
app.access_logger = FakeLogger()
|
|
|
|
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET',
|
|
|
|
'HTTP_X_AUTH_TOKEN': auth_token})
|
|
|
|
resp = app(req.environ, start_response)
|
|
|
|
resp_body = ''.join(resp)
|
|
|
|
log_parts = self._log_parts(app)
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual(log_parts[9], '...')
|
2013-07-23 15:10:09 +01:00
|
|
|
|
2013-08-31 23:42:43 -04:00
|
|
|
# Avoids pyflakes error, "local variable 'resp_body' is assigned to
|
|
|
|
# but never used
|
|
|
|
self.assertTrue(resp_body is not None)
|
2012-06-13 00:40:44 +00:00
|
|
|
|
2013-11-22 16:59:09 -05:00
|
|
|
def test_ensure_fields(self):
|
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(FakeApp(), {})
|
|
|
|
app.access_logger = FakeLogger()
|
|
|
|
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'})
|
2013-09-19 16:56:07 -04:00
|
|
|
with mock.patch('time.time',
|
|
|
|
mock.MagicMock(
|
|
|
|
side_effect=[10000000.0, 10000001.0])):
|
2013-11-22 16:59:09 -05:00
|
|
|
resp = app(req.environ, start_response)
|
|
|
|
resp_body = ''.join(resp)
|
|
|
|
log_parts = self._log_parts(app)
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual(len(log_parts), 21)
|
|
|
|
self.assertEqual(log_parts[0], '-')
|
|
|
|
self.assertEqual(log_parts[1], '-')
|
|
|
|
self.assertEqual(log_parts[2], '26/Apr/1970/17/46/41')
|
|
|
|
self.assertEqual(log_parts[3], 'GET')
|
|
|
|
self.assertEqual(log_parts[4], '/')
|
|
|
|
self.assertEqual(log_parts[5], 'HTTP/1.0')
|
|
|
|
self.assertEqual(log_parts[6], '200')
|
|
|
|
self.assertEqual(log_parts[7], '-')
|
|
|
|
self.assertEqual(log_parts[8], '-')
|
|
|
|
self.assertEqual(log_parts[9], '-')
|
|
|
|
self.assertEqual(log_parts[10], '-')
|
|
|
|
self.assertEqual(resp_body, 'FAKE APP')
|
|
|
|
self.assertEqual(log_parts[11], str(len(resp_body)))
|
|
|
|
self.assertEqual(log_parts[12], '-')
|
|
|
|
self.assertEqual(log_parts[13], '-')
|
|
|
|
self.assertEqual(log_parts[14], '-')
|
|
|
|
self.assertEqual(log_parts[15], '1.0000')
|
|
|
|
self.assertEqual(log_parts[16], '-')
|
|
|
|
self.assertEqual(log_parts[17], '-')
|
|
|
|
self.assertEqual(log_parts[18], '10000000.000000000')
|
|
|
|
self.assertEqual(log_parts[19], '10000001.000000000')
|
|
|
|
self.assertEqual(log_parts[20], '-')
|
2013-11-22 16:59:09 -05:00
|
|
|
|
Invert which proxy logging middleware instance logs
Prior to this patch the proxy_logging middleware always prepared to
read the response and process it for access logging, where the
proxy_logging instance first to handle the response bytes marked the
request as "logged".
This meant that the proxy_logging instance immediately before the
proxy-server app (right most in the pipeline, if properly setup) would
always log the responses for all the client requests, regardless if
middleware to the left of it still had processing to do for the
response. This would break SLO, where the slo middleware passed along
the GET of the manifest, unchanged from the client, so that the right
most proxy logging middleware would log the sponse for just the
manifest, but then the slo middleware would fetch all the segments of
the manifest, feeding them out in the response to the client, the
request now marked as "logged" so that the left most proxy logging
middleware would not log it.
This patch inverts this behavior so that now the first proxy_logging
middleware instance to receive a request in the pipeline marks that
request as handling it. So now, the left most proxy_logging middleware
handles logging for all client reaquests, and the right most
proxy_logging middleware handles all other requests initiated from
within the pipeline to its left.
Closes bug: 1297438
Change-Id: Ia3561523db76c693e4e0b2c38f461544dfcee086
2014-03-25 15:56:44 -04:00
|
|
|
def test_dual_logging_middlewares(self):
|
|
|
|
# Since no internal request is being made, outer most proxy logging
|
|
|
|
# middleware, log1, should have performed the logging.
|
|
|
|
app = FakeApp()
|
|
|
|
flg0 = FakeLogger()
|
|
|
|
env = {}
|
|
|
|
log0 = proxy_logging.ProxyLoggingMiddleware(app, env, logger=flg0)
|
|
|
|
flg1 = FakeLogger()
|
|
|
|
log1 = proxy_logging.ProxyLoggingMiddleware(log0, env, logger=flg1)
|
|
|
|
|
|
|
|
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'})
|
|
|
|
resp = log1(req.environ, start_response)
|
|
|
|
resp_body = ''.join(resp)
|
|
|
|
self._log_parts(log0, should_be_empty=True)
|
|
|
|
log_parts = self._log_parts(log1)
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual(log_parts[3], 'GET')
|
|
|
|
self.assertEqual(log_parts[4], '/')
|
|
|
|
self.assertEqual(log_parts[5], 'HTTP/1.0')
|
|
|
|
self.assertEqual(log_parts[6], '200')
|
|
|
|
self.assertEqual(resp_body, 'FAKE APP')
|
|
|
|
self.assertEqual(log_parts[11], str(len(resp_body)))
|
Invert which proxy logging middleware instance logs
Prior to this patch the proxy_logging middleware always prepared to
read the response and process it for access logging, where the
proxy_logging instance first to handle the response bytes marked the
request as "logged".
This meant that the proxy_logging instance immediately before the
proxy-server app (right most in the pipeline, if properly setup) would
always log the responses for all the client requests, regardless if
middleware to the left of it still had processing to do for the
response. This would break SLO, where the slo middleware passed along
the GET of the manifest, unchanged from the client, so that the right
most proxy logging middleware would log the sponse for just the
manifest, but then the slo middleware would fetch all the segments of
the manifest, feeding them out in the response to the client, the
request now marked as "logged" so that the left most proxy logging
middleware would not log it.
This patch inverts this behavior so that now the first proxy_logging
middleware instance to receive a request in the pipeline marks that
request as handling it. So now, the left most proxy_logging middleware
handles logging for all client reaquests, and the right most
proxy_logging middleware handles all other requests initiated from
within the pipeline to its left.
Closes bug: 1297438
Change-Id: Ia3561523db76c693e4e0b2c38f461544dfcee086
2014-03-25 15:56:44 -04:00
|
|
|
|
|
|
|
def test_dual_logging_middlewares_w_inner(self):
|
|
|
|
|
|
|
|
class FakeMiddleware(object):
|
|
|
|
"""
|
|
|
|
Fake middleware to make a separate internal request, but construct
|
|
|
|
the response with different data.
|
|
|
|
"""
|
|
|
|
def __init__(self, app, conf):
|
|
|
|
self.app = app
|
|
|
|
self.conf = conf
|
|
|
|
|
|
|
|
def GET(self, req):
|
|
|
|
# Make the internal request
|
|
|
|
ireq = Request.blank('/', environ={'REQUEST_METHOD': 'GET'})
|
|
|
|
resp = self.app(ireq.environ, start_response)
|
|
|
|
resp_body = ''.join(resp)
|
|
|
|
if resp_body != 'FAKE APP':
|
|
|
|
return Response(request=req,
|
|
|
|
body="FAKE APP WAS NOT RETURNED",
|
|
|
|
content_type="text/plain")
|
|
|
|
# But our response is different
|
|
|
|
return Response(request=req, body="FAKE MIDDLEWARE",
|
|
|
|
content_type="text/plain")
|
|
|
|
|
|
|
|
def __call__(self, env, start_response):
|
|
|
|
req = Request(env)
|
|
|
|
return self.GET(req)(env, start_response)
|
|
|
|
|
|
|
|
# Since an internal request is being made, inner most proxy logging
|
|
|
|
# middleware, log0, should have performed the logging.
|
|
|
|
app = FakeApp()
|
|
|
|
flg0 = FakeLogger()
|
|
|
|
env = {}
|
|
|
|
log0 = proxy_logging.ProxyLoggingMiddleware(app, env, logger=flg0)
|
|
|
|
fake = FakeMiddleware(log0, env)
|
|
|
|
flg1 = FakeLogger()
|
|
|
|
log1 = proxy_logging.ProxyLoggingMiddleware(fake, env, logger=flg1)
|
|
|
|
|
|
|
|
req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'})
|
|
|
|
resp = log1(req.environ, start_response)
|
|
|
|
resp_body = ''.join(resp)
|
|
|
|
|
|
|
|
# Inner most logger should have logged the app's response
|
|
|
|
log_parts = self._log_parts(log0)
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual(log_parts[3], 'GET')
|
|
|
|
self.assertEqual(log_parts[4], '/')
|
|
|
|
self.assertEqual(log_parts[5], 'HTTP/1.0')
|
|
|
|
self.assertEqual(log_parts[6], '200')
|
|
|
|
self.assertEqual(log_parts[11], str(len('FAKE APP')))
|
Invert which proxy logging middleware instance logs
Prior to this patch the proxy_logging middleware always prepared to
read the response and process it for access logging, where the
proxy_logging instance first to handle the response bytes marked the
request as "logged".
This meant that the proxy_logging instance immediately before the
proxy-server app (right most in the pipeline, if properly setup) would
always log the responses for all the client requests, regardless if
middleware to the left of it still had processing to do for the
response. This would break SLO, where the slo middleware passed along
the GET of the manifest, unchanged from the client, so that the right
most proxy logging middleware would log the sponse for just the
manifest, but then the slo middleware would fetch all the segments of
the manifest, feeding them out in the response to the client, the
request now marked as "logged" so that the left most proxy logging
middleware would not log it.
This patch inverts this behavior so that now the first proxy_logging
middleware instance to receive a request in the pipeline marks that
request as handling it. So now, the left most proxy_logging middleware
handles logging for all client reaquests, and the right most
proxy_logging middleware handles all other requests initiated from
within the pipeline to its left.
Closes bug: 1297438
Change-Id: Ia3561523db76c693e4e0b2c38f461544dfcee086
2014-03-25 15:56:44 -04:00
|
|
|
|
|
|
|
# Outer most logger should have logged the other middleware's response
|
|
|
|
log_parts = self._log_parts(log1)
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual(log_parts[3], 'GET')
|
|
|
|
self.assertEqual(log_parts[4], '/')
|
|
|
|
self.assertEqual(log_parts[5], 'HTTP/1.0')
|
|
|
|
self.assertEqual(log_parts[6], '200')
|
|
|
|
self.assertEqual(resp_body, 'FAKE MIDDLEWARE')
|
|
|
|
self.assertEqual(log_parts[11], str(len(resp_body)))
|
Invert which proxy logging middleware instance logs
Prior to this patch the proxy_logging middleware always prepared to
read the response and process it for access logging, where the
proxy_logging instance first to handle the response bytes marked the
request as "logged".
This meant that the proxy_logging instance immediately before the
proxy-server app (right most in the pipeline, if properly setup) would
always log the responses for all the client requests, regardless if
middleware to the left of it still had processing to do for the
response. This would break SLO, where the slo middleware passed along
the GET of the manifest, unchanged from the client, so that the right
most proxy logging middleware would log the sponse for just the
manifest, but then the slo middleware would fetch all the segments of
the manifest, feeding them out in the response to the client, the
request now marked as "logged" so that the left most proxy logging
middleware would not log it.
This patch inverts this behavior so that now the first proxy_logging
middleware instance to receive a request in the pipeline marks that
request as handling it. So now, the left most proxy_logging middleware
handles logging for all client reaquests, and the right most
proxy_logging middleware handles all other requests initiated from
within the pipeline to its left.
Closes bug: 1297438
Change-Id: Ia3561523db76c693e4e0b2c38f461544dfcee086
2014-03-25 15:56:44 -04:00
|
|
|
|
2014-11-27 18:42:49 +09:00
|
|
|
def test_policy_index(self):
|
|
|
|
# Policy index can be specified by X-Backend-Storage-Policy-Index
|
|
|
|
# in the request header for object API
|
2015-07-09 23:10:05 -04:00
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(FakeApp(policy_idx='1'), {})
|
2014-11-27 18:42:49 +09:00
|
|
|
app.access_logger = FakeLogger()
|
2015-07-09 23:10:05 -04:00
|
|
|
req = Request.blank('/v1/a/c/o', environ={'REQUEST_METHOD': 'PUT'})
|
2014-11-27 18:42:49 +09:00
|
|
|
resp = app(req.environ, start_response)
|
|
|
|
''.join(resp)
|
|
|
|
log_parts = self._log_parts(app)
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual(log_parts[20], '1')
|
2014-11-27 18:42:49 +09:00
|
|
|
|
|
|
|
# Policy index can be specified by X-Backend-Storage-Policy-Index
|
|
|
|
# in the response header for container API
|
|
|
|
app = proxy_logging.ProxyLoggingMiddleware(FakeApp(), {})
|
|
|
|
app.access_logger = FakeLogger()
|
|
|
|
req = Request.blank('/v1/a/c', environ={'REQUEST_METHOD': 'GET'})
|
|
|
|
|
|
|
|
def fake_call(app, env, start_response):
|
|
|
|
start_response(app.response_str,
|
|
|
|
[('Content-Type', 'text/plain'),
|
|
|
|
('Content-Length', str(sum(map(len, app.body)))),
|
|
|
|
('X-Backend-Storage-Policy-Index', '1')])
|
|
|
|
while env['wsgi.input'].read(5):
|
|
|
|
pass
|
|
|
|
return app.body
|
|
|
|
|
|
|
|
with mock.patch.object(FakeApp, '__call__', fake_call):
|
|
|
|
resp = app(req.environ, start_response)
|
|
|
|
''.join(resp)
|
|
|
|
log_parts = self._log_parts(app)
|
2015-08-05 23:58:14 +05:30
|
|
|
self.assertEqual(log_parts[20], '1')
|