databaseLandingPage.tsx 9.3 KB

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