httpLandingPage.tsx 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. import React, {Fragment} from 'react';
  2. import {Breadcrumbs} from 'sentry/components/breadcrumbs';
  3. import ButtonBar from 'sentry/components/buttonBar';
  4. import FeedbackWidgetButton from 'sentry/components/feedback/widget/feedbackWidgetButton';
  5. import * as Layout from 'sentry/components/layouts/thirds';
  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 {PageHeadingQuestionTooltip} from 'sentry/components/pageHeadingQuestionTooltip';
  11. import SearchBar from 'sentry/components/searchBar';
  12. import {t} from 'sentry/locale';
  13. import {browserHistory} from 'sentry/utils/browserHistory';
  14. import {decodeScalar, decodeSorts} from 'sentry/utils/queryString';
  15. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  16. import useLocationQuery from 'sentry/utils/url/useLocationQuery';
  17. import {useLocation} from 'sentry/utils/useLocation';
  18. import useOrganization from 'sentry/utils/useOrganization';
  19. import {useOnboardingProject} from 'sentry/views/performance/browser/webVitals/utils/useOnboardingProject';
  20. import {DurationChart} from 'sentry/views/performance/http/charts/durationChart';
  21. import {ResponseRateChart} from 'sentry/views/performance/http/charts/responseRateChart';
  22. import {ThroughputChart} from 'sentry/views/performance/http/charts/throughputChart';
  23. import {Referrer} from 'sentry/views/performance/http/referrers';
  24. import {
  25. BASE_FILTERS,
  26. MODULE_DESCRIPTION,
  27. MODULE_DOC_LINK,
  28. MODULE_TITLE,
  29. } from 'sentry/views/performance/http/settings';
  30. import {
  31. DomainsTable,
  32. isAValidSort,
  33. } from 'sentry/views/performance/http/tables/domainsTable';
  34. import * as ModuleLayout from 'sentry/views/performance/moduleLayout';
  35. import {ModulePageProviders} from 'sentry/views/performance/modulePageProviders';
  36. import Onboarding from 'sentry/views/performance/onboarding';
  37. import {useModuleBreadcrumbs} from 'sentry/views/performance/utils/useModuleBreadcrumbs';
  38. import {useSynchronizeCharts} from 'sentry/views/starfish/components/chart';
  39. import {useSpanMetrics} from 'sentry/views/starfish/queries/useDiscover';
  40. import {useSpanMetricsSeries} from 'sentry/views/starfish/queries/useDiscoverSeries';
  41. import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';
  42. export function HTTPLandingPage() {
  43. const organization = useOrganization();
  44. const location = useLocation();
  45. const onboardingProject = useOnboardingProject();
  46. const sortField = decodeScalar(location.query?.[QueryParameterNames.DOMAINS_SORT]);
  47. // TODO: Pull this using `useLocationQuery` below
  48. const sort = decodeSorts(sortField).filter(isAValidSort).at(0) ?? DEFAULT_SORT;
  49. const query = useLocationQuery({
  50. fields: {
  51. 'span.domain': decodeScalar,
  52. },
  53. });
  54. const chartFilters = {
  55. ...BASE_FILTERS,
  56. };
  57. const tableFilters = {
  58. ...BASE_FILTERS,
  59. 'span.domain': query['span.domain'] ? `*${query['span.domain']}*` : undefined,
  60. };
  61. const cursor = decodeScalar(location.query?.[QueryParameterNames.DOMAINS_CURSOR]);
  62. const handleSearch = (newDomain: string) => {
  63. browserHistory.push({
  64. ...location,
  65. query: {
  66. ...location.query,
  67. 'span.domain': newDomain === '' ? undefined : newDomain,
  68. [QueryParameterNames.SPANS_CURSOR]: undefined,
  69. },
  70. });
  71. };
  72. const {
  73. isLoading: isThroughputDataLoading,
  74. data: throughputData,
  75. error: throughputError,
  76. } = useSpanMetricsSeries(
  77. {
  78. search: MutableSearch.fromQueryObject(chartFilters),
  79. yAxis: ['spm()'],
  80. },
  81. Referrer.LANDING_THROUGHPUT_CHART
  82. );
  83. const {
  84. isLoading: isDurationDataLoading,
  85. data: durationData,
  86. error: durationError,
  87. } = useSpanMetricsSeries(
  88. {
  89. search: MutableSearch.fromQueryObject(chartFilters),
  90. yAxis: [`avg(span.self_time)`],
  91. },
  92. Referrer.LANDING_DURATION_CHART
  93. );
  94. const {
  95. isLoading: isResponseCodeDataLoading,
  96. data: responseCodeData,
  97. error: responseCodeError,
  98. } = useSpanMetricsSeries(
  99. {
  100. search: MutableSearch.fromQueryObject(chartFilters),
  101. yAxis: ['http_response_rate(3)', 'http_response_rate(4)', 'http_response_rate(5)'],
  102. },
  103. Referrer.LANDING_RESPONSE_CODE_CHART
  104. );
  105. const domainsListResponse = useSpanMetrics(
  106. {
  107. search: MutableSearch.fromQueryObject(tableFilters),
  108. fields: [
  109. 'project',
  110. 'project.id',
  111. 'span.domain',
  112. 'spm()',
  113. 'http_response_rate(3)',
  114. 'http_response_rate(4)',
  115. 'http_response_rate(5)',
  116. 'avg(span.self_time)',
  117. 'sum(span.self_time)',
  118. 'time_spent_percentage()',
  119. ],
  120. sorts: [sort],
  121. limit: DOMAIN_TABLE_ROW_COUNT,
  122. cursor,
  123. },
  124. Referrer.LANDING_DOMAINS_LIST
  125. );
  126. useSynchronizeCharts([!isThroughputDataLoading && !isDurationDataLoading]);
  127. const crumbs = useModuleBreadcrumbs('http');
  128. return (
  129. <React.Fragment>
  130. <Layout.Header>
  131. <Layout.HeaderContent>
  132. <Breadcrumbs crumbs={crumbs} />
  133. <Layout.Title>
  134. {MODULE_TITLE}
  135. <PageHeadingQuestionTooltip
  136. docsUrl={MODULE_DOC_LINK}
  137. title={MODULE_DESCRIPTION}
  138. />
  139. </Layout.Title>
  140. </Layout.HeaderContent>
  141. <Layout.HeaderActions>
  142. <ButtonBar gap={1}>
  143. <FeedbackWidgetButton />
  144. </ButtonBar>
  145. </Layout.HeaderActions>
  146. </Layout.Header>
  147. <Layout.Body>
  148. <Layout.Main fullWidth>
  149. <ModuleLayout.Layout>
  150. <ModuleLayout.Full>
  151. <PageFilterBar condensed>
  152. <ProjectPageFilter />
  153. <EnvironmentPageFilter />
  154. <DatePageFilter />
  155. </PageFilterBar>
  156. </ModuleLayout.Full>
  157. {onboardingProject && (
  158. <ModuleLayout.Full>
  159. <Onboarding organization={organization} project={onboardingProject} />
  160. </ModuleLayout.Full>
  161. )}
  162. {!onboardingProject && (
  163. <Fragment>
  164. <ModuleLayout.Third>
  165. <ThroughputChart
  166. series={throughputData['spm()']}
  167. isLoading={isThroughputDataLoading}
  168. error={throughputError}
  169. />
  170. </ModuleLayout.Third>
  171. <ModuleLayout.Third>
  172. <DurationChart
  173. series={[durationData[`avg(span.self_time)`]]}
  174. isLoading={isDurationDataLoading}
  175. error={durationError}
  176. />
  177. </ModuleLayout.Third>
  178. <ModuleLayout.Third>
  179. <ResponseRateChart
  180. series={[
  181. {
  182. ...responseCodeData[`http_response_rate(3)`],
  183. seriesName: t('3XX'),
  184. },
  185. {
  186. ...responseCodeData[`http_response_rate(4)`],
  187. seriesName: t('4XX'),
  188. },
  189. {
  190. ...responseCodeData[`http_response_rate(5)`],
  191. seriesName: t('5XX'),
  192. },
  193. ]}
  194. isLoading={isResponseCodeDataLoading}
  195. error={responseCodeError}
  196. />
  197. </ModuleLayout.Third>
  198. <ModuleLayout.Full>
  199. <SearchBar
  200. query={query['span.domain']}
  201. placeholder={t('Search for more domains')}
  202. onSearch={handleSearch}
  203. />
  204. </ModuleLayout.Full>
  205. <ModuleLayout.Full>
  206. <DomainsTable response={domainsListResponse} sort={sort} />
  207. </ModuleLayout.Full>
  208. </Fragment>
  209. )}
  210. </ModuleLayout.Layout>
  211. </Layout.Main>
  212. </Layout.Body>
  213. </React.Fragment>
  214. );
  215. }
  216. const DEFAULT_SORT = {
  217. field: 'time_spent_percentage()' as const,
  218. kind: 'desc' as const,
  219. };
  220. const DOMAIN_TABLE_ROW_COUNT = 10;
  221. function PageWithProviders() {
  222. return (
  223. <ModulePageProviders moduleName="http" features="spans-first-ui">
  224. <HTTPLandingPage />
  225. </ModulePageProviders>
  226. );
  227. }
  228. export default PageWithProviders;