Skip to content

Commit 16bdffb

Browse files
jarrettscottcursoragent
authored andcommitted
feat(billing): Update usage totals for Logs (#95467)
Closes: https://linear.app/getsentry/issue/BIL-1088/convert-units-for-usage-total-cards Updates usage total calculations for the Logs data category
1 parent 6c9a58b commit 16bdffb

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

static/gsApp/utils/dataCategory.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,10 @@ export function isContinuousProfiling(category: DataCategory | string) {
277277
);
278278
}
279279

280+
export function isByteCategory(category: DataCategory | string) {
281+
return category === DataCategory.ATTACHMENTS || category === DataCategory.LOG_BYTE;
282+
}
283+
280284
export function getChunkCategoryFromDuration(category: DataCategory) {
281285
if (category === DataCategory.PROFILE_DURATION) {
282286
return DataCategory.PROFILE_CHUNKS;

static/gsApp/views/subscriptionPage/usageTotals.spec.tsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2001,6 +2001,42 @@ describe('calculateCategoryPrepaidUsage', () => {
20012001
expect(result.prepaidSpend).toBe(0); // No price bucket found for SEER in regular subscription
20022002
expect(result.prepaidUsage).toBe(10);
20032003
});
2004+
2005+
it('converts prepaid limit to bytes for LOG_BYTE category', () => {
2006+
const subscription = SubscriptionFixture({
2007+
organization,
2008+
plan: 'am2_team',
2009+
planTier: 'am2',
2010+
});
2011+
const prepaidGb = 10; // 10 GB prepaid limit
2012+
const usageBytes = 5 * GIGABYTE; // 5 GB actual usage
2013+
2014+
// Add price bucket information for LOG_BYTE category
2015+
subscription.planDetails.planCategories.logBytes = [
2016+
{events: prepaidGb, price: 1000, unitPrice: 0.1, onDemandPrice: 0.2},
2017+
];
2018+
2019+
subscription.categories.logBytes = MetricHistoryFixture({
2020+
prepaid: prepaidGb,
2021+
reserved: prepaidGb,
2022+
usage: usageBytes,
2023+
});
2024+
2025+
const result = calculateCategoryPrepaidUsage(
2026+
DataCategory.LOG_BYTE,
2027+
subscription,
2028+
prepaidGb
2029+
);
2030+
2031+
// Should multiply prepaid by GIGABYTE for unit conversion
2032+
expect(result).toEqual({
2033+
onDemandUsage: 0,
2034+
prepaidPercentUsed: 50, // 5GB / 10GB = 50%
2035+
prepaidPrice: 1000,
2036+
prepaidSpend: 500,
2037+
prepaidUsage: usageBytes,
2038+
});
2039+
});
20042040
});
20052041

20062042
describe('calculateCategoryOnDemandUsage', () => {

static/gsApp/views/subscriptionPage/usageTotals.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import {
4242
import {
4343
getChunkCategoryFromDuration,
4444
getPlanCategoryName,
45+
isByteCategory,
4546
isContinuousProfiling,
4647
isPartOfReservedBudget,
4748
} from 'getsentry/utils/dataCategory';
@@ -235,10 +236,9 @@ export function calculateCategoryPrepaidUsage(
235236
// Convert prepaid limits to the appropriate unit based on category
236237
prepaidTotal =
237238
prepaid *
238-
(category === DataCategory.ATTACHMENTS
239+
(isByteCategory(category)
239240
? GIGABYTE
240-
: category === DataCategory.PROFILE_DURATION ||
241-
category === DataCategory.PROFILE_DURATION_UI
241+
: isContinuousProfiling(category)
242242
? MILLISECONDS_IN_HOUR
243243
: 1);
244244
}

0 commit comments

Comments
 (0)