backendOverviewPage.tsx 9.3 KB

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