From 1916fc87b093e462262b196a222a1fed9bd654f5 Mon Sep 17 00:00:00 2001 From: Amol Umbark Date: Wed, 28 Dec 2022 14:30:37 +0530 Subject: [PATCH 1/3] fix: added clear filters button (#1920) * fix: added clear filters button * fix: removed console log Co-authored-by: mindhash Co-authored-by: Pranay Prateek Co-authored-by: Ankit Nayan --- .../SearchFields/ActionBar.tsx | 36 ++++++++++++++ .../LogsSearchFilter/SearchFields/index.tsx | 47 ++++++++++--------- 2 files changed, 61 insertions(+), 22 deletions(-) create mode 100644 frontend/src/container/LogsSearchFilter/SearchFields/ActionBar.tsx diff --git a/frontend/src/container/LogsSearchFilter/SearchFields/ActionBar.tsx b/frontend/src/container/LogsSearchFilter/SearchFields/ActionBar.tsx new file mode 100644 index 0000000000..a8d5c777c9 --- /dev/null +++ b/frontend/src/container/LogsSearchFilter/SearchFields/ActionBar.tsx @@ -0,0 +1,36 @@ +import { Button, Row } from 'antd'; +import React from 'react'; + +import { QueryFields } from './utils'; + +interface SearchFieldsActionBarProps { + fieldsQuery: QueryFields[][]; + applyUpdate: () => void; + clearFilters: () => void; +} + +export function SearchFieldsActionBar({ + fieldsQuery, + applyUpdate, + clearFilters, +}: SearchFieldsActionBarProps): JSX.Element | null { + if (fieldsQuery.length === 0) { + return null; + } + + return ( + + + + + ); +} +export default SearchFieldsActionBar; diff --git a/frontend/src/container/LogsSearchFilter/SearchFields/index.tsx b/frontend/src/container/LogsSearchFilter/SearchFields/index.tsx index bca82bdaaf..a7228c6c45 100644 --- a/frontend/src/container/LogsSearchFilter/SearchFields/index.tsx +++ b/frontend/src/container/LogsSearchFilter/SearchFields/index.tsx @@ -1,10 +1,11 @@ -import { Button, notification, Row } from 'antd'; +import { notification } from 'antd'; import { flatten } from 'lodash-es'; import React, { useCallback, useEffect, useRef, useState } from 'react'; import { useSelector } from 'react-redux'; import { AppState } from 'store/reducers'; import { ILogsReducer } from 'types/reducer/logs'; +import { SearchFieldsActionBar } from './ActionBar'; import QueryBuilder from './QueryBuilder/QueryBuilder'; import Suggestions from './Suggestions'; import { @@ -68,24 +69,26 @@ function SearchFields({ [fieldsQuery, setFieldsQuery], ); - const applyUpdate = useCallback( - (e): void => { - e.preventDefault(); - const flatParsedQuery = flatten(fieldsQuery); + const applyUpdate = useCallback((): void => { + const flatParsedQuery = flatten(fieldsQuery); - if (!fieldsQueryIsvalid(flatParsedQuery)) { - notification.error({ - message: 'Please enter a valid criteria for each of the selected fields', - }); - return; - } + if (!fieldsQueryIsvalid(flatParsedQuery)) { + notification.error({ + message: 'Please enter a valid criteria for each of the selected fields', + }); + return; + } - keyPrefixRef.current = hashCode(JSON.stringify(flatParsedQuery)); - updateParsedQuery(flatParsedQuery); - onDropDownToggleHandler(false)(); - }, - [onDropDownToggleHandler, fieldsQuery, updateParsedQuery], - ); + keyPrefixRef.current = hashCode(JSON.stringify(flatParsedQuery)); + updateParsedQuery(flatParsedQuery); + onDropDownToggleHandler(false)(); + }, [onDropDownToggleHandler, fieldsQuery, updateParsedQuery]); + + const clearFilters = useCallback((): void => { + keyPrefixRef.current = hashCode(JSON.stringify([])); + updateParsedQuery([]); + onDropDownToggleHandler(false)(); + }, [onDropDownToggleHandler, updateParsedQuery]); return ( <> @@ -96,11 +99,11 @@ function SearchFields({ fieldsQuery={fieldsQuery} setFieldsQuery={setFieldsQuery} /> - - - + ); From 2e58f6db7aa6283ad9652994cfa65aa73989f1ec Mon Sep 17 00:00:00 2001 From: Nityananda Gohain Date: Wed, 28 Dec 2022 14:31:57 +0530 Subject: [PATCH 2/3] fix: error handling for index removal from selected field (#1935) Co-authored-by: Ankit Nayan --- pkg/query-service/app/clickhouseReader/reader.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/query-service/app/clickhouseReader/reader.go b/pkg/query-service/app/clickhouseReader/reader.go index a9626d887b..9eb90ac6df 100644 --- a/pkg/query-service/app/clickhouseReader/reader.go +++ b/pkg/query-service/app/clickhouseReader/reader.go @@ -3233,7 +3233,8 @@ func (r *ClickHouseReader) UpdateLogField(ctx context.Context, field *model.Upda // remove index query := fmt.Sprintf("ALTER TABLE %s.%s ON CLUSTER %s DROP INDEX IF EXISTS %s_idx", r.logsDB, r.logsLocalTable, cluster, field.Name) err := r.db.Exec(ctx, query) - if err != nil { + // we are ignoring errors with code 341 as it is an error with updating old part https://github.com/SigNoz/engineering-pod/issues/919#issuecomment-1366344346 + if err != nil && !strings.HasPrefix(err.Error(), "code: 341") { return &model.ApiError{Err: err, Typ: model.ErrorInternal} } } From 88a97fc4b823b6978f1707b07c0da5571cf12a6a Mon Sep 17 00:00:00 2001 From: Vishal Sharma Date: Wed, 28 Dec 2022 14:54:15 +0530 Subject: [PATCH 3/3] add exception page filters support (#1919) * feat: backend changes for supporting exception filters * feat: frontend changes for exception page filter support * chore: extractSingleFilterValue is updated * fix: handle frontend edge case Co-authored-by: Ankit Nayan Co-authored-by: Palash Gupta --- frontend/src/container/AllError/constant.ts | 9 ++ frontend/src/container/AllError/index.tsx | 110 ++++++++++++++---- frontend/src/container/AllError/utils.ts | 101 +++++++++++++++- frontend/src/types/api/errors/getAll.ts | 2 + .../app/clickhouseReader/reader.go | 38 +++++- pkg/query-service/app/parser.go | 16 ++- pkg/query-service/model/queryParams.go | 20 ++-- 7 files changed, 258 insertions(+), 38 deletions(-) create mode 100644 frontend/src/container/AllError/constant.ts diff --git a/frontend/src/container/AllError/constant.ts b/frontend/src/container/AllError/constant.ts new file mode 100644 index 0000000000..268f3ff89c --- /dev/null +++ b/frontend/src/container/AllError/constant.ts @@ -0,0 +1,9 @@ +const DEFAULT_FILTER_VALUE = ''; +const EXCEPTION_TYPE_FILTER_NAME = 'exceptionType'; +const SERVICE_NAME_FILTER_NAME = 'serviceName'; + +export { + DEFAULT_FILTER_VALUE, + EXCEPTION_TYPE_FILTER_NAME, + SERVICE_NAME_FILTER_NAME, +}; diff --git a/frontend/src/container/AllError/index.tsx b/frontend/src/container/AllError/index.tsx index 6db945b9bc..3b3939a4a7 100644 --- a/frontend/src/container/AllError/index.tsx +++ b/frontend/src/container/AllError/index.tsx @@ -17,6 +17,7 @@ import getAll from 'api/errors/getAll'; import getErrorCounts from 'api/errors/getErrorCounts'; import ROUTES from 'constants/routes'; import dayjs from 'dayjs'; +import useUrlQuery from 'hooks/useUrlQuery'; import createQueryParams from 'lib/createQueryParams'; import history from 'lib/history'; import React, { useCallback, useEffect, useMemo } from 'react'; @@ -30,7 +31,11 @@ import { Exception, PayloadProps } from 'types/api/errors/getAll'; import { GlobalReducer } from 'types/reducer/globalTime'; import { + extractFilterValues, + getDefaultFilterValue, getDefaultOrder, + getFilterString, + getFilterValues, getNanoSeconds, getOffSet, getOrder, @@ -43,15 +48,27 @@ function AllErrors(): JSX.Element { const { maxTime, minTime, loading } = useSelector( (state) => state.globalTime, ); - const { search, pathname } = useLocation(); - const params = useMemo(() => new URLSearchParams(search), [search]); - + const { pathname } = useLocation(); + const params = useUrlQuery(); const { t } = useTranslation(['common']); - - const updatedOrder = getOrder(params.get(urlKey.order)); - const getUpdatedOffset = getOffSet(params.get(urlKey.offset)); - const getUpdatedParams = getOrderParams(params.get(urlKey.orderParam)); - const getUpdatedPageSize = getUpdatePageSize(params.get(urlKey.pageSize)); + const { + updatedOrder, + getUpdatedOffset, + getUpdatedParams, + getUpdatedPageSize, + getUpdatedExceptionType, + getUpdatedServiceName, + } = useMemo( + () => ({ + updatedOrder: getOrder(params.get(urlKey.order)), + getUpdatedOffset: getOffSet(params.get(urlKey.offset)), + getUpdatedParams: getOrderParams(params.get(urlKey.orderParam)), + getUpdatedPageSize: getUpdatePageSize(params.get(urlKey.pageSize)), + getUpdatedExceptionType: getFilterString(params.get(urlKey.exceptionType)), + getUpdatedServiceName: getFilterString(params.get(urlKey.serviceName)), + }), + [params], + ); const updatedPath = useMemo( () => @@ -60,6 +77,8 @@ function AllErrors(): JSX.Element { offset: getUpdatedOffset, orderParam: getUpdatedParams, pageSize: getUpdatedPageSize, + exceptionType: getUpdatedExceptionType, + serviceName: getUpdatedServiceName, })}`, [ pathname, @@ -67,6 +86,8 @@ function AllErrors(): JSX.Element { getUpdatedOffset, getUpdatedParams, getUpdatedPageSize, + getUpdatedExceptionType, + getUpdatedServiceName, ], ); @@ -81,6 +102,8 @@ function AllErrors(): JSX.Element { limit: getUpdatedPageSize, offset: getUpdatedOffset, orderParam: getUpdatedParams, + exceptionType: getUpdatedExceptionType, + serviceName: getUpdatedServiceName, }), enabled: !loading, }, @@ -108,14 +131,43 @@ function AllErrors(): JSX.Element { const filterIcon = useCallback(() => , []); - const handleSearch = ( - confirm: (param?: FilterConfirmProps) => void, - ): VoidFunction => (): void => { - confirm(); - }; + const handleSearch = useCallback( + ( + confirm: (param?: FilterConfirmProps) => void, + filterValue: string, + filterKey: string, + ): VoidFunction => (): void => { + const { exceptionFilterValue, serviceFilterValue } = getFilterValues( + getUpdatedServiceName, + getUpdatedExceptionType, + filterKey, + filterValue, + ); + history.replace( + `${pathname}?${createQueryParams({ + order: updatedOrder, + offset: getUpdatedOffset, + orderParam: getUpdatedParams, + pageSize: getUpdatedPageSize, + exceptionType: exceptionFilterValue, + serviceName: serviceFilterValue, + })}`, + ); + confirm(); + }, + [ + getUpdatedExceptionType, + getUpdatedOffset, + getUpdatedPageSize, + getUpdatedParams, + getUpdatedServiceName, + pathname, + updatedOrder, + ], + ); const filterDropdownWrapper = useCallback( - ({ setSelectedKeys, selectedKeys, confirm, placeholder }) => { + ({ setSelectedKeys, selectedKeys, confirm, placeholder, filterKey }) => { return ( @@ -126,11 +178,16 @@ function AllErrors(): JSX.Element { setSelectedKeys(e.target.value ? [e.target.value] : []) } allowClear - onPressEnter={handleSearch(confirm)} + defaultValue={getDefaultFilterValue( + filterKey, + getUpdatedServiceName, + getUpdatedExceptionType, + )} + onPressEnter={handleSearch(confirm, selectedKeys[0], filterKey)} />