@oneuptime/common 7.0.3980 → 7.0.3985
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/DatabaseModels/Index.ts +3 -0
- package/Models/DatabaseModels/Label.ts +1 -0
- package/Models/DatabaseModels/MetricType.ts +339 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1743518485566-MigrationName.ts +67 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1743521461137-MigrationName.ts +23 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts +4 -0
- package/Server/Services/MetricTypeService.ts +10 -0
- package/Server/Services/MonitorStatusTimelineService.ts +0 -4
- package/Server/Utils/Monitor/MonitorResource.ts +20 -0
- package/Server/Utils/Telemetry/Telemetry.ts +94 -0
- package/build/dist/Models/DatabaseModels/Index.js +2 -0
- package/build/dist/Models/DatabaseModels/Index.js.map +1 -1
- package/build/dist/Models/DatabaseModels/Label.js +1 -0
- package/build/dist/Models/DatabaseModels/Label.js.map +1 -1
- package/build/dist/Models/DatabaseModels/MetricType.js +347 -0
- package/build/dist/Models/DatabaseModels/MetricType.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1743518485566-MigrationName.js +30 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1743518485566-MigrationName.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1743521461137-MigrationName.js +14 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1743521461137-MigrationName.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js +4 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js.map +1 -1
- package/build/dist/Server/Services/MetricTypeService.js +9 -0
- package/build/dist/Server/Services/MetricTypeService.js.map +1 -0
- package/build/dist/Server/Services/MonitorStatusTimelineService.js +0 -4
- package/build/dist/Server/Services/MonitorStatusTimelineService.js.map +1 -1
- package/build/dist/Server/Utils/Monitor/MonitorResource.js +17 -0
- package/build/dist/Server/Utils/Monitor/MonitorResource.js.map +1 -1
- package/build/dist/Server/Utils/Telemetry/Telemetry.js +81 -0
- package/build/dist/Server/Utils/Telemetry/Telemetry.js.map +1 -1
- package/package.json +2 -2
|
@@ -168,6 +168,7 @@ import WorkspaceNotificationRule from "./WorkspaceNotificationRule";
|
|
|
168
168
|
import ProjectUser from "./ProjectUser";
|
|
169
169
|
import OnCallDutyPolicyUserOverride from "./OnCallDutyPolicyUserOverride";
|
|
170
170
|
import MonitorFeed from "./MonitorFeed";
|
|
171
|
+
import MetricType from "./MetricType";
|
|
171
172
|
|
|
172
173
|
const AllModelTypes: Array<{
|
|
173
174
|
new (): BaseModel;
|
|
@@ -361,6 +362,8 @@ const AllModelTypes: Array<{
|
|
|
361
362
|
ProjectUser,
|
|
362
363
|
|
|
363
364
|
MonitorFeed,
|
|
365
|
+
|
|
366
|
+
MetricType,
|
|
364
367
|
];
|
|
365
368
|
|
|
366
369
|
const modelTypeMap: { [key: string]: { new (): BaseModel } } = {};
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
import Project from "./Project";
|
|
2
|
+
import User from "./User";
|
|
3
|
+
import Route from "../../Types/API/Route";
|
|
4
|
+
import ColumnAccessControl from "../../Types/Database/AccessControl/ColumnAccessControl";
|
|
5
|
+
import TableAccessControl from "../../Types/Database/AccessControl/TableAccessControl";
|
|
6
|
+
import ColumnLength from "../../Types/Database/ColumnLength";
|
|
7
|
+
import ColumnType from "../../Types/Database/ColumnType";
|
|
8
|
+
import CrudApiEndpoint from "../../Types/Database/CrudApiEndpoint";
|
|
9
|
+
import EnableDocumentation from "../../Types/Database/EnableDocumentation";
|
|
10
|
+
import EnableWorkflow from "../../Types/Database/EnableWorkflow";
|
|
11
|
+
import SlugifyColumn from "../../Types/Database/SlugifyColumn";
|
|
12
|
+
import TableColumn from "../../Types/Database/TableColumn";
|
|
13
|
+
import TableColumnType from "../../Types/Database/TableColumnType";
|
|
14
|
+
import TableMetadata from "../../Types/Database/TableMetadata";
|
|
15
|
+
import TenantColumn from "../../Types/Database/TenantColumn";
|
|
16
|
+
import UniqueColumnBy from "../../Types/Database/UniqueColumnBy";
|
|
17
|
+
import IconProp from "../../Types/Icon/IconProp";
|
|
18
|
+
import ObjectID from "../../Types/ObjectID";
|
|
19
|
+
import Permission from "../../Types/Permission";
|
|
20
|
+
import {
|
|
21
|
+
Column,
|
|
22
|
+
Entity,
|
|
23
|
+
Index,
|
|
24
|
+
JoinColumn,
|
|
25
|
+
JoinTable,
|
|
26
|
+
ManyToMany,
|
|
27
|
+
ManyToOne,
|
|
28
|
+
} from "typeorm";
|
|
29
|
+
import BaseModel from "./DatabaseBaseModel/DatabaseBaseModel";
|
|
30
|
+
import TelemetryService from "./TelemetryService";
|
|
31
|
+
|
|
32
|
+
@EnableDocumentation()
|
|
33
|
+
@TenantColumn("projectId")
|
|
34
|
+
@TableAccessControl({
|
|
35
|
+
create: [
|
|
36
|
+
Permission.ProjectOwner,
|
|
37
|
+
Permission.ProjectAdmin,
|
|
38
|
+
Permission.ProjectMember,
|
|
39
|
+
Permission.CreateTelemetryServiceMetrics,
|
|
40
|
+
],
|
|
41
|
+
read: [
|
|
42
|
+
Permission.ProjectOwner,
|
|
43
|
+
Permission.ProjectAdmin,
|
|
44
|
+
Permission.ProjectMember,
|
|
45
|
+
Permission.ReadTelemetryServiceMetrics,
|
|
46
|
+
],
|
|
47
|
+
delete: [
|
|
48
|
+
Permission.ProjectOwner,
|
|
49
|
+
Permission.ProjectAdmin,
|
|
50
|
+
Permission.DeleteTelemetryServiceMetrics,
|
|
51
|
+
],
|
|
52
|
+
update: [
|
|
53
|
+
Permission.ProjectOwner,
|
|
54
|
+
Permission.ProjectAdmin,
|
|
55
|
+
Permission.ProjectMember,
|
|
56
|
+
Permission.EditTelemetryServiceMetrics,
|
|
57
|
+
],
|
|
58
|
+
})
|
|
59
|
+
@EnableWorkflow({
|
|
60
|
+
create: true,
|
|
61
|
+
delete: true,
|
|
62
|
+
update: true,
|
|
63
|
+
read: true,
|
|
64
|
+
})
|
|
65
|
+
@CrudApiEndpoint(new Route("/metric-type"))
|
|
66
|
+
@SlugifyColumn("name", "slug")
|
|
67
|
+
@TableMetadata({
|
|
68
|
+
tableName: "MetricType",
|
|
69
|
+
singularName: "Metric Type",
|
|
70
|
+
pluralName: "Metric Types",
|
|
71
|
+
icon: IconProp.Graph,
|
|
72
|
+
tableDescription: "List of all the metrics ingested with OpenTelemetry",
|
|
73
|
+
})
|
|
74
|
+
@Entity({
|
|
75
|
+
name: "MetricType",
|
|
76
|
+
})
|
|
77
|
+
export default class MetricType extends BaseModel {
|
|
78
|
+
@ColumnAccessControl({
|
|
79
|
+
create: [
|
|
80
|
+
Permission.ProjectOwner,
|
|
81
|
+
Permission.ProjectAdmin,
|
|
82
|
+
Permission.CreateTelemetryServiceMetrics,
|
|
83
|
+
],
|
|
84
|
+
read: [
|
|
85
|
+
Permission.ProjectOwner,
|
|
86
|
+
Permission.ProjectAdmin,
|
|
87
|
+
Permission.ProjectMember,
|
|
88
|
+
Permission.ReadTelemetryServiceMetrics,
|
|
89
|
+
],
|
|
90
|
+
update: [],
|
|
91
|
+
})
|
|
92
|
+
@TableColumn({
|
|
93
|
+
manyToOneRelationColumn: "projectId",
|
|
94
|
+
type: TableColumnType.Entity,
|
|
95
|
+
modelType: Project,
|
|
96
|
+
title: "Project",
|
|
97
|
+
description: "Relation to Project Resource in which this object belongs",
|
|
98
|
+
})
|
|
99
|
+
@ManyToOne(
|
|
100
|
+
() => {
|
|
101
|
+
return Project;
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
eager: false,
|
|
105
|
+
nullable: true,
|
|
106
|
+
onDelete: "CASCADE",
|
|
107
|
+
orphanedRowAction: "nullify",
|
|
108
|
+
},
|
|
109
|
+
)
|
|
110
|
+
@JoinColumn({ name: "projectId" })
|
|
111
|
+
public project?: Project = undefined;
|
|
112
|
+
|
|
113
|
+
@ColumnAccessControl({
|
|
114
|
+
create: [
|
|
115
|
+
Permission.ProjectOwner,
|
|
116
|
+
Permission.ProjectAdmin,
|
|
117
|
+
Permission.ProjectMember,
|
|
118
|
+
Permission.CreateProjectIncident,
|
|
119
|
+
],
|
|
120
|
+
read: [
|
|
121
|
+
Permission.ProjectOwner,
|
|
122
|
+
Permission.ProjectAdmin,
|
|
123
|
+
Permission.ProjectMember,
|
|
124
|
+
Permission.ReadProjectIncident,
|
|
125
|
+
],
|
|
126
|
+
update: [
|
|
127
|
+
Permission.ProjectOwner,
|
|
128
|
+
Permission.ProjectAdmin,
|
|
129
|
+
Permission.ProjectMember,
|
|
130
|
+
Permission.EditProjectIncident,
|
|
131
|
+
],
|
|
132
|
+
})
|
|
133
|
+
@TableColumn({
|
|
134
|
+
required: false,
|
|
135
|
+
type: TableColumnType.EntityArray,
|
|
136
|
+
modelType: TelemetryService,
|
|
137
|
+
title: "Telemetry Services",
|
|
138
|
+
description: "List of services this metric is related to",
|
|
139
|
+
})
|
|
140
|
+
@ManyToMany(
|
|
141
|
+
() => {
|
|
142
|
+
return TelemetryService;
|
|
143
|
+
},
|
|
144
|
+
{ eager: false },
|
|
145
|
+
)
|
|
146
|
+
@JoinTable({
|
|
147
|
+
name: "MetricTypeTelemetryService",
|
|
148
|
+
inverseJoinColumn: {
|
|
149
|
+
name: "telemetryServiceId",
|
|
150
|
+
referencedColumnName: "_id",
|
|
151
|
+
},
|
|
152
|
+
joinColumn: {
|
|
153
|
+
name: "metricTypeId",
|
|
154
|
+
referencedColumnName: "_id",
|
|
155
|
+
},
|
|
156
|
+
})
|
|
157
|
+
public telemetryServices?: Array<TelemetryService> = undefined;
|
|
158
|
+
|
|
159
|
+
@ColumnAccessControl({
|
|
160
|
+
create: [
|
|
161
|
+
Permission.ProjectOwner,
|
|
162
|
+
Permission.ProjectAdmin,
|
|
163
|
+
Permission.CreateTelemetryServiceMetrics,
|
|
164
|
+
],
|
|
165
|
+
read: [
|
|
166
|
+
Permission.ProjectOwner,
|
|
167
|
+
Permission.ProjectAdmin,
|
|
168
|
+
Permission.ProjectMember,
|
|
169
|
+
Permission.ReadTelemetryServiceMetrics,
|
|
170
|
+
],
|
|
171
|
+
update: [],
|
|
172
|
+
})
|
|
173
|
+
@Index()
|
|
174
|
+
@TableColumn({
|
|
175
|
+
type: TableColumnType.ObjectID,
|
|
176
|
+
required: true,
|
|
177
|
+
canReadOnRelationQuery: true,
|
|
178
|
+
title: "Project ID",
|
|
179
|
+
description: "ID of your OneUptime Project in which this object belongs",
|
|
180
|
+
})
|
|
181
|
+
@Column({
|
|
182
|
+
type: ColumnType.ObjectID,
|
|
183
|
+
nullable: false,
|
|
184
|
+
transformer: ObjectID.getDatabaseTransformer(),
|
|
185
|
+
})
|
|
186
|
+
public projectId?: ObjectID = undefined;
|
|
187
|
+
|
|
188
|
+
@ColumnAccessControl({
|
|
189
|
+
create: [
|
|
190
|
+
Permission.ProjectOwner,
|
|
191
|
+
Permission.ProjectAdmin,
|
|
192
|
+
Permission.CreateTelemetryServiceMetrics,
|
|
193
|
+
],
|
|
194
|
+
read: [
|
|
195
|
+
Permission.ProjectOwner,
|
|
196
|
+
Permission.ProjectAdmin,
|
|
197
|
+
Permission.ProjectMember,
|
|
198
|
+
Permission.ReadTelemetryServiceMetrics,
|
|
199
|
+
],
|
|
200
|
+
update: [
|
|
201
|
+
Permission.ProjectOwner,
|
|
202
|
+
Permission.ProjectAdmin,
|
|
203
|
+
Permission.EditTelemetryServiceMetrics,
|
|
204
|
+
],
|
|
205
|
+
})
|
|
206
|
+
@TableColumn({
|
|
207
|
+
required: true,
|
|
208
|
+
type: TableColumnType.ShortText,
|
|
209
|
+
canReadOnRelationQuery: true,
|
|
210
|
+
title: "Name",
|
|
211
|
+
description: "Any friendly name of this object",
|
|
212
|
+
})
|
|
213
|
+
@Column({
|
|
214
|
+
nullable: false,
|
|
215
|
+
type: ColumnType.ShortText,
|
|
216
|
+
length: ColumnLength.ShortText,
|
|
217
|
+
})
|
|
218
|
+
@UniqueColumnBy("projectId")
|
|
219
|
+
@Index()
|
|
220
|
+
public name?: string = undefined;
|
|
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
|
+
})
|
|
236
|
+
@TableColumn({
|
|
237
|
+
manyToOneRelationColumn: "createdByUserId",
|
|
238
|
+
type: TableColumnType.Entity,
|
|
239
|
+
modelType: User,
|
|
240
|
+
title: "Created by User",
|
|
241
|
+
description:
|
|
242
|
+
"Relation to User who created this object (if this object was created by a User)",
|
|
243
|
+
})
|
|
244
|
+
@ManyToOne(
|
|
245
|
+
() => {
|
|
246
|
+
return User;
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
eager: false,
|
|
250
|
+
nullable: true,
|
|
251
|
+
onDelete: "SET NULL",
|
|
252
|
+
orphanedRowAction: "nullify",
|
|
253
|
+
},
|
|
254
|
+
)
|
|
255
|
+
@JoinColumn({ name: "createdByUserId" })
|
|
256
|
+
public createdByUser?: User = undefined;
|
|
257
|
+
|
|
258
|
+
@ColumnAccessControl({
|
|
259
|
+
create: [
|
|
260
|
+
Permission.ProjectOwner,
|
|
261
|
+
Permission.ProjectAdmin,
|
|
262
|
+
Permission.CreateTelemetryServiceMetrics,
|
|
263
|
+
],
|
|
264
|
+
read: [
|
|
265
|
+
Permission.ProjectOwner,
|
|
266
|
+
Permission.ProjectAdmin,
|
|
267
|
+
Permission.ProjectMember,
|
|
268
|
+
Permission.ReadTelemetryServiceMetrics,
|
|
269
|
+
],
|
|
270
|
+
update: [],
|
|
271
|
+
})
|
|
272
|
+
@TableColumn({
|
|
273
|
+
type: TableColumnType.ObjectID,
|
|
274
|
+
title: "Created by User ID",
|
|
275
|
+
description:
|
|
276
|
+
"User ID who created this object (if this object was created by a User)",
|
|
277
|
+
})
|
|
278
|
+
@Column({
|
|
279
|
+
type: ColumnType.ObjectID,
|
|
280
|
+
nullable: true,
|
|
281
|
+
transformer: ObjectID.getDatabaseTransformer(),
|
|
282
|
+
})
|
|
283
|
+
public createdByUserId?: ObjectID = undefined;
|
|
284
|
+
|
|
285
|
+
@ColumnAccessControl({
|
|
286
|
+
create: [],
|
|
287
|
+
read: [
|
|
288
|
+
Permission.ProjectOwner,
|
|
289
|
+
Permission.ProjectAdmin,
|
|
290
|
+
Permission.ProjectMember,
|
|
291
|
+
Permission.ReadTelemetryServiceMetrics,
|
|
292
|
+
],
|
|
293
|
+
update: [],
|
|
294
|
+
})
|
|
295
|
+
@TableColumn({
|
|
296
|
+
manyToOneRelationColumn: "deletedByUserId",
|
|
297
|
+
type: TableColumnType.Entity,
|
|
298
|
+
title: "Deleted by User",
|
|
299
|
+
description:
|
|
300
|
+
"Relation to User who deleted this object (if this object was deleted by a User)",
|
|
301
|
+
})
|
|
302
|
+
@ManyToOne(
|
|
303
|
+
() => {
|
|
304
|
+
return User;
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
cascade: false,
|
|
308
|
+
eager: false,
|
|
309
|
+
nullable: true,
|
|
310
|
+
onDelete: "SET NULL",
|
|
311
|
+
orphanedRowAction: "nullify",
|
|
312
|
+
},
|
|
313
|
+
)
|
|
314
|
+
@JoinColumn({ name: "deletedByUserId" })
|
|
315
|
+
public deletedByUser?: User = undefined;
|
|
316
|
+
|
|
317
|
+
@ColumnAccessControl({
|
|
318
|
+
create: [],
|
|
319
|
+
read: [
|
|
320
|
+
Permission.ProjectOwner,
|
|
321
|
+
Permission.ProjectAdmin,
|
|
322
|
+
Permission.ProjectMember,
|
|
323
|
+
Permission.ReadTelemetryServiceMetrics,
|
|
324
|
+
],
|
|
325
|
+
update: [],
|
|
326
|
+
})
|
|
327
|
+
@TableColumn({
|
|
328
|
+
type: TableColumnType.ObjectID,
|
|
329
|
+
title: "Deleted by User ID",
|
|
330
|
+
description:
|
|
331
|
+
"User ID who deleted this object (if this object was deleted by a User)",
|
|
332
|
+
})
|
|
333
|
+
@Column({
|
|
334
|
+
type: ColumnType.ObjectID,
|
|
335
|
+
nullable: true,
|
|
336
|
+
transformer: ObjectID.getDatabaseTransformer(),
|
|
337
|
+
})
|
|
338
|
+
public deletedByUserId?: ObjectID = undefined;
|
|
339
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { MigrationInterface, QueryRunner } from "typeorm";
|
|
2
|
+
|
|
3
|
+
export class MigrationName1743518485566 implements MigrationInterface {
|
|
4
|
+
public name = "MigrationName1743518485566";
|
|
5
|
+
|
|
6
|
+
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
7
|
+
await queryRunner.query(
|
|
8
|
+
`CREATE TABLE "MetricType" ("_id" uuid NOT NULL DEFAULT uuid_generate_v4(), "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "deletedAt" TIMESTAMP WITH TIME ZONE, "version" integer NOT NULL, "projectId" uuid NOT NULL, "name" character varying(100) NOT NULL, "createdByUserId" uuid, "deletedByUserId" uuid, CONSTRAINT "PK_3b19440ac8f314d9c775e026af5" PRIMARY KEY ("_id"))`,
|
|
9
|
+
);
|
|
10
|
+
await queryRunner.query(
|
|
11
|
+
`CREATE INDEX "IDX_d25bfc3fab2ebac8e977d88593" ON "MetricType" ("projectId") `,
|
|
12
|
+
);
|
|
13
|
+
await queryRunner.query(
|
|
14
|
+
`CREATE TABLE "MetricTypeTelemetryService" ("metricTypeId" uuid NOT NULL, "telemetryServiceId" uuid NOT NULL, CONSTRAINT "PK_ff3bdfa86c187345b15bf2d94e5" PRIMARY KEY ("metricTypeId", "telemetryServiceId"))`,
|
|
15
|
+
);
|
|
16
|
+
await queryRunner.query(
|
|
17
|
+
`CREATE INDEX "IDX_2e26ea92e9cb5693040fd0a65b" ON "MetricTypeTelemetryService" ("metricTypeId") `,
|
|
18
|
+
);
|
|
19
|
+
await queryRunner.query(
|
|
20
|
+
`CREATE INDEX "IDX_f5ca58781b68c634e61ce25868" ON "MetricTypeTelemetryService" ("telemetryServiceId") `,
|
|
21
|
+
);
|
|
22
|
+
await queryRunner.query(
|
|
23
|
+
`ALTER TABLE "MetricType" ADD CONSTRAINT "FK_d25bfc3fab2ebac8e977d88593a" FOREIGN KEY ("projectId") REFERENCES "Project"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`,
|
|
24
|
+
);
|
|
25
|
+
await queryRunner.query(
|
|
26
|
+
`ALTER TABLE "MetricType" ADD CONSTRAINT "FK_0662070948eed6110c5e108e77f" FOREIGN KEY ("createdByUserId") REFERENCES "User"("_id") ON DELETE SET NULL ON UPDATE NO ACTION`,
|
|
27
|
+
);
|
|
28
|
+
await queryRunner.query(
|
|
29
|
+
`ALTER TABLE "MetricType" ADD CONSTRAINT "FK_154d3b5c6f725d30753ef209666" FOREIGN KEY ("deletedByUserId") REFERENCES "User"("_id") ON DELETE SET NULL ON UPDATE NO ACTION`,
|
|
30
|
+
);
|
|
31
|
+
await queryRunner.query(
|
|
32
|
+
`ALTER TABLE "MetricTypeTelemetryService" ADD CONSTRAINT "FK_2e26ea92e9cb5693040fd0a65bb" FOREIGN KEY ("metricTypeId") REFERENCES "MetricType"("_id") ON DELETE CASCADE ON UPDATE CASCADE`,
|
|
33
|
+
);
|
|
34
|
+
await queryRunner.query(
|
|
35
|
+
`ALTER TABLE "MetricTypeTelemetryService" ADD CONSTRAINT "FK_f5ca58781b68c634e61ce25868b" FOREIGN KEY ("telemetryServiceId") REFERENCES "TelemetryService"("_id") ON DELETE CASCADE ON UPDATE CASCADE`,
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
40
|
+
await queryRunner.query(
|
|
41
|
+
`ALTER TABLE "MetricTypeTelemetryService" DROP CONSTRAINT "FK_f5ca58781b68c634e61ce25868b"`,
|
|
42
|
+
);
|
|
43
|
+
await queryRunner.query(
|
|
44
|
+
`ALTER TABLE "MetricTypeTelemetryService" DROP CONSTRAINT "FK_2e26ea92e9cb5693040fd0a65bb"`,
|
|
45
|
+
);
|
|
46
|
+
await queryRunner.query(
|
|
47
|
+
`ALTER TABLE "MetricType" DROP CONSTRAINT "FK_154d3b5c6f725d30753ef209666"`,
|
|
48
|
+
);
|
|
49
|
+
await queryRunner.query(
|
|
50
|
+
`ALTER TABLE "MetricType" DROP CONSTRAINT "FK_0662070948eed6110c5e108e77f"`,
|
|
51
|
+
);
|
|
52
|
+
await queryRunner.query(
|
|
53
|
+
`ALTER TABLE "MetricType" DROP CONSTRAINT "FK_d25bfc3fab2ebac8e977d88593a"`,
|
|
54
|
+
);
|
|
55
|
+
await queryRunner.query(
|
|
56
|
+
`DROP INDEX "public"."IDX_f5ca58781b68c634e61ce25868"`,
|
|
57
|
+
);
|
|
58
|
+
await queryRunner.query(
|
|
59
|
+
`DROP INDEX "public"."IDX_2e26ea92e9cb5693040fd0a65b"`,
|
|
60
|
+
);
|
|
61
|
+
await queryRunner.query(`DROP TABLE "MetricTypeTelemetryService"`);
|
|
62
|
+
await queryRunner.query(
|
|
63
|
+
`DROP INDEX "public"."IDX_d25bfc3fab2ebac8e977d88593"`,
|
|
64
|
+
);
|
|
65
|
+
await queryRunner.query(`DROP TABLE "MetricType"`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { MigrationInterface, QueryRunner } from "typeorm";
|
|
2
|
+
|
|
3
|
+
export class MigrationName1743521461137 implements MigrationInterface {
|
|
4
|
+
public name = "MigrationName1743521461137";
|
|
5
|
+
|
|
6
|
+
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
7
|
+
await queryRunner.query(
|
|
8
|
+
`CREATE INDEX "IDX_b2dd2b4597d3514ee4209ccd69" ON "Label" ("name") `,
|
|
9
|
+
);
|
|
10
|
+
await queryRunner.query(
|
|
11
|
+
`CREATE INDEX "IDX_2dfba2253270684804431fd3c8" ON "MetricType" ("name") `,
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
16
|
+
await queryRunner.query(
|
|
17
|
+
`ALTER TABLE "OnCallDutyPolicyScheduleLayer" ALTER COLUMN "restrictionTimes" SET DEFAULT '{"_type": "RestrictionTimes", "value": {"restictionType": "None", "dayRestrictionTimes": null, "weeklyRestrictionTimes": []}}'`,
|
|
18
|
+
);
|
|
19
|
+
await queryRunner.query(
|
|
20
|
+
`ALTER TABLE "OnCallDutyPolicyScheduleLayer" ALTER COLUMN "rotation" SET DEFAULT '{"_type": "Recurring", "value": {"intervalType": "Day", "intervalCount": {"_type": "PositiveNumber", "value": 1}}}'`,
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -123,6 +123,8 @@ import { MigrationName1742305668133 } from "./1742305668133-MigrationName";
|
|
|
123
123
|
import { MigrationName1743005293206 } from "./1743005293206-MigrationName";
|
|
124
124
|
import { MigrationName1743006662678 } from "./1743006662678-MigrationName";
|
|
125
125
|
import { MigrationName1743186793413 } from "./1743186793413-MigrationName";
|
|
126
|
+
import { MigrationName1743518485566 } from "./1743518485566-MigrationName";
|
|
127
|
+
import { MigrationName1743521461137 } from "./1743521461137-MigrationName";
|
|
126
128
|
|
|
127
129
|
export default [
|
|
128
130
|
InitialMigration,
|
|
@@ -250,4 +252,6 @@ export default [
|
|
|
250
252
|
MigrationName1743005293206,
|
|
251
253
|
MigrationName1743006662678,
|
|
252
254
|
MigrationName1743186793413,
|
|
255
|
+
MigrationName1743518485566,
|
|
256
|
+
MigrationName1743521461137,
|
|
253
257
|
];
|
|
@@ -14,7 +14,6 @@ import BadDataException from "../../Types/Exception/BadDataException";
|
|
|
14
14
|
import ObjectID from "../../Types/ObjectID";
|
|
15
15
|
import PositiveNumber from "../../Types/PositiveNumber";
|
|
16
16
|
import MonitorStatusTimeline from "Common/Models/DatabaseModels/MonitorStatusTimeline";
|
|
17
|
-
import { IsBillingEnabled } from "../EnvironmentConfig";
|
|
18
17
|
import MonitorFeedService from "./MonitorFeedService";
|
|
19
18
|
import { MonitorFeedEventType } from "../../Models/DatabaseModels/MonitorFeed";
|
|
20
19
|
import MonitorStatus from "../../Models/DatabaseModels/MonitorStatus";
|
|
@@ -23,9 +22,6 @@ import MonitorStatusService from "./MonitorStatusService";
|
|
|
23
22
|
export class Service extends DatabaseService<MonitorStatusTimeline> {
|
|
24
23
|
public constructor() {
|
|
25
24
|
super(MonitorStatusTimeline);
|
|
26
|
-
if (IsBillingEnabled) {
|
|
27
|
-
this.hardDeleteItemsOlderThanInDays("startsAt", 120);
|
|
28
|
-
}
|
|
29
25
|
}
|
|
30
26
|
|
|
31
27
|
@CaptureSpan()
|
|
@@ -963,6 +963,26 @@ export default class MonitorResourceUtil {
|
|
|
963
963
|
},
|
|
964
964
|
});
|
|
965
965
|
|
|
966
|
+
// Metric name to serviceId map
|
|
967
|
+
// example: "cpu.usage" -> [serviceId1, serviceId2]
|
|
968
|
+
// since these are monitor metrics. They dont belong to any service so we can keep the array empty.
|
|
969
|
+
const metricNameServiceNameMap: Dictionary<Array<ObjectID>> = {};
|
|
970
|
+
|
|
971
|
+
for (const metric of itemsToSave) {
|
|
972
|
+
const metricName: string = metric.name!;
|
|
973
|
+
if (!metricNameServiceNameMap[metricName]) {
|
|
974
|
+
metricNameServiceNameMap[metricName] = [];
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
// index metrics
|
|
979
|
+
TelemetryUtil.indexMetricNameServiceNameMap({
|
|
980
|
+
projectId: data.projectId,
|
|
981
|
+
metricNameServiceNameMap: metricNameServiceNameMap,
|
|
982
|
+
}).catch((err: Error) => {
|
|
983
|
+
logger.error(err);
|
|
984
|
+
});
|
|
985
|
+
|
|
966
986
|
// index attributes.
|
|
967
987
|
TelemetryUtil.indexAttributes({
|
|
968
988
|
attributes: [
|
|
@@ -6,10 +6,104 @@ import GlobalCache from "../../Infrastructure/GlobalCache";
|
|
|
6
6
|
import TelemetryAttributeService from "../../Services/TelemetryAttributeService";
|
|
7
7
|
import CaptureSpan from "./CaptureSpan";
|
|
8
8
|
import logger from "../Logger";
|
|
9
|
+
import MetricType from "../../../Models/DatabaseModels/MetricType";
|
|
10
|
+
import MetricTypeService from "../../Services/MetricTypeService";
|
|
11
|
+
import TelemetryService from "../../../Models/DatabaseModels/TelemetryService";
|
|
9
12
|
|
|
10
13
|
export type AttributeType = string | number | boolean | null;
|
|
11
14
|
|
|
12
15
|
export default class TelemetryUtil {
|
|
16
|
+
@CaptureSpan()
|
|
17
|
+
public static async indexMetricNameServiceNameMap(data: {
|
|
18
|
+
projectId: ObjectID;
|
|
19
|
+
metricNameServiceNameMap: Dictionary<Array<ObjectID>>;
|
|
20
|
+
}): Promise<void> {
|
|
21
|
+
for (const metricName of Object.keys(data.metricNameServiceNameMap)) {
|
|
22
|
+
// fetch metric
|
|
23
|
+
const metricType: MetricType | null = await MetricTypeService.findOneBy({
|
|
24
|
+
query: {
|
|
25
|
+
projectId: data.projectId,
|
|
26
|
+
name: metricName,
|
|
27
|
+
},
|
|
28
|
+
select: {
|
|
29
|
+
telemetryServices: true,
|
|
30
|
+
},
|
|
31
|
+
props: {
|
|
32
|
+
isRoot: true,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
if (metricType) {
|
|
37
|
+
if (!metricType.telemetryServices) {
|
|
38
|
+
metricType.telemetryServices = [];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const telemetryServiceIds: Array<ObjectID> =
|
|
42
|
+
metricType.telemetryServices!.map((service: TelemetryService) => {
|
|
43
|
+
return service.id!;
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// check if telemetry services are same as the ones in the map
|
|
47
|
+
const telemetryServicesInMap: Array<ObjectID> =
|
|
48
|
+
data.metricNameServiceNameMap[metricName] || [];
|
|
49
|
+
|
|
50
|
+
let isSame: boolean = true;
|
|
51
|
+
|
|
52
|
+
for (const telemetryServiceId of telemetryServicesInMap) {
|
|
53
|
+
if (
|
|
54
|
+
telemetryServiceIds.filter((serviceId: ObjectID) => {
|
|
55
|
+
return serviceId.toString() === telemetryServiceId.toString();
|
|
56
|
+
}).length === 0
|
|
57
|
+
) {
|
|
58
|
+
isSame = false;
|
|
59
|
+
// add the service id to the list
|
|
60
|
+
const telemetryService: TelemetryService = new TelemetryService();
|
|
61
|
+
telemetryService.id = telemetryServiceId;
|
|
62
|
+
metricType.telemetryServices!.push(telemetryService);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// if its not the same then update the metric type
|
|
67
|
+
|
|
68
|
+
if (!isSame) {
|
|
69
|
+
// update metric type
|
|
70
|
+
await MetricTypeService.updateOneById({
|
|
71
|
+
id: metricType.id!,
|
|
72
|
+
data: {
|
|
73
|
+
telemetryServices: metricType.telemetryServices || [],
|
|
74
|
+
},
|
|
75
|
+
props: {
|
|
76
|
+
isRoot: true,
|
|
77
|
+
},
|
|
78
|
+
} as any);
|
|
79
|
+
}
|
|
80
|
+
} else {
|
|
81
|
+
// create metric type
|
|
82
|
+
const metricType: MetricType = new MetricType();
|
|
83
|
+
metricType.name = metricName;
|
|
84
|
+
metricType.projectId = data.projectId;
|
|
85
|
+
metricType.telemetryServices = [];
|
|
86
|
+
|
|
87
|
+
const telemetryServiceIds: Array<ObjectID> =
|
|
88
|
+
data.metricNameServiceNameMap[metricName] || [];
|
|
89
|
+
|
|
90
|
+
for (const telemetryServiceId of telemetryServiceIds) {
|
|
91
|
+
const telemetryService: TelemetryService = new TelemetryService();
|
|
92
|
+
telemetryService.id = telemetryServiceId;
|
|
93
|
+
metricType.telemetryServices!.push(telemetryService);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// save metric type
|
|
97
|
+
await MetricTypeService.create({
|
|
98
|
+
data: metricType,
|
|
99
|
+
props: {
|
|
100
|
+
isRoot: true,
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
13
107
|
@CaptureSpan()
|
|
14
108
|
public static async indexAttributes(data: {
|
|
15
109
|
attributes: Array<string>;
|
|
@@ -159,6 +159,7 @@ import WorkspaceNotificationRule from "./WorkspaceNotificationRule";
|
|
|
159
159
|
import ProjectUser from "./ProjectUser";
|
|
160
160
|
import OnCallDutyPolicyUserOverride from "./OnCallDutyPolicyUserOverride";
|
|
161
161
|
import MonitorFeed from "./MonitorFeed";
|
|
162
|
+
import MetricType from "./MetricType";
|
|
162
163
|
const AllModelTypes = [
|
|
163
164
|
User,
|
|
164
165
|
WorkspaceUserAuthToken,
|
|
@@ -303,6 +304,7 @@ const AllModelTypes = [
|
|
|
303
304
|
WorkspaceNotificationRule,
|
|
304
305
|
ProjectUser,
|
|
305
306
|
MonitorFeed,
|
|
307
|
+
MetricType,
|
|
306
308
|
];
|
|
307
309
|
const modelTypeMap = {};
|
|
308
310
|
export const getModelTypeByName = (tableName) => {
|