httpDomainSummaryPage.tsx 11 KB

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