Skip to content

Commit 429203b

Browse files
authored
feat(billing): Update per-category on-demand for Logs (#95472)
Closes: https://linear.app/getsentry/issue/BIL-1065/set-default-per-category-budget Enables Logs to be tracked as a separate category in on-demand budgets
1 parent ed17b7f commit 429203b

File tree

4 files changed

+77
-4
lines changed

4 files changed

+77
-4
lines changed

static/gsApp/types/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ export type PerCategoryOnDemandBudget = {
244244
errorsBudget: number;
245245
replaysBudget: number;
246246
transactionsBudget: number;
247+
logBytesBudget?: number;
247248
monitorSeatsBudget?: number;
248249
profileDurationBudget?: number;
249250
profileDurationUIBudget?: number;

static/gsApp/views/amCheckout/steps/onDemandBudgets.spec.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ describe('OnDemandBudgets AM Checkout', function () {
221221
replaysBudget: 0,
222222
profileDurationBudget: 0,
223223
profileDurationUIBudget: 0,
224+
logBytesBudget: 0,
224225
budgets: {
225226
errors: 1000,
226227
transactions: 2000,
@@ -230,6 +231,7 @@ describe('OnDemandBudgets AM Checkout', function () {
230231
uptime: 0,
231232
profileDuration: 0,
232233
profileDurationUI: 0,
234+
logBytes: 0,
233235
},
234236
},
235237
onDemandMaxSpend: 10000,

static/gsApp/views/onDemandBudgets/utils.spec.tsx

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ import {
55
SubscriptionFixture,
66
} from 'getsentry-test/fixtures/subscription';
77

8+
import {DataCategory} from 'sentry/types/core';
9+
810
import {OnDemandBudgetMode, type OnDemandBudgets} from 'getsentry/types';
911
import {
1012
exceedsInvoicedBudgetLimit,
13+
getOnDemandBudget,
1114
getTotalBudget,
1215
parseOnDemandBudgetsFromSubscription,
1316
} from 'getsentry/views/onDemandBudgets/utils';
@@ -196,6 +199,7 @@ describe('parseOnDemandBudgetsFromSubscription', function () {
196199
replaysBudget: 0,
197200
profileDurationBudget: 0,
198201
profileDurationUIBudget: 0,
202+
logBytesBudget: 0,
199203
budgets: {
200204
errors: 100,
201205
transactions: 200,
@@ -514,3 +518,69 @@ describe('exceedsInvoicedBudgetLimit', function () {
514518
expect(exceedsInvoicedBudgetLimit(subscription, ondemandBudget)).toBe(true);
515519
});
516520
});
521+
522+
describe('getOnDemandBudget', function () {
523+
it('returns 0 for category when in per-category mode without explicit budget', function () {
524+
const budget: OnDemandBudgets = {
525+
budgetMode: OnDemandBudgetMode.PER_CATEGORY,
526+
errorsBudget: 100,
527+
transactionsBudget: 200,
528+
attachmentsBudget: 300,
529+
replaysBudget: 0,
530+
monitorSeatsBudget: 0,
531+
profileDurationBudget: 0,
532+
profileDurationUIBudget: 0,
533+
uptimeBudget: 0,
534+
logBytesBudget: 0,
535+
budgets: {
536+
errors: 100,
537+
transactions: 200,
538+
attachments: 300,
539+
replays: 0,
540+
monitorSeats: 0,
541+
profileDuration: 0,
542+
profileDurationUI: 0,
543+
uptime: 0,
544+
},
545+
};
546+
547+
expect(getOnDemandBudget(budget, DataCategory.LOG_BYTE)).toBe(0);
548+
});
549+
550+
it('returns correct value for LOG_BYTE category when in per-category mode with explicit budget', function () {
551+
const budget: OnDemandBudgets = {
552+
budgetMode: OnDemandBudgetMode.PER_CATEGORY,
553+
errorsBudget: 100,
554+
transactionsBudget: 200,
555+
attachmentsBudget: 300,
556+
replaysBudget: 0,
557+
monitorSeatsBudget: 0,
558+
profileDurationBudget: 0,
559+
profileDurationUIBudget: 0,
560+
uptimeBudget: 0,
561+
logBytesBudget: 500,
562+
budgets: {
563+
errors: 100,
564+
transactions: 200,
565+
attachments: 300,
566+
replays: 0,
567+
monitorSeats: 0,
568+
profileDuration: 0,
569+
profileDurationUI: 0,
570+
uptime: 0,
571+
logBytes: 500,
572+
},
573+
};
574+
575+
expect(getOnDemandBudget(budget, DataCategory.LOG_BYTE)).toBe(500);
576+
});
577+
578+
it('returns total budget for LOG_BYTE category when in shared mode', function () {
579+
const budget: OnDemandBudgets = {
580+
budgetMode: OnDemandBudgetMode.SHARED,
581+
sharedMaxBudget: 1000,
582+
};
583+
584+
expect(getOnDemandBudget(budget, DataCategory.LOG_BYTE)).toBe(1000);
585+
});
586+
});

static/gsApp/views/onDemandBudgets/utils.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export function parseOnDemandBudgets(
6363
profileDurationBudget: 0,
6464
profileDurationUIBudget: 0,
6565
uptimeBudget: 0,
66+
logBytesBudget: 0,
6667
// Spread the calculated values over the defaults
6768
...categoryBudgets,
6869
budgets: parsedBudgets,
@@ -150,10 +151,7 @@ function getBudgetMode(budget: OnDemandBudgets) {
150151
}
151152

152153
export function getOnDemandBudget(budget: OnDemandBudgets, dataCategory: DataCategory) {
153-
if (
154-
budget.budgetMode === OnDemandBudgetMode.PER_CATEGORY &&
155-
dataCategory in budget.budgets
156-
) {
154+
if (budget.budgetMode === OnDemandBudgetMode.PER_CATEGORY) {
157155
return budget.budgets[dataCategory] ?? 0;
158156
}
159157
return getTotalBudget(budget);
@@ -256,6 +254,7 @@ export function convertOnDemandBudget(
256254
uptime: 0,
257255
profileDuration: 0,
258256
profileDurationUI: 0,
257+
logBytes: 0,
259258
};
260259

261260
if (currentOnDemandBudget.budgetMode === OnDemandBudgetMode.PER_CATEGORY) {
@@ -288,6 +287,7 @@ export function convertOnDemandBudget(
288287
uptimeBudget: 0,
289288
profileDurationBudget: 0,
290289
profileDurationUIBudget: 0,
290+
logBytesBudget: 0,
291291
// Spread the calculated values over the defaults
292292
...categoryBudgets,
293293
budgets: newBudgets,

0 commit comments

Comments
 (0)