@oneuptime/common 7.0.3987 → 7.0.3993
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Models/AnalyticsModels/Metric.ts +0 -62
- package/Models/DatabaseModels/MetricType.ts +63 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1743538648415-MigrationName.ts +19 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts +2 -0
- package/Server/Services/AlertService.ts +58 -36
- package/Server/Services/IncidentService.ts +49 -9
- package/Server/Utils/Monitor/MonitorResource.ts +93 -33
- package/Server/Utils/Telemetry/Telemetry.ts +32 -9
- package/UI/Components/ModelTable/BaseModelTable.tsx +4 -1
- package/build/dist/Models/AnalyticsModels/Metric.js +0 -56
- package/build/dist/Models/AnalyticsModels/Metric.js.map +1 -1
- package/build/dist/Models/DatabaseModels/MetricType.js +67 -0
- package/build/dist/Models/DatabaseModels/MetricType.js.map +1 -1
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1743538648415-MigrationName.js +14 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1743538648415-MigrationName.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js +2 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js.map +1 -1
- package/build/dist/Server/Services/AlertService.js +52 -32
- package/build/dist/Server/Services/AlertService.js.map +1 -1
- package/build/dist/Server/Services/IncidentService.js +38 -9
- package/build/dist/Server/Services/IncidentService.js.map +1 -1
- package/build/dist/Server/Utils/Monitor/MonitorResource.js +56 -31
- package/build/dist/Server/Utils/Monitor/MonitorResource.js.map +1 -1
- package/build/dist/Server/Utils/Telemetry/Telemetry.js +25 -4
- package/build/dist/Server/Utils/Telemetry/Telemetry.js.map +1 -1
- package/build/dist/UI/Components/ModelTable/BaseModelTable.js +4 -1
- package/build/dist/UI/Components/ModelTable/BaseModelTable.js.map +1 -1
- package/package.json +2 -2
|
@@ -158,52 +158,6 @@ export default class Metric extends AnalyticsBaseModel {
|
|
|
158
158
|
},
|
|
159
159
|
}),
|
|
160
160
|
|
|
161
|
-
new AnalyticsTableColumn({
|
|
162
|
-
key: "description",
|
|
163
|
-
title: "Description",
|
|
164
|
-
description: "Description of the Metric",
|
|
165
|
-
required: false,
|
|
166
|
-
type: TableColumnType.Text,
|
|
167
|
-
accessControl: {
|
|
168
|
-
read: [
|
|
169
|
-
Permission.ProjectOwner,
|
|
170
|
-
Permission.ProjectAdmin,
|
|
171
|
-
Permission.ProjectMember,
|
|
172
|
-
Permission.ReadTelemetryServiceLog,
|
|
173
|
-
],
|
|
174
|
-
create: [
|
|
175
|
-
Permission.ProjectOwner,
|
|
176
|
-
Permission.ProjectAdmin,
|
|
177
|
-
Permission.ProjectMember,
|
|
178
|
-
Permission.CreateTelemetryServiceLog,
|
|
179
|
-
],
|
|
180
|
-
update: [],
|
|
181
|
-
},
|
|
182
|
-
}),
|
|
183
|
-
|
|
184
|
-
new AnalyticsTableColumn({
|
|
185
|
-
key: "unit",
|
|
186
|
-
title: "Unit",
|
|
187
|
-
description: "Unit of the Metric",
|
|
188
|
-
required: false,
|
|
189
|
-
type: TableColumnType.Text,
|
|
190
|
-
accessControl: {
|
|
191
|
-
read: [
|
|
192
|
-
Permission.ProjectOwner,
|
|
193
|
-
Permission.ProjectAdmin,
|
|
194
|
-
Permission.ProjectMember,
|
|
195
|
-
Permission.ReadTelemetryServiceLog,
|
|
196
|
-
],
|
|
197
|
-
create: [
|
|
198
|
-
Permission.ProjectOwner,
|
|
199
|
-
Permission.ProjectAdmin,
|
|
200
|
-
Permission.ProjectMember,
|
|
201
|
-
Permission.CreateTelemetryServiceLog,
|
|
202
|
-
],
|
|
203
|
-
update: [],
|
|
204
|
-
},
|
|
205
|
-
}),
|
|
206
|
-
|
|
207
161
|
new AnalyticsTableColumn({
|
|
208
162
|
key: "aggregationTemporality",
|
|
209
163
|
title: "Aggregation Temporality",
|
|
@@ -603,22 +557,6 @@ export default class Metric extends AnalyticsBaseModel {
|
|
|
603
557
|
this.setColumnValue("metricPointType", v);
|
|
604
558
|
}
|
|
605
559
|
|
|
606
|
-
public get description(): string | undefined {
|
|
607
|
-
return this.getColumnValue("description") as string | undefined;
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
public set description(v: string | undefined) {
|
|
611
|
-
this.setColumnValue("description", v);
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
public get unit(): string | undefined {
|
|
615
|
-
return this.getColumnValue("unit") as string | undefined;
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
public set unit(v: string | undefined) {
|
|
619
|
-
this.setColumnValue("unit", v);
|
|
620
|
-
}
|
|
621
|
-
|
|
622
560
|
public get isMonotonic(): boolean | undefined {
|
|
623
561
|
return this.getColumnValue("isMonotonic") as boolean | undefined;
|
|
624
562
|
}
|
|
@@ -219,6 +219,69 @@ export default class MetricType extends BaseModel {
|
|
|
219
219
|
@Index()
|
|
220
220
|
public name?: string = undefined;
|
|
221
221
|
|
|
222
|
+
@ColumnAccessControl({
|
|
223
|
+
create: [
|
|
224
|
+
Permission.ProjectOwner,
|
|
225
|
+
Permission.ProjectAdmin,
|
|
226
|
+
Permission.CreateTelemetryServiceMetrics,
|
|
227
|
+
],
|
|
228
|
+
read: [
|
|
229
|
+
Permission.ProjectOwner,
|
|
230
|
+
Permission.ProjectAdmin,
|
|
231
|
+
Permission.ProjectMember,
|
|
232
|
+
Permission.ReadTelemetryServiceMetrics,
|
|
233
|
+
],
|
|
234
|
+
update: [
|
|
235
|
+
Permission.ProjectOwner,
|
|
236
|
+
Permission.ProjectAdmin,
|
|
237
|
+
Permission.EditTelemetryServiceMetrics,
|
|
238
|
+
],
|
|
239
|
+
})
|
|
240
|
+
@TableColumn({
|
|
241
|
+
required: false,
|
|
242
|
+
type: TableColumnType.VeryLongText,
|
|
243
|
+
canReadOnRelationQuery: true,
|
|
244
|
+
title: "Description",
|
|
245
|
+
description: "Metric description",
|
|
246
|
+
})
|
|
247
|
+
@Column({
|
|
248
|
+
nullable: true,
|
|
249
|
+
type: ColumnType.VeryLongText,
|
|
250
|
+
})
|
|
251
|
+
public description?: string = undefined;
|
|
252
|
+
|
|
253
|
+
@ColumnAccessControl({
|
|
254
|
+
create: [
|
|
255
|
+
Permission.ProjectOwner,
|
|
256
|
+
Permission.ProjectAdmin,
|
|
257
|
+
Permission.CreateTelemetryServiceMetrics,
|
|
258
|
+
],
|
|
259
|
+
read: [
|
|
260
|
+
Permission.ProjectOwner,
|
|
261
|
+
Permission.ProjectAdmin,
|
|
262
|
+
Permission.ProjectMember,
|
|
263
|
+
Permission.ReadTelemetryServiceMetrics,
|
|
264
|
+
],
|
|
265
|
+
update: [
|
|
266
|
+
Permission.ProjectOwner,
|
|
267
|
+
Permission.ProjectAdmin,
|
|
268
|
+
Permission.EditTelemetryServiceMetrics,
|
|
269
|
+
],
|
|
270
|
+
})
|
|
271
|
+
@TableColumn({
|
|
272
|
+
required: false,
|
|
273
|
+
type: TableColumnType.VeryLongText,
|
|
274
|
+
canReadOnRelationQuery: true,
|
|
275
|
+
title: "Description",
|
|
276
|
+
description: "Metric description",
|
|
277
|
+
})
|
|
278
|
+
@Column({
|
|
279
|
+
nullable: true,
|
|
280
|
+
type: ColumnType.ShortText,
|
|
281
|
+
length: ColumnLength.ShortText,
|
|
282
|
+
})
|
|
283
|
+
public unit?: string = undefined;
|
|
284
|
+
|
|
222
285
|
@ColumnAccessControl({
|
|
223
286
|
create: [
|
|
224
287
|
Permission.ProjectOwner,
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { MigrationInterface, QueryRunner } from "typeorm";
|
|
2
|
+
|
|
3
|
+
export class MigrationName1743538648415 implements MigrationInterface {
|
|
4
|
+
public name = "MigrationName1743538648415";
|
|
5
|
+
|
|
6
|
+
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
7
|
+
await queryRunner.query(`ALTER TABLE "MetricType" ADD "description" text`);
|
|
8
|
+
await queryRunner.query(
|
|
9
|
+
`ALTER TABLE "MetricType" ADD "unit" character varying(100)`,
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
14
|
+
await queryRunner.query(`ALTER TABLE "MetricType" DROP COLUMN "unit"`);
|
|
15
|
+
await queryRunner.query(
|
|
16
|
+
`ALTER TABLE "MetricType" DROP COLUMN "description"`,
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -126,6 +126,7 @@ import { MigrationName1743186793413 } from "./1743186793413-MigrationName";
|
|
|
126
126
|
import { MigrationName1743518485566 } from "./1743518485566-MigrationName";
|
|
127
127
|
import { MigrationName1743521461137 } from "./1743521461137-MigrationName";
|
|
128
128
|
import { MigrationName1743530326936 } from "./1743530326936-MigrationName";
|
|
129
|
+
import { MigrationName1743538648415 } from "./1743538648415-MigrationName";
|
|
129
130
|
|
|
130
131
|
export default [
|
|
131
132
|
InitialMigration,
|
|
@@ -256,4 +257,5 @@ export default [
|
|
|
256
257
|
MigrationName1743518485566,
|
|
257
258
|
MigrationName1743521461137,
|
|
258
259
|
MigrationName1743530326936,
|
|
260
|
+
MigrationName1743538648415,
|
|
259
261
|
];
|
|
@@ -52,6 +52,8 @@ import Monitor from "../../Models/DatabaseModels/Monitor";
|
|
|
52
52
|
import MonitorService from "./MonitorService";
|
|
53
53
|
import { MessageBlocksByWorkspaceType } from "./WorkspaceNotificationRuleService";
|
|
54
54
|
import CaptureSpan from "../Utils/Telemetry/CaptureSpan";
|
|
55
|
+
import MetricType from "../../Models/DatabaseModels/MetricType";
|
|
56
|
+
import Dictionary from "../../Types/Dictionary";
|
|
55
57
|
|
|
56
58
|
export class Service extends DatabaseService<Model> {
|
|
57
59
|
public constructor() {
|
|
@@ -946,8 +948,8 @@ ${alertSeverity.name}
|
|
|
946
948
|
name: true,
|
|
947
949
|
},
|
|
948
950
|
alertSeverity: {
|
|
949
|
-
name: true,
|
|
950
951
|
_id: true,
|
|
952
|
+
name: true,
|
|
951
953
|
},
|
|
952
954
|
},
|
|
953
955
|
props: {
|
|
@@ -960,11 +962,10 @@ ${alertSeverity.name}
|
|
|
960
962
|
}
|
|
961
963
|
|
|
962
964
|
if (!alert.projectId) {
|
|
963
|
-
throw new BadDataException("
|
|
965
|
+
throw new BadDataException("Alert Project ID not found");
|
|
964
966
|
}
|
|
965
967
|
|
|
966
968
|
// get alert state timeline
|
|
967
|
-
|
|
968
969
|
const alertStateTimelines: Array<AlertStateTimeline> =
|
|
969
970
|
await AlertStateTimelineService.findBy({
|
|
970
971
|
query: {
|
|
@@ -993,8 +994,7 @@ ${alertSeverity.name}
|
|
|
993
994
|
const firstAlertStateTimeline: AlertStateTimeline | undefined =
|
|
994
995
|
alertStateTimelines[0];
|
|
995
996
|
|
|
996
|
-
// delete all the alert metrics with this alert id because
|
|
997
|
-
|
|
997
|
+
// delete all the alert metrics with this alert id because it's a refresh
|
|
998
998
|
await MetricService.deleteBy({
|
|
999
999
|
query: {
|
|
1000
1000
|
serviceId: data.alertId,
|
|
@@ -1005,9 +1005,9 @@ ${alertSeverity.name}
|
|
|
1005
1005
|
});
|
|
1006
1006
|
|
|
1007
1007
|
const itemsToSave: Array<Metric> = [];
|
|
1008
|
+
const metricTypesMap: Dictionary<MetricType> = {};
|
|
1008
1009
|
|
|
1009
1010
|
// now we need to create new metrics for this alert - TimeToAcknowledge, TimeToResolve, AlertCount, AlertDuration
|
|
1010
|
-
|
|
1011
1011
|
const alertStartsAt: Date =
|
|
1012
1012
|
firstAlertStateTimeline?.startsAt ||
|
|
1013
1013
|
alert.createdAt ||
|
|
@@ -1019,16 +1019,14 @@ ${alertSeverity.name}
|
|
|
1019
1019
|
alertCountMetric.serviceId = alert.id!;
|
|
1020
1020
|
alertCountMetric.serviceType = ServiceType.Alert;
|
|
1021
1021
|
alertCountMetric.name = AlertMetricType.AlertCount;
|
|
1022
|
-
alertCountMetric.description = "Number of alerts created";
|
|
1023
1022
|
alertCountMetric.value = 1;
|
|
1024
|
-
alertCountMetric.unit = "";
|
|
1025
1023
|
alertCountMetric.attributes = {
|
|
1026
1024
|
alertId: data.alertId.toString(),
|
|
1027
1025
|
projectId: alert.projectId.toString(),
|
|
1028
|
-
monitorId: alert.monitor?.
|
|
1029
|
-
monitorName: alert.monitor?.name
|
|
1030
|
-
alertSeverityId: alert.alertSeverity?.
|
|
1031
|
-
alertSeverityName: alert.alertSeverity?.name
|
|
1026
|
+
monitorId: alert.monitor?._id?.toString(),
|
|
1027
|
+
monitorName: alert.monitor?.name?.toString(),
|
|
1028
|
+
alertSeverityId: alert.alertSeverity?._id?.toString(),
|
|
1029
|
+
alertSeverityName: alert.alertSeverity?.name?.toString(),
|
|
1032
1030
|
};
|
|
1033
1031
|
|
|
1034
1032
|
alertCountMetric.time = alertStartsAt;
|
|
@@ -1039,6 +1037,13 @@ ${alertSeverity.name}
|
|
|
1039
1037
|
|
|
1040
1038
|
itemsToSave.push(alertCountMetric);
|
|
1041
1039
|
|
|
1040
|
+
const metricType: MetricType = new MetricType();
|
|
1041
|
+
metricType.name = alertCountMetric.name;
|
|
1042
|
+
metricType.description = "Number of alerts created";
|
|
1043
|
+
metricType.unit = "";
|
|
1044
|
+
metricType.telemetryServices = [];
|
|
1045
|
+
metricTypesMap[alertCountMetric.name] = metricType;
|
|
1046
|
+
|
|
1042
1047
|
// is the alert acknowledged?
|
|
1043
1048
|
const isAlertAcknowledged: boolean = alertStateTimelines.some(
|
|
1044
1049
|
(timeline: AlertStateTimeline) => {
|
|
@@ -1059,20 +1064,17 @@ ${alertSeverity.name}
|
|
|
1059
1064
|
timeToAcknowledgeMetric.serviceId = alert.id!;
|
|
1060
1065
|
timeToAcknowledgeMetric.serviceType = ServiceType.Alert;
|
|
1061
1066
|
timeToAcknowledgeMetric.name = AlertMetricType.TimeToAcknowledge;
|
|
1062
|
-
timeToAcknowledgeMetric.description =
|
|
1063
|
-
"Time taken to acknowledge the alert";
|
|
1064
1067
|
timeToAcknowledgeMetric.value = OneUptimeDate.getDifferenceInSeconds(
|
|
1065
1068
|
ackAlertStateTimeline?.startsAt || OneUptimeDate.getCurrentDate(),
|
|
1066
1069
|
alertStartsAt,
|
|
1067
1070
|
);
|
|
1068
|
-
timeToAcknowledgeMetric.unit = "seconds";
|
|
1069
1071
|
timeToAcknowledgeMetric.attributes = {
|
|
1070
1072
|
alertId: data.alertId.toString(),
|
|
1071
1073
|
projectId: alert.projectId.toString(),
|
|
1072
|
-
monitorId: alert.monitor?.
|
|
1073
|
-
monitorName: alert.monitor?.name
|
|
1074
|
-
alertSeverityId: alert.alertSeverity?.
|
|
1075
|
-
alertSeverityName: alert.alertSeverity?.name
|
|
1074
|
+
monitorId: alert.monitor?._id?.toString(),
|
|
1075
|
+
monitorName: alert.monitor?.name?.toString(),
|
|
1076
|
+
alertSeverityId: alert.alertSeverity?._id?.toString(),
|
|
1077
|
+
alertSeverityName: alert.alertSeverity?.name?.toString(),
|
|
1076
1078
|
};
|
|
1077
1079
|
|
|
1078
1080
|
timeToAcknowledgeMetric.time =
|
|
@@ -1085,6 +1087,12 @@ ${alertSeverity.name}
|
|
|
1085
1087
|
timeToAcknowledgeMetric.metricPointType = MetricPointType.Sum;
|
|
1086
1088
|
|
|
1087
1089
|
itemsToSave.push(timeToAcknowledgeMetric);
|
|
1090
|
+
|
|
1091
|
+
const metricType: MetricType = new MetricType();
|
|
1092
|
+
metricType.name = timeToAcknowledgeMetric.name;
|
|
1093
|
+
metricType.description = "Time taken to acknowledge the alert";
|
|
1094
|
+
metricType.unit = "seconds";
|
|
1095
|
+
metricTypesMap[timeToAcknowledgeMetric.name] = metricType;
|
|
1088
1096
|
}
|
|
1089
1097
|
}
|
|
1090
1098
|
|
|
@@ -1108,20 +1116,18 @@ ${alertSeverity.name}
|
|
|
1108
1116
|
timeToResolveMetric.serviceId = alert.id!;
|
|
1109
1117
|
timeToResolveMetric.serviceType = ServiceType.Alert;
|
|
1110
1118
|
timeToResolveMetric.name = AlertMetricType.TimeToResolve;
|
|
1111
|
-
timeToResolveMetric.description = "Time taken to resolve the alert";
|
|
1112
1119
|
timeToResolveMetric.value = OneUptimeDate.getDifferenceInSeconds(
|
|
1113
1120
|
resolvedAlertStateTimeline?.startsAt ||
|
|
1114
1121
|
OneUptimeDate.getCurrentDate(),
|
|
1115
1122
|
alertStartsAt,
|
|
1116
1123
|
);
|
|
1117
|
-
timeToResolveMetric.unit = "seconds";
|
|
1118
1124
|
timeToResolveMetric.attributes = {
|
|
1119
1125
|
alertId: data.alertId.toString(),
|
|
1120
1126
|
projectId: alert.projectId.toString(),
|
|
1121
|
-
monitorId: alert.monitor?.
|
|
1122
|
-
monitorName: alert.monitor?.name
|
|
1123
|
-
alertSeverityId: alert.alertSeverity?.
|
|
1124
|
-
alertSeverityName: alert.alertSeverity?.name
|
|
1127
|
+
monitorId: alert.monitor?._id?.toString(),
|
|
1128
|
+
monitorName: alert.monitor?.name?.toString(),
|
|
1129
|
+
alertSeverityId: alert.alertSeverity?._id?.toString(),
|
|
1130
|
+
alertSeverityName: alert.alertSeverity?.name?.toString(),
|
|
1125
1131
|
};
|
|
1126
1132
|
|
|
1127
1133
|
timeToResolveMetric.time =
|
|
@@ -1134,11 +1140,16 @@ ${alertSeverity.name}
|
|
|
1134
1140
|
timeToResolveMetric.metricPointType = MetricPointType.Sum;
|
|
1135
1141
|
|
|
1136
1142
|
itemsToSave.push(timeToResolveMetric);
|
|
1143
|
+
|
|
1144
|
+
const metricType: MetricType = new MetricType();
|
|
1145
|
+
metricType.name = timeToResolveMetric.name;
|
|
1146
|
+
metricType.description = "Time taken to resolve the alert";
|
|
1147
|
+
metricType.unit = "seconds";
|
|
1148
|
+
metricTypesMap[timeToResolveMetric.name] = metricType;
|
|
1137
1149
|
}
|
|
1138
1150
|
}
|
|
1139
1151
|
|
|
1140
1152
|
// alert duration
|
|
1141
|
-
|
|
1142
1153
|
const alertDurationMetric: Metric = new Metric();
|
|
1143
1154
|
|
|
1144
1155
|
const lastAlertStateTimeline: AlertStateTimeline | undefined =
|
|
@@ -1148,25 +1159,21 @@ ${alertSeverity.name}
|
|
|
1148
1159
|
const alertEndsAt: Date =
|
|
1149
1160
|
lastAlertStateTimeline.startsAt || OneUptimeDate.getCurrentDate();
|
|
1150
1161
|
|
|
1151
|
-
// save metric.
|
|
1152
|
-
|
|
1153
1162
|
alertDurationMetric.projectId = alert.projectId;
|
|
1154
1163
|
alertDurationMetric.serviceId = alert.id!;
|
|
1155
1164
|
alertDurationMetric.serviceType = ServiceType.Alert;
|
|
1156
1165
|
alertDurationMetric.name = AlertMetricType.AlertDuration;
|
|
1157
|
-
alertDurationMetric.description = "Duration of the alert";
|
|
1158
1166
|
alertDurationMetric.value = OneUptimeDate.getDifferenceInSeconds(
|
|
1159
1167
|
alertEndsAt,
|
|
1160
1168
|
alertStartsAt,
|
|
1161
1169
|
);
|
|
1162
|
-
alertDurationMetric.unit = "seconds";
|
|
1163
1170
|
alertDurationMetric.attributes = {
|
|
1164
1171
|
alertId: data.alertId.toString(),
|
|
1165
1172
|
projectId: alert.projectId.toString(),
|
|
1166
|
-
monitorId: alert.monitor?.
|
|
1167
|
-
monitorName: alert.monitor?.name
|
|
1168
|
-
alertSeverityId: alert.alertSeverity?.
|
|
1169
|
-
alertSeverityName: alert.alertSeverity?.name
|
|
1173
|
+
monitorId: alert.monitor?._id?.toString(),
|
|
1174
|
+
monitorName: alert.monitor?.name?.toString(),
|
|
1175
|
+
alertSeverityId: alert.alertSeverity?._id?.toString(),
|
|
1176
|
+
alertSeverityName: alert.alertSeverity?.name?.toString(),
|
|
1170
1177
|
};
|
|
1171
1178
|
|
|
1172
1179
|
alertDurationMetric.time =
|
|
@@ -1177,6 +1184,14 @@ ${alertSeverity.name}
|
|
|
1177
1184
|
alertDurationMetric.time,
|
|
1178
1185
|
);
|
|
1179
1186
|
alertDurationMetric.metricPointType = MetricPointType.Sum;
|
|
1187
|
+
|
|
1188
|
+
itemsToSave.push(alertDurationMetric);
|
|
1189
|
+
|
|
1190
|
+
const metricType: MetricType = new MetricType();
|
|
1191
|
+
metricType.name = alertDurationMetric.name;
|
|
1192
|
+
metricType.description = "Duration of the alert";
|
|
1193
|
+
metricType.unit = "seconds";
|
|
1194
|
+
metricTypesMap[alertDurationMetric.name] = metricType;
|
|
1180
1195
|
}
|
|
1181
1196
|
|
|
1182
1197
|
await MetricService.createMany({
|
|
@@ -1186,14 +1201,21 @@ ${alertSeverity.name}
|
|
|
1186
1201
|
},
|
|
1187
1202
|
});
|
|
1188
1203
|
|
|
1189
|
-
// index attributes
|
|
1204
|
+
// index attributes
|
|
1190
1205
|
TelemetryUtil.indexAttributes({
|
|
1191
|
-
attributes: ["monitorId", "projectId", "alertId", "
|
|
1206
|
+
attributes: ["monitorId", "projectId", "alertId", "monitorName"],
|
|
1192
1207
|
projectId: alert.projectId,
|
|
1193
1208
|
telemetryType: TelemetryType.Metric,
|
|
1194
1209
|
}).catch((err: Error) => {
|
|
1195
1210
|
logger.error(err);
|
|
1196
1211
|
});
|
|
1212
|
+
|
|
1213
|
+
TelemetryUtil.indexMetricNameServiceNameMap({
|
|
1214
|
+
metricNameServiceNameMap: metricTypesMap,
|
|
1215
|
+
projectId: alert.projectId,
|
|
1216
|
+
}).catch((err: Error) => {
|
|
1217
|
+
logger.error(err);
|
|
1218
|
+
});
|
|
1197
1219
|
}
|
|
1198
1220
|
|
|
1199
1221
|
@CaptureSpan()
|
|
@@ -59,6 +59,8 @@ import WorkspaceType from "../../Types/Workspace/WorkspaceType";
|
|
|
59
59
|
import { MessageBlocksByWorkspaceType } from "./WorkspaceNotificationRuleService";
|
|
60
60
|
import NotificationRuleWorkspaceChannel from "../../Types/Workspace/NotificationRules/NotificationRuleWorkspaceChannel";
|
|
61
61
|
import CaptureSpan from "../Utils/Telemetry/CaptureSpan";
|
|
62
|
+
import { Dictionary } from "lodash";
|
|
63
|
+
import MetricType from "../../Models/DatabaseModels/MetricType";
|
|
62
64
|
|
|
63
65
|
export class Service extends DatabaseService<Model> {
|
|
64
66
|
public constructor() {
|
|
@@ -1327,15 +1329,15 @@ ${incidentSeverity.name}
|
|
|
1327
1329
|
incident.createdAt ||
|
|
1328
1330
|
OneUptimeDate.getCurrentDate();
|
|
1329
1331
|
|
|
1332
|
+
const metricTypesMap: Dictionary<MetricType> = {};
|
|
1333
|
+
|
|
1330
1334
|
const incidentCountMetric: Metric = new Metric();
|
|
1331
1335
|
|
|
1332
1336
|
incidentCountMetric.projectId = incident.projectId;
|
|
1333
1337
|
incidentCountMetric.serviceId = incident.id!;
|
|
1334
1338
|
incidentCountMetric.serviceType = ServiceType.Incident;
|
|
1335
1339
|
incidentCountMetric.name = IncidentMetricType.IncidentCount;
|
|
1336
|
-
incidentCountMetric.description = "Number of incidents created";
|
|
1337
1340
|
incidentCountMetric.value = 1;
|
|
1338
|
-
incidentCountMetric.unit = "";
|
|
1339
1341
|
incidentCountMetric.attributes = {
|
|
1340
1342
|
incidentId: data.incidentId.toString(),
|
|
1341
1343
|
projectId: incident.projectId.toString(),
|
|
@@ -1359,6 +1361,16 @@ ${incidentSeverity.name}
|
|
|
1359
1361
|
|
|
1360
1362
|
itemsToSave.push(incidentCountMetric);
|
|
1361
1363
|
|
|
1364
|
+
// add metric type for this to map.
|
|
1365
|
+
const metricType: MetricType = new MetricType();
|
|
1366
|
+
metricType.name = incidentCountMetric.name;
|
|
1367
|
+
metricType.description = "Number of incidents created";
|
|
1368
|
+
metricType.unit = "";
|
|
1369
|
+
metricType.telemetryServices = [];
|
|
1370
|
+
|
|
1371
|
+
// add to map.
|
|
1372
|
+
metricTypesMap[incidentCountMetric.name] = metricType;
|
|
1373
|
+
|
|
1362
1374
|
// is the incident acknowledged?
|
|
1363
1375
|
const isIncidentAcknowledged: boolean = incidentStateTimelines.some(
|
|
1364
1376
|
(timeline: IncidentStateTimeline) => {
|
|
@@ -1379,13 +1391,10 @@ ${incidentSeverity.name}
|
|
|
1379
1391
|
timeToAcknowledgeMetric.serviceId = incident.id!;
|
|
1380
1392
|
timeToAcknowledgeMetric.serviceType = ServiceType.Incident;
|
|
1381
1393
|
timeToAcknowledgeMetric.name = IncidentMetricType.TimeToAcknowledge;
|
|
1382
|
-
timeToAcknowledgeMetric.description =
|
|
1383
|
-
"Time taken to acknowledge the incident";
|
|
1384
1394
|
timeToAcknowledgeMetric.value = OneUptimeDate.getDifferenceInSeconds(
|
|
1385
1395
|
ackIncidentStateTimeline?.startsAt || OneUptimeDate.getCurrentDate(),
|
|
1386
1396
|
incidentStartsAt,
|
|
1387
1397
|
);
|
|
1388
|
-
timeToAcknowledgeMetric.unit = "seconds";
|
|
1389
1398
|
timeToAcknowledgeMetric.attributes = {
|
|
1390
1399
|
incidentId: data.incidentId.toString(),
|
|
1391
1400
|
projectId: incident.projectId.toString(),
|
|
@@ -1411,6 +1420,15 @@ ${incidentSeverity.name}
|
|
|
1411
1420
|
timeToAcknowledgeMetric.metricPointType = MetricPointType.Sum;
|
|
1412
1421
|
|
|
1413
1422
|
itemsToSave.push(timeToAcknowledgeMetric);
|
|
1423
|
+
|
|
1424
|
+
// add metric type for this to map.
|
|
1425
|
+
const metricType: MetricType = new MetricType();
|
|
1426
|
+
metricType.name = timeToAcknowledgeMetric.name;
|
|
1427
|
+
metricType.description = "Time taken to acknowledge the incident";
|
|
1428
|
+
metricType.unit = "seconds";
|
|
1429
|
+
|
|
1430
|
+
// add to map.
|
|
1431
|
+
metricTypesMap[timeToAcknowledgeMetric.name] = metricType;
|
|
1414
1432
|
}
|
|
1415
1433
|
}
|
|
1416
1434
|
|
|
@@ -1434,13 +1452,11 @@ ${incidentSeverity.name}
|
|
|
1434
1452
|
timeToResolveMetric.serviceId = incident.id!;
|
|
1435
1453
|
timeToResolveMetric.serviceType = ServiceType.Incident;
|
|
1436
1454
|
timeToResolveMetric.name = IncidentMetricType.TimeToResolve;
|
|
1437
|
-
timeToResolveMetric.description = "Time taken to resolve the incident";
|
|
1438
1455
|
timeToResolveMetric.value = OneUptimeDate.getDifferenceInSeconds(
|
|
1439
1456
|
resolvedIncidentStateTimeline?.startsAt ||
|
|
1440
1457
|
OneUptimeDate.getCurrentDate(),
|
|
1441
1458
|
incidentStartsAt,
|
|
1442
1459
|
);
|
|
1443
|
-
timeToResolveMetric.unit = "seconds";
|
|
1444
1460
|
timeToResolveMetric.attributes = {
|
|
1445
1461
|
incidentId: data.incidentId.toString(),
|
|
1446
1462
|
projectId: incident.projectId.toString(),
|
|
@@ -1466,6 +1482,14 @@ ${incidentSeverity.name}
|
|
|
1466
1482
|
timeToResolveMetric.metricPointType = MetricPointType.Sum;
|
|
1467
1483
|
|
|
1468
1484
|
itemsToSave.push(timeToResolveMetric);
|
|
1485
|
+
|
|
1486
|
+
// add metric type for this to map.
|
|
1487
|
+
const metricType: MetricType = new MetricType();
|
|
1488
|
+
metricType.name = timeToResolveMetric.name;
|
|
1489
|
+
metricType.description = "Time taken to resolve the incident";
|
|
1490
|
+
metricType.unit = "seconds";
|
|
1491
|
+
// add to map.
|
|
1492
|
+
metricTypesMap[timeToResolveMetric.name] = metricType;
|
|
1469
1493
|
}
|
|
1470
1494
|
}
|
|
1471
1495
|
|
|
@@ -1486,12 +1510,10 @@ ${incidentSeverity.name}
|
|
|
1486
1510
|
incidentDurationMetric.serviceId = incident.id!;
|
|
1487
1511
|
incidentDurationMetric.serviceType = ServiceType.Incident;
|
|
1488
1512
|
incidentDurationMetric.name = IncidentMetricType.IncidentDuration;
|
|
1489
|
-
incidentDurationMetric.description = "Duration of the incident";
|
|
1490
1513
|
incidentDurationMetric.value = OneUptimeDate.getDifferenceInSeconds(
|
|
1491
1514
|
incidentEndsAt,
|
|
1492
1515
|
incidentStartsAt,
|
|
1493
1516
|
);
|
|
1494
|
-
incidentDurationMetric.unit = "seconds";
|
|
1495
1517
|
incidentDurationMetric.attributes = {
|
|
1496
1518
|
incidentId: data.incidentId.toString(),
|
|
1497
1519
|
projectId: incident.projectId.toString(),
|
|
@@ -1515,6 +1537,17 @@ ${incidentSeverity.name}
|
|
|
1515
1537
|
incidentDurationMetric.time,
|
|
1516
1538
|
);
|
|
1517
1539
|
incidentDurationMetric.metricPointType = MetricPointType.Sum;
|
|
1540
|
+
|
|
1541
|
+
itemsToSave.push(incidentDurationMetric);
|
|
1542
|
+
|
|
1543
|
+
// add metric type for this to map.
|
|
1544
|
+
const metricType: MetricType = new MetricType();
|
|
1545
|
+
metricType.name = incidentDurationMetric.name;
|
|
1546
|
+
metricType.description = "Duration of the incident";
|
|
1547
|
+
metricType.unit = "seconds";
|
|
1548
|
+
|
|
1549
|
+
// add to map.
|
|
1550
|
+
metricTypesMap[incidentDurationMetric.name] = metricType;
|
|
1518
1551
|
}
|
|
1519
1552
|
|
|
1520
1553
|
await MetricService.createMany({
|
|
@@ -1532,6 +1565,13 @@ ${incidentSeverity.name}
|
|
|
1532
1565
|
}).catch((err: Error) => {
|
|
1533
1566
|
logger.error(err);
|
|
1534
1567
|
});
|
|
1568
|
+
|
|
1569
|
+
TelemetryUtil.indexMetricNameServiceNameMap({
|
|
1570
|
+
metricNameServiceNameMap: metricTypesMap,
|
|
1571
|
+
projectId: incident.projectId,
|
|
1572
|
+
}).catch((err: Error) => {
|
|
1573
|
+
logger.error(err);
|
|
1574
|
+
});
|
|
1535
1575
|
}
|
|
1536
1576
|
|
|
1537
1577
|
@CaptureSpan()
|