REST API for logs 59/39359/3
authorTaseer Ahmed <taseer94@gmail.com>
Tue, 15 Aug 2017 18:04:23 +0000 (23:04 +0500)
committerTaseer Ahmed <taseer94@gmail.com>
Sun, 20 Aug 2017 17:15:25 +0000 (22:15 +0500)
JIRA: STORPERF-94

Change-Id: I59189109d7f731977fc682b3fb78e60bc92a8270
Signed-off-by: Taseer Ahmed <taseer94@gmail.com>
docker/storperf-master/rest_server.py
docker/storperf-master/storperf/storperf_master.py
docs/testing/user/test-usage.rst

index 19f87ca..8d1ad78 100644 (file)
@@ -26,6 +26,35 @@ api = swagger.docs(Api(app), apiVersion='1.0')
 storperf = StorPerfMaster()
 
 
+class Logs(Resource):
+    def __init__(self):
+        self.logger = logging.getLogger(__name__)
+
+    @swagger.operation(
+        notes="Fetch logs",
+        parameters=[
+            {
+                "name": "lines",
+                "description": "The number of lines to fetch",
+                "required": "False",
+                "type": "string",
+                "allowedMultiple": "False",
+                "paramType": "query"
+            }
+        ]
+    )
+    def get(self):
+        lines = request.args.get('lines')
+        if lines:
+            try:
+                lines = int(lines)
+            except Exception:
+                pass
+        else:
+            lines = 35
+        return jsonify({'logs': storperf.get_logs(lines)})
+
+
 @swagger.model
 class ConfigurationRequestModel:
     resource_fields = {
@@ -343,6 +372,7 @@ def setup_logging(default_path='logging.json',
 api.add_resource(Configure, "/api/v1.0/configurations")
 api.add_resource(Quota, "/api/v1.0/quotas")
 api.add_resource(Job, "/api/v1.0/jobs")
+api.add_resource(Logs, "/api/v1.0/logs")
 
 if __name__ == "__main__":
     setup_logging()
index 8c2a7b4..7f2c395 100644 (file)
@@ -256,6 +256,23 @@ class StorPerfMaster(object):
             'workloads',
             str(self._test_executor.workload_modules))
 
+    def get_logs(self, lines=None):
+        LOG_DIR = '/var/log/supervisor/storperf-webapp.log'
+
+        if isinstance(lines, int):
+            logs = []
+            index = 0
+            for line in reversed(open(LOG_DIR).readlines()):
+                if index != int(lines):
+                    logs.insert(0, line.strip())
+                    index += 1
+                else:
+                    break
+        else:
+            with open(LOG_DIR) as f:
+                logs = f.read().split('\n')
+        return logs
+
     def create_stack(self):
         if (self.stack_id is not None):
             raise ParameterError("ERROR: Stack has already been created")
index 3854e0a..8cd7f20 100644 (file)
@@ -255,3 +255,20 @@ issuing an HTTP DELETE to the configurations API.
 You may also want to delete an environment, and then create a new one with a
 different number of VMs/Cinder volumes to test the impact of the number of VMs
 in your environment.
+
+Viewing StorPerf Logs
+=====================
+
+Logs are an integral part of any application as they help debugging the application. The user just
+needs to issue an HTTP request. To view the entire logs
+
+.. code-block:: bash
+
+  curl -X GET --header 'Accept: application/json' http://StorPerf:5000/api/v1.0/logs?lines=all
+
+Alternatively, one can also view a certain amount of lines by specifying the number in the
+request. If no lines are specified, then last 35 lines are returned
+
+.. code-block:: bash
+
+  curl -X GET --header 'Accept: application/json' http://StorPerf:5000/api/v1.0/logs?lines=12
\ No newline at end of file