projectPerformance.tsx 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060
  1. import {Fragment} from 'react';
  2. import {RouteComponentProps} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import {addErrorMessage} from 'sentry/actionCreators/indicator';
  5. import Access from 'sentry/components/acl/access';
  6. import Feature from 'sentry/components/acl/feature';
  7. import {Button} from 'sentry/components/button';
  8. import Confirm from 'sentry/components/confirm';
  9. import FieldWrapper from 'sentry/components/forms/fieldGroup/fieldWrapper';
  10. import Form from 'sentry/components/forms/form';
  11. import JsonForm from 'sentry/components/forms/jsonForm';
  12. import {Field, JsonFormObject} from 'sentry/components/forms/types';
  13. import ExternalLink from 'sentry/components/links/externalLink';
  14. import LoadingIndicator from 'sentry/components/loadingIndicator';
  15. import Panel from 'sentry/components/panels/panel';
  16. import PanelFooter from 'sentry/components/panels/panelFooter';
  17. import PanelHeader from 'sentry/components/panels/panelHeader';
  18. import PanelItem from 'sentry/components/panels/panelItem';
  19. import {t, tct} from 'sentry/locale';
  20. import ConfigStore from 'sentry/stores/configStore';
  21. import ProjectsStore from 'sentry/stores/projectsStore';
  22. import {space} from 'sentry/styles/space';
  23. import {IssueTitle, IssueType, Organization, Project, Scope} from 'sentry/types';
  24. import {DynamicSamplingBiasType} from 'sentry/types/sampling';
  25. import {trackAnalytics} from 'sentry/utils/analytics';
  26. import {formatPercentage} from 'sentry/utils/formatters';
  27. import {safeGetQsParam} from 'sentry/utils/integrationUtil';
  28. import {isActiveSuperuser} from 'sentry/utils/isActiveSuperuser';
  29. import routeTitleGen from 'sentry/utils/routeTitle';
  30. import DeprecatedAsyncView from 'sentry/views/deprecatedAsyncView';
  31. import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader';
  32. import PermissionAlert from 'sentry/views/settings/project/permissionAlert';
  33. // These labels need to be exported so that they can be used in audit logs
  34. export const retentionPrioritiesLabels = {
  35. boostLatestRelease: t('Prioritize new releases'),
  36. boostEnvironments: t('Prioritize dev environments'),
  37. boostLowVolumeTransactions: t('Prioritize low-volume transactions'),
  38. ignoreHealthChecks: t('Deprioritize health checks'),
  39. };
  40. export const allowedDurationValues: number[] = [
  41. 50, 60, 70, 80, 90, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1500, 2000, 2500,
  42. 3000, 3500, 4000, 4500, 5000, 5500, 6000, 6500, 7000, 7500, 8000, 8500, 9000, 9500,
  43. 10000,
  44. ]; // In milliseconds
  45. export const allowedPercentageValues: number[] = [
  46. 0.2, 0.25, 0.3, 0.33, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95,
  47. ];
  48. export const allowedSizeValues: number[] = [
  49. 50000, 100000, 200000, 300000, 400000, 500000, 512000, 600000, 700000, 800000, 900000,
  50. 1000000, 2000000, 3000000, 4000000, 5000000, 6000000, 7000000, 8000000, 9000000,
  51. 10000000,
  52. ]; // 50kb to 10MB in bytes
  53. export const projectDetectorSettingsId = 'detector-threshold-settings';
  54. type ProjectPerformanceSettings = {[key: string]: number | boolean};
  55. enum DetectorConfigAdmin {
  56. N_PLUS_DB_ENABLED = 'n_plus_one_db_queries_detection_enabled',
  57. SLOW_DB_ENABLED = 'slow_db_queries_detection_enabled',
  58. DB_MAIN_THREAD_ENABLED = 'db_on_main_thread_detection_enabled',
  59. FILE_IO_ENABLED = 'file_io_on_main_thread_detection_enabled',
  60. CONSECUTIVE_DB_ENABLED = 'consecutive_db_queries_detection_enabled',
  61. RENDER_BLOCK_ASSET_ENABLED = 'large_render_blocking_asset_detection_enabled',
  62. UNCOMPRESSED_ASSET_ENABLED = 'uncompressed_assets_detection_enabled',
  63. LARGE_HTTP_PAYLOAD_ENABLED = 'large_http_payload_detection_enabled',
  64. N_PLUS_ONE_API_CALLS_ENABLED = 'n_plus_one_api_calls_detection_enabled',
  65. CONSECUTIVE_HTTP_ENABLED = 'consecutive_http_spans_detection_enabled',
  66. HTTP_OVERHEAD_ENABLED = 'http_overhead_detection_enabled',
  67. }
  68. export enum DetectorConfigCustomer {
  69. SLOW_DB_DURATION = 'slow_db_query_duration_threshold',
  70. N_PLUS_DB_DURATION = 'n_plus_one_db_duration_threshold',
  71. N_PLUS_API_CALLS_DURATION = 'n_plus_one_api_calls_total_duration_threshold',
  72. RENDER_BLOCKING_ASSET_RATIO = 'render_blocking_fcp_ratio',
  73. LARGE_HTT_PAYLOAD_SIZE = 'large_http_payload_size_threshold',
  74. DB_ON_MAIN_THREAD_DURATION = 'db_on_main_thread_duration_threshold',
  75. FILE_IO_MAIN_THREAD_DURATION = 'file_io_on_main_thread_duration_threshold',
  76. UNCOMPRESSED_ASSET_DURATION = 'uncompressed_asset_duration_threshold',
  77. UNCOMPRESSED_ASSET_SIZE = 'uncompressed_asset_size_threshold',
  78. CONSECUTIVE_DB_MIN_TIME_SAVED = 'consecutive_db_min_time_saved_threshold',
  79. CONSECUTIVE_HTTP_MIN_TIME_SAVED = 'consecutive_http_spans_min_time_saved_threshold',
  80. HTTP_OVERHEAD_REQUEST_DELAY = 'http_request_delay_threshold',
  81. }
  82. type RouteParams = {orgId: string; projectId: string};
  83. type Props = RouteComponentProps<{projectId: string}, {}> & {
  84. organization: Organization;
  85. project: Project;
  86. };
  87. type ProjectThreshold = {
  88. metric: string;
  89. threshold: string;
  90. editedBy?: string;
  91. id?: string;
  92. };
  93. type State = DeprecatedAsyncView['state'] & {
  94. threshold: ProjectThreshold;
  95. };
  96. class ProjectPerformance extends DeprecatedAsyncView<Props, State> {
  97. getTitle() {
  98. const {projectId} = this.props.params;
  99. return routeTitleGen(t('Performance'), projectId, false);
  100. }
  101. getProjectEndpoint({orgId, projectId}: RouteParams) {
  102. return `/projects/${orgId}/${projectId}/`;
  103. }
  104. getPerformanceIssuesEndpoint({orgId, projectId}: RouteParams) {
  105. return `/projects/${orgId}/${projectId}/performance-issues/configure/`;
  106. }
  107. getEndpoints(): ReturnType<DeprecatedAsyncView['getEndpoints']> {
  108. const {params, organization} = this.props;
  109. const {projectId} = params;
  110. const endpoints: ReturnType<DeprecatedAsyncView['getEndpoints']> = [
  111. [
  112. 'threshold',
  113. `/projects/${organization.slug}/${projectId}/transaction-threshold/configure/`,
  114. ],
  115. ['project', `/projects/${organization.slug}/${projectId}/`],
  116. ];
  117. if (organization.features.includes('project-performance-settings-admin')) {
  118. const performanceIssuesEndpoint = [
  119. 'performance_issue_settings',
  120. `/projects/${organization.slug}/${projectId}/performance-issues/configure/`,
  121. ] as [string, string];
  122. endpoints.push(performanceIssuesEndpoint);
  123. }
  124. return endpoints;
  125. }
  126. getRetentionPrioritiesData(...data) {
  127. return {
  128. dynamicSamplingBiases: Object.entries(data[1].form).map(([key, value]) => ({
  129. id: key,
  130. active: value,
  131. })),
  132. };
  133. }
  134. handleDelete = () => {
  135. const {projectId} = this.props.params;
  136. const {organization} = this.props;
  137. this.setState({
  138. loading: true,
  139. });
  140. this.api.request(
  141. `/projects/${organization.slug}/${projectId}/transaction-threshold/configure/`,
  142. {
  143. method: 'DELETE',
  144. success: () => {
  145. trackAnalytics('performance_views.project_transaction_threshold.clear', {
  146. organization,
  147. });
  148. },
  149. complete: () => this.fetchData(),
  150. }
  151. );
  152. };
  153. handleThresholdsReset = () => {
  154. const {projectId} = this.props.params;
  155. const {organization, project} = this.props;
  156. this.setState({
  157. loading: true,
  158. });
  159. trackAnalytics('performance_views.project_issue_detection_thresholds_reset', {
  160. organization,
  161. project_slug: project.slug,
  162. });
  163. this.api.request(
  164. `/projects/${organization.slug}/${projectId}/performance-issues/configure/`,
  165. {
  166. method: 'DELETE',
  167. complete: () => this.fetchData(),
  168. }
  169. );
  170. };
  171. getEmptyMessage() {
  172. return t('There is no threshold set for this project.');
  173. }
  174. renderLoading() {
  175. return (
  176. <LoadingIndicatorContainer>
  177. <LoadingIndicator />
  178. </LoadingIndicatorContainer>
  179. );
  180. }
  181. get formFields(): Field[] {
  182. const fields: Field[] = [
  183. {
  184. name: 'metric',
  185. type: 'select',
  186. label: t('Calculation Method'),
  187. options: [
  188. {value: 'duration', label: t('Transaction Duration')},
  189. {value: 'lcp', label: t('Largest Contentful Paint')},
  190. ],
  191. help: tct(
  192. 'This determines which duration is used to set your thresholds. By default, we use transaction duration which measures the entire length of the transaction. You can also set this to use a [link:Web Vital].',
  193. {
  194. link: (
  195. <ExternalLink href="https://docs.sentry.io/product/performance/web-vitals/" />
  196. ),
  197. }
  198. ),
  199. },
  200. {
  201. name: 'threshold',
  202. type: 'string',
  203. label: t('Response Time Threshold (ms)'),
  204. placeholder: t('300'),
  205. help: tct(
  206. 'Define what a satisfactory response time is based on the calculation method above. This will affect how your [link1:Apdex] and [link2:User Misery] thresholds are calculated. For example, misery will be 4x your satisfactory response time.',
  207. {
  208. link1: (
  209. <ExternalLink href="https://docs.sentry.io/performance-monitoring/performance/metrics/#apdex" />
  210. ),
  211. link2: (
  212. <ExternalLink href="https://docs.sentry.io/product/performance/metrics/#user-misery" />
  213. ),
  214. }
  215. ),
  216. },
  217. ];
  218. return fields;
  219. }
  220. get areAllConfigurationsDisabled(): boolean {
  221. let result = true;
  222. Object.values(DetectorConfigAdmin).forEach(threshold => {
  223. result = result && !this.state.performance_issue_settings[threshold];
  224. });
  225. return result;
  226. }
  227. get performanceIssueFormFields(): Field[] {
  228. return [
  229. {
  230. name: 'performanceIssueCreationRate',
  231. type: 'range',
  232. label: t('Performance Issue Creation Rate'),
  233. min: 0.0,
  234. max: 1.0,
  235. step: 0.01,
  236. defaultValue: 0,
  237. help: t(
  238. 'This determines the rate at which performance issues are created. A rate of 0.0 will disable performance issue creation.'
  239. ),
  240. },
  241. {
  242. name: 'performanceIssueSendToPlatform',
  243. type: 'boolean',
  244. label: t('Send Occurrences To Platform'),
  245. defaultValue: false,
  246. help: t(
  247. 'This determines whether performance issue occurrences are sent to the issues platform.'
  248. ),
  249. },
  250. {
  251. name: 'performanceIssueCreationThroughPlatform',
  252. type: 'boolean',
  253. label: t('Create Issues Through Issues Platform'),
  254. defaultValue: false,
  255. help: t(
  256. 'This determines whether performance issues are created through the issues platform.'
  257. ),
  258. },
  259. ];
  260. }
  261. get performanceIssueDetectorAdminFields(): Field[] {
  262. return [
  263. {
  264. name: DetectorConfigAdmin.N_PLUS_DB_ENABLED,
  265. type: 'boolean',
  266. label: t('N+1 DB Queries Detection Enabled'),
  267. defaultValue: true,
  268. onChange: value =>
  269. this.setState({
  270. performance_issue_settings: {
  271. ...this.state.performance_issue_settings,
  272. n_plus_one_db_queries_detection_enabled: value,
  273. },
  274. }),
  275. },
  276. {
  277. name: DetectorConfigAdmin.SLOW_DB_ENABLED,
  278. type: 'boolean',
  279. label: t('Slow DB Queries Detection Enabled'),
  280. defaultValue: true,
  281. onChange: value =>
  282. this.setState({
  283. performance_issue_settings: {
  284. ...this.state.performance_issue_settings,
  285. slow_db_queries_detection_enabled: value,
  286. },
  287. }),
  288. },
  289. {
  290. name: DetectorConfigAdmin.N_PLUS_ONE_API_CALLS_ENABLED,
  291. type: 'boolean',
  292. label: t('N+1 API Calls Detection Enabled'),
  293. defaultValue: true,
  294. onChange: value =>
  295. this.setState({
  296. performance_issue_settings: {
  297. ...this.state.performance_issue_settings,
  298. n_plus_one_api_calls_detection_enabled: value,
  299. },
  300. }),
  301. },
  302. {
  303. name: DetectorConfigAdmin.RENDER_BLOCK_ASSET_ENABLED,
  304. type: 'boolean',
  305. label: t('Large Render Blocking Asset Detection Enabled'),
  306. defaultValue: true,
  307. onChange: value =>
  308. this.setState({
  309. performance_issue_settings: {
  310. ...this.state.performance_issue_settings,
  311. large_render_blocking_asset_detection_enabled: value,
  312. },
  313. }),
  314. },
  315. {
  316. name: DetectorConfigAdmin.CONSECUTIVE_DB_ENABLED,
  317. type: 'boolean',
  318. label: t('Consecutive DB Queries Detection Enabled'),
  319. defaultValue: true,
  320. onChange: value =>
  321. this.setState({
  322. performance_issue_settings: {
  323. ...this.state.performance_issue_settings,
  324. consecutive_db_queries_detection_enabled: value,
  325. },
  326. }),
  327. },
  328. {
  329. name: DetectorConfigAdmin.LARGE_HTTP_PAYLOAD_ENABLED,
  330. type: 'boolean',
  331. label: t('Large HTTP Payload Detection Enabled'),
  332. defaultValue: true,
  333. onChange: value =>
  334. this.setState({
  335. performance_issue_settings: {
  336. ...this.state.performance_issue_settings,
  337. large_http_payload_detection_enabled: value,
  338. },
  339. }),
  340. },
  341. {
  342. name: DetectorConfigAdmin.DB_MAIN_THREAD_ENABLED,
  343. type: 'boolean',
  344. label: t('DB On Main Thread Detection Enabled'),
  345. defaultValue: true,
  346. onChange: value =>
  347. this.setState({
  348. performance_issue_settings: {
  349. ...this.state.performance_issue_settings,
  350. db_on_main_thread_detection_enabled: value,
  351. },
  352. }),
  353. },
  354. {
  355. name: DetectorConfigAdmin.FILE_IO_ENABLED,
  356. type: 'boolean',
  357. label: t('File I/O on Main Thread Detection Enabled'),
  358. defaultValue: true,
  359. onChange: value =>
  360. this.setState({
  361. performance_issue_settings: {
  362. ...this.state.performance_issue_settings,
  363. file_io_on_main_thread_detection_enabled: value,
  364. },
  365. }),
  366. },
  367. {
  368. name: DetectorConfigAdmin.UNCOMPRESSED_ASSET_ENABLED,
  369. type: 'boolean',
  370. label: t('Uncompressed Assets Detection Enabled'),
  371. defaultValue: true,
  372. onChange: value =>
  373. this.setState({
  374. performance_issue_settings: {
  375. ...this.state.performance_issue_settings,
  376. uncompressed_assets_detection_enabled: value,
  377. },
  378. }),
  379. },
  380. {
  381. name: DetectorConfigAdmin.CONSECUTIVE_HTTP_ENABLED,
  382. type: 'boolean',
  383. label: t('Consecutive HTTP Detection Enabled'),
  384. defaultValue: true,
  385. onChange: value =>
  386. this.setState({
  387. performance_issue_settings: {
  388. ...this.state.performance_issue_settings,
  389. consecutive_http_spans_detection_enabled: value,
  390. },
  391. }),
  392. },
  393. {
  394. name: DetectorConfigAdmin.HTTP_OVERHEAD_ENABLED,
  395. type: 'boolean',
  396. label: t('HTTP/1.1 Overhead Enabled'),
  397. defaultValue: true,
  398. onChange: value =>
  399. this.setState({
  400. performance_issue_settings: {
  401. ...this.state.performance_issue_settings,
  402. [DetectorConfigAdmin.HTTP_OVERHEAD_ENABLED]: value,
  403. },
  404. }),
  405. },
  406. ];
  407. }
  408. project_owner_detector_settings = (hasAccess: boolean): JsonFormObject[] => {
  409. const performanceSettings: ProjectPerformanceSettings =
  410. this.state.performance_issue_settings;
  411. const supportMail = ConfigStore.get('supportEmail');
  412. const disabledReason = hasAccess
  413. ? tct(
  414. 'Detection of this issue has been disabled. Contact our support team at [link:support@sentry.io].',
  415. {
  416. link: <ExternalLink href={'mailto:' + supportMail} />,
  417. }
  418. )
  419. : null;
  420. const formatDuration = (value: number | ''): string => {
  421. return value ? (value < 1000 ? `${value}ms` : `${value / 1000}s`) : '';
  422. };
  423. const formatSize = (value: number | ''): string => {
  424. return value
  425. ? value < 1000000
  426. ? `${value / 1000}KB`
  427. : `${value / 1000000}MB`
  428. : '';
  429. };
  430. const formatFrameRate = (value: number | ''): string => {
  431. const fps = value && 1000 / value;
  432. return fps ? `${Math.floor(fps / 5) * 5}fps` : '';
  433. };
  434. const issueType = safeGetQsParam('issueType');
  435. return [
  436. {
  437. title: IssueTitle.PERFORMANCE_N_PLUS_ONE_DB_QUERIES,
  438. fields: [
  439. {
  440. name: DetectorConfigCustomer.N_PLUS_DB_DURATION,
  441. type: 'range',
  442. label: t('Minimum Total Duration'),
  443. defaultValue: 100, // ms
  444. help: t(
  445. 'Setting the value to 100ms, means that an eligible event will be detected as a N+1 DB Query Issue only if the total duration of the involved spans exceeds 100ms'
  446. ),
  447. allowedValues: allowedDurationValues,
  448. disabled: !(
  449. hasAccess && performanceSettings[DetectorConfigAdmin.N_PLUS_DB_ENABLED]
  450. ),
  451. tickValues: [0, allowedDurationValues.length - 1],
  452. showTickLabels: true,
  453. formatLabel: formatDuration,
  454. flexibleControlStateSize: true,
  455. disabledReason,
  456. },
  457. ],
  458. initiallyCollapsed: issueType !== IssueType.PERFORMANCE_N_PLUS_ONE_DB_QUERIES,
  459. },
  460. {
  461. title: IssueTitle.PERFORMANCE_SLOW_DB_QUERY,
  462. fields: [
  463. {
  464. name: DetectorConfigCustomer.SLOW_DB_DURATION,
  465. type: 'range',
  466. label: t('Minimum Duration'),
  467. defaultValue: 1000, // ms
  468. help: t(
  469. 'Setting the value to 1s, means that an eligible event will be detected as a Slow DB Query Issue only if the duration of the involved db span exceeds 1s.'
  470. ),
  471. tickValues: [0, allowedDurationValues.slice(5).length - 1],
  472. showTickLabels: true,
  473. allowedValues: allowedDurationValues.slice(5),
  474. disabled: !(
  475. hasAccess && performanceSettings[DetectorConfigAdmin.SLOW_DB_ENABLED]
  476. ),
  477. formatLabel: formatDuration,
  478. disabledReason,
  479. },
  480. ],
  481. initiallyCollapsed: issueType !== IssueType.PERFORMANCE_SLOW_DB_QUERY,
  482. },
  483. {
  484. title: IssueTitle.PERFORMANCE_N_PLUS_ONE_API_CALLS,
  485. fields: [
  486. {
  487. name: DetectorConfigCustomer.N_PLUS_API_CALLS_DURATION,
  488. type: 'range',
  489. label: t('Minimum Total Duration'),
  490. defaultValue: 300, // ms
  491. help: t(
  492. 'Setting the value to 300ms, means that an eligible event will be detected as a N+1 API Calls Issue only if the total duration of the involved spans exceeds 300ms'
  493. ),
  494. allowedValues: allowedDurationValues.slice(5),
  495. disabled: !(
  496. hasAccess &&
  497. performanceSettings[DetectorConfigAdmin.N_PLUS_ONE_API_CALLS_ENABLED]
  498. ),
  499. tickValues: [0, allowedDurationValues.slice(5).length - 1],
  500. showTickLabels: true,
  501. formatLabel: formatDuration,
  502. flexibleControlStateSize: true,
  503. disabledReason,
  504. },
  505. ],
  506. initiallyCollapsed: issueType !== IssueType.PERFORMANCE_N_PLUS_ONE_API_CALLS,
  507. },
  508. {
  509. title: IssueTitle.PERFORMANCE_RENDER_BLOCKING_ASSET,
  510. fields: [
  511. {
  512. name: DetectorConfigCustomer.RENDER_BLOCKING_ASSET_RATIO,
  513. type: 'range',
  514. label: t('Minimum FCP Ratio'),
  515. defaultValue: 0.33,
  516. help: t(
  517. 'Setting the value to 33%, means that an eligible event will be detected as a Large Render Blocking Asset Issue only if the duration of the involved span is at least 33% of First Contentful Paint (FCP).'
  518. ),
  519. allowedValues: allowedPercentageValues,
  520. tickValues: [0, allowedPercentageValues.length - 1],
  521. showTickLabels: true,
  522. disabled: !(
  523. hasAccess &&
  524. performanceSettings[DetectorConfigAdmin.RENDER_BLOCK_ASSET_ENABLED]
  525. ),
  526. formatLabel: value => value && formatPercentage(value),
  527. disabledReason,
  528. },
  529. ],
  530. initiallyCollapsed: issueType !== IssueType.PERFORMANCE_RENDER_BLOCKING_ASSET,
  531. },
  532. {
  533. title: IssueTitle.PERFORMANCE_LARGE_HTTP_PAYLOAD,
  534. fields: [
  535. {
  536. name: DetectorConfigCustomer.LARGE_HTT_PAYLOAD_SIZE,
  537. type: 'range',
  538. label: t('Minimum Size'),
  539. defaultValue: 1000000, // 1MB in bytes
  540. help: t(
  541. 'Setting the value to 1MB, means that an eligible event will be detected as a Large HTTP Payload Issue only if the involved HTTP span has a payload size that exceeds 1MB.'
  542. ),
  543. tickValues: [0, allowedSizeValues.slice(1).length - 1],
  544. showTickLabels: true,
  545. allowedValues: allowedSizeValues.slice(1),
  546. disabled: !(
  547. hasAccess &&
  548. performanceSettings[DetectorConfigAdmin.LARGE_HTTP_PAYLOAD_ENABLED]
  549. ),
  550. formatLabel: formatSize,
  551. disabledReason,
  552. },
  553. ],
  554. initiallyCollapsed: issueType !== IssueType.PERFORMANCE_LARGE_HTTP_PAYLOAD,
  555. },
  556. {
  557. title: IssueTitle.PERFORMANCE_DB_MAIN_THREAD,
  558. fields: [
  559. {
  560. name: DetectorConfigCustomer.DB_ON_MAIN_THREAD_DURATION,
  561. type: 'range',
  562. label: t('Frame Rate Drop'),
  563. defaultValue: 16, // ms
  564. help: t(
  565. 'Setting the value to 60fps, means that an eligible event will be detected as a DB on Main Thread Issue only if database spans on the main thread cause frame rate to drop below 60fps.'
  566. ),
  567. tickValues: [0, 3],
  568. showTickLabels: true,
  569. allowedValues: [10, 16, 33, 50], // representation of 100 to 20 fps in milliseconds
  570. disabled: !(
  571. hasAccess && performanceSettings[DetectorConfigAdmin.DB_MAIN_THREAD_ENABLED]
  572. ),
  573. formatLabel: formatFrameRate,
  574. disabledReason,
  575. },
  576. ],
  577. initiallyCollapsed: issueType !== IssueType.PERFORMANCE_DB_MAIN_THREAD,
  578. },
  579. {
  580. title: IssueTitle.PERFORMANCE_FILE_IO_MAIN_THREAD,
  581. fields: [
  582. {
  583. name: DetectorConfigCustomer.FILE_IO_MAIN_THREAD_DURATION,
  584. type: 'range',
  585. label: t('Frame Rate Drop'),
  586. defaultValue: 16, // ms
  587. help: t(
  588. 'Setting the value to 60fps, means that an eligible event will be detected as a File I/O on Main Thread Issue only if File I/O spans on the main thread cause frame rate to drop below 60fps.'
  589. ),
  590. tickValues: [0, 3],
  591. showTickLabels: true,
  592. allowedValues: [10, 16, 33, 50], // representation of 100, 60, 30, 20 fps in milliseconds
  593. disabled: !(
  594. hasAccess && performanceSettings[DetectorConfigAdmin.FILE_IO_ENABLED]
  595. ),
  596. formatLabel: formatFrameRate,
  597. disabledReason,
  598. },
  599. ],
  600. initiallyCollapsed: issueType !== IssueType.PERFORMANCE_FILE_IO_MAIN_THREAD,
  601. },
  602. {
  603. title: IssueTitle.PERFORMANCE_CONSECUTIVE_DB_QUERIES,
  604. fields: [
  605. {
  606. name: DetectorConfigCustomer.CONSECUTIVE_DB_MIN_TIME_SAVED,
  607. type: 'range',
  608. label: t('Minimum Time Saved'),
  609. defaultValue: 100, // ms
  610. help: t(
  611. 'Setting the value to 100ms, means that an eligible event will be detected as a Consecutive DB Queries Issue only if the time saved by parallelizing the queries exceeds 100ms.'
  612. ),
  613. tickValues: [0, allowedDurationValues.slice(0, 23).length - 1],
  614. showTickLabels: true,
  615. allowedValues: allowedDurationValues.slice(0, 23),
  616. disabled: !(
  617. hasAccess && performanceSettings[DetectorConfigAdmin.CONSECUTIVE_DB_ENABLED]
  618. ),
  619. formatLabel: formatDuration,
  620. disabledReason,
  621. },
  622. ],
  623. initiallyCollapsed: issueType !== IssueType.PERFORMANCE_CONSECUTIVE_DB_QUERIES,
  624. },
  625. {
  626. title: IssueTitle.PERFORMANCE_UNCOMPRESSED_ASSET,
  627. fields: [
  628. {
  629. name: DetectorConfigCustomer.UNCOMPRESSED_ASSET_SIZE,
  630. type: 'range',
  631. label: t('Minimum Size'),
  632. defaultValue: 512000, // in kilobytes
  633. help: t(
  634. 'Setting the value to 512KB, means that an eligible event will be detected as an Uncompressed Asset Issue only if the size of the uncompressed asset being transferred exceeds 512KB.'
  635. ),
  636. tickValues: [0, allowedSizeValues.slice(1).length - 1],
  637. showTickLabels: true,
  638. allowedValues: allowedSizeValues.slice(1),
  639. disabled: !(
  640. hasAccess &&
  641. performanceSettings[DetectorConfigAdmin.UNCOMPRESSED_ASSET_ENABLED]
  642. ),
  643. formatLabel: formatSize,
  644. disabledReason,
  645. },
  646. {
  647. name: DetectorConfigCustomer.UNCOMPRESSED_ASSET_DURATION,
  648. type: 'range',
  649. label: t('Minimum Duration'),
  650. defaultValue: 500, // in ms
  651. help: t(
  652. 'Setting the value to 500ms, means that an eligible event will be detected as an Uncompressed Asset Issue only if the duration of the span responsible for transferring the uncompressed asset exceeds 500ms.'
  653. ),
  654. tickValues: [0, allowedDurationValues.slice(5).length - 1],
  655. showTickLabels: true,
  656. allowedValues: allowedDurationValues.slice(5),
  657. disabled: !(
  658. hasAccess &&
  659. performanceSettings[DetectorConfigAdmin.UNCOMPRESSED_ASSET_ENABLED]
  660. ),
  661. formatLabel: formatDuration,
  662. disabledReason,
  663. },
  664. ],
  665. initiallyCollapsed: issueType !== IssueType.PERFORMANCE_UNCOMPRESSED_ASSET,
  666. },
  667. {
  668. title: IssueTitle.PERFORMANCE_CONSECUTIVE_HTTP,
  669. fields: [
  670. {
  671. name: DetectorConfigCustomer.CONSECUTIVE_HTTP_MIN_TIME_SAVED,
  672. type: 'range',
  673. label: t('Minimum Time Saved'),
  674. defaultValue: 2000, // in ms
  675. help: t(
  676. 'Setting the value to 2s, means that an eligible event will be detected as a Consecutive HTTP Issue only if the time saved by parallelizing the http spans exceeds 2s.'
  677. ),
  678. tickValues: [0, allowedDurationValues.slice(14).length - 1],
  679. showTickLabels: true,
  680. allowedValues: allowedDurationValues.slice(14),
  681. disabled: !(
  682. hasAccess &&
  683. performanceSettings[DetectorConfigAdmin.CONSECUTIVE_HTTP_ENABLED]
  684. ),
  685. formatLabel: formatDuration,
  686. disabledReason,
  687. },
  688. ],
  689. initiallyCollapsed: issueType !== IssueType.PERFORMANCE_CONSECUTIVE_HTTP,
  690. },
  691. {
  692. title: IssueTitle.PERFORMANCE_HTTP_OVERHEAD,
  693. fields: [
  694. {
  695. name: DetectorConfigCustomer.HTTP_OVERHEAD_REQUEST_DELAY,
  696. type: 'range',
  697. label: t('Request Delay'),
  698. defaultValue: 500, // in ms
  699. help: t(
  700. 'Setting the value to 500ms, means that the HTTP request delay (wait time) will have to exceed 500ms for an HTTP Overhead issue to be created.'
  701. ),
  702. tickValues: [0, allowedDurationValues.slice(6, 17).length - 1],
  703. showTickLabels: true,
  704. allowedValues: allowedDurationValues.slice(6, 17),
  705. disabled: !(
  706. hasAccess && performanceSettings[DetectorConfigAdmin.HTTP_OVERHEAD_ENABLED]
  707. ),
  708. formatLabel: formatDuration,
  709. disabledReason,
  710. },
  711. ],
  712. initiallyCollapsed: issueType !== IssueType.PERFORMANCE_HTTP_OVERHEAD,
  713. },
  714. ];
  715. };
  716. get retentionPrioritiesFormFields(): Field[] {
  717. return [
  718. {
  719. name: 'boostLatestRelease',
  720. type: 'boolean',
  721. label: retentionPrioritiesLabels.boostLatestRelease,
  722. help: t(
  723. 'Captures more transactions for your new releases as they are being adopted'
  724. ),
  725. getData: this.getRetentionPrioritiesData,
  726. },
  727. {
  728. name: 'boostEnvironments',
  729. type: 'boolean',
  730. label: retentionPrioritiesLabels.boostEnvironments,
  731. help: t(
  732. 'Captures more traces from environments that contain "debug", "dev", "local", "qa", and "test"'
  733. ),
  734. getData: this.getRetentionPrioritiesData,
  735. },
  736. {
  737. name: 'boostLowVolumeTransactions',
  738. type: 'boolean',
  739. label: retentionPrioritiesLabels.boostLowVolumeTransactions,
  740. help: t("Balance high-volume endpoints so they don't drown out low-volume ones"),
  741. getData: this.getRetentionPrioritiesData,
  742. },
  743. {
  744. name: 'ignoreHealthChecks',
  745. type: 'boolean',
  746. label: retentionPrioritiesLabels.ignoreHealthChecks,
  747. help: t('Captures fewer of your health checks transactions'),
  748. getData: this.getRetentionPrioritiesData,
  749. },
  750. ];
  751. }
  752. get initialData() {
  753. const {threshold} = this.state;
  754. return {
  755. threshold: threshold.threshold,
  756. metric: threshold.metric,
  757. };
  758. }
  759. renderBody() {
  760. const {organization, project} = this.props;
  761. const endpoint = `/projects/${organization.slug}/${project.slug}/transaction-threshold/configure/`;
  762. const requiredScopes: Scope[] = ['project:write'];
  763. const params = {orgId: organization.slug, projectId: project.slug};
  764. const projectEndpoint = this.getProjectEndpoint(params);
  765. const performanceIssuesEndpoint = this.getPerformanceIssuesEndpoint(params);
  766. const isSuperUser = isActiveSuperuser();
  767. return (
  768. <Fragment>
  769. <SettingsPageHeader title={t('Performance')} />
  770. <PermissionAlert project={project} />
  771. <Form
  772. saveOnBlur
  773. allowUndo
  774. initialData={this.initialData}
  775. apiMethod="POST"
  776. apiEndpoint={endpoint}
  777. onSubmitSuccess={resp => {
  778. const initial = this.initialData;
  779. const changedThreshold = initial.metric === resp.metric;
  780. trackAnalytics('performance_views.project_transaction_threshold.change', {
  781. organization,
  782. from: changedThreshold ? initial.threshold : initial.metric,
  783. to: changedThreshold ? resp.threshold : resp.metric,
  784. key: changedThreshold ? 'threshold' : 'metric',
  785. });
  786. this.setState({threshold: resp});
  787. }}
  788. >
  789. <Access access={requiredScopes} project={project}>
  790. {({hasAccess}) => (
  791. <JsonForm
  792. title={t('General')}
  793. fields={this.formFields}
  794. disabled={!hasAccess}
  795. renderFooter={() => (
  796. <Actions>
  797. <Button onClick={() => this.handleDelete()}>{t('Reset All')}</Button>
  798. </Actions>
  799. )}
  800. />
  801. )}
  802. </Access>
  803. </Form>
  804. <Feature features={['organizations:dynamic-sampling']}>
  805. <Form
  806. saveOnBlur
  807. allowUndo
  808. initialData={
  809. project.dynamicSamplingBiases?.reduce((acc, bias) => {
  810. acc[bias.id] = bias.active;
  811. return acc;
  812. }, {}) ?? {}
  813. }
  814. onSubmitSuccess={(response, _instance, id, change) => {
  815. ProjectsStore.onUpdateSuccess(response);
  816. trackAnalytics(
  817. change?.new === true
  818. ? 'dynamic_sampling_settings.priority_enabled'
  819. : 'dynamic_sampling_settings.priority_disabled',
  820. {
  821. organization,
  822. project_id: project.id,
  823. id: id as DynamicSamplingBiasType,
  824. }
  825. );
  826. }}
  827. apiMethod="PUT"
  828. apiEndpoint={projectEndpoint}
  829. >
  830. <Access access={requiredScopes} project={project}>
  831. {({hasAccess}) => (
  832. <JsonForm
  833. title={t('Retention Priorities')}
  834. fields={this.retentionPrioritiesFormFields}
  835. disabled={!hasAccess}
  836. renderFooter={() => (
  837. <Actions>
  838. <Button
  839. external
  840. href="https://docs.sentry.io/product/performance/performance-at-scale/"
  841. >
  842. {t('Read docs')}
  843. </Button>
  844. </Actions>
  845. )}
  846. />
  847. )}
  848. </Access>
  849. </Form>
  850. </Feature>
  851. <Fragment>
  852. <Feature features={['organizations:performance-issues-dev']}>
  853. <Form
  854. saveOnBlur
  855. allowUndo
  856. initialData={{
  857. performanceIssueCreationRate:
  858. this.state.project.performanceIssueCreationRate,
  859. performanceIssueSendToPlatform:
  860. this.state.project.performanceIssueSendToPlatform,
  861. performanceIssueCreationThroughPlatform:
  862. this.state.project.performanceIssueCreationThroughPlatform,
  863. }}
  864. apiMethod="PUT"
  865. apiEndpoint={projectEndpoint}
  866. >
  867. <Access access={requiredScopes} project={project}>
  868. {({hasAccess}) => (
  869. <JsonForm
  870. title={t('Performance Issues - All')}
  871. fields={this.performanceIssueFormFields}
  872. disabled={!hasAccess}
  873. />
  874. )}
  875. </Access>
  876. </Form>
  877. </Feature>
  878. <Feature features={['organizations:project-performance-settings-admin']}>
  879. {isSuperUser && (
  880. <Form
  881. saveOnBlur
  882. allowUndo
  883. initialData={this.state.performance_issue_settings}
  884. apiMethod="PUT"
  885. onSubmitError={error => {
  886. if (error.status === 403) {
  887. addErrorMessage(
  888. t(
  889. 'This action requires active super user access. Please re-authenticate to make changes.'
  890. )
  891. );
  892. }
  893. }}
  894. apiEndpoint={performanceIssuesEndpoint}
  895. >
  896. <JsonForm
  897. title={t(
  898. '### INTERNAL ONLY ### - Performance Issues Admin Detector Settings'
  899. )}
  900. fields={this.performanceIssueDetectorAdminFields}
  901. disabled={!isSuperUser}
  902. />
  903. </Form>
  904. )}
  905. <Form
  906. allowUndo
  907. initialData={this.state.performance_issue_settings}
  908. apiMethod="PUT"
  909. apiEndpoint={performanceIssuesEndpoint}
  910. saveOnBlur
  911. onSubmitSuccess={(option: {[key: string]: number}) => {
  912. const [threshold_key, threshold_value] = Object.entries(option)[0];
  913. trackAnalytics(
  914. 'performance_views.project_issue_detection_threshold_changed',
  915. {
  916. organization,
  917. project_slug: project.slug,
  918. threshold_key,
  919. threshold_value,
  920. }
  921. );
  922. }}
  923. >
  924. <Access access={requiredScopes} project={project}>
  925. {({hasAccess}) => (
  926. <div id={projectDetectorSettingsId}>
  927. <StyledPanelHeader>
  928. {t('Performance Issues - Detector Threshold Settings')}
  929. </StyledPanelHeader>
  930. <StyledJsonForm
  931. forms={this.project_owner_detector_settings(hasAccess)}
  932. collapsible
  933. />
  934. <StyledPanelFooter>
  935. <Actions>
  936. <Confirm
  937. message={t(
  938. 'Are you sure you wish to reset all detector thresholds?'
  939. )}
  940. onConfirm={() => this.handleThresholdsReset()}
  941. disabled={!hasAccess || this.areAllConfigurationsDisabled}
  942. >
  943. <Button>{t('Reset All Thresholds')}</Button>
  944. </Confirm>
  945. </Actions>
  946. </StyledPanelFooter>
  947. </div>
  948. )}
  949. </Access>
  950. </Form>
  951. </Feature>
  952. </Fragment>
  953. </Fragment>
  954. );
  955. }
  956. }
  957. const Actions = styled(PanelItem)`
  958. justify-content: flex-end;
  959. `;
  960. const StyledPanelHeader = styled(PanelHeader)`
  961. border: 1px solid ${p => p.theme.border};
  962. border-bottom: none;
  963. `;
  964. const StyledJsonForm = styled(JsonForm)`
  965. ${Panel} {
  966. margin-bottom: 0;
  967. border-radius: 0;
  968. border-bottom: 0;
  969. }
  970. ${FieldWrapper} {
  971. border-top: 1px solid ${p => p.theme.border};
  972. }
  973. ${FieldWrapper} + ${FieldWrapper} {
  974. border-top: 0;
  975. }
  976. ${Panel} + ${Panel} {
  977. border-top: 1px solid ${p => p.theme.border};
  978. }
  979. ${PanelHeader} {
  980. border-bottom: 0;
  981. text-transform: none;
  982. margin-bottom: 0;
  983. background: none;
  984. padding: ${space(3)} ${space(2)};
  985. }
  986. `;
  987. const StyledPanelFooter = styled(PanelFooter)`
  988. background: ${p => p.theme.background};
  989. border: 1px solid ${p => p.theme.border};
  990. border-radius: 0 0 calc(${p => p.theme.panelBorderRadius} - 1px)
  991. calc(${p => p.theme.panelBorderRadius} - 1px);
  992. ${Actions} {
  993. padding: ${space(1.5)};
  994. }
  995. `;
  996. const LoadingIndicatorContainer = styled('div')`
  997. margin: 18px 18px 0;
  998. `;
  999. export default ProjectPerformance;