Skip to content

Commit f48c339

Browse files
[SIEM] Fixes Signals count spinner (#56797) (#56809)
## Fixes an issue where the Signals count spinner can spin forever Per the animated gif below, in `7.6` `BC 4`, the `Signals count` spinner on the Overview page spins forever until the signals index is created (in the current Kibana space): ![signals-count-loading-spinner](https://user-images.githubusercontent.com/4459398/73785251-2ca42000-4754-11ea-8671-daa81f351c9b.gif) The `Signals count` spinner will spin forever until the user clicks the `Detections` tab, which-in turn creates the signals index (if it doesn't exist), per the animated gif below: ![create-signals-index](https://user-images.githubusercontent.com/4459398/73785319-4ba2b200-4754-11ea-9bb0-a745a8b2be5d.gif) This behavior is an issue because: - When a fresh deployment is created on Elastic Cloud, a user won't understand why the `Signals count` widget is always spinning on the `Overview` page. (The user must click the `Detections` page to resolve this.) - In deployments where authentication is disabled, or, for _reasons_, a Detections index will never be created, the `Signals count` spinner on the Overview page will always spin. To reproduce: 1. Spin up a new `7.6` `BC 4` deployment on Elastic Cloud 2. Login to Kibana for the first time 3. Navigate to the SIEM app **Expected result** - All histograms on the Overview page eventually stop displaying their respective loading spinners **Actual result** - The `Signals count` widget spinner spins forever. (The user must click the `Detections` tab to create the signals index.) ## Deleting the signals index To reproduce the issue above when a signals index has already been created (by clicking on the Detections tab), run the following from the Kibana `Dev Tools` `Console`: ``` DELETE /.siem-signals-default-000001 ``` It is also possible to reproduce this issue by creating a new space, because it won't have a signals index. elastic/siem-team#514
1 parent 33f937e commit f48c339

File tree

4 files changed

+59
-7
lines changed

4 files changed

+59
-7
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { showInitialLoadingSpinner } from './helpers';
8+
9+
describe('helpers', () => {
10+
describe('showInitialLoadingSpinner', () => {
11+
test('it should (only) show the spinner during initial loading, while we are fetching data', () => {
12+
expect(showInitialLoadingSpinner({ isInitialLoading: true, isLoadingSignals: true })).toBe(
13+
true
14+
);
15+
});
16+
17+
test('it should STOP showing the spinner (during initial loading) when the first data fetch completes', () => {
18+
expect(showInitialLoadingSpinner({ isInitialLoading: true, isLoadingSignals: false })).toBe(
19+
false
20+
);
21+
});
22+
23+
test('it should NOT show the spinner after initial loading has completed, even if the user requests more data (e.g. by clicking Refresh)', () => {
24+
expect(showInitialLoadingSpinner({ isInitialLoading: false, isLoadingSignals: true })).toBe(
25+
false
26+
);
27+
});
28+
29+
test('it should NOT show the spinner after initial loading has completed', () => {
30+
expect(showInitialLoadingSpinner({ isInitialLoading: false, isLoadingSignals: false })).toBe(
31+
false
32+
);
33+
});
34+
});
35+
});

x-pack/legacy/plugins/siem/public/pages/detection_engine/components/signals_histogram_panel/helpers.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,17 @@ export const getSignalsHistogramQuery = (
7676
},
7777
},
7878
});
79+
80+
/**
81+
* Returns `true` when the signals histogram initial loading spinner should be shown
82+
*
83+
* @param isInitialLoading The loading spinner will only be displayed if this value is `true`, because after initial load, a different, non-spinner loading indicator is displayed
84+
* @param isLoadingSignals When `true`, IO is being performed to request signals (for rendering in the histogram)
85+
*/
86+
export const showInitialLoadingSpinner = ({
87+
isInitialLoading,
88+
isLoadingSignals,
89+
}: {
90+
isInitialLoading: boolean;
91+
isLoadingSignals: boolean;
92+
}): boolean => isInitialLoading && isLoadingSignals;

x-pack/legacy/plugins/siem/public/pages/detection_engine/components/signals_histogram_panel/index.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { InspectButtonContainer } from '../../../../components/inspect';
2323
import { useQuerySignals } from '../../../../containers/detection_engine/signals/use_query';
2424
import { MatrixLoader } from '../../../../components/matrix_histogram/matrix_loader';
2525

26-
import { formatSignalsData, getSignalsHistogramQuery } from './helpers';
26+
import { formatSignalsData, getSignalsHistogramQuery, showInitialLoadingSpinner } from './helpers';
2727
import * as i18n from './translations';
2828

2929
const DEFAULT_PANEL_HEIGHT = 300;
@@ -54,7 +54,6 @@ interface SignalsHistogramPanelProps {
5454
from: number;
5555
query?: Query;
5656
legendPosition?: Position;
57-
loadingInitial?: boolean;
5857
panelHeight?: number;
5958
signalIndexName: string | null;
6059
setQuery: (params: RegisterQuery) => void;
@@ -75,7 +74,6 @@ export const SignalsHistogramPanel = memo<SignalsHistogramPanelProps>(
7574
query,
7675
from,
7776
legendPosition = 'right',
78-
loadingInitial = false,
7977
panelHeight = DEFAULT_PANEL_HEIGHT,
8078
setQuery,
8179
signalIndexName,
@@ -86,7 +84,7 @@ export const SignalsHistogramPanel = memo<SignalsHistogramPanelProps>(
8684
title = i18n.HISTOGRAM_HEADER,
8785
updateDateRange,
8886
}) => {
89-
const [isInitialLoading, setIsInitialLoading] = useState(loadingInitial || true);
87+
const [isInitialLoading, setIsInitialLoading] = useState(true);
9088
const [defaultNumberFormat] = useUiSetting$<string>(DEFAULT_NUMBER_FORMAT);
9189
const [totalSignalsObj, setTotalSignalsObj] = useState<SignalsTotal>(defaultTotalSignalsObj);
9290
const [selectedStackByOption, setSelectedStackByOption] = useState<SignalsHistogramOption>(
@@ -124,10 +122,16 @@ export const SignalsHistogramPanel = memo<SignalsHistogramPanelProps>(
124122
const formattedSignalsData = useMemo(() => formatSignalsData(signalsData), [signalsData]);
125123

126124
useEffect(() => {
127-
if (!loadingInitial && isInitialLoading && !isLoadingSignals && signalsData) {
125+
let canceled = false;
126+
127+
if (!canceled && !showInitialLoadingSpinner({ isInitialLoading, isLoadingSignals })) {
128128
setIsInitialLoading(false);
129129
}
130-
}, [loadingInitial, isLoadingSignals, signalsData]);
130+
131+
return () => {
132+
canceled = true; // prevent long running data fetches from updating state after unmounting
133+
};
134+
}, [isInitialLoading, isLoadingSignals, setIsInitialLoading]);
131135

132136
useEffect(() => {
133137
return () => {

x-pack/legacy/plugins/siem/public/pages/detection_engine/detection_engine.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ const DetectionEnginePageComponent: React.FC<DetectionEnginePageComponentProps>
177177
deleteQuery={deleteQuery}
178178
filters={filters}
179179
from={from}
180-
loadingInitial={loading}
181180
query={query}
182181
setQuery={setQuery}
183182
showTotalSignalsCount={true}

0 commit comments

Comments
 (0)