databaseSpanSummaryPage.tsx 7.6 KB

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