Skip to content
Open
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
102 changes: 102 additions & 0 deletions static/app/constants/index.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import {DATA_CATEGORY_INFO} from 'sentry/constants';
import {DataCategoryExact} from 'sentry/types/core';

describe('DATA_CATEGORY_INFO', () => {
describe('formatting property', () => {
it('all categories have formatting info', () => {
const categories = Object.values(DataCategoryExact);
for (const category of categories) {
expect(DATA_CATEGORY_INFO[category]).toBeDefined();
expect(DATA_CATEGORY_INFO[category].formatting).toBeDefined();
}
});

it('byte categories have correct formatting', () => {
const byteCategories = [DataCategoryExact.ATTACHMENT, DataCategoryExact.LOG_BYTE];

for (const category of byteCategories) {
const {formatting} = DATA_CATEGORY_INFO[category];
expect(formatting.unitType).toBe('bytes');
expect(formatting.reservedMultiplier).toBe(10 ** 9); // GIGABYTE
expect(formatting.bigNumUnit).toBe(1);
expect(formatting.priceFormatting.minIntegerDigits).toBe(2);
expect(formatting.priceFormatting.maxIntegerDigits).toBe(2);
}
});

it('attachment category uses non-abbreviated projected format', () => {
const {formatting} = DATA_CATEGORY_INFO[DataCategoryExact.ATTACHMENT];
expect(formatting.projectedAbbreviated).toBe(false);
});

it('log byte category uses abbreviated projected format', () => {
const {formatting} = DATA_CATEGORY_INFO[DataCategoryExact.LOG_BYTE];
expect(formatting.projectedAbbreviated).toBe(true);
});

it('duration hour categories have correct formatting', () => {
const durationCategories = [
DataCategoryExact.PROFILE_DURATION,
DataCategoryExact.PROFILE_DURATION_UI,
];

for (const category of durationCategories) {
const {formatting} = DATA_CATEGORY_INFO[category];
expect(formatting.unitType).toBe('durationHours');
expect(formatting.reservedMultiplier).toBe(3_600_000); // MILLISECONDS_IN_HOUR
expect(formatting.bigNumUnit).toBe(0);
expect(formatting.priceFormatting.minIntegerDigits).toBe(5);
expect(formatting.priceFormatting.maxIntegerDigits).toBe(7);
expect(formatting.projectedAbbreviated).toBe(true);
}
});

it('count categories have correct formatting', () => {
const countCategories = [
DataCategoryExact.ERROR,
DataCategoryExact.TRANSACTION,
DataCategoryExact.REPLAY,
DataCategoryExact.SPAN,
DataCategoryExact.MONITOR_SEAT,
];

for (const category of countCategories) {
const {formatting} = DATA_CATEGORY_INFO[category];
expect(formatting.unitType).toBe('count');
expect(formatting.reservedMultiplier).toBe(1);
expect(formatting.bigNumUnit).toBe(0);
expect(formatting.priceFormatting.minIntegerDigits).toBe(5);
expect(formatting.priceFormatting.maxIntegerDigits).toBe(7);
expect(formatting.projectedAbbreviated).toBe(true);
}
});

it('formatting unitType matches expected categories', () => {
const bytesCategories = [DataCategoryExact.ATTACHMENT, DataCategoryExact.LOG_BYTE];
const durationHoursCategories = [
DataCategoryExact.PROFILE_DURATION,
DataCategoryExact.PROFILE_DURATION_UI,
];

// Check bytes categories
for (const category of bytesCategories) {
expect(DATA_CATEGORY_INFO[category].formatting.unitType).toBe('bytes');
}

// Check duration categories
for (const category of durationHoursCategories) {
expect(DATA_CATEGORY_INFO[category].formatting.unitType).toBe('durationHours');
}

// All other categories should be count
const allCategories = Object.values(DataCategoryExact);
const nonCountCategories = [...bytesCategories, ...durationHoursCategories];

for (const category of allCategories) {
if (!nonCountCategories.includes(category)) {
expect(DATA_CATEGORY_INFO[category].formatting.unitType).toBe('count');
}
}
});
});
});
63 changes: 63 additions & 0 deletions static/app/constants/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,43 @@ const DEFAULT_STATS_INFO = {
};
const GIGABYTE = 10 ** 9;
const KILOBYTE = 10 ** 3;
const MILLISECONDS_IN_HOUR = 3_600_000;

/**
* Default formatting configuration for count-based categories.
* Most categories use this configuration.
*/
const DEFAULT_COUNT_FORMATTING = {
unitType: 'count' as const,
reservedMultiplier: 1,
bigNumUnit: 0 as const,
priceFormatting: {minIntegerDigits: 5, maxIntegerDigits: 7},
projectedAbbreviated: true,
};

/**
* Formatting configuration for byte-based categories (attachments, logs).
* Reserved values are in GB, raw values are in bytes.
*/
const BYTES_FORMATTING = {
unitType: 'bytes' as const,
reservedMultiplier: GIGABYTE,
bigNumUnit: 1 as const,
priceFormatting: {minIntegerDigits: 2, maxIntegerDigits: 2},
projectedAbbreviated: true,
};

/**
* Formatting configuration for duration-based categories (continuous profiling).
* Reserved values are in hours, raw values are in milliseconds.
*/
const DURATION_HOURS_FORMATTING = {
unitType: 'durationHours' as const,
reservedMultiplier: MILLISECONDS_IN_HOUR,
bigNumUnit: 0 as const,
priceFormatting: {minIntegerDigits: 5, maxIntegerDigits: 7},
projectedAbbreviated: true,
};

// https://github.com/getsentry/relay/blob/master/relay-base-schema/src/data_category.rs
export const DATA_CATEGORY_INFO = {
Expand All @@ -268,6 +305,7 @@ export const DATA_CATEGORY_INFO = {
...DEFAULT_STATS_INFO,
showExternalStats: true,
},
formatting: DEFAULT_COUNT_FORMATTING,
},
[DataCategoryExact.TRANSACTION]: {
name: DataCategoryExact.TRANSACTION,
Expand All @@ -283,6 +321,7 @@ export const DATA_CATEGORY_INFO = {
...DEFAULT_STATS_INFO,
showExternalStats: true,
},
formatting: DEFAULT_COUNT_FORMATTING,
},
[DataCategoryExact.ATTACHMENT]: {
name: DataCategoryExact.ATTACHMENT,
Expand All @@ -299,6 +338,7 @@ export const DATA_CATEGORY_INFO = {
showExternalStats: true,
yAxisMinInterval: 0.5 * GIGABYTE,
},
formatting: {...BYTES_FORMATTING, projectedAbbreviated: false},
},
[DataCategoryExact.PROFILE]: {
name: DataCategoryExact.PROFILE,
Expand All @@ -314,6 +354,7 @@ export const DATA_CATEGORY_INFO = {
...DEFAULT_STATS_INFO,
showExternalStats: true,
},
formatting: DEFAULT_COUNT_FORMATTING,
},
[DataCategoryExact.PROFILE_INDEXED]: {
name: DataCategoryExact.PROFILE_INDEXED,
Expand All @@ -325,6 +366,7 @@ export const DATA_CATEGORY_INFO = {
uid: 11,
isBilledCategory: false,
statsInfo: DEFAULT_STATS_INFO,
formatting: DEFAULT_COUNT_FORMATTING,
},
[DataCategoryExact.REPLAY]: {
name: DataCategoryExact.REPLAY,
Expand All @@ -340,6 +382,7 @@ export const DATA_CATEGORY_INFO = {
...DEFAULT_STATS_INFO,
showExternalStats: true,
},
formatting: DEFAULT_COUNT_FORMATTING,
},
[DataCategoryExact.USER_REPORT_V2]: {
name: DataCategoryExact.USER_REPORT_V2,
Expand All @@ -355,6 +398,7 @@ export const DATA_CATEGORY_INFO = {
...DEFAULT_STATS_INFO,
showExternalStats: true,
},
formatting: DEFAULT_COUNT_FORMATTING,
},
[DataCategoryExact.TRANSACTION_PROCESSED]: {
name: DataCategoryExact.TRANSACTION_PROCESSED,
Expand All @@ -369,6 +413,7 @@ export const DATA_CATEGORY_INFO = {
...DEFAULT_STATS_INFO,
showInternalStats: false,
},
formatting: DEFAULT_COUNT_FORMATTING,
},
[DataCategoryExact.TRANSACTION_INDEXED]: {
name: DataCategoryExact.TRANSACTION_INDEXED,
Expand All @@ -380,6 +425,7 @@ export const DATA_CATEGORY_INFO = {
uid: 9,
isBilledCategory: false,
statsInfo: DEFAULT_STATS_INFO,
formatting: DEFAULT_COUNT_FORMATTING,
},
[DataCategoryExact.MONITOR]: {
name: DataCategoryExact.MONITOR,
Expand All @@ -394,6 +440,7 @@ export const DATA_CATEGORY_INFO = {
...DEFAULT_STATS_INFO,
showExternalStats: true,
},
formatting: DEFAULT_COUNT_FORMATTING,
},
[DataCategoryExact.SPAN]: {
name: DataCategoryExact.SPAN,
Expand All @@ -409,6 +456,7 @@ export const DATA_CATEGORY_INFO = {
...DEFAULT_STATS_INFO,
showExternalStats: true,
},
formatting: DEFAULT_COUNT_FORMATTING,
},
[DataCategoryExact.MONITOR_SEAT]: {
name: DataCategoryExact.MONITOR_SEAT,
Expand All @@ -424,6 +472,7 @@ export const DATA_CATEGORY_INFO = {
...DEFAULT_STATS_INFO,
showInternalStats: false,
},
formatting: DEFAULT_COUNT_FORMATTING,
},
[DataCategoryExact.SPAN_INDEXED]: {
name: DataCategoryExact.SPAN_INDEXED,
Expand All @@ -436,6 +485,7 @@ export const DATA_CATEGORY_INFO = {
isBilledCategory: false,
docsUrl: 'https://docs.sentry.io/product/performance/',
statsInfo: DEFAULT_STATS_INFO,
formatting: DEFAULT_COUNT_FORMATTING,
},
[DataCategoryExact.PROFILE_DURATION]: {
name: DataCategoryExact.PROFILE_DURATION,
Expand All @@ -452,6 +502,7 @@ export const DATA_CATEGORY_INFO = {
...DEFAULT_STATS_INFO,
showExternalStats: true,
},
formatting: DURATION_HOURS_FORMATTING,
},
[DataCategoryExact.PROFILE_CHUNK]: {
name: DataCategoryExact.PROFILE_CHUNK,
Expand All @@ -463,6 +514,7 @@ export const DATA_CATEGORY_INFO = {
uid: 18,
isBilledCategory: false,
statsInfo: DEFAULT_STATS_INFO,
formatting: DEFAULT_COUNT_FORMATTING,
},
[DataCategoryExact.PROFILE_DURATION_UI]: {
name: DataCategoryExact.PROFILE_DURATION_UI,
Expand All @@ -479,6 +531,7 @@ export const DATA_CATEGORY_INFO = {
...DEFAULT_STATS_INFO,
showExternalStats: true,
},
formatting: DURATION_HOURS_FORMATTING,
},
[DataCategoryExact.PROFILE_CHUNK_UI]: {
name: DataCategoryExact.PROFILE_CHUNK_UI,
Expand All @@ -490,6 +543,7 @@ export const DATA_CATEGORY_INFO = {
uid: 26,
isBilledCategory: false,
statsInfo: DEFAULT_STATS_INFO,
formatting: DEFAULT_COUNT_FORMATTING,
},

[DataCategoryExact.UPTIME]: {
Expand All @@ -506,6 +560,7 @@ export const DATA_CATEGORY_INFO = {
...DEFAULT_STATS_INFO,
showInternalStats: false,
},
formatting: DEFAULT_COUNT_FORMATTING,
},
[DataCategoryExact.LOG_ITEM]: {
name: DataCategoryExact.LOG_ITEM,
Expand All @@ -520,6 +575,7 @@ export const DATA_CATEGORY_INFO = {
...DEFAULT_STATS_INFO,
showExternalStats: true,
},
formatting: DEFAULT_COUNT_FORMATTING,
},
[DataCategoryExact.LOG_BYTE]: {
name: DataCategoryExact.LOG_BYTE,
Expand All @@ -536,6 +592,7 @@ export const DATA_CATEGORY_INFO = {
showExternalStats: true,
yAxisMinInterval: 1 * KILOBYTE,
},
formatting: BYTES_FORMATTING,
},
[DataCategoryExact.SEER_AUTOFIX]: {
name: DataCategoryExact.SEER_AUTOFIX,
Expand All @@ -550,6 +607,7 @@ export const DATA_CATEGORY_INFO = {
...DEFAULT_STATS_INFO,
showExternalStats: true,
},
formatting: DEFAULT_COUNT_FORMATTING,
},
[DataCategoryExact.SEER_SCANNER]: {
name: DataCategoryExact.SEER_SCANNER,
Expand All @@ -564,6 +622,7 @@ export const DATA_CATEGORY_INFO = {
...DEFAULT_STATS_INFO,
showExternalStats: true,
},
formatting: DEFAULT_COUNT_FORMATTING,
},
[DataCategoryExact.PREVENT_USER]: {
name: DataCategoryExact.PREVENT_USER,
Expand All @@ -578,6 +637,7 @@ export const DATA_CATEGORY_INFO = {
...DEFAULT_STATS_INFO,
showExternalStats: false, // TODO(prevent): add external stats when ready
},
formatting: DEFAULT_COUNT_FORMATTING,
},
[DataCategoryExact.PREVENT_REVIEW]: {
name: DataCategoryExact.PREVENT_REVIEW,
Expand All @@ -592,6 +652,7 @@ export const DATA_CATEGORY_INFO = {
...DEFAULT_STATS_INFO,
showExternalStats: false, // TODO(prevent): add external stats when ready
},
formatting: DEFAULT_COUNT_FORMATTING,
},
[DataCategoryExact.TRACE_METRIC]: {
name: DataCategoryExact.TRACE_METRIC,
Expand All @@ -606,6 +667,7 @@ export const DATA_CATEGORY_INFO = {
...DEFAULT_STATS_INFO,
showExternalStats: true,
},
formatting: DEFAULT_COUNT_FORMATTING,
},
[DataCategoryExact.SEER_USER]: {
name: DataCategoryExact.SEER_USER,
Expand All @@ -620,6 +682,7 @@ export const DATA_CATEGORY_INFO = {
...DEFAULT_STATS_INFO,
showExternalStats: false, // TODO(seer): add external stats when ready
},
formatting: DEFAULT_COUNT_FORMATTING,
},
} as const satisfies Record<DataCategoryExact, DataCategoryInfo>;

Expand Down
Loading
Loading