123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279 |
- import React, {Fragment} from 'react';
- import styled from '@emotion/styled';
- import Alert from 'sentry/components/alert';
- import {Breadcrumbs} from 'sentry/components/breadcrumbs';
- import ButtonBar from 'sentry/components/buttonBar';
- import FeedbackWidgetButton from 'sentry/components/feedback/widget/feedbackWidgetButton';
- import * as Layout from 'sentry/components/layouts/thirds';
- import {DatePageFilter} from 'sentry/components/organizations/datePageFilter';
- import {EnvironmentPageFilter} from 'sentry/components/organizations/environmentPageFilter';
- import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
- import {ProjectPageFilter} from 'sentry/components/organizations/projectPageFilter';
- import {PageHeadingQuestionTooltip} from 'sentry/components/pageHeadingQuestionTooltip';
- import SearchBar from 'sentry/components/searchBar';
- import {t} from 'sentry/locale';
- import {space} from 'sentry/styles/space';
- import {browserHistory} from 'sentry/utils/browserHistory';
- import {decodeScalar, decodeSorts} from 'sentry/utils/queryString';
- import {MutableSearch} from 'sentry/utils/tokenizeSearch';
- import {useLocation} from 'sentry/utils/useLocation';
- import useOrganization from 'sentry/utils/useOrganization';
- import {useOnboardingProject} from 'sentry/views/performance/browser/webVitals/utils/useOnboardingProject';
- import {DurationChart} from 'sentry/views/performance/database/durationChart';
- import {NoDataMessage} from 'sentry/views/performance/database/noDataMessage';
- import {isAValidSort, QueriesTable} from 'sentry/views/performance/database/queriesTable';
- import {
- MODULE_DESCRIPTION,
- MODULE_DOC_LINK,
- MODULE_TITLE,
- } from 'sentry/views/performance/database/settings';
- import {ThroughputChart} from 'sentry/views/performance/database/throughputChart';
- import {useSelectedDurationAggregate} from 'sentry/views/performance/database/useSelectedDurationAggregate';
- import * as ModuleLayout from 'sentry/views/performance/moduleLayout';
- import {ModulePageProviders} from 'sentry/views/performance/modulePageProviders';
- import Onboarding from 'sentry/views/performance/onboarding';
- import {useModuleBreadcrumbs} from 'sentry/views/performance/utils/useModuleBreadcrumbs';
- import {useSynchronizeCharts} from 'sentry/views/starfish/components/chart';
- import {useSpanMetrics} from 'sentry/views/starfish/queries/useDiscover';
- import {useSpanMetricsSeries} from 'sentry/views/starfish/queries/useDiscoverSeries';
- import {ModuleName, SpanMetricsField} from 'sentry/views/starfish/types';
- import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';
- import {ActionSelector} from 'sentry/views/starfish/views/spans/selectors/actionSelector';
- import {DomainSelector} from 'sentry/views/starfish/views/spans/selectors/domainSelector';
- export function DatabaseLandingPage() {
- const organization = useOrganization();
- const moduleName = ModuleName.DB;
- const location = useLocation();
- const onboardingProject = useOnboardingProject();
- const [selectedAggregate] = useSelectedDurationAggregate();
- const spanDescription = decodeScalar(location.query?.['span.description'], '');
- const spanAction = decodeScalar(location.query?.['span.action']);
- const spanDomain = decodeScalar(location.query?.['span.domain']);
- const sortField = decodeScalar(location.query?.[QueryParameterNames.SPANS_SORT]);
- let sort = decodeSorts(sortField).filter(isAValidSort)[0];
- if (!sort) {
- sort = DEFAULT_SORT;
- }
- const handleSearch = (newQuery: string) => {
- browserHistory.push({
- ...location,
- query: {
- ...location.query,
- 'span.description': newQuery === '' ? undefined : newQuery,
- [QueryParameterNames.SPANS_CURSOR]: undefined,
- },
- });
- };
- const chartFilters = {
- 'span.module': ModuleName.DB,
- has: 'span.description',
- };
- const tableFilters = {
- 'span.module': ModuleName.DB,
- 'span.action': spanAction,
- 'span.domain': spanDomain,
- 'span.description': spanDescription ? `*${spanDescription}*` : undefined,
- has: 'span.description',
- };
- const cursor = decodeScalar(location.query?.[QueryParameterNames.SPANS_CURSOR]);
- const queryListResponse = useSpanMetrics(
- {
- search: MutableSearch.fromQueryObject(tableFilters),
- fields: [
- 'project.id',
- 'span.group',
- 'span.description',
- 'spm()',
- 'avg(span.self_time)',
- 'sum(span.self_time)',
- 'time_spent_percentage()',
- ],
- sorts: [sort],
- limit: LIMIT,
- cursor,
- },
- 'api.starfish.use-span-list'
- );
- const {
- isLoading: isThroughputDataLoading,
- data: throughputData,
- error: throughputError,
- } = useSpanMetricsSeries(
- {
- search: MutableSearch.fromQueryObject(chartFilters),
- yAxis: ['spm()'],
- },
- 'api.starfish.span-landing-page-metrics-chart'
- );
- const {
- isLoading: isDurationDataLoading,
- data: durationData,
- error: durationError,
- } = useSpanMetricsSeries(
- {
- search: MutableSearch.fromQueryObject(chartFilters),
- yAxis: [`${selectedAggregate}(${SpanMetricsField.SPAN_SELF_TIME})`],
- },
- 'api.starfish.span-landing-page-metrics-chart'
- );
- const isCriticalDataLoading =
- isThroughputDataLoading || isDurationDataLoading || queryListResponse.isLoading;
- const isAnyCriticalDataAvailable =
- (queryListResponse.data ?? []).length > 0 ||
- durationData[`${selectedAggregate}(span.self_time)`].data?.some(
- ({value}) => value > 0
- ) ||
- throughputData['spm()'].data?.some(({value}) => value > 0);
- useSynchronizeCharts([!isThroughputDataLoading && !isDurationDataLoading]);
- const crumbs = useModuleBreadcrumbs('db');
- return (
- <React.Fragment>
- <Layout.Header>
- <Layout.HeaderContent>
- <Breadcrumbs crumbs={crumbs} />
- <Layout.Title>
- {MODULE_TITLE}
- <PageHeadingQuestionTooltip
- docsUrl={MODULE_DOC_LINK}
- title={MODULE_DESCRIPTION}
- />
- </Layout.Title>
- </Layout.HeaderContent>
- <Layout.HeaderActions>
- <ButtonBar gap={1}>
- <FeedbackWidgetButton />
- </ButtonBar>
- </Layout.HeaderActions>
- </Layout.Header>
- <Layout.Body>
- <Layout.Main fullWidth>
- <ModuleLayout.Layout>
- {!onboardingProject && !isCriticalDataLoading && (
- <ModuleLayout.Full>
- <NoDataMessage
- Wrapper={AlertBanner}
- isDataAvailable={isAnyCriticalDataAvailable}
- />
- </ModuleLayout.Full>
- )}
- <ModuleLayout.Full>
- <PageFilterBar condensed>
- <ProjectPageFilter />
- <EnvironmentPageFilter />
- <DatePageFilter />
- </PageFilterBar>
- </ModuleLayout.Full>
- {onboardingProject && (
- <ModuleLayout.Full>
- <Onboarding organization={organization} project={onboardingProject} />
- </ModuleLayout.Full>
- )}
- {!onboardingProject && (
- <Fragment>
- <ModuleLayout.Half>
- <ThroughputChart
- series={throughputData['spm()']}
- isLoading={isThroughputDataLoading}
- error={throughputError}
- />
- </ModuleLayout.Half>
- <ModuleLayout.Half>
- <DurationChart
- series={[durationData[`${selectedAggregate}(span.self_time)`]]}
- isLoading={isDurationDataLoading}
- error={durationError}
- />
- </ModuleLayout.Half>
- <ModuleLayout.Full>
- <FilterOptionsContainer>
- <SelectorContainer>
- <ActionSelector moduleName={moduleName} value={spanAction ?? ''} />
- </SelectorContainer>
- <SelectorContainer>
- <DomainSelector moduleName={moduleName} value={spanDomain ?? ''} />
- </SelectorContainer>
- </FilterOptionsContainer>
- </ModuleLayout.Full>
- <ModuleLayout.Full>
- <SearchBar
- query={spanDescription}
- placeholder={t('Search for more Queries')}
- onSearch={handleSearch}
- />
- </ModuleLayout.Full>
- <ModuleLayout.Full>
- <QueriesTable response={queryListResponse} sort={sort} />
- </ModuleLayout.Full>
- </Fragment>
- )}
- </ModuleLayout.Layout>
- </Layout.Main>
- </Layout.Body>
- </React.Fragment>
- );
- }
- const DEFAULT_SORT = {
- field: 'time_spent_percentage()' as const,
- kind: 'desc' as const,
- };
- function AlertBanner(props) {
- return <Alert {...props} type="info" showIcon />;
- }
- const FilterOptionsContainer = styled('div')`
- display: flex;
- flex-wrap: wrap;
- gap: ${space(2)};
- @media (min-width: ${p => p.theme.breakpoints.small}) {
- flex-wrap: nowrap;
- }
- `;
- const SelectorContainer = styled('div')`
- flex-basis: 100%;
- @media (min-width: ${p => p.theme.breakpoints.small}) {
- flex-basis: auto;
- }
- `;
- const LIMIT: number = 25;
- function PageWithProviders() {
- return (
- <ModulePageProviders moduleName="db" features="spans-first-ui">
- <DatabaseLandingPage />
- </ModulePageProviders>
- );
- }
- export default PageWithProviders;
|