mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Fleet] Only display log level in Filter that are present in the logs (#84277)
This commit is contained in:
parent
f80da6cc39
commit
5f53d856c0
2 changed files with 15 additions and 4 deletions
|
@ -32,4 +32,6 @@ export const AGENT_LOG_LEVELS = {
|
|||
DEBUG: 'debug',
|
||||
};
|
||||
|
||||
export const ORDERED_FILTER_LOG_LEVELS = ['error', 'warning', 'warn', 'notice', 'info', 'debug'];
|
||||
|
||||
export const DEFAULT_LOG_LEVEL = AGENT_LOG_LEVELS.INFO;
|
||||
|
|
|
@ -6,10 +6,19 @@
|
|||
import React, { memo, useState, useEffect } from 'react';
|
||||
import { EuiPopover, EuiFilterButton, EuiFilterSelectItem } from '@elastic/eui';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { AGENT_LOG_LEVELS, AGENT_LOG_INDEX_PATTERN, LOG_LEVEL_FIELD } from './constants';
|
||||
import { ORDERED_FILTER_LOG_LEVELS, AGENT_LOG_INDEX_PATTERN, LOG_LEVEL_FIELD } from './constants';
|
||||
import { useStartServices } from '../../../../../hooks';
|
||||
|
||||
const LEVEL_VALUES = Object.values(AGENT_LOG_LEVELS);
|
||||
function sortLogLevels(levels: string[]): string[] {
|
||||
return [
|
||||
...new Set([
|
||||
// order by severity for known level
|
||||
...ORDERED_FILTER_LOG_LEVELS.filter((level) => levels.includes(level)),
|
||||
// Add unknown log level
|
||||
...levels.sort(),
|
||||
]),
|
||||
];
|
||||
}
|
||||
|
||||
export const LogLevelFilter: React.FunctionComponent<{
|
||||
selectedLevels: string[];
|
||||
|
@ -18,7 +27,7 @@ export const LogLevelFilter: React.FunctionComponent<{
|
|||
const { data } = useStartServices();
|
||||
const [isOpen, setIsOpen] = useState<boolean>(false);
|
||||
const [isLoading, setIsLoading] = useState<boolean>(false);
|
||||
const [levelValues, setLevelValues] = useState<string[]>(LEVEL_VALUES);
|
||||
const [levelValues, setLevelValues] = useState<string[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchValues = async () => {
|
||||
|
@ -32,7 +41,7 @@ export const LogLevelFilter: React.FunctionComponent<{
|
|||
field: LOG_LEVEL_FIELD,
|
||||
query: '',
|
||||
});
|
||||
setLevelValues([...new Set([...LEVEL_VALUES, ...values.sort()])]);
|
||||
setLevelValues(sortLogLevels(values));
|
||||
} catch (e) {
|
||||
setLevelValues([]);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue