Skip to content

Commit

Permalink
refactor: enhance logging and improve incident feed notification mess…
Browse files Browse the repository at this point in the history
…ages across multiple services
  • Loading branch information
simlarsen committed Jan 15, 2025
1 parent c09d973 commit a84e32f
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 5 deletions.
15 changes: 14 additions & 1 deletion Common/Server/Services/IncidentFeedService.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import IncidentFeed from "Common/Models/DatabaseModels/IncidentFeed";
import { Blue500 } from "../../Types/BrandColors";
import Color from "../../Types/Color";
import OneUptimeDate from "../../Types/Date";
import BadDataException from "../../Types/Exception/BadDataException";
import ObjectID from "../../Types/ObjectID";
import { IsBillingEnabled } from "../EnvironmentConfig";
import logger from "../Utils/Logger";
import DatabaseService from "./DatabaseService";
import Model, {
IncidentFeedEventType,
Expand All @@ -28,6 +30,10 @@ export class Service extends DatabaseService<Model> {
userId?: ObjectID | undefined;
postedAt?: Date | undefined;
}): Promise<Model> {

logger.debug("IncidentFeedService.createIncidentFeed");
logger.debug(data);

const incidentFeed: Model = new Model();

if (!data.incidentId) {
Expand Down Expand Up @@ -68,12 +74,19 @@ export class Service extends DatabaseService<Model> {
incidentFeed.moreInformationInMarkdown = data.moreInformationInMarkdown;
}

return await this.create({
const createdIncidentFeed: IncidentFeed = await this.create({
data: incidentFeed,
props: {
isRoot: true,
},
});

logger.debug("Incident Feed created");
logger.debug(createdIncidentFeed);

return createdIncidentFeed;


}
}

Expand Down
2 changes: 1 addition & 1 deletion Common/UI/Components/InfoCard/InfoCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const InfoCard: FunctionComponent<ComponentProps> = (
): ReactElement => {
return (
<div
className={`rounded-md bg-white shadow-md p-5 ${props.className || ""}`}
className={`rounded-md bg-white shadow p-5 ${props.className || ""}`}
>
<div>
<FieldLabelElement title={props.title} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const SummarysScreenshot: FunctionComponent<ComponentProps> = (
<div className="w-fit">
<div className="">
<img
className="rounded-md w-fit h-fit shadow-md m-1"
className="rounded-md w-fit h-fit shadow m-1"
src={`data:image/png;base64,${props.screenshot}`}
alt={props.screenshotName}
/>
Expand Down
11 changes: 10 additions & 1 deletion Worker/Jobs/Incident/SendNotificationToSubscribers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ RunCron(
_id: true,
title: true,
description: true,
projectId: true,
monitors: {
_id: true,
},
Expand All @@ -65,7 +66,8 @@ RunCron(
const httpProtocol: Protocol = await DatabaseConfig.getHttpProtocol();

for (const incident of incidents) {
const incidentFeedText: string = `Notification sent to Status Page Subscribers on Incident Creation`;
const incidentFeedText: string = `**Subscriber Incident Created Notification Sent**:
Notification sent to status page subscribers because this incident was created.`;

if (!incident.monitors || incident.monitors.length === 0) {
continue;
Expand Down Expand Up @@ -269,13 +271,20 @@ RunCron(
}
}

debugger;

logger.debug("Creating incident feed for subscriber notification");

await IncidentFeedService.createIncidentFeed({
incidentId: incident.id!,
projectId: incident.projectId!,
incidentFeedEventType: IncidentFeedEventType.SubscriberNotificationSent,
displayColor: Blue500,
feedInfoInMarkdown: incidentFeedText,
});

logger.debug("Incident Feed created");
}

},
);
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ RunCron(
});

for (const incident of incidents) {
const incidentFeedText: string = `**Incident Created Notification Sent**:
const incidentFeedText: string = `**Owner Incident Created Notification Sent**:
Notification sent to owners of this incident because this incident was created.`;
let moreIncidentFeedInformationInMarkdown: string = "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ RunCron(
_id: true,
note: true,
incidentId: true,
projectId: true,
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ RunCron(
skip: 0,
select: {
_id: true,
projectId: true,
incidentId: true,
incidentStateId: true,
incidentState: {
Expand Down

0 comments on commit a84e32f

Please sign in to comment.