httpDomainSummaryPage.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. import React from 'react';
  2. import styled from '@emotion/styled';
  3. import Alert from 'sentry/components/alert';
  4. import ProjectAvatar from 'sentry/components/avatar/projectAvatar';
  5. import FeatureBadge from 'sentry/components/badge/featureBadge';
  6. import {Breadcrumbs} from 'sentry/components/breadcrumbs';
  7. import ButtonBar from 'sentry/components/buttonBar';
  8. import FeedbackWidgetButton from 'sentry/components/feedback/widget/feedbackWidgetButton';
  9. import * as Layout from 'sentry/components/layouts/thirds';
  10. import ExternalLink from 'sentry/components/links/externalLink';
  11. import {DatePageFilter} from 'sentry/components/organizations/datePageFilter';
  12. import {EnvironmentPageFilter} from 'sentry/components/organizations/environmentPageFilter';
  13. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  14. import {t, tct} from 'sentry/locale';
  15. import {space} from 'sentry/styles/space';
  16. import {DurationUnit, RateUnit} from 'sentry/utils/discover/fields';
  17. import {decodeScalar, decodeSorts} from 'sentry/utils/queryString';
  18. import {
  19. EMPTY_OPTION_VALUE,
  20. escapeFilterValue,
  21. MutableSearch,
  22. } from 'sentry/utils/tokenizeSearch';
  23. import useLocationQuery from 'sentry/utils/url/useLocationQuery';
  24. import {useLocation} from 'sentry/utils/useLocation';
  25. import useOrganization from 'sentry/utils/useOrganization';
  26. import useProjects from 'sentry/utils/useProjects';
  27. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  28. import {DurationChart} from 'sentry/views/performance/http/charts/durationChart';
  29. import {ResponseRateChart} from 'sentry/views/performance/http/charts/responseRateChart';
  30. import {ThroughputChart} from 'sentry/views/performance/http/charts/throughputChart';
  31. import {DomainStatusLink} from 'sentry/views/performance/http/components/domainStatusLink';
  32. import {HTTPSamplesPanel} from 'sentry/views/performance/http/httpSamplesPanel';
  33. import {Referrer} from 'sentry/views/performance/http/referrers';
  34. import {
  35. MODULE_TITLE,
  36. NULL_DOMAIN_DESCRIPTION,
  37. RELEASE_LEVEL,
  38. } from 'sentry/views/performance/http/settings';
  39. import {
  40. DomainTransactionsTable,
  41. isAValidSort,
  42. } from 'sentry/views/performance/http/tables/domainTransactionsTable';
  43. import {MetricReadout} from 'sentry/views/performance/metricReadout';
  44. import * as ModuleLayout from 'sentry/views/performance/moduleLayout';
  45. import {ModulePageProviders} from 'sentry/views/performance/modulePageProviders';
  46. import {useSynchronizeCharts} from 'sentry/views/starfish/components/chart';
  47. import {getTimeSpentExplanation} from 'sentry/views/starfish/components/tableCells/timeSpentCell';
  48. import {useSpanMetrics} from 'sentry/views/starfish/queries/useSpanMetrics';
  49. import {useSpanMetricsSeries} from 'sentry/views/starfish/queries/useSpanMetricsSeries';
  50. import type {SpanMetricsQueryFilters} from 'sentry/views/starfish/types';
  51. import {ModuleName, SpanFunction, SpanMetricsField} from 'sentry/views/starfish/types';
  52. import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';
  53. import {DataTitles, getThroughputTitle} from 'sentry/views/starfish/views/spans/types';
  54. type Query = {
  55. aggregate?: string;
  56. domain?: string;
  57. };
  58. export function HTTPDomainSummaryPage() {
  59. const location = useLocation<Query>();
  60. const organization = useOrganization();
  61. const {projects} = useProjects();
  62. // TODO: Fetch sort information using `useLocationQuery`
  63. const sortField = decodeScalar(location.query?.[QueryParameterNames.TRANSACTIONS_SORT]);
  64. const sort = decodeSorts(sortField).filter(isAValidSort).at(0) ?? DEFAULT_SORT;
  65. const {domain, project: projectId} = useLocationQuery({
  66. fields: {
  67. project: decodeScalar,
  68. domain: decodeScalar,
  69. },
  70. });
  71. const project = projects.find(p => projectId === p.id);
  72. const filters: SpanMetricsQueryFilters = {
  73. 'span.module': ModuleName.HTTP,
  74. 'span.domain': domain === '' ? EMPTY_OPTION_VALUE : escapeFilterValue(domain),
  75. };
  76. const cursor = decodeScalar(location.query?.[QueryParameterNames.TRANSACTIONS_CURSOR]);
  77. const {data: domainMetrics, isLoading: areDomainMetricsLoading} = useSpanMetrics({
  78. search: MutableSearch.fromQueryObject(filters),
  79. fields: [
  80. `${SpanFunction.SPM}()`,
  81. `avg(${SpanMetricsField.SPAN_SELF_TIME})`,
  82. `sum(${SpanMetricsField.SPAN_SELF_TIME})`,
  83. 'http_response_rate(3)',
  84. 'http_response_rate(4)',
  85. 'http_response_rate(5)',
  86. `${SpanFunction.TIME_SPENT_PERCENTAGE}()`,
  87. ],
  88. referrer: Referrer.DOMAIN_SUMMARY_METRICS_RIBBON,
  89. });
  90. const {
  91. isLoading: isThroughputDataLoading,
  92. data: throughputData,
  93. error: throughputError,
  94. } = useSpanMetricsSeries({
  95. search: MutableSearch.fromQueryObject(filters),
  96. yAxis: ['spm()'],
  97. referrer: Referrer.DOMAIN_SUMMARY_THROUGHPUT_CHART,
  98. });
  99. const {
  100. isLoading: isDurationDataLoading,
  101. data: durationData,
  102. error: durationError,
  103. } = useSpanMetricsSeries({
  104. search: MutableSearch.fromQueryObject(filters),
  105. yAxis: [`avg(${SpanMetricsField.SPAN_SELF_TIME})`],
  106. referrer: Referrer.DOMAIN_SUMMARY_DURATION_CHART,
  107. });
  108. const {
  109. isLoading: isResponseCodeDataLoading,
  110. data: responseCodeData,
  111. error: responseCodeError,
  112. } = useSpanMetricsSeries({
  113. search: MutableSearch.fromQueryObject(filters),
  114. yAxis: ['http_response_rate(3)', 'http_response_rate(4)', 'http_response_rate(5)'],
  115. referrer: Referrer.DOMAIN_SUMMARY_RESPONSE_CODE_CHART,
  116. });
  117. const {
  118. isLoading: isTransactionsListLoading,
  119. data: transactionsList,
  120. meta: transactionsListMeta,
  121. error: transactionsListError,
  122. pageLinks: transactionsListPageLinks,
  123. } = useSpanMetrics({
  124. search: MutableSearch.fromQueryObject(filters),
  125. fields: [
  126. 'project.id',
  127. 'transaction',
  128. 'transaction.method',
  129. 'spm()',
  130. 'http_response_rate(3)',
  131. 'http_response_rate(4)',
  132. 'http_response_rate(5)',
  133. 'avg(span.self_time)',
  134. 'sum(span.self_time)',
  135. 'time_spent_percentage()',
  136. ],
  137. sorts: [sort],
  138. limit: TRANSACTIONS_TABLE_ROW_COUNT,
  139. cursor,
  140. referrer: Referrer.DOMAIN_SUMMARY_TRANSACTIONS_LIST,
  141. });
  142. useSynchronizeCharts([!isThroughputDataLoading && !isDurationDataLoading]);
  143. return (
  144. <React.Fragment>
  145. <Layout.Header>
  146. <Layout.HeaderContent>
  147. <Breadcrumbs
  148. crumbs={[
  149. {
  150. label: 'Performance',
  151. to: normalizeUrl(`/organizations/${organization.slug}/performance/`),
  152. preservePageFilters: true,
  153. },
  154. {
  155. label: MODULE_TITLE,
  156. to: normalizeUrl(`/organizations/${organization.slug}/performance/http`),
  157. preservePageFilters: true,
  158. },
  159. {
  160. label: 'Domain Summary',
  161. },
  162. ]}
  163. />
  164. <Layout.Title>
  165. {project && <ProjectAvatar project={project} size={36} />}
  166. {domain || NULL_DOMAIN_DESCRIPTION}
  167. <DomainStatusLink domain={domain} />
  168. <FeatureBadge type={RELEASE_LEVEL} />
  169. </Layout.Title>
  170. </Layout.HeaderContent>
  171. <Layout.HeaderActions>
  172. <ButtonBar gap={1}>
  173. <FeedbackWidgetButton />
  174. </ButtonBar>
  175. </Layout.HeaderActions>
  176. </Layout.Header>
  177. <Layout.Body>
  178. <Layout.Main fullWidth>
  179. {domain === '' && (
  180. <Alert type="info">
  181. {tct(
  182. '"Unknown Domain" entries can be caused by instrumentation errors. Please refer to our [link] for more information.',
  183. {
  184. link: (
  185. <ExternalLink href="https://docs.sentry.io/product/performance/requests/">
  186. documentation
  187. </ExternalLink>
  188. ),
  189. }
  190. )}
  191. </Alert>
  192. )}
  193. <ModuleLayout.Layout>
  194. <ModuleLayout.Full>
  195. <HeaderContainer>
  196. <PageFilterBar condensed>
  197. <EnvironmentPageFilter />
  198. <DatePageFilter />
  199. </PageFilterBar>
  200. <MetricsRibbon>
  201. <MetricReadout
  202. title={getThroughputTitle('http')}
  203. value={domainMetrics?.[0]?.[`${SpanFunction.SPM}()`]}
  204. unit={RateUnit.PER_MINUTE}
  205. isLoading={areDomainMetricsLoading}
  206. />
  207. <MetricReadout
  208. title={DataTitles.avg}
  209. value={
  210. domainMetrics?.[0]?.[`avg(${SpanMetricsField.SPAN_SELF_TIME})`]
  211. }
  212. unit={DurationUnit.MILLISECOND}
  213. isLoading={areDomainMetricsLoading}
  214. />
  215. <MetricReadout
  216. title={t('3XXs')}
  217. value={domainMetrics?.[0]?.[`http_response_rate(3)`]}
  218. unit="percentage"
  219. isLoading={areDomainMetricsLoading}
  220. />
  221. <MetricReadout
  222. title={t('4XXs')}
  223. value={domainMetrics?.[0]?.[`http_response_rate(4)`]}
  224. unit="percentage"
  225. isLoading={areDomainMetricsLoading}
  226. />
  227. <MetricReadout
  228. title={t('5XXs')}
  229. value={domainMetrics?.[0]?.[`http_response_rate(5)`]}
  230. unit="percentage"
  231. isLoading={areDomainMetricsLoading}
  232. />
  233. <MetricReadout
  234. title={DataTitles.timeSpent}
  235. value={domainMetrics?.[0]?.['sum(span.self_time)']}
  236. unit={DurationUnit.MILLISECOND}
  237. tooltip={getTimeSpentExplanation(
  238. domainMetrics?.[0]?.['time_spent_percentage()'],
  239. 'http'
  240. )}
  241. isLoading={areDomainMetricsLoading}
  242. />
  243. </MetricsRibbon>
  244. </HeaderContainer>
  245. </ModuleLayout.Full>
  246. <ModuleLayout.Third>
  247. <ThroughputChart
  248. series={throughputData['spm()']}
  249. isLoading={isThroughputDataLoading}
  250. error={throughputError}
  251. />
  252. </ModuleLayout.Third>
  253. <ModuleLayout.Third>
  254. <DurationChart
  255. series={[durationData[`avg(${SpanMetricsField.SPAN_SELF_TIME})`]]}
  256. isLoading={isDurationDataLoading}
  257. error={durationError}
  258. />
  259. </ModuleLayout.Third>
  260. <ModuleLayout.Third>
  261. <ResponseRateChart
  262. series={[
  263. {
  264. ...responseCodeData[`http_response_rate(3)`],
  265. seriesName: t('3XX'),
  266. },
  267. {
  268. ...responseCodeData[`http_response_rate(4)`],
  269. seriesName: t('4XX'),
  270. },
  271. {
  272. ...responseCodeData[`http_response_rate(5)`],
  273. seriesName: t('5XX'),
  274. },
  275. ]}
  276. isLoading={isResponseCodeDataLoading}
  277. error={responseCodeError}
  278. />
  279. </ModuleLayout.Third>
  280. <ModuleLayout.Full>
  281. <DomainTransactionsTable
  282. domain={domain}
  283. data={transactionsList}
  284. error={transactionsListError}
  285. isLoading={isTransactionsListLoading}
  286. meta={transactionsListMeta}
  287. pageLinks={transactionsListPageLinks}
  288. sort={sort}
  289. />
  290. </ModuleLayout.Full>
  291. </ModuleLayout.Layout>
  292. </Layout.Main>
  293. </Layout.Body>
  294. <HTTPSamplesPanel />
  295. </React.Fragment>
  296. );
  297. }
  298. const DEFAULT_SORT = {
  299. field: 'time_spent_percentage()' as const,
  300. kind: 'desc' as const,
  301. };
  302. const TRANSACTIONS_TABLE_ROW_COUNT = 20;
  303. const HeaderContainer = styled('div')`
  304. display: flex;
  305. justify-content: space-between;
  306. flex-wrap: wrap;
  307. `;
  308. const MetricsRibbon = styled('div')`
  309. display: flex;
  310. flex-wrap: wrap;
  311. gap: ${space(4)};
  312. `;
  313. function LandingPageWithProviders() {
  314. return (
  315. <ModulePageProviders
  316. baseURL="/performance/http"
  317. title={[t('Performance'), MODULE_TITLE, t('Domain Summary')].join(' — ')}
  318. features="performance-http-view"
  319. >
  320. <HTTPDomainSummaryPage />
  321. </ModulePageProviders>
  322. );
  323. }
  324. export default LandingPageWithProviders;