From 7db1a3456b7f02acd4611952d77ce94bf71d373e Mon Sep 17 00:00:00 2001 From: Dunemask Date: Sun, 8 May 2022 01:36:22 +0000 Subject: [PATCH] Updated Tables --- ROADMAP.md | 32 ++++++++++++++++++++ lib/core/JobManager.js | 10 ++++-- lib/core/Qualiteer.js | 6 ++-- lib/core/server.js | 8 +++++ lib/database/TABLES.md | 42 ++++++++++++++++++++++++++ lib/database/queries/silenced_tests.js | 15 +++++++++ lib/database/queries/tests.js | 15 +++++++++ lib/routes/alerting-route.js | 18 +++++++++++ lib/routes/jobs-route.js | 12 ++++++++ lib/routes/react-route.js | 6 ++++ lib/routes/results-route.js | 13 ++++++-- lib/routes/tests-route.js | 22 ++++++++++++++ package.json | 2 +- 13 files changed, 192 insertions(+), 9 deletions(-) create mode 100644 ROADMAP.md create mode 100644 lib/database/TABLES.md create mode 100644 lib/database/queries/silenced_tests.js create mode 100644 lib/database/queries/tests.js create mode 100644 lib/routes/alerting-route.js create mode 100644 lib/routes/jobs-route.js create mode 100644 lib/routes/react-route.js create mode 100644 lib/routes/tests-route.js diff --git a/ROADMAP.md b/ROADMAP.md new file mode 100644 index 0000000..23384cb --- /dev/null +++ b/ROADMAP.md @@ -0,0 +1,32 @@ +# Roadmap +### The end goal of this application is to provide a powerful application able to process and handle all of the your realtime QA data needs + +## v0.0.1 +- [x] Initial Skeleton +- [x] Frontend Drafts +- [ ] Frontend Core +- [ ] Frontend Pages + +## v0.0.2 +- [ ] Database Queries (Req PG) +- [ ] Database Tables (Req PG) +- [ ] Backend Routes (Req Database) +- [ ] Crons + +## v0.0.3 +- [ ] Rabbitmq Consumers (Req Database) +- [ ] Alerting +- [ ] Silencing + +## v0.0.4 +- [ ] Auth + +## v0.0.5 +- [ ] Docker config +- [ ] Gitlab Integration +- [ ] Garden config + +## v0.0.6 +- [ ] Internal Tests +- [ ] Self Test Suite + diff --git a/lib/core/JobManager.js b/lib/core/JobManager.js index 2a2053a..84857fc 100644 --- a/lib/core/JobManager.js +++ b/lib/core/JobManager.js @@ -1,9 +1,11 @@ import { v4 } from "uuid"; import applyJob from "./kubernetes.js"; -export default class JobManager { - constructor(clientMaxJobs) { - this.clientMaxJobs = clientMaxJobs; +const maxJobs = process.env.MAX_JOBS ? parseInt(process.env.MAX_JOBS) : 3; + +class JobManager { + constructor() { + this.clientMaxJobs = maxJobs; this.clients = {}; } @@ -53,3 +55,5 @@ export default class JobManager { ); } } + +export default new JobManager(); diff --git a/lib/core/Qualiteer.js b/lib/core/Qualiteer.js index 17fb422..92f8ea2 100644 --- a/lib/core/Qualiteer.js +++ b/lib/core/Qualiteer.js @@ -6,7 +6,7 @@ import { INFO, OK, logInfo } from "../util/logging.js"; // Import Core Modules import expressApp from "./server.js"; import applySockets from "../sockets/handler.js"; -import JobManager from "./JobManager.js"; +import jobManager from "./JobManager.js"; import rabbiteer from "../rabbit/rabbit-workers.js"; // Constants @@ -17,12 +17,12 @@ const port = process.env.QUALITEER_DEV_PORT ?? 52000; export default class Qualiteer { constructor(options = {}) { for (var k in options) this[k] = options[k]; - this.jobs = new JobManager(options.maxClientJobs ?? 3); + this.jobs = jobManager; this.port = options.port ?? port; } async _preinitialize() { - logInfo(fig.textSync(title, "Cosmike")); + logInfo(fig.textSync(title, "Cyberlarge")); INFO("INIT", "Initializing..."); this.app = expressApp; this.server = http.createServer(this.app); diff --git a/lib/core/server.js b/lib/core/server.js index 5fea567..8ebddbb 100644 --- a/lib/core/server.js +++ b/lib/core/server.js @@ -3,6 +3,10 @@ import express from "express"; // Routes import results from "../routes/results-route.js"; +import alerting from "../routes/alerting-route.js"; +import react from "../routes/react-route.js"; +import tests from "../routes/tests-route.js"; +import jobs from "../routes/jobs-route.js"; const app = express(); app.all("/", (req, res) => res.redirect("/qualiteer")); @@ -10,6 +14,10 @@ app.all("/", (req, res) => res.redirect("/qualiteer")); // Middlewares // Routes +app.use(react); // Static Build Route app.use("/api/results", results); +app.use("/api/alerting", alerting); +app.use("/api/tests", tests); +app.use("/api/jobs", jobs); export default app; diff --git a/lib/database/TABLES.md b/lib/database/TABLES.md new file mode 100644 index 0000000..d128ade --- /dev/null +++ b/lib/database/TABLES.md @@ -0,0 +1,42 @@ +CREATE SEQUENCE test_results_id_seq; +CREATE TABLE test_results ( + id bigint NOT NULL DEFAULT nextval('test_results_seq') PRIMARY KEY, + test_name varchar(255) DEFAULT NULL, + test_class varchar(255) DEFAULT NULL, + test_method varchar(255) DEFAULT NULL, + test_path varchar(255) DEFAULT NULL, + test_type varchar(32) DEFAULT NULL, + test_timestamp timestamptz NOT NULL DEFAULT now(), + test_retry BOOLEAN DEFAULT FALSE, + origin varchar(255) DEFAULT NULL, + failed BOOLEAN DEFAULT FALSE, + failed_message varchar(2047) DEFAULT NULL, + screenshot_url varchar(255) DEFAULT NULL, + weblog_url varchar(255) DEFAULT NULL, +); +ALTER SEQUENCE test_results_id_seq OWNED BY test_results.id; + +# Tables +PG Database Tables Mapped Out + +## ```test_results``` +| id | test_name | test_class | test_method | test_path | test_type | test_timestamp | test_retry | origin | failed | failed_message | screenshot_url | weblog_url | +| int | string | string | string | string | string | timestamp | boolean | string | boolean | string | string | string | +| 1 | My Test | My Test Class | My Failing Test Method | My Test Class Path | API | Date.now() | false | Test Suite A | true | Some Failure Messsage | screenshotUrl | weblogUrl | + +- id Automatically Generated +- test_name\* Name of test +- test_class\* Name of class +- test_method Name of failed method if failed else null +- test_path Path to test class +- test_type API/UI/Mobile +- test_timestamp UTC Timestamp +- test_retry Should test remedy failed tests +- origin Test Suite test belongs to +- failed Indicates if the test failed or not +- failed_message Failure Message of test or null +- screenshot_url Screenshot of failure +- weblog_url Log from the web console + + + diff --git a/lib/database/queries/silenced_tests.js b/lib/database/queries/silenced_tests.js new file mode 100644 index 0000000..bf1049e --- /dev/null +++ b/lib/database/queries/silenced_tests.js @@ -0,0 +1,15 @@ +import pg from "../postgres.js"; +// Imports +import { + insertQuery, + selectWhereAnyQuery, + updateWhereAnyQuery, +} from "../pg-query.js"; +// Constants +const table = "silenced_tests"; +// Queries +export const getSilencedTests = () => { + const query = `SELECT * from ${table}`; + return pg.query(query); +}; + diff --git a/lib/database/queries/tests.js b/lib/database/queries/tests.js new file mode 100644 index 0000000..82ce5dd --- /dev/null +++ b/lib/database/queries/tests.js @@ -0,0 +1,15 @@ +import pg from "../postgres.js"; +// Imports +import { + insertQuery, + selectWhereAnyQuery, + updateWhereAnyQuery, +} from "../pg-query.js"; +// Constants +const table = "tests"; +// Queries +export const getTests = () => { + const query = `SELECT * from ${table}`; + return pg.query(query); +}; + diff --git a/lib/routes/alerting-route.js b/lib/routes/alerting-route.js new file mode 100644 index 0000000..f328235 --- /dev/null +++ b/lib/routes/alerting-route.js @@ -0,0 +1,18 @@ +import { Router, json as jsonMiddleware } from "express"; +import { getSilencedTests } from "../database/queries/silenced_tests.js"; +const router = Router(); + +// Apply Middlewares +router.use(jsonMiddleware()); + +// Get Routes +router.get("/silenced", (req, res) => { + getSilencedTests().then(res.send); +}); + +// Post Routes +router.post("/silence", (req,res)=>{ + res.sendStatus(200); +}); + +export default router; diff --git a/lib/routes/jobs-route.js b/lib/routes/jobs-route.js new file mode 100644 index 0000000..b007a19 --- /dev/null +++ b/lib/routes/jobs-route.js @@ -0,0 +1,12 @@ +import { Router, json as jsonMiddleware } from "express"; +import jobs from "../core/JobManager.js"; + +const router = Router(); + +router.get("/jobs", (req, res) => { + const { clients } = jobs; + const allJobs = []; + for(var c of clients) allJobs.push(...c.jobs); + res.json(allJobs); +}); +export default router; diff --git a/lib/routes/react-route.js b/lib/routes/react-route.js new file mode 100644 index 0000000..1a43041 --- /dev/null +++ b/lib/routes/react-route.js @@ -0,0 +1,6 @@ +import express, { Router } from "express"; + +const router = Router(); + +router.use("/qualiteer", express.static("build/")); +export default router; diff --git a/lib/routes/results-route.js b/lib/routes/results-route.js index aebb013..8675d09 100644 --- a/lib/routes/results-route.js +++ b/lib/routes/results-route.js @@ -1,9 +1,18 @@ -import express from "express"; +import { Router, json as jsonMiddleware } from "express"; import { getCurrentlyFailing } from "../database/queries/test_results.js"; -const router = express.Router(); +const router = Router(); +// Apply Middlewares +router.use(jsonMiddleware()); + +// Get Routes router.get("/failing", (req, res) => { res.send([]); }); +// Post Routes +router.post("/history", (req,res)=>{ + res.send([]); +}); + export default router; diff --git a/lib/routes/tests-route.js b/lib/routes/tests-route.js new file mode 100644 index 0000000..2cb1d38 --- /dev/null +++ b/lib/routes/tests-route.js @@ -0,0 +1,22 @@ +import { Router, json as jsonMiddleware } from "express"; +import { getTests } from "../database/queries/tests.js"; +const router = Router(); + +const maxSize = 1024 * 1024 * 100; // 100MB + +// Apply Middlewares +router.use(jsonMiddleware({limit: maxSize})); + +// Get Routes +router.get("/tests", async (req, res) => { + const tests = await getTests(); + res.json(tests); +}); + +// Post Routes +router.post("/update", (req,res)=>{ + // Update All Tests + res.sendStatus(200); +}); + +export default router; diff --git a/package.json b/package.json index 3ccaaef..aaf16d4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "qualiteer", - "version": "1.0.0", + "version": "0.0.1", "description": "QA Data Management", "license": "LGPL-2.1-only", "author": "Dunemask",