From 7573fbd4985fb090cc315b5af9e7531dc900b7b8 Mon Sep 17 00:00:00 2001 From: Steven Lang Date: Mon, 23 Jun 2014 12:59:24 -0700 Subject: [PATCH] Object services user-agent string uses full name It does not appear that, aside from the user-agent string, the strings "obj-server", "obj-updater", or "obj-replicator" (or "obj-"*) appear in the swift code base, aside from the directory containing the object services code being named "obj". Furthermore, the container, account, and proxy services construct their user-agent string, as reported in the logs, using their full name. In addition, this full name also shows up as the name of the process via "ps" or "top", etc., which can make it easier for admins to match log entries with other tools. For consistency, we update the object services to use an "object-" prefix rather than "obj-" in its user agent string. * obj-etag does appear in a unit test, but not part of the regular code. Change-Id: I914fc189514207df2535731eda10cb4b3d30cc6c --- doc/source/logs.rst | 8 +++++--- swift/obj/mem_server.py | 2 +- swift/obj/replicator.py | 2 +- swift/obj/server.py | 2 +- swift/obj/updater.py | 2 +- test/unit/obj/test_replicator.py | 2 +- test/unit/obj/test_server.py | 21 +++++++++++---------- 7 files changed, 21 insertions(+), 18 deletions(-) diff --git a/doc/source/logs.rst b/doc/source/logs.rst index 6239b93d25..709406e692 100644 --- a/doc/source/logs.rst +++ b/doc/source/logs.rst @@ -126,9 +126,11 @@ status_int The response code for the request. content_length The value of the Content-Length header in the response. referer The value of the HTTP Referer header. transaction_id The transaction id of the request. -user_agent The value of the HTTP User-Agent header. Swift's proxy - server sets its user-agent to - ``"proxy-server ".`` +user_agent The value of the HTTP User-Agent header. Swift services + report a user-agent string of the service name followed by + the process ID, such as ``"proxy-server "`` or ``"object-updater "``. request_time The duration of the request. additional_info Additional useful information. =================== ========================================================== diff --git a/swift/obj/mem_server.py b/swift/obj/mem_server.py index 7b3baf1b59..83647661aa 100644 --- a/swift/obj/mem_server.py +++ b/swift/obj/mem_server.py @@ -70,7 +70,7 @@ class ObjectController(server.ObjectController): :param objdevice: device name that the object is in :param policy_idx: the associated storage policy index """ - headers_out['user-agent'] = 'obj-server %s' % os.getpid() + headers_out['user-agent'] = 'object-server %s' % os.getpid() full_path = '/%s/%s/%s' % (account, container, obj) if all([host, partition, contdevice]): try: diff --git a/swift/obj/replicator.py b/swift/obj/replicator.py index fdc5378252..6994ca39cb 100644 --- a/swift/obj/replicator.py +++ b/swift/obj/replicator.py @@ -86,7 +86,7 @@ class ObjectReplicator(Daemon): self.disk_chunk_size = int(conf.get('disk_chunk_size', 65536)) self.headers = { 'Content-Length': '0', - 'user-agent': 'obj-replicator %s' % os.getpid()} + 'user-agent': 'object-replicator %s' % os.getpid()} self.rsync_error_log_line_length = \ int(conf.get('rsync_error_log_line_length', 0)) self.handoffs_first = config_true_value(conf.get('handoffs_first', diff --git a/swift/obj/server.py b/swift/obj/server.py index 4a3b9926ff..8fe1e7c8fe 100644 --- a/swift/obj/server.py +++ b/swift/obj/server.py @@ -169,7 +169,7 @@ class ObjectController(object): :param objdevice: device name that the object is in :param policy_index: the associated storage policy index """ - headers_out['user-agent'] = 'obj-server %s' % os.getpid() + headers_out['user-agent'] = 'object-server %s' % os.getpid() full_path = '/%s/%s/%s' % (account, container, obj) if all([host, partition, contdevice]): try: diff --git a/swift/obj/updater.py b/swift/obj/updater.py index 6a9e7a1a4c..62ab9a39b9 100644 --- a/swift/obj/updater.py +++ b/swift/obj/updater.py @@ -258,7 +258,7 @@ class ObjectUpdater(Daemon): :param headers: headers to send with the update """ headers_out = headers.copy() - headers_out['user-agent'] = 'obj-updater %s' % os.getpid() + headers_out['user-agent'] = 'object-updater %s' % os.getpid() try: with ConnectionTimeout(self.conn_timeout): conn = http_connect(node['ip'], node['port'], node['device'], diff --git a/test/unit/obj/test_replicator.py b/test/unit/obj/test_replicator.py index 2b49f20167..cda8e9a2f0 100644 --- a/test/unit/obj/test_replicator.py +++ b/test/unit/obj/test_replicator.py @@ -689,7 +689,7 @@ class TestObjectReplicator(unittest.TestCase): self.replicator.partition_times = [] self.headers = {'Content-Length': '0', - 'user-agent': 'obj-replicator %s' % os.getpid()} + 'user-agent': 'object-replicator %s' % os.getpid()} self.replicator.logger = mock_logger = mock.MagicMock() mock_tpool_reraise.return_value = (0, {}) diff --git a/test/unit/obj/test_server.py b/test/unit/obj/test_server.py index 67c24dd743..f12b7d9313 100755 --- a/test/unit/obj/test_server.py +++ b/test/unit/obj/test_server.py @@ -2319,7 +2319,7 @@ class TestObjectController(unittest.TestCase): given_args, ['127.0.0.1', '1234', 'sdc1', 1, 'PUT', '/a/c/o', { 'x-timestamp': '1', 'x-out': 'set', - 'user-agent': 'obj-server %s' % os.getpid(), + 'user-agent': 'object-server %s' % os.getpid(), 'X-Backend-Storage-Policy-Index': policy.idx}]) @patch_policies([storage_policy.StoragePolicy(0, 'zero', True), @@ -2399,7 +2399,7 @@ class TestObjectController(unittest.TestCase): 'x-timestamp': utils.Timestamp('12345').internal, 'X-Backend-Storage-Policy-Index': '37', 'referer': 'PUT http://localhost/sda1/p/a/c/o', - 'user-agent': 'obj-server %d' % os.getpid(), + 'user-agent': 'object-server %d' % os.getpid(), 'X-Backend-Storage-Policy-Index': policy.idx, 'x-trans-id': '-'})}) self.assertEquals( @@ -2417,7 +2417,7 @@ class TestObjectController(unittest.TestCase): 'x-size': '0', 'x-timestamp': utils.Timestamp('12345').internal, 'referer': 'PUT http://localhost/sda1/p/a/c/o', - 'user-agent': 'obj-server %d' % os.getpid(), + 'user-agent': 'object-server %d' % os.getpid(), # system account storage policy is 0 'X-Backend-Storage-Policy-Index': 0, 'x-trans-id': '-'})}) @@ -2436,7 +2436,7 @@ class TestObjectController(unittest.TestCase): 'x-size': '0', 'x-timestamp': utils.Timestamp('12345').internal, 'referer': 'PUT http://localhost/sda1/p/a/c/o', - 'user-agent': 'obj-server %d' % os.getpid(), + 'user-agent': 'object-server %d' % os.getpid(), # system account storage policy is 0 'X-Backend-Storage-Policy-Index': 0, 'x-trans-id': '-'})}) @@ -2507,7 +2507,7 @@ class TestObjectController(unittest.TestCase): 'x-timestamp': utils.Timestamp('12345').internal, 'X-Backend-Storage-Policy-Index': '26', 'referer': 'PUT http://localhost/sda1/p/a/c/o', - 'user-agent': 'obj-server %d' % os.getpid(), + 'user-agent': 'object-server %d' % os.getpid(), 'x-trans-id': '-'})}) self.assertEquals( http_connect_args[1], @@ -2525,7 +2525,7 @@ class TestObjectController(unittest.TestCase): 'x-timestamp': utils.Timestamp('12345').internal, 'X-Backend-Storage-Policy-Index': '26', 'referer': 'PUT http://localhost/sda1/p/a/c/o', - 'user-agent': 'obj-server %d' % os.getpid(), + 'user-agent': 'object-server %d' % os.getpid(), 'x-trans-id': '-'})}) def test_object_delete_at_aysnc_update(self): @@ -2639,7 +2639,7 @@ class TestObjectController(unittest.TestCase): '06fbf0b514e5199dfc4e00f42eb5ea83-%s' % utils.Timestamp(1).internal))), {'headers': {'x-timestamp': '1', 'x-out': 'set', - 'user-agent': 'obj-server %s' % os.getpid(), + 'user-agent': 'object-server %s' % os.getpid(), 'X-Backend-Storage-Policy-Index': policy.idx}, 'account': 'a', 'container': 'c', 'obj': 'o', 'op': 'PUT'}) @@ -2680,7 +2680,8 @@ class TestObjectController(unittest.TestCase): '06fbf0b514e5199dfc4e00f42eb5ea83-%s' % utils.Timestamp(1).internal))), {'headers': {'x-timestamp': '1', 'x-out': str(status), - 'user-agent': 'obj-server %s' % os.getpid(), + 'user-agent': + 'object-server %s' % os.getpid(), 'X-Backend-Storage-Policy-Index': policy.idx}, 'account': 'a', 'container': 'c', 'obj': 'o', @@ -2803,7 +2804,7 @@ class TestObjectController(unittest.TestCase): self.assertEqual(method, 'PUT') self.assertEqual(path, '/cdevice/cpartition/a/c/o') self.assertEqual(headers, HeaderKeyDict({ - 'user-agent': 'obj-server %s' % os.getpid(), + 'user-agent': 'object-server %s' % os.getpid(), 'x-size': '0', 'x-etag': 'd41d8cd98f00b204e9800998ecf8427e', 'x-content-type': 'text/plain', @@ -2844,7 +2845,7 @@ class TestObjectController(unittest.TestCase): self.assertEqual(data, { 'headers': HeaderKeyDict({ 'X-Size': '0', - 'User-Agent': 'obj-server %s' % os.getpid(), + 'User-Agent': 'object-server %s' % os.getpid(), 'X-Content-Type': 'text/plain', 'X-Timestamp': utils.Timestamp(1).internal, 'X-Trans-Id': '123',