mirror of
https://github.com/SigNoz/signoz.git
synced 2025-12-17 15:36:48 +00:00
fix: added fix for passing activeLogId in query range in log context view (#9180)
* fix: added fix for passing activitylogId in query range in log context view * chore: added tests
This commit is contained in:
parent
7ddaa84387
commit
d595dcc222
@ -59,6 +59,7 @@ import {
|
|||||||
Query,
|
Query,
|
||||||
TagFilter,
|
TagFilter,
|
||||||
} from 'types/api/queryBuilder/queryBuilderData';
|
} from 'types/api/queryBuilder/queryBuilderData';
|
||||||
|
import { Filter } from 'types/api/v5/queryRange';
|
||||||
import { QueryDataV3 } from 'types/api/widgets/getQuery';
|
import { QueryDataV3 } from 'types/api/widgets/getQuery';
|
||||||
import { DataSource, LogsAggregatorOperator } from 'types/common/queryBuilder';
|
import { DataSource, LogsAggregatorOperator } from 'types/common/queryBuilder';
|
||||||
import { GlobalReducer } from 'types/reducer/globalTime';
|
import { GlobalReducer } from 'types/reducer/globalTime';
|
||||||
@ -171,6 +172,11 @@ function LogsExplorerViewsContainer({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let updatedFilterExpression = listQuery.filter?.expression || '';
|
||||||
|
if (activeLogId) {
|
||||||
|
updatedFilterExpression = `${updatedFilterExpression} id <= '${activeLogId}'`.trim();
|
||||||
|
}
|
||||||
|
|
||||||
const modifiedQueryData: IBuilderQuery = {
|
const modifiedQueryData: IBuilderQuery = {
|
||||||
...listQuery,
|
...listQuery,
|
||||||
aggregateOperator: LogsAggregatorOperator.COUNT,
|
aggregateOperator: LogsAggregatorOperator.COUNT,
|
||||||
@ -183,6 +189,10 @@ function LogsExplorerViewsContainer({
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
legend: '{{severity_text}}',
|
legend: '{{severity_text}}',
|
||||||
|
filter: {
|
||||||
|
...listQuery?.filter,
|
||||||
|
expression: updatedFilterExpression || '',
|
||||||
|
},
|
||||||
...(activeLogId && {
|
...(activeLogId && {
|
||||||
filters: {
|
filters: {
|
||||||
...listQuery?.filters,
|
...listQuery?.filters,
|
||||||
@ -286,6 +296,7 @@ function LogsExplorerViewsContainer({
|
|||||||
page: number;
|
page: number;
|
||||||
pageSize: number;
|
pageSize: number;
|
||||||
filters: TagFilter;
|
filters: TagFilter;
|
||||||
|
filter: Filter;
|
||||||
},
|
},
|
||||||
): Query | null => {
|
): Query | null => {
|
||||||
if (!query) return null;
|
if (!query) return null;
|
||||||
@ -297,6 +308,7 @@ function LogsExplorerViewsContainer({
|
|||||||
|
|
||||||
// Add filter for activeLogId if present
|
// Add filter for activeLogId if present
|
||||||
let updatedFilters = params.filters;
|
let updatedFilters = params.filters;
|
||||||
|
let updatedFilterExpression = params.filter?.expression || '';
|
||||||
if (activeLogId) {
|
if (activeLogId) {
|
||||||
updatedFilters = {
|
updatedFilters = {
|
||||||
...params.filters,
|
...params.filters,
|
||||||
@ -315,6 +327,7 @@ function LogsExplorerViewsContainer({
|
|||||||
],
|
],
|
||||||
op: 'AND',
|
op: 'AND',
|
||||||
};
|
};
|
||||||
|
updatedFilterExpression = `${updatedFilterExpression} id <= '${activeLogId}'`.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create orderBy array based on orderDirection
|
// Create orderBy array based on orderDirection
|
||||||
@ -336,6 +349,9 @@ function LogsExplorerViewsContainer({
|
|||||||
...(listQuery || initialQueryBuilderFormValues),
|
...(listQuery || initialQueryBuilderFormValues),
|
||||||
...paginateData,
|
...paginateData,
|
||||||
...(updatedFilters ? { filters: updatedFilters } : {}),
|
...(updatedFilters ? { filters: updatedFilters } : {}),
|
||||||
|
filter: {
|
||||||
|
expression: updatedFilterExpression || '',
|
||||||
|
},
|
||||||
...(selectedView === ExplorerViews.LIST
|
...(selectedView === ExplorerViews.LIST
|
||||||
? { order: newOrderBy, orderBy: newOrderBy }
|
? { order: newOrderBy, orderBy: newOrderBy }
|
||||||
: { order: [] }),
|
: { order: [] }),
|
||||||
@ -368,7 +384,7 @@ function LogsExplorerViewsContainer({
|
|||||||
if (isLimit) return;
|
if (isLimit) return;
|
||||||
if (logs.length < pageSize) return;
|
if (logs.length < pageSize) return;
|
||||||
|
|
||||||
const { limit, filters } = listQuery;
|
const { limit, filters, filter } = listQuery;
|
||||||
|
|
||||||
const nextLogsLength = logs.length + pageSize;
|
const nextLogsLength = logs.length + pageSize;
|
||||||
|
|
||||||
@ -379,6 +395,7 @@ function LogsExplorerViewsContainer({
|
|||||||
|
|
||||||
const newRequestData = getRequestData(stagedQuery, {
|
const newRequestData = getRequestData(stagedQuery, {
|
||||||
filters: filters || { items: [], op: 'AND' },
|
filters: filters || { items: [], op: 'AND' },
|
||||||
|
filter: filter || { expression: '' },
|
||||||
page: page + 1,
|
page: page + 1,
|
||||||
pageSize: nextPageSize,
|
pageSize: nextPageSize,
|
||||||
});
|
});
|
||||||
@ -526,6 +543,7 @@ function LogsExplorerViewsContainer({
|
|||||||
|
|
||||||
const newRequestData = getRequestData(stagedQuery, {
|
const newRequestData = getRequestData(stagedQuery, {
|
||||||
filters: listQuery?.filters || initialFilters,
|
filters: listQuery?.filters || initialFilters,
|
||||||
|
filter: listQuery?.filter || { expression: '' },
|
||||||
page: 1,
|
page: 1,
|
||||||
pageSize,
|
pageSize,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import { PANEL_TYPES } from 'constants/queryBuilder';
|
||||||
import ROUTES from 'constants/routes';
|
import ROUTES from 'constants/routes';
|
||||||
import { useCopyLogLink } from 'hooks/logs/useCopyLogLink';
|
import { useCopyLogLink } from 'hooks/logs/useCopyLogLink';
|
||||||
import { useGetExplorerQueryRange } from 'hooks/queryBuilder/useGetExplorerQueryRange';
|
import { useGetExplorerQueryRange } from 'hooks/queryBuilder/useGetExplorerQueryRange';
|
||||||
@ -261,6 +262,68 @@ describe('LogsExplorerViews -', () => {
|
|||||||
|
|
||||||
// Verify the total number of filters (original + 1 new activeLogId filter)
|
// Verify the total number of filters (original + 1 new activeLogId filter)
|
||||||
expect(firstQuery.filters?.items.length).toBe(expectedFiltersLength);
|
expect(firstQuery.filters?.items.length).toBe(expectedFiltersLength);
|
||||||
|
|
||||||
|
// Verify the filter expression
|
||||||
|
expect(firstQuery.filter?.expression).toBe(`id <= '${ACTIVE_LOG_ID}'`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should update filter expression with activeLogId when present with existing filter expression', async () => {
|
||||||
|
// Mock useCopyLogLink to return an activeLogId
|
||||||
|
(useCopyLogLink as jest.Mock).mockReturnValue({
|
||||||
|
activeLogId: ACTIVE_LOG_ID,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create a custom QueryBuilderContext with an existing filter expression
|
||||||
|
const customContext = {
|
||||||
|
...mockQueryBuilderContextValue,
|
||||||
|
panelType: PANEL_TYPES.LIST,
|
||||||
|
stagedQuery: {
|
||||||
|
...mockQueryBuilderContextValue.stagedQuery,
|
||||||
|
builder: {
|
||||||
|
...mockQueryBuilderContextValue.stagedQuery.builder,
|
||||||
|
queryData: [
|
||||||
|
{
|
||||||
|
...mockQueryBuilderContextValue.stagedQuery.builder.queryData[0],
|
||||||
|
filter: { expression: "service = 'frontend'" },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
lodsQueryServerRequest();
|
||||||
|
|
||||||
|
render(
|
||||||
|
<QueryBuilderContext.Provider value={customContext as any}>
|
||||||
|
<PreferenceContextProvider>
|
||||||
|
<LogsExplorerViews
|
||||||
|
selectedView={ExplorerViews.LIST}
|
||||||
|
setIsLoadingQueries={(): void => {}}
|
||||||
|
listQueryKeyRef={{ current: {} }}
|
||||||
|
chartQueryKeyRef={{ current: {} }}
|
||||||
|
setWarning={(): void => {}}
|
||||||
|
showLiveLogs={false}
|
||||||
|
/>
|
||||||
|
</PreferenceContextProvider>
|
||||||
|
</QueryBuilderContext.Provider>,
|
||||||
|
);
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
// Find the call made for LIST panel type (main logs list request)
|
||||||
|
const listCall = (useGetExplorerQueryRange as jest.Mock).mock.calls.find(
|
||||||
|
(call) => call[1] === PANEL_TYPES.LIST && call[0],
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(listCall).toBeDefined();
|
||||||
|
if (listCall) {
|
||||||
|
const queryArg = listCall[0];
|
||||||
|
const firstQuery = queryArg.builder.queryData[0];
|
||||||
|
// It should append the activeLogId condition to existing expression
|
||||||
|
expect(firstQuery.filter?.expression).toBe(
|
||||||
|
"service = 'frontend' id <= 'test-log-id'",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user