projectPerformance.tsx 35 KB

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