httpLandingPage.tsx 8.5 KB

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