projectPerformance.tsx 36 KB

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