databaseLandingPage.tsx 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. import React, {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import Alert from 'sentry/components/alert';
  4. import {Breadcrumbs} from 'sentry/components/breadcrumbs';
  5. import ButtonBar from 'sentry/components/buttonBar';
  6. import FeedbackWidgetButton from 'sentry/components/feedback/widget/feedbackWidgetButton';
  7. import * as Layout from 'sentry/components/layouts/thirds';
  8. import {DatePageFilter} from 'sentry/components/organizations/datePageFilter';
  9. import {EnvironmentPageFilter} from 'sentry/components/organizations/environmentPageFilter';
  10. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  11. import {ProjectPageFilter} from 'sentry/components/organizations/projectPageFilter';
  12. import {PageHeadingQuestionTooltip} from 'sentry/components/pageHeadingQuestionTooltip';
  13. import SearchBar from 'sentry/components/searchBar';
  14. import {t} from 'sentry/locale';
  15. import {space} from 'sentry/styles/space';
  16. import {browserHistory} from 'sentry/utils/browserHistory';
  17. import {decodeScalar, decodeSorts} from 'sentry/utils/queryString';
  18. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  19. import {useLocation} from 'sentry/utils/useLocation';
  20. import useOrganization from 'sentry/utils/useOrganization';
  21. import {useOnboardingProject} from 'sentry/views/performance/browser/webVitals/utils/useOnboardingProject';
  22. import {DurationChart} from 'sentry/views/performance/database/durationChart';
  23. import {NoDataMessage} from 'sentry/views/performance/database/noDataMessage';
  24. import {isAValidSort, QueriesTable} from 'sentry/views/performance/database/queriesTable';
  25. import {
  26. MODULE_DESCRIPTION,
  27. MODULE_DOC_LINK,
  28. MODULE_TITLE,
  29. } from 'sentry/views/performance/database/settings';
  30. import {ThroughputChart} from 'sentry/views/performance/database/throughputChart';
  31. import {useSelectedDurationAggregate} from 'sentry/views/performance/database/useSelectedDurationAggregate';
  32. import * as ModuleLayout from 'sentry/views/performance/moduleLayout';
  33. import {ModulePageProviders} from 'sentry/views/performance/modulePageProviders';
  34. import Onboarding from 'sentry/views/performance/onboarding';
  35. import {useModuleBreadcrumbs} from 'sentry/views/performance/utils/useModuleBreadcrumbs';
  36. import {useSynchronizeCharts} from 'sentry/views/starfish/components/chart';
  37. import {useSpanMetrics} from 'sentry/views/starfish/queries/useDiscover';
  38. import {useSpanMetricsSeries} from 'sentry/views/starfish/queries/useDiscoverSeries';
  39. import {ModuleName, SpanMetricsField} from 'sentry/views/starfish/types';
  40. import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';
  41. import {ActionSelector} from 'sentry/views/starfish/views/spans/selectors/actionSelector';
  42. import {DomainSelector} from 'sentry/views/starfish/views/spans/selectors/domainSelector';
  43. export function DatabaseLandingPage() {
  44. const organization = useOrganization();
  45. const moduleName = ModuleName.DB;
  46. const location = useLocation();
  47. const onboardingProject = useOnboardingProject();
  48. const [selectedAggregate] = useSelectedDurationAggregate();
  49. const spanDescription = decodeScalar(location.query?.['span.description'], '');
  50. const spanAction = decodeScalar(location.query?.['span.action']);
  51. const spanDomain = decodeScalar(location.query?.['span.domain']);
  52. const sortField = decodeScalar(location.query?.[QueryParameterNames.SPANS_SORT]);
  53. let sort = decodeSorts(sortField).filter(isAValidSort)[0];
  54. if (!sort) {
  55. sort = DEFAULT_SORT;
  56. }
  57. const handleSearch = (newQuery: string) => {
  58. browserHistory.push({
  59. ...location,
  60. query: {
  61. ...location.query,
  62. 'span.description': newQuery === '' ? undefined : newQuery,
  63. [QueryParameterNames.SPANS_CURSOR]: undefined,
  64. },
  65. });
  66. };
  67. const chartFilters = {
  68. 'span.module': ModuleName.DB,
  69. has: 'span.description',
  70. };
  71. const tableFilters = {
  72. 'span.module': ModuleName.DB,
  73. 'span.action': spanAction,
  74. 'span.domain': spanDomain,
  75. 'span.description': spanDescription ? `*${spanDescription}*` : undefined,
  76. has: 'span.description',
  77. };
  78. const cursor = decodeScalar(location.query?.[QueryParameterNames.SPANS_CURSOR]);
  79. const queryListResponse = useSpanMetrics(
  80. {
  81. search: MutableSearch.fromQueryObject(tableFilters),
  82. fields: [
  83. 'project.id',
  84. 'span.group',
  85. 'span.description',
  86. 'spm()',
  87. 'avg(span.self_time)',
  88. 'sum(span.self_time)',
  89. 'time_spent_percentage()',
  90. ],
  91. sorts: [sort],
  92. limit: LIMIT,
  93. cursor,
  94. },
  95. 'api.starfish.use-span-list'
  96. );
  97. const {
  98. isLoading: isThroughputDataLoading,
  99. data: throughputData,
  100. error: throughputError,
  101. } = useSpanMetricsSeries(
  102. {
  103. search: MutableSearch.fromQueryObject(chartFilters),
  104. yAxis: ['spm()'],
  105. },
  106. 'api.starfish.span-landing-page-metrics-chart'
  107. );
  108. const {
  109. isLoading: isDurationDataLoading,
  110. data: durationData,
  111. error: durationError,
  112. } = useSpanMetricsSeries(
  113. {
  114. search: MutableSearch.fromQueryObject(chartFilters),
  115. yAxis: [`${selectedAggregate}(${SpanMetricsField.SPAN_SELF_TIME})`],
  116. },
  117. 'api.starfish.span-landing-page-metrics-chart'
  118. );
  119. const isCriticalDataLoading =
  120. isThroughputDataLoading || isDurationDataLoading || queryListResponse.isLoading;
  121. const isAnyCriticalDataAvailable =
  122. (queryListResponse.data ?? []).length > 0 ||
  123. durationData[`${selectedAggregate}(span.self_time)`].data?.some(
  124. ({value}) => value > 0
  125. ) ||
  126. throughputData['spm()'].data?.some(({value}) => value > 0);
  127. useSynchronizeCharts([!isThroughputDataLoading && !isDurationDataLoading]);
  128. const crumbs = useModuleBreadcrumbs('db');
  129. return (
  130. <React.Fragment>
  131. <Layout.Header>
  132. <Layout.HeaderContent>
  133. <Breadcrumbs crumbs={crumbs} />
  134. <Layout.Title>
  135. {MODULE_TITLE}
  136. <PageHeadingQuestionTooltip
  137. docsUrl={MODULE_DOC_LINK}
  138. title={MODULE_DESCRIPTION}
  139. />
  140. </Layout.Title>
  141. </Layout.HeaderContent>
  142. <Layout.HeaderActions>
  143. <ButtonBar gap={1}>
  144. <FeedbackWidgetButton />
  145. </ButtonBar>
  146. </Layout.HeaderActions>
  147. </Layout.Header>
  148. <Layout.Body>
  149. <Layout.Main fullWidth>
  150. <ModuleLayout.Layout>
  151. {!onboardingProject && !isCriticalDataLoading && (
  152. <ModuleLayout.Full>
  153. <NoDataMessage
  154. Wrapper={AlertBanner}
  155. isDataAvailable={isAnyCriticalDataAvailable}
  156. />
  157. </ModuleLayout.Full>
  158. )}
  159. <ModuleLayout.Full>
  160. <PageFilterBar condensed>
  161. <ProjectPageFilter />
  162. <EnvironmentPageFilter />
  163. <DatePageFilter />
  164. </PageFilterBar>
  165. </ModuleLayout.Full>
  166. {onboardingProject && (
  167. <ModuleLayout.Full>
  168. <Onboarding organization={organization} project={onboardingProject} />
  169. </ModuleLayout.Full>
  170. )}
  171. {!onboardingProject && (
  172. <Fragment>
  173. <ModuleLayout.Half>
  174. <ThroughputChart
  175. series={throughputData['spm()']}
  176. isLoading={isThroughputDataLoading}
  177. error={throughputError}
  178. />
  179. </ModuleLayout.Half>
  180. <ModuleLayout.Half>
  181. <DurationChart
  182. series={[durationData[`${selectedAggregate}(span.self_time)`]]}
  183. isLoading={isDurationDataLoading}
  184. error={durationError}
  185. />
  186. </ModuleLayout.Half>
  187. <ModuleLayout.Full>
  188. <FilterOptionsContainer>
  189. <SelectorContainer>
  190. <ActionSelector moduleName={moduleName} value={spanAction ?? ''} />
  191. </SelectorContainer>
  192. <SelectorContainer>
  193. <DomainSelector moduleName={moduleName} value={spanDomain ?? ''} />
  194. </SelectorContainer>
  195. </FilterOptionsContainer>
  196. </ModuleLayout.Full>
  197. <ModuleLayout.Full>
  198. <SearchBar
  199. query={spanDescription}
  200. placeholder={t('Search for more Queries')}
  201. onSearch={handleSearch}
  202. />
  203. </ModuleLayout.Full>
  204. <ModuleLayout.Full>
  205. <QueriesTable response={queryListResponse} sort={sort} />
  206. </ModuleLayout.Full>
  207. </Fragment>
  208. )}
  209. </ModuleLayout.Layout>
  210. </Layout.Main>
  211. </Layout.Body>
  212. </React.Fragment>
  213. );
  214. }
  215. const DEFAULT_SORT = {
  216. field: 'time_spent_percentage()' as const,
  217. kind: 'desc' as const,
  218. };
  219. function AlertBanner(props) {
  220. return <Alert {...props} type="info" showIcon />;
  221. }
  222. const FilterOptionsContainer = styled('div')`
  223. display: flex;
  224. flex-wrap: wrap;
  225. gap: ${space(2)};
  226. @media (min-width: ${p => p.theme.breakpoints.small}) {
  227. flex-wrap: nowrap;
  228. }
  229. `;
  230. const SelectorContainer = styled('div')`
  231. flex-basis: 100%;
  232. @media (min-width: ${p => p.theme.breakpoints.small}) {
  233. flex-basis: auto;
  234. }
  235. `;
  236. const LIMIT: number = 25;
  237. function PageWithProviders() {
  238. return (
  239. <ModulePageProviders moduleName="db" features="spans-first-ui">
  240. <DatabaseLandingPage />
  241. </ModulePageProviders>
  242. );
  243. }
  244. export default PageWithProviders;