databaseSpanSummaryPage.tsx 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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 FeedbackWidget from 'sentry/components/feedback/widget/feedbackWidget';
  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 {RateUnits} from 'sentry/utils/discover/fields';
  14. import {formatRate} from 'sentry/utils/formatters';
  15. import {decodeScalar} from 'sentry/utils/queryString';
  16. import {useLocation} from 'sentry/utils/useLocation';
  17. import useOrganization from 'sentry/utils/useOrganization';
  18. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  19. import {DurationAggregateSelector} from 'sentry/views/performance/database/durationAggregateSelector';
  20. import {ModulePageProviders} from 'sentry/views/performance/database/modulePageProviders';
  21. import {
  22. AVAILABLE_DURATION_AGGREGATE_OPTIONS,
  23. DEFAULT_DURATION_AGGREGATE,
  24. } from 'sentry/views/performance/database/settings';
  25. import {AVG_COLOR, THROUGHPUT_COLOR} from 'sentry/views/starfish/colours';
  26. import Chart, {useSynchronizeCharts} from 'sentry/views/starfish/components/chart';
  27. import ChartPanel from 'sentry/views/starfish/components/chartPanel';
  28. import {SpanDescription} from 'sentry/views/starfish/components/spanDescription';
  29. import {useFullSpanFromTrace} from 'sentry/views/starfish/queries/useFullSpanFromTrace';
  30. import {
  31. SpanSummaryQueryFilters,
  32. useSpanMetrics,
  33. } from 'sentry/views/starfish/queries/useSpanMetrics';
  34. import {useSpanMetricsSeries} from 'sentry/views/starfish/queries/useSpanMetricsSeries';
  35. import {SpanFunction, SpanMetricsField} from 'sentry/views/starfish/types';
  36. import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';
  37. import {getThroughputChartTitle} from 'sentry/views/starfish/views/spans/types';
  38. import {useModuleSort} from 'sentry/views/starfish/views/spans/useModuleSort';
  39. import {Block, BlockContainer} from 'sentry/views/starfish/views/spanSummaryPage/block';
  40. import {SampleList} from 'sentry/views/starfish/views/spanSummaryPage/sampleList';
  41. import {SpanMetricsRibbon} from 'sentry/views/starfish/views/spanSummaryPage/spanMetricsRibbon';
  42. import {SpanTransactionsTable} from 'sentry/views/starfish/views/spanSummaryPage/spanTransactionsTable';
  43. type Query = {
  44. endpoint: string;
  45. endpointMethod: string;
  46. transaction: string;
  47. transactionMethod: string;
  48. [QueryParameterNames.SPANS_SORT]: string;
  49. aggregate?: string;
  50. };
  51. type Props = {
  52. location: Location<Query>;
  53. } & RouteComponentProps<Query, {groupId: string}>;
  54. function SpanSummaryPage({params}: Props) {
  55. const organization = useOrganization();
  56. const location = useLocation<Query>();
  57. const arePercentilesEnabled = organization.features?.includes(
  58. 'performance-database-view-percentiles'
  59. );
  60. let durationAggregate = arePercentilesEnabled
  61. ? decodeScalar(location.query.aggregate, DEFAULT_DURATION_AGGREGATE)
  62. : DEFAULT_DURATION_AGGREGATE;
  63. if (
  64. !AVAILABLE_DURATION_AGGREGATE_OPTIONS.map(option => option.value).includes(
  65. durationAggregate
  66. )
  67. ) {
  68. durationAggregate = DEFAULT_DURATION_AGGREGATE;
  69. }
  70. const {groupId} = params;
  71. const {transaction, transactionMethod, endpoint, endpointMethod} = location.query;
  72. const queryFilter: SpanSummaryQueryFilters = endpoint
  73. ? {transactionName: endpoint, 'transaction.method': endpointMethod}
  74. : {};
  75. const sort = useModuleSort(QueryParameterNames.ENDPOINTS_SORT, DEFAULT_SORT);
  76. const {data: fullSpan} = useFullSpanFromTrace(groupId);
  77. const {data: spanMetrics} = useSpanMetrics(
  78. groupId,
  79. queryFilter,
  80. [
  81. SpanMetricsField.SPAN_OP,
  82. SpanMetricsField.SPAN_DESCRIPTION,
  83. SpanMetricsField.SPAN_ACTION,
  84. SpanMetricsField.SPAN_DOMAIN,
  85. 'count()',
  86. `${SpanFunction.SPM}()`,
  87. `sum(${SpanMetricsField.SPAN_SELF_TIME})`,
  88. `avg(${SpanMetricsField.SPAN_SELF_TIME})`,
  89. `${SpanFunction.TIME_SPENT_PERCENTAGE}()`,
  90. `${SpanFunction.HTTP_ERROR_COUNT}()`,
  91. ],
  92. 'api.starfish.span-summary-page-metrics'
  93. );
  94. const span = {
  95. ...spanMetrics,
  96. [SpanMetricsField.SPAN_GROUP]: groupId,
  97. } as {
  98. [SpanMetricsField.SPAN_OP]: string;
  99. [SpanMetricsField.SPAN_DESCRIPTION]: string;
  100. [SpanMetricsField.SPAN_ACTION]: string;
  101. [SpanMetricsField.SPAN_DOMAIN]: string[];
  102. [SpanMetricsField.SPAN_GROUP]: string;
  103. };
  104. const {isLoading: isThroughputDataLoading, data: throughputData} = useSpanMetricsSeries(
  105. groupId,
  106. queryFilter,
  107. ['spm()'],
  108. 'api.starfish.span-summary-page-metrics-chart'
  109. );
  110. const {isLoading: isDurationDataLoading, data: durationData} = useSpanMetricsSeries(
  111. groupId,
  112. queryFilter,
  113. [`${durationAggregate}(${SpanMetricsField.SPAN_SELF_TIME})`],
  114. 'api.starfish.span-summary-page-metrics-chart'
  115. );
  116. useSynchronizeCharts([!isThroughputDataLoading && !isDurationDataLoading]);
  117. return (
  118. <ModulePageProviders
  119. title={[t('Performance'), t('Database'), t('Query Summary')].join(' — ')}
  120. >
  121. <Layout.Header>
  122. <Layout.HeaderContent>
  123. <Breadcrumbs
  124. crumbs={[
  125. {
  126. label: 'Performance',
  127. to: normalizeUrl(`/organizations/${organization.slug}/performance/`),
  128. preservePageFilters: true,
  129. },
  130. {
  131. label: 'Queries',
  132. to: normalizeUrl(
  133. `/organizations/${organization.slug}/performance/database`
  134. ),
  135. preservePageFilters: true,
  136. },
  137. {
  138. label: 'Query Summary',
  139. },
  140. ]}
  141. />
  142. <Layout.Title>{t('Query Summary')}</Layout.Title>
  143. </Layout.HeaderContent>
  144. </Layout.Header>
  145. <Layout.Body>
  146. <FeedbackWidget />
  147. <Layout.Main fullWidth>
  148. <HeaderContainer>
  149. <PaddedContainer>
  150. <PageFilterBar condensed>
  151. <EnvironmentPageFilter />
  152. <DatePageFilter />
  153. </PageFilterBar>
  154. </PaddedContainer>
  155. <SpanMetricsRibbon spanMetrics={span} />
  156. </HeaderContainer>
  157. {span?.[SpanMetricsField.SPAN_DESCRIPTION] && (
  158. <DescriptionContainer>
  159. <SpanDescription
  160. span={{
  161. ...span,
  162. [SpanMetricsField.SPAN_DESCRIPTION]:
  163. fullSpan?.description ??
  164. spanMetrics?.[SpanMetricsField.SPAN_DESCRIPTION],
  165. }}
  166. />
  167. </DescriptionContainer>
  168. )}
  169. <BlockContainer>
  170. <Block>
  171. <ChartPanel
  172. title={getThroughputChartTitle(span?.[SpanMetricsField.SPAN_OP])}
  173. >
  174. <Chart
  175. height={CHART_HEIGHT}
  176. data={[throughputData['spm()']]}
  177. loading={isThroughputDataLoading}
  178. utc={false}
  179. chartColors={[THROUGHPUT_COLOR]}
  180. isLineChart
  181. definedAxisTicks={4}
  182. aggregateOutputFormat="rate"
  183. rateUnit={RateUnits.PER_MINUTE}
  184. tooltipFormatterOptions={{
  185. valueFormatter: value => formatRate(value, RateUnits.PER_MINUTE),
  186. }}
  187. />
  188. </ChartPanel>
  189. </Block>
  190. <Block>
  191. <ChartPanel
  192. title={
  193. arePercentilesEnabled ? (
  194. <DurationAggregateSelector aggregate={durationAggregate} />
  195. ) : (
  196. t('Average Duration')
  197. )
  198. }
  199. >
  200. <Chart
  201. height={CHART_HEIGHT}
  202. data={[
  203. durationData[
  204. `${durationAggregate}(${SpanMetricsField.SPAN_SELF_TIME})`
  205. ],
  206. ]}
  207. loading={isDurationDataLoading}
  208. utc={false}
  209. chartColors={[AVG_COLOR]}
  210. isLineChart
  211. definedAxisTicks={4}
  212. />
  213. </ChartPanel>
  214. </Block>
  215. </BlockContainer>
  216. {span && (
  217. <SpanTransactionsTable
  218. span={span}
  219. sort={sort}
  220. endpoint={endpoint}
  221. endpointMethod={endpointMethod}
  222. />
  223. )}
  224. <SampleList
  225. groupId={span[SpanMetricsField.SPAN_GROUP]}
  226. transactionName={transaction}
  227. transactionMethod={transactionMethod}
  228. />
  229. </Layout.Main>
  230. </Layout.Body>
  231. </ModulePageProviders>
  232. );
  233. }
  234. const CHART_HEIGHT = 160;
  235. const DEFAULT_SORT: Sort = {
  236. kind: 'desc',
  237. field: 'time_spent_percentage()',
  238. };
  239. const PaddedContainer = styled('div')`
  240. margin-bottom: ${space(2)};
  241. `;
  242. const HeaderContainer = styled('div')`
  243. display: flex;
  244. justify-content: space-between;
  245. flex-wrap: wrap;
  246. `;
  247. const DescriptionContainer = styled('div')`
  248. width: 100%;
  249. margin-bottom: ${space(2)};
  250. font-size: 1rem;
  251. line-height: 1.2;
  252. `;
  253. export default SpanSummaryPage;