oneuptime/Common/Models/DatabaseModels/TelemetryUsageBilling.ts
Nawaz Dhandala e7089e9e85
Refactor TelemetryService to Service across the application
- Replaced all instances of TelemetryService with Service in components, pages, and utilities.
- Updated related imports and state management to reflect the new Service model.
- Removed the TelemetryServices view and associated routes, as it is no longer needed.
- Adjusted breadcrumb and route mappings to remove references to Telemetry Services.
- Ensured that all relevant functionality, such as logs and metrics, now utilize the Service model.
2026-01-09 15:49:52 +00:00

434 lines
11 KiB
TypeScript

import Project from "./Project";
import Service from "./Service";
import User from "./User";
import BaseModel from "./DatabaseBaseModel/DatabaseBaseModel";
import Route from "../../Types/API/Route";
import ColumnAccessControl from "../../Types/Database/AccessControl/ColumnAccessControl";
import TableAccessControl from "../../Types/Database/AccessControl/TableAccessControl";
import ColumnLength from "../../Types/Database/ColumnLength";
import ColumnType from "../../Types/Database/ColumnType";
import CrudApiEndpoint from "../../Types/Database/CrudApiEndpoint";
import TableColumn from "../../Types/Database/TableColumn";
import TableColumnType from "../../Types/Database/TableColumnType";
import TableMetadata from "../../Types/Database/TableMetadata";
import TenantColumn from "../../Types/Database/TenantColumn";
import Decimal from "../../Types/Decimal";
import IconProp from "../../Types/Icon/IconProp";
import ProductType from "../../Types/MeteredPlan/ProductType";
import ObjectID from "../../Types/ObjectID";
import Permission from "../../Types/Permission";
import { Column, Entity, Index, JoinColumn, ManyToOne } from "typeorm";
export const DEFAULT_RETENTION_IN_DAYS: number = 15;
@TenantColumn("projectId")
@TableAccessControl({
create: [],
read: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ManageProjectBilling,
],
delete: [],
update: [],
})
@CrudApiEndpoint(new Route("/telemetry-usage-billing"))
@TableMetadata({
tableName: "TelemetryUsageBilling",
singularName: "Telemetry Usage Billing",
pluralName: "Telemetry Usage Billings",
icon: IconProp.Billing,
tableDescription:
"Stores historical usage billing data for your telemetry data like Logs, Metrics, Traces, and Exceptions.",
})
@Entity({
name: "TelemetryUsageBilling",
})
export default class TelemetryUsageBilling extends BaseModel {
@ColumnAccessControl({
create: [],
read: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ManageProjectBilling,
],
update: [],
})
@TableColumn({
manyToOneRelationColumn: "projectId",
type: TableColumnType.Entity,
modelType: Project,
title: "Project",
description: "Relation to Project Resource in which this object belongs",
example: "5f8b9c0d-e1a2-4b3c-8d5e-6f7a8b9c0d1e",
})
@ManyToOne(
() => {
return Project;
},
{
eager: false,
nullable: true,
onDelete: "CASCADE",
orphanedRowAction: "nullify",
},
)
@JoinColumn({ name: "projectId" })
public project?: Project = undefined;
@ColumnAccessControl({
create: [],
read: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ManageProjectBilling,
],
update: [],
})
@Index()
@TableColumn({
type: TableColumnType.ObjectID,
required: true,
canReadOnRelationQuery: true,
title: "Project ID",
description: "ID of your OneUptime Project in which this object belongs",
example: "5f8b9c0d-e1a2-4b3c-8d5e-6f7a8b9c0d1e",
})
@Column({
type: ColumnType.ObjectID,
nullable: false,
transformer: ObjectID.getDatabaseTransformer(),
})
public projectId?: ObjectID = undefined;
@ColumnAccessControl({
create: [],
read: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ManageProjectBilling,
],
update: [],
})
@TableColumn({
required: true,
type: TableColumnType.ShortText,
canReadOnRelationQuery: true,
title: "Day",
description: "Day of the month this usage billing was generated for",
example: "12-12-2025",
})
@Column({
nullable: false,
type: ColumnType.ShortText,
length: ColumnLength.ShortText,
})
public day?: string = undefined; // this is of format DD-MM-YYYY
@ColumnAccessControl({
create: [],
read: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ManageProjectBilling,
],
update: [],
})
@TableColumn({
required: true,
type: TableColumnType.ShortText,
canReadOnRelationQuery: true,
title: "Product Type",
description: "Product Type this usage billing was generated for",
example: "Logs",
})
@Column({
nullable: false,
type: ColumnType.ShortText,
length: ColumnLength.ShortText,
})
public productType?: ProductType = undefined;
@ColumnAccessControl({
create: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ManageProjectBilling,
],
read: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ManageProjectBilling,
],
update: [],
})
@TableColumn({
type: TableColumnType.Number,
title: "Retain Telemetry Data For Days",
description: "Number of days to retain telemetry data for this service.",
defaultValue: DEFAULT_RETENTION_IN_DAYS,
example: 30,
})
@Column({
type: ColumnType.Number,
nullable: true,
unique: false,
default: DEFAULT_RETENTION_IN_DAYS,
})
public retainTelemetryDataForDays?: number = undefined;
@ColumnAccessControl({
create: [],
read: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ManageProjectBilling,
],
update: [],
})
@TableColumn({
required: true,
type: TableColumnType.Number,
canReadOnRelationQuery: true,
title: "Data Ingested (in GB)",
description: "Data Ingested in GB this usage billing was generated for",
example: 125.5,
})
@Column({
nullable: false,
type: ColumnType.Decimal,
transformer: Decimal.getDatabaseTransformer(),
})
public dataIngestedInGB?: Decimal = undefined;
@ColumnAccessControl({
create: [],
read: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ManageProjectBilling,
],
update: [],
})
@TableColumn({
required: true,
type: TableColumnType.Number,
canReadOnRelationQuery: true,
title: "Total Cost in USD",
description: "Total Cost in USD this usage billing was generated for",
example: 45.99,
})
@Column({
nullable: false,
type: ColumnType.Decimal,
transformer: Decimal.getDatabaseTransformer(),
})
public totalCostInUSD?: Decimal = undefined;
@ColumnAccessControl({
create: [],
read: [],
update: [],
})
@TableColumn({
required: true,
type: TableColumnType.Boolean,
canReadOnRelationQuery: true,
title: "Reported to Billing Provider",
description:
"Whether this usage billing was reported to billing provider or not (eg Stripe)",
example: true,
})
@Column({
nullable: false,
type: ColumnType.Boolean,
default: false,
})
public isReportedToBillingProvider?: boolean = undefined;
@ColumnAccessControl({
create: [],
read: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ManageProjectBilling,
],
update: [],
})
@TableColumn({
manyToOneRelationColumn: "serviceId",
type: TableColumnType.Entity,
modelType: Service,
title: "Service",
description: "Relation to Service Resource in which this object belongs",
example: "d4e5f6a7-b8c9-0123-def1-234567890123",
})
@ManyToOne(
() => {
return Service;
},
{
eager: false,
nullable: true,
onDelete: "CASCADE",
orphanedRowAction: "nullify",
},
)
@JoinColumn({ name: "serviceId" })
public service?: Service = undefined;
@ColumnAccessControl({
create: [],
read: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ManageProjectBilling,
],
update: [],
})
@Index()
@TableColumn({
type: TableColumnType.ObjectID,
required: true,
title: "Service ID",
description: "ID of your Service resource where this object belongs",
example: "d4e5f6a7-b8c9-0123-def1-234567890123",
})
@Column({
type: ColumnType.ObjectID,
nullable: false,
transformer: ObjectID.getDatabaseTransformer(),
})
public serviceId?: ObjectID = undefined;
@ColumnAccessControl({
create: [],
read: [],
update: [],
})
@TableColumn({
required: false,
type: TableColumnType.Date,
canReadOnRelationQuery: true,
title: "Reported to Billing Provider At",
description:
"When this usage billing was reported to billing provider or not (eg Stripe)",
example: "2025-12-12T10:00:00.000Z",
})
@Column({
nullable: true,
type: ColumnType.Date,
})
public reportedToBillingProviderAt?: Date = undefined;
@ColumnAccessControl({
create: [],
read: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ManageProjectBilling,
],
update: [],
})
@TableColumn({
manyToOneRelationColumn: "createdByUserId",
type: TableColumnType.Entity,
modelType: User,
title: "Created by User",
description:
"Relation to User who created this object (if this object was created by a User)",
example: "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
})
@ManyToOne(
() => {
return User;
},
{
eager: false,
nullable: true,
onDelete: "SET NULL",
orphanedRowAction: "nullify",
},
)
@JoinColumn({ name: "createdByUserId" })
public createdByUser?: User = undefined;
@ColumnAccessControl({
create: [],
read: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ManageProjectBilling,
],
update: [],
})
@TableColumn({
type: TableColumnType.ObjectID,
title: "Created by User ID",
description:
"User ID who created this object (if this object was created by a User)",
example: "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
})
@Column({
type: ColumnType.ObjectID,
nullable: true,
transformer: ObjectID.getDatabaseTransformer(),
})
public createdByUserId?: ObjectID = undefined;
@ColumnAccessControl({
create: [],
read: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ManageProjectBilling,
],
update: [],
})
@TableColumn({
manyToOneRelationColumn: "deletedByUserId",
type: TableColumnType.Entity,
title: "Deleted by User",
modelType: User,
description:
"Relation to User who deleted this object (if this object was deleted by a User)",
example: "b2c3d4e5-f6a7-8901-bcde-f12345678901",
})
@ManyToOne(
() => {
return User;
},
{
cascade: false,
eager: false,
nullable: true,
onDelete: "SET NULL",
orphanedRowAction: "nullify",
},
)
@JoinColumn({ name: "deletedByUserId" })
public deletedByUser?: User = undefined;
@ColumnAccessControl({
create: [],
read: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ManageProjectBilling,
],
update: [],
})
@TableColumn({
type: TableColumnType.ObjectID,
title: "Deleted by User ID",
description:
"User ID who deleted this object (if this object was deleted by a User)",
example: "b2c3d4e5-f6a7-8901-bcde-f12345678901",
})
@Column({
type: ColumnType.ObjectID,
nullable: true,
transformer: ObjectID.getDatabaseTransformer(),
})
public deletedByUserId?: ObjectID = undefined;
}