httpLandingPage.tsx 8.3 KB

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