Skip to content

Commit

Permalink
Make the meaning of some strings in the schemas explicit.
Browse files Browse the repository at this point in the history
  • Loading branch information
vdbergh authored and ppigazzini committed Feb 24, 2024
1 parent f9959ec commit 5898806
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 38 deletions.
129 changes: 96 additions & 33 deletions server/fishtest/actiondb.py
Original file line number Diff line number Diff line change
@@ -1,98 +1,164 @@
from datetime import datetime, timezone

from bson.objectid import ObjectId
from fishtest.util import hex_print, worker_name
from pymongo import DESCENDING
from vtjson import _validate, union
from vtjson import regex, union, validate

run_id = regex(r"[a-f0-9]{24}", name="run_id")
run_name = regex(r".*-[a-f0-9]{7}", name="run_name")
short_worker_name = regex(r".*-[\d]+cores-[a-z0-9]{2,8}", name="short_worker_name")
long_worker_name = regex(
r".*-[\d]+cores-[a-z0-9]{2,8}-[a-f0-9]{4}\*?", name="long_worker_name"
)

schema = union(
{
"_id?": ObjectId,
"time": float,
"action": "failed_task",
"username": str,
"worker": str,
"run_id": str,
"run": str,
"worker": long_worker_name,
"run_id": run_id,
"run": run_name,
"task_id": int,
"message": str,
},
{
"_id?": ObjectId,
"time": float,
"action": "crash_or_time",
"username": str,
"worker": str,
"run_id": str,
"run": str,
"worker": long_worker_name,
"run_id": run_id,
"run": run_name,
"task_id": int,
"message": str,
},
{
"_id?": ObjectId,
"time": float,
"action": "dead_task",
"username": str,
"worker": str,
"run_id": str,
"run": str,
"worker": long_worker_name,
"run_id": run_id,
"run": run_name,
"task_id": int,
},
{"action": "system_event", "username": "fishtest.system", "message": str},
{
"_id?": ObjectId,
"time": float,
"action": "system_event",
"username": "fishtest.system",
"message": str,
},
{
"_id?": ObjectId,
"time": float,
"action": "new_run",
"username": str,
"run_id": str,
"run": str,
"run_id": run_id,
"run": run_name,
"message": str,
},
{"action": "upload_nn", "username": str, "nn": str},
{
"_id?": ObjectId,
"time": float,
"action": "upload_nn",
"username": str,
"nn": str,
},
{
"_id?": ObjectId,
"time": float,
"action": "modify_run",
"username": str,
"run_id": str,
"run": str,
"run_id": run_id,
"run": run_name,
"message": str,
},
{"action": "delete_run", "username": str, "run_id": str, "run": str},
{
"_id?": ObjectId,
"time": float,
"action": "delete_run",
"username": str,
"run_id": run_id,
"run": run_name,
},
{
"_id?": ObjectId,
"time": float,
"action": "stop_run",
"username": str,
"worker": str,
"run_id": str,
"run": str,
"worker": long_worker_name,
"run_id": run_id,
"run": run_name,
"task_id": int,
"message": str,
},
{
"_id?": ObjectId,
"time": float,
"action": "stop_run",
"username": str,
"run_id": str,
"run": str,
"run_id": run_id,
"run": run_name,
"message": str,
},
{
"_id?": ObjectId,
"time": float,
"action": "finished_run",
"username": str,
"run_id": str,
"run": str,
"run_id": run_id,
"run": run_name,
"message": str,
},
{
"_id?": ObjectId,
"time": float,
"action": "approve_run",
"username": str,
"run_id": run_id,
"run": run_name,
},
{
"_id?": ObjectId,
"time": float,
"action": "purge_run",
"username": str,
"run_id": run_id,
"run": run_name,
"message": str,
},
{"action": "approve_run", "username": str, "run_id": str, "run": str},
{"action": "purge_run", "username": str, "run_id": str, "run": str, "message": str},
{
"_id?": ObjectId,
"time": float,
"action": "block_user",
"username": str,
"user": str,
"message": union("blocked", "unblocked"),
},
{
"_id?": ObjectId,
"time": float,
"action": "accept_user",
"username": str,
"user": str,
"message": "accepted",
},
{
"_id?": ObjectId,
"time": float,
"action": "block_worker",
"username": str,
"worker": str,
"worker": short_worker_name,
"message": union("blocked", "unblocked"),
},
)

del long_worker_name, run_id, run_name, short_worker_name


def run_name(run):
run_id = str(run["_id"])
Expand Down Expand Up @@ -295,9 +361,6 @@ def block_worker(self, username=None, worker=None, message=None):
def insert_action(self, **action):
if "run_id" in action:
action["run_id"] = str(action["run_id"])
ret = _validate(schema, action, "action")
if ret == "":
action["time"] = datetime.now(timezone.utc).timestamp()
self.actions.insert_one(action)
else:
raise Exception("Validation failed with error '{}'".format(ret))
action["time"] = datetime.now(timezone.utc).timestamp()
validate(schema, action, "action") # may raise exception
self.actions.insert_one(action)
2 changes: 1 addition & 1 deletion server/fishtest/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"""

run_id = regex(r"[a-f0-9]{24}", name="run_id")
uuid = regex(r"[0-9a-zA-z]{2,8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}", name="uuid")
uuid = regex(r"[0-9a-zA-Z]{2,8}(-[a-f0-9]{4}){3}-[a-f0-9]{12}", name="uuid")

uint = intersect(int, interval(0, ...))
suint = intersect(int, interval(1, ...))
Expand Down
4 changes: 3 additions & 1 deletion server/fishtest/rundb.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
sha = regex(r"[a-f0-9]{40}", name="sha")
country_code = regex(r"[A-Z][A-Z]", name="country_code")
run_id = regex(r"[a-f0-9]{24}", name="run_id")
uuid = regex(r"[0-9a-zA-Z]{2,8}(-[a-f0-9]{4}){3}-[a-f0-9]{12}", name="uuid")

worker_info_schema = {
"uname": str,
Expand All @@ -68,7 +69,7 @@
"python_version": [int, int, int],
"gcc_version": [int, int, int],
"compiler": union("clang++", "g++"),
"unique_key": str,
"unique_key": uuid,
"modified": bool,
"ARCH": str,
"nps": number,
Expand Down Expand Up @@ -230,6 +231,7 @@
tc,
union,
url,
uuid,
worker_info_schema,
)

Expand Down
10 changes: 7 additions & 3 deletions server/fishtest/workerdb.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from datetime import datetime, timezone

from vtjson import _validate
from bson.objectid import ObjectId
from vtjson import regex, validate

short_worker_name = regex(r".*-[\d]+cores-[a-z0-9]{2,8}", name="short_worker_name")

schema = {
"worker_name": str,
"_id?": ObjectId,
"worker_name": short_worker_name,
"blocked": bool,
"message": str,
"last_updated": datetime,
Expand Down Expand Up @@ -40,7 +44,7 @@ def update_worker(self, worker_name, blocked=None, message=None):
"message": message,
"last_updated": datetime.now(timezone.utc),
}
assert _validate(schema, r, "worker") == ""
validate(schema, r, "worker") # may throw exception
self.workers.replace_one({"worker_name": worker_name}, r, upsert=True)

def get_blocked_workers(self):
Expand Down

0 comments on commit 5898806

Please sign in to comment.