Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added trace-filter in new trace-explorer #5081

Merged
merged 23 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8a9b4a8
feat: added trace-filter in new trace-explorer
SagarRajput-7 May 27, 2024
2929871
feat: added trace-filter in new trace-explorer
SagarRajput-7 May 27, 2024
6c41e69
feat: style improvement
SagarRajput-7 May 28, 2024
0b7d3c7
feat: query builder sync and filter section refactor
SagarRajput-7 May 29, 2024
ba91bdf
feat: added duration and code refactor
SagarRajput-7 May 29, 2024
1be1b96
feat: added default open case
SagarRajput-7 May 29, 2024
dede20f
feat: removed API calls and used keys from const
SagarRajput-7 May 30, 2024
e693e6b
feat: added sync and prepare data logic for querybuilder
SagarRajput-7 May 30, 2024
d5a35f3
feat: added styles for lightmode
SagarRajput-7 May 30, 2024
e17f7ae
feat: code refactor and sync issue fixed
SagarRajput-7 May 30, 2024
3f33199
feat: code refactor and sync issue fixed
SagarRajput-7 May 30, 2024
17615cf
feat: code refactor and feedback issue fixed
SagarRajput-7 Jun 1, 2024
453376c
feat: checkbox label and other feedback fix
SagarRajput-7 Jun 1, 2024
9fc385c
feat: filter open and close btn style and handling
SagarRajput-7 Jun 1, 2024
479dd0e
feat: added filter reset and clear all
SagarRajput-7 Jun 1, 2024
5619559
feat: fixed query modification issue when filtering
SagarRajput-7 Jun 1, 2024
628283e
feat: code refactor
SagarRajput-7 Jun 1, 2024
2ceb517
feat: search text via BE API
SagarRajput-7 Jun 1, 2024
f6dd430
feat: added CTA btn for old explorer page
SagarRajput-7 Jun 1, 2024
180de08
feat: make trace-explorer default page
SagarRajput-7 Jun 1, 2024
ba25fb9
feat: removed new ribbon on CTA for old trace explorer
SagarRajput-7 Jun 1, 2024
d821d2c
feat: fixed qb and filter panel sync via url state
SagarRajput-7 Jun 3, 2024
b6bcc53
feat: fixed duration section issues
SagarRajput-7 Jun 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions frontend/src/container/NewExplorerCTA/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export const buttonText: Record<string, string> = {
[ROUTES.LOGS_EXPLORER]: 'Switch to Old Logs Explorer',
[ROUTES.TRACE]: 'Try new Traces Explorer',
[ROUTES.OLD_LOGS_EXPLORER]: 'Switch to New Logs Explorer',
[ROUTES.TRACES_EXPLORER]: 'Switch to Old Trace Explorer',
};
9 changes: 8 additions & 1 deletion frontend/src/container/NewExplorerCTA/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ function NewExplorerCTA(): JSX.Element | null {
() =>
location.pathname === ROUTES.LOGS_EXPLORER ||
location.pathname === ROUTES.TRACE ||
location.pathname === ROUTES.OLD_LOGS_EXPLORER,
location.pathname === ROUTES.OLD_LOGS_EXPLORER ||
location.pathname === ROUTES.TRACES_EXPLORER,
[location.pathname],
);

Expand All @@ -25,6 +26,8 @@ function NewExplorerCTA(): JSX.Element | null {
history.push(ROUTES.TRACES_EXPLORER);
} else if (location.pathname === ROUTES.OLD_LOGS_EXPLORER) {
history.push(ROUTES.LOGS_EXPLORER);
} else if (location.pathname === ROUTES.TRACES_EXPLORER) {
history.push(ROUTES.TRACE);
}
}, [location.pathname]);

Expand All @@ -47,6 +50,10 @@ function NewExplorerCTA(): JSX.Element | null {
return null;
}

if (location.pathname === ROUTES.TRACES_EXPLORER) {
return button;
}

if (location.pathname === ROUTES.LOGS_EXPLORER) {
return button;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ function QueryBuilderSearch({
const { tagKey, tagOperator, tagValue } = getTagToken(tag);

const filterAttribute = [...initialSourceKeys, ...sourceKeys].find(
(key) => key.key === getRemovePrefixFromKey(tagKey),
(key) => key?.key === getRemovePrefixFromKey(tagKey),
);

const computedTagValue =
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/container/SideNav/menuItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const menuItems: SidebarItem[] = [
icon: <BarChart2 size={16} />,
},
{
key: ROUTES.TRACE,
key: ROUTES.TRACES_EXPLORER,
label: 'Traces',
icon: <DraftingCompass size={16} />,
},
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/container/TopNav/DateTimeSelectionV2/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
defaultLiveQueryDataConfig,
} from 'container/LiveLogs/constants';
import { QueryHistoryState } from 'container/LiveLogs/types';
import NewExplorerCTA from 'container/NewExplorerCTA';
import dayjs, { Dayjs } from 'dayjs';
import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder';
import { updateStepInterval } from 'hooks/queryBuilder/useStepInterval';
Expand Down Expand Up @@ -63,6 +64,7 @@ function DateTimeSelection({
location,
updateTimeInterval,
globalTimeLoading,
showOldExplorerCTA = false,
}: Props): JSX.Element {
const [formSelector] = Form.useForm();

Expand Down Expand Up @@ -561,6 +563,11 @@ function DateTimeSelection({

return (
<div className="date-time-selector">
{showOldExplorerCTA && (
<div style={{ marginRight: 12 }}>
<NewExplorerCTA />
</div>
)}
{!hasSelectedTimeError && !refreshButtonHidden && (
<RefreshText
{...{
Expand Down Expand Up @@ -646,10 +653,12 @@ function DateTimeSelection({
interface DateTimeSelectionV2Props {
showAutoRefresh: boolean;
hideShareModal?: boolean;
showOldExplorerCTA?: boolean;
}

DateTimeSelection.defaultProps = {
hideShareModal: false,
showOldExplorerCTA: false,
};
interface DispatchProps {
updateTimeInterval: (
Expand Down
42 changes: 25 additions & 17 deletions frontend/src/hooks/queryBuilder/useFetchKeysAndValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const useFetchKeysAndValues = (
const [keys, setKeys] = useState<BaseAutocompleteData[]>([]);
const [sourceKeys, setSourceKeys] = useState<BaseAutocompleteData[]>([]);
const [results, setResults] = useState<string[]>([]);
const [isAggregateFetching, setAggregateFetching] = useState<boolean>(false);

const memoizedSearchParams = useMemo(
() => [
Expand Down Expand Up @@ -106,22 +107,29 @@ export const useFetchKeysAndValues = (
if (!tagKey || !tagOperator) {
return;
}

const { payload } = await getAttributesValues({
aggregateOperator: query.aggregateOperator,
dataSource: query.dataSource,
aggregateAttribute: query.aggregateAttribute.key,
attributeKey: filterAttributeKey?.key ?? tagKey,
filterAttributeKeyDataType: filterAttributeKey?.dataType ?? DataTypes.EMPTY,
tagType: filterAttributeKey?.type ?? '',
searchText: isInNInOperator(tagOperator)
? tagValue[tagValue.length - 1]?.toString() ?? '' // last element of tagvalue will be always user search value
: tagValue?.toString() ?? '',
});

if (payload) {
const values = Object.values(payload).find((el) => !!el) || [];
setResults(values);
setAggregateFetching(true);

try {
const { payload } = await getAttributesValues({
aggregateOperator: query.aggregateOperator,
dataSource: query.dataSource,
aggregateAttribute: query.aggregateAttribute.key,
attributeKey: filterAttributeKey?.key ?? tagKey,
filterAttributeKeyDataType: filterAttributeKey?.dataType ?? DataTypes.EMPTY,
tagType: filterAttributeKey?.type ?? '',
searchText: isInNInOperator(tagOperator)
? tagValue[tagValue.length - 1]?.toString() ?? '' // last element of tagvalue will be always user search value
: tagValue?.toString() ?? '',
});

if (payload) {
const values = Object.values(payload).find((el) => !!el) || [];
setResults(values);
}
} catch (e) {
console.error(e);
} finally {
setAggregateFetching(false);
}
};

Expand Down Expand Up @@ -157,7 +165,7 @@ export const useFetchKeysAndValues = (
return {
keys,
results,
isFetching,
isFetching: isFetching || isAggregateFetching,
sourceKeys,
handleRemoveSourceKey,
};
Expand Down
143 changes: 143 additions & 0 deletions frontend/src/pages/TracesExplorer/Filter/DurationSection.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import { Input, Slider } from 'antd';
import { SliderRangeProps } from 'antd/es/slider';
import { getMs } from 'container/Trace/Filters/Panel/PanelBody/Duration/util';
import useDebouncedFn from 'hooks/useDebouncedFunction';
import {
ChangeEventHandler,
Dispatch,
SetStateAction,
useCallback,
useEffect,
useMemo,
useState,
} from 'react';

import { addFilter, FilterType, traceFilterKeys } from './filterUtils';

interface DurationProps {
selectedFilters: FilterType | undefined;
setSelectedFilters: Dispatch<SetStateAction<FilterType | undefined>>;
}

export function DurationSection(props: DurationProps): JSX.Element {
const { setSelectedFilters, selectedFilters } = props;

const getDuration = useMemo(() => {
if (selectedFilters?.durationNanoMin || selectedFilters?.durationNanoMax) {
return {
minDuration: selectedFilters?.durationNanoMin?.values || '',
maxDuration: selectedFilters?.durationNanoMax?.values || '',
};
}

if (selectedFilters?.durationNano) {
return {
minDuration: getMs(selectedFilters?.durationNano?.values?.[0] || ''),
maxDuration: getMs(selectedFilters?.durationNano?.values?.[1] || ''),
};
}

return {
maxDuration: '',
minDuration: '',
};
}, [selectedFilters]);

const [preMax, setPreMax] = useState<string>('');
SagarRajput-7 marked this conversation as resolved.
Show resolved Hide resolved
const [preMin, setPreMin] = useState<string>('');

useEffect(() => {
setPreMax(getDuration.maxDuration as string);
setPreMin(getDuration.minDuration as string);
}, [getDuration]);

const updateDurationFilter = (min: string, max: string): void => {
const durationMin = 'durationNanoMin';
const durationMax = 'durationNanoMax';

addFilter(durationMin, min, setSelectedFilters, traceFilterKeys.durationNano);
addFilter(durationMax, max, setSelectedFilters, traceFilterKeys.durationNano);
};

const onRangeSliderHandler = (number: [string, string]): void => {
const [min, max] = number;

setPreMin(min);
setPreMax(max);
};

const debouncedFunction = useDebouncedFn(
(min, max) => {
updateDurationFilter(min as string, max as string);
},
1500,
undefined,
SagarRajput-7 marked this conversation as resolved.
Show resolved Hide resolved
);

const onChangeMaxHandler: ChangeEventHandler<HTMLInputElement> = (event) => {
const { value } = event.target;
const min = preMin;
const max = value;

onRangeSliderHandler([min, max]);
debouncedFunction(min, max);
};

const onChangeMinHandler: ChangeEventHandler<HTMLInputElement> = (event) => {
const { value } = event.target;
const min = value;
const max = preMax;

onRangeSliderHandler([min, max]);
debouncedFunction(min, max);
};

const onRangeHandler: SliderRangeProps['onChange'] = ([min, max]) => {
updateDurationFilter(min.toString(), max.toString());
};

const TipComponent = useCallback((value: undefined | number) => {
if (value === undefined) {
return <div />;
}
return <div>{`${value?.toString()}ms`}</div>;
}, []);

return (
<div>
<div className="duration-inputs">
<Input
type="number"
SagarRajput-7 marked this conversation as resolved.
Show resolved Hide resolved
addonBefore="MIN"
placeholder="0"
className="min-max-input"
onChange={onChangeMinHandler}
value={preMin}
addonAfter="ms"
/>
<Input
type="number"
addonBefore="MAX"
placeholder="100000000"
className="min-max-input"
onChange={onChangeMaxHandler}
value={preMax}
addonAfter="ms"
/>
</div>
<div>
<Slider
min={0}
max={100000}
range
tooltip={{ formatter: TipComponent }}
onChange={([min, max]): void => {
onRangeSliderHandler([String(min), String(max)]);
}}
onAfterChange={onRangeHandler}
value={[Number(preMin), Number(preMax)]}
/>
</div>
</div>
);
}
Loading
Loading