Skip to content

Commit 49c33d4

Browse files
authored
NETOBSERV-1285 Move "query is slow" info to query summary (#438)
* query is slow alert * ensure duration text * fix table scroll perfs * format above ms
1 parent 5d8faa0 commit 49c33d4

File tree

10 files changed

+253
-97
lines changed

10 files changed

+253
-97
lines changed

web/locales/en/plugin__netobserv-plugin.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,15 @@
333333
"ms": "ms",
334334
"Filtered avg RTT": "Filtered avg RTT",
335335
"Overall avg RTT": "Overall avg RTT",
336+
"Loading...": "Loading...",
336337
"Last refresh: {{time}}": "Last refresh: {{time}}",
338+
"Query count: {{count}}": "Query count: {{count}}",
339+
"Query count: {{count}}_plural": "Query count: {{count}}",
340+
"Duration: {{duration}}": "Duration: {{duration}}",
337341
"running": "running",
338342
"queries": "queries",
339343
"query": "query",
344+
"in": "in",
340345
"Configuration": "Configuration",
341346
"Sampling": "Sampling",
342347
"Version": "Version",

web/src/components/netflow-overview/netflow-overview.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,8 +673,6 @@ export const NetflowOverview: React.FC<NetflowOverviewProps> = ({
673673
} else {
674674
return (
675675
<div
676-
id="overview-container"
677-
className={isDark ? 'dark' : 'light'}
678676
style={{ padding: `${containerPadding}px 0 ${containerPadding}px ${containerPadding}px` }}
679677
ref={containerRef}
680678
>

web/src/components/netflow-table/netflow-table.tsx

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ const NetflowTable: React.FC<{
140140
const handleScroll = React.useCallback(() => {
141141
const rowHeight = getRowHeight();
142142
const container = document.getElementById('table-container');
143-
const header = container?.children[0].children[0];
143+
const header = container?.children[0]?.children[0];
144144
if (container && header) {
145145
const position = container.scrollTop - header.clientHeight;
146146
//updates only when position moved more than one row height
@@ -257,33 +257,31 @@ const NetflowTable: React.FC<{
257257
}
258258

259259
return (
260-
<div id="table-container">
261-
<TableComposable
262-
data-test="table-composable"
263-
data-test-cols-count={columns.length}
264-
data-test-rows-count={flows.length}
265-
aria-label="Netflow table"
266-
variant="compact"
267-
style={{ minWidth: `${width}em` }}
268-
isStickyHeader
269-
>
270-
<NetflowTableHeader
271-
data-test="table-header"
272-
onSort={onSort}
273-
sortDirection={activeSortDirection}
274-
sortId={activeSortId}
275-
columns={columns}
276-
setColumns={setColumns}
277-
columnSizes={columnSizes}
278-
setColumnSizes={setColumnSizes}
279-
tableWidth={width}
280-
isDark={isDark}
281-
/>
282-
<Tbody id="table-body" data-test="table-body">
283-
{getBody()}
284-
</Tbody>
285-
</TableComposable>
286-
</div>
260+
<TableComposable
261+
data-test="table-composable"
262+
data-test-cols-count={columns.length}
263+
data-test-rows-count={flows.length}
264+
aria-label="Netflow table"
265+
variant="compact"
266+
style={{ minWidth: `${width}em` }}
267+
isStickyHeader
268+
>
269+
<NetflowTableHeader
270+
data-test="table-header"
271+
onSort={onSort}
272+
sortDirection={activeSortDirection}
273+
sortId={activeSortId}
274+
columns={columns}
275+
setColumns={setColumns}
276+
columnSizes={columnSizes}
277+
setColumnSizes={setColumnSizes}
278+
tableWidth={width}
279+
isDark={isDark}
280+
/>
281+
<Tbody id="table-body" data-test="table-body">
282+
{getBody()}
283+
</Tbody>
284+
</TableComposable>
287285
);
288286
};
289287

web/src/components/netflow-traffic.tsx

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { isModelFeatureFlag, ModelFeatureFlag, useResolvedExtensions } from '@openshift-console/dynamic-plugin-sdk';
22
import {
3-
Alert,
4-
AlertActionCloseButton,
53
Button,
64
Drawer,
75
DrawerContent,
@@ -194,7 +192,6 @@ export const NetflowTraffic: React.FC<NetflowTrafficProps> = ({ forcedFilters, i
194192
setURLParams(queryParams);
195193
}
196194

197-
const warningTimeOut = React.useRef<NodeJS.Timeout | undefined>();
198195
const [config, setConfig] = React.useState<Config>(defaultConfig);
199196
const [warningMessage, setWarningMessage] = React.useState<string | undefined>();
200197
const [showViewOptions, setShowViewOptions] = useLocalStorage<boolean>(LOCAL_STORAGE_SHOW_OPTIONS_KEY, false);
@@ -217,6 +214,7 @@ export const NetflowTraffic: React.FC<NetflowTrafficProps> = ({ forcedFilters, i
217214
const metricsRef = React.useRef(metrics);
218215
const [isShowQuerySummary, setShowQuerySummary] = React.useState<boolean>(false);
219216
const [lastRefresh, setLastRefresh] = React.useState<Date | undefined>(undefined);
217+
const [lastDuration, setLastDuration] = React.useState<number | undefined>(undefined);
220218
const [error, setError] = React.useState<string | undefined>();
221219
const [size, setSize] = useLocalStorage<Size>(LOCAL_STORAGE_SIZE_KEY, 'm');
222220
const [isTRModalOpen, setTRModalOpen] = React.useState(false);
@@ -397,9 +395,8 @@ export const NetflowTraffic: React.FC<NetflowTrafficProps> = ({ forcedFilters, i
397395
setFilters(f);
398396
setFlows([]);
399397
setMetrics({});
400-
setWarningMessage(undefined);
401398
},
402-
[setFilters, setFlows, setWarningMessage]
399+
[setFilters, setFlows]
403400
);
404401

405402
const backAndForth = filters.backAndForth;
@@ -528,7 +525,10 @@ export const NetflowTraffic: React.FC<NetflowTrafficProps> = ({ forcedFilters, i
528525

529526
const manageWarnings = React.useCallback(
530527
(query: Promise<unknown>) => {
531-
Promise.race([query, new Promise((resolve, reject) => setTimeout(reject, 2000, 'slow'))]).then(
528+
setLastRefresh(undefined);
529+
setLastDuration(undefined);
530+
setWarningMessage(undefined);
531+
Promise.race([query, new Promise((resolve, reject) => setTimeout(reject, 4000, 'slow'))]).then(
532532
null,
533533
(reason: string) => {
534534
if (reason === 'slow') {
@@ -877,6 +877,8 @@ export const NetflowTraffic: React.FC<NetflowTrafficProps> = ({ forcedFilters, i
877877
break;
878878
}
879879
if (promises) {
880+
const startDate = new Date();
881+
setStats(undefined);
880882
manageWarnings(
881883
promises
882884
.then(allStats => {
@@ -890,8 +892,10 @@ export const NetflowTraffic: React.FC<NetflowTrafficProps> = ({ forcedFilters, i
890892
setWarningMessage(undefined);
891893
})
892894
.finally(() => {
895+
const endDate = new Date();
893896
setLoading(false);
894-
setLastRefresh(new Date());
897+
setLastRefresh(endDate);
898+
setLastDuration(endDate.getTime() - startDate.getTime());
895899
})
896900
);
897901
}
@@ -1035,15 +1039,6 @@ export const NetflowTraffic: React.FC<NetflowTrafficProps> = ({ forcedFilters, i
10351039
// eslint-disable-next-line react-hooks/exhaustive-deps
10361040
}, [filters]);
10371041

1038-
//clear warning message after 10s
1039-
React.useEffect(() => {
1040-
if (warningTimeOut.current) {
1041-
clearTimeout(warningTimeOut.current);
1042-
}
1043-
1044-
warningTimeOut.current = setTimeout(() => setWarningMessage(undefined), 10000);
1045-
}, [warningMessage]);
1046-
10471042
//invalidate groups if necessary, when metrics scope changed
10481043
React.useEffect(() => {
10491044
const groups = getAvailableGroups(metricScope as MetricScopeOptions);
@@ -1322,6 +1317,9 @@ export const NetflowTraffic: React.FC<NetflowTrafficProps> = ({ forcedFilters, i
13221317
stats={stats}
13231318
limit={limit}
13241319
lastRefresh={lastRefresh}
1320+
lastDuration={lastDuration}
1321+
warningMessage={warningMessage}
1322+
slownessReason={slownessReason()}
13251323
range={range}
13261324
showDNSLatency={isDNSTracking()}
13271325
showRTTLatency={isFlowRTT()}
@@ -1445,13 +1443,23 @@ export const NetflowTraffic: React.FC<NetflowTrafficProps> = ({ forcedFilters, i
14451443

14461444
return (
14471445
<Flex id="page-content-flex" direction={{ default: 'column' }}>
1448-
<FlexItem flex={{ default: 'flex_1' }}>{content}</FlexItem>
1446+
<FlexItem
1447+
id={`${selectedViewId}-container`}
1448+
flex={{ default: 'flex_1' }}
1449+
className={isDarkTheme ? 'dark' : 'light'}
1450+
>
1451+
{content}
1452+
</FlexItem>
14491453
<FlexItem>
14501454
{_.isEmpty(flows) ? (
14511455
<MetricsQuerySummary
14521456
metrics={metrics}
14531457
stats={stats}
1458+
loading={loading}
14541459
lastRefresh={lastRefresh}
1460+
lastDuration={lastDuration}
1461+
warningMessage={warningMessage}
1462+
slownessReason={slownessReason()}
14551463
isShowQuerySummary={isShowQuerySummary}
14561464
toggleQuerySummary={() => onToggleQuerySummary(!isShowQuerySummary)}
14571465
isDark={isDarkTheme}
@@ -1460,7 +1468,11 @@ export const NetflowTraffic: React.FC<NetflowTrafficProps> = ({ forcedFilters, i
14601468
<FlowsQuerySummary
14611469
flows={flows}
14621470
stats={stats}
1471+
loading={loading}
14631472
lastRefresh={lastRefresh}
1473+
lastDuration={lastDuration}
1474+
warningMessage={warningMessage}
1475+
slownessReason={slownessReason()}
14641476
range={range}
14651477
type={recordType}
14661478
isShowQuerySummary={isShowQuerySummary}
@@ -1491,7 +1503,7 @@ export const NetflowTraffic: React.FC<NetflowTrafficProps> = ({ forcedFilters, i
14911503
});
14921504
}, [isFullScreen]);
14931505

1494-
const slownessReason = React.useCallback(() => {
1506+
const slownessReason = React.useCallback((): string => {
14951507
if (match === 'any' && hasNonIndexFields(filters.list)) {
14961508
return t(
14971509
// eslint-disable-next-line max-len
@@ -1782,16 +1794,6 @@ export const NetflowTraffic: React.FC<NetflowTrafficProps> = ({ forcedFilters, i
17821794
/>
17831795
</>
17841796
)}
1785-
{!_.isEmpty(warningMessage) && (
1786-
<Alert
1787-
id="netflow-warning"
1788-
title={warningMessage}
1789-
variant="warning"
1790-
actionClose={<AlertActionCloseButton onClose={() => setWarningMessage(undefined)} />}
1791-
>
1792-
{slownessReason()}
1793-
</Alert>
1794-
)}
17951797
<GuidedTourPopover id="netobserv" ref={guidedTourRef} isDark={isDarkTheme} />
17961798
</PageSection>
17971799
) : null;

web/src/components/query-summary/__tests__/summary-panel.spec.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import SummaryPanel, { SummaryPanelContent } from '../summary-panel';
77
import { NetflowMetrics } from 'src/api/loki';
88

99
describe('<SummaryPanel />', () => {
10+
const now = new Date();
11+
1012
const mocks = {
1113
onClose: jest.fn(),
1214
flows: FlowsSample,
@@ -19,7 +21,7 @@ describe('<SummaryPanel />', () => {
1921
appStats: undefined,
2022
limit: 5,
2123
range: 300,
22-
lastRefresh: new Date(),
24+
lastRefresh: now,
2325
id: 'summary-panel'
2426
};
2527

web/src/components/query-summary/flows-query-summary.tsx

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ export const FlowsQuerySummaryContent: React.FC<{
1717
numQueries?: number;
1818
limitReached: boolean;
1919
range: number | TimeRange;
20-
lastRefresh: Date | undefined;
20+
loading?: boolean;
21+
lastRefresh?: Date;
22+
lastDuration?: number;
23+
warningMessage?: string;
24+
slownessReason?: string;
2125
direction: 'row' | 'column';
2226
className?: string;
2327
isShowQuerySummary?: boolean;
@@ -28,7 +32,11 @@ export const FlowsQuerySummaryContent: React.FC<{
2832
numQueries,
2933
limitReached,
3034
range,
35+
loading,
3136
lastRefresh,
37+
lastDuration,
38+
warningMessage,
39+
slownessReason,
3240
direction,
3341
className,
3442
isShowQuerySummary,
@@ -91,6 +99,15 @@ export const FlowsQuerySummaryContent: React.FC<{
9199
</Text>
92100
</FlexItem>
93101
)}
102+
<StatsQuerySummary
103+
detailed={direction === 'column'}
104+
loading={loading}
105+
lastRefresh={lastRefresh}
106+
lastDuration={lastDuration}
107+
numQueries={numQueries}
108+
warningMessage={warningMessage}
109+
slownessReason={slownessReason}
110+
/>
94111
{!_.isEmpty(flows) && (
95112
<FlexItem>
96113
<Flex direction={{ default: 'row' }}>
@@ -124,9 +141,6 @@ export const FlowsQuerySummaryContent: React.FC<{
124141
</FlexItem>
125142
)}
126143
{counters()}
127-
{lastRefresh && (
128-
<StatsQuerySummary lastRefresh={lastRefresh} numQueries={direction === 'column' ? numQueries : undefined} />
129-
)}
130144
{direction === 'row' && toggleQuerySummary && (
131145
<FlexItem>
132146
<Text id="query-summary-toggle" component={TextVariants.a} onClick={toggleQuerySummary}>
@@ -140,13 +154,29 @@ export const FlowsQuerySummaryContent: React.FC<{
140154

141155
export const FlowsQuerySummary: React.FC<{
142156
flows: Record[];
143-
stats: Stats | undefined;
157+
stats?: Stats;
144158
type: RecordType;
145159
range: number | TimeRange;
146-
lastRefresh: Date | undefined;
160+
loading?: boolean;
161+
lastRefresh?: Date;
162+
lastDuration?: number;
163+
warningMessage?: string;
164+
slownessReason?: string;
147165
isShowQuerySummary?: boolean;
148166
toggleQuerySummary?: () => void;
149-
}> = ({ flows, stats, type, range, lastRefresh, isShowQuerySummary, toggleQuerySummary }) => {
167+
}> = ({
168+
flows,
169+
stats,
170+
type,
171+
range,
172+
loading,
173+
lastRefresh,
174+
lastDuration,
175+
warningMessage,
176+
slownessReason,
177+
isShowQuerySummary,
178+
toggleQuerySummary
179+
}) => {
150180
if (!_.isEmpty(flows) && stats) {
151181
return (
152182
<Card id="query-summary" isFlat>
@@ -157,7 +187,11 @@ export const FlowsQuerySummary: React.FC<{
157187
numQueries={stats.numQueries}
158188
limitReached={stats.limitReached}
159189
range={range}
190+
loading={loading}
160191
lastRefresh={lastRefresh}
192+
lastDuration={lastDuration}
193+
warningMessage={warningMessage}
194+
slownessReason={slownessReason}
161195
isShowQuerySummary={isShowQuerySummary}
162196
toggleQuerySummary={toggleQuerySummary}
163197
/>

0 commit comments

Comments
 (0)