Included time inside trans_id

Including the time inside the trans_id can be very useful for knowing
which logs to scan. I made this so the trans_id will still be the
same length (the randomness of the remaining uuid4 should be enough
for this use). I also added a convenience function for retreiving the
time information from a trans_id.

If you're wondering why I just didn't use uuid1 that embeds the time,
it's because it also embeds uuid.getnode() which "The first time this
runs, it may launch a separate program, which could be quite slow."
We could supply our own getnode value, but then we have to guarantee
its uniqueness, yada yada yada.

Change-Id: Ie33caf1e839fd1a21b01a928a8b301126bef7396
This commit is contained in:
gholt
2013-04-20 03:34:48 +00:00
parent 58259df8df
commit 00ab3d4f36
4 changed files with 56 additions and 6 deletions

View File

@@ -27,7 +27,6 @@
import mimetypes
import os
from ConfigParser import ConfigParser
import uuid
from random import shuffle
from time import time
@@ -35,7 +34,7 @@ from eventlet import Timeout
from swift.common.ring import Ring
from swift.common.utils import cache_from_env, get_logger, \
get_remote_client, split_path, config_true_value
get_remote_client, split_path, config_true_value, generate_trans_id
from swift.common.constraints import check_utf8
from swift.proxy.controllers import AccountController, ObjectController, \
ContainerController
@@ -221,7 +220,7 @@ class Application(object):
controller = controller(self, **path_parts)
if 'swift.trans_id' not in req.environ:
# if this wasn't set by an earlier middleware, set it now
trans_id = 'tx' + uuid.uuid4().hex + self.trans_id_suffix
trans_id = generate_trans_id(self.trans_id_suffix)
req.environ['swift.trans_id'] = trans_id
self.logger.txn_id = trans_id
req.headers['x-trans-id'] = req.environ['swift.trans_id']