httpLandingPage.tsx 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. import React, {Fragment} from 'react';
  2. import {Breadcrumbs} from 'sentry/components/breadcrumbs';
  3. import FeatureBadge from 'sentry/components/featureBadge';
  4. import FloatingFeedbackWidget from 'sentry/components/feedback/widget/floatingFeedbackWidget';
  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 {t} from 'sentry/locale';
  11. import {fromSorts} from 'sentry/utils/discover/eventView';
  12. import {decodeScalar} from 'sentry/utils/queryString';
  13. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  14. import {useLocation} from 'sentry/utils/useLocation';
  15. import useOrganization from 'sentry/utils/useOrganization';
  16. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  17. import {useOnboardingProject} from 'sentry/views/performance/browser/webVitals/utils/useOnboardingProject';
  18. import {DomainsTable, isAValidSort} from 'sentry/views/performance/http/domainsTable';
  19. import {DurationChart} from 'sentry/views/performance/http/durationChart';
  20. import {ResponseRateChart} from 'sentry/views/performance/http/responseRateChart';
  21. import {MODULE_TITLE, RELEASE_LEVEL} from 'sentry/views/performance/http/settings';
  22. import {ThroughputChart} from 'sentry/views/performance/http/throughputChart';
  23. import * as ModuleLayout from 'sentry/views/performance/moduleLayout';
  24. import {ModulePageProviders} from 'sentry/views/performance/modulePageProviders';
  25. import Onboarding from 'sentry/views/performance/onboarding';
  26. import {useSynchronizeCharts} from 'sentry/views/starfish/components/chart';
  27. import {useSpanMetrics} from 'sentry/views/starfish/queries/useSpanMetrics';
  28. import {useSpanMetricsSeries} from 'sentry/views/starfish/queries/useSpanMetricsSeries';
  29. import {ModuleName} from 'sentry/views/starfish/types';
  30. import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';
  31. export function HTTPLandingPage() {
  32. const organization = useOrganization();
  33. const location = useLocation();
  34. const onboardingProject = useOnboardingProject();
  35. const sortField = decodeScalar(location.query?.[QueryParameterNames.DOMAINS_SORT]);
  36. const sort = fromSorts(sortField).filter(isAValidSort).at(0) ?? DEFAULT_SORT;
  37. const chartFilters = {
  38. 'span.module': ModuleName.HTTP,
  39. has: 'span.domain',
  40. };
  41. const tableFilters = {
  42. 'span.module': ModuleName.HTTP,
  43. has: 'span.domain',
  44. };
  45. const cursor = decodeScalar(location.query?.[QueryParameterNames.DOMAINS_CURSOR]);
  46. const {
  47. isLoading: isThroughputDataLoading,
  48. data: throughputData,
  49. error: throughputError,
  50. } = useSpanMetricsSeries({
  51. search: MutableSearch.fromQueryObject(chartFilters),
  52. yAxis: ['spm()'],
  53. referrer: 'api.starfish.http-module-landing-throughput-chart',
  54. });
  55. const {
  56. isLoading: isDurationDataLoading,
  57. data: durationData,
  58. error: durationError,
  59. } = useSpanMetricsSeries({
  60. search: MutableSearch.fromQueryObject(chartFilters),
  61. yAxis: [`avg(span.self_time)`],
  62. referrer: 'api.starfish.http-module-landing-duration-chart',
  63. });
  64. const {
  65. isLoading: isResponseCodeDataLoading,
  66. data: responseCodeData,
  67. error: responseCodeError,
  68. } = useSpanMetricsSeries({
  69. search: MutableSearch.fromQueryObject(chartFilters),
  70. yAxis: ['http_response_rate(3)', 'http_response_rate(4)', 'http_response_rate(5)'],
  71. referrer: 'api.starfish.http-module-landing-response-code-chart',
  72. });
  73. const domainsListResponse = useSpanMetrics({
  74. search: MutableSearch.fromQueryObject(tableFilters),
  75. fields: [
  76. 'project.id',
  77. 'span.domain',
  78. 'spm()',
  79. 'http_response_rate(3)',
  80. 'http_response_rate(4)',
  81. 'http_response_rate(5)',
  82. 'avg(span.self_time)',
  83. 'sum(span.self_time)',
  84. 'time_spent_percentage()',
  85. ],
  86. sorts: [sort],
  87. limit: DOMAIN_TABLE_ROW_COUNT,
  88. cursor,
  89. referrer: 'api.starfish.http-module-landing-domains-list',
  90. });
  91. useSynchronizeCharts([!isThroughputDataLoading && !isDurationDataLoading]);
  92. return (
  93. <React.Fragment>
  94. <Layout.Header>
  95. <Layout.HeaderContent>
  96. <Breadcrumbs
  97. crumbs={[
  98. {
  99. label: t('Performance'),
  100. to: normalizeUrl(`/organizations/${organization.slug}/performance/`),
  101. preservePageFilters: true,
  102. },
  103. {
  104. label: MODULE_TITLE,
  105. },
  106. ]}
  107. />
  108. <Layout.Title>
  109. {MODULE_TITLE}
  110. <FeatureBadge type={RELEASE_LEVEL} />
  111. </Layout.Title>
  112. </Layout.HeaderContent>
  113. </Layout.Header>
  114. <Layout.Body>
  115. <Layout.Main fullWidth>
  116. <FloatingFeedbackWidget />
  117. <ModuleLayout.Layout>
  118. <ModuleLayout.Full>
  119. <PageFilterBar condensed>
  120. <ProjectPageFilter />
  121. <EnvironmentPageFilter />
  122. <DatePageFilter />
  123. </PageFilterBar>
  124. </ModuleLayout.Full>
  125. {onboardingProject && (
  126. <Onboarding organization={organization} project={onboardingProject} />
  127. )}
  128. {!onboardingProject && (
  129. <Fragment>
  130. <ModuleLayout.Third>
  131. <ThroughputChart
  132. series={throughputData['spm()']}
  133. isLoading={isThroughputDataLoading}
  134. error={throughputError}
  135. />
  136. </ModuleLayout.Third>
  137. <ModuleLayout.Third>
  138. <DurationChart
  139. series={[durationData[`avg(span.self_time)`]]}
  140. isLoading={isDurationDataLoading}
  141. error={durationError}
  142. />
  143. </ModuleLayout.Third>
  144. <ModuleLayout.Third>
  145. <ResponseRateChart
  146. series={[
  147. {
  148. ...responseCodeData[`http_response_rate(3)`],
  149. seriesName: t('3XX'),
  150. },
  151. {
  152. ...responseCodeData[`http_response_rate(4)`],
  153. seriesName: t('4XX'),
  154. },
  155. {
  156. ...responseCodeData[`http_response_rate(5)`],
  157. seriesName: t('5XX'),
  158. },
  159. ]}
  160. isLoading={isResponseCodeDataLoading}
  161. error={responseCodeError}
  162. />
  163. </ModuleLayout.Third>
  164. <ModuleLayout.Full>
  165. <DomainsTable response={domainsListResponse} sort={sort} />
  166. </ModuleLayout.Full>
  167. </Fragment>
  168. )}
  169. </ModuleLayout.Layout>
  170. </Layout.Main>
  171. </Layout.Body>
  172. </React.Fragment>
  173. );
  174. }
  175. const DEFAULT_SORT = {
  176. field: 'time_spent_percentage()' as const,
  177. kind: 'desc' as const,
  178. };
  179. const DOMAIN_TABLE_ROW_COUNT = 10;
  180. function LandingPageWithProviders() {
  181. return (
  182. <ModulePageProviders
  183. title={[t('Performance'), MODULE_TITLE].join(' — ')}
  184. baseURL="/performance/http"
  185. features="performance-http-view"
  186. >
  187. <HTTPLandingPage />
  188. </ModulePageProviders>
  189. );
  190. }
  191. export default LandingPageWithProviders;