backendOverviewPage.tsx 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. import styled from '@emotion/styled';
  2. import Feature from 'sentry/components/acl/feature';
  3. import {COL_WIDTH_UNDEFINED} from 'sentry/components/gridEditable';
  4. import * as Layout from 'sentry/components/layouts/thirds';
  5. import ExternalLink from 'sentry/components/links/externalLink';
  6. import {NoAccess} from 'sentry/components/noAccess';
  7. import {DatePageFilter} from 'sentry/components/organizations/datePageFilter';
  8. import {EnvironmentPageFilter} from 'sentry/components/organizations/environmentPageFilter';
  9. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  10. import {ProjectPageFilter} from 'sentry/components/organizations/projectPageFilter';
  11. import TransactionNameSearchBar from 'sentry/components/performance/searchBar';
  12. import * as TeamKeyTransactionManager from 'sentry/components/performance/teamKeyTransactionsManager';
  13. import {tct} from 'sentry/locale';
  14. import {trackAnalytics} from 'sentry/utils/analytics';
  15. import {
  16. canUseMetricsData,
  17. useMEPSettingContext,
  18. } from 'sentry/utils/performance/contexts/metricsEnhancedSetting';
  19. import {PageAlert, usePageAlert} from 'sentry/utils/performance/contexts/pageAlert';
  20. import {PerformanceDisplayProvider} from 'sentry/utils/performance/contexts/performanceDisplayContext';
  21. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  22. import {useLocation} from 'sentry/utils/useLocation';
  23. import {useNavigate} from 'sentry/utils/useNavigate';
  24. import useOrganization from 'sentry/utils/useOrganization';
  25. import useProjects from 'sentry/utils/useProjects';
  26. import {useUserTeams} from 'sentry/utils/useUserTeams';
  27. import * as ModuleLayout from 'sentry/views/insights/common/components/moduleLayout';
  28. import {ToolRibbon} from 'sentry/views/insights/common/components/ribbon';
  29. import {useOnboardingProject} from 'sentry/views/insights/common/queries/useOnboardingProject';
  30. import {ViewTrendsButton} from 'sentry/views/insights/common/viewTrendsButton';
  31. import {BackendHeader} from 'sentry/views/insights/pages/backend/backendPageHeader';
  32. import {BACKEND_LANDING_TITLE} from 'sentry/views/insights/pages/backend/settings';
  33. import {DomainOverviewPageProviders} from 'sentry/views/insights/pages/domainOverviewPageProviders';
  34. import {OVERVIEW_PAGE_ALLOWED_OPS as FRONTEND_OVERVIEW_PAGE_OPS} from 'sentry/views/insights/pages/frontend/settings';
  35. import {OVERVIEW_PAGE_ALLOWED_OPS as BACKEND_OVERVIEW_PAGE_OPS} from 'sentry/views/insights/pages/mobile/settings';
  36. import {
  37. generateBackendPerformanceEventView,
  38. USER_MISERY_TOOLTIP,
  39. } from 'sentry/views/performance/data';
  40. import {
  41. DoubleChartRow,
  42. TripleChartRow,
  43. } from 'sentry/views/performance/landing/widgets/components/widgetChartRow';
  44. import {filterAllowedChartsMetrics} from 'sentry/views/performance/landing/widgets/utils';
  45. import {PerformanceWidgetSetting} from 'sentry/views/performance/landing/widgets/widgetDefinitions';
  46. import Onboarding from 'sentry/views/performance/onboarding';
  47. import Table from 'sentry/views/performance/table';
  48. import {
  49. getTransactionSearchQuery,
  50. ProjectPerformanceType,
  51. } from 'sentry/views/performance/utils';
  52. const APDEX_TOOLTIP = tct(
  53. 'An industry-standard metric used to measure user satisfaction based on your application response times. [link:Learn more.]',
  54. {
  55. link: (
  56. <ExternalLink href="https://docs.sentry.io/product/performance/metrics/#apdex" />
  57. ),
  58. }
  59. );
  60. export const BACKEND_COLUMN_TITLES = [
  61. {title: 'http method'},
  62. {title: 'transaction'},
  63. {title: 'operation'},
  64. {title: 'project'},
  65. {title: 'tpm'},
  66. {title: 'p50()'},
  67. {title: 'p95()'},
  68. {title: 'failure rate'},
  69. {title: 'apdex', tooltip: APDEX_TOOLTIP},
  70. {title: 'users'},
  71. {title: 'user misery', tooltip: USER_MISERY_TOOLTIP},
  72. ];
  73. function BackendOverviewPage() {
  74. const organization = useOrganization();
  75. const location = useLocation();
  76. const {setPageError} = usePageAlert();
  77. const {projects} = useProjects();
  78. const onboardingProject = useOnboardingProject();
  79. const navigate = useNavigate();
  80. const {teams} = useUserTeams();
  81. const mepSetting = useMEPSettingContext();
  82. const withStaticFilters = canUseMetricsData(organization);
  83. const eventView = generateBackendPerformanceEventView(
  84. location,
  85. withStaticFilters,
  86. organization
  87. );
  88. // TODO - this should come from MetricsField / EAP fields
  89. eventView.fields = [
  90. {field: 'team_key_transaction'},
  91. {field: 'http.method'},
  92. {field: 'transaction'},
  93. {field: 'transaction.op'},
  94. {field: 'project'},
  95. {field: 'tpm()'},
  96. {field: 'p50()'},
  97. {field: 'p95()'},
  98. {field: 'failure_rate()'},
  99. {field: 'apdex()'},
  100. {field: 'count_unique(user)'},
  101. {field: 'count_miserable(user)'},
  102. {field: 'user_misery()'},
  103. ].map(field => ({...field, width: COL_WIDTH_UNDEFINED}));
  104. const doubleChartRowEventView = eventView.clone(); // some of the double chart rows rely on span metrics, so they can't be queried with the same tags/filters
  105. const disallowedOps = [
  106. ...new Set([...FRONTEND_OVERVIEW_PAGE_OPS, ...BACKEND_OVERVIEW_PAGE_OPS]),
  107. ];
  108. const existingQuery = new MutableSearch(eventView.query);
  109. existingQuery.addFilterValues('!transaction.op', disallowedOps);
  110. eventView.query = existingQuery.formatString();
  111. const showOnboarding = onboardingProject !== undefined;
  112. const doubleChartRowCharts = [
  113. PerformanceWidgetSetting.SLOW_HTTP_OPS,
  114. PerformanceWidgetSetting.SLOW_DB_OPS,
  115. ];
  116. const tripleChartRowCharts = filterAllowedChartsMetrics(
  117. organization,
  118. [
  119. PerformanceWidgetSetting.TPM_AREA,
  120. PerformanceWidgetSetting.DURATION_HISTOGRAM,
  121. PerformanceWidgetSetting.P50_DURATION_AREA,
  122. PerformanceWidgetSetting.P75_DURATION_AREA,
  123. PerformanceWidgetSetting.P95_DURATION_AREA,
  124. PerformanceWidgetSetting.P99_DURATION_AREA,
  125. PerformanceWidgetSetting.FAILURE_RATE_AREA,
  126. PerformanceWidgetSetting.APDEX_AREA,
  127. ],
  128. mepSetting
  129. );
  130. if (organization.features.includes('insights-initial-modules')) {
  131. doubleChartRowCharts.unshift(
  132. PerformanceWidgetSetting.HIGHEST_CACHE_MISS_RATE_TRANSACTIONS
  133. );
  134. doubleChartRowCharts.unshift(PerformanceWidgetSetting.MOST_TIME_CONSUMING_DOMAINS);
  135. doubleChartRowCharts.unshift(PerformanceWidgetSetting.MOST_TIME_SPENT_DB_QUERIES);
  136. }
  137. const sharedProps = {eventView, location, organization, withStaticFilters};
  138. const getFreeTextFromQuery = (query: string) => {
  139. const conditions = new MutableSearch(query);
  140. const transactionValues = conditions.getFilterValues('transaction');
  141. if (transactionValues.length) {
  142. return transactionValues[0];
  143. }
  144. if (conditions.freeText.length > 0) {
  145. // raw text query will be wrapped in wildcards in generatePerformanceEventView
  146. // so no need to wrap it here
  147. return conditions.freeText.join(' ');
  148. }
  149. return '';
  150. };
  151. function handleSearch(searchQuery: string) {
  152. trackAnalytics('performance.domains.backend.search', {organization});
  153. navigate({
  154. pathname: location.pathname,
  155. query: {
  156. ...location.query,
  157. cursor: undefined,
  158. query: String(searchQuery).trim() || undefined,
  159. isDefaultQuery: false,
  160. },
  161. });
  162. }
  163. const derivedQuery = getTransactionSearchQuery(location, eventView.query);
  164. return (
  165. <Feature
  166. features="performance-view"
  167. organization={organization}
  168. renderDisabled={NoAccess}
  169. >
  170. <BackendHeader
  171. headerTitle={BACKEND_LANDING_TITLE}
  172. headerActions={<ViewTrendsButton />}
  173. />
  174. <Layout.Body>
  175. <Layout.Main fullWidth>
  176. <ModuleLayout.Layout>
  177. <ModuleLayout.Full>
  178. <ToolRibbon>
  179. <PageFilterBar condensed>
  180. <ProjectPageFilter />
  181. <EnvironmentPageFilter />
  182. <DatePageFilter />
  183. </PageFilterBar>
  184. {!showOnboarding && (
  185. <StyledTransactionNameSearchBar
  186. organization={organization}
  187. eventView={eventView}
  188. onSearch={(query: string) => {
  189. handleSearch(query);
  190. }}
  191. query={getFreeTextFromQuery(derivedQuery)!}
  192. />
  193. )}
  194. </ToolRibbon>
  195. </ModuleLayout.Full>
  196. <PageAlert />
  197. <ModuleLayout.Full>
  198. {!showOnboarding && (
  199. <PerformanceDisplayProvider
  200. value={{performanceType: ProjectPerformanceType.BACKEND}}
  201. >
  202. <TeamKeyTransactionManager.Provider
  203. organization={organization}
  204. teams={teams}
  205. selectedTeams={['myteams']}
  206. selectedProjects={eventView.project.map(String)}
  207. >
  208. <DoubleChartRow
  209. allowedCharts={doubleChartRowCharts}
  210. {...sharedProps}
  211. eventView={doubleChartRowEventView}
  212. />
  213. <TripleChartRow
  214. allowedCharts={tripleChartRowCharts}
  215. {...sharedProps}
  216. />
  217. <Table
  218. projects={projects}
  219. columnTitles={BACKEND_COLUMN_TITLES}
  220. setError={setPageError}
  221. {...sharedProps}
  222. />
  223. </TeamKeyTransactionManager.Provider>
  224. </PerformanceDisplayProvider>
  225. )}
  226. {showOnboarding && (
  227. <Onboarding project={onboardingProject} organization={organization} />
  228. )}
  229. </ModuleLayout.Full>
  230. </ModuleLayout.Layout>
  231. </Layout.Main>
  232. </Layout.Body>
  233. </Feature>
  234. );
  235. }
  236. function BackendOverviewPageWithProviders() {
  237. return (
  238. <DomainOverviewPageProviders>
  239. <BackendOverviewPage />
  240. </DomainOverviewPageProviders>
  241. );
  242. }
  243. const StyledTransactionNameSearchBar = styled(TransactionNameSearchBar)`
  244. flex: 2;
  245. `;
  246. export default BackendOverviewPageWithProviders;