httpLandingPage.tsx 7.2 KB

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