Skip to content

Commit c17cd02

Browse files
authored
feat(explore): Hook to respect new downsampled retention (#104013)
This implements a version of the `useMaxPickableDays` hook that relies on their subcription's effectiveRetention`
1 parent bda4505 commit c17cd02

File tree

20 files changed

+363
-45
lines changed

20 files changed

+363
-45
lines changed

static/app/types/hooks.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type {ProductSelectionProps} from 'sentry/components/onboarding/productSe
88
import type DateRange from 'sentry/components/timeRangeSelector/dateRange';
99
import type SelectorItems from 'sentry/components/timeRangeSelector/selectorItems';
1010
import type {SentryRouteObject} from 'sentry/router/types';
11+
import type {useMaxPickableDays} from 'sentry/utils/useMaxPickableDays';
1112
import type {WidgetType} from 'sentry/views/dashboards/types';
1213
import type {OrganizationStatsProps} from 'sentry/views/organizationStats';
1314
import type {RouteAnalyticsContext} from 'sentry/views/routeAnalyticsContextProvider';
@@ -331,6 +332,7 @@ type ReactHooks = {
331332
dataset: WidgetType;
332333
}) => number;
333334
'react-hook:use-get-max-retention-days': () => number | undefined;
335+
'react-hook:use-max-pickable-days': typeof useMaxPickableDays;
334336
'react-hook:use-metric-detector-limit': () => {
335337
detectorCount: number;
336338
detectorLimit: number;

static/app/utils/useMaxPickableDays.spec.tsx

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import {OrganizationFixture} from 'sentry-fixture/organization';
22

3-
import {renderHook} from 'sentry-test/reactTestingLibrary';
3+
import {renderHookWithProviders} from 'sentry-test/reactTestingLibrary';
44

55
import {DataCategory} from 'sentry/types/core';
66

77
import {useMaxPickableDays} from './useMaxPickableDays';
88

99
describe('useMaxPickableDays', () => {
1010
it('returns 30/90 for spans without flag', () => {
11-
const {result} = renderHook(() =>
11+
const {result} = renderHookWithProviders(() =>
1212
useMaxPickableDays({
1313
dataCategories: [DataCategory.SPANS],
14-
organization: OrganizationFixture({features: []}),
1514
})
1615
);
1716

@@ -23,11 +22,14 @@ describe('useMaxPickableDays', () => {
2322
});
2423

2524
it('returns 90/90 for spans with flag', () => {
26-
const {result} = renderHook(() =>
27-
useMaxPickableDays({
28-
dataCategories: [DataCategory.SPANS],
25+
const {result} = renderHookWithProviders(
26+
() =>
27+
useMaxPickableDays({
28+
dataCategories: [DataCategory.SPANS],
29+
}),
30+
{
2931
organization: OrganizationFixture({features: ['visibility-explore-range-high']}),
30-
})
32+
}
3133
);
3234

3335
expect(result.current).toEqual({
@@ -38,10 +40,9 @@ describe('useMaxPickableDays', () => {
3840
});
3941

4042
it('returns 30/30 days for tracemetrics', () => {
41-
const {result} = renderHook(() =>
43+
const {result} = renderHookWithProviders(() =>
4244
useMaxPickableDays({
4345
dataCategories: [DataCategory.TRACE_METRICS],
44-
organization: OrganizationFixture(),
4546
})
4647
);
4748

@@ -53,10 +54,9 @@ describe('useMaxPickableDays', () => {
5354
});
5455

5556
it('returns 30/30 days for logs', () => {
56-
const {result} = renderHook(() =>
57+
const {result} = renderHookWithProviders(() =>
5758
useMaxPickableDays({
5859
dataCategories: [DataCategory.LOG_BYTE, DataCategory.LOG_ITEM],
59-
organization: OrganizationFixture(),
6060
})
6161
);
6262

@@ -68,7 +68,7 @@ describe('useMaxPickableDays', () => {
6868
});
6969

7070
it('returns 30/90 for many without flag', () => {
71-
const {result} = renderHook(() =>
71+
const {result} = renderHookWithProviders(() =>
7272
useMaxPickableDays({
7373
dataCategories: [
7474
DataCategory.SPANS,
@@ -77,7 +77,6 @@ describe('useMaxPickableDays', () => {
7777
DataCategory.LOG_BYTE,
7878
DataCategory.LOG_ITEM,
7979
],
80-
organization: OrganizationFixture(),
8180
})
8281
);
8382

static/app/utils/useMaxPickableDays.tsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import {useMemo, type ReactNode} from 'react';
33
import HookOrDefault from 'sentry/components/hookOrDefault';
44
import type {DatePageFilterProps} from 'sentry/components/organizations/datePageFilter';
55
import {t} from 'sentry/locale';
6+
import HookStore from 'sentry/stores/hookStore';
67
import {DataCategory} from 'sentry/types/core';
78
import type {Organization} from 'sentry/types/organization';
9+
import useOrganization from 'sentry/utils/useOrganization';
810

911
export interface MaxPickableDaysOptions {
1012
/**
@@ -19,15 +21,20 @@ export interface MaxPickableDaysOptions {
1921
upsellFooter?: ReactNode;
2022
}
2123

22-
interface UseMaxPickableDaysProps {
24+
export interface UseMaxPickableDaysProps {
2325
dataCategories: readonly [DataCategory, ...DataCategory[]];
24-
organization: Organization;
2526
}
2627

2728
export function useMaxPickableDays({
2829
dataCategories,
29-
organization,
3030
}: UseMaxPickableDaysProps): MaxPickableDaysOptions {
31+
const useMaxPickableDaysHook =
32+
HookStore.get('react-hook:use-max-pickable-days')[0] ?? useMaxPickableDaysImpl;
33+
return useMaxPickableDaysHook({dataCategories});
34+
}
35+
36+
function useMaxPickableDaysImpl({dataCategories}: UseMaxPickableDaysProps) {
37+
const organization = useOrganization();
3138
return useMemo(() => {
3239
function getMaxPickableDaysFor(dataCategory: DataCategory) {
3340
return getMaxPickableDays(dataCategory, organization);
@@ -37,7 +44,7 @@ export function useMaxPickableDays({
3744
}, [dataCategories, organization]);
3845
}
3946

40-
function getBestMaxPickableDays(
47+
export function getBestMaxPickableDays(
4148
dataCategories: readonly [DataCategory, ...DataCategory[]],
4249
getMaxPickableDaysFor: (dataCategory: DataCategory) => MaxPickableDaysOptions
4350
) {
@@ -69,7 +76,7 @@ function max(
6976

7077
const DESCRIPTION = t('To query over longer time ranges, upgrade to Business');
7178

72-
function getMaxPickableDays(
79+
export function getMaxPickableDays(
7380
dataCategory: DataCategory,
7481
organization: Organization
7582
): MaxPickableDaysOptions {
@@ -84,7 +91,7 @@ function getMaxPickableDays(
8491
return {
8592
maxPickableDays,
8693
maxUpgradableDays: 90,
87-
upsellFooter: <UpsellFooterHook description={DESCRIPTION} source="spans" />,
94+
upsellFooter: SpansUpsellFooter,
8895
};
8996
}
9097
case DataCategory.TRACE_METRICS:
@@ -106,3 +113,7 @@ const UpsellFooterHook = HookOrDefault({
106113
hookName: 'component:header-date-page-filter-upsell-footer',
107114
defaultComponent: () => null,
108115
});
116+
117+
export const SpansUpsellFooter = (
118+
<UpsellFooterHook description={DESCRIPTION} source="spans" />
119+
);

static/app/views/explore/logs/content.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export default function LogsContent() {
3535
const organization = useOrganization();
3636
const maxPickableDays = useMaxPickableDays({
3737
dataCategories: [DataCategory.LOG_BYTE],
38-
organization,
3938
});
4039
const datePageFilterProps = useDatePageFilterProps(maxPickableDays);
4140

static/app/views/explore/metrics/content.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ export default function MetricsContent() {
2828
const onboardingProject = useOnboardingProject({property: 'hasTraceMetrics'});
2929
const maxPickableDays = useMaxPickableDays({
3030
dataCategories: [DataCategory.TRACE_METRICS],
31-
organization,
3231
});
3332
const datePageFilterProps = useDatePageFilterProps(maxPickableDays);
3433
return (

static/app/views/explore/multiQueryMode/content.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,8 @@ function Content({datePageFilterProps}: ContentProps) {
212212
}
213213

214214
export function MultiQueryModeContent() {
215-
const organization = useOrganization();
216215
const maxPickableDays = useMaxPickableDays({
217216
dataCategories: [DataCategory.SPANS],
218-
organization,
219217
});
220218
const datePageFilterProps = useDatePageFilterProps(maxPickableDays);
221219

static/app/views/explore/spans/content.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ export function ExploreContent() {
4444
const onboardingProject = useOnboardingProject();
4545
const maxPickableDays = useMaxPickableDays({
4646
dataCategories: [DataCategory.SPANS],
47-
organization,
4847
});
4948
const datePageFilterProps = useDatePageFilterProps(maxPickableDays);
5049

static/app/views/insights/agentModels/views/modelsLandingPage.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {SearchQueryBuilderProvider} from 'sentry/components/searchQueryBuilder/c
1010
import {DataCategory} from 'sentry/types/core';
1111
import {useDatePageFilterProps} from 'sentry/utils/useDatePageFilterProps';
1212
import {useMaxPickableDays} from 'sentry/utils/useMaxPickableDays';
13-
import useOrganization from 'sentry/utils/useOrganization';
1413
import {TraceItemAttributeProvider} from 'sentry/views/explore/contexts/traceItemAttributeContext';
1514
import {TraceItemDataset} from 'sentry/views/explore/types';
1615
import {InsightsEnvironmentSelector} from 'sentry/views/insights/common/components/enviornmentSelector';
@@ -98,10 +97,8 @@ function AgentModelsLandingPage({datePageFilterProps}: AgentModelsLandingPagePro
9897
}
9998

10099
function PageWithProviders() {
101-
const organization = useOrganization();
102100
const maxPickableDays = useMaxPickableDays({
103101
dataCategories: [DataCategory.SPANS],
104-
organization,
105102
});
106103
const datePageFilterProps = useDatePageFilterProps(maxPickableDays);
107104

static/app/views/insights/agentTools/views/toolsLandingPage.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {SearchQueryBuilderProvider} from 'sentry/components/searchQueryBuilder/c
1010
import {DataCategory} from 'sentry/types/core';
1111
import {useDatePageFilterProps} from 'sentry/utils/useDatePageFilterProps';
1212
import {useMaxPickableDays} from 'sentry/utils/useMaxPickableDays';
13-
import useOrganization from 'sentry/utils/useOrganization';
1413
import {TraceItemAttributeProvider} from 'sentry/views/explore/contexts/traceItemAttributeContext';
1514
import {TraceItemDataset} from 'sentry/views/explore/types';
1615
import {InsightsEnvironmentSelector} from 'sentry/views/insights/common/components/enviornmentSelector';
@@ -94,10 +93,8 @@ function AgentToolsLandingPage({datePageFilterProps}: AgentToolsLandingPageProps
9493
}
9594

9695
function PageWithProviders() {
97-
const organization = useOrganization();
9896
const maxPickableDays = useMaxPickableDays({
9997
dataCategories: [DataCategory.SPANS],
100-
organization,
10198
});
10299
const datePageFilterProps = useDatePageFilterProps(maxPickableDays);
103100

static/app/views/insights/aiGenerations/views/overview.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,8 @@ function AIGenerationsPage({datePageFilterProps}: AIGenerationsPageProps) {
261261
}
262262

263263
function PageWithProviders() {
264-
const organization = useOrganization();
265264
const maxPickableDays = useMaxPickableDays({
266265
dataCategories: [DataCategory.SPANS],
267-
organization,
268266
});
269267
const datePageFilterProps = useDatePageFilterProps(maxPickableDays);
270268

0 commit comments

Comments
 (0)