Skip to content

Commit

Permalink
Refactor migration files to improve index management and clean up Mon…
Browse files Browse the repository at this point in the history
…itorIncident and MonitorResource utility classes
  • Loading branch information
simlarsen committed Nov 12, 2024
1 parent c0994ff commit 76f9537
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class MigrationName1731433043136 implements MigrationInterface {
public name = 'MigrationName1731433043136'
public name = "MigrationName1731433043136";

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP INDEX "public"."IDX_5218e92f700d91afe6a8db79cb"`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE INDEX "IDX_5218e92f700d91afe6a8db79cb" ON "Incident" ("rootCause") `);
}
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`DROP INDEX "public"."IDX_5218e92f700d91afe6a8db79cb"`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE INDEX "IDX_5218e92f700d91afe6a8db79cb" ON "Incident" ("rootCause") `,
);
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class MigrationName1731433309124 implements MigrationInterface {
public name = 'MigrationName1731433309124'
public name = "MigrationName1731433309124";

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP INDEX "public"."IDX_fc40ea6a9ad55f29bca4f4a15d"`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE INDEX "IDX_fc40ea6a9ad55f29bca4f4a15d" ON "Alert" ("rootCause") `);
}
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`DROP INDEX "public"."IDX_fc40ea6a9ad55f29bca4f4a15d"`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE INDEX "IDX_fc40ea6a9ad55f29bca4f4a15d" ON "Alert" ("rootCause") `,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,5 @@ export default [
MigrationName1730209089495,
MigrationName1730223198692,
MigrationName1731433043136,
MigrationName1731433309124
MigrationName1731433309124,
];
4 changes: 0 additions & 4 deletions Common/Server/Utils/Monitor/MonitorIncident.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,6 @@ export default class MonitorIncident {
continue;
}

// create incident here.

debugger;

logger.debug(`${input.monitor.id?.toString()} - Create incident.`);

const incident: Incident = new Incident();
Expand Down
19 changes: 10 additions & 9 deletions Common/Server/Utils/Monitor/MonitorResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ export default class MonitorResourceUtil {

// get last log. We do this because there are many monitoring steps and we need to store those.
logger.debug(
`${dataToProcess.monitorId.toString()} - monitor type ${monitor.monitorType
`${dataToProcess.monitorId.toString()} - monitor type ${
monitor.monitorType
}`,
);

Expand Down Expand Up @@ -309,7 +310,7 @@ export default class MonitorResourceUtil {
if (incidentTemplate.autoResolveIncident) {
if (
!autoResolveCriteriaInstanceIdIncidentIdsDictionary[
criteriaInstance.data.id.toString()
criteriaInstance.data.id.toString()
]
) {
autoResolveCriteriaInstanceIdIncidentIdsDictionary[
Expand Down Expand Up @@ -345,7 +346,7 @@ export default class MonitorResourceUtil {
if (alertTemplate.autoResolveAlert) {
if (
!autoResolveCriteriaInstanceIdAlertIdsDictionary[
criteriaInstance.data.id.toString()
criteriaInstance.data.id.toString()
]
) {
autoResolveCriteriaInstanceIdAlertIdsDictionary[
Expand Down Expand Up @@ -415,11 +416,13 @@ export default class MonitorResourceUtil {

if (response.criteriaMetId && response.rootCause) {
logger.debug(
`${dataToProcess.monitorId.toString()} - Criteria met: ${response.criteriaMetId
`${dataToProcess.monitorId.toString()} - Criteria met: ${
response.criteriaMetId
}`,
);
logger.debug(
`${dataToProcess.monitorId.toString()} - Root cause: ${response.rootCause
`${dataToProcess.monitorId.toString()} - Root cause: ${
response.rootCause
}`,
);

Expand Down Expand Up @@ -480,7 +483,7 @@ export default class MonitorResourceUtil {
!response.criteriaMetId &&
monitorSteps.data.defaultMonitorStatusId &&
monitor.currentMonitorStatusId?.toString() !==
monitorSteps.data.defaultMonitorStatusId.toString()
monitorSteps.data.defaultMonitorStatusId.toString()
) {
logger.debug(
`${dataToProcess.monitorId.toString()} - No criteria met. Change to default status.`,
Expand Down Expand Up @@ -517,7 +520,7 @@ export default class MonitorResourceUtil {
lastMonitorStatusTimeline &&
lastMonitorStatusTimeline.monitorStatusId &&
lastMonitorStatusTimeline.monitorStatusId.toString() ===
monitorSteps.data.defaultMonitorStatusId.toString()
monitorSteps.data.defaultMonitorStatusId.toString()
) {
// status is same as last status. do not create new status timeline.
// do nothing! status is same as last status.
Expand Down Expand Up @@ -954,7 +957,6 @@ export default class MonitorResourceUtil {
probeApiIngestResponse: ProbeApiIngestResponse;
criteriaInstance: MonitorCriteriaInstance;
}): Promise<string | null> {

// returns root cause if any. Otherwise criteria is not met.
let finalResult: string | null = "All filters met. ";

Expand Down Expand Up @@ -1018,7 +1020,6 @@ export default class MonitorResourceUtil {
});

if (screenshotInBase64) {

finalResult += `
**Screenshot**:
Expand Down

0 comments on commit 76f9537

Please sign in to comment.