Skip to content

Commit 6b16d41

Browse files
authored
fix(logs): Disable auto-refresh when not counting logs (#97899)
Previously, this was allowing users to turn on auto-refresh when using another aggregate. However, the streaming only supported counting messages.
1 parent 06fc0ef commit 6b16d41

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

static/app/views/explore/logs/logsAutoRefresh.spec.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,36 @@ describe('LogsAutoRefresh Integration Tests', () => {
212212
});
213213
});
214214

215+
it('disables auto-refresh when using not count(message)', async () => {
216+
renderWithProviders(<AutorefreshToggle />, {
217+
initialRouterConfig: {
218+
...routerConfig,
219+
location: {
220+
...routerConfig.location,
221+
query: {
222+
...routerConfig.location.query,
223+
logsAggregate: 'avg',
224+
logsAggregateParam: 'payload_size',
225+
},
226+
},
227+
},
228+
organization,
229+
});
230+
231+
const toggleSwitch = screen.getByRole('checkbox', {name: 'Auto-refresh'});
232+
expect(toggleSwitch).toBeDisabled();
233+
234+
await userEvent.hover(toggleSwitch);
235+
236+
await waitFor(() => {
237+
expect(
238+
screen.getByText(
239+
/Auto-refresh is only available when visualizing `count\(logs\)`./i
240+
)
241+
).toBeInTheDocument();
242+
});
243+
});
244+
215245
it('shows error state in URL when query fails', async () => {
216246
const {router} = renderWithProviders(<AutorefreshToggle />, {
217247
initialRouterConfig: enabledRouterConfig,

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {Switch} from 'sentry/components/core/switch';
44
import {Tooltip} from 'sentry/components/core/tooltip';
55
import {t, tct} from 'sentry/locale';
66
import {trackAnalytics} from 'sentry/utils/analytics';
7+
import {AggregationKey} from 'sentry/utils/fields';
78
import useOrganization from 'sentry/utils/useOrganization';
89
import usePageFilters from 'sentry/utils/usePageFilters';
910
import usePrevious from 'sentry/utils/usePrevious';
@@ -21,15 +22,22 @@ import {
2122
import {AutoRefreshLabel} from 'sentry/views/explore/logs/styles';
2223
import {useLogsAutoRefreshInterval} from 'sentry/views/explore/logs/useLogsAutoRefreshInterval';
2324
import {checkSortIsTimeBasedDescending} from 'sentry/views/explore/logs/utils';
24-
import {useQueryParamsMode} from 'sentry/views/explore/queryParams/context';
25+
import {
26+
useQueryParamsMode,
27+
useQueryParamsVisualizes,
28+
} from 'sentry/views/explore/queryParams/context';
2529
import {Mode} from 'sentry/views/explore/queryParams/mode';
30+
import type {Visualize} from 'sentry/views/explore/queryParams/visualize';
31+
32+
import {OurLogKnownFieldKey} from './types';
2633

2734
const MAX_LOGS_PER_SECOND = 100; // Rate limit for initial check
2835

2936
type PreFlightDisableReason =
3037
| 'sort' // Wrong sort order
3138
| 'absolute_time' // Using absolute date range
3239
| 'aggregates' // In aggregates view
40+
| 'unsupported_aggregation' // using an aggregate that's not `count(message)`
3341
| 'rate_limit_initial' // Too many logs per second
3442
| 'initial_error'; // Initial table query errored
3543

@@ -55,6 +63,7 @@ export function AutorefreshToggle({averageLogsPerSecond = 0}: AutorefreshToggleP
5563
const setAutorefresh = useSetLogsAutoRefresh();
5664
const sortBys = useLogsSortBys();
5765
const mode = useQueryParamsMode();
66+
const visualizes = useQueryParamsVisualizes();
5867
const {selection} = usePageFilters();
5968
const selectionString = JSON.stringify(selection);
6069
const previousSelection = usePrevious(selectionString);
@@ -79,6 +88,7 @@ export function AutorefreshToggle({averageLogsPerSecond = 0}: AutorefreshToggleP
7988
sortBys,
8089
hasAbsoluteDates,
8190
mode,
91+
visualizes,
8292
averageLogsPerSecond,
8393
initialIsError: isError,
8494
});
@@ -127,18 +137,28 @@ function getPreFlightDisableReason({
127137
sortBys,
128138
hasAbsoluteDates,
129139
mode,
140+
visualizes,
130141
averageLogsPerSecond,
131142
initialIsError,
132143
}: {
133144
hasAbsoluteDates: boolean;
134145
mode: Mode;
135146
sortBys: ReturnType<typeof useLogsSortBys>;
147+
visualizes: readonly Visualize[];
136148
averageLogsPerSecond?: number | null;
137149
initialIsError?: boolean;
138150
}): PreFlightDisableReason | null {
139151
if (mode === Mode.AGGREGATE) {
140152
return 'aggregates';
141153
}
154+
if (
155+
visualizes.some(
156+
visualize =>
157+
visualize.yAxis !== `${AggregationKey.COUNT}(${OurLogKnownFieldKey.MESSAGE})`
158+
)
159+
) {
160+
return 'unsupported_aggregation';
161+
}
142162
if (!checkSortIsTimeBasedDescending(sortBys)) {
143163
return 'sort';
144164
}
@@ -185,6 +205,8 @@ function getTooltipMessage(
185205
);
186206
case 'aggregates':
187207
return t('Auto-refresh is not available in the aggregates view.');
208+
case 'unsupported_aggregation':
209+
return t('Auto-refresh is only available when visualizing `count(logs)`.');
188210
case 'initial_error':
189211
return t(
190212
'Auto-refresh is not available due to an error fetching logs. If the issue persists, please contact support.'

0 commit comments

Comments
 (0)