Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions microservices/status-run/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Dockerfile
.dockerignore
node_modules/
README.md
2 changes: 2 additions & 0 deletions microservices/status-run/.gcloudignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
README.md
1 change: 1 addition & 0 deletions microservices/status-run/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
26 changes: 26 additions & 0 deletions microservices/status-run/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# syntax=docker/dockerfile:1
FROM node:18-slim

# Below we use Dockerfile Labels w/ predefined annotation keys to properly link
# to arbitrary container images to the proper Pulsar Repo.
LABEL org.opencontainers.artifact.description="Microservice to update the current system status of various Pulsar webservices."
LABEL org.opencontainers.image.source="https://github.com/pulsar-edit/package-frontend/tree/main/microservices/status-run"
LABEL org.opencontainers.image.author="confused-Techie"
LABEL org.opencontainers.image.license="MIT"
LABEL org.opencontainers.image.description="Microservice to update the current system status of various Pulsar webservices."
LABEL org.opencontainers.image.documentation="https://github.com/pulsar-edit/package-frontend/blob/main/microservices/status-run/README.md"

# Create and change to the app directory
WORKDIR /usr/src/app

# Copy application dependency manifests to the other image.
COPY package*.json ./

# Install production dependencies
RUN npm install --only=production

# Copy local code to the container image.
COPY . ./

# Run the web service on container startup
CMD [ "npm", "start" ]
3 changes: 3 additions & 0 deletions microservices/status-run/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Status Run

This microservice runs periodically to update the current status of all Pulsar services.
277 changes: 277 additions & 0 deletions microservices/status-run/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,277 @@
const http = require("node:http");
const https = require("node:https");
const fs = require("node:fs");

const PORT = parseInt(process.env.PORT) || 8080;

const server = http.createServer(async (req, res) => {
const path = req.url.split("?"); // strip any query params

if (path[0] === "/" && req.method === "POST") {
console.log(`Status-Run triggered by '${req.headers["user-agent"]}'`);

const job = await run();

// With our status check done, lets write it to GCP storage
// Which is actually mounted on the volume as plain-ole local storage
try {
fs.writeFileSync("./status.json", JSON.stringify(job), { encoding: "utf8" });
res.writeHead(201, { "Content-Type": "application/json" });
res.write(JSON.stringify({ message: "Successfully updated status file." }));
res.end();
} catch(err) {
console.error(err);
res.writeHead(500, { "Content-Type": "application/json" });
res.write(JSON.stringify({ message: "Failed to write new status file details", err: err.toString() }));
res.end();
}
} else {
res.writeHead(404, { "Content-Type": "application/json" });
res.write(JSON.stringify({ message: "Location Not Found" }));
res.end();
}
});

server.listen(PORT, () => {
console.log(`Status-Run Microservice exposed on port: ${PORT}`);
});

async function run() {
// The bulk of functionality of actually checking the status of various services

// Initialize an empty, fail first status object
const status = {
homepage: { // https://pulsar-edit.dev
ok: false,
updated: Date.now(),
details: null,
condition: "unknown"
},
docs: { // https://docs.pulsar-edit.dev
ok: false,
updated: Date.now(),
details: null,
condition: "unknown"
},
blog: { // https://blog.pulsar-edit.dev
ok: false,
updated: Date.now(),
details: null,
condition: "unknown"
},
api: { // https://api.pulsar-edit.dev
ok: false,
updated: Date.now(),
details: null,
condition: "unknown"
},
image: { // https://image.pulsar-edit.dev
ok: false,
updated: Date.now(),
details: null,
condition: "unknown"
},
download: { // https://download.pulsar-edit.dev
ok: false,
updated: Date.now(),
details: null,
condition: "unknown"
}
};

// === Homepage Check
try {
const homepage = await request({
hostname: "pulsar-edit.dev",
path: "/",
method: "GET",
headers: {
"Accept": "text/html",
"User-Agent": "pulsar-edit/package-frontend/microservices/status-run"
}
});

if (homepage.status === 200 && homepage.headers.server === "GitHub.com") {
status.homepage.ok = true;
status.homepage.condition = "Healthy";
status.homepage.details = "Service is Operational";
} else {
status.homepage.ok = false;
status.homepage.condition = "Unhealthy";
status.homepage.details = homepage.statusMsg;
}
} catch(err) {
status.homepage.ok = false;
status.homepage.condition = "Unhealthy";
status.homepage.details = err.toString();
}

// === Docs Check
try {
const docs = await request({
hostname: "docs.pulsar-edit.dev",
path: "/",
method: "GET",
headers: {
"Accept": "text/html",
"User-Agent": "pulsar-edit/package-frontend/microservices/status-run"
}
});
if (docs.status === 200 && docs.headers.server === "GitHub.com") {
status.docs.ok = true;
status.docs.condition = "Healthy";
status.docs.details = "Service is Operational";
} else {
status.docs.ok = false;
status.docs.condition = "Unhealthy";
status.docs.details = docs.statusMsg;
}
} catch(err) {
status.docs.ok = false;
status.docs.condition = "Unhealthy";
status.docs.details = err.toString();
}

// === Blog Check
try {
const blog = await request({
hostname: "blog.pulsar-edit.dev",
path: "/",
method: "GET",
headers: {
"Accept": "text/html",
"User-Agent": "pulsar-edit/package-frontend/microservices/status-run"
}
});
if (blog.status === 200 && blog.headers.server === "GitHub.com") {
status.blog.ok = true;
status.blog.condition = "Healthy";
status.blog.details = "Service is Operational";
} else {
status.blog.ok = false;
status.blog.condition = "Unhealthy";
status.blog.details = blog.statusMsg;
}
} catch(err) {
status.blog.ok = false;
status.blog.condition = "Unhealthy";
status.blog.details = err.toString();
}

// === API Check
try {
const api = await request({
hostname: "api.pulsar-edit.dev",
path: "/",
method: "GET",
headers: {
"Accept": "application/json",
"User-Agent": "pulsar-edit/package-frontend/microservices/status-run"
}
});
if (api.status === 200 && api.body.includes("Server is up and running")) {
// TODO: The API has no real status check, but this at least ensures it
// is up for the most part
status.api.ok = true;
status.api.condition = "Healthy";
status.api.details = "Service is Operational";
} else {
status.api.ok = false;
status.api.condition = "Unhealthy";
status.api.condition = api.statusMsg;
}
} catch(err) {
status.api.ok = false;
status.api.condition = "Unhealthy";
status.api.details = err.toString();
}

// === Image Check
try {
const image = await request({
hostname: "image.pulsar-edit.dev",
path: "/",
method: "GET",
headers: {
"Accept": "application/json",
"User-Agent": "pulsar-edit/package-frontend/microservices/status-run"
}
});
const imageBody = JSON.parse(image.body);
if (image.status === 404 && imageBody.message === "Not Found") {
// TODO: The image microservice contains no health check, so we check that
// it's running and properly returning a 404 on the homepage
status.image.ok = true;
status.image.condition = "Healthy";
status.image.details = "Service is Operational";
} else {
status.image.ok = false;
status.image.condition = "Unhealthy";
status.image.details = image.statusMsg;
}
} catch(err) {
status.image.ok = false;
status.image.condition = "Unhealthy";
status.image.details = err.toString();
}

// === Download Check
try {
const download = await request({
hostname: "download.pulsar-edit.dev",
path: "/?os=linux&type=linux_appimage",
method: "GET",
headers: {
"Accept": "application/json",
"User-Agent": "pulsar-edit/package-frontend/microservice/status-run"
}
});
if (download.status === 307 && download.headers.location.startsWith("https://github.com")) {
// We expect the download microservice to successfully redirect us to GitHub
status.download.ok = true;
status.download.condition = "Healthy";
status.download.details = "Service is Operational";
} else {
status.download.ok = false;
status.download.condition = "Unhealthy";
status.download.details = download.statusMsg;
}
} catch(err) {
status.download.ok = false;
status.download.condition = "Unhealthy";
status.download.details = err.toString();
}

// === Return Results
return status;
}

function request(options) {
return new Promise((resolve, reject) => {
let data = {
body: "",
status: null,
statusMsg: null,
headers: null
};

const req = https.request(options, (res) => {
data.status = res.statusCode;
data.statusMsg = res.statusMessage;
data.headers = res.headers;
res.setEncoding("utf8");
res.on("data", (chunk) => {
data.body += chunk;
});
res.on("end", () => {
resolve(data);
});
});

req.on("error", (e) => {
reject(e);
});

req.end();
});
}
13 changes: 13 additions & 0 deletions microservices/status-run/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions microservices/status-run/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "status-run",
"version": "1.0.0",
"description": "Update the current system status of various Pulsar webservices.",
"main": "index.js",
"scripts": {
"start": "node ./index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "confused-Techie",
"license": "MIT"
}
4 changes: 4 additions & 0 deletions microservices/status-run/policy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bindings:
- members:
- serviceAccount:[email protected]
role: roles/run.invoker
23 changes: 23 additions & 0 deletions microservices/status-run/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: status-run
spec:
template:
metadata:
annotations:
run.googleapis.com/execution-environment: gen2
spec:
serviceAccountName:
containers:
- image: "us-west2-docker.pkg.dev/pulsar-357404/package-frontend/status-run:1.0.0"
volumeMounts:
- name: GCS
mountPath: /usr/src/app/
volumes:
- name: GCS
csi:
driver: gcsfuse.run.googleapis.com
readOnly: False
volumeAttributes:
bucketName: "pulsar-system-status"
3 changes: 3 additions & 0 deletions microservices/status-view/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Status View

This microservice is what's displayed to users to view the current status of various Pulsar web services.
9 changes: 9 additions & 0 deletions microservices/status-view/gcloud-cors-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[
{
"origin": ["https://status.pulsar-edit.dev"],
"method": ["GET"],
"responseHeader": ["Content-Type"],
"maxAgeSeconds": 3600
}

]
Loading