Fix formatting and add missing commas

This commit is contained in:
Simon Larsen
2023-12-22 12:18:14 +00:00
parent d42d95f28e
commit f374459c5a
18 changed files with 232 additions and 272 deletions

View File

@@ -88,21 +88,21 @@ export default class ProjectAPI extends BaseAPI<Project, ProjectServiceType> {
}
}
// get reseller for each project.
for(const project of projects) {
if(project.resellerId) {
// get reseller for each project.
for (const project of projects) {
if (project.resellerId) {
const reseller: Reseller | null =
await ResellerService.findOneById({
id: project.resellerId,
select: {
enableTelemetryFeatures: true,
},
props: {
isRoot: true,
},
});
const reseller: Reseller | null = await ResellerService.findOneById({
id: project.resellerId,
select: {
enableTelemetryFeatures: true
},
props: {
isRoot: true,
}
});
if(!reseller) {
if (!reseller) {
continue;
}

View File

@@ -38,7 +38,6 @@ export interface Invoice {
}
export class BillingService extends BaseService {
public constructor() {
super();
}
@@ -143,9 +142,12 @@ export class BillingService extends BaseService {
);
for (const serverMeteredPlan of data.serverMeteredPlans) {
await serverMeteredPlan.reportQuantityToBillingProvider(data.projectId, {
meteredPlanSubscriptionId: meteredSubscription.id,
});
await serverMeteredPlan.reportQuantityToBillingProvider(
data.projectId,
{
meteredPlanSubscriptionId: meteredSubscription.id,
}
);
}
return {
@@ -297,7 +299,6 @@ export class BillingService extends BaseService {
meteredPlan: MeteredPlan,
quantity: number
): Promise<void> {
if (!this.isBillingEnabled()) {
throw new BadDataException(
Errors.BillingService.BILLING_NOT_ENABLED

View File

@@ -8,22 +8,28 @@ import QueryHelper from '../Types/Database/QueryHelper';
import SortOrder from 'Common/Types/BaseDatabase/SortOrder';
export class Service extends DatabaseService<Model> {
public constructor(postgresDatabase?: PostgresDatabase) {
super(Model, postgresDatabase);
this.hardDeleteItemsOlderThanInDays('createdAt', 120);
}
public async getUnreportedUsageBilling(data: { projectId: ObjectID; productType: ProductType; }): Promise<Model[]> {
public async getUnreportedUsageBilling(data: {
projectId: ObjectID;
productType: ProductType;
}): Promise<Model[]> {
return await this.findBy({
query: {
projectId: data.projectId,
productType: data.productType,
isReportedToBillingProvider: false,
createdAt: QueryHelper.lessThan(OneUptimeDate.addRemoveDays(OneUptimeDate.getCurrentDate(), -1)) // we need to get everything that's not today.
createdAt: QueryHelper.lessThan(
OneUptimeDate.addRemoveDays(
OneUptimeDate.getCurrentDate(),
-1
)
), // we need to get everything that's not today.
},
skip: 0,
skip: 0,
limit: LIMIT_PER_PROJECT,
select: {
_id: true,
@@ -35,13 +41,23 @@ export class Service extends DatabaseService<Model> {
});
}
public async updateUsageBilling(data: { projectId: ObjectID; productType: ProductType; usageCount: number }): Promise<void> {
public async updateUsageBilling(data: {
projectId: ObjectID;
productType: ProductType;
usageCount: number;
}): Promise<void> {
const usageBilling: Model | null = await this.findOneBy({
query: {
projectId: data.projectId,
productType: data.productType,
isReportedToBillingProvider: false,
createdAt: QueryHelper.inBetween(OneUptimeDate.addRemoveDays(OneUptimeDate.getCurrentDate(), -1), OneUptimeDate.getCurrentDate())
createdAt: QueryHelper.inBetween(
OneUptimeDate.addRemoveDays(
OneUptimeDate.getCurrentDate(),
-1
),
OneUptimeDate.getCurrentDate()
),
},
select: {
_id: true,
@@ -51,21 +67,22 @@ export class Service extends DatabaseService<Model> {
isRoot: true,
},
sort: {
createdAt: SortOrder.Descending
}
createdAt: SortOrder.Descending,
},
});
if(usageBilling && usageBilling.id){
if (usageBilling && usageBilling.id) {
await this.updateOneById({
id: usageBilling.id,
data: {
usageCount: (usageBilling.usageCount || 0) + data.usageCount
usageCount:
(usageBilling.usageCount || 0) + data.usageCount,
},
props: {
isRoot: true,
},
props:{
isRoot: true
}
});
}else{
} else {
const usageBilling: Model = new Model();
usageBilling.projectId = data.projectId;
usageBilling.productType = data.productType;
@@ -73,7 +90,6 @@ export class Service extends DatabaseService<Model> {
usageBilling.isReportedToBillingProvider = false;
usageBilling.createdAt = OneUptimeDate.getCurrentDate();
// add total cost in USD as well.
await this.create({
@@ -82,7 +98,6 @@ export class Service extends DatabaseService<Model> {
isRoot: true,
},
});
}
}
}

View File

@@ -70,6 +70,5 @@ export default class ActiveMonitoringMeteredPlan extends ServerMeteredPlan {
count.toNumber()
);
}
}
}

View File

@@ -4,7 +4,7 @@ import ServerMeteredPlan from './ServerMeteredPlan';
const AllMeteredPlans: Array<typeof ServerMeteredPlan> = [
ActiveMonitoringMeteredPlan,
LogsDataIngestMeteredPlan
LogsDataIngestMeteredPlan,
];
export default AllMeteredPlans;

View File

@@ -23,14 +23,13 @@ export default class LogsDataIngestMeteredPlan extends ServerMeteredPlan {
meteredPlanSubscriptionId?: string | undefined;
}
): Promise<void> {
// get all unreported logs
const usageBillings: Array<UsageBilling> = await UsageBillingService.getUnreportedUsageBilling({
projectId: projectId,
productType: ProductType.Logs
});
const usageBillings: Array<UsageBilling> =
await UsageBillingService.getUnreportedUsageBilling({
projectId: projectId,
productType: ProductType.Logs,
});
if (usageBillings.length === 0) {
return;
@@ -54,28 +53,31 @@ export default class LogsDataIngestMeteredPlan extends ServerMeteredPlan {
project.paymentProviderMeteredSubscriptionId) &&
project.paymentProviderPlanId
) {
for (const usageBilling of usageBillings) {
if (usageBilling?.usageCount && usageBilling?.usageCount > 0 && usageBilling.id) {
if (
usageBilling?.usageCount &&
usageBilling?.usageCount > 0 &&
usageBilling.id
) {
await BillingService.addOrUpdateMeteredPricingOnSubscription(
(options?.meteredPlanSubscriptionId as string) ||
(project.paymentProviderMeteredSubscriptionId as string),
(project.paymentProviderMeteredSubscriptionId as string),
LogsDataIngestMeteredPlan.getMeteredPlan(),
usageBilling.usageCount
);
// now mark it as reported.
// now mark it as reported.
await UsageBillingService.updateOneById({
id: usageBilling.id,
data: {
isReportedToBillingProvider: true,
reportedToBillingProviderAt: OneUptimeDate.getCurrentDate(),
reportedToBillingProviderAt:
OneUptimeDate.getCurrentDate(),
},
props: {
isRoot: true,
}
},
});
}
}

View File

@@ -33,9 +33,11 @@ const LogsFilters: FunctionComponent<ComponentProps> = (
props.onFilterChanged(filterOptions);
}, [filterOptions]);
const showAutoScrollButton: boolean = !isSqlQuery && !showMoreFilters && !filterOptions.searchText;
const showSearchButton: boolean = Boolean(showMoreFilters || filterOptions.searchText);
const showAutoScrollButton: boolean =
!isSqlQuery && !showMoreFilters && !filterOptions.searchText;
const showSearchButton: boolean = Boolean(
showMoreFilters || filterOptions.searchText
);
return (
<div className="shadow sm:overflow-hidden sm:rounded-md">
@@ -175,8 +177,6 @@ const LogsFilters: FunctionComponent<ComponentProps> = (
</div>
</div>
)}
</div>
{showAutoScrollButton && (
<div>
@@ -211,7 +211,7 @@ const LogsFilters: FunctionComponent<ComponentProps> = (
<div className="mt-12 -ml-8 justify-end flex w-44">
<Button
title="Search with SQL"
onClick={() => { }}
onClick={() => {}}
/>
</div>
</div>
@@ -221,7 +221,7 @@ const LogsFilters: FunctionComponent<ComponentProps> = (
<div className="mt-7 -ml-20 justify-end flex w-44">
<Button
title="Search"
onClick={() => { }}
onClick={() => {}}
icon={IconProp.Search}
/>
</div>

View File

@@ -11,12 +11,11 @@ import UsageBilling from 'Model/Models/UsageBilling';
import FieldType from 'CommonUI/src/Components/Types/FieldType';
import DashboardNavigation from '../../Utils/Navigation';
export interface ComponentProps extends PageComponentProps { }
export interface ComponentProps extends PageComponentProps {}
const Settings: FunctionComponent<ComponentProps> = (
_props: ComponentProps
): ReactElement => {
return (
<Page
title={'Project Settings'}
@@ -42,72 +41,76 @@ const Settings: FunctionComponent<ComponentProps> = (
]}
sideMenu={<DashboardSideMenu />}
>
<ModelTable<UsageBilling>
modelType={UsageBilling}
id="usage-history-table"
isDeleteable={false}
name="Settings > Billing > Usage History"
isEditable={false}
isCreateable={false}
isViewable={false}
cardProps={{
title: 'Usage History',
description:
'Here is the usage history for this project.',
}}
noItemsMessage={'No usage history found. Maybe you have not used Telemetry features yet?'}
query={{
projectId:
DashboardNavigation.getProjectId()?.toString(),
}}
showRefreshButton={true}
showFilterButton={false}
selectMoreFields={{
usageUnitName: true,
}}
columns={[
{
field: {
productType: true,
},
title: 'Product',
type: FieldType.Text,
isFilterable: true,
<ModelTable<UsageBilling>
modelType={UsageBilling}
id="usage-history-table"
isDeleteable={false}
name="Settings > Billing > Usage History"
isEditable={false}
isCreateable={false}
isViewable={false}
cardProps={{
title: 'Usage History',
description: 'Here is the usage history for this project.',
}}
noItemsMessage={
'No usage history found. Maybe you have not used Telemetry features yet?'
}
query={{
projectId: DashboardNavigation.getProjectId()?.toString(),
}}
showRefreshButton={true}
showFilterButton={false}
selectMoreFields={{
usageUnitName: true,
}}
columns={[
{
field: {
productType: true,
},
{
field: {
createdAt: true,
},
title: 'Day',
type: FieldType.Date,
isFilterable: true,
title: 'Product',
type: FieldType.Text,
isFilterable: true,
},
{
field: {
createdAt: true,
},
{
field: {
usageCount: true,
},
title: 'Usage',
type: FieldType.Text,
getElement: (item: JSONObject) => {
return <div>{`${item['usageCount'] as string} ${item['usageUnitName'] as string}`}</div>;
},
title: 'Day',
type: FieldType.Date,
isFilterable: true,
},
{
field: {
usageCount: true,
},
{
field: {
totalCostInUSD: true,
},
title: 'Total Cost',
type: FieldType.Text,
getElement: (item: JSONObject) => {
return <div>{`${item['totalCostInUSD'] as string} USD`}</div>;
},
title: 'Usage',
type: FieldType.Text,
getElement: (item: JSONObject) => {
return (
<div>{`${item['usageCount'] as string} ${
item['usageUnitName'] as string
}`}</div>
);
},
]}
/>
},
{
field: {
totalCostInUSD: true,
},
title: 'Total Cost',
type: FieldType.Text,
getElement: (item: JSONObject) => {
return (
<div>{`${
item['totalCostInUSD'] as string
} USD`}</div>
);
},
},
]}
/>
</Page>
);
};

View File

@@ -20,11 +20,13 @@ import ErrorMessage from 'CommonUI/src/Components/ErrorMessage/ErrorMessage';
const Services: FunctionComponent<PageComponentProps> = (
props: PageComponentProps
): ReactElement => {
const disableTelemetryForThisProject: boolean =
props.currentProject?.reseller?.enableTelemetryFeatures === false;
const disableTelemetryForThisProject: boolean = props.currentProject?.reseller?.enableTelemetryFeatures === false;
if(disableTelemetryForThisProject){
return <ErrorMessage error="Looks like you have bought this plan from a reseller. It did not include telemetry features in your plan. Telemetry features are disabled for this project." />
if (disableTelemetryForThisProject) {
return (
<ErrorMessage error="Looks like you have bought this plan from a reseller. It did not include telemetry features in your plan. Telemetry features are disabled for this project." />
);
}
return (
@@ -52,8 +54,6 @@ const Services: FunctionComponent<PageComponentProps> = (
]}
sideMenu={<SideMenu />}
>
<ModelTable<TelemetryService>
modelType={TelemetryService}
id="services-table"

View File

@@ -166,7 +166,6 @@ const SettingsUsageHistory: LazyExoticComponent<
return import('../Pages/Settings/UsageHistory');
});
const SettingsRoutes: FunctionComponent<ComponentProps> = (
props: ComponentProps
): ReactElement => {
@@ -208,7 +207,7 @@ const SettingsRoutes: FunctionComponent<ComponentProps> = (
{...props}
pageRoute={
RouteMap[
PageMap.SETTINGS_INCIDENT_TEMPLATES
PageMap.SETTINGS_INCIDENT_TEMPLATES
] as Route
}
/>
@@ -219,7 +218,7 @@ const SettingsRoutes: FunctionComponent<ComponentProps> = (
<PageRoute
path={
SettingsRoutePath[
PageMap.SETTINGS_INCIDENT_TEMPLATES_VIEW
PageMap.SETTINGS_INCIDENT_TEMPLATES_VIEW
] || ''
}
element={
@@ -228,7 +227,7 @@ const SettingsRoutes: FunctionComponent<ComponentProps> = (
{...props}
pageRoute={
RouteMap[
PageMap.SETTINGS_INCIDENT_TEMPLATES_VIEW
PageMap.SETTINGS_INCIDENT_TEMPLATES_VIEW
] as Route
}
/>
@@ -236,20 +235,15 @@ const SettingsRoutes: FunctionComponent<ComponentProps> = (
}
/>
<PageRoute
path={
SettingsRoutePath[
PageMap.SETTINGS_USAGE_HISTORY
] || ''
}
path={SettingsRoutePath[PageMap.SETTINGS_USAGE_HISTORY] || ''}
element={
<Suspense fallback={Loader}>
<SettingsUsageHistory
{...props}
pageRoute={
RouteMap[
PageMap.SETTINGS_USAGE_HISTORY
PageMap.SETTINGS_USAGE_HISTORY
] as Route
}
/>
@@ -265,7 +259,7 @@ const SettingsRoutes: FunctionComponent<ComponentProps> = (
{...props}
pageRoute={
RouteMap[
PageMap.SETTINGS_FEATURE_FLAGS
PageMap.SETTINGS_FEATURE_FLAGS
] as Route
}
/>
@@ -276,7 +270,7 @@ const SettingsRoutes: FunctionComponent<ComponentProps> = (
<PageRoute
path={
SettingsRoutePath[
PageMap.SETTINGS_INCIDENT_NOTE_TEMPLATES
PageMap.SETTINGS_INCIDENT_NOTE_TEMPLATES
] || ''
}
element={
@@ -285,7 +279,7 @@ const SettingsRoutes: FunctionComponent<ComponentProps> = (
{...props}
pageRoute={
RouteMap[
PageMap.SETTINGS_INCIDENT_NOTE_TEMPLATES
PageMap.SETTINGS_INCIDENT_NOTE_TEMPLATES
] as Route
}
/>
@@ -296,7 +290,7 @@ const SettingsRoutes: FunctionComponent<ComponentProps> = (
<PageRoute
path={
SettingsRoutePath[
PageMap.SETTINGS_INCIDENT_NOTE_TEMPLATES_VIEW
PageMap.SETTINGS_INCIDENT_NOTE_TEMPLATES_VIEW
] || ''
}
element={
@@ -305,8 +299,8 @@ const SettingsRoutes: FunctionComponent<ComponentProps> = (
{...props}
pageRoute={
RouteMap[
PageMap
.SETTINGS_INCIDENT_NOTE_TEMPLATES_VIEW
PageMap
.SETTINGS_INCIDENT_NOTE_TEMPLATES_VIEW
] as Route
}
/>
@@ -317,7 +311,7 @@ const SettingsRoutes: FunctionComponent<ComponentProps> = (
<PageRoute
path={
SettingsRoutePath[
PageMap.SETTINGS_SCHEDULED_MAINTENANCE_NOTE_TEMPLATES
PageMap.SETTINGS_SCHEDULED_MAINTENANCE_NOTE_TEMPLATES
] || ''
}
element={
@@ -326,8 +320,8 @@ const SettingsRoutes: FunctionComponent<ComponentProps> = (
{...props}
pageRoute={
RouteMap[
PageMap
.SETTINGS_SCHEDULED_MAINTENANCE_NOTE_TEMPLATES
PageMap
.SETTINGS_SCHEDULED_MAINTENANCE_NOTE_TEMPLATES
] as Route
}
/>
@@ -338,8 +332,8 @@ const SettingsRoutes: FunctionComponent<ComponentProps> = (
<PageRoute
path={
SettingsRoutePath[
PageMap
.SETTINGS_SCHEDULED_MAINTENANCE_NOTE_TEMPLATES_VIEW
PageMap
.SETTINGS_SCHEDULED_MAINTENANCE_NOTE_TEMPLATES_VIEW
] || ''
}
element={
@@ -348,8 +342,8 @@ const SettingsRoutes: FunctionComponent<ComponentProps> = (
{...props}
pageRoute={
RouteMap[
PageMap
.SETTINGS_SCHEDULED_MAINTENANCE_NOTE_TEMPLATES_VIEW
PageMap
.SETTINGS_SCHEDULED_MAINTENANCE_NOTE_TEMPLATES_VIEW
] as Route
}
/>
@@ -407,7 +401,7 @@ const SettingsRoutes: FunctionComponent<ComponentProps> = (
{...props}
pageRoute={
RouteMap[
PageMap.SETTINGS_MONITORS_STATUS
PageMap.SETTINGS_MONITORS_STATUS
] as Route
}
/>
@@ -423,7 +417,7 @@ const SettingsRoutes: FunctionComponent<ComponentProps> = (
{...props}
pageRoute={
RouteMap[
PageMap.SETTINGS_INCIDENTS_STATE
PageMap.SETTINGS_INCIDENTS_STATE
] as Route
}
/>
@@ -434,7 +428,7 @@ const SettingsRoutes: FunctionComponent<ComponentProps> = (
<PageRoute
path={
SettingsRoutePath[
PageMap.SETTINGS_SCHEDULED_MAINTENANCE_STATE
PageMap.SETTINGS_SCHEDULED_MAINTENANCE_STATE
] || ''
}
element={
@@ -443,7 +437,7 @@ const SettingsRoutes: FunctionComponent<ComponentProps> = (
{...props}
pageRoute={
RouteMap[
PageMap.SETTINGS_SCHEDULED_MAINTENANCE_STATE
PageMap.SETTINGS_SCHEDULED_MAINTENANCE_STATE
] as Route
}
/>
@@ -473,7 +467,7 @@ const SettingsRoutes: FunctionComponent<ComponentProps> = (
{...props}
pageRoute={
RouteMap[
PageMap.SETTINGS_INCIDENTS_SEVERITY
PageMap.SETTINGS_INCIDENTS_SEVERITY
] as Route
}
/>
@@ -548,7 +542,7 @@ const SettingsRoutes: FunctionComponent<ComponentProps> = (
{...props}
pageRoute={
RouteMap[
PageMap.SETTINGS_MONITOR_CUSTOM_FIELDS
PageMap.SETTINGS_MONITOR_CUSTOM_FIELDS
] as Route
}
/>
@@ -559,7 +553,7 @@ const SettingsRoutes: FunctionComponent<ComponentProps> = (
<PageRoute
path={
SettingsRoutePath[
PageMap.SETTINGS_STATUS_PAGE_CUSTOM_FIELDS
PageMap.SETTINGS_STATUS_PAGE_CUSTOM_FIELDS
] || ''
}
element={
@@ -568,7 +562,7 @@ const SettingsRoutes: FunctionComponent<ComponentProps> = (
{...props}
pageRoute={
RouteMap[
PageMap.SETTINGS_STATUS_PAGE_CUSTOM_FIELDS
PageMap.SETTINGS_STATUS_PAGE_CUSTOM_FIELDS
] as Route
}
/>
@@ -579,7 +573,7 @@ const SettingsRoutes: FunctionComponent<ComponentProps> = (
<PageRoute
path={
SettingsRoutePath[
PageMap.SETTINGS_SCHEDULED_MAINTENANCE_CUSTOM_FIELDS
PageMap.SETTINGS_SCHEDULED_MAINTENANCE_CUSTOM_FIELDS
] || ''
}
element={
@@ -588,8 +582,8 @@ const SettingsRoutes: FunctionComponent<ComponentProps> = (
{...props}
pageRoute={
RouteMap[
PageMap
.SETTINGS_SCHEDULED_MAINTENANCE_CUSTOM_FIELDS
PageMap
.SETTINGS_SCHEDULED_MAINTENANCE_CUSTOM_FIELDS
] as Route
}
/>
@@ -600,7 +594,7 @@ const SettingsRoutes: FunctionComponent<ComponentProps> = (
<PageRoute
path={
SettingsRoutePath[
PageMap.SETTINGS_INCIDENT_CUSTOM_FIELDS
PageMap.SETTINGS_INCIDENT_CUSTOM_FIELDS
] || ''
}
element={
@@ -609,7 +603,7 @@ const SettingsRoutes: FunctionComponent<ComponentProps> = (
{...props}
pageRoute={
RouteMap[
PageMap.SETTINGS_INCIDENT_CUSTOM_FIELDS
PageMap.SETTINGS_INCIDENT_CUSTOM_FIELDS
] as Route
}
/>
@@ -620,7 +614,7 @@ const SettingsRoutes: FunctionComponent<ComponentProps> = (
<PageRoute
path={
SettingsRoutePath[
PageMap.SETTINGS_ON_CALL_DUTY_POLICY_CUSTOM_FIELDS
PageMap.SETTINGS_ON_CALL_DUTY_POLICY_CUSTOM_FIELDS
] || ''
}
element={
@@ -629,8 +623,8 @@ const SettingsRoutes: FunctionComponent<ComponentProps> = (
{...props}
pageRoute={
RouteMap[
PageMap
.SETTINGS_ON_CALL_DUTY_POLICY_CUSTOM_FIELDS
PageMap
.SETTINGS_ON_CALL_DUTY_POLICY_CUSTOM_FIELDS
] as Route
}
/>
@@ -662,7 +656,7 @@ const SettingsRoutes: FunctionComponent<ComponentProps> = (
{...props}
pageRoute={
RouteMap[
PageMap.SETTINGS_BILLING_INVOICES
PageMap.SETTINGS_BILLING_INVOICES
] as Route
}
/>

View File

@@ -135,10 +135,7 @@ router.use(
serviceProjectId as string
);
// report to Usage Service.
// report to Usage Service.
next();
} catch (err) {

View File

@@ -265,5 +265,5 @@ export default [
OnCallDutyPolicyEscalationRuleSchedule,
UsageBilling
UsageBilling,
];

View File

@@ -529,7 +529,6 @@ export default class Model extends TenantModel {
})
public workflowRunsInLast30Days?: number = undefined;
@ColumnAccessControl({
create: [],
read: [
@@ -540,16 +539,17 @@ export default class Model extends TenantModel {
],
update: [],
})
@TableColumn({
@TableColumn({
type: TableColumnType.Number,
title: 'Retain Telemetry Logs For Days',
description: 'Number of days to retain telemetry logs for this project.',
description:
'Number of days to retain telemetry logs for this project.',
})
@Column({
type: ColumnType.Number,
nullable: true,
unique: false,
default: 15
default: 15,
})
public retainTelemetryLogsForDays?: number = undefined;
@@ -563,16 +563,17 @@ export default class Model extends TenantModel {
],
update: [],
})
@TableColumn({
@TableColumn({
type: TableColumnType.Number,
title: 'Retain Telemetry Traces For Days',
description: 'Number of days to retain telemetry traces for this project.',
description:
'Number of days to retain telemetry traces for this project.',
})
@Column({
type: ColumnType.Number,
nullable: true,
unique: false,
default: 15
default: 15,
})
public retainTelemetryTracesForDays?: number = undefined;

View File

@@ -268,8 +268,7 @@ export default class Reseller extends BaseModel {
type: TableColumnType.Boolean,
canReadOnRelationQuery: true,
title: 'Enable Telemetry Features',
description:
'Should we enable telemetry features for this reseller?',
description: 'Should we enable telemetry features for this reseller?',
})
@Column({
nullable: true,

View File

@@ -17,7 +17,6 @@ import TenantColumn from 'Common/Types/Database/TenantColumn';
import TableMetadata from 'Common/Types/Database/TableMetadata';
import IconProp from 'Common/Types/Icon/IconProp';
export enum ProductType {
Logs = 'Logs',
Traces = 'Traces',
@@ -26,20 +25,14 @@ export enum ProductType {
@TenantColumn('projectId')
@TableAccessControl({
create: [
],
create: [],
read: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.CanManageProjectBilling,
],
delete: [
],
update: [
],
delete: [],
update: [],
})
@CrudApiEndpoint(new Route('/usage-billing'))
@SlugifyColumn('name', 'slug')
@@ -56,9 +49,7 @@ export enum ProductType {
})
export default class UsageBilling extends AccessControlModel {
@ColumnAccessControl({
create: [
],
create: [],
read: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
@@ -89,9 +80,7 @@ export default class UsageBilling extends AccessControlModel {
public project?: Project = undefined;
@ColumnAccessControl({
create: [
],
create: [],
read: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
@@ -116,17 +105,13 @@ export default class UsageBilling extends AccessControlModel {
public projectId?: ObjectID = undefined;
@ColumnAccessControl({
create: [
],
create: [],
read: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.CanManageProjectBilling,
],
update: [
],
update: [],
})
@TableColumn({
required: true,
@@ -142,19 +127,14 @@ export default class UsageBilling extends AccessControlModel {
})
public day?: string = undefined; // this is of format DD-MM-YYYY
@ColumnAccessControl({
create: [
],
create: [],
read: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.CanManageProjectBilling,
],
update: [
],
update: [],
})
@TableColumn({
required: true,
@@ -170,19 +150,14 @@ export default class UsageBilling extends AccessControlModel {
})
public productType?: ProductType = undefined;
@ColumnAccessControl({
create: [
],
create: [],
read: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.CanManageProjectBilling,
],
update: [
],
update: [],
})
@TableColumn({
required: true,
@@ -198,24 +173,21 @@ export default class UsageBilling extends AccessControlModel {
public usageCount?: number = undefined;
@ColumnAccessControl({
create: [
],
create: [],
read: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.CanManageProjectBilling,
],
update: [
],
update: [],
})
@TableColumn({
required: true,
type: TableColumnType.ShortText,
canReadOnRelationQuery: true,
title: 'Usage Unit Name',
description: 'Usage Unit Name this usage billing was generated for (eg: GB, MB, etc.)',
description:
'Usage Unit Name this usage billing was generated for (eg: GB, MB, etc.)',
})
@Column({
nullable: false,
@@ -225,17 +197,13 @@ export default class UsageBilling extends AccessControlModel {
public usageUnitName?: string = undefined;
@ColumnAccessControl({
create: [
],
create: [],
read: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.CanManageProjectBilling,
],
update: [
],
update: [],
})
@TableColumn({
required: true,
@@ -250,50 +218,38 @@ export default class UsageBilling extends AccessControlModel {
})
public totalCostInUSD?: number = undefined;
@ColumnAccessControl({
create: [
],
read: [
],
update: [
],
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)',
description:
'Whether this usage billing was reported to billing provider or not (eg Stripe)',
})
@Column({
nullable: false,
type: ColumnType.Boolean,
default: false
default: false,
})
public isReportedToBillingProvider?: boolean = undefined;
@ColumnAccessControl({
create: [
],
read: [
],
update: [
],
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)',
description:
'When this usage billing was reported to billing provider or not (eg Stripe)',
})
@Column({
nullable: true,
@@ -301,12 +257,8 @@ export default class UsageBilling extends AccessControlModel {
})
public reportedToBillingProviderAt?: Date = undefined;
@ColumnAccessControl({
create: [
],
create: [],
read: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
@@ -337,9 +289,7 @@ export default class UsageBilling extends AccessControlModel {
public createdByUser?: User = undefined;
@ColumnAccessControl({
create: [
],
create: [],
read: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
@@ -412,5 +362,4 @@ export default class UsageBilling extends AccessControlModel {
transformer: ObjectID.getDatabaseTransformer(),
})
public deletedByUserId?: ObjectID = undefined;
}

View File

@@ -34,7 +34,10 @@ export default class UpdateActiveMonitorCountToBillingProvider extends DataMigra
for (const project of projects) {
for (const meteredPlan of AllMeteredPlans) {
await meteredPlan.reportQuantityToBillingProvider(project.id!, {});
await meteredPlan.reportQuantityToBillingProvider(
project.id!,
{}
);
}
await Sleep.sleep(100);

View File

@@ -77,7 +77,6 @@ import { ClickhouseAppInstance } from 'CommonServer/Infrastructure/ClickhouseDat
import './Jobs/Workflow/TimeoutJobs';
import './Jobs/MeteredPlan/ReportTelemetryMeteredPlan';
const APP_NAME: string = 'workers';
const app: ExpressApplication = Express.getExpressApp();

View File

@@ -23,9 +23,7 @@ RunCron(
}
const projects: Array<Project> = await ProjectService.findBy({
query: {
},
query: {},
select: {
_id: true,
},
@@ -38,11 +36,11 @@ RunCron(
for (const project of projects) {
if (project.id) {
await LogsDataIngestMeteredPlan.reportQuantityToBillingProvider(project.id);
await LogsDataIngestMeteredPlan.reportQuantityToBillingProvider(
project.id
);
await Sleep.sleep(1000);
}
}
}
);