mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-01-16 23:00:51 +00:00
Update launch.json and ObjectID.ts, add debugger statement, modify BillingService.test.ts, Statement.ts, and NavBar.tsx, and update OTelIngest.ts
This commit is contained in:
parent
937679d544
commit
224eff0d3d
9 changed files with 63 additions and 55 deletions
42
.vscode/launch.json
vendored
42
.vscode/launch.json
vendored
|
|
@ -181,48 +181,6 @@
|
|||
"restart": true,
|
||||
"autoAttachChildProcesses": true
|
||||
},
|
||||
{
|
||||
"address": "127.0.0.1",
|
||||
"localRoot": "${workspaceFolder}/Alert",
|
||||
"name": "Alert: Debug with Docker",
|
||||
"port": 9133,
|
||||
"remoteRoot": "/usr/src/app",
|
||||
"request": "attach",
|
||||
"skipFiles": [
|
||||
"<node_internals>/**"
|
||||
],
|
||||
"type": "node",
|
||||
"restart": true,
|
||||
"autoAttachChildProcesses": true
|
||||
},
|
||||
{
|
||||
"address": "127.0.0.1",
|
||||
"localRoot": "${workspaceFolder}/Alert",
|
||||
"name": "Integration: Debug with Docker",
|
||||
"port": 9134,
|
||||
"remoteRoot": "/usr/src/app",
|
||||
"request": "attach",
|
||||
"skipFiles": [
|
||||
"<node_internals>/**"
|
||||
],
|
||||
"type": "node",
|
||||
"restart": true,
|
||||
"autoAttachChildProcesses": true
|
||||
},
|
||||
{
|
||||
"address": "127.0.0.1",
|
||||
"localRoot": "${workspaceFolder}/licensing",
|
||||
"name": "Licensing: Debug with Docker",
|
||||
"port": 9233,
|
||||
"remoteRoot": "/usr/src/app",
|
||||
"request": "attach",
|
||||
"skipFiles": [
|
||||
"<node_internals>/**"
|
||||
],
|
||||
"type": "node",
|
||||
"restart": true,
|
||||
"autoAttachChildProcesses": true
|
||||
},
|
||||
{
|
||||
"address": "127.0.0.1",
|
||||
"localRoot": "${workspaceFolder}/HttpTestServer",
|
||||
|
|
|
|||
13
Common/Types/DiskSize.ts
Normal file
13
Common/Types/DiskSize.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
export default class DiskSize {
|
||||
public static byteSizeToGB(byteSize: number): number {
|
||||
return byteSize / 1024 / 1024 / 1024;
|
||||
}
|
||||
|
||||
public static byteSizeToMB(byteSize: number): number {
|
||||
return byteSize / 1024 / 1024;
|
||||
}
|
||||
|
||||
public static byteSizeToKB(byteSize: number): number {
|
||||
return byteSize / 1024;
|
||||
}
|
||||
}
|
||||
|
|
@ -23,6 +23,10 @@ export default class ObjectID extends DatabaseProperty {
|
|||
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public get value() : string {
|
||||
return this._id.toString();
|
||||
}
|
||||
|
||||
public equals(other: ObjectID): boolean {
|
||||
return this.id.toString() === other.id.toString();
|
||||
|
|
|
|||
|
|
@ -85,6 +85,7 @@ export default class BaseAnalyticsAPI<
|
|||
next: NextFunction
|
||||
) => {
|
||||
try {
|
||||
debugger;
|
||||
await this.getList(req, res);
|
||||
} catch (err) {
|
||||
next(err);
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ import {
|
|||
Subscription,
|
||||
} from '../TestingUtils/Services/Types';
|
||||
import { ActiveMonitoringMeteredPlan } from '../../Types/Billing/MeteredPlan/AllMeteredPlans';
|
||||
import Database from '../TestingUtils/Database';
|
||||
|
||||
describe('BillingService', () => {
|
||||
let billingService: BillingService;
|
||||
|
|
@ -43,22 +42,14 @@ describe('BillingService', () => {
|
|||
customer.id.toString()
|
||||
);
|
||||
|
||||
let database!: Database;
|
||||
|
||||
beforeEach(
|
||||
async () => {
|
||||
jest.clearAllMocks();
|
||||
billingService = mockIsBillingEnabled(true);
|
||||
database = new Database();
|
||||
await database.createAndConnect();
|
||||
},
|
||||
10 * 1000 // 10 second timeout because setting up the DB is slow
|
||||
);
|
||||
|
||||
afterEach(async () => {
|
||||
await database.disconnectAndDropDatabase();
|
||||
});
|
||||
|
||||
describe('Customer Management', () => {
|
||||
describe('createCustomer', () => {
|
||||
it('should create a customer when valid data is provided', async () => {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { BaseQueryParams } from '@clickhouse/client';
|
|||
import { integer } from '@elastic/elasticsearch/lib/api/types';
|
||||
import { RecordValue } from 'Common/AnalyticsModels/CommonModel';
|
||||
import TableColumnType from 'Common/Types/AnalyticsDatabase/TableColumnType';
|
||||
import ObjectID from 'Common/Types/ObjectID';
|
||||
import { inspect } from 'util';
|
||||
|
||||
/**
|
||||
|
|
@ -17,7 +18,7 @@ export class Statement implements BaseQueryParams {
|
|||
public constructor(
|
||||
private strings: string[] = [''],
|
||||
private values: Array<StatementParameter | string> = []
|
||||
) {}
|
||||
) { }
|
||||
|
||||
public get query(): string {
|
||||
let query: string = this.strings.reduce(
|
||||
|
|
@ -46,9 +47,22 @@ export class Statement implements BaseQueryParams {
|
|||
}
|
||||
|
||||
public get query_params(): Record<string, unknown> {
|
||||
|
||||
debugger;
|
||||
|
||||
return Object.fromEntries(
|
||||
this.values.map((v: StatementParameter | string, i: integer) => {
|
||||
return [`p${i}`, typeof v === 'string' ? v : v.value];
|
||||
let finalValue: any = v;
|
||||
|
||||
if (typeof v === 'string') {
|
||||
finalValue = v;
|
||||
} else if (v.value instanceof ObjectID) {
|
||||
finalValue = v.value.toString();
|
||||
} else {
|
||||
finalValue = v.value;
|
||||
}
|
||||
|
||||
return [`p${i}`, finalValue];
|
||||
})
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ const DashboardNavbar: FunctionComponent<ComponentProps> = (
|
|||
),
|
||||
}}
|
||||
>
|
||||
{/* <NavBarMenuItem
|
||||
<NavBarMenuItem
|
||||
title="Telemetry"
|
||||
description="Logs, Traces, Metrics and more."
|
||||
route={RouteUtil.populateRouteParams(
|
||||
|
|
@ -144,7 +144,7 @@ const DashboardNavbar: FunctionComponent<ComponentProps> = (
|
|||
onClick={() => {
|
||||
forceHideMoreMenu();
|
||||
}}
|
||||
/> */}
|
||||
/>
|
||||
|
||||
<NavBarMenuItem
|
||||
title="On-Call Duty"
|
||||
|
|
|
|||
|
|
@ -33,3 +33,4 @@
|
|||
2.0
|
||||
2.0
|
||||
2.0
|
||||
2.0
|
||||
|
|
|
|||
|
|
@ -25,6 +25,9 @@ import OTelIngestService from '../Service/OTelIngest';
|
|||
import GlobalCache from 'CommonServer/Infrastructure/GlobalCache';
|
||||
import TelemetryServiceService from 'CommonServer/Services/TelemetryServiceService';
|
||||
import TelemetryService from 'Model/Models/TelemetryService';
|
||||
import DiskSize from 'Common/Types/DiskSize';
|
||||
import UsageBillingService from 'CommonServer/Services/UsageBillingService';
|
||||
import { ProductType } from 'Model/Models/UsageBilling';
|
||||
|
||||
// Load proto file for OTel
|
||||
|
||||
|
|
@ -60,12 +63,26 @@ router.use(
|
|||
'/otel/*',
|
||||
async (req: ExpressRequest, _res: ExpressResponse, next: NextFunction) => {
|
||||
try {
|
||||
|
||||
|
||||
// size of req.body in bytes.
|
||||
const sizeInBytes: number = Buffer.byteLength(
|
||||
JSON.stringify(req.body)
|
||||
);
|
||||
|
||||
let productType: ProductType;
|
||||
|
||||
const sizeToGb: number = DiskSize.byteSizeToGB(sizeInBytes);
|
||||
|
||||
if (req.baseUrl === '/otel/v1/traces') {
|
||||
req.body = TracesData.decode(req.body);
|
||||
productType = ProductType.Traces;
|
||||
} else if (req.baseUrl === '/otel/v1/logs') {
|
||||
req.body = LogsData.decode(req.body);
|
||||
productType = ProductType.Logs;
|
||||
} else if (req.baseUrl === '/otel/v1/metrics') {
|
||||
req.body = MetricsData.decode(req.body);
|
||||
productType = ProductType.Metrics;
|
||||
} else {
|
||||
throw new BadRequestException('Invalid URL: ' + req.baseUrl);
|
||||
}
|
||||
|
|
@ -137,6 +154,15 @@ router.use(
|
|||
|
||||
// report to Usage Service.
|
||||
|
||||
UsageBillingService.updateUsageBilling({
|
||||
projectId: (req as OtelRequest).projectId,
|
||||
productType: productType,
|
||||
usageCount: sizeToGb,
|
||||
}).catch((err: Error) => {
|
||||
logger.error("Failed to update usage billing for OTel");
|
||||
logger.error(err);
|
||||
});
|
||||
|
||||
next();
|
||||
} catch (err) {
|
||||
return next(err);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue