Mercurial > p > roundup > code
diff roundup/rest.py @ 6185:1cb2375015f0
Enable timing stats reporting in REST interface.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Wed, 03 Jun 2020 00:52:32 -0400 |
| parents | 2a513a057691 |
| children | 5b66c480f71f |
line wrap: on
line diff
--- a/roundup/rest.py Sun May 24 14:34:05 2020 -0400 +++ b/roundup/rest.py Wed Jun 03 00:52:32 2020 -0400 @@ -116,6 +116,9 @@ } } else: + if hasattr(self.db, 'stats') and self.report_stats: + self.db.stats['elapsed'] = time.time()-self.start + data['@stats'] = self.db.stats result = { 'data': data } @@ -370,6 +373,11 @@ self.client = client self.db = db self.translator = client.translator + # record start time for statistics reporting + self.start = time.time() + # disable stat reporting by default enable with @stats=True + # query param + self.report_stats = False # This used to be initialized from client.instance.actions which # would include too many actions that do not make sense in the # REST-API context, so for now we only permit the retire and @@ -1951,6 +1959,14 @@ except (KeyError, TypeError): pretty_output = True + # check for runtime statistics + try: + self.report_stats = input['@stats'].value.lower() == "true" + # Can also return a TypeError ("not indexable") + # In case the FieldStorage could not parse the result + except (KeyError, TypeError): + report_stats = False + # check for @apiver in query string msg = ("Unrecognized version: %s. " "See /rest without specifying version "
