data.tsx 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. import {Location} from 'history';
  2. import {COL_WIDTH_UNDEFINED} from 'sentry/components/gridEditable';
  3. import {wrapQueryInWildcards} from 'sentry/components/performance/searchBar';
  4. import {t} from 'sentry/locale';
  5. import {NewQuery, Organization, Project, SelectValue} from 'sentry/types';
  6. import EventView from 'sentry/utils/discover/eventView';
  7. import {WEB_VITAL_DETAILS} from 'sentry/utils/performance/vitals/constants';
  8. import {decodeScalar} from 'sentry/utils/queryString';
  9. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  10. import {getCurrentTrendParameter} from 'sentry/views/performance/trends/utils';
  11. export const DEFAULT_STATS_PERIOD = '7d';
  12. export const DEFAULT_PROJECT_THRESHOLD_METRIC = 'duration';
  13. export const DEFAULT_PROJECT_THRESHOLD = 300;
  14. export const COLUMN_TITLES = ['endpoint', 'tpm', 'p50(duration)', 'p95(duration)'];
  15. const TOKEN_KEYS_SUPPORTED_IN_LIMITED_SEARCH = ['transaction'];
  16. export const getDefaultStatsPeriod = (organization: Organization) => {
  17. if (organization?.features?.includes('performance-landing-page-stats-period')) {
  18. return '14d';
  19. }
  20. return DEFAULT_STATS_PERIOD;
  21. };
  22. export enum PERFORMANCE_TERM {
  23. TPM = 'tpm',
  24. THROUGHPUT = 'throughput',
  25. FAILURE_RATE = 'failureRate',
  26. P50 = 'p50',
  27. P75 = 'p75',
  28. P95 = 'p95',
  29. P99 = 'p99',
  30. LCP = 'lcp',
  31. FCP = 'fcp',
  32. FID = 'fid',
  33. CLS = 'cls',
  34. STATUS_BREAKDOWN = 'statusBreakdown',
  35. DURATION_DISTRIBUTION = 'durationDistribution',
  36. USER_MISERY = 'userMisery',
  37. APDEX = 'apdex',
  38. APP_START_COLD = 'appStartCold',
  39. APP_START_WARM = 'appStartWarm',
  40. SLOW_FRAMES = 'slowFrames',
  41. FROZEN_FRAMES = 'frozenFrames',
  42. STALL_PERCENTAGE = 'stallPercentage',
  43. MOST_ISSUES = 'mostIssues',
  44. MOST_ERRORS = 'mostErrors',
  45. SLOW_HTTP_SPANS = 'slowHTTPSpans',
  46. TIME_TO_FULL_DISPLAY = 'timeToFullDisplay',
  47. TIME_TO_INITIAL_DISPLAY = 'timeToInitialDisplay',
  48. }
  49. export type TooltipOption = SelectValue<string> & {
  50. tooltip: string;
  51. };
  52. export function getAxisOptions(organization: Organization): TooltipOption[] {
  53. return [
  54. {
  55. tooltip: getTermHelp(organization, PERFORMANCE_TERM.APDEX),
  56. value: 'apdex()',
  57. label: t('Apdex'),
  58. },
  59. {
  60. tooltip: getTermHelp(organization, PERFORMANCE_TERM.TPM),
  61. value: 'tpm()',
  62. label: t('Transactions Per Minute'),
  63. },
  64. {
  65. tooltip: getTermHelp(organization, PERFORMANCE_TERM.FAILURE_RATE),
  66. value: 'failure_rate()',
  67. label: t('Failure Rate'),
  68. },
  69. {
  70. tooltip: getTermHelp(organization, PERFORMANCE_TERM.P50),
  71. value: 'p50()',
  72. label: t('p50 Duration'),
  73. },
  74. {
  75. tooltip: getTermHelp(organization, PERFORMANCE_TERM.P95),
  76. value: 'p95()',
  77. label: t('p95 Duration'),
  78. },
  79. {
  80. tooltip: getTermHelp(organization, PERFORMANCE_TERM.P99),
  81. value: 'p99()',
  82. label: t('p99 Duration'),
  83. },
  84. ];
  85. }
  86. export type AxisOption = TooltipOption & {
  87. field: string;
  88. label: string;
  89. backupOption?: AxisOption;
  90. isDistribution?: boolean;
  91. isLeftDefault?: boolean;
  92. isRightDefault?: boolean;
  93. };
  94. export function getFrontendAxisOptions(organization: Organization): AxisOption[] {
  95. return [
  96. {
  97. tooltip: getTermHelp(organization, PERFORMANCE_TERM.LCP),
  98. value: `p75(lcp)`,
  99. label: t('LCP p75'),
  100. field: 'p75(measurements.lcp)',
  101. isLeftDefault: true,
  102. backupOption: {
  103. tooltip: getTermHelp(organization, PERFORMANCE_TERM.FCP),
  104. value: `p75(fcp)`,
  105. label: t('FCP p75'),
  106. field: 'p75(measurements.fcp)',
  107. },
  108. },
  109. {
  110. tooltip: getTermHelp(organization, PERFORMANCE_TERM.DURATION_DISTRIBUTION),
  111. value: 'lcp_distribution',
  112. label: t('LCP Distribution'),
  113. field: 'measurements.lcp',
  114. isDistribution: true,
  115. isRightDefault: true,
  116. backupOption: {
  117. tooltip: getTermHelp(organization, PERFORMANCE_TERM.DURATION_DISTRIBUTION),
  118. value: 'fcp_distribution',
  119. label: t('FCP Distribution'),
  120. field: 'measurements.fcp',
  121. isDistribution: true,
  122. },
  123. },
  124. {
  125. tooltip: getTermHelp(organization, PERFORMANCE_TERM.TPM),
  126. value: 'tpm()',
  127. label: t('Transactions Per Minute'),
  128. field: 'tpm()',
  129. },
  130. ];
  131. }
  132. export function getFrontendOtherAxisOptions(organization: Organization): AxisOption[] {
  133. return [
  134. {
  135. tooltip: getTermHelp(organization, PERFORMANCE_TERM.P50),
  136. value: `p50()`,
  137. label: t('Duration p50'),
  138. field: 'p50(transaction.duration)',
  139. },
  140. {
  141. tooltip: getTermHelp(organization, PERFORMANCE_TERM.P75),
  142. value: `p75()`,
  143. label: t('Duration p75'),
  144. field: 'p75(transaction.duration)',
  145. isLeftDefault: true,
  146. },
  147. {
  148. tooltip: getTermHelp(organization, PERFORMANCE_TERM.P95),
  149. value: `p95()`,
  150. label: t('Duration p95'),
  151. field: 'p95(transaction.duration)',
  152. },
  153. {
  154. tooltip: getTermHelp(organization, PERFORMANCE_TERM.DURATION_DISTRIBUTION),
  155. value: 'duration_distribution',
  156. label: t('Duration Distribution'),
  157. field: 'transaction.duration',
  158. isDistribution: true,
  159. isRightDefault: true,
  160. },
  161. ];
  162. }
  163. export function getBackendAxisOptions(organization: Organization): AxisOption[] {
  164. return [
  165. {
  166. tooltip: getTermHelp(organization, PERFORMANCE_TERM.P50),
  167. value: `p50()`,
  168. label: t('Duration p50'),
  169. field: 'p50(transaction.duration)',
  170. },
  171. {
  172. tooltip: getTermHelp(organization, PERFORMANCE_TERM.P75),
  173. value: `p75()`,
  174. label: t('Duration p75'),
  175. field: 'p75(transaction.duration)',
  176. isLeftDefault: true,
  177. },
  178. {
  179. tooltip: getTermHelp(organization, PERFORMANCE_TERM.P95),
  180. value: `p95()`,
  181. label: t('Duration p95'),
  182. field: 'p95(transaction.duration)',
  183. },
  184. {
  185. tooltip: getTermHelp(organization, PERFORMANCE_TERM.P99),
  186. value: `p99()`,
  187. label: t('Duration p99'),
  188. field: 'p99(transaction.duration)',
  189. },
  190. {
  191. tooltip: getTermHelp(organization, PERFORMANCE_TERM.TPM),
  192. value: 'tpm()',
  193. label: t('Transactions Per Minute'),
  194. field: 'tpm()',
  195. },
  196. {
  197. tooltip: getTermHelp(organization, PERFORMANCE_TERM.FAILURE_RATE),
  198. value: 'failure_rate()',
  199. label: t('Failure Rate'),
  200. field: 'failure_rate()',
  201. },
  202. {
  203. tooltip: getTermHelp(organization, PERFORMANCE_TERM.DURATION_DISTRIBUTION),
  204. value: 'duration_distribution',
  205. label: t('Duration Distribution'),
  206. field: 'transaction.duration',
  207. isDistribution: true,
  208. isRightDefault: true,
  209. },
  210. {
  211. tooltip: getTermHelp(organization, PERFORMANCE_TERM.APDEX),
  212. value: 'apdex()',
  213. label: t('Apdex'),
  214. field: 'apdex()',
  215. },
  216. ];
  217. }
  218. export function getMobileAxisOptions(organization: Organization): AxisOption[] {
  219. return [
  220. {
  221. tooltip: getTermHelp(organization, PERFORMANCE_TERM.APP_START_COLD),
  222. value: `p50(measurements.app_start_cold)`,
  223. label: t('Cold Start Duration p50'),
  224. field: 'p50(measurements.app_start_cold)',
  225. },
  226. {
  227. tooltip: getTermHelp(organization, PERFORMANCE_TERM.APP_START_COLD),
  228. value: `p75(measurements.app_start_cold)`,
  229. label: t('Cold Start Duration p75'),
  230. field: 'p75(measurements.app_start_cold)',
  231. isLeftDefault: true,
  232. },
  233. {
  234. tooltip: getTermHelp(organization, PERFORMANCE_TERM.APP_START_COLD),
  235. value: `p95(measurements.app_start_cold)`,
  236. label: t('Cold Start Duration p95'),
  237. field: 'p95(measurements.app_start_cold)',
  238. },
  239. {
  240. tooltip: getTermHelp(organization, PERFORMANCE_TERM.APP_START_COLD),
  241. value: `p99(measurements.app_start_cold)`,
  242. label: t('Cold Start Duration p99'),
  243. field: 'p99(measurements.app_start_cold)',
  244. },
  245. {
  246. tooltip: getTermHelp(organization, PERFORMANCE_TERM.DURATION_DISTRIBUTION),
  247. value: 'app_start_cold_distribution',
  248. label: t('Cold Start Distribution'),
  249. field: 'measurements.app_start_cold',
  250. isDistribution: true,
  251. isRightDefault: true,
  252. },
  253. {
  254. tooltip: getTermHelp(organization, PERFORMANCE_TERM.APP_START_WARM),
  255. value: `p50(measurements.app_start_warm)`,
  256. label: t('Warm Start Duration p50'),
  257. field: 'p50(measurements.app_start_warm)',
  258. },
  259. {
  260. tooltip: getTermHelp(organization, PERFORMANCE_TERM.APP_START_WARM),
  261. value: `p75(measurements.app_start_warm)`,
  262. label: t('Warm Start Duration p75'),
  263. field: 'p75(measurements.app_start_warm)',
  264. },
  265. {
  266. tooltip: getTermHelp(organization, PERFORMANCE_TERM.APP_START_WARM),
  267. value: `p95(measurements.app_start_warm)`,
  268. label: t('Warm Start Duration p95'),
  269. field: 'p95(measurements.app_start_warm)',
  270. },
  271. {
  272. tooltip: getTermHelp(organization, PERFORMANCE_TERM.APP_START_WARM),
  273. value: `p99(measurements.app_start_warm)`,
  274. label: t('Warm Start Duration p99'),
  275. field: 'p99(measurements.app_start_warm)',
  276. },
  277. {
  278. tooltip: getTermHelp(organization, PERFORMANCE_TERM.DURATION_DISTRIBUTION),
  279. value: 'app_start_warm_distribution',
  280. label: t('Warm Start Distribution'),
  281. field: 'measurements.app_start_warm',
  282. isDistribution: true,
  283. },
  284. {
  285. tooltip: getTermHelp(organization, PERFORMANCE_TERM.TPM),
  286. value: 'tpm()',
  287. label: t('Transactions Per Minute'),
  288. field: 'tpm()',
  289. },
  290. {
  291. tooltip: getTermHelp(organization, PERFORMANCE_TERM.FAILURE_RATE),
  292. value: 'failure_rate()',
  293. label: t('Failure Rate'),
  294. field: 'failure_rate()',
  295. },
  296. ];
  297. }
  298. type TermFormatter = (organization: Organization) => string;
  299. export const PERFORMANCE_TERMS: Record<PERFORMANCE_TERM, TermFormatter> = {
  300. tpm: () => t('TPM is the number of recorded transaction events per minute.'),
  301. throughput: () =>
  302. t('Throughput is the number of recorded transaction events per minute.'),
  303. failureRate: () =>
  304. t(
  305. 'Failure rate is the percentage of recorded transactions that had a known and unsuccessful status.'
  306. ),
  307. p50: () => t('p50 indicates the duration that 50% of transactions are faster than.'),
  308. p75: () => t('p75 indicates the duration that 75% of transactions are faster than.'),
  309. p95: () => t('p95 indicates the duration that 95% of transactions are faster than.'),
  310. p99: () => t('p99 indicates the duration that 99% of transactions are faster than.'),
  311. lcp: () =>
  312. t('Largest contentful paint (LCP) is a web vital meant to represent user load times'),
  313. fcp: () =>
  314. t('First contentful paint (FCP) is a web vital meant to represent user load times'),
  315. fid: () =>
  316. t(
  317. 'First input delay (FID) is a web vital representing load for the first user interaction on a page.'
  318. ),
  319. cls: () =>
  320. t(
  321. 'Cumulative layout shift (CLS) is a web vital measuring unexpected visual shifting a user experiences.'
  322. ),
  323. statusBreakdown: () =>
  324. t(
  325. 'The breakdown of transaction statuses. This may indicate what type of failure it is.'
  326. ),
  327. durationDistribution: () =>
  328. t(
  329. 'Distribution buckets counts of transactions at specifics times for your current date range'
  330. ),
  331. userMisery: () =>
  332. t(
  333. "User Misery is a score that represents the number of unique users who have experienced load times 4x the project's configured threshold. Adjust project threshold in project performance settings."
  334. ),
  335. apdex: () =>
  336. t(
  337. 'Apdex is the ratio of both satisfactory and tolerable response times to all response times. To adjust the tolerable threshold, go to project performance settings.'
  338. ),
  339. appStartCold: () =>
  340. t('Cold start is a measure of the application start up time from scratch.'),
  341. appStartWarm: () =>
  342. t('Warm start is a measure of the application start up time while still in memory.'),
  343. slowFrames: () => t('The count of the number of slow frames in the transaction.'),
  344. frozenFrames: () => t('The count of the number of frozen frames in the transaction.'),
  345. mostErrors: () => t('Transactions with the most associated errors.'),
  346. mostIssues: () => t('The most instances of an issue for a related transaction.'),
  347. slowHTTPSpans: () => t('The transactions with the slowest spans of a certain type.'),
  348. stallPercentage: () =>
  349. t(
  350. 'The percentage of the transaction duration in which the application is in a stalled state.'
  351. ),
  352. timeToFullDisplay: () =>
  353. t(
  354. 'The time between application launch and complete display of all resources and views'
  355. ),
  356. timeToInitialDisplay: () =>
  357. t('The time it takes for an application to produce its first frame'),
  358. };
  359. export function getTermHelp(
  360. organization: Organization,
  361. term: keyof typeof PERFORMANCE_TERMS
  362. ): string {
  363. if (!PERFORMANCE_TERMS.hasOwnProperty(term)) {
  364. return '';
  365. }
  366. return PERFORMANCE_TERMS[term](organization);
  367. }
  368. function prepareQueryForLandingPage(searchQuery, withStaticFilters) {
  369. const conditions = new MutableSearch(searchQuery);
  370. // If there is a bare text search, we want to treat it as a search
  371. // on the transaction name.
  372. if (conditions.freeText.length > 0) {
  373. const parsedFreeText = conditions.freeText.join(' ');
  374. // the query here is a user entered condition, no need to escape it
  375. conditions.setFilterValues(
  376. 'transaction',
  377. [wrapQueryInWildcards(parsedFreeText)],
  378. false
  379. );
  380. conditions.freeText = [];
  381. }
  382. if (withStaticFilters) {
  383. conditions.tokens = conditions.tokens.filter(
  384. token => token.key && TOKEN_KEYS_SUPPORTED_IN_LIMITED_SEARCH.includes(token.key)
  385. );
  386. }
  387. return conditions.formatString();
  388. }
  389. function generateGenericPerformanceEventView(
  390. location: Location,
  391. withStaticFilters: boolean,
  392. organization: Organization
  393. ): EventView {
  394. const {query} = location;
  395. const fields = [
  396. 'team_key_transaction',
  397. 'transaction',
  398. 'http.method',
  399. 'tpm()',
  400. 'p50()',
  401. 'p95()',
  402. 'project',
  403. ];
  404. const hasStartAndEnd = query.start && query.end;
  405. const savedQuery: NewQuery = {
  406. id: undefined,
  407. name: t('Performance'),
  408. query: 'event.type:transaction has:http.method',
  409. projects: [],
  410. fields,
  411. version: 2,
  412. };
  413. const widths = Array(savedQuery.fields.length).fill(COL_WIDTH_UNDEFINED);
  414. widths[savedQuery.fields.length - 1] = '110';
  415. savedQuery.widths = widths;
  416. if (!query.statsPeriod && !hasStartAndEnd) {
  417. savedQuery.range = getDefaultStatsPeriod(organization);
  418. }
  419. savedQuery.orderby = decodeScalar(query.sort, '-tpm');
  420. const searchQuery = decodeScalar(query.query, '');
  421. savedQuery.query = prepareQueryForLandingPage(searchQuery, withStaticFilters);
  422. const eventView = EventView.fromNewQueryWithLocation(savedQuery, location);
  423. eventView.additionalConditions.addFilterValues('event.type', ['transaction']);
  424. if (query.trendParameter) {
  425. // projects and projectIds are not necessary here since trendParameter will always
  426. // be present in location and will not be determined based on the project type
  427. const trendParameter = getCurrentTrendParameter(location, [], []);
  428. if (WEB_VITAL_DETAILS[trendParameter.column]) {
  429. eventView.additionalConditions.addFilterValues('has', [trendParameter.column]);
  430. }
  431. }
  432. return eventView;
  433. }
  434. export function generatePerformanceEventView(
  435. location: Location,
  436. _: Project[],
  437. {isTrends = false, withStaticFilters = false} = {},
  438. organization: Organization
  439. ) {
  440. const eventView = generateGenericPerformanceEventView(
  441. location,
  442. withStaticFilters,
  443. organization
  444. );
  445. if (isTrends) {
  446. return eventView;
  447. }
  448. return eventView;
  449. }