Skip to content
This repository has been archived by the owner on May 8, 2021. It is now read-only.

Commit

Permalink
Introduce Lightship health checks (#57)
Browse files Browse the repository at this point in the history
* Set lightship signal status on mongoose connection

* Add unified topology option to mongoose connection

* Remove incompatible mongoose options

* Register lightship shutdown handler

* Update deployment manifest with readiness and liveness probes
  • Loading branch information
lukebettridge authored Mar 21, 2020
1 parent 7a03893 commit ef1c15b
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 30 deletions.
30 changes: 15 additions & 15 deletions config/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,29 +101,29 @@ spec:
name: mern-auth-boilerplate-config
image: <IMAGE>
imagePullPolicy: IfNotPresent
readinessProbe:
httpGet:
path: /ready
port: 9000
failureThreshold: 1
initialDelaySeconds: 5
periodSeconds: 5
successThreshold: 1
timeoutSeconds: 5
livenessProbe:
failureThreshold: 3
httpGet:
path: /
port: http
scheme: HTTP
periodSeconds: 10
path: /live
port: 9000
failureThreshold: 3
initialDelaySeconds: 5
periodSeconds: 30
successThreshold: 1
timeoutSeconds: 1
timeoutSeconds: 5
name: nodeapp
ports:
- containerPort: 5000
name: http
protocol: TCP
readinessProbe:
failureThreshold: 3
httpGet:
path: /
port: http
scheme: HTTP
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 1
resources: {}
securityContext: {}
terminationMessagePath: /dev/termination-log
Expand Down
83 changes: 76 additions & 7 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"is-empty": "^1.2.0",
"js-cookie": "^2.2.1",
"jsonwebtoken": "^8.5.1",
"lightship": "^6.1.0",
"lodash": "^4.17.15",
"moment": "^2.24.0",
"mongoose": "^5.8.6",
Expand Down Expand Up @@ -103,4 +104,4 @@
"webpack-dev-middleware": "^1.9.0",
"webpack-dev-server": "^3.10.1"
}
}
}
5 changes: 2 additions & 3 deletions server/config/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ module.exports = {
"admin"}${MONGO_REPLICASET ? `&replicaSet=${MONGO_REPLICASET}` : ""}`,
options: {
connectTimeoutMS: 10000,
reconnectTries: 10,
reconnectInterval: 500,
useNewUrlParser: true
useNewUrlParser: true,
useUnifiedTopology: true
}
};
23 changes: 19 additions & 4 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const bodyParser = require("body-parser");
const cookieParser = require("cookie-parser");
const express = require("express");
const mongoose = require("mongoose");
const { createLightship } = require("lightship");
const { ApolloServer } = require("apollo-server-express");
const router = express.Router();

Expand All @@ -19,12 +20,26 @@ const typeDefs = require("./src/types");

const PORT = process.env.PORT || 5000;

const app = express();

const lightship = createLightship();
lightship.registerShutdownHandler(() => {
server.close();
});

mongoose
.connect(db.url, db.options)
.then(() => console.log("MongoDB successfully connected"))
.catch(err => console.log(err));

const app = express();
.then(() => {
console.log("MongoDB successfully connected");
mongoose.connection.on("disconnected", () => {
lightship.signalNotReady();
});
lightship.signalReady();
})
.catch(err => {
console.log(err);
lightship.signalNotReady();
});

process.env.NODE_ENV !== "production"
? require("./init.dev")(app)
Expand Down

0 comments on commit ef1c15b

Please sign in to comment.