purge distributed uptime
This commit is contained in:
1 parent
5690d91d59
commit
274595a533
70 files changed
+17
-4494
No files matched your search
@@ -61,105 +61,6 @@ const updateStatusPage = async (statusPageData, image) => {
|
||||
}
|
||||
};
|
||||
|
||||
const getDistributedStatusPageByUrl = async ({ url, daysToShow = 30 }) => {
|
||||
const stringService = ServiceRegistry.get(StringService.SERVICE_NAME);
|
||||
try {
|
||||
const statusPage = await StatusPage.findOne({ url }).lean();
|
||||
|
||||
if (!statusPage) {
|
||||
const error = new Error(stringService.statusPageNotFound);
|
||||
error.status = 404;
|
||||
throw error;
|
||||
}
|
||||
|
||||
// No sub monitors, return status page
|
||||
if (statusPage.subMonitors.length === 0) {
|
||||
return statusPage;
|
||||
}
|
||||
// Sub monitors, return status page with sub monitors
|
||||
const daysAgo = new Date();
|
||||
daysAgo.setDate(daysAgo.getDate() - daysToShow);
|
||||
|
||||
const subMonitors = await Monitor.aggregate([
|
||||
{ $match: { _id: { $in: statusPage.subMonitors } } },
|
||||
{
|
||||
$addFields: {
|
||||
orderIndex: { $indexOfArray: [statusPage.subMonitors, "$_id"] },
|
||||
},
|
||||
},
|
||||
|
||||
// Return 30 days of checks by default
|
||||
{
|
||||
$lookup: {
|
||||
from: "checks",
|
||||
let: { monitorId: "$_id" },
|
||||
pipeline: [
|
||||
{
|
||||
$match: {
|
||||
$expr: {
|
||||
$and: [
|
||||
{ $eq: ["$monitorId", "$$monitorId"] },
|
||||
{ $gte: ["$updatedAt", daysAgo] },
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$group: {
|
||||
_id: {
|
||||
$dateToString: { format: "%Y-%m-%d", date: "$updatedAt" },
|
||||
},
|
||||
responseTime: {
|
||||
$avg: "$responseTime",
|
||||
},
|
||||
trueCount: {
|
||||
$sum: {
|
||||
$cond: [{ $eq: ["$status", true] }, 1, 0],
|
||||
},
|
||||
},
|
||||
totalCount: {
|
||||
$sum: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
_id: 1,
|
||||
responseTime: 1,
|
||||
upPercentage: {
|
||||
$cond: [
|
||||
{ $eq: ["$totalCount", 0] },
|
||||
0,
|
||||
{ $multiply: [{ $divide: ["$trueCount", "$totalCount"] }, 100] },
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$sort: { _id: -1 },
|
||||
},
|
||||
],
|
||||
as: "checks",
|
||||
},
|
||||
},
|
||||
{ $sort: { orderIndex: 1 } },
|
||||
{ $project: { orderIndex: 0 } },
|
||||
]);
|
||||
|
||||
const normalizedSubMonitors = subMonitors.map((monitor) => {
|
||||
return {
|
||||
...monitor,
|
||||
checks: NormalizeData(monitor.checks, 10, 100),
|
||||
};
|
||||
});
|
||||
return { ...statusPage, subMonitors: normalizedSubMonitors };
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "getDistributedStatusPageByUrl";
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
const getStatusPageByUrl = async (url, type) => {
|
||||
// TODO This is deprecated, can remove and have controller call getStatusPage
|
||||
try {
|
||||
@@ -306,7 +207,6 @@ export {
|
||||
getStatusPagesByTeamId,
|
||||
getStatusPage,
|
||||
getStatusPageByUrl,
|
||||
getDistributedStatusPageByUrl,
|
||||
deleteStatusPage,
|
||||
deleteStatusPagesByMonitorId,
|
||||
};
|
||||
Reference in new issue
Block a user