2020-02-16 14:01:47 +00:00
|
|
|
/* eslint-disable
|
|
|
|
camelcase,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
2020-02-16 14:01:46 +00:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2020-08-28 12:13:19 +00:00
|
|
|
const { db, ObjectId } = require('./mongodb')
|
2020-02-16 14:02:21 +00:00
|
|
|
const request = require('request')
|
|
|
|
const async = require('async')
|
|
|
|
const _ = require('underscore')
|
|
|
|
const crypto = require('crypto')
|
2021-07-12 16:47:20 +00:00
|
|
|
const settings = require('@overleaf/settings')
|
2020-02-16 14:02:21 +00:00
|
|
|
const { port } = settings.internal.docstore
|
|
|
|
const logger = require('logger-sharelatex')
|
2015-10-16 09:13:54 +00:00
|
|
|
|
2020-02-16 14:02:21 +00:00
|
|
|
module.exports = {
|
|
|
|
check(callback) {
|
|
|
|
const doc_id = ObjectId()
|
|
|
|
const project_id = ObjectId(settings.docstore.healthCheck.project_id)
|
|
|
|
const url = `http://localhost:${port}/project/${project_id}/doc/${doc_id}`
|
|
|
|
const lines = [
|
|
|
|
'smoke test - delete me',
|
2021-07-13 11:04:48 +00:00
|
|
|
`${crypto.randomBytes(32).toString('hex')}`,
|
2020-02-16 14:02:21 +00:00
|
|
|
]
|
|
|
|
const getOpts = () => ({
|
|
|
|
url,
|
2021-07-13 11:04:48 +00:00
|
|
|
timeout: 3000,
|
2020-02-16 14:02:21 +00:00
|
|
|
})
|
|
|
|
logger.log({ lines, url, doc_id, project_id }, 'running health check')
|
|
|
|
const jobs = [
|
2020-05-28 13:20:54 +00:00
|
|
|
function (cb) {
|
2020-02-16 14:02:21 +00:00
|
|
|
const opts = getOpts()
|
|
|
|
opts.json = { lines, version: 42, ranges: {} }
|
|
|
|
return request.post(opts, cb)
|
|
|
|
},
|
2020-05-28 13:20:54 +00:00
|
|
|
function (cb) {
|
2020-02-16 14:02:21 +00:00
|
|
|
const opts = getOpts()
|
|
|
|
opts.json = true
|
2020-05-28 13:20:54 +00:00
|
|
|
return request.get(opts, function (err, res, body) {
|
2020-02-16 14:02:21 +00:00
|
|
|
if (err != null) {
|
|
|
|
logger.err({ err }, 'docstore returned a error in health check get')
|
|
|
|
return cb(err)
|
|
|
|
} else if (res == null) {
|
|
|
|
return cb('no response from docstore with get check')
|
|
|
|
} else if ((res != null ? res.statusCode : undefined) !== 200) {
|
|
|
|
return cb(`status code not 200, its ${res.statusCode}`)
|
|
|
|
} else if (
|
|
|
|
_.isEqual(body != null ? body.lines : undefined, lines) &&
|
|
|
|
(body != null ? body._id : undefined) === doc_id.toString()
|
|
|
|
) {
|
|
|
|
return cb()
|
|
|
|
} else {
|
|
|
|
return cb(`health check lines not equal ${body.lines} != ${lines}`)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
2021-07-13 11:04:48 +00:00
|
|
|
cb => db.docs.deleteOne({ _id: doc_id, project_id }, cb),
|
|
|
|
cb => db.docOps.deleteOne({ doc_id }, cb),
|
2020-02-16 14:02:21 +00:00
|
|
|
]
|
|
|
|
return async.series(jobs, callback)
|
2021-07-13 11:04:48 +00:00
|
|
|
},
|
2020-02-16 14:02:21 +00:00
|
|
|
}
|