httpDomainSummaryPage.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. import React from 'react';
  2. import styled from '@emotion/styled';
  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 {t} from 'sentry/locale';
  10. import {space} from 'sentry/styles/space';
  11. import {fromSorts} from 'sentry/utils/discover/eventView';
  12. import {DurationUnit, RateUnit} from 'sentry/utils/discover/fields';
  13. import {decodeScalar} from 'sentry/utils/queryString';
  14. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  15. import {useLocation} from 'sentry/utils/useLocation';
  16. import useOrganization from 'sentry/utils/useOrganization';
  17. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  18. import {
  19. DomainTransactionsTable,
  20. isAValidSort,
  21. } from 'sentry/views/performance/http/domainTransactionsTable';
  22. import {DurationChart} from 'sentry/views/performance/http/durationChart';
  23. import {HTTPSamplesPanel} from 'sentry/views/performance/http/httpSamplesPanel';
  24. import {ResponseRateChart} from 'sentry/views/performance/http/responseRateChart';
  25. import {ThroughputChart} from 'sentry/views/performance/http/throughputChart';
  26. import {MetricReadout} from 'sentry/views/performance/metricReadout';
  27. import * as ModuleLayout from 'sentry/views/performance/moduleLayout';
  28. import {ModulePageProviders} from 'sentry/views/performance/modulePageProviders';
  29. import {useSynchronizeCharts} from 'sentry/views/starfish/components/chart';
  30. import {getTimeSpentExplanation} from 'sentry/views/starfish/components/tableCells/timeSpentCell';
  31. import {useSpanMetrics} from 'sentry/views/starfish/queries/useSpanMetrics';
  32. import {useSpanMetricsSeries} from 'sentry/views/starfish/queries/useSpanMetricsSeries';
  33. import type {SpanMetricsQueryFilters} from 'sentry/views/starfish/types';
  34. import {ModuleName, SpanFunction, SpanMetricsField} from 'sentry/views/starfish/types';
  35. import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';
  36. import {DataTitles, getThroughputTitle} from 'sentry/views/starfish/views/spans/types';
  37. type Query = {
  38. aggregate?: string;
  39. domain?: string;
  40. };
  41. export function HTTPDomainSummaryPage() {
  42. const location = useLocation<Query>();
  43. const organization = useOrganization();
  44. const sortField = decodeScalar(location.query?.[QueryParameterNames.TRANSACTIONS_SORT]);
  45. const sort = fromSorts(sortField).filter(isAValidSort).at(0) ?? DEFAULT_SORT;
  46. const {domain} = location.query;
  47. const filters: SpanMetricsQueryFilters = {
  48. 'span.module': ModuleName.HTTP,
  49. 'span.domain': domain,
  50. };
  51. const cursor = decodeScalar(location.query?.[QueryParameterNames.TRANSACTIONS_CURSOR]);
  52. const {data: domainMetrics, isLoading: areDomainMetricsLoading} = useSpanMetrics({
  53. search: MutableSearch.fromQueryObject(filters),
  54. fields: [
  55. `${SpanFunction.SPM}()`,
  56. `avg(${SpanMetricsField.SPAN_SELF_TIME})`,
  57. `sum(${SpanMetricsField.SPAN_SELF_TIME})`,
  58. 'http_response_rate(3)',
  59. 'http_response_rate(4)',
  60. 'http_response_rate(5)',
  61. `${SpanFunction.TIME_SPENT_PERCENTAGE}()`,
  62. ],
  63. enabled: Boolean(domain),
  64. referrer: 'api.starfish.http-module-domain-summary-metrics-ribbon',
  65. });
  66. const {
  67. isLoading: isThroughputDataLoading,
  68. data: throughputData,
  69. error: throughputError,
  70. } = useSpanMetricsSeries({
  71. search: MutableSearch.fromQueryObject(filters),
  72. yAxis: ['spm()'],
  73. enabled: Boolean(domain),
  74. referrer: 'api.starfish.http-module-domain-summary-throughput-chart',
  75. });
  76. const {
  77. isLoading: isDurationDataLoading,
  78. data: durationData,
  79. error: durationError,
  80. } = useSpanMetricsSeries({
  81. search: MutableSearch.fromQueryObject(filters),
  82. yAxis: [`avg(${SpanMetricsField.SPAN_SELF_TIME})`],
  83. enabled: Boolean(domain),
  84. referrer: 'api.starfish.http-module-domain-summary-duration-chart',
  85. });
  86. const {
  87. isLoading: isResponseCodeDataLoading,
  88. data: responseCodeData,
  89. error: responseCodeError,
  90. } = useSpanMetricsSeries({
  91. search: MutableSearch.fromQueryObject(filters),
  92. yAxis: ['http_response_rate(3)', 'http_response_rate(4)', 'http_response_rate(5)'],
  93. referrer: 'api.starfish.http-module-domain-summary-response-code-chart',
  94. });
  95. const {
  96. isLoading: isTransactionsListLoading,
  97. data: transactionsList,
  98. meta: transactionsListMeta,
  99. error: transactionsListError,
  100. pageLinks: transactionsListPageLinks,
  101. } = useSpanMetrics({
  102. search: MutableSearch.fromQueryObject(filters),
  103. fields: [
  104. 'project.id',
  105. 'transaction',
  106. 'transaction.method',
  107. 'spm()',
  108. 'http_response_rate(3)',
  109. 'http_response_rate(4)',
  110. 'http_response_rate(5)',
  111. 'avg(span.self_time)',
  112. 'sum(span.self_time)',
  113. 'time_spent_percentage()',
  114. ],
  115. sorts: [sort],
  116. limit: TRANSACTIONS_TABLE_ROW_COUNT,
  117. cursor,
  118. referrer: 'api.starfish.http-module-domain-summary-transactions-list',
  119. });
  120. useSynchronizeCharts([!isThroughputDataLoading && !isDurationDataLoading]);
  121. return (
  122. <React.Fragment>
  123. <Layout.Header>
  124. <Layout.HeaderContent>
  125. <Breadcrumbs
  126. crumbs={[
  127. {
  128. label: 'Performance',
  129. to: normalizeUrl(`/organizations/${organization.slug}/performance/`),
  130. preservePageFilters: true,
  131. },
  132. {
  133. label: 'HTTP',
  134. to: normalizeUrl(`/organizations/${organization.slug}/performance/http`),
  135. preservePageFilters: true,
  136. },
  137. {
  138. label: 'Domain Summary',
  139. },
  140. ]}
  141. />
  142. <Layout.Title>{domain}</Layout.Title>
  143. </Layout.HeaderContent>
  144. </Layout.Header>
  145. <Layout.Body>
  146. <Layout.Main fullWidth>
  147. <FloatingFeedbackWidget />
  148. <ModuleLayout.Layout>
  149. <ModuleLayout.Full>
  150. <HeaderContainer>
  151. <PageFilterBar condensed>
  152. <EnvironmentPageFilter />
  153. <DatePageFilter />
  154. </PageFilterBar>
  155. <MetricsRibbon>
  156. <MetricReadout
  157. title={getThroughputTitle('http')}
  158. value={domainMetrics?.[0]?.[`${SpanFunction.SPM}()`]}
  159. unit={RateUnit.PER_MINUTE}
  160. isLoading={areDomainMetricsLoading}
  161. />
  162. <MetricReadout
  163. title={DataTitles.avg}
  164. value={
  165. domainMetrics?.[0]?.[`avg(${SpanMetricsField.SPAN_SELF_TIME})`]
  166. }
  167. unit={DurationUnit.MILLISECOND}
  168. isLoading={areDomainMetricsLoading}
  169. />
  170. <MetricReadout
  171. title={t('3XXs')}
  172. value={domainMetrics?.[0]?.[`http_response_rate(3)`]}
  173. unit="percentage"
  174. isLoading={areDomainMetricsLoading}
  175. />
  176. <MetricReadout
  177. title={t('4XXs')}
  178. value={domainMetrics?.[0]?.[`http_response_rate(4)`]}
  179. unit="percentage"
  180. isLoading={areDomainMetricsLoading}
  181. />
  182. <MetricReadout
  183. title={t('5XXs')}
  184. value={domainMetrics?.[0]?.[`http_response_rate(5)`]}
  185. unit="percentage"
  186. isLoading={areDomainMetricsLoading}
  187. />
  188. <MetricReadout
  189. title={DataTitles.timeSpent}
  190. value={domainMetrics?.[0]?.['sum(span.self_time)']}
  191. unit={DurationUnit.MILLISECOND}
  192. tooltip={getTimeSpentExplanation(
  193. domainMetrics?.[0]?.['time_spent_percentage()'],
  194. 'db'
  195. )}
  196. isLoading={areDomainMetricsLoading}
  197. />
  198. </MetricsRibbon>
  199. </HeaderContainer>
  200. </ModuleLayout.Full>
  201. <ModuleLayout.Third>
  202. <ThroughputChart
  203. series={throughputData['spm()']}
  204. isLoading={isThroughputDataLoading}
  205. error={throughputError}
  206. />
  207. </ModuleLayout.Third>
  208. <ModuleLayout.Third>
  209. <DurationChart
  210. series={durationData[`avg(${SpanMetricsField.SPAN_SELF_TIME})`]}
  211. isLoading={isDurationDataLoading}
  212. error={durationError}
  213. />
  214. </ModuleLayout.Third>
  215. <ModuleLayout.Third>
  216. <ResponseRateChart
  217. series={[
  218. {
  219. ...responseCodeData[`http_response_rate(3)`],
  220. seriesName: t('3XX'),
  221. },
  222. {
  223. ...responseCodeData[`http_response_rate(4)`],
  224. seriesName: t('4XX'),
  225. },
  226. {
  227. ...responseCodeData[`http_response_rate(5)`],
  228. seriesName: t('5XX'),
  229. },
  230. ]}
  231. isLoading={isResponseCodeDataLoading}
  232. error={responseCodeError}
  233. />
  234. </ModuleLayout.Third>
  235. <ModuleLayout.Full>
  236. <DomainTransactionsTable
  237. domain={domain}
  238. data={transactionsList}
  239. error={transactionsListError}
  240. isLoading={isTransactionsListLoading}
  241. meta={transactionsListMeta}
  242. pageLinks={transactionsListPageLinks}
  243. sort={sort}
  244. />
  245. </ModuleLayout.Full>
  246. </ModuleLayout.Layout>
  247. </Layout.Main>
  248. </Layout.Body>
  249. <HTTPSamplesPanel />
  250. </React.Fragment>
  251. );
  252. }
  253. const DEFAULT_SORT = {
  254. field: 'time_spent_percentage()' as const,
  255. kind: 'desc' as const,
  256. };
  257. const TRANSACTIONS_TABLE_ROW_COUNT = 20;
  258. const HeaderContainer = styled('div')`
  259. display: flex;
  260. justify-content: space-between;
  261. flex-wrap: wrap;
  262. `;
  263. const MetricsRibbon = styled('div')`
  264. display: flex;
  265. flex-wrap: wrap;
  266. gap: ${space(4)};
  267. `;
  268. function LandingPageWithProviders() {
  269. return (
  270. <ModulePageProviders
  271. baseURL="/performance/http"
  272. title={[t('Performance'), t('HTTP'), t('Domain Summary')].join(' — ')}
  273. features="performance-http-view"
  274. >
  275. <HTTPDomainSummaryPage />
  276. </ModulePageProviders>
  277. );
  278. }
  279. export default LandingPageWithProviders;