mirror of
https://github.com/neondatabase/neon.git
synced 2026-05-23 16:10:37 +00:00
Store Allure tests statistics in database (#2367)
This commit is contained in:
committed by
GitHub
parent
dc2150a90e
commit
83dca73f85
@@ -2,6 +2,7 @@
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
from contextlib import contextmanager
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
@@ -26,7 +27,7 @@ CREATE TABLE IF NOT EXISTS perf_test_results (
|
||||
|
||||
def err(msg):
|
||||
print(f"error: {msg}")
|
||||
exit(1)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
@contextmanager
|
||||
@@ -43,8 +44,8 @@ def create_table(cur):
|
||||
cur.execute(CREATE_TABLE)
|
||||
|
||||
|
||||
def ingest_perf_test_result(cursor, data_dile: Path, recorded_at_timestamp: int) -> int:
|
||||
run_data = json.loads(data_dile.read_text())
|
||||
def ingest_perf_test_result(cursor, data_file: Path, recorded_at_timestamp: int) -> int:
|
||||
run_data = json.loads(data_file.read_text())
|
||||
revision = run_data["revision"]
|
||||
platform = run_data["platform"]
|
||||
|
||||
|
||||
97
scripts/ingest_regress_test_result.py
Normal file
97
scripts/ingest_regress_test_result.py
Normal file
@@ -0,0 +1,97 @@
|
||||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
from contextlib import contextmanager
|
||||
from pathlib import Path
|
||||
|
||||
import psycopg2
|
||||
|
||||
CREATE_TABLE = """
|
||||
CREATE TABLE IF NOT EXISTS regress_test_results (
|
||||
id SERIAL PRIMARY KEY,
|
||||
reference CHAR(255),
|
||||
revision CHAR(40),
|
||||
build_type CHAR(16),
|
||||
data JSONB
|
||||
)
|
||||
"""
|
||||
|
||||
|
||||
def err(msg):
|
||||
print(f"error: {msg}")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
@contextmanager
|
||||
def get_connection_cursor():
|
||||
connstr = os.getenv("DATABASE_URL")
|
||||
if not connstr:
|
||||
err("DATABASE_URL environment variable is not set")
|
||||
with psycopg2.connect(connstr, connect_timeout=30) as conn:
|
||||
with conn.cursor() as cur:
|
||||
yield cur
|
||||
|
||||
|
||||
def create_table(cur):
|
||||
cur.execute(CREATE_TABLE)
|
||||
|
||||
|
||||
def ingest_regress_test_result(
|
||||
cursor, reference: str, revision: str, build_type: str, data_file: Path
|
||||
):
|
||||
values = (
|
||||
reference,
|
||||
revision,
|
||||
build_type,
|
||||
data_file.read_text(),
|
||||
)
|
||||
cursor.execute(
|
||||
"""
|
||||
INSERT INTO regress_test_results (
|
||||
reference,
|
||||
revision,
|
||||
build_type,
|
||||
data
|
||||
) VALUES (%s, %s, %s, %s)
|
||||
""",
|
||||
values,
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Regress test result uploader. \
|
||||
Database connection string should be provided via DATABASE_URL environment variable",
|
||||
)
|
||||
parser.add_argument("--initdb", action="store_true", help="Initialuze database")
|
||||
parser.add_argument(
|
||||
"--reference", type=str, required=True, help="git reference, for example refs/heads/main"
|
||||
)
|
||||
parser.add_argument("--revision", type=str, required=True, help="git revision")
|
||||
parser.add_argument(
|
||||
"--build-type", type=str, required=True, help="build type: release, debug or remote"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--ingest", type=Path, required=True, help="Path to regress test result file"
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
with get_connection_cursor() as cur:
|
||||
if args.initdb:
|
||||
create_table(cur)
|
||||
|
||||
if not args.ingest.exists():
|
||||
err(f"ingest path {args.ingest} does not exist")
|
||||
|
||||
ingest_regress_test_result(
|
||||
cur,
|
||||
reference=args.reference,
|
||||
revision=args.revision,
|
||||
build_type=args.build_type,
|
||||
data_file=args.ingest,
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user