httpDomainSummaryPage.tsx 12 KB

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