databaseSpanSummaryPage.tsx 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. import {RouteComponentProps} from 'react-router';
  2. import styled from '@emotion/styled';
  3. import {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 {
  25. SpanFunction,
  26. SpanMetricsField,
  27. SpanMetricsQueryFilters,
  28. } from 'sentry/views/starfish/types';
  29. import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';
  30. import {useModuleSort} from 'sentry/views/starfish/views/spans/useModuleSort';
  31. import {SampleList} from 'sentry/views/starfish/views/spanSummaryPage/sampleList';
  32. import {SpanMetricsRibbon} from 'sentry/views/starfish/views/spanSummaryPage/spanMetricsRibbon';
  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} = 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 {isLoading: isThroughputDataLoading, data: throughputData} = useSpanMetricsSeries(
  87. {
  88. filters,
  89. yAxis: ['spm()'],
  90. referrer: 'api.starfish.span-summary-page-metrics-chart',
  91. }
  92. );
  93. const {isLoading: isDurationDataLoading, data: durationData} = useSpanMetricsSeries({
  94. filters,
  95. yAxis: [`${selectedAggregate}(${SpanMetricsField.SPAN_SELF_TIME})`],
  96. referrer: 'api.starfish.span-summary-page-metrics-chart',
  97. });
  98. useSynchronizeCharts([!isThroughputDataLoading && !isDurationDataLoading]);
  99. return (
  100. <ModulePageProviders
  101. title={[t('Performance'), t('Database'), t('Query Summary')].join(' — ')}
  102. >
  103. <Layout.Header>
  104. <Layout.HeaderContent>
  105. <Breadcrumbs
  106. crumbs={[
  107. {
  108. label: 'Performance',
  109. to: normalizeUrl(`/organizations/${organization.slug}/performance/`),
  110. preservePageFilters: true,
  111. },
  112. {
  113. label: 'Queries',
  114. to: normalizeUrl(
  115. `/organizations/${organization.slug}/performance/database`
  116. ),
  117. preservePageFilters: true,
  118. },
  119. {
  120. label: 'Query Summary',
  121. },
  122. ]}
  123. />
  124. <Layout.Title>{t('Query Summary')}</Layout.Title>
  125. </Layout.HeaderContent>
  126. </Layout.Header>
  127. <Layout.Body>
  128. <Layout.Main fullWidth>
  129. <FloatingFeedbackWidget />
  130. <HeaderContainer>
  131. <PaddedContainer>
  132. <PageFilterBar condensed>
  133. <EnvironmentPageFilter />
  134. <DatePageFilter />
  135. </PageFilterBar>
  136. </PaddedContainer>
  137. <SpanMetricsRibbon spanMetrics={span} />
  138. </HeaderContainer>
  139. {groupId && (
  140. <DescriptionContainer>
  141. <DatabaseSpanDescription
  142. groupId={groupId}
  143. preliminaryDescription={spanMetrics?.['span.description']}
  144. />
  145. </DescriptionContainer>
  146. )}
  147. <ChartContainer>
  148. <ThroughputChart
  149. series={throughputData['spm()']}
  150. isLoading={isThroughputDataLoading}
  151. />
  152. <DurationChart
  153. series={
  154. durationData[`${selectedAggregate}(${SpanMetricsField.SPAN_SELF_TIME})`]
  155. }
  156. isLoading={isDurationDataLoading}
  157. />
  158. </ChartContainer>
  159. {span && (
  160. <SpanTransactionsTable
  161. span={span}
  162. sort={sort}
  163. endpoint={endpoint}
  164. endpointMethod={endpointMethod}
  165. />
  166. )}
  167. <SampleList
  168. groupId={span[SpanMetricsField.SPAN_GROUP]}
  169. transactionName={transaction}
  170. transactionMethod={transactionMethod}
  171. />
  172. </Layout.Main>
  173. </Layout.Body>
  174. </ModulePageProviders>
  175. );
  176. }
  177. const DEFAULT_SORT: Sort = {
  178. kind: 'desc',
  179. field: 'time_spent_percentage()',
  180. };
  181. const PaddedContainer = styled('div')`
  182. margin-bottom: ${space(2)};
  183. `;
  184. const ChartContainer = styled('div')`
  185. display: grid;
  186. gap: 0;
  187. grid-template-columns: 1fr;
  188. @media (min-width: ${p => p.theme.breakpoints.small}) {
  189. grid-template-columns: 1fr 1fr;
  190. gap: ${space(2)};
  191. }
  192. `;
  193. const HeaderContainer = styled('div')`
  194. display: flex;
  195. justify-content: space-between;
  196. flex-wrap: wrap;
  197. `;
  198. const DescriptionContainer = styled('div')`
  199. width: 100%;
  200. margin-bottom: ${space(2)};
  201. font-size: 1rem;
  202. line-height: 1.2;
  203. `;
  204. export default SpanSummaryPage;