Skip to content

Commit

Permalink
Remove unused index decorators from Alert and Incident models, and ad…
Browse files Browse the repository at this point in the history
…d new migration files to drop specific indexes
  • Loading branch information
simlarsen committed Nov 12, 2024
1 parent 86694d9 commit c0994ff
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 29 deletions.
1 change: 0 additions & 1 deletion Common/Models/DatabaseModels/Alert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,6 @@ export default class Alert extends BaseModel {
],
update: [],
})
@Index()
@TableColumn({
type: TableColumnType.Markdown,
required: false,
Expand Down
1 change: 0 additions & 1 deletion Common/Models/DatabaseModels/Incident.ts
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,6 @@ export default class Incident extends BaseModel {
],
update: [],
})
@Index()
@TableColumn({
type: TableColumnType.Markdown,
required: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class MigrationName1731433043136 implements MigrationInterface {
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") `);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class MigrationName1731433309124 implements MigrationInterface {
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") `);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ import { MigrationName1729682875503 } from "./1729682875503-MigrationName";
import { MigrationName1730117995642 } from "./1730117995642-MigrationName";
import { MigrationName1730209089495 } from "./1730209089495-MigrationName";
import { MigrationName1730223198692 } from "./1730223198692-MigrationName";
import { MigrationName1731433043136 } from "./1731433043136-MigrationName";
import { MigrationName1731433309124 } from "./1731433309124-MigrationName";

export default [
InitialMigration,
Expand Down Expand Up @@ -160,4 +162,6 @@ export default [
MigrationName1730117995642,
MigrationName1730209089495,
MigrationName1730223198692,
MigrationName1731433043136,
MigrationName1731433309124
];
38 changes: 22 additions & 16 deletions Common/Server/Utils/Browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,39 @@ import LocalFile from "./LocalFile";
import BadDataException from "../../Types/Exception/BadDataException";
import ScreenSizeType from "../../Types/ScreenSizeType";
import BrowserType from "../../Types/BrowserType";
import logger from "./Logger";

export type Page = PlaywrightPage;
export type Browser = PlaywrightBrowser;

export default class BrowserUtil {
public static async convertHtmlToBase64Screenshot(data: {
html: string;
}): Promise<string> {
const html: string = data.html;

const pageAndBrowser: {
page: Page;
browser: Browser;
} = await BrowserUtil.getPageByBrowserType({
browserType: BrowserType.Chromium,
screenSizeType: ScreenSizeType.Desktop,
});
}): Promise<string | null> {
try {
const html: string = data.html;

const pageAndBrowser: {
page: Page;
browser: Browser;
} = await BrowserUtil.getPageByBrowserType({
browserType: BrowserType.Chromium,
screenSizeType: ScreenSizeType.Desktop,
});

const page: Page = pageAndBrowser.page;
const browser: Browser = pageAndBrowser.browser;
const page: Page = pageAndBrowser.page;
const browser: Browser = pageAndBrowser.browser;

await page.setContent(html);
const screenshot: Buffer = await page.screenshot({ type: "png" });
await page.setContent(html);
const screenshot: Buffer = await page.screenshot({ type: "png" });

await browser.close();
await browser.close();

return screenshot.toString("base64");
return screenshot.toString("base64");
} catch (e) {
logger.debug(e);
return null;
}
}

public static async getPageByBrowserType(data: {
Expand Down
2 changes: 2 additions & 0 deletions Common/Server/Utils/Monitor/MonitorIncident.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ export default class MonitorIncident {

// create incident here.

debugger;

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

const incident: Incident = new Incident();
Expand Down
24 changes: 13 additions & 11 deletions Common/Server/Utils/Monitor/MonitorResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ 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 @@ -310,7 +309,7 @@ export default class MonitorResourceUtil {
if (incidentTemplate.autoResolveIncident) {
if (
!autoResolveCriteriaInstanceIdIncidentIdsDictionary[
criteriaInstance.data.id.toString()
criteriaInstance.data.id.toString()
]
) {
autoResolveCriteriaInstanceIdIncidentIdsDictionary[
Expand Down Expand Up @@ -346,7 +345,7 @@ export default class MonitorResourceUtil {
if (alertTemplate.autoResolveAlert) {
if (
!autoResolveCriteriaInstanceIdAlertIdsDictionary[
criteriaInstance.data.id.toString()
criteriaInstance.data.id.toString()
]
) {
autoResolveCriteriaInstanceIdAlertIdsDictionary[
Expand Down Expand Up @@ -416,13 +415,11 @@ 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 @@ -483,7 +480,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 @@ -520,7 +517,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 @@ -957,6 +954,7 @@ 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 @@ -1019,10 +1017,14 @@ export default class MonitorResourceUtil {
.responseBody as string,
});

finalResult += `
if (screenshotInBase64) {

finalResult += `
**Screenshot**:
![Screenshot](data:image/png;base64,${screenshotInBase64});
`;
}
}
}
}
Expand Down

0 comments on commit c0994ff

Please sign in to comment.