@oneuptime/common 9.3.8 → 9.3.9
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/AIAgentTask.ts +18 -3
- package/Models/DatabaseModels/Index.ts +0 -5
- package/Models/DatabaseModels/MetricType.ts +7 -7
- package/Models/DatabaseModels/Service.ts +34 -8
- package/Models/DatabaseModels/TelemetryException.ts +11 -13
- package/Models/DatabaseModels/TelemetryUsageBilling.ts +11 -13
- package/Server/API/AIAgentDataAPI.ts +71 -108
- package/Server/Infrastructure/Postgres/SchemaMigrations/1767979055522-MigrationName.ts +743 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1767979448478-MigrationName.ts +224 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts +4 -0
- package/Server/Services/Index.ts +0 -5
- package/Server/Services/OpenTelemetryIngestService.ts +26 -28
- package/Server/Services/ServiceService.ts +23 -0
- package/Server/Services/TelemetryExceptionService.ts +3 -4
- package/Server/Services/TelemetryUsageBillingService.ts +30 -32
- package/Server/Utils/Telemetry/Telemetry.ts +24 -23
- package/Types/AI/AIAgentTaskMetadata.ts +1 -1
- package/UI/Components/LogsViewer/LogsViewer.tsx +20 -23
- package/UI/Components/LogsViewer/components/LogDetailsPanel.tsx +3 -3
- package/UI/Components/LogsViewer/components/LogsTable.tsx +3 -4
- package/build/dist/Models/DatabaseModels/AIAgentTask.js +18 -3
- package/build/dist/Models/DatabaseModels/AIAgentTask.js.map +1 -1
- package/build/dist/Models/DatabaseModels/Index.js +0 -4
- package/build/dist/Models/DatabaseModels/Index.js.map +1 -1
- package/build/dist/Models/DatabaseModels/MetricType.js +8 -8
- package/build/dist/Models/DatabaseModels/MetricType.js.map +1 -1
- package/build/dist/Models/DatabaseModels/Service.js +36 -8
- package/build/dist/Models/DatabaseModels/Service.js.map +1 -1
- package/build/dist/Models/DatabaseModels/TelemetryException.js +14 -14
- package/build/dist/Models/DatabaseModels/TelemetryException.js.map +1 -1
- package/build/dist/Models/DatabaseModels/TelemetryUsageBilling.js +14 -14
- package/build/dist/Models/DatabaseModels/TelemetryUsageBilling.js.map +1 -1
- package/build/dist/Server/API/AIAgentDataAPI.js +47 -76
- package/build/dist/Server/API/AIAgentDataAPI.js.map +1 -1
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1767979055522-MigrationName.js +254 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1767979055522-MigrationName.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1767979448478-MigrationName.js +140 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1767979448478-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/Index.js +0 -4
- package/build/dist/Server/Services/Index.js.map +1 -1
- package/build/dist/Server/Services/OpenTelemetryIngestService.js +7 -7
- package/build/dist/Server/Services/OpenTelemetryIngestService.js.map +1 -1
- package/build/dist/Server/Services/ServiceService.js +23 -0
- package/build/dist/Server/Services/ServiceService.js.map +1 -1
- package/build/dist/Server/Services/TelemetryExceptionService.js +3 -4
- package/build/dist/Server/Services/TelemetryExceptionService.js.map +1 -1
- package/build/dist/Server/Services/TelemetryUsageBillingService.js +15 -16
- package/build/dist/Server/Services/TelemetryUsageBillingService.js.map +1 -1
- package/build/dist/Server/Utils/Telemetry/Telemetry.js +20 -20
- package/build/dist/Server/Utils/Telemetry/Telemetry.js.map +1 -1
- package/build/dist/UI/Components/LogsViewer/LogsViewer.js +5 -5
- package/build/dist/UI/Components/LogsViewer/LogsViewer.js.map +1 -1
- package/build/dist/UI/Components/LogsViewer/components/LogDetailsPanel.js.map +1 -1
- package/build/dist/UI/Components/LogsViewer/components/LogsTable.js.map +1 -1
- package/package.json +1 -1
- package/Models/DatabaseModels/ServiceTelemetryService.ts +0 -419
- package/Models/DatabaseModels/TelemetryService.ts +0 -529
- package/Server/Services/ServiceTelemetryServiceService.ts +0 -59
- package/Server/Services/TelemetryServiceService.ts +0 -53
- package/build/dist/Models/DatabaseModels/ServiceTelemetryService.js +0 -436
- package/build/dist/Models/DatabaseModels/ServiceTelemetryService.js.map +0 -1
- package/build/dist/Models/DatabaseModels/TelemetryService.js +0 -545
- package/build/dist/Models/DatabaseModels/TelemetryService.js.map +0 -1
- package/build/dist/Server/Services/ServiceTelemetryServiceService.js +0 -56
- package/build/dist/Server/Services/ServiceTelemetryServiceService.js.map +0 -1
- package/build/dist/Server/Services/TelemetryServiceService.js +0 -59
- package/build/dist/Server/Services/TelemetryServiceService.js.map +0 -1
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { MigrationInterface, QueryRunner } from "typeorm";
|
|
2
|
+
|
|
3
|
+
// Schema + Data migration: Move TelemetryService to Service table
|
|
4
|
+
export class MigrationName1767979448478 implements MigrationInterface {
|
|
5
|
+
public name = "MigrationName1767979448478";
|
|
6
|
+
|
|
7
|
+
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
8
|
+
// Step 1: Drop old FK constraints (pointing to TelemetryService)
|
|
9
|
+
await queryRunner.query(
|
|
10
|
+
`ALTER TABLE "TelemetryException" DROP CONSTRAINT IF EXISTS "FK_6470c69cb5f53c5899c0483df5f"`,
|
|
11
|
+
);
|
|
12
|
+
await queryRunner.query(
|
|
13
|
+
`ALTER TABLE "TelemetryUsageBilling" DROP CONSTRAINT IF EXISTS "FK_91333210492e5d2f334231468a7"`,
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
// Step 2: Drop old indexes
|
|
17
|
+
await queryRunner.query(
|
|
18
|
+
`DROP INDEX IF EXISTS "public"."IDX_6470c69cb5f53c5899c0483df5"`,
|
|
19
|
+
);
|
|
20
|
+
await queryRunner.query(
|
|
21
|
+
`DROP INDEX IF EXISTS "public"."IDX_91333210492e5d2f334231468a"`,
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
// Step 3: Add retainTelemetryDataForDays column to Service (needed before data migration)
|
|
25
|
+
await queryRunner.query(
|
|
26
|
+
`ALTER TABLE "Service" ADD COLUMN IF NOT EXISTS "retainTelemetryDataForDays" integer DEFAULT '15'`,
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
/*
|
|
30
|
+
* Step 4: Migrate TelemetryService data to Service table (BEFORE renaming columns and adding FK)
|
|
31
|
+
* Preserve the same _id so existing references remain valid
|
|
32
|
+
*/
|
|
33
|
+
const telemetryServiceTableExists: Array<{ exists: boolean }> =
|
|
34
|
+
await queryRunner.query(`
|
|
35
|
+
SELECT EXISTS (
|
|
36
|
+
SELECT FROM information_schema.tables
|
|
37
|
+
WHERE table_schema = 'public'
|
|
38
|
+
AND table_name = 'TelemetryService'
|
|
39
|
+
)
|
|
40
|
+
`);
|
|
41
|
+
|
|
42
|
+
if (telemetryServiceTableExists[0]?.exists) {
|
|
43
|
+
await queryRunner.query(`
|
|
44
|
+
INSERT INTO "Service" (
|
|
45
|
+
"_id",
|
|
46
|
+
"createdAt",
|
|
47
|
+
"updatedAt",
|
|
48
|
+
"deletedAt",
|
|
49
|
+
"version",
|
|
50
|
+
"projectId",
|
|
51
|
+
"name",
|
|
52
|
+
"slug",
|
|
53
|
+
"description",
|
|
54
|
+
"createdByUserId",
|
|
55
|
+
"deletedByUserId",
|
|
56
|
+
"serviceColor",
|
|
57
|
+
"retainTelemetryDataForDays"
|
|
58
|
+
)
|
|
59
|
+
SELECT
|
|
60
|
+
"_id",
|
|
61
|
+
"createdAt",
|
|
62
|
+
"updatedAt",
|
|
63
|
+
"deletedAt",
|
|
64
|
+
"version",
|
|
65
|
+
"projectId",
|
|
66
|
+
"name",
|
|
67
|
+
"slug",
|
|
68
|
+
"description",
|
|
69
|
+
"createdByUserId",
|
|
70
|
+
"deletedByUserId",
|
|
71
|
+
"serviceColor",
|
|
72
|
+
"retainTelemetryDataForDays"
|
|
73
|
+
FROM "TelemetryService"
|
|
74
|
+
ON CONFLICT ("_id") DO NOTHING
|
|
75
|
+
`);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Step 5: Migrate TelemetryServiceLabel to ServiceLabel
|
|
79
|
+
const telemetryServiceLabelExists: Array<{ exists: boolean }> =
|
|
80
|
+
await queryRunner.query(`
|
|
81
|
+
SELECT EXISTS (
|
|
82
|
+
SELECT FROM information_schema.tables
|
|
83
|
+
WHERE table_schema = 'public'
|
|
84
|
+
AND table_name = 'TelemetryServiceLabel'
|
|
85
|
+
)
|
|
86
|
+
`);
|
|
87
|
+
|
|
88
|
+
if (telemetryServiceLabelExists[0]?.exists) {
|
|
89
|
+
await queryRunner.query(`
|
|
90
|
+
INSERT INTO "ServiceLabel" ("serviceId", "labelId")
|
|
91
|
+
SELECT "telemetryServiceId", "labelId"
|
|
92
|
+
FROM "TelemetryServiceLabel"
|
|
93
|
+
ON CONFLICT DO NOTHING
|
|
94
|
+
`);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Step 6: Rename columns (telemetryServiceId -> serviceId)
|
|
98
|
+
await queryRunner.query(
|
|
99
|
+
`ALTER TABLE "TelemetryException" RENAME COLUMN "telemetryServiceId" TO "serviceId"`,
|
|
100
|
+
);
|
|
101
|
+
await queryRunner.query(
|
|
102
|
+
`ALTER TABLE "TelemetryUsageBilling" RENAME COLUMN "telemetryServiceId" TO "serviceId"`,
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
// Step 7: Create MetricTypeService table
|
|
106
|
+
await queryRunner.query(
|
|
107
|
+
`CREATE TABLE IF NOT EXISTS "MetricTypeService" ("metricTypeId" uuid NOT NULL, "serviceId" uuid NOT NULL, CONSTRAINT "PK_21b7a84eea5b71922ac5ccc92e9" PRIMARY KEY ("metricTypeId", "serviceId"))`,
|
|
108
|
+
);
|
|
109
|
+
await queryRunner.query(
|
|
110
|
+
`CREATE INDEX IF NOT EXISTS "IDX_e6b6e365ad502b487cb63d2891" ON "MetricTypeService" ("metricTypeId") `,
|
|
111
|
+
);
|
|
112
|
+
await queryRunner.query(
|
|
113
|
+
`CREATE INDEX IF NOT EXISTS "IDX_c67839207ff53f33eb22648b56" ON "MetricTypeService" ("serviceId") `,
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
// Step 8: Migrate MetricTypeTelemetryService to MetricTypeService
|
|
117
|
+
const metricTypeTelemetryServiceExists: Array<{ exists: boolean }> =
|
|
118
|
+
await queryRunner.query(`
|
|
119
|
+
SELECT EXISTS (
|
|
120
|
+
SELECT FROM information_schema.tables
|
|
121
|
+
WHERE table_schema = 'public'
|
|
122
|
+
AND table_name = 'MetricTypeTelemetryService'
|
|
123
|
+
)
|
|
124
|
+
`);
|
|
125
|
+
|
|
126
|
+
if (metricTypeTelemetryServiceExists[0]?.exists) {
|
|
127
|
+
await queryRunner.query(`
|
|
128
|
+
INSERT INTO "MetricTypeService" ("metricTypeId", "serviceId")
|
|
129
|
+
SELECT "metricTypeId", "telemetryServiceId"
|
|
130
|
+
FROM "MetricTypeTelemetryService"
|
|
131
|
+
ON CONFLICT DO NOTHING
|
|
132
|
+
`);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Step 10: Create new indexes
|
|
136
|
+
await queryRunner.query(
|
|
137
|
+
`CREATE INDEX IF NOT EXISTS "IDX_08a0cfa9f184257b1e57da4cf5" ON "TelemetryException" ("serviceId") `,
|
|
138
|
+
);
|
|
139
|
+
await queryRunner.query(
|
|
140
|
+
`CREATE INDEX IF NOT EXISTS "IDX_b9f49cd8318a35757fc843ee90" ON "TelemetryUsageBilling" ("serviceId") `,
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
// Step 11: Add new FK constraints (NOW safe because Service table has the migrated data)
|
|
144
|
+
await queryRunner.query(
|
|
145
|
+
`ALTER TABLE "TelemetryException" ADD CONSTRAINT "FK_08a0cfa9f184257b1e57da4cf50" FOREIGN KEY ("serviceId") REFERENCES "Service"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`,
|
|
146
|
+
);
|
|
147
|
+
await queryRunner.query(
|
|
148
|
+
`ALTER TABLE "TelemetryUsageBilling" ADD CONSTRAINT "FK_b9f49cd8318a35757fc843ee900" FOREIGN KEY ("serviceId") REFERENCES "Service"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`,
|
|
149
|
+
);
|
|
150
|
+
await queryRunner.query(
|
|
151
|
+
`ALTER TABLE "MetricTypeService" ADD CONSTRAINT "FK_e6b6e365ad502b487cb63d28913" FOREIGN KEY ("metricTypeId") REFERENCES "MetricType"("_id") ON DELETE CASCADE ON UPDATE CASCADE`,
|
|
152
|
+
);
|
|
153
|
+
await queryRunner.query(
|
|
154
|
+
`ALTER TABLE "MetricTypeService" ADD CONSTRAINT "FK_c67839207ff53f33eb22648b567" FOREIGN KEY ("serviceId") REFERENCES "Service"("_id") ON DELETE CASCADE ON UPDATE CASCADE`,
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
159
|
+
// Drop new FK constraints
|
|
160
|
+
await queryRunner.query(
|
|
161
|
+
`ALTER TABLE "MetricTypeService" DROP CONSTRAINT "FK_c67839207ff53f33eb22648b567"`,
|
|
162
|
+
);
|
|
163
|
+
await queryRunner.query(
|
|
164
|
+
`ALTER TABLE "MetricTypeService" DROP CONSTRAINT "FK_e6b6e365ad502b487cb63d28913"`,
|
|
165
|
+
);
|
|
166
|
+
await queryRunner.query(
|
|
167
|
+
`ALTER TABLE "TelemetryUsageBilling" DROP CONSTRAINT "FK_b9f49cd8318a35757fc843ee900"`,
|
|
168
|
+
);
|
|
169
|
+
await queryRunner.query(
|
|
170
|
+
`ALTER TABLE "TelemetryException" DROP CONSTRAINT "FK_08a0cfa9f184257b1e57da4cf50"`,
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
// Drop new indexes
|
|
174
|
+
await queryRunner.query(
|
|
175
|
+
`DROP INDEX "public"."IDX_b9f49cd8318a35757fc843ee90"`,
|
|
176
|
+
);
|
|
177
|
+
await queryRunner.query(
|
|
178
|
+
`DROP INDEX "public"."IDX_08a0cfa9f184257b1e57da4cf5"`,
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
// Drop retainTelemetryDataForDays column
|
|
182
|
+
await queryRunner.query(
|
|
183
|
+
`ALTER TABLE "Service" DROP COLUMN "retainTelemetryDataForDays"`,
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
// Drop MetricTypeService table and indexes
|
|
187
|
+
await queryRunner.query(
|
|
188
|
+
`DROP INDEX "public"."IDX_c67839207ff53f33eb22648b56"`,
|
|
189
|
+
);
|
|
190
|
+
await queryRunner.query(
|
|
191
|
+
`DROP INDEX "public"."IDX_e6b6e365ad502b487cb63d2891"`,
|
|
192
|
+
);
|
|
193
|
+
await queryRunner.query(`DROP TABLE "MetricTypeService"`);
|
|
194
|
+
|
|
195
|
+
// Rename columns back
|
|
196
|
+
await queryRunner.query(
|
|
197
|
+
`ALTER TABLE "TelemetryUsageBilling" RENAME COLUMN "serviceId" TO "telemetryServiceId"`,
|
|
198
|
+
);
|
|
199
|
+
await queryRunner.query(
|
|
200
|
+
`ALTER TABLE "TelemetryException" RENAME COLUMN "serviceId" TO "telemetryServiceId"`,
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
// Recreate old indexes
|
|
204
|
+
await queryRunner.query(
|
|
205
|
+
`CREATE INDEX "IDX_91333210492e5d2f334231468a" ON "TelemetryUsageBilling" ("telemetryServiceId") `,
|
|
206
|
+
);
|
|
207
|
+
await queryRunner.query(
|
|
208
|
+
`CREATE INDEX "IDX_6470c69cb5f53c5899c0483df5" ON "TelemetryException" ("telemetryServiceId") `,
|
|
209
|
+
);
|
|
210
|
+
|
|
211
|
+
// Restore old FK constraints (pointing back to TelemetryService)
|
|
212
|
+
await queryRunner.query(
|
|
213
|
+
`ALTER TABLE "TelemetryUsageBilling" ADD CONSTRAINT "FK_91333210492e5d2f334231468a7" FOREIGN KEY ("telemetryServiceId") REFERENCES "TelemetryService"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`,
|
|
214
|
+
);
|
|
215
|
+
await queryRunner.query(
|
|
216
|
+
`ALTER TABLE "TelemetryException" ADD CONSTRAINT "FK_6470c69cb5f53c5899c0483df5f" FOREIGN KEY ("telemetryServiceId") REFERENCES "TelemetryService"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`,
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
/*
|
|
220
|
+
* Note: We don't delete the migrated data from Service table in down migration
|
|
221
|
+
* as it could be dangerous if new Service records were created
|
|
222
|
+
*/
|
|
223
|
+
}
|
|
224
|
+
}
|
|
@@ -214,6 +214,8 @@ import { MigrationName1766923324521 } from "./1766923324521-MigrationName";
|
|
|
214
214
|
import { AddGitHubAppInstallationIdToProject1766958924188 } from "./1766958924188-AddGitHubAppInstallationIdToProject";
|
|
215
215
|
import { MigrationName1767009661768 } from "./1767009661768-MigrationName";
|
|
216
216
|
import { RenameServiceCatalogToService1767966850199 } from "./1767966850199-RenameServiceCatalogToService";
|
|
217
|
+
import { MigrationName1767979055522 } from "./1767979055522-MigrationName";
|
|
218
|
+
import { MigrationName1767979448478 } from "./1767979448478-MigrationName";
|
|
217
219
|
|
|
218
220
|
export default [
|
|
219
221
|
InitialMigration,
|
|
@@ -432,4 +434,6 @@ export default [
|
|
|
432
434
|
AddGitHubAppInstallationIdToProject1766958924188,
|
|
433
435
|
MigrationName1767009661768,
|
|
434
436
|
RenameServiceCatalogToService1767966850199,
|
|
437
|
+
MigrationName1767979055522,
|
|
438
|
+
MigrationName1767979448478,
|
|
435
439
|
];
|
package/Server/Services/Index.ts
CHANGED
|
@@ -91,7 +91,6 @@ import ServiceOwnerTeamService from "./ServiceOwnerTeamService";
|
|
|
91
91
|
import ServiceOwnerUserService from "./ServiceOwnerUserService";
|
|
92
92
|
import ServiceService from "./ServiceService";
|
|
93
93
|
import ServiceMonitorService from "./ServiceMonitorService";
|
|
94
|
-
import ServiceTelemetryServiceService from "./ServiceTelemetryServiceService";
|
|
95
94
|
import ServiceCodeRepositoryService from "./ServiceCodeRepositoryService";
|
|
96
95
|
import ShortLinkService from "./ShortLinkService";
|
|
97
96
|
// SMS Log Service
|
|
@@ -123,7 +122,6 @@ import TeamPermissionService from "./TeamPermissionService";
|
|
|
123
122
|
import TeamComplianceSettingService from "./TeamComplianceSettingService";
|
|
124
123
|
// Team
|
|
125
124
|
import TeamService from "./TeamService";
|
|
126
|
-
import TelemetryServiceService from "./TelemetryServiceService";
|
|
127
125
|
import UsageBillingService from "./TelemetryUsageBillingService";
|
|
128
126
|
import UserCallService from "./UserCallService";
|
|
129
127
|
import UserEmailService from "./UserEmailService";
|
|
@@ -315,8 +313,6 @@ const services: Array<BaseService> = [
|
|
|
315
313
|
MonitorGroupOwnerUserService,
|
|
316
314
|
MonitorGroupOwnerTeamService,
|
|
317
315
|
|
|
318
|
-
TelemetryServiceService,
|
|
319
|
-
|
|
320
316
|
// On Call Duty Policy Schedule
|
|
321
317
|
OnCallDutyPolicyScheduleService,
|
|
322
318
|
OnCallDutyPolicyScheduleLayerUserService,
|
|
@@ -331,7 +327,6 @@ const services: Array<BaseService> = [
|
|
|
331
327
|
ServiceOwnerUserService,
|
|
332
328
|
ServiceDependencyService,
|
|
333
329
|
ServiceMonitorService,
|
|
334
|
-
ServiceTelemetryServiceService,
|
|
335
330
|
ServiceCodeRepositoryService,
|
|
336
331
|
|
|
337
332
|
TelemetryExceptionService,
|
|
@@ -4,8 +4,8 @@ import ObjectID from "../../Types/ObjectID";
|
|
|
4
4
|
import Metric, {
|
|
5
5
|
AggregationTemporality,
|
|
6
6
|
} from "../../Models/AnalyticsModels/Metric";
|
|
7
|
-
import
|
|
8
|
-
import
|
|
7
|
+
import Service from "../../Models/DatabaseModels/Service";
|
|
8
|
+
import ServiceService from "../../Server/Services/ServiceService";
|
|
9
9
|
import { DEFAULT_RETENTION_IN_DAYS } from "../../Models/DatabaseModels/TelemetryUsageBilling";
|
|
10
10
|
import TelemetryUtil from "../../Server/Utils/Telemetry/Telemetry";
|
|
11
11
|
import CaptureSpan from "../Utils/Telemetry/CaptureSpan";
|
|
@@ -30,37 +30,35 @@ export default class OTelIngestService {
|
|
|
30
30
|
serviceId: ObjectID;
|
|
31
31
|
dataRententionInDays: number;
|
|
32
32
|
}> {
|
|
33
|
-
const service:
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
});
|
|
33
|
+
const service: Service | null = await ServiceService.findOneBy({
|
|
34
|
+
query: {
|
|
35
|
+
projectId: data.projectId,
|
|
36
|
+
name: data.serviceName,
|
|
37
|
+
},
|
|
38
|
+
select: {
|
|
39
|
+
_id: true,
|
|
40
|
+
retainTelemetryDataForDays: true,
|
|
41
|
+
},
|
|
42
|
+
props: {
|
|
43
|
+
isRoot: true,
|
|
44
|
+
},
|
|
45
|
+
});
|
|
47
46
|
|
|
48
47
|
if (!service) {
|
|
49
48
|
// create service
|
|
50
49
|
|
|
51
|
-
const newService:
|
|
50
|
+
const newService: Service = new Service();
|
|
52
51
|
newService.projectId = data.projectId;
|
|
53
52
|
newService.name = data.serviceName;
|
|
54
53
|
newService.description = data.serviceName;
|
|
55
54
|
newService.retainTelemetryDataForDays = DEFAULT_RETENTION_IN_DAYS;
|
|
56
55
|
|
|
57
|
-
const createdService:
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
});
|
|
56
|
+
const createdService: Service = await ServiceService.create({
|
|
57
|
+
data: newService,
|
|
58
|
+
props: {
|
|
59
|
+
isRoot: true,
|
|
60
|
+
},
|
|
61
|
+
});
|
|
64
62
|
|
|
65
63
|
return {
|
|
66
64
|
serviceId: createdService.id!,
|
|
@@ -80,8 +78,8 @@ export default class OTelIngestService {
|
|
|
80
78
|
datapoint: JSONObject;
|
|
81
79
|
aggregationTemporality: OtelAggregationTemporality;
|
|
82
80
|
isMonotonic: boolean | undefined;
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
serviceId: ObjectID;
|
|
82
|
+
serviceName: string;
|
|
85
83
|
}): Metric {
|
|
86
84
|
const { dbMetric, datapoint, aggregationTemporality, isMonotonic } = data;
|
|
87
85
|
|
|
@@ -164,8 +162,8 @@ export default class OTelIngestService {
|
|
|
164
162
|
|
|
165
163
|
newDbMetric.attributes = {
|
|
166
164
|
...TelemetryUtil.getAttributesForServiceIdAndServiceName({
|
|
167
|
-
serviceId: data.
|
|
168
|
-
serviceName: data.
|
|
165
|
+
serviceId: data.serviceId,
|
|
166
|
+
serviceName: data.serviceName,
|
|
169
167
|
}),
|
|
170
168
|
...TelemetryUtil.getAttributes({
|
|
171
169
|
items: (datapoint["attributes"] as JSONArray) || [],
|
|
@@ -3,6 +3,8 @@ import { OnCreate } from "../Types/Database/Hooks";
|
|
|
3
3
|
import DatabaseService from "./DatabaseService";
|
|
4
4
|
import ArrayUtil from "../../Utils/Array";
|
|
5
5
|
import { BrightColors } from "../../Types/BrandColors";
|
|
6
|
+
import BadDataException from "../../Types/Exception/BadDataException";
|
|
7
|
+
import ObjectID from "../../Types/ObjectID";
|
|
6
8
|
import Model from "../../Models/DatabaseModels/Service";
|
|
7
9
|
import CaptureSpan from "../Utils/Telemetry/CaptureSpan";
|
|
8
10
|
|
|
@@ -23,6 +25,27 @@ export class Service extends DatabaseService<Model> {
|
|
|
23
25
|
createBy: createBy,
|
|
24
26
|
};
|
|
25
27
|
}
|
|
28
|
+
|
|
29
|
+
@CaptureSpan()
|
|
30
|
+
public async getTelemetryDataRetentionInDays(
|
|
31
|
+
serviceId: ObjectID,
|
|
32
|
+
): Promise<number> {
|
|
33
|
+
const service: Model | null = await this.findOneById({
|
|
34
|
+
id: serviceId,
|
|
35
|
+
select: {
|
|
36
|
+
retainTelemetryDataForDays: true,
|
|
37
|
+
},
|
|
38
|
+
props: {
|
|
39
|
+
isRoot: true,
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
if (!service) {
|
|
44
|
+
throw new BadDataException("Service not found");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return service.retainTelemetryDataForDays || 15; // default is 15 days.
|
|
48
|
+
}
|
|
26
49
|
}
|
|
27
50
|
|
|
28
51
|
export default new Service();
|
|
@@ -37,7 +37,7 @@ export class Service extends DatabaseService<Model> {
|
|
|
37
37
|
projectId: true,
|
|
38
38
|
message: true,
|
|
39
39
|
stackTrace: true,
|
|
40
|
-
|
|
40
|
+
serviceId: true,
|
|
41
41
|
exceptionType: true,
|
|
42
42
|
},
|
|
43
43
|
props,
|
|
@@ -160,9 +160,8 @@ export class Service extends DatabaseService<Model> {
|
|
|
160
160
|
metadata.errorMessage = telemetryException.message;
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
-
if (telemetryException.
|
|
164
|
-
metadata.
|
|
165
|
-
telemetryException.telemetryServiceId.toString();
|
|
163
|
+
if (telemetryException.serviceId) {
|
|
164
|
+
metadata.serviceId = telemetryException.serviceId.toString();
|
|
166
165
|
}
|
|
167
166
|
|
|
168
167
|
return metadata;
|
|
@@ -11,7 +11,7 @@ import ObjectID from "../../Types/ObjectID";
|
|
|
11
11
|
import Model, {
|
|
12
12
|
DEFAULT_RETENTION_IN_DAYS,
|
|
13
13
|
} from "../../Models/DatabaseModels/TelemetryUsageBilling";
|
|
14
|
-
import
|
|
14
|
+
import ServiceService from "./ServiceService";
|
|
15
15
|
import SpanService from "./SpanService";
|
|
16
16
|
import LogService from "./LogService";
|
|
17
17
|
import MetricService from "./MetricService";
|
|
@@ -20,7 +20,7 @@ import AnalyticsQueryHelper from "../Types/AnalyticsDatabase/QueryHelper";
|
|
|
20
20
|
import DiskSize from "../../Types/DiskSize";
|
|
21
21
|
import logger from "../Utils/Logger";
|
|
22
22
|
import PositiveNumber from "../../Types/PositiveNumber";
|
|
23
|
-
import
|
|
23
|
+
import ServiceModel from "../../Models/DatabaseModels/Service";
|
|
24
24
|
import {
|
|
25
25
|
AverageSpanRowSizeInBytes,
|
|
26
26
|
AverageLogRowSizeInBytes,
|
|
@@ -97,28 +97,27 @@ export class Service extends DatabaseService<Model> {
|
|
|
97
97
|
const startOfDay: Date = OneUptimeDate.getStartOfDay(usageDate);
|
|
98
98
|
const endOfDay: Date = OneUptimeDate.getEndOfDay(usageDate);
|
|
99
99
|
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
});
|
|
100
|
+
const services: Array<ServiceModel> = await ServiceService.findBy({
|
|
101
|
+
query: {
|
|
102
|
+
projectId: data.projectId,
|
|
103
|
+
},
|
|
104
|
+
select: {
|
|
105
|
+
_id: true,
|
|
106
|
+
retainTelemetryDataForDays: true,
|
|
107
|
+
},
|
|
108
|
+
skip: 0,
|
|
109
|
+
limit: LIMIT_MAX,
|
|
110
|
+
props: {
|
|
111
|
+
isRoot: true,
|
|
112
|
+
},
|
|
113
|
+
});
|
|
115
114
|
|
|
116
|
-
if (!
|
|
115
|
+
if (!services || services.length === 0) {
|
|
117
116
|
return;
|
|
118
117
|
}
|
|
119
118
|
|
|
120
|
-
for (const
|
|
121
|
-
if (!
|
|
119
|
+
for (const service of services) {
|
|
120
|
+
if (!service?.id) {
|
|
122
121
|
continue;
|
|
123
122
|
}
|
|
124
123
|
|
|
@@ -126,7 +125,7 @@ export class Service extends DatabaseService<Model> {
|
|
|
126
125
|
query: {
|
|
127
126
|
projectId: data.projectId,
|
|
128
127
|
productType: data.productType,
|
|
129
|
-
|
|
128
|
+
serviceId: service.id,
|
|
130
129
|
day: usageDayString,
|
|
131
130
|
},
|
|
132
131
|
select: {
|
|
@@ -148,7 +147,7 @@ export class Service extends DatabaseService<Model> {
|
|
|
148
147
|
const spanCount: PositiveNumber = await SpanService.countBy({
|
|
149
148
|
query: {
|
|
150
149
|
projectId: data.projectId,
|
|
151
|
-
serviceId:
|
|
150
|
+
serviceId: service.id,
|
|
152
151
|
startTime: AnalyticsQueryHelper.inBetween(startOfDay, endOfDay),
|
|
153
152
|
},
|
|
154
153
|
skip: 0,
|
|
@@ -162,7 +161,7 @@ export class Service extends DatabaseService<Model> {
|
|
|
162
161
|
await ExceptionInstanceService.countBy({
|
|
163
162
|
query: {
|
|
164
163
|
projectId: data.projectId,
|
|
165
|
-
serviceId:
|
|
164
|
+
serviceId: service.id,
|
|
166
165
|
time: AnalyticsQueryHelper.inBetween(startOfDay, endOfDay),
|
|
167
166
|
},
|
|
168
167
|
skip: 0,
|
|
@@ -186,7 +185,7 @@ export class Service extends DatabaseService<Model> {
|
|
|
186
185
|
const count: PositiveNumber = await LogService.countBy({
|
|
187
186
|
query: {
|
|
188
187
|
projectId: data.projectId,
|
|
189
|
-
serviceId:
|
|
188
|
+
serviceId: service.id,
|
|
190
189
|
time: AnalyticsQueryHelper.inBetween(startOfDay, endOfDay),
|
|
191
190
|
},
|
|
192
191
|
skip: 0,
|
|
@@ -207,7 +206,7 @@ export class Service extends DatabaseService<Model> {
|
|
|
207
206
|
const count: PositiveNumber = await MetricService.countBy({
|
|
208
207
|
query: {
|
|
209
208
|
projectId: data.projectId,
|
|
210
|
-
serviceId:
|
|
209
|
+
serviceId: service.id,
|
|
211
210
|
time: AnalyticsQueryHelper.inBetween(startOfDay, endOfDay),
|
|
212
211
|
},
|
|
213
212
|
skip: 0,
|
|
@@ -227,7 +226,7 @@ export class Service extends DatabaseService<Model> {
|
|
|
227
226
|
}
|
|
228
227
|
} catch (error) {
|
|
229
228
|
logger.error(
|
|
230
|
-
`Failed to compute telemetry usage for service ${
|
|
229
|
+
`Failed to compute telemetry usage for service ${service.id?.toString()}:`,
|
|
231
230
|
);
|
|
232
231
|
logger.error(error as Error);
|
|
233
232
|
continue;
|
|
@@ -244,13 +243,12 @@ export class Service extends DatabaseService<Model> {
|
|
|
244
243
|
}
|
|
245
244
|
|
|
246
245
|
const dataRetentionInDays: number =
|
|
247
|
-
|
|
248
|
-
DEFAULT_RETENTION_IN_DAYS;
|
|
246
|
+
service.retainTelemetryDataForDays || DEFAULT_RETENTION_IN_DAYS;
|
|
249
247
|
|
|
250
248
|
await this.updateUsageBilling({
|
|
251
249
|
projectId: data.projectId,
|
|
252
250
|
productType: data.productType,
|
|
253
|
-
|
|
251
|
+
serviceId: service.id,
|
|
254
252
|
dataIngestedInGB: estimatedGigabytes,
|
|
255
253
|
retentionInDays: dataRetentionInDays,
|
|
256
254
|
usageDate: usageDate,
|
|
@@ -262,7 +260,7 @@ export class Service extends DatabaseService<Model> {
|
|
|
262
260
|
public async updateUsageBilling(data: {
|
|
263
261
|
projectId: ObjectID;
|
|
264
262
|
productType: ProductType;
|
|
265
|
-
|
|
263
|
+
serviceId: ObjectID;
|
|
266
264
|
dataIngestedInGB: number;
|
|
267
265
|
retentionInDays: number;
|
|
268
266
|
usageDate?: Date;
|
|
@@ -298,7 +296,7 @@ export class Service extends DatabaseService<Model> {
|
|
|
298
296
|
query: {
|
|
299
297
|
projectId: data.projectId,
|
|
300
298
|
productType: data.productType,
|
|
301
|
-
|
|
299
|
+
serviceId: data.serviceId,
|
|
302
300
|
isReportedToBillingProvider: false,
|
|
303
301
|
day: usageDayString,
|
|
304
302
|
},
|
|
@@ -347,7 +345,7 @@ export class Service extends DatabaseService<Model> {
|
|
|
347
345
|
usageBilling.projectId = data.projectId;
|
|
348
346
|
usageBilling.productType = data.productType;
|
|
349
347
|
usageBilling.dataIngestedInGB = new Decimal(data.dataIngestedInGB);
|
|
350
|
-
usageBilling.
|
|
348
|
+
usageBilling.serviceId = data.serviceId;
|
|
351
349
|
usageBilling.retainTelemetryDataForDays = data.retentionInDays;
|
|
352
350
|
usageBilling.isReportedToBillingProvider = false;
|
|
353
351
|
usageBilling.createdAt = usageDate;
|