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: apply resource filters on coming from service details to traces page #5827

Merged
merged 5 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
7 changes: 5 additions & 2 deletions frontend/src/container/MetricsApplication/Tabs/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,15 @@ export function onGraphClickHandler(
};
}

export const handleNonInQueryRange = (tags: TagFilterItem[]): TagFilterItem[] =>
export const handleNonInQueryRange = (
tags: TagFilterItem[],
isTrace = false,
): TagFilterItem[] =>
tags.map((tag) => {
if (tag.op === 'Not IN') {
return {
...tag,
op: 'NIN',
op: isTrace ? 'nin' : 'NIN',
ahmadshaheer marked this conversation as resolved.
Show resolved Hide resolved
};
}
return tag;
Expand Down
43 changes: 27 additions & 16 deletions frontend/src/container/MetricsApplication/TopOperationsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ import { ResizeTable } from 'components/ResizeTable';
import Download from 'container/Download/Download';
import { filterDropdown } from 'container/ServiceApplication/Filter/FilterDropdown';
import useResourceAttribute from 'hooks/useResourceAttribute';
import { convertRawQueriesToTraceSelectedTags } from 'hooks/useResourceAttribute/utils';
import { useRef } from 'react';
import {
convertRawQueriesToTraceSelectedTags,
resourceAttributesToTracesFilterItems,
} from 'hooks/useResourceAttribute/utils';
import { useMemo, useRef } from 'react';
import { useSelector } from 'react-redux';
import { useParams } from 'react-router-dom';
import { AppState } from 'store/reducers';
Expand All @@ -18,7 +21,7 @@ import { GlobalReducer } from 'types/reducer/globalTime';
import { v4 as uuid } from 'uuid';

import { IServiceName } from './Tabs/types';
import { useGetAPMToTracesQueries } from './Tabs/util';
import { handleNonInQueryRange, useGetAPMToTracesQueries } from './Tabs/util';
import {
convertedTracesToDownloadData,
getErrorRate,
Expand All @@ -45,24 +48,32 @@ function TopOperationsTable({
const apmToTraceQuery = useGetAPMToTracesQueries({ servicename });

const params = useParams<{ servicename: string }>();
const tagFilters = useMemo(
() =>
handleNonInQueryRange(resourceAttributesToTracesFilterItems(queries), true),
[queries],
);

const handleOnClick = (operation: string): void => {
const { servicename: encodedServiceName } = params;
const servicename = decodeURIComponent(encodedServiceName);

const opFilter: TagFilterItem = {
id: uuid().slice(0, 8),
key: {
key: 'name',
dataType: DataTypes.String,
type: 'tag',
isColumn: true,
isJSON: false,
id: 'name--string--tag--true',
const opFilters: TagFilterItem[] = [
{
id: uuid().slice(0, 8),
key: {
key: 'name',
dataType: DataTypes.String,
type: 'tag',
isColumn: true,
isJSON: false,
id: 'name--string--tag--true',
},
op: 'in',
value: [operation],
},
op: 'in',
value: [operation],
};
...tagFilters,
];

const preparedQuery: Query = {
...apmToTraceQuery,
Expand All @@ -72,7 +83,7 @@ function TopOperationsTable({
...item,
filters: {
...item.filters,
items: [...item.filters.items, opFilter],
items: [...item.filters.items, ...opFilters],
},
})),
},
Expand Down
16 changes: 16 additions & 0 deletions frontend/src/hooks/useResourceAttribute/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,22 @@ export const resourceAttributesToTagFilterItems = (
value: `${res.tagValue}`.split(','),
}));
};
/* Convert resource attributes to trace filters items for queryBuilder */
export const resourceAttributesToTracesFilterItems = (
queries: IResourceAttribute[],
): TagFilterItem[] =>
queries.map((res) => ({
id: `${res.id}`,
key: {
key: convertMetricKeyToTrace(res.tagKey),
isColumn: false,
type: MetricsType.Resource,
dataType: DataTypes.String,
id: `${convertMetricKeyToTrace(res.tagKey)}--string--resource--true`,
ahmadshaheer marked this conversation as resolved.
Show resolved Hide resolved
},
op: `${res.operator}`,
value: `${res.tagValue}`.split(','),
ahmadshaheer marked this conversation as resolved.
Show resolved Hide resolved
}));

export const OperatorSchema: IOption[] = OperatorConversions.map(
(operator) => ({
Expand Down
Loading