Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Fix the json endpoints in thermos
# Fixing the json endpoints in thermos

`TaskObserverJSONBindings` is mixin that includes a few routes that serve info about tasks and processes in pure JSON format. The functions are overridden in the main bottle server, so the routes are not accessible. This patch fixes it by renaming those methods.

Check here:
https://github.com/apache/aurora/blob/master/src/main/python/apache/thermos/observer/http/http_observer.py#L72

Testing Done:
There was no unit test affected.

After fixing the routes server the expected content.
```
? curl http://192.168.33.7:1338/j/task_ids
{"type": "all", "tasks": [{"status": "sleeping", "ram": 3727360, "state_timestamp": 1523728477, "threads": 2, "user": 0.24, "disk": 10117120, "launch_timestamp": 1523728477, "vms": 22990848, "rss": 3727360, "name": "hello", "task_id": "www-data-prod-hello-0-00e58d09-a67f-4a46-94a0-15bcad26a098", "system": 0.34, "ports": {}, "state": "ACTIVE", "role": "www-data", "cpu": 0.0, "nice": 0}], "num": 20, "task_count": 1, "offset": 0}%

? curl http://192.168.33.7:1338/j/task/www-data-prod-hello-0-00e58d09-a67f-4a46-94a0-15bcad26a098
{"www-data-prod-hello-0-00e58d09-a67f-4a46-94a0-15bcad26a098": {"task": {"processes": [{"daemon": false, "name": "hello", "max_failures": 1, "ephemeral": false, "min_duration": 5, "cmdline": "\n    while true; do\n      echo hello world\n      sleep 10\n    done\n  ", "final": false}], "name": "hello", "finalization_wait": 30, "max_failures": 1, "max_concurrency": 0, "resources": {"gpu": 0, "disk": 134217728, "ram": 134217728, "cpu": 1.0}, "constraints": [{"order": ["hello"]}]}, "name": "hello", "task_id": "www-data-prod-hello-0-00e58d09-a67f-4a46-94a0-15bcad26a098", "processes": {"failed": [], "running": ["hello"], "killed": [], "success": [], "waiting": []}, "state_timestamp": 1523728477, "state": "ACTIVE", "resource_consumption": {"status": "sleeping", "disk": 10113024, "ram": 3719168, "system": 0.33, "vms": 22990848, "threads": 2, "user": 0.24, "rss": 3719168, "cpu": 0.0, "nice": 0}, "user": "www-data", "launch_timestamp": 1523728477, "ports": {}}}%

? curl http://192.168.33.7:1338/j/task\?task_id\=www-data-prod-hello-0-00e58d09-a67f-4a46-94a0-15bcad26a098
{"www-data-prod-hello-0-00e58d09-a67f-4a46-94a0-15bcad26a098": {"task": {"processes": [{"daemon": false, "name": "hello", "max_failures": 1, "ephemeral": false, "min_duration": 5, "cmdline": "\n    while true; do\n      echo hello world\n      sleep 10\n    done\n  ", "final": false}], "name": "hello", "finalization_wait": 30, "max_failures": 1, "max_concurrency": 0, "resources": {"gpu": 0, "disk": 134217728, "ram": 134217728, "cpu": 1.0}, "constraints": [{"order": ["hello"]}]}, "name": "hello", "task_id": "www-data-prod-hello-0-00e58d09-a67f-4a46-94a0-15bcad26a098", "processes": {"failed": [], "running": ["hello"], "killed": [], "success": [], "waiting": []}, "state_timestamp": 1523728477, "state": "ACTIVE", "resource_consumption": {"status": "sleeping", "disk": 10141696, "ram": 3731456, "system": 0.35, "vms": 22994944, "threads": 2, "user": 0.24, "rss": 3731456, "cpu": 0.0, "nice": 0}, "user": "www-data", "launch_timestamp": 1523728477, "ports": {}}}%

? curl http://192.168.33.7:1338/j/process/www-data-prod-hello-0-00e58d09-a67f-4a46-94a0-15bcad26a098/hello/0
{"state": "RUNNING", "process_name": "hello", "used": {"status": "sleeping", "ram": 3735552, "system": 0.34, "vms": 22990848, "threads": 2, "user": 0.24, "rss": 3735552, "cpu": 0.0, "nice": 0}, "start_time": 1523728477.867429, "process_run": 0}%

? curl http://192.168.33.7:1338/j/processes\?task_id\=www-data-prod-hello-0-00e58d09-a67f-4a46-94a0-15bcad26a098
{"www-data-prod-hello-0-00e58d09-a67f-4a46-94a0-15bcad26a098": {"hello": {"state": "RUNNING", "process_name": "hello", "used": {"status": "sleeping", "ram": 3735552, "system": 0.35, "vms": 22994944, "threads": 2, "user": 0.25, "rss": 3735552, "cpu": 0.0005000061512750167, "nice": 0}, "start_time": 1523728477.867429, "process_run": 0}}}%
```

Reviewed at https://reviews.apache.org/r/66623/
  • Loading branch information
rezmont authored and shanmugh committed Apr 20, 2018
1 parent 38aae0f commit 02a685117562e8eec81a0d4546fbbf300d8a7893
Showing 2 changed files with 8 additions and 7 deletions.
@@ -26,18 +26,18 @@ class TaskObserverJSONBindings(object):
@HttpServer.route("/j/task_ids/:which")
@HttpServer.route("/j/task_ids/:which/:offset")
@HttpServer.route("/j/task_ids/:which/:offset/:num")
def handle_task_ids(self, which=None, offset=None, num=None):
return self._observer.task_ids(
def handle_json_task_ids(self, which=None, offset=None, num=None):
return self._observer.main(
which,
int(offset) if offset is not None else 0,
int(num) if num is not None else 20)

@HttpServer.route("/j/task_id_count")
def handle_task_id_count(self):
def handle_json_task_id_count(self):
return self._observer.task_id_count()

@HttpServer.route("/j/task")
def handle_tasks(self):
def handle_json_tasks(self):
"""
Additional parameters:
task_id = comma separated list of task_ids.
@@ -48,17 +48,17 @@ def handle_tasks(self):
return self._observer.tasks(task_ids)

@HttpServer.route("/j/task/:task_id")
def handle_task(self, task_id):
def handle_json_task(self, task_id):
return self._observer.tasks([task_id])

@HttpServer.route("/j/process/:task_id")
@HttpServer.route("/j/process/:task_id/:process")
@HttpServer.route("/j/process/:task_id/:process/:run")
def handle_process(self, task_id, process=None, run=None):
def handle_json_process(self, task_id, process=None, run=None):
return self._observer.process(task_id, process, run)

@HttpServer.route("/j/processes")
def handle_processes(self):
def handle_json_processes(self):
"""
Additional parameters:
task_ids = comma separated list of task_ids.
@@ -17,6 +17,7 @@ python_tests(
sources = globs('*.py'),
dependencies = [
'3rdparty/python:mock',
'3rdparty/python:requests',
'src/main/python/apache/thermos/monitoring',
'src/main/python/apache/thermos/observer',
]

0 comments on commit 02a6851

Please sign in to comment.