[Kimchi-devel] [PATCH] [Wok 4/7] Sort user log records by microsecond

Lucio Correia luciojhc at linux.vnet.ibm.com
Fri Aug 19 19:37:39 UTC 2016


With several requests occurring at the same second, we need
further information to return user request entries in correct
order.

Signed-off-by: Lucio Correia <luciojhc at linux.vnet.ibm.com>
---
 src/wok/reqlogger.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/wok/reqlogger.py b/src/wok/reqlogger.py
index c57b141..39d70e6 100644
--- a/src/wok/reqlogger.py
+++ b/src/wok/reqlogger.py
@@ -55,6 +55,7 @@ RECORD_TEMPLATE_DICT = {
 SECONDS_PER_HOUR = 360
 TS_DATE_FORMAT = "%Y-%m-%d"
 TS_TIME_FORMAT = "%H:%M:%S"
+TS_MS_FORMAT = "%f"
 TS_ZONE_FORMAT = "%Z"
 UNSAFE_REQUEST_PARAMETERS = ['password', 'passwd']
 
@@ -106,7 +107,8 @@ class RequestParser(object):
         """
         try:
             # sort records chronologically
-            sortedList = sorted(records, key=lambda k: k['date'] + k['time'])
+            sortedList = sorted(records, key=lambda k: k['date'] + k['time'] +
+                                k.get('ms', ''))
 
             # generate log file
             fd = NamedTemporaryFile(mode='w', dir=self.downloadDir,
@@ -246,6 +248,7 @@ class RequestRecord(object):
         timestamp = time.localtime()
         self.logData['date'] = time.strftime(TS_DATE_FORMAT, timestamp)
         self.logData['time'] = time.strftime(TS_TIME_FORMAT, timestamp)
+        self.logData['ms'] = time.strftime(TS_MS_FORMAT, timestamp)
         self.logData['zone'] = time.strftime(TS_ZONE_FORMAT, timestamp)
 
     def getSafeReqParams(self, params):
-- 
1.9.1




More information about the Kimchi-devel mailing list