From 84cae9807a41ca9b0bc3f5f2aa005fe91fb9c168 Mon Sep 17 00:00:00 2001 From: Kevan-Y <58233223+Kevan-Y@users.noreply.github.com> Date: Tue, 30 Nov 2021 16:55:52 -0500 Subject: [PATCH] Add API status to the new dashboard --- src/api/status/public/index.html | 436 +------------------- src/api/status/public/js/pages/dashboard.js | 2 + src/api/status/public/js/serviceStatus.js | 71 ++++ src/api/status/src/server.js | 11 + 4 files changed, 98 insertions(+), 422 deletions(-) create mode 100644 src/api/status/public/js/serviceStatus.js diff --git a/src/api/status/public/index.html b/src/api/status/public/index.html index 5adcdc574b..5828fbf3c6 100644 --- a/src/api/status/public/index.html +++ b/src/api/status/public/index.html @@ -444,43 +444,12 @@
Completed Tasks
-
-
Projects
+
+
Telescope API Status

- - 30 done this month + Status of the Telescope Web and Microservices API servers.

-
- -
@@ -491,404 +460,27 @@
Projects
- Companies - - - Members + Service - Budget + Staging - Completion + Production - - - -
-
- xd -
-
-
Material XD Version
-
-
- - - - - - $14,000 - - -
-
-
- 60% -
-
-
-
-
-
- - - - -
-
- atlassian -
-
-
Add Progress Track
-
-
- - - - - - $3,000 - - -
-
-
- 10% -
-
-
-
-
-
- - - - -
-
- team7 -
-
-
Fix Platform Errors
-
-
- - - - - - Not set - - -
-
-
- 100% -
-
-
-
-
-
- - - - -
-
- spotify -
-
-
Launch our Mobile App
-
-
- - - - - - $20,500 - - -
-
-
- 100% -
-
-
-
-
-
- - + - -
-
- jira -
-
-
Add the New Pricing Page
-
-
- - -
- - user5 - -
- - - $500 - - -
-
-
- 25% -
-
-
-
-
-
- - - - -
-
- invision -
-
-
Redesign New Online Shop
-
-
- - - - - - $2,000 - - -
-
-
- 40% -
-
-
-
-
+ +
+
+ Loading... +
diff --git a/src/api/status/public/js/pages/dashboard.js b/src/api/status/public/js/pages/dashboard.js index 4c5b4158a2..71557f1f38 100644 --- a/src/api/status/public/js/pages/dashboard.js +++ b/src/api/status/public/js/pages/dashboard.js @@ -1,10 +1,12 @@ import getPostsCount from '../post/index.js'; import getFeedCount from '../feed/index.js'; import getGitHubData from '../github-stats.js'; +import getAllServicesStatus from '../serviceStatus.js'; window.addEventListener('load', () => { getGitHubData('Seneca-CDOT', 'telescope'); getGitHubData('Seneca-CDOT', 'satellite'); getFeedCount(); getPostsCount(); + getAllServicesStatus(); }); diff --git a/src/api/status/public/js/serviceStatus.js b/src/api/status/public/js/serviceStatus.js new file mode 100644 index 0000000000..a14329de0a --- /dev/null +++ b/src/api/status/public/js/serviceStatus.js @@ -0,0 +1,71 @@ +const reportTbody = () => document.querySelector('#report'); +const requestMessageReport = () => document.querySelector('#request-message'); + +// Create td for service name +const createTdText = (content) => { + const td = document.createElement('td'); + const div = document.createElement('div'); + const h6 = document.createElement('h6'); + + h6.className = 'text-capitalize mb-0 text-sm'; + h6.innerHTML = content; + div.className = 'text-start px-2 py-1'; + div.appendChild(h6); + td.appendChild(div); + + return td; +}; + +// Create td for icon +const createTdIcon = (status) => { + const td = document.createElement('td'); + const icon = document.createElement('i'); + + td.className = 'align-middle text-center'; + icon.title = status; + icon.className = + status >= 200 && status <= 299 + ? 'text-lg text-success fas fa-check-circle' + : 'text-lg text-danger fas fa-exclamation-circle'; + + td.appendChild(icon); + + return td; +}; + +// Create row of the table +const serviceRowFormat = (result) => { + const { + name, + status: { staging, production }, + } = result; + const tr = document.createElement('tr'); + + tr.appendChild(createTdText(name)); + tr.appendChild(createTdIcon(staging)); + tr.appendChild(createTdIcon(production)); + reportTbody().appendChild(tr); +}; + +export default function getAllServicesStatus() { + fetch('/v1/status/status') + .then((res) => { + if (res.ok) return res.json(); + + const messageReport = requestMessageReport(); + if (messageReport) { + messageReport.innerHTML = ''; + const icon = document.createElement('i'); + icon.className = 'fas fa-server px-2'; + messageReport.appendChild(icon); + messageReport.innerHTML += `${res.status} Unable to get API status.`; + } + throw new Error('unable to get API status'); + }) + .then((results) => { + reportTbody().innerHTML = ''; + results.forEach((result) => serviceRowFormat(result)); + return setTimeout(getAllServicesStatus, 5000); + }) + .catch((err) => console.error(err)); +} diff --git a/src/api/status/src/server.js b/src/api/status/src/server.js index 9b8fff673f..0130cf018e 100644 --- a/src/api/status/src/server.js +++ b/src/api/status/src/server.js @@ -1,6 +1,7 @@ const { Satellite } = require('@senecacdot/satellite'); const { static: serveStatic } = require('express'); const path = require('path'); +const { check } = require('./services'); const host = process.env.API_HOST || 'localhost'; @@ -43,5 +44,15 @@ if (process.env.PATH_PREFIX) { service.router.use('/', serveStatic(path.join(__dirname, '../public'))); } +service.router.get('/v1/status/status', (req, res) => { + check() + .then((status) => { + // This status response shouldn't be cached (we need current status info) + res.set('Cache-Control', 'no-store, max-age=0'); + return res.json(status); + }) + .catch((err) => res.status(500).json({ error: err.message })); +}); + const port = parseInt(process.env.STATUS_PORT || 1111, 10); service.start(port);