output access log of subrequests from swift3 to proxy-server
I made modifications to output access log of subrequests from swift3 to proxy-server. Currently, only access log from client to swift3 is output. I think that we should output proxy-server from swift3 to analyze it quickly when a problem occurred. Change-Id: If8fc17ec93eb9ca27446f23e4d1992e9d354437b
This commit is contained in:
		@@ -96,6 +96,9 @@ use = egg:swift3#swift3
 | 
			
		||||
# If you set this to false, Swift3 returns all buckets.
 | 
			
		||||
# check_bucket_owner = false
 | 
			
		||||
#
 | 
			
		||||
# If set to 'true', proxy-logging output access log from Swift3 to
 | 
			
		||||
# proxy-server.
 | 
			
		||||
# force_swift_request_proxy_log = false
 | 
			
		||||
 | 
			
		||||
[filter:catch_errors]
 | 
			
		||||
use = egg:swift#catch_errors
 | 
			
		||||
 
 | 
			
		||||
@@ -61,4 +61,5 @@ CONF = Config({
 | 
			
		||||
    'auth_pipeline_check': True,
 | 
			
		||||
    'max_upload_part_num': 1000,
 | 
			
		||||
    'check_bucket_owner': False,
 | 
			
		||||
    'force_swift_request_proxy_log': False,
 | 
			
		||||
})
 | 
			
		||||
 
 | 
			
		||||
@@ -433,6 +433,8 @@ class Request(swob.Request):
 | 
			
		||||
            del env['HTTP_X_AMZ_COPY_SOURCE']
 | 
			
		||||
            env['CONTENT_LENGTH'] = '0'
 | 
			
		||||
 | 
			
		||||
        if CONF.force_swift_request_proxy_log:
 | 
			
		||||
            env['swift.proxy_access_log_made'] = False
 | 
			
		||||
        env['swift.source'] = 'S3'
 | 
			
		||||
        if method is not None:
 | 
			
		||||
            env['REQUEST_METHOD'] = method
 | 
			
		||||
 
 | 
			
		||||
@@ -241,6 +241,41 @@ class TestRequest(Swift3TestCase):
 | 
			
		||||
            self.assertTrue('Authorization' not in sw_req.headers)
 | 
			
		||||
            self.assertEquals(sw_req.headers['X-Auth-Token'], 'token')
 | 
			
		||||
 | 
			
		||||
    def test_to_swift_req_subrequest_proxy_access_log(self):
 | 
			
		||||
        container = 'bucket'
 | 
			
		||||
        obj = 'obj'
 | 
			
		||||
        method = 'GET'
 | 
			
		||||
 | 
			
		||||
        # force_swift_request_proxy_log is True
 | 
			
		||||
        req = Request.blank('/%s/%s' % (container, obj),
 | 
			
		||||
                            environ={'REQUEST_METHOD': method,
 | 
			
		||||
                                     'swift.proxy_access_log_made': True},
 | 
			
		||||
                            headers={'Authorization': 'AWS test:tester:hmac'})
 | 
			
		||||
        with nested(patch.object(Request, 'get_response'),
 | 
			
		||||
                    patch.object(Request, 'remote_user', 'authorized'),
 | 
			
		||||
                    patch('swift3.cfg.CONF.force_swift_request_proxy_log',
 | 
			
		||||
                    True)) \
 | 
			
		||||
                as (m_swift_resp, m_remote_user, m_cfg):
 | 
			
		||||
 | 
			
		||||
            m_swift_resp.return_value = FakeSwiftResponse()
 | 
			
		||||
            s3_req = S3AclRequest(req.environ, MagicMock())
 | 
			
		||||
            sw_req = s3_req.to_swift_req(method, container, obj)
 | 
			
		||||
            self.assertFalse(sw_req.environ['swift.proxy_access_log_made'])
 | 
			
		||||
 | 
			
		||||
        # force_swift_request_proxy_log is False
 | 
			
		||||
        req = Request.blank('/%s/%s' % (container, obj),
 | 
			
		||||
                            environ={'REQUEST_METHOD': method,
 | 
			
		||||
                                     'swift.proxy_access_log_made': True},
 | 
			
		||||
                            headers={'Authorization': 'AWS test:tester:hmac'})
 | 
			
		||||
        with nested(patch.object(Request, 'get_response'),
 | 
			
		||||
                    patch.object(Request, 'remote_user', 'authorized')) \
 | 
			
		||||
                as (m_swift_resp, m_remote_user):
 | 
			
		||||
 | 
			
		||||
            m_swift_resp.return_value = FakeSwiftResponse()
 | 
			
		||||
            s3_req = S3AclRequest(req.environ, MagicMock())
 | 
			
		||||
            sw_req = s3_req.to_swift_req(method, container, obj)
 | 
			
		||||
            self.assertTrue(sw_req.environ['swift.proxy_access_log_made'])
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if __name__ == '__main__':
 | 
			
		||||
    unittest.main()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user