httpLandingPage.tsx 5.8 KB

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