Skip to content

Commit 12f0348

Browse files
tobias-wilfertandrewshie-sentry
authored andcommitted
fix(outcomes): Make 'Too Large' outcome future proof (#87286)
1 parent b348855 commit 12f0348

File tree

3 files changed

+93
-86
lines changed

3 files changed

+93
-86
lines changed

static/app/views/organizationStats/getReasonGroupName.spec.ts

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,59 @@ import {ClientDiscardReason, getReasonGroupName} from './getReasonGroupName';
44

55
describe('getReasonGroupName', function () {
66
it('handles legacy too_large reason', function () {
7-
expect(getReasonGroupName(Outcome.INVALID, 'too_large')).toBe('too_large');
7+
expect(getReasonGroupName(Outcome.INVALID, 'too_large')).toBe('too_large_other');
88
});
99

10-
it('handles all new too_large reasons', function () {
10+
it('handles all new (visible) discard reasons', function () {
1111
const testCases: Array<[string, string]> = [
12-
['too_large_unknown', 'too_large'],
13-
['too_large_event', 'too_large_event'],
14-
['too_large_transaction', 'too_large_transaction'],
15-
['too_large_security', 'too_large_security'],
16-
['too_large_attachment', 'too_large_attachment'],
17-
['too_large_form_data', 'too_large_form_data'],
18-
['too_large_raw_security', 'too_large_raw_security'],
19-
['too_large_nel', 'too_large_nel'],
20-
['too_large_unreal_report', 'too_large_unreal_report'],
21-
['too_large_user_report', 'too_large_user_report'],
22-
['too_large_session', 'too_large_session'],
23-
['too_large_sessions', 'too_large_sessions'],
24-
['too_large_statsd', 'too_large_statsd'],
25-
['too_large_metric_buckets', 'too_large_metric_buckets'],
26-
['too_large_client_report', 'too_large_client_report'],
27-
['too_large_profile', 'too_large_profile'],
28-
['too_large_replay_event', 'too_large_replay_event'],
29-
['too_large_replay_recording', 'too_large_replay_recording'],
30-
['too_large_replay_video', 'too_large_replay_video'],
31-
['too_large_check_in', 'too_large_check_in'],
32-
['too_large_otel_log', 'too_large_otel_log'],
33-
['too_large_log', 'too_large_log'],
34-
['too_large_span', 'too_large_span'],
35-
['too_large_otel_span', 'too_large_otel_span'],
36-
['too_large_otel_traces_data', 'too_large_otel_traces_data'],
37-
['too_large_user_report_v2', 'too_large_user_report_v2'],
38-
['too_large_profile_chunk', 'too_large_profile_chunk'],
12+
['too_large:unknown', 'too_large_other'],
13+
['too_large:security', 'too_large_other'],
14+
['too_large:raw_security', 'too_large_other'],
15+
['too_large:statsd', 'too_large_other'],
16+
['too_large:metric_buckets', 'too_large_other'],
17+
['too_large:client_report', 'too_large_other'],
18+
['too_large:check_in', 'too_large_other'],
19+
['too_large:otel_traces_data', 'too_large_other'],
20+
21+
['too_large:event', 'too_large_event'],
22+
['too_large:transaction', 'too_large_transaction'],
23+
['too_large:attachment', 'too_large_attachment'],
24+
['too_large:form_data', 'too_large_form_data'],
25+
['too_large:nel', 'too_large_nel'],
26+
['too_large:unreal_report', 'too_large_unreal_report'],
27+
['too_large:user_report', 'too_large_user_report'],
28+
['too_large:user_report_v2', 'too_large_user_report'],
29+
['too_large:session', 'too_large_session'],
30+
['too_large:sessions', 'too_large_session'],
31+
['too_large:profile', 'too_large_profile'],
32+
['too_large:replay_event', 'too_large_replay'],
33+
['too_large:replay_recording', 'too_large_replay'],
34+
['too_large:replay_video', 'too_large_replay'],
35+
['too_large:otel_log', 'too_large_log'],
36+
['too_large:log', 'too_large_log'],
37+
['too_large:span', 'too_large_span'],
38+
['too_large:otel_span', 'too_large_span'],
39+
['too_large:profile_chunk', 'too_large_profile'],
3940
];
4041

4142
testCases.forEach(([input, expected]) => {
4243
expect(getReasonGroupName(Outcome.INVALID, input)).toBe(expected);
4344
});
4445
});
4546

46-
it('handles unknown too_large reasons', function () {
47-
expect(getReasonGroupName(Outcome.INVALID, 'too_large_future_type')).toBe('internal');
47+
it('handles all edge cases for reasons', function () {
48+
const testCases: Array<[string, string]> = [
49+
['too_large:invalid', 'too_large_other'],
50+
['too_large:strange:reason', 'too_large_other'],
51+
['to_large:raw_security', 'internal'],
52+
[':attachment', 'internal'],
53+
['', 'internal'],
54+
['too_large:future_reason', 'too_large_other'],
55+
];
56+
57+
testCases.forEach(([input, expected]) => {
58+
expect(getReasonGroupName(Outcome.INVALID, input)).toBe(expected);
59+
});
4860
});
4961

5062
it('handles other existing reason types', function () {

static/app/views/organizationStats/getReasonGroupName.ts

Lines changed: 49 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,26 @@ enum DiscardReason {
2525
PAYLOAD = 'payload',
2626
INVALID_COMPRESSION = 'invalid_compression',
2727
TOO_LARGE = 'too_large', // Left for backwards compatibility
28-
TOO_LARGE_UNKNOWN = 'too_large_unknown',
29-
TOO_LARGE_EVENT = 'too_large_event',
30-
TOO_LARGE_TRANSACTION = 'too_large_transaction',
31-
TOO_LARGE_SECURITY = 'too_large_security',
32-
TOO_LARGE_ATTACHMENT = 'too_large_attachment',
33-
TOO_LARGE_FORM_DATA = 'too_large_form_data',
34-
TOO_LARGE_RAW_SECURITY = 'too_large_raw_security',
35-
TOO_LARGE_NEL = 'too_large_nel',
36-
TOO_LARGE_UNREAL_REPORT = 'too_large_unreal_report',
37-
TOO_LARGE_USER_REPORT = 'too_large_user_report',
38-
TOO_LARGE_SESSION = 'too_large_session',
39-
TOO_LARGE_SESSIONS = 'too_large_sessions',
40-
TOO_LARGE_STATSD = 'too_large_statsd',
41-
TOO_LARGE_METRIC_BUCKETS = 'too_large_metric_buckets',
42-
TOO_LARGE_CLIENT_REPORT = 'too_large_client_report',
43-
TOO_LARGE_PROFILE = 'too_large_profile',
44-
TOO_LARGE_REPLAY_EVENT = 'too_large_replay_event',
45-
TOO_LARGE_REPLAY_RECORDING = 'too_large_replay_recording',
46-
TOO_LARGE_REPLAY_VIDEO = 'too_large_replay_video',
47-
TOO_LARGE_CHECK_IN = 'too_large_check_in',
48-
TOO_LARGE_OTEL_LOG = 'too_large_otel_log',
49-
TOO_LARGE_LOG = 'too_large_log',
50-
TOO_LARGE_SPAN = 'too_large_span',
51-
TOO_LARGE_OTEL_SPAN = 'too_large_otel_span',
52-
TOO_LARGE_OTEL_TRACES_DATA = 'too_large_otel_traces_data',
53-
TOO_LARGE_USER_REPORT_V2 = 'too_large_user_report_v2',
54-
TOO_LARGE_PROFILE_CHUNK = 'too_large_profile_chunk',
28+
// All the too_large we want to communicate to the end-user
29+
TOO_LARGE_EVENT = 'too_large:event',
30+
TOO_LARGE_TRANSACTION = 'too_large:transaction',
31+
TOO_LARGE_ATTACHMENT = 'too_large:attachment',
32+
TOO_LARGE_FORM_DATA = 'too_large:form_data',
33+
TOO_LARGE_NEL = 'too_large:nel',
34+
TOO_LARGE_UNREAL_REPORT = 'too_large:unreal_report',
35+
TOO_LARGE_USER_REPORT = 'too_large:user_report',
36+
TOO_LARGE_USER_REPORT_V2 = 'too_large:user_report_v2',
37+
TOO_LARGE_SESSION = 'too_large:session',
38+
TOO_LARGE_SESSIONS = 'too_large:sessions',
39+
TOO_LARGE_REPLAY_EVENT = 'too_large:replay_event',
40+
TOO_LARGE_REPLAY_RECORDING = 'too_large:replay_recording',
41+
TOO_LARGE_REPLAY_VIDEO = 'too_large:replay_video',
42+
TOO_LARGE_OTEL_LOG = 'too_large:otel_log',
43+
TOO_LARGE_LOG = 'too_large:log',
44+
TOO_LARGE_SPAN = 'too_large:span',
45+
TOO_LARGE_OTEL_SPAN = 'too_large:otel_span',
46+
TOO_LARGE_PROFILE_CHUNK = 'too_large:profile_chunk',
47+
TOO_LARGE_PROFILE = 'too_large:profile',
5548
MISSING_MINIDUMP_UPLOAD = 'missing_minidump_upload',
5649
INVALID_MINIDUMP = 'invalid_minidump',
5750
SECURITY_REPORT = 'security_report',
@@ -118,36 +111,29 @@ const invalidReasonsGroup: Record<string, DiscardReason[]> = {
118111
DiscardReason.INVALID_REPLAY_VIDEO,
119112
],
120113
payload: [DiscardReason.PAYLOAD, DiscardReason.INVALID_COMPRESSION],
121-
too_large: [
122-
DiscardReason.TOO_LARGE, // Left for backwards compatibility
123-
DiscardReason.TOO_LARGE_UNKNOWN,
124-
],
114+
too_large_other: [DiscardReason.TOO_LARGE],
125115
too_large_event: [DiscardReason.TOO_LARGE_EVENT],
126116
too_large_transaction: [DiscardReason.TOO_LARGE_TRANSACTION],
127-
too_large_security: [DiscardReason.TOO_LARGE_SECURITY],
128117
too_large_attachment: [DiscardReason.TOO_LARGE_ATTACHMENT],
129118
too_large_form_data: [DiscardReason.TOO_LARGE_FORM_DATA],
130-
too_large_raw_security: [DiscardReason.TOO_LARGE_RAW_SECURITY],
131119
too_large_nel: [DiscardReason.TOO_LARGE_NEL],
132120
too_large_unreal_report: [DiscardReason.TOO_LARGE_UNREAL_REPORT],
133-
too_large_user_report: [DiscardReason.TOO_LARGE_USER_REPORT],
134-
too_large_session: [DiscardReason.TOO_LARGE_SESSION],
135-
too_large_sessions: [DiscardReason.TOO_LARGE_SESSIONS],
136-
too_large_statsd: [DiscardReason.TOO_LARGE_STATSD],
137-
too_large_metric_buckets: [DiscardReason.TOO_LARGE_METRIC_BUCKETS],
138-
too_large_client_report: [DiscardReason.TOO_LARGE_CLIENT_REPORT],
139-
too_large_profile: [DiscardReason.TOO_LARGE_PROFILE],
140-
too_large_replay_event: [DiscardReason.TOO_LARGE_REPLAY_EVENT],
141-
too_large_replay_recording: [DiscardReason.TOO_LARGE_REPLAY_RECORDING],
142-
too_large_replay_video: [DiscardReason.TOO_LARGE_REPLAY_VIDEO],
143-
too_large_check_in: [DiscardReason.TOO_LARGE_CHECK_IN],
144-
too_large_otel_log: [DiscardReason.TOO_LARGE_OTEL_LOG],
145-
too_large_log: [DiscardReason.TOO_LARGE_LOG],
146-
too_large_span: [DiscardReason.TOO_LARGE_SPAN],
147-
too_large_otel_span: [DiscardReason.TOO_LARGE_OTEL_SPAN],
148-
too_large_otel_traces_data: [DiscardReason.TOO_LARGE_OTEL_TRACES_DATA],
149-
too_large_user_report_v2: [DiscardReason.TOO_LARGE_USER_REPORT_V2],
150-
too_large_profile_chunk: [DiscardReason.TOO_LARGE_PROFILE_CHUNK],
121+
too_large_user_report: [
122+
DiscardReason.TOO_LARGE_USER_REPORT,
123+
DiscardReason.TOO_LARGE_USER_REPORT_V2,
124+
],
125+
too_large_session: [DiscardReason.TOO_LARGE_SESSION, DiscardReason.TOO_LARGE_SESSIONS],
126+
too_large_replay: [
127+
DiscardReason.TOO_LARGE_REPLAY_EVENT,
128+
DiscardReason.TOO_LARGE_REPLAY_RECORDING,
129+
DiscardReason.TOO_LARGE_REPLAY_VIDEO,
130+
],
131+
too_large_log: [DiscardReason.TOO_LARGE_OTEL_LOG, DiscardReason.TOO_LARGE_LOG],
132+
too_large_span: [DiscardReason.TOO_LARGE_SPAN, DiscardReason.TOO_LARGE_OTEL_SPAN],
133+
too_large_profile: [
134+
DiscardReason.TOO_LARGE_PROFILE_CHUNK,
135+
DiscardReason.TOO_LARGE_PROFILE,
136+
],
151137
minidump: [DiscardReason.MISSING_MINIDUMP_UPLOAD, DiscardReason.INVALID_MINIDUMP],
152138
security_report: [DiscardReason.SECURITY_REPORT, DiscardReason.SECURITY_REPORT_TYPE],
153139
unreal: [DiscardReason.PROCESS_UNREAL],
@@ -160,12 +146,21 @@ const invalidReasonsGroup: Record<string, DiscardReason[]> = {
160146
sampling: [DiscardReason.TRANSACTION_SAMPLED],
161147
};
162148

163-
function getInvalidReasonGroupName(reason: DiscardReason): string {
149+
function getInvalidReasonGroupName(reason: string): string {
150+
// 1. Check if there is a direct match in the `invalidReasonsGroup`
151+
for (const [group, reasons] of Object.entries(invalidReasonsGroup)) {
152+
if (reasons.includes(reason as DiscardReason)) {
153+
return group;
154+
}
155+
}
156+
// 2. If there is no direct match check if there is a match for the baseReason
157+
const baseReason = reason.split(':')[0];
164158
for (const [group, reasons] of Object.entries(invalidReasonsGroup)) {
165-
if (reasons.includes(reason)) {
159+
if (reasons.includes(baseReason as DiscardReason)) {
166160
return group;
167161
}
168162
}
163+
// 3. Else just return internal
169164
return 'internal';
170165
}
171166

@@ -214,7 +209,7 @@ function getClientDiscardReasonGroupName(reason: ClientDiscardReason): string {
214209
export function getReasonGroupName(outcome: string | number, reason: string): string {
215210
switch (outcome) {
216211
case Outcome.INVALID:
217-
return getInvalidReasonGroupName(reason as DiscardReason);
212+
return getInvalidReasonGroupName(reason);
218213
case Outcome.CARDINALITY_LIMITED:
219214
case Outcome.RATE_LIMITED:
220215
case Outcome.ABUSE:

static/app/views/organizationStats/utils.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ describe('formatUsageWithUnits', function () {
166166

167167
it('Correctly groups invalid outcome reasons', function () {
168168
expect(getReasonGroupName('invalid', 'duplicate_item')).toBe('invalid_request');
169-
expect(getReasonGroupName('invalid', 'too_large')).toBe('too_large');
169+
expect(getReasonGroupName('invalid', 'too_large')).toBe('too_large_other');
170170
expect(getReasonGroupName('invalid', 'some_other_reason')).toBe('internal');
171171
});
172172
});

0 commit comments

Comments
 (0)