Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sneha release 4.0.1 #41

Closed
wants to merge 5 commits into from
Closed
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
19 changes: 16 additions & 3 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
try {
try {
const env = require("dotenv").config();
const createError = require("http-errors");
const express = require("express");
Expand Down Expand Up @@ -51,13 +51,16 @@ try {
app.use(
"/v1/graphql",
proxy(`${process.env.GRAPHQL_BASE_URL}/v1/graphql`, {
proxyReqOptDecorator: function (proxyReqOpts, srcReq) {

proxyReqOptDecorator: function (proxyReqOpts, srcReq) {
proxyReqOpts.headers = {
"x-hasura-admin-secret": `${process.env.HASURA_GRAPHQL_ADMIN_SECRET}`,
};
};
return proxyReqOpts;
},

proxyReqPathResolver: (req) => {
console.log("log:",url.parse(req.baseUrl).path)
return url.parse(req.baseUrl).path;
},
})
Expand All @@ -71,6 +74,16 @@ try {
require("./routes/conversationLogic")(app);
require("./routes/bot")(app);
require("./routes/odk")(app);
require("./healthCheck/DB")(app);
require("./healthCheck/kafka")(app);
require("./healthCheck/gql")(app);
require("./healthCheck/fusionAuth")(app);
require("./healthCheck/redis")(app);
require("./healthCheck/campagin")(app);
require("./healthCheck/test")(app);
require("./healthCheck/inbound")(app);
require("./healthCheck/transformer")(app);
require("./healthCheck/health")(app);
module.exports = app;
return app;
};
Expand Down
86 changes: 86 additions & 0 deletions src/healthCheck/DB.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
const requestMiddleware = require("../middlewares/request.middleware");
const Knex = require("knex");
const response = require("../routes/response");
const messageUtils = require("../service/messageUtil");
const HealthMessages = messageUtils.HEALTH_CHECK;
const errorCode = messageUtils.ERRORCODES;
const BASE_URL = "/admin/v1";

async function checkDB(req, res) {
const errCode = HealthMessages.EXCEPTION_CODE;
const knexConfig = {
development: {
debug: false,
client: "pg",
useNullAsDefault: true,
connection: process.env.PSQL_DB_URL_DEV,
pool: {
min: 20,
max: 50,

},
},
production: {
debug: false,
client: "pg",
useNullAsDefault: true,
connection: process.env.PSQL_DB_URL,
pool: {
min: 2,
max: 5,
},
},
};
let checks = []

// Initialize knex.
const config =
process.env.ENV === "dev" ? knexConfig.development : knexConfig.production;
const knex = Knex(config);
if(knex){
checks.push({"name":"connection",
"healthy":" true"})
} else {
checks.push({"name":"connection",
"healthy":" false"})
}

knex
.select()
.from("transformer")
.then((data) => {
console.log("trans", data);
checks.push({"name":"migration",
"healthy":" true"})
checks.push({"name":"test-query",
"healthy":" true"})
response.sendHealthSuccessRes(
req,
true,
checks,
res,
HealthMessages.POSTGRES_DB.SUCCESS_CODE
);
})
.catch((err) => {
response.sendHealthErrorRes(
req,
res,
HealthMessages.POSTGRES_DB.FAILED_CODE,
errorCode,
HealthMessages.POSTGRES_DB.FAILED_MESSAGE,
false,
errCode
);
});
}

module.exports = function (app) {
app
.route(BASE_URL + "/health/DB")
.get(
requestMiddleware.gzipCompression(),
requestMiddleware.createAndValidateRequestBody,
checkDB
);
};
56 changes: 56 additions & 0 deletions src/healthCheck/campagin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const response = require("../routes/response");
const requestMiddleware = require("../middlewares/request.middleware");
const messageUtils = require("../service/messageUtil");
const HealthMessages = messageUtils.HEALTH_CHECK;
const errorCode = messageUtils.ERRORCODES;
const BASE_URL = "/admin/v1";
const errCode = HealthMessages.EXCEPTION_CODE;
const fetch = require("node-fetch");

async function checkCampagin(req, res) {
let checks = [];
fetch(`${process.env.CAMPAIGN_URL}`)
.then(async (s) => {
if(s.statusText === 'OK'){
checks.push({"name":"connection",
"healthy":" true"})
response.sendHealthSuccessRes(
req,
true,
checks,
res,
HealthMessages.CAMPAIGN.SUCCESS_CODE
);
} else{
response.sendHealthErrorRes(
req,
res,
HealthMessages.CAMPAIGN.FAILED_CODE,
errorCode,
HealthMessages.CAMPAIGN.FAILED_MESSAGE,
false,
errCode
);
}
})
.catch((e) => {
response.sendHealthErrorRes(
req,
res,
HealthMessages.CAMPAIGN.FAILED_CODE,
errorCode,
HealthMessages.CAMPAIGN.FAILED_MESSAGE,
false,
errCode
);
});
}
module.exports = function (app) {
app
.route(BASE_URL + "/health/campaign")
.get(
requestMiddleware.gzipCompression(),
requestMiddleware.createAndValidateRequestBody,
checkCampagin
);
};
58 changes: 58 additions & 0 deletions src/healthCheck/fusionAuth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const response = require("../routes/response");
const requestMiddleware = require("../middlewares/request.middleware");
const messageUtils = require("../service/messageUtil");
const HealthMessages = messageUtils.HEALTH_CHECK;
const errorCode = messageUtils.ERRORCODES;
const { DeviceManager } = require("../helpers/userSegment/deviceManager");
const BASE_URL = "/admin/v1";
const errCode = HealthMessages.EXCEPTION_CODE;
const fetch = require("node-fetch");

async function checkFusion(req, res) {
let checks = [];
fetch(`${process.env.FA_URL}/api/status`)
.then(async (s) => {
console.log("Result:", s.status)
if(s.statusText === 'OK'){
checks.push({"name":"connection",
"healthy":" true"})
response.sendHealthSuccessRes(
req,
true,
checks,
res,
HealthMessages.FUSION.SUCCESS_CODE
);
} else{
response.sendHealthErrorRes(
req,
res,
HealthMessages.FUSION.FAILED_CODE,
errorCode,
HealthMessages.FUSION.FAILED_MESSAGE,
false,
errCode
);
}
})
.catch((e) => {
response.sendHealthErrorRes(
req,
res,
HealthMessages.FUSION.FAILED_CODE,
errorCode,
HealthMessages.FUSION.FAILED_MESSAGE,
false,
errCode
);
});
}
module.exports = function (app) {
app
.route(BASE_URL + "/health/fusionAuth")
.get(
requestMiddleware.gzipCompression(),
requestMiddleware.createAndValidateRequestBody,
checkFusion
);
};
75 changes: 75 additions & 0 deletions src/healthCheck/gql.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
const response = require("../routes/response");
const requestMiddleware = require("../middlewares/request.middleware");
const gql = require("graphql-tag");

const fetch = require("node-fetch");
const messageUtils = require("../service/messageUtil");
const HealthMessages = messageUtils.HEALTH_CHECK;
const errorCode = messageUtils.ERRORCODES;
const BASE_URL = "/admin/v1";
const errCode = HealthMessages.EXCEPTION_CODE;
const GQLClient = require("./overAllHealths")

async function checkGQL(req, res){
let checks = []
const client = GQLClient.getGQLClient()
if (client) {
checks.push({"name":"connection",
"healthy":" true"})
}
checks.push({"name":"connection",
"healthy":" true"})
let userQuery = `query getListOfStates{
organisation(distinct_on:state){
state
}
}`
return client
.query({
query: gql`
${userQuery}
`,
})
.then(async (resp) => {
console.log("Success", resp)
checks.push({"name":"Test-query",
"healthy":" true"})
response.sendHealthSuccessRes(req, true,checks, res,HealthMessages.GQL.SUCCESS_CODE);

})
.catch((e) => {
console.log("ERROR",e);
response.sendHealthErrorRes(
req,
res,
HealthMessages.GQL.FAILED_CODE,
errorCode,
HealthMessages.GQL.FAILED_MESSAGE,
false,
errCode
);
});
}
// function getGQLClient(credentials) {
// return new ApolloClient({
// link: new HttpLink({
// uri:`${process.env.GRAPHQL_BASE_URL}/v1/graphql`,
// fetch:fetch ,
// headers: {
// "x-hasura-admin-secret": `${process.env.HASURA_GRAPHQL_ADMIN_SECRET}`,
// }
// }),
// cache: new InMemoryCache(),
// });
// }


module.exports = function (app) {
app
.route(BASE_URL + "/health/gql")
.get(
requestMiddleware.gzipCompression(),
requestMiddleware.createAndValidateRequestBody,
checkGQL
);
};
55 changes: 55 additions & 0 deletions src/healthCheck/health.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const health = require("./overAllHealths")
const requestMiddleware = require("../middlewares/request.middleware");
const BASE_URL = "/admin/v1";
const response = require("../routes/response");


async function checkOverAllHealth(req, res){
let checks =[]
let healthstatus = true
let fusionAuth = await health.checkFusion()
await checks.push(fusionAuth)
let inbound = await health.checkInbound()
await checks.push(inbound)
let transformer = await health.checkTransformer()
await checks.push(transformer)
let postgres = await health.checkDB()
await checks.push(postgres)
let kafka = await health.checkKafka()
await checks.push(kafka)
let gql = await health.checkGQL()
await checks.push(gql)
let redis = await health.checkRedis()
await checks.push(redis)

if(fusionAuth.healthy
&&inbound.healthy
&&transformer.healthy
&&postgres.healthy
&&kafka.healthy
&&gql.healthy
&&redis.healthy){
healthstatus = true
}else{
healthstatus = false
}

response.sendHealthSuccessRes(
req,
healthstatus,
checks,
res,
"SUCCESS"
);

}

module.exports = function (app) {
app
.route(BASE_URL + "/health")
.get(
requestMiddleware.gzipCompression(),
requestMiddleware.createAndValidateRequestBody,
checkOverAllHealth
);
};
Loading