databaseSpanSummaryPage.tsx 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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. filters['transaction.method'] = endpointMethod;
  57. }
  58. const sort = useModuleSort(QueryParameterNames.ENDPOINTS_SORT, DEFAULT_SORT);
  59. const {data, isLoading: areSpanMetricsLoading} = useSpanMetrics({
  60. filters,
  61. fields: [
  62. SpanMetricsField.SPAN_OP,
  63. SpanMetricsField.SPAN_DESCRIPTION,
  64. SpanMetricsField.SPAN_ACTION,
  65. SpanMetricsField.SPAN_DOMAIN,
  66. 'count()',
  67. `${SpanFunction.SPM}()`,
  68. `sum(${SpanMetricsField.SPAN_SELF_TIME})`,
  69. `avg(${SpanMetricsField.SPAN_SELF_TIME})`,
  70. `${SpanFunction.TIME_SPENT_PERCENTAGE}()`,
  71. `${SpanFunction.HTTP_ERROR_COUNT}()`,
  72. ],
  73. referrer: 'api.starfish.span-summary-page-metrics',
  74. });
  75. const spanMetrics = data[0] ?? {};
  76. const span = {
  77. ...spanMetrics,
  78. [SpanMetricsField.SPAN_GROUP]: groupId,
  79. } as {
  80. [SpanMetricsField.SPAN_OP]: string;
  81. [SpanMetricsField.SPAN_DESCRIPTION]: string;
  82. [SpanMetricsField.SPAN_ACTION]: string;
  83. [SpanMetricsField.SPAN_DOMAIN]: string[];
  84. [SpanMetricsField.SPAN_GROUP]: string;
  85. };
  86. const {
  87. isLoading: isThroughputDataLoading,
  88. data: throughputData,
  89. error: throughputError,
  90. } = useSpanMetricsSeries({
  91. filters,
  92. yAxis: ['spm()'],
  93. referrer: 'api.starfish.span-summary-page-metrics-chart',
  94. });
  95. const {
  96. isLoading: isDurationDataLoading,
  97. data: durationData,
  98. error: durationError,
  99. } = useSpanMetricsSeries({
  100. filters,
  101. yAxis: [`${selectedAggregate}(${SpanMetricsField.SPAN_SELF_TIME})`],
  102. referrer: 'api.starfish.span-summary-page-metrics-chart',
  103. });
  104. useSynchronizeCharts([!isThroughputDataLoading && !isDurationDataLoading]);
  105. return (
  106. <ModulePageProviders
  107. title={[t('Performance'), t('Database'), t('Query Summary')].join(' — ')}
  108. baseURL="/performance/database"
  109. features="performance-database-view"
  110. >
  111. <Layout.Header>
  112. <Layout.HeaderContent>
  113. <Breadcrumbs
  114. crumbs={[
  115. {
  116. label: 'Performance',
  117. to: normalizeUrl(`/organizations/${organization.slug}/performance/`),
  118. preservePageFilters: true,
  119. },
  120. {
  121. label: 'Queries',
  122. to: normalizeUrl(
  123. `/organizations/${organization.slug}/performance/database`
  124. ),
  125. preservePageFilters: true,
  126. },
  127. {
  128. label: 'Query Summary',
  129. },
  130. ]}
  131. />
  132. <Layout.Title>{t('Query Summary')}</Layout.Title>
  133. </Layout.HeaderContent>
  134. </Layout.Header>
  135. <Layout.Body>
  136. <Layout.Main fullWidth>
  137. <FloatingFeedbackWidget />
  138. <HeaderContainer>
  139. <PageFilterBar condensed>
  140. <EnvironmentPageFilter />
  141. <DatePageFilter />
  142. </PageFilterBar>
  143. <MetricsRibbon>
  144. <MetricReadout
  145. title={getThroughputTitle('db')}
  146. value={spanMetrics?.[`${SpanFunction.SPM}()`]}
  147. unit={RateUnit.PER_MINUTE}
  148. isLoading={areSpanMetricsLoading}
  149. />
  150. <MetricReadout
  151. title={DataTitles.avg}
  152. value={spanMetrics?.[`avg(${SpanMetricsField.SPAN_SELF_TIME})`]}
  153. unit={DurationUnit.MILLISECOND}
  154. isLoading={areSpanMetricsLoading}
  155. />
  156. <MetricReadout
  157. title={DataTitles.timeSpent}
  158. value={spanMetrics?.['sum(span.self_time)']}
  159. unit={DurationUnit.MILLISECOND}
  160. tooltip={getTimeSpentExplanation(
  161. spanMetrics?.['time_spent_percentage()'],
  162. 'db'
  163. )}
  164. isLoading={areSpanMetricsLoading}
  165. />
  166. </MetricsRibbon>
  167. </HeaderContainer>
  168. <ModuleLayout.Layout>
  169. {groupId && (
  170. <DescriptionContainer>
  171. <DatabaseSpanDescription
  172. groupId={groupId}
  173. preliminaryDescription={spanMetrics?.['span.description']}
  174. />
  175. </DescriptionContainer>
  176. )}
  177. <ModuleLayout.Full>
  178. <ChartContainer>
  179. <ThroughputChart
  180. series={throughputData['spm()']}
  181. isLoading={isThroughputDataLoading}
  182. error={throughputError}
  183. />
  184. <DurationChart
  185. series={
  186. durationData[
  187. `${selectedAggregate}(${SpanMetricsField.SPAN_SELF_TIME})`
  188. ]
  189. }
  190. isLoading={isDurationDataLoading}
  191. error={durationError}
  192. />
  193. </ChartContainer>
  194. </ModuleLayout.Full>
  195. {span && (
  196. <ModuleLayout.Full>
  197. <SpanTransactionsTable
  198. span={span}
  199. sort={sort}
  200. endpoint={endpoint}
  201. endpointMethod={endpointMethod}
  202. />
  203. </ModuleLayout.Full>
  204. )}
  205. <SampleList
  206. groupId={span[SpanMetricsField.SPAN_GROUP]}
  207. transactionName={transaction}
  208. transactionMethod={transactionMethod}
  209. />
  210. </ModuleLayout.Layout>
  211. </Layout.Main>
  212. </Layout.Body>
  213. </ModulePageProviders>
  214. );
  215. }
  216. const DEFAULT_SORT: Sort = {
  217. kind: 'desc',
  218. field: 'time_spent_percentage()',
  219. };
  220. const ChartContainer = styled('div')`
  221. display: grid;
  222. gap: 0;
  223. grid-template-columns: 1fr;
  224. @media (min-width: ${p => p.theme.breakpoints.small}) {
  225. grid-template-columns: 1fr 1fr;
  226. gap: ${space(2)};
  227. }
  228. `;
  229. const HeaderContainer = styled('div')`
  230. display: flex;
  231. justify-content: space-between;
  232. flex-wrap: wrap;
  233. `;
  234. const DescriptionContainer = styled(ModuleLayout.Full)`
  235. line-height: 1.2;
  236. `;
  237. const MetricsRibbon = styled('div')`
  238. display: flex;
  239. flex-wrap: wrap;
  240. gap: ${space(4)};
  241. `;
  242. export default SpanSummaryPage;