From dffa3c4cf6385e88cd7279ac1999d60430364b34 Mon Sep 17 00:00:00 2001 From: Matthew Rowland Date: Fri, 1 Nov 2024 16:01:35 -0700 Subject: [PATCH] feat: Remove statuspage --- apps/statuspage/config.dotenv.js | 4 - apps/statuspage/config.js | 6 - .../config.statuspage.template.json | 15 -- apps/statuspage/index.js | 147 ------------------ apps/statuspage/init.sh | 6 - apps/statuspage/package.json | 26 ---- apps/statuspage/prettier.config.cjs | 12 -- apps/statuspage/setup-tests.js | 28 ---- apps/statuspage/tests/catalog.test.js | 17 -- apps/statuspage/tests/simple.test.js | 8 - 10 files changed, 269 deletions(-) delete mode 100644 apps/statuspage/config.dotenv.js delete mode 100644 apps/statuspage/config.js delete mode 100644 apps/statuspage/config.statuspage.template.json delete mode 100644 apps/statuspage/index.js delete mode 100644 apps/statuspage/init.sh delete mode 100644 apps/statuspage/package.json delete mode 100644 apps/statuspage/prettier.config.cjs delete mode 100644 apps/statuspage/setup-tests.js delete mode 100644 apps/statuspage/tests/catalog.test.js delete mode 100644 apps/statuspage/tests/simple.test.js diff --git a/apps/statuspage/config.dotenv.js b/apps/statuspage/config.dotenv.js deleted file mode 100644 index 9a5821714..000000000 --- a/apps/statuspage/config.dotenv.js +++ /dev/null @@ -1,4 +0,0 @@ -import dotenv from "dotenv"; -dotenv.config({ - path: `.env`, -}); diff --git a/apps/statuspage/config.js b/apps/statuspage/config.js deleted file mode 100644 index 690e2a346..000000000 --- a/apps/statuspage/config.js +++ /dev/null @@ -1,6 +0,0 @@ -export const PORT_EXPRESS_HTTP = 80; -export const PORT_EXPRESS_HTTPS = 443; -export const STATUS_DEGRADED_PERFORMANCE = "degraded_performance"; -export const STATUS_OPERATIONAL = "operational"; -export const STATUS_MAJOR_OUTAGE = "major_outage"; -export const URL_BERKELEYTIME = "https://berkeleytime.com"; diff --git a/apps/statuspage/config.statuspage.template.json b/apps/statuspage/config.statuspage.template.json deleted file mode 100644 index 7da376fd3..000000000 --- a/apps/statuspage/config.statuspage.template.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "apiKey": "32465954-9baf-4532-....", - "pageId": "0xf....", - "apiStatus": { - "metricId": "6kt04d...", - "componentId": "8gz..." - }, - "frontendStatus": { - "metricId": "sdysw0....", - "componentId": "4yzhg..." - }, - "gitlabStatus": { - "componentId": "z4m6slg..." - } -} diff --git a/apps/statuspage/index.js b/apps/statuspage/index.js deleted file mode 100644 index dc567359b..000000000 --- a/apps/statuspage/index.js +++ /dev/null @@ -1,147 +0,0 @@ -import axios from "axios"; -import express from "express"; -import { readFile } from "fs/promises"; -import { setInterval } from "timers/promises"; -import http from "http"; -import https from "https"; -import moment from "moment-timezone"; - -/** - * this service lives outside of Kubernetes - * - * because this exists independent of Kubernetes, the cert loading process is - * manual - * - * to manually pull certificates from k8s: - * kubectl get secrets/bt-tls --template='{{index .data "tls.crt"}}' | base64 --decode > bt-tls.cert - * kubectl get secrets/bt-tls --template='{{index.data "tls.key"}}' | base64 --decode > bt-tls.key - * - * to create a DNS A record for status.berkeleytime.com - * export ADDRESS= - * gcloud dns record-sets delete --zone berkeleytime --type A status.berkeleytime.com - * gcloud dns record-sets delete --zone berkeleytime --type A *.status.berkeleytime.com - * gcloud dns record-sets create status.berkeleytime.com --type A --ttl 300 --zone berkeleytime --rrdatas 34.82.91.206 - * gcloud dns record-sets create *.status.berkeleytime.com --type A --ttl 300 --zone berkeleytime --rrdatas 34.82.91.206 - * - * TODO: - * pull certificate + key every x amount of days and then restart server - */ - -/* redirect status.berkeleytime.com to statuspage.io ************************ */ -const cert = await readFile("bt-tls.cert"); -const key = await readFile("bt-tls.key"); -const app = express(); -app.use((req, res) => { - console.log(`${req.ip} redirect to https://berkeleytime.statuspage.io`); - res.redirect("https://berkeleytime.statuspage.io"); -}); -http.createServer(app).listen(PORT_EXPRESS_HTTP); -https - .createServer( - { - key, - cert, - }, - app - ) - .listen(PORT_EXPRESS_HTTPS); -console.log( - `Server now listening on port ${PORT_EXPRESS_HTTP} and ${PORT_EXPRESS_HTTPS}` -); -/* ************************ redirect status.berkeleytime.com to statuspage.io */ - -/* update berkeleytime.statuspage.io **************************************** */ -import { - PORT_EXPRESS_HTTP, - PORT_EXPRESS_HTTPS, - STATUS_DEGRADED_PERFORMANCE, - STATUS_OPERATIONAL, - STATUS_MAJOR_OUTAGE, -} from "./config.js"; -import spConfig from "./config.statuspage.json"; - -axios.defaults.headers["Authorization"] = `OAuth ${spConfig.apiKey}`; - -const updateStatuspage = async (ping, auth) => { - const { pageId } = spConfig; - const { componentId, metricId } = auth; - const statusUrl = `https://api.statuspage.io/v1/pages/${pageId}`; - - try { - const start = Date.now(); - await ping(); - const responseTime = Date.now() - start; - - if (metricId) { - await axios.post(`${statusUrl}/metrics/${metricId}/data`, { - data: { - timestamp: Math.floor(start / 1000), - value: responseTime, - }, - }); - } - - let status; - if (metricId && responseTime > 2000) { - status = STATUS_DEGRADED_PERFORMANCE; - } else { - status = STATUS_OPERATIONAL; - } - - await axios.patch(`${statusUrl}/components/${componentId}`, { - component: { - status, - }, - }); - } catch (err) { - console.error(err); - await axios.patch(`${statusUrl}/components/${componentId}`, { - component: { - status: STATUS_MAJOR_OUTAGE, - }, - }); - } -}; - -for await (const _ of setInterval(spConfig.statusInterval * 1000)) { - const { apiStatus, frontendStatus, gitlabStatus, elasticsearchStatus, url } = - spConfig; - const niceTime = () => - moment().tz("America/Los_Angeles").format(`YYYY-MM-DD HH:mm:ss dddd`); - await updateStatuspage(async () => { - await axios.post(`${url}/api/graphql`, { - query: "query PingQuery{ ping }", - }); - console.log(`${niceTime()} successful ping for /api/graphql`); - }, apiStatus); - - await updateStatuspage(async () => { - await axios.get(`${url}/landing`); - console.log(`${niceTime()} successful ping for /landing`); - }, frontendStatus); - - await updateStatuspage(async () => { - if ( - !(await axios.get(`${url}/git`)).request.res.responseUrl.includes( - "sign_in" - ) - ) { - throw Error("expected sign-in page"); - } - console.log(`${niceTime()} successful ping for /git`); - }, gitlabStatus); - - await updateStatuspage(async () => { - try { - await axios.get(`${url}/kibana`); - throw Error("expected 401 Unauthorized"); - } catch (err) { - if (err.response && err.response.status == 401) { - console.log(`${niceTime()} successful ping for /kibana`); - } else { - throw err; - } - } - }, elasticsearchStatus); -} -/* **************************************** update berkeleytime.statuspage.io */ diff --git a/apps/statuspage/init.sh b/apps/statuspage/init.sh deleted file mode 100644 index e7a9c20e5..000000000 --- a/apps/statuspage/init.sh +++ /dev/null @@ -1,6 +0,0 @@ -# this init relates to 'statuspage' VM in GCP, for status.berkeleytime.com -# gcloud compute ssh root@statuspage -curl -s https://deb.nodesource.com/setup_16.x | bash -| bash - -apt install -y nodejs -git clone https://github.com/asuc-octo/berkeleytime.git -npm run start --prefix berkeleytime/statuspage diff --git a/apps/statuspage/package.json b/apps/statuspage/package.json deleted file mode 100644 index 3e9051c33..000000000 --- a/apps/statuspage/package.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "name": "statuspage", - "version": "1.0.0", - "description": "berkeleytime.statuspage.io", - "main": "index.js", - "imports": { - "#root/*": "./*.js" - }, - "scripts": { - "start": "nodemon --experimental-json-modules index.js", - "test": "mocha tests/**/*.test.js --experimental-json-modules --file setup-tests.js" - }, - "type": "module", - "dependencies": { - "axios": "^0.21.1", - "chai": "^4.3.0", - "dotenv": "^8.2.0", - "express": "^4.17.1", - "mocha": "^8.3.0", - "moment-timezone": "^0.5.33" - }, - "devDependencies": { - "nodemon": "^2.0.15", - "prettier-plugin-jsdoc": "^0.3.18" - } -} diff --git a/apps/statuspage/prettier.config.cjs b/apps/statuspage/prettier.config.cjs deleted file mode 100644 index 8566748d3..000000000 --- a/apps/statuspage/prettier.config.cjs +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = { - useTabs: false, - printWidth: 80, - tabWidth: 2, - singleQuote: false, - jsdocParser: true, - jsxBracketSameLine: false, - importOrder: ["^@core/(.*)$", "^@server/(.*)$", "^@ui/(.*)$", "^[./]"], - importOrderSeparation: true, - noSemi: true, - rcVerbose: true, -}; diff --git a/apps/statuspage/setup-tests.js b/apps/statuspage/setup-tests.js deleted file mode 100644 index 1f78fd634..000000000 --- a/apps/statuspage/setup-tests.js +++ /dev/null @@ -1,28 +0,0 @@ -import express from "express"; -import dotenv from "dotenv"; // future use: currently not using values from .env -import spConfig from "./config.statuspage.json"; - -export default { - mochaHooks: { - beforeAll() { - dotenv.config(); - }, - }, - - graphql: { - catalog: ` - query CourseJsonTest { - allCourses { - edges { - node { - id - courseNumber - abbreviation - title - } - } - } - } - `, - }, -}; diff --git a/apps/statuspage/tests/catalog.test.js b/apps/statuspage/tests/catalog.test.js deleted file mode 100644 index 9f83f520f..000000000 --- a/apps/statuspage/tests/catalog.test.js +++ /dev/null @@ -1,17 +0,0 @@ -import { expect } from "chai"; -import { URL_BERKELEYTIME } from "#root/config"; -import axios from "axios"; - -describe("Catalog test", () => { - it("should compare the /catalog_json endpoint", async () => { - const restResponse = await axios.get( - `${URL_BERKELEYTIME}/api/catalog/catalog_json` - ); - - const gqlResponse = await axios.post(`${URL_BERKELEYTIME}/api/graphql`, { - query: "query PingQuery{ ping }", - }); - expect(gqlResponse.status).to.equal(200); - const gqlData = await gqlResponse.data; - }).timeout(50000); -}); diff --git a/apps/statuspage/tests/simple.test.js b/apps/statuspage/tests/simple.test.js deleted file mode 100644 index aff0896d5..000000000 --- a/apps/statuspage/tests/simple.test.js +++ /dev/null @@ -1,8 +0,0 @@ -import { expect } from "chai"; - -describe("Simple test", () => { - it("should banana", () => { - const banana = ("b" + "a" + +"a" + "a").toLowerCase(); - expect(banana).to.equal("banana"); - }); -});