httpLandingPage.tsx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 {useLocation} from 'sentry/utils/useLocation';
  13. import useOrganization from 'sentry/utils/useOrganization';
  14. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  15. import {useOnboardingProject} from 'sentry/views/performance/browser/webVitals/utils/useOnboardingProject';
  16. import {DomainsTable, isAValidSort} from 'sentry/views/performance/http/domainsTable';
  17. import {DurationChart} from 'sentry/views/performance/http/durationChart';
  18. import {ThroughputChart} from 'sentry/views/performance/http/throughputChart';
  19. import * as ModuleLayout from 'sentry/views/performance/moduleLayout';
  20. import {ModulePageProviders} from 'sentry/views/performance/modulePageProviders';
  21. import Onboarding from 'sentry/views/performance/onboarding';
  22. import {useSynchronizeCharts} from 'sentry/views/starfish/components/chart';
  23. import {useSpanMetrics} from 'sentry/views/starfish/queries/useSpanMetrics';
  24. import {useSpanMetricsSeries} from 'sentry/views/starfish/queries/useSpanMetricsSeries';
  25. import {ModuleName} from 'sentry/views/starfish/types';
  26. import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';
  27. export function HTTPLandingPage() {
  28. const organization = useOrganization();
  29. const location = useLocation();
  30. const onboardingProject = useOnboardingProject();
  31. const sortField = decodeScalar(location.query?.[QueryParameterNames.DOMAINS_SORT]);
  32. const sort = fromSorts(sortField).filter(isAValidSort).at(0) ?? DEFAULT_SORT;
  33. const chartFilters = {
  34. 'span.module': ModuleName.HTTP,
  35. has: 'span.domain',
  36. };
  37. const tableFilters = {
  38. 'span.module': ModuleName.HTTP,
  39. has: 'span.domain',
  40. };
  41. const cursor = decodeScalar(location.query?.[QueryParameterNames.DOMAINS_CURSOR]);
  42. const {
  43. isLoading: isThroughputDataLoading,
  44. data: throughputData,
  45. error: throughputError,
  46. } = useSpanMetricsSeries({
  47. filters: chartFilters,
  48. yAxis: ['spm()'],
  49. referrer: 'api.starfish.http-module-landing-throughput-chart',
  50. });
  51. const {
  52. isLoading: isDurationDataLoading,
  53. data: durationData,
  54. error: durationError,
  55. } = useSpanMetricsSeries({
  56. filters: chartFilters,
  57. yAxis: [`avg(span.self_time)`],
  58. referrer: 'api.starfish.http-module-landing-duration-chart',
  59. });
  60. const domainsListResponse = useSpanMetrics({
  61. filters: tableFilters,
  62. fields: [
  63. 'project.id',
  64. 'span.domain',
  65. 'spm()',
  66. 'avg(span.self_time)',
  67. 'sum(span.self_time)',
  68. 'time_spent_percentage()',
  69. ],
  70. sorts: [sort],
  71. limit: DOMAIN_TABLE_ROW_COUNT,
  72. cursor,
  73. referrer: 'api.starfish.http-module-landing-domains-list',
  74. });
  75. useSynchronizeCharts([!isThroughputDataLoading && !isDurationDataLoading]);
  76. return (
  77. <React.Fragment>
  78. <Layout.Header>
  79. <Layout.HeaderContent>
  80. <Breadcrumbs
  81. crumbs={[
  82. {
  83. label: t('Performance'),
  84. to: normalizeUrl(`/organizations/${organization.slug}/performance/`),
  85. preservePageFilters: true,
  86. },
  87. {
  88. label: t('HTTP'),
  89. },
  90. ]}
  91. />
  92. <Layout.Title>{t('HTTP')}</Layout.Title>
  93. </Layout.HeaderContent>
  94. </Layout.Header>
  95. <Layout.Body>
  96. <Layout.Main fullWidth>
  97. <FloatingFeedbackWidget />
  98. <ModuleLayout.Layout>
  99. <ModuleLayout.Full>
  100. <PageFilterBar condensed>
  101. <ProjectPageFilter />
  102. <EnvironmentPageFilter />
  103. <DatePageFilter />
  104. </PageFilterBar>
  105. </ModuleLayout.Full>
  106. {onboardingProject && (
  107. <Onboarding organization={organization} project={onboardingProject} />
  108. )}
  109. {!onboardingProject && (
  110. <Fragment>
  111. <ModuleLayout.Half>
  112. <ThroughputChart
  113. series={throughputData['spm()']}
  114. isLoading={isThroughputDataLoading}
  115. error={throughputError}
  116. />
  117. </ModuleLayout.Half>
  118. <ModuleLayout.Half>
  119. <DurationChart
  120. series={durationData[`avg(span.self_time)`]}
  121. isLoading={isDurationDataLoading}
  122. error={durationError}
  123. />
  124. </ModuleLayout.Half>
  125. <ModuleLayout.Full>
  126. <DomainsTable response={domainsListResponse} sort={sort} />
  127. </ModuleLayout.Full>
  128. </Fragment>
  129. )}
  130. </ModuleLayout.Layout>
  131. </Layout.Main>
  132. </Layout.Body>
  133. </React.Fragment>
  134. );
  135. }
  136. const DEFAULT_SORT = {
  137. field: 'time_spent_percentage()' as const,
  138. kind: 'desc' as const,
  139. };
  140. const DOMAIN_TABLE_ROW_COUNT = 10;
  141. function LandingPageWithProviders() {
  142. return (
  143. <ModulePageProviders
  144. title={[t('Performance'), t('HTTP')].join(' — ')}
  145. baseURL="/performance/http"
  146. features="performance-http-view"
  147. >
  148. <HTTPLandingPage />
  149. </ModulePageProviders>
  150. );
  151. }
  152. export default LandingPageWithProviders;