Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for the system stats query endpoint. #37

Merged
merged 5 commits into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .ci/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
DOCKER_CONTAINER_NAME = 'autograder-py-verify-test-data'
DOCKER_START_SLEEP_TIME_SECS = 0.25
DOCKER_STOP_WAIT_TIME_SECS = 1
DOCKER_STOP_FINAL_WAIT_TIME_SECS = 0.5

SOURCE_START_SLEEP_TIME_SECS = 0.25
SOURCE_KILL_SLEEP_TIME_SECS = 0.25
Expand Down Expand Up @@ -91,6 +92,7 @@ def stop(self, **kwargs):
]

util.run(args)
time.sleep(DOCKER_STOP_FINAL_WAIT_TIME_SECS)
self._is_running = False

def reset(self, **kwargs):
Expand Down
Empty file.
Empty file.
36 changes: 36 additions & 0 deletions autograder/api/stats/system/query.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import autograder.api.common
import autograder.api.config

API_ENDPOINT = 'stats/system/query'
API_PARAMS = [
autograder.api.config.PARAM_USER_EMAIL,
autograder.api.config.PARAM_USER_PASS,

autograder.api.config.APIParam('limit',
'The maximum number of records to return.',
required = False, parser_options = {'action': 'store', 'type': int}),

autograder.api.config.APIParam('after',
'If supplied, only return stat records after this timestamp.',
required = False),

autograder.api.config.APIParam('before',
'If supplied, only return stat records before this timestamp.',
required = False),

autograder.api.config.APIParam('sort',
'Sort the results. -1 for ascending, 0 for no sorting, 1 for descending.',
required = False, parser_options = {'action': 'store', 'type': int}),
]

DESCRIPTION = 'Query system stats from the autograder server.'

def send(arguments, **kwargs):
return autograder.api.common.handle_api_request(arguments, API_PARAMS, API_ENDPOINT, **kwargs)

def _get_parser():
parser = autograder.api.config.get_argument_parser(
description = DESCRIPTION,
params = API_PARAMS)

return parser
Empty file.
14 changes: 14 additions & 0 deletions autograder/cli/stats/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""
The `autograder.cli.stats` package contains tools for
managing stats from the autograder server.
"""

import sys

import autograder.util.cli

def main():
return autograder.util.cli.main()

if (__name__ == '__main__'):
sys.exit(main())
Empty file.
14 changes: 14 additions & 0 deletions autograder/cli/stats/system/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""
The `autograder.cli.stats.system` package contains tools for
managing system-level stats from the autograder server.
"""

import sys

import autograder.util.cli

def main():
return autograder.util.cli.main()

if (__name__ == '__main__'):
sys.exit(main())
20 changes: 20 additions & 0 deletions autograder/cli/stats/system/query.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import json
import sys

import autograder.api.stats.system.query

def run(arguments):
result = autograder.api.stats.system.query.send(arguments, exit_on_error = True)
print(json.dumps(result['results'], indent = 4))
return 0

def main():
return run(_get_parser().parse_args())

def _get_parser():
parser = autograder.api.stats.system.query._get_parser()

return parser

if (__name__ == '__main__'):
sys.exit(main())
32 changes: 32 additions & 0 deletions tests/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,35 @@ def clean_output_logs(output):
return output

_discover_api_tests()

def fake_system_stats(output):
"""
Because of the variable and fine-grained level of system stats,
the entire output must be faked.
"""

return {
"results": [
{
"timestamp": 100,
"cpu-percent": 1,
"mem-percent": 1,
"net-bytes-sent": 1,
"net-bytes-received": 1,
},
{
"timestamp": 200,
"cpu-percent": 2,
"mem-percent": 2,
"net-bytes-sent": 2,
"net-bytes-received": 2,
},
{
"timestamp": 300,
"cpu-percent": 3,
"mem-percent": 3,
"net-bytes-sent": 3,
"net-bytes-received": 3,
},
],
}
5 changes: 5 additions & 0 deletions tests/api/testdata/metadata/metadata_describe_base.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@
"response-type": "*metadata.DescribeResponse",
"description": "Describe all endpoints on the server."
},
"stats/system/query": {
"request-type": "*system.QueryRequest",
"response-type": "*system.QueryResponse",
"description": "Query the system stats for the server."
},
"users/auth": {
"request-type": "*users.AuthRequest",
"response-type": "*users.AuthResponse",
Expand Down
33 changes: 33 additions & 0 deletions tests/api/testdata/stats/system/stats_system_query_base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"module": "autograder.api.stats.system.query",
"arguments": {
"user": "[email protected]",
"pass": "server-admin"
},
"output-modifier": "fake_system_stats",
"output": {
"results": [
{
"timestamp": 100,
"cpu-percent": 1,
"mem-percent": 1,
"net-bytes-sent": 1,
"net-bytes-received": 1
},
{
"timestamp": 200,
"cpu-percent": 2,
"mem-percent": 2,
"net-bytes-sent": 2,
"net-bytes-received": 2
},
{
"timestamp": 300,
"cpu-percent": 3,
"mem-percent": 3,
"net-bytes-sent": 3,
"net-bytes-received": 3
}
]
}
}
5 changes: 5 additions & 0 deletions tests/cli/testdata/metadata/metadata_describe_base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@
"response-type": "*metadata.DescribeResponse",
"description": "Describe all endpoints on the server."
},
"stats/system/query": {
"request-type": "*system.QueryRequest",
"response-type": "*system.QueryResponse",
"description": "Query the system stats for the server."
},
"users/auth": {
"request-type": "*users.AuthRequest",
"response-type": "*users.AuthResponse",
Expand Down
31 changes: 31 additions & 0 deletions tests/cli/testdata/stats/system/stats_system_query_base.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"cli": "autograder.cli.stats.system.query",
"arguments": [
"--user", "[email protected]",
"--pass", "server-admin"
]
}
---
[
{
"timestamp": 100,
"cpu-percent": 1,
"mem-percent": 1,
"net-bytes-sent": 1,
"net-bytes-received": 1
},
{
"timestamp": 200,
"cpu-percent": 2,
"mem-percent": 2,
"net-bytes-sent": 2,
"net-bytes-received": 2
},
{
"timestamp": 300,
"cpu-percent": 3,
"mem-percent": 3,
"net-bytes-sent": 3,
"net-bytes-received": 3
}
]
Loading