@oneuptime/common 7.0.3225 → 7.0.3227
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/Index.ts +0 -2
- package/Models/AnalyticsModels/Metric.ts +39 -1
- package/Server/API/BaseAnalyticsAPI.ts +11 -0
- package/Server/Services/AnalyticsDatabaseService.ts +17 -7
- package/Server/Services/DatabaseService.ts +11 -3
- package/Server/Services/Index.ts +0 -2
- package/Server/Utils/AnalyticsDatabase/StatementGenerator.ts +18 -4
- package/Server/Utils/Monitor/Criteria/EvaluateOverTime.ts +21 -21
- package/Server/Utils/Monitor/MonitorResource.ts +186 -127
- package/Server/Utils/Telemetry/Telemetry.ts +154 -0
- package/Types/BaseDatabase/AggregateBy.ts +2 -0
- package/Types/BaseDatabase/AggregatedModel.ts +3 -0
- package/Types/Metrics/MetricsQuery.ts +8 -0
- package/Types/Monitor/CriteriaFilter.ts +0 -36
- package/Types/Monitor/MonitorMetricType.ts +11 -0
- package/Types/Monitor/MonitorType.ts +18 -0
- package/UI/Components/Charts/ChartGroup/ChartGroup.tsx +1 -1
- package/UI/Components/Charts/ChartLibrary/LineChart/LineChart.tsx +2 -2
- package/UI/Components/Charts/Line/LineChart.tsx +2 -2
- package/Utils/Monitor/MonitorMetricType.ts +142 -0
- package/build/dist/Models/AnalyticsModels/Index.js +0 -2
- package/build/dist/Models/AnalyticsModels/Index.js.map +1 -1
- package/build/dist/Models/AnalyticsModels/Metric.js +36 -1
- package/build/dist/Models/AnalyticsModels/Metric.js.map +1 -1
- package/build/dist/Server/API/BaseAnalyticsAPI.js +7 -0
- package/build/dist/Server/API/BaseAnalyticsAPI.js.map +1 -1
- package/build/dist/Server/Services/AnalyticsDatabaseService.js +7 -0
- package/build/dist/Server/Services/AnalyticsDatabaseService.js.map +1 -1
- package/build/dist/Server/Services/DatabaseService.js +6 -1
- package/build/dist/Server/Services/DatabaseService.js.map +1 -1
- package/build/dist/Server/Services/Index.js +0 -2
- package/build/dist/Server/Services/Index.js.map +1 -1
- package/build/dist/Server/Utils/AnalyticsDatabase/StatementGenerator.js +13 -4
- package/build/dist/Server/Utils/AnalyticsDatabase/StatementGenerator.js.map +1 -1
- package/build/dist/Server/Utils/Monitor/Criteria/EvaluateOverTime.js +9 -8
- package/build/dist/Server/Utils/Monitor/Criteria/EvaluateOverTime.js.map +1 -1
- package/build/dist/Server/Utils/Monitor/MonitorResource.js +164 -98
- package/build/dist/Server/Utils/Monitor/MonitorResource.js.map +1 -1
- package/build/dist/Server/Utils/Telemetry/Telemetry.js +100 -0
- package/build/dist/Server/Utils/Telemetry/Telemetry.js.map +1 -0
- package/build/dist/Types/Monitor/CriteriaFilter.js +0 -29
- package/build/dist/Types/Monitor/CriteriaFilter.js.map +1 -1
- package/build/dist/Types/Monitor/MonitorMetricType.js +12 -0
- package/build/dist/Types/Monitor/MonitorMetricType.js.map +1 -0
- package/build/dist/Types/Monitor/MonitorType.js +14 -0
- package/build/dist/Types/Monitor/MonitorType.js.map +1 -1
- package/build/dist/UI/Components/Charts/ChartGroup/ChartGroup.js +1 -1
- package/build/dist/UI/Components/Charts/ChartLibrary/LineChart/LineChart.js +1 -1
- package/build/dist/UI/Components/Charts/Line/LineChart.js +1 -1
- package/build/dist/Utils/Monitor/MonitorMetricType.js +118 -0
- package/build/dist/Utils/Monitor/MonitorMetricType.js.map +1 -0
- package/package.json +2 -2
- package/Models/AnalyticsModels/MonitorMetricsByMinute.ts +0 -177
- package/Server/Services/MonitorMetricsByMinuteService.ts +0 -14
- package/build/dist/Models/AnalyticsModels/MonitorMetricsByMinute.js +0 -149
- package/build/dist/Models/AnalyticsModels/MonitorMetricsByMinute.js.map +0 -1
- package/build/dist/Server/Services/MonitorMetricsByMinuteService.js +0 -12
- package/build/dist/Server/Services/MonitorMetricsByMinuteService.js.map +0 -1
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import AnalyticsBaseModel from "./AnalyticsBaseModel/AnalyticsBaseModel";
|
|
2
2
|
import Log from "./Log";
|
|
3
3
|
import Metric from "./Metric";
|
|
4
|
-
import MonitorMetricsByMinute from "./MonitorMetricsByMinute";
|
|
5
4
|
import Span from "./Span";
|
|
6
5
|
import TelemetryAttribute from "./TelemetryAttribute";
|
|
7
6
|
import ExceptionInstance from "./ExceptionInstance";
|
|
@@ -10,7 +9,6 @@ const AnalyticsModels: Array<{ new (): AnalyticsBaseModel }> = [
|
|
|
10
9
|
Log,
|
|
11
10
|
Span,
|
|
12
11
|
Metric,
|
|
13
|
-
MonitorMetricsByMinute,
|
|
14
12
|
TelemetryAttribute,
|
|
15
13
|
ExceptionInstance,
|
|
16
14
|
];
|
|
@@ -19,6 +19,11 @@ export enum MetricPointType {
|
|
|
19
19
|
ExponentialHistogram = "ExponentialHistogram",
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
export enum ServiceType {
|
|
23
|
+
OpenTelemetry = "OpenTelemetry",
|
|
24
|
+
Monitor = "Monitor",
|
|
25
|
+
}
|
|
26
|
+
|
|
22
27
|
export default class Metric extends AnalyticsBaseModel {
|
|
23
28
|
public constructor() {
|
|
24
29
|
super({
|
|
@@ -78,10 +83,11 @@ export default class Metric extends AnalyticsBaseModel {
|
|
|
78
83
|
},
|
|
79
84
|
}),
|
|
80
85
|
|
|
86
|
+
// this can also be the monitor id or the telemetry service id.
|
|
81
87
|
new AnalyticsTableColumn({
|
|
82
88
|
key: "serviceId",
|
|
83
89
|
title: "Service ID",
|
|
84
|
-
description: "ID of the Service which created the
|
|
90
|
+
description: "ID of the Service which created the Metric",
|
|
85
91
|
required: true,
|
|
86
92
|
type: TableColumnType.ObjectID,
|
|
87
93
|
accessControl: {
|
|
@@ -101,6 +107,30 @@ export default class Metric extends AnalyticsBaseModel {
|
|
|
101
107
|
},
|
|
102
108
|
}),
|
|
103
109
|
|
|
110
|
+
// this can also be the monitor id or the telemetry service id.
|
|
111
|
+
new AnalyticsTableColumn({
|
|
112
|
+
key: "serviceType",
|
|
113
|
+
title: "Service Type",
|
|
114
|
+
description: "Type of the service that this telemetry belongs to",
|
|
115
|
+
required: false,
|
|
116
|
+
type: TableColumnType.Text,
|
|
117
|
+
accessControl: {
|
|
118
|
+
read: [
|
|
119
|
+
Permission.ProjectOwner,
|
|
120
|
+
Permission.ProjectAdmin,
|
|
121
|
+
Permission.ProjectMember,
|
|
122
|
+
Permission.ReadTelemetryServiceLog,
|
|
123
|
+
],
|
|
124
|
+
create: [
|
|
125
|
+
Permission.ProjectOwner,
|
|
126
|
+
Permission.ProjectAdmin,
|
|
127
|
+
Permission.ProjectMember,
|
|
128
|
+
Permission.CreateTelemetryServiceLog,
|
|
129
|
+
],
|
|
130
|
+
update: [],
|
|
131
|
+
},
|
|
132
|
+
}),
|
|
133
|
+
|
|
104
134
|
// add name and description
|
|
105
135
|
|
|
106
136
|
new AnalyticsTableColumn({
|
|
@@ -539,6 +569,10 @@ export default class Metric extends AnalyticsBaseModel {
|
|
|
539
569
|
return this.getColumnValue("serviceId") as ObjectID | undefined;
|
|
540
570
|
}
|
|
541
571
|
|
|
572
|
+
public get serviceType(): ServiceType | undefined {
|
|
573
|
+
return this.getColumnValue("serviceType") as ServiceType | undefined;
|
|
574
|
+
}
|
|
575
|
+
|
|
542
576
|
public get name(): string | undefined {
|
|
543
577
|
return this.getColumnValue("name") as string | undefined;
|
|
544
578
|
}
|
|
@@ -595,6 +629,10 @@ export default class Metric extends AnalyticsBaseModel {
|
|
|
595
629
|
this.setColumnValue("serviceId", v);
|
|
596
630
|
}
|
|
597
631
|
|
|
632
|
+
public set serviceType(v: ServiceType | undefined) {
|
|
633
|
+
this.setColumnValue("serviceType", v);
|
|
634
|
+
}
|
|
635
|
+
|
|
598
636
|
public get time(): Date | undefined {
|
|
599
637
|
return this.getColumnValue("time") as Date | undefined;
|
|
600
638
|
}
|
|
@@ -291,6 +291,17 @@ export default class BaseAnalyticsAPI<
|
|
|
291
291
|
) as any;
|
|
292
292
|
}
|
|
293
293
|
|
|
294
|
+
let groupBy: GroupBy<AnalyticsDataModel> | null =
|
|
295
|
+
req.body["groupBy"] || null;
|
|
296
|
+
|
|
297
|
+
if (groupBy && Object.keys(groupBy).length > 0) {
|
|
298
|
+
groupBy = JSONFunctions.deserialize(groupBy as JSONObject) as any;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
if (groupBy && Object.keys(groupBy).length === 0) {
|
|
302
|
+
groupBy = null;
|
|
303
|
+
}
|
|
304
|
+
|
|
294
305
|
if (!aggregateBy) {
|
|
295
306
|
throw new BadRequestException("AggregateBy is required");
|
|
296
307
|
}
|
|
@@ -259,6 +259,11 @@ export default class AnalyticsDatabaseService<
|
|
|
259
259
|
|
|
260
260
|
// convert date column from string to date.
|
|
261
261
|
|
|
262
|
+
const groupByColumnName: keyof TBaseModel | undefined =
|
|
263
|
+
aggregateBy.groupBy && Object.keys(aggregateBy.groupBy).length > 0
|
|
264
|
+
? (Object.keys(aggregateBy.groupBy)[0] as keyof TBaseModel)
|
|
265
|
+
: undefined;
|
|
266
|
+
|
|
262
267
|
for (const item of items) {
|
|
263
268
|
if (
|
|
264
269
|
!(item as JSONObject)[
|
|
@@ -277,6 +282,9 @@ export default class AnalyticsDatabaseService<
|
|
|
277
282
|
value: (item as JSONObject)[
|
|
278
283
|
aggregateBy.aggregateColumnName as string
|
|
279
284
|
] as number,
|
|
285
|
+
[groupByColumnName as string]: (item as JSONObject)[
|
|
286
|
+
groupByColumnName as string
|
|
287
|
+
],
|
|
280
288
|
};
|
|
281
289
|
|
|
282
290
|
aggregatedItems.push(aggregatedModel);
|
|
@@ -457,7 +465,7 @@ export default class AnalyticsDatabaseService<
|
|
|
457
465
|
count()
|
|
458
466
|
FROM ${databaseName}.${this.model.tableName}
|
|
459
467
|
WHERE TRUE `.append(whereStatement);
|
|
460
|
-
|
|
468
|
+
|
|
461
469
|
|
|
462
470
|
if (countBy.groupBy && Object.keys(countBy.groupBy).length > 0) {
|
|
463
471
|
statement.append(
|
|
@@ -519,9 +527,11 @@ export default class AnalyticsDatabaseService<
|
|
|
519
527
|
statement.append(SQL` FROM ${databaseName}.${this.model.tableName}`);
|
|
520
528
|
statement.append(SQL` WHERE TRUE `).append(whereStatement);
|
|
521
529
|
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
530
|
+
statement.append(SQL` GROUP BY `).append(`${aggregateBy.aggregationTimestampColumnName.toString()}`);
|
|
531
|
+
|
|
532
|
+
if (aggregateBy.groupBy && Object.keys(aggregateBy.groupBy).length > 0) {
|
|
533
|
+
statement.append(SQL` , `).append(this.statementGenerator.toGroupByStatement(aggregateBy.groupBy));
|
|
534
|
+
}
|
|
525
535
|
|
|
526
536
|
statement.append(SQL` ORDER BY `).append(sortStatement);
|
|
527
537
|
|
|
@@ -538,7 +548,7 @@ export default class AnalyticsDatabaseService<
|
|
|
538
548
|
}}
|
|
539
549
|
`);
|
|
540
550
|
|
|
541
|
-
|
|
551
|
+
|
|
542
552
|
|
|
543
553
|
logger.debug(`${this.model.tableName} Aggregate Statement`);
|
|
544
554
|
logger.debug(statement);
|
|
@@ -604,7 +614,7 @@ export default class AnalyticsDatabaseService<
|
|
|
604
614
|
}}
|
|
605
615
|
`);
|
|
606
616
|
|
|
607
|
-
|
|
617
|
+
|
|
608
618
|
|
|
609
619
|
logger.debug(`${this.model.tableName} Find Statement`);
|
|
610
620
|
logger.debug(statement);
|
|
@@ -626,7 +636,7 @@ export default class AnalyticsDatabaseService<
|
|
|
626
636
|
const statement: Statement = SQL`
|
|
627
637
|
ALTER TABLE ${databaseName}.${this.model.tableName}
|
|
628
638
|
DELETE WHERE TRUE `.append(whereStatement);
|
|
629
|
-
|
|
639
|
+
|
|
630
640
|
|
|
631
641
|
logger.debug(`${this.model.tableName} Delete Statement`);
|
|
632
642
|
logger.debug(statement);
|
|
@@ -437,10 +437,10 @@ class DatabaseService<TBaseModel extends BaseModel> extends BaseService {
|
|
|
437
437
|
const columns: Columns = this.model.getTableColumns();
|
|
438
438
|
|
|
439
439
|
for (const columnName of columns.columns) {
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
this.model.getTableColumnMetadata(columnName);
|
|
440
|
+
const tableColumnMetadata: TableColumnMetadata =
|
|
441
|
+
this.model.getTableColumnMetadata(columnName);
|
|
443
442
|
|
|
443
|
+
if (this.model.isEntityColumn(columnName)) {
|
|
444
444
|
const columnValue: JSONValue = (data as any)[columnName];
|
|
445
445
|
|
|
446
446
|
if (
|
|
@@ -507,6 +507,14 @@ class DatabaseService<TBaseModel extends BaseModel> extends BaseService {
|
|
|
507
507
|
(data as any)[columnName] = columnValue.toString();
|
|
508
508
|
}
|
|
509
509
|
}
|
|
510
|
+
|
|
511
|
+
// if its a Date column and if date is null then set it to null.
|
|
512
|
+
if (
|
|
513
|
+
(data as any)[columnName] === "" &&
|
|
514
|
+
tableColumnMetadata.type === TableColumnType.Date
|
|
515
|
+
) {
|
|
516
|
+
(data as any)[columnName] = null;
|
|
517
|
+
}
|
|
510
518
|
}
|
|
511
519
|
|
|
512
520
|
// check createByUserId.
|
package/Server/Services/Index.ts
CHANGED
|
@@ -41,7 +41,6 @@ import MonitorGroupOwnerTeamService from "./MonitorGroupOwnerTeamService";
|
|
|
41
41
|
import MonitorGroupOwnerUserService from "./MonitorGroupOwnerUserService";
|
|
42
42
|
import MonitorGroupResourceService from "./MonitorGroupResourceService";
|
|
43
43
|
import MonitorGroupService from "./MonitorGroupService";
|
|
44
|
-
import MonitorMetricsByMinuteService from "./MonitorMetricsByMinuteService";
|
|
45
44
|
import MonitorOwnerTeamService from "./MonitorOwnerTeamService";
|
|
46
45
|
import MonitorOwnerUserService from "./MonitorOwnerUserService";
|
|
47
46
|
import MonitorProbeService from "./MonitorProbeService";
|
|
@@ -316,7 +315,6 @@ export const AnalyticsServices: Array<
|
|
|
316
315
|
LogService,
|
|
317
316
|
SpanService,
|
|
318
317
|
MetricService,
|
|
319
|
-
MonitorMetricsByMinuteService,
|
|
320
318
|
TelemetryAttributeService,
|
|
321
319
|
ExceptionInstanceService,
|
|
322
320
|
];
|
|
@@ -548,11 +548,25 @@ export default class StatementGenerator<TBaseModel extends AnalyticsBaseModel> {
|
|
|
548
548
|
`${aggregationMethod}(${aggregateBy.aggregateColumnName.toString()}) as ${aggregateBy.aggregateColumnName.toString()}, date_trunc('${aggregationInterval.toLowerCase()}', toStartOfInterval(${aggregateBy.aggregationTimestampColumnName.toString()}, INTERVAL 1 ${aggregationInterval.toLowerCase()})) as ${aggregateBy.aggregationTimestampColumnName.toString()}`,
|
|
549
549
|
);
|
|
550
550
|
|
|
551
|
+
const columns: Array<string> = [
|
|
552
|
+
aggregateBy.aggregateColumnName.toString(),
|
|
553
|
+
aggregateBy.aggregationTimestampColumnName.toString(),
|
|
554
|
+
];
|
|
555
|
+
|
|
556
|
+
if (aggregateBy.groupBy && Object.keys(aggregateBy.groupBy).length > 0) {
|
|
557
|
+
const groupByStatement: Statement = this.toGroupByStatement(
|
|
558
|
+
aggregateBy.groupBy,
|
|
559
|
+
);
|
|
560
|
+
selectStatement.append(SQL`, `).append(groupByStatement);
|
|
561
|
+
|
|
562
|
+
// add to columns.
|
|
563
|
+
for (const key in aggregateBy.groupBy) {
|
|
564
|
+
columns.push(key);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
|
|
551
568
|
return {
|
|
552
|
-
columns:
|
|
553
|
-
aggregateBy.aggregateColumnName.toString(),
|
|
554
|
-
aggregateBy.aggregationTimestampColumnName.toString(),
|
|
555
|
-
],
|
|
569
|
+
columns: columns,
|
|
556
570
|
statement: selectStatement,
|
|
557
571
|
};
|
|
558
572
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import MonitorMetricsByMinuteService from "../../../Services/MonitorMetricsByMinuteService";
|
|
2
1
|
import Query from "../../../Types/AnalyticsDatabase/Query";
|
|
3
2
|
import GreaterThanOrEqual from "Common/Types/BaseDatabase/GreaterThanOrEqual";
|
|
4
3
|
import { LIMIT_PER_PROJECT } from "Common/Types/Database/LimitMax";
|
|
@@ -10,7 +9,9 @@ import {
|
|
|
10
9
|
EvaluateOverTimeType,
|
|
11
10
|
} from "Common/Types/Monitor/CriteriaFilter";
|
|
12
11
|
import ObjectID from "Common/Types/ObjectID";
|
|
13
|
-
import
|
|
12
|
+
import Metric from "../../../../Models/AnalyticsModels/Metric";
|
|
13
|
+
import MonitorMetricTypeUtil from "../../../../Utils/Monitor/MonitorMetricType";
|
|
14
|
+
import MetricService from "../../../Services/MetricService";
|
|
14
15
|
|
|
15
16
|
export default class EvaluateOverTime {
|
|
16
17
|
public static async getValueOverTime(data: {
|
|
@@ -27,36 +28,35 @@ export default class EvaluateOverTime {
|
|
|
27
28
|
|
|
28
29
|
// TODO: Query over miscData
|
|
29
30
|
|
|
30
|
-
const query: Query<
|
|
31
|
+
const query: Query<Metric> = {
|
|
31
32
|
createdAt: new GreaterThanOrEqual(lastMinutesDate),
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
serviceId: data.monitorId,
|
|
34
|
+
name: MonitorMetricTypeUtil.getMonitorMeticTypeByCheckOn(data.metricType),
|
|
34
35
|
};
|
|
35
36
|
|
|
36
37
|
if (data.miscData) {
|
|
37
|
-
query.
|
|
38
|
+
query.attributes = data.miscData;
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
const monitorMetricsItems: Array<
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
});
|
|
41
|
+
const monitorMetricsItems: Array<Metric> = await MetricService.findBy({
|
|
42
|
+
query: query,
|
|
43
|
+
limit: LIMIT_PER_PROJECT,
|
|
44
|
+
skip: 0,
|
|
45
|
+
props: {
|
|
46
|
+
isRoot: true,
|
|
47
|
+
},
|
|
48
|
+
select: {
|
|
49
|
+
value: true,
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
52
|
|
|
53
53
|
const values: Array<number | boolean> = monitorMetricsItems
|
|
54
|
-
.map((item:
|
|
54
|
+
.map((item: Metric) => {
|
|
55
55
|
if (data.metricType === CheckOn.IsOnline) {
|
|
56
|
-
return item.
|
|
56
|
+
return item.value === 1;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
return item.
|
|
59
|
+
return item.value;
|
|
60
60
|
})
|
|
61
61
|
.filter((value: number | boolean | undefined) => {
|
|
62
62
|
return value !== undefined;
|