databaseSpanSummaryPage.tsx 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. import type {RouteComponentProps} from 'react-router';
  2. import styled from '@emotion/styled';
  3. import type {Location} from 'history';
  4. import {Breadcrumbs} from 'sentry/components/breadcrumbs';
  5. import FloatingFeedbackWidget from 'sentry/components/feedback/widget/floatingFeedbackWidget';
  6. import * as Layout from 'sentry/components/layouts/thirds';
  7. import {DatePageFilter} from 'sentry/components/organizations/datePageFilter';
  8. import {EnvironmentPageFilter} from 'sentry/components/organizations/environmentPageFilter';
  9. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  10. import {t} from 'sentry/locale';
  11. import {space} from 'sentry/styles/space';
  12. import {DurationUnit, RateUnit, type Sort} from 'sentry/utils/discover/fields';
  13. import {useLocation} from 'sentry/utils/useLocation';
  14. import useOrganization from 'sentry/utils/useOrganization';
  15. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  16. import {DurationChart} from 'sentry/views/performance/database/durationChart';
  17. import {ThroughputChart} from 'sentry/views/performance/database/throughputChart';
  18. import {useSelectedDurationAggregate} from 'sentry/views/performance/database/useSelectedDurationAggregate';
  19. import {MetricReadout} from 'sentry/views/performance/metricReadout';
  20. import * as ModuleLayout from 'sentry/views/performance/moduleLayout';
  21. import {ModulePageProviders} from 'sentry/views/performance/modulePageProviders';
  22. import {useSynchronizeCharts} from 'sentry/views/starfish/components/chart';
  23. import {DatabaseSpanDescription} from 'sentry/views/starfish/components/spanDescription';
  24. import {getTimeSpentExplanation} from 'sentry/views/starfish/components/tableCells/timeSpentCell';
  25. import {useSpanMetrics} from 'sentry/views/starfish/queries/useSpanMetrics';
  26. import {useSpanMetricsSeries} from 'sentry/views/starfish/queries/useSpanMetricsSeries';
  27. import type {SpanMetricsQueryFilters} from 'sentry/views/starfish/types';
  28. import {SpanFunction, SpanMetricsField} from 'sentry/views/starfish/types';
  29. import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';
  30. import {DataTitles, getThroughputTitle} from 'sentry/views/starfish/views/spans/types';
  31. import {useModuleSort} from 'sentry/views/starfish/views/spans/useModuleSort';
  32. import {SampleList} from 'sentry/views/starfish/views/spanSummaryPage/sampleList';
  33. import {SpanTransactionsTable} from 'sentry/views/starfish/views/spanSummaryPage/spanTransactionsTable';
  34. type Query = {
  35. endpoint: string;
  36. endpointMethod: string;
  37. transaction: string;
  38. transactionMethod: string;
  39. [QueryParameterNames.SPANS_SORT]: string;
  40. aggregate?: string;
  41. };
  42. type Props = {
  43. location: Location<Query>;
  44. } & RouteComponentProps<Query, {groupId: string}>;
  45. function SpanSummaryPage({params}: Props) {
  46. const organization = useOrganization();
  47. const location = useLocation<Query>();
  48. const [selectedAggregate] = useSelectedDurationAggregate();
  49. const {groupId} = params;
  50. const {transaction, transactionMethod, endpoint, endpointMethod} = location.query;
  51. const filters: SpanMetricsQueryFilters = {
  52. 'span.group': groupId,
  53. };
  54. if (endpoint) {
  55. filters.transaction = endpoint;
  56. }
  57. if (endpointMethod) {
  58. filters['transaction.method'] = endpointMethod;
  59. }
  60. const sort = useModuleSort(QueryParameterNames.ENDPOINTS_SORT, DEFAULT_SORT);
  61. const {data, isLoading: areSpanMetricsLoading} = useSpanMetrics({
  62. filters,
  63. fields: [
  64. SpanMetricsField.SPAN_OP,
  65. SpanMetricsField.SPAN_DESCRIPTION,
  66. SpanMetricsField.SPAN_ACTION,
  67. SpanMetricsField.SPAN_DOMAIN,
  68. 'count()',
  69. `${SpanFunction.SPM}()`,
  70. `sum(${SpanMetricsField.SPAN_SELF_TIME})`,
  71. `avg(${SpanMetricsField.SPAN_SELF_TIME})`,
  72. `${SpanFunction.TIME_SPENT_PERCENTAGE}()`,
  73. `${SpanFunction.HTTP_ERROR_COUNT}()`,
  74. ],
  75. enabled: Boolean(groupId),
  76. referrer: 'api.starfish.span-summary-page-metrics',
  77. });
  78. const spanMetrics = data[0] ?? {};
  79. const span = {
  80. ...spanMetrics,
  81. [SpanMetricsField.SPAN_GROUP]: groupId,
  82. } as {
  83. [SpanMetricsField.SPAN_OP]: string;
  84. [SpanMetricsField.SPAN_DESCRIPTION]: string;
  85. [SpanMetricsField.SPAN_ACTION]: string;
  86. [SpanMetricsField.SPAN_DOMAIN]: string[];
  87. [SpanMetricsField.SPAN_GROUP]: string;
  88. };
  89. const {
  90. isLoading: isThroughputDataLoading,
  91. data: throughputData,
  92. error: throughputError,
  93. } = useSpanMetricsSeries({
  94. filters,
  95. yAxis: ['spm()'],
  96. enabled: Boolean(groupId),
  97. referrer: 'api.starfish.span-summary-page-metrics-chart',
  98. });
  99. const {
  100. isLoading: isDurationDataLoading,
  101. data: durationData,
  102. error: durationError,
  103. } = useSpanMetricsSeries({
  104. filters,
  105. yAxis: [`${selectedAggregate}(${SpanMetricsField.SPAN_SELF_TIME})`],
  106. enabled: Boolean(groupId),
  107. referrer: 'api.starfish.span-summary-page-metrics-chart',
  108. });
  109. useSynchronizeCharts([!isThroughputDataLoading && !isDurationDataLoading]);
  110. return (
  111. <ModulePageProviders
  112. title={[t('Performance'), t('Database'), t('Query Summary')].join(' — ')}
  113. baseURL="/performance/database"
  114. features="performance-database-view"
  115. >
  116. <Layout.Header>
  117. <Layout.HeaderContent>
  118. <Breadcrumbs
  119. crumbs={[
  120. {
  121. label: 'Performance',
  122. to: normalizeUrl(`/organizations/${organization.slug}/performance/`),
  123. preservePageFilters: true,
  124. },
  125. {
  126. label: 'Queries',
  127. to: normalizeUrl(
  128. `/organizations/${organization.slug}/performance/database`
  129. ),
  130. preservePageFilters: true,
  131. },
  132. {
  133. label: 'Query Summary',
  134. },
  135. ]}
  136. />
  137. <Layout.Title>{t('Query Summary')}</Layout.Title>
  138. </Layout.HeaderContent>
  139. </Layout.Header>
  140. <Layout.Body>
  141. <Layout.Main fullWidth>
  142. <FloatingFeedbackWidget />
  143. <HeaderContainer>
  144. <PageFilterBar condensed>
  145. <EnvironmentPageFilter />
  146. <DatePageFilter />
  147. </PageFilterBar>
  148. <MetricsRibbon>
  149. <MetricReadout
  150. title={getThroughputTitle('db')}
  151. value={spanMetrics?.[`${SpanFunction.SPM}()`]}
  152. unit={RateUnit.PER_MINUTE}
  153. isLoading={areSpanMetricsLoading}
  154. />
  155. <MetricReadout
  156. title={DataTitles.avg}
  157. value={spanMetrics?.[`avg(${SpanMetricsField.SPAN_SELF_TIME})`]}
  158. unit={DurationUnit.MILLISECOND}
  159. isLoading={areSpanMetricsLoading}
  160. />
  161. <MetricReadout
  162. title={DataTitles.timeSpent}
  163. value={spanMetrics?.['sum(span.self_time)']}
  164. unit={DurationUnit.MILLISECOND}
  165. tooltip={getTimeSpentExplanation(
  166. spanMetrics?.['time_spent_percentage()'],
  167. 'db'
  168. )}
  169. isLoading={areSpanMetricsLoading}
  170. />
  171. </MetricsRibbon>
  172. </HeaderContainer>
  173. <ModuleLayout.Layout>
  174. {groupId && (
  175. <DescriptionContainer>
  176. <DatabaseSpanDescription
  177. groupId={groupId}
  178. preliminaryDescription={spanMetrics?.['span.description']}
  179. />
  180. </DescriptionContainer>
  181. )}
  182. <ModuleLayout.Full>
  183. <ChartContainer>
  184. <ThroughputChart
  185. series={throughputData['spm()']}
  186. isLoading={isThroughputDataLoading}
  187. error={throughputError}
  188. />
  189. <DurationChart
  190. series={
  191. durationData[
  192. `${selectedAggregate}(${SpanMetricsField.SPAN_SELF_TIME})`
  193. ]
  194. }
  195. isLoading={isDurationDataLoading}
  196. error={durationError}
  197. />
  198. </ChartContainer>
  199. </ModuleLayout.Full>
  200. {span && (
  201. <ModuleLayout.Full>
  202. <SpanTransactionsTable
  203. span={span}
  204. sort={sort}
  205. endpoint={endpoint}
  206. endpointMethod={endpointMethod}
  207. />
  208. </ModuleLayout.Full>
  209. )}
  210. <SampleList
  211. groupId={span[SpanMetricsField.SPAN_GROUP]}
  212. transactionName={transaction}
  213. transactionMethod={transactionMethod}
  214. />
  215. </ModuleLayout.Layout>
  216. </Layout.Main>
  217. </Layout.Body>
  218. </ModulePageProviders>
  219. );
  220. }
  221. const DEFAULT_SORT: Sort = {
  222. kind: 'desc',
  223. field: 'time_spent_percentage()',
  224. };
  225. const ChartContainer = styled('div')`
  226. display: grid;
  227. gap: 0;
  228. grid-template-columns: 1fr;
  229. @media (min-width: ${p => p.theme.breakpoints.small}) {
  230. grid-template-columns: 1fr 1fr;
  231. gap: ${space(2)};
  232. }
  233. `;
  234. const HeaderContainer = styled('div')`
  235. display: flex;
  236. justify-content: space-between;
  237. flex-wrap: wrap;
  238. `;
  239. const DescriptionContainer = styled(ModuleLayout.Full)`
  240. line-height: 1.2;
  241. `;
  242. const MetricsRibbon = styled('div')`
  243. display: flex;
  244. flex-wrap: wrap;
  245. gap: ${space(4)};
  246. `;
  247. export default SpanSummaryPage;