databaseSpanSummaryPage.tsx 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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 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 {ModulePageProviders} from 'sentry/views/performance/database/modulePageProviders';
  18. import {ThroughputChart} from 'sentry/views/performance/database/throughputChart';
  19. import {useSelectedDurationAggregate} from 'sentry/views/performance/database/useSelectedDurationAggregate';
  20. import {useSynchronizeCharts} from 'sentry/views/starfish/components/chart';
  21. import {DatabaseSpanDescription} from 'sentry/views/starfish/components/spanDescription';
  22. import {useSpanMetrics} from 'sentry/views/starfish/queries/useSpanMetrics';
  23. import {useSpanMetricsSeries} from 'sentry/views/starfish/queries/useSpanMetricsSeries';
  24. import type {SpanMetricsQueryFilters} from 'sentry/views/starfish/types';
  25. import {SpanFunction, SpanMetricsField} from 'sentry/views/starfish/types';
  26. import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';
  27. import {useModuleSort} from 'sentry/views/starfish/views/spans/useModuleSort';
  28. import {SampleList} from 'sentry/views/starfish/views/spanSummaryPage/sampleList';
  29. import {SpanMetricsRibbon} from 'sentry/views/starfish/views/spanSummaryPage/spanMetricsRibbon';
  30. import {SpanTransactionsTable} from 'sentry/views/starfish/views/spanSummaryPage/spanTransactionsTable';
  31. type Query = {
  32. endpoint: string;
  33. endpointMethod: string;
  34. transaction: string;
  35. transactionMethod: string;
  36. [QueryParameterNames.SPANS_SORT]: string;
  37. aggregate?: string;
  38. };
  39. type Props = {
  40. location: Location<Query>;
  41. } & RouteComponentProps<Query, {groupId: string}>;
  42. function SpanSummaryPage({params}: Props) {
  43. const organization = useOrganization();
  44. const location = useLocation<Query>();
  45. const [selectedAggregate] = useSelectedDurationAggregate();
  46. const {groupId} = params;
  47. const {transaction, transactionMethod, endpoint, endpointMethod} = location.query;
  48. const filters: SpanMetricsQueryFilters = {
  49. 'span.group': groupId,
  50. };
  51. if (endpoint) {
  52. filters.transaction = endpoint;
  53. filters['transaction.method'] = endpointMethod;
  54. }
  55. const sort = useModuleSort(QueryParameterNames.ENDPOINTS_SORT, DEFAULT_SORT);
  56. const {data} = useSpanMetrics({
  57. filters,
  58. fields: [
  59. SpanMetricsField.SPAN_OP,
  60. SpanMetricsField.SPAN_DESCRIPTION,
  61. SpanMetricsField.SPAN_ACTION,
  62. SpanMetricsField.SPAN_DOMAIN,
  63. 'count()',
  64. `${SpanFunction.SPM}()`,
  65. `sum(${SpanMetricsField.SPAN_SELF_TIME})`,
  66. `avg(${SpanMetricsField.SPAN_SELF_TIME})`,
  67. `${SpanFunction.TIME_SPENT_PERCENTAGE}()`,
  68. `${SpanFunction.HTTP_ERROR_COUNT}()`,
  69. ],
  70. referrer: 'api.starfish.span-summary-page-metrics',
  71. });
  72. const spanMetrics = data[0] ?? {};
  73. const span = {
  74. ...spanMetrics,
  75. [SpanMetricsField.SPAN_GROUP]: groupId,
  76. } as {
  77. [SpanMetricsField.SPAN_OP]: string;
  78. [SpanMetricsField.SPAN_DESCRIPTION]: string;
  79. [SpanMetricsField.SPAN_ACTION]: string;
  80. [SpanMetricsField.SPAN_DOMAIN]: string[];
  81. [SpanMetricsField.SPAN_GROUP]: string;
  82. };
  83. const {isLoading: isThroughputDataLoading, data: throughputData} = useSpanMetricsSeries(
  84. {
  85. filters,
  86. yAxis: ['spm()'],
  87. referrer: 'api.starfish.span-summary-page-metrics-chart',
  88. }
  89. );
  90. const {isLoading: isDurationDataLoading, data: durationData} = useSpanMetricsSeries({
  91. filters,
  92. yAxis: [`${selectedAggregate}(${SpanMetricsField.SPAN_SELF_TIME})`],
  93. referrer: 'api.starfish.span-summary-page-metrics-chart',
  94. });
  95. useSynchronizeCharts([!isThroughputDataLoading && !isDurationDataLoading]);
  96. return (
  97. <ModulePageProviders
  98. title={[t('Performance'), t('Database'), t('Query Summary')].join(' — ')}
  99. >
  100. <Layout.Header>
  101. <Layout.HeaderContent>
  102. <Breadcrumbs
  103. crumbs={[
  104. {
  105. label: 'Performance',
  106. to: normalizeUrl(`/organizations/${organization.slug}/performance/`),
  107. preservePageFilters: true,
  108. },
  109. {
  110. label: 'Queries',
  111. to: normalizeUrl(
  112. `/organizations/${organization.slug}/performance/database`
  113. ),
  114. preservePageFilters: true,
  115. },
  116. {
  117. label: 'Query Summary',
  118. },
  119. ]}
  120. />
  121. <Layout.Title>{t('Query Summary')}</Layout.Title>
  122. </Layout.HeaderContent>
  123. </Layout.Header>
  124. <Layout.Body>
  125. <Layout.Main fullWidth>
  126. <FloatingFeedbackWidget />
  127. <HeaderContainer>
  128. <PaddedContainer>
  129. <PageFilterBar condensed>
  130. <EnvironmentPageFilter />
  131. <DatePageFilter />
  132. </PageFilterBar>
  133. </PaddedContainer>
  134. <SpanMetricsRibbon spanMetrics={span} />
  135. </HeaderContainer>
  136. {groupId && (
  137. <DescriptionContainer>
  138. <DatabaseSpanDescription
  139. groupId={groupId}
  140. preliminaryDescription={spanMetrics?.['span.description']}
  141. />
  142. </DescriptionContainer>
  143. )}
  144. <ChartContainer>
  145. <ThroughputChart
  146. series={throughputData['spm()']}
  147. isLoading={isThroughputDataLoading}
  148. />
  149. <DurationChart
  150. series={
  151. durationData[`${selectedAggregate}(${SpanMetricsField.SPAN_SELF_TIME})`]
  152. }
  153. isLoading={isDurationDataLoading}
  154. />
  155. </ChartContainer>
  156. {span && (
  157. <SpanTransactionsTable
  158. span={span}
  159. sort={sort}
  160. endpoint={endpoint}
  161. endpointMethod={endpointMethod}
  162. />
  163. )}
  164. <SampleList
  165. groupId={span[SpanMetricsField.SPAN_GROUP]}
  166. transactionName={transaction}
  167. transactionMethod={transactionMethod}
  168. />
  169. </Layout.Main>
  170. </Layout.Body>
  171. </ModulePageProviders>
  172. );
  173. }
  174. const DEFAULT_SORT: Sort = {
  175. kind: 'desc',
  176. field: 'time_spent_percentage()',
  177. };
  178. const PaddedContainer = styled('div')`
  179. margin-bottom: ${space(2)};
  180. `;
  181. const ChartContainer = styled('div')`
  182. display: grid;
  183. gap: 0;
  184. grid-template-columns: 1fr;
  185. @media (min-width: ${p => p.theme.breakpoints.small}) {
  186. grid-template-columns: 1fr 1fr;
  187. gap: ${space(2)};
  188. }
  189. `;
  190. const HeaderContainer = styled('div')`
  191. display: flex;
  192. justify-content: space-between;
  193. flex-wrap: wrap;
  194. `;
  195. const DescriptionContainer = styled('div')`
  196. width: 100%;
  197. margin-bottom: ${space(2)};
  198. font-size: 1rem;
  199. line-height: 1.2;
  200. `;
  201. export default SpanSummaryPage;