Skip to content

Commit

Permalink
Refactor code for improved readability and consistency across Monitor…
Browse files Browse the repository at this point in the history
… components
  • Loading branch information
simlarsen committed Dec 10, 2024
1 parent 14d3228 commit 450488e
Show file tree
Hide file tree
Showing 13 changed files with 258 additions and 235 deletions.
2 changes: 0 additions & 2 deletions Common/Server/Utils/Monitor/Criteria/MetricMonitorCriteria.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import AggregateModel from "../../../../Types/BaseDatabase/AggregatedModel";
import AggregatedResult from "../../../../Types/BaseDatabase/AggregatedResult";
import MetricMonitorResponse from "../../../../Types/Monitor/MetricMonitor/MetricMonitorResponse";
import DataToProcess from "../DataToProcess";
import CompareCriteria from "./CompareCriteria";
import { CheckOn, CriteriaFilter } from "Common/Types/Monitor/CriteriaFilter";
import LogMonitorResponse from "Common/Types/Monitor/LogMonitor/LogMonitorResponse";

export default class LogMonitorCriteria {
public static async isMonitorInstanceCriteriaFilterMet(input: {
Expand Down
5 changes: 2 additions & 3 deletions Common/Types/Monitor/CriteriaFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ export enum CheckOn {
// Trace monitors.
SpanCount = "Span Count",

// Metric Monitors.
// Metric Monitors.
MetricValue = "Metric Value",

}

export interface ServerMonitorOptions {
Expand Down Expand Up @@ -81,7 +80,7 @@ export interface EvaluateOverTimeOptions {
export interface CriteriaFilter {
checkOn: CheckOn;
serverMonitorOptions?: ServerMonitorOptions | undefined;
metricMonitorOptions?: MetricMonitorOptions | undefined;
metricMonitorOptions?: MetricMonitorOptions | undefined;
filterType: FilterType | undefined;
value: string | number | undefined;
eveluateOverTime?: boolean | undefined;
Expand Down
19 changes: 14 additions & 5 deletions Common/Types/Monitor/MonitorCriteriaInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default class MonitorCriteriaInstance extends DatabaseProperty {
monitorName: string;
metricOptions?: {
metricAliases: Array<string>;
}
};
}): MonitorCriteriaInstance | null {
if (arg.monitorType === MonitorType.IncomingRequest) {
const monitorCriteriaInstance: MonitorCriteriaInstance =
Expand Down Expand Up @@ -130,7 +130,12 @@ export default class MonitorCriteriaInstance extends DatabaseProperty {
checkOn: CheckOn.MetricValue,
filterType: FilterType.GreaterThan,
metricMonitorOptions: {
metricAlias: arg.metricOptions && arg.metricOptions.metricAliases && arg.metricOptions.metricAliases.length > 0 ? arg.metricOptions.metricAliases[0] : undefined,
metricAlias:
arg.metricOptions &&
arg.metricOptions.metricAliases &&
arg.metricOptions.metricAliases.length > 0
? arg.metricOptions.metricAliases[0]
: undefined,
},
value: 0, // if there are some logs then monitor is online.
},
Expand Down Expand Up @@ -313,7 +318,7 @@ export default class MonitorCriteriaInstance extends DatabaseProperty {
monitorName: string;
metricOptions?: {
metricAliases: Array<string>;
}
};
}): MonitorCriteriaInstance {
const monitorCriteriaInstance: MonitorCriteriaInstance =
new MonitorCriteriaInstance();
Expand Down Expand Up @@ -451,7 +456,6 @@ export default class MonitorCriteriaInstance extends DatabaseProperty {
};
}


if (arg.monitorType === MonitorType.Metrics) {
monitorCriteriaInstance.data = {
id: ObjectID.generate().toString(),
Expand All @@ -462,7 +466,12 @@ export default class MonitorCriteriaInstance extends DatabaseProperty {
checkOn: CheckOn.MetricValue,
filterType: FilterType.EqualTo,
metricMonitorOptions: {
metricAlias: arg.metricOptions && arg.metricOptions.metricAliases && arg.metricOptions.metricAliases.length > 0 ? arg.metricOptions.metricAliases[0] : undefined,
metricAlias:
arg.metricOptions &&
arg.metricOptions.metricAliases &&
arg.metricOptions.metricAliases.length > 0
? arg.metricOptions.metricAliases[0]
: undefined,
},
value: 0, // if there are no logs then the monitor is offline
},
Expand Down
24 changes: 15 additions & 9 deletions Common/Types/Monitor/MonitorStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import { FindOperator } from "typeorm";
import MonitorStepTraceMonitor, {
MonitorStepTraceMonitorUtil,
} from "./MonitorStepTraceMonitor";
import MonitorStepMetricMonitor, { MonitorStepMetricMonitorUtil } from "./MonitorStepMetricMonitor";
import MonitorStepMetricMonitor, {
MonitorStepMetricMonitorUtil,
} from "./MonitorStepMetricMonitor";

export interface MonitorStepType {
id: string;
Expand Down Expand Up @@ -52,8 +54,7 @@ export interface MonitorStepType {
// trace monitor type.
traceMonitor?: MonitorStepTraceMonitor | undefined;


// Metric Monitor
// Metric Monitor
metricMonitor: MonitorStepMetricMonitor | undefined;
}

Expand Down Expand Up @@ -172,7 +173,9 @@ export default class MonitorStep extends DatabaseProperty {
return this;
}

public setMetricMonitor(metricMonitor: MonitorStepMetricMonitor): MonitorStep {
public setMetricMonitor(
metricMonitor: MonitorStepMetricMonitor,
): MonitorStep {
this.data!.metricMonitor = metricMonitor;
return this;
}
Expand Down Expand Up @@ -297,7 +300,9 @@ export default class MonitorStep extends DatabaseProperty {
this.data.logMonitor || MonitorStepLogMonitorUtil.getDefault(),
)
: undefined,
metricMonitor: this.data.metricMonitor ? MonitorStepMetricMonitorUtil.toJSON(this.data.metricMonitor) : undefined,
metricMonitor: this.data.metricMonitor
? MonitorStepMetricMonitorUtil.toJSON(this.data.metricMonitor)
: undefined,
traceMonitor: this.data.traceMonitor
? MonitorStepTraceMonitorUtil.toJSON(
this.data.traceMonitor ||
Expand Down Expand Up @@ -396,8 +401,8 @@ export default class MonitorStep extends DatabaseProperty {
logMonitor: json["logMonitor"]
? (json["logMonitor"] as JSONObject)
: undefined,
metricMonitor: json["metricMonitor"]
? (json["metricMonitor"] as JSONObject)
metricMonitor: json["metricMonitor"]
? (json["metricMonitor"] as JSONObject)
: undefined,
traceMonitor: json["traceMonitor"]
? (json["traceMonitor"] as JSONObject)
Expand All @@ -412,8 +417,9 @@ export default class MonitorStep extends DatabaseProperty {
monitorStep.data.traceMonitor = MonitorStepTraceMonitorUtil.getDefault();
}

if(monitorStep.data && !monitorStep.data?.metricMonitor) {
monitorStep.data.metricMonitor = MonitorStepMetricMonitorUtil.getDefault();
if (monitorStep.data && !monitorStep.data?.metricMonitor) {
monitorStep.data.metricMonitor =
MonitorStepMetricMonitorUtil.getDefault();
}

return monitorStep;
Expand Down
9 changes: 4 additions & 5 deletions Common/Types/Monitor/MonitorStepMetricMonitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,21 @@ export default interface MonitorStepMetricMonitor {
}

export class MonitorStepMetricMonitorUtil {

public static getDefault(): MonitorStepMetricMonitor {
return {
metricViewConfig: {
queryConfigs: [],
formulaConfigs: []
formulaConfigs: [],
},
rollingTime: RollingTime.Past1Minute
rollingTime: RollingTime.Past1Minute,
};
}

public static fromJSON(json: JSONObject): MonitorStepMetricMonitor {
return (json as any) as MonitorStepMetricMonitor;
return json as any as MonitorStepMetricMonitor;
}

public static toJSON(monitor: MonitorStepMetricMonitor): JSONObject {
return (monitor as any) as JSONObject;
return monitor as any as JSONObject;
}
}
45 changes: 22 additions & 23 deletions Common/Types/RollingTime/RollingTime.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
enum RollingTime {
Past1Minute = "Past 1 Minute",
Past5Minutes = "Past 5 Minutes",
Past10Minutes = "Past 10 Minutes",
Past15Minutes = "Past 15 Minutes",
Past30Minutes = "Past 30 Minutes",
Past1Hour = "Past 1 Hour",
Past2Hours = "Past 2 Hours",
Past3Hours = "Past 3 Hours",
Past6Hours = "Past 6 Hours",
Past12Hours = "Past 12 Hours",
Past1Hours = "Past 1 Day",
Past2Days = "Past 2 Days",
Past3Days = "Past 3 Days",
Past7Days = "Past 7 Days",
Past14Days = "Past 14 Days",
Past30Days = "Past 30 Days",
Past60Days = "Past 60 Days",
Past90Days = "Past 90 Days",
Past180Days = "Past 180 Days",
Past365Days = "Past 365 Days",
enum RollingTime {
Past1Minute = "Past 1 Minute",
Past5Minutes = "Past 5 Minutes",
Past10Minutes = "Past 10 Minutes",
Past15Minutes = "Past 15 Minutes",
Past30Minutes = "Past 30 Minutes",
Past1Hour = "Past 1 Hour",
Past2Hours = "Past 2 Hours",
Past3Hours = "Past 3 Hours",
Past6Hours = "Past 6 Hours",
Past12Hours = "Past 12 Hours",
Past1Hours = "Past 1 Day",
Past2Days = "Past 2 Days",
Past3Days = "Past 3 Days",
Past7Days = "Past 7 Days",
Past14Days = "Past 14 Days",
Past30Days = "Past 30 Days",
Past60Days = "Past 60 Days",
Past90Days = "Past 90 Days",
Past180Days = "Past 180 Days",
Past365Days = "Past 365 Days",
}


export default RollingTime;
export default RollingTime;
Loading

0 comments on commit 450488e

Please sign in to comment.