Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions static/gsApp/views/subscriptionPage/usageOverview.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {resetMockDate, setMockDate} from 'sentry-test/utils';

import {DataCategory} from 'sentry/types/core';

import {GIGABYTE} from 'getsentry/constants';
import SubscriptionStore from 'getsentry/stores/subscriptionStore';
import Overview from 'getsentry/views/subscriptionPage/overview';
import UsageOverview from 'getsentry/views/subscriptionPage/usageOverview';
Expand Down Expand Up @@ -116,6 +117,12 @@ describe('UsageOverview', () => {
usage: 6000,
onDemandSpendUsed: 10_00,
};
subscription.categories.attachments = {
...subscription.categories.attachments!,
reserved: 25, // 25 GB
free: 0,
usage: GIGABYTE / 2,
};
subscription.categories.spans = {
...subscription.categories.spans!,
reserved: 20_000_000,
Expand Down Expand Up @@ -143,6 +150,12 @@ describe('UsageOverview', () => {
// Errors usage and gifted units
expect(screen.getByText('6,000 / 51,000')).toBeInTheDocument();
expect(screen.getByText('$10.00')).toBeInTheDocument();
expect(screen.getByText('12%')).toBeInTheDocument();

// Attachments usage should be in the correct unit + above platform volume
expect(screen.getByText('500 MB / 25 GB')).toBeInTheDocument();
expect(screen.getByText('50%')).toBeInTheDocument();
expect(screen.getByText('$6.00')).toBeInTheDocument();

// Reserved spans above platform volume
expect(screen.getByText('0 / 20,000,000')).toBeInTheDocument();
Expand Down
22 changes: 18 additions & 4 deletions static/gsApp/views/subscriptionPage/usageOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ import {NavLayout} from 'sentry/views/nav/types';

import ProductTrialTag from 'getsentry/components/productTrial/productTrialTag';
import StartTrialButton from 'getsentry/components/startTrialButton';
import {RESERVED_BUDGET_QUOTA, UNLIMITED, UNLIMITED_RESERVED} from 'getsentry/constants';
import {
GIGABYTE,
RESERVED_BUDGET_QUOTA,
UNLIMITED,
UNLIMITED_RESERVED,
} from 'getsentry/constants';
import {useCurrentBillingHistory} from 'getsentry/hooks/useCurrentBillingHistory';
import {
AddOnCategory,
Expand All @@ -47,10 +52,13 @@ import {
getPercentage,
getPotentialProductTrial,
getReservedBudgetCategoryForAddOn,
MILLISECONDS_IN_HOUR,
} from 'getsentry/utils/billing';
import {
getCategoryInfoFromPlural,
getPlanCategoryName,
isByteCategory,
isContinuousProfiling,
sortCategories,
} from 'getsentry/utils/dataCategory';
import {displayPriceWithCents, getBucket} from 'getsentry/views/amCheckout/utils';
Expand Down Expand Up @@ -248,7 +256,8 @@ function UsageOverviewTable({subscription, organization, usageData}: UsageOvervi
title: true,
});
const reserved = metricHistory.reserved ?? 0;
const free = metricHistory.free;
const free = metricHistory.free ?? 0;
const prepaid = metricHistory.prepaid ?? 0;
const total = metricHistory.usage;
const paygTotal = metricHistory.onDemandSpendUsed;
const softCapType =
Expand All @@ -270,11 +279,16 @@ function UsageOverviewTable({subscription, organization, usageData}: UsageOvervi
: reserved > 0;

const bucket = getBucket({
events: reserved,
events: reserved, // buckets use the converted unit reserved amount (ie. in GB for byte categories)
buckets: subscription.planDetails.planCategories[category],
});
const recurringReservedSpend = bucket.price ?? 0;
const reservedTotal = (reserved ?? 0) + (free ?? 0);
// convert prepaid amount to the same unit as usage to accurately calculate percent used
const reservedTotal = isByteCategory(category)
? prepaid * GIGABYTE
: isContinuousProfiling(category)
? prepaid * MILLISECONDS_IN_HOUR
: prepaid;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Incorrect Calculation of Reserved Total

The reservedTotal calculation now relies solely on prepaid, which often defaults to zero or doesn't include the reserved and free amounts. This results in an incorrect denominator for percentage calculations, potentially causing division by zero or displaying an inaccurate usage percentage to users.

Fix in Cursor Fix in Web

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prepaid is made up of reserved and free on the backend

zero division is not a problem since we only call getPercentage if reservedTotal is truthy

const percentUsed = reservedTotal
? getPercentage(total, reservedTotal)
: undefined;
Expand Down
Loading