From c16ae790d4ee438ed91782fb5e9b905da1401065 Mon Sep 17 00:00:00 2001 From: Palash gupta Date: Mon, 13 Jun 2022 19:05:17 +0530 Subject: [PATCH 1/7] feat: rule id is passed as params --- frontend/src/constants/routes.ts | 2 +- .../container/ListAlertRules/ListAlert.tsx | 7 +--- frontend/src/pages/EditRules/index.tsx | 32 +++++++++++++------ 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/frontend/src/constants/routes.ts b/frontend/src/constants/routes.ts index 636a3b0758..506474af97 100644 --- a/frontend/src/constants/routes.ts +++ b/frontend/src/constants/routes.ts @@ -12,7 +12,7 @@ const ROUTES = { ALL_DASHBOARD: '/dashboard', DASHBOARD: '/dashboard/:dashboardId', DASHBOARD_WIDGET: '/dashboard/:dashboardId/:widgetId', - EDIT_ALERTS: '/alerts/edit/:ruleId', + EDIT_ALERTS: '/alerts/edit', LIST_ALL_ALERT: '/alerts', ALERTS_NEW: '/alerts/new', ALL_CHANNELS: '/settings/channels', diff --git a/frontend/src/container/ListAlertRules/ListAlert.tsx b/frontend/src/container/ListAlertRules/ListAlert.tsx index 8ec1fa9987..b851b0829a 100644 --- a/frontend/src/container/ListAlertRules/ListAlert.tsx +++ b/frontend/src/container/ListAlertRules/ListAlert.tsx @@ -11,7 +11,6 @@ import React, { useCallback, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { UseQueryResult } from 'react-query'; import { useSelector } from 'react-redux'; -import { generatePath } from 'react-router-dom'; import { AppState } from 'store/reducers'; import { ErrorResponse, SuccessResponse } from 'types/api'; import { Alerts } from 'types/api/alerts/getAll'; @@ -51,11 +50,7 @@ function ListAlert({ allAlertRules, refetch }: ListAlertProps): JSX.Element { const [notifications, Element] = notification.useNotification(); const onEditHandler = (id: string): void => { - history.push( - generatePath(ROUTES.EDIT_ALERTS, { - ruleId: id, - }), - ); + history.push(`${ROUTES.EDIT_ALERTS}?ruleId=${id}`); }; const columns: ColumnsType = [ diff --git a/frontend/src/pages/EditRules/index.tsx b/frontend/src/pages/EditRules/index.tsx index 9b80ff7024..1a65e668af 100644 --- a/frontend/src/pages/EditRules/index.tsx +++ b/frontend/src/pages/EditRules/index.tsx @@ -1,23 +1,41 @@ +import { notification } from 'antd'; import get from 'api/alerts/get'; import Spinner from 'components/Spinner'; +import ROUTES from 'constants/routes'; import EditRulesContainer from 'container/EditRules'; -import React from 'react'; +import history from 'lib/history'; +import React, { useEffect } from 'react'; import { useTranslation } from 'react-i18next'; import { useQuery } from 'react-query'; -import { useParams } from 'react-router-dom'; +import { useLocation } from 'react-router-dom'; function EditRules(): JSX.Element { - const { ruleId } = useParams(); + const { search } = useLocation(); + const params = new URLSearchParams(search); + const ruleId = params.get('ruleId'); + const { t } = useTranslation('common'); + const isValidRuleId = ruleId !== null && String(ruleId).length !== 0; + const { isLoading, data, isError } = useQuery(['ruleId', ruleId], { queryFn: () => get({ - id: parseInt(ruleId, 10), + id: parseInt(ruleId || '', 10), }), + enabled: isValidRuleId, }); - if (isError) { + useEffect(() => { + if (!isValidRuleId) { + notification.error({ + message: 'Rule Id is required', + }); + history.replace(ROUTES.LIST_ALL_ALERT); + } + }, [isValidRuleId, ruleId]); + + if ((isError && !isValidRuleId) || ruleId == null) { return
{data?.error || t('something_went_wrong')}
; } @@ -28,8 +46,4 @@ function EditRules(): JSX.Element { return ; } -interface EditRulesParam { - ruleId: string; -} - export default EditRules; From 0a5eff2255279eaf2d567ffb883e8b8529691461 Mon Sep 17 00:00:00 2001 From: Palash gupta Date: Wed, 15 Jun 2022 01:34:56 +0530 Subject: [PATCH 2/7] feat: alerts breadcrumb is added --- frontend/src/container/TopNav/Breadcrumbs/index.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/src/container/TopNav/Breadcrumbs/index.tsx b/frontend/src/container/TopNav/Breadcrumbs/index.tsx index 25ff730711..33d42ac5b0 100644 --- a/frontend/src/container/TopNav/Breadcrumbs/index.tsx +++ b/frontend/src/container/TopNav/Breadcrumbs/index.tsx @@ -16,6 +16,7 @@ const breadcrumbNameMap = { [ROUTES.ORG_SETTINGS]: 'Organization Settings', [ROUTES.MY_SETTINGS]: 'My Settings', [ROUTES.ERROR_DETAIL]: 'Errors', + [ROUTES.LIST_ALL_ALERT]: 'Alerts', }; function ShowBreadcrumbs(props: RouteComponentProps): JSX.Element { From ba5e3dcfd3f8c499e4fc81478c6eb422eb370957 Mon Sep 17 00:00:00 2001 From: zedongh <248348907@qq.com> Date: Tue, 14 Jun 2022 20:15:13 +0800 Subject: [PATCH 3/7] fix: getMinMax with 'GLOBAL_TIME' and 'custom' need pass globalTimefeat (#1269) --- .../src/container/GridGraphLayout/Graph/FullView/index.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/frontend/src/container/GridGraphLayout/Graph/FullView/index.tsx b/frontend/src/container/GridGraphLayout/Graph/FullView/index.tsx index e4b4bc8183..3111e33e87 100644 --- a/frontend/src/container/GridGraphLayout/Graph/FullView/index.tsx +++ b/frontend/src/container/GridGraphLayout/Graph/FullView/index.tsx @@ -57,7 +57,10 @@ function FullView({ time: timePreferenceType, ): { min: string | number; max: string | number } => { if (time === 'GLOBAL_TIME') { - const minMax = GetMinMax(globalSelectedTime); + const minMax = GetMinMax(globalSelectedTime, [ + minTime / 1000000, + maxTime / 1000000, + ]); return { min: convertToNanoSecondsToSecond(minMax.minTime / 1000), max: convertToNanoSecondsToSecond(minMax.maxTime / 1000), From 3603e497a6570fb114ef1c9a1afd4befe856903d Mon Sep 17 00:00:00 2001 From: Palash Date: Wed, 22 Jun 2022 22:49:01 +0530 Subject: [PATCH 4/7] chore: error state is updated --- frontend/src/pages/EditRules/index.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/frontend/src/pages/EditRules/index.tsx b/frontend/src/pages/EditRules/index.tsx index 1a65e668af..09cda600ab 100644 --- a/frontend/src/pages/EditRules/index.tsx +++ b/frontend/src/pages/EditRules/index.tsx @@ -35,7 +35,11 @@ function EditRules(): JSX.Element { } }, [isValidRuleId, ruleId]); - if ((isError && !isValidRuleId) || ruleId == null) { + if ( + (isError && !isValidRuleId) || + ruleId == null || + (data?.payload?.data === undefined && !isLoading) + ) { return
{data?.error || t('something_went_wrong')}
; } From b8c3fd1cbf61c76da5a041222121ddb0c94278fd Mon Sep 17 00:00:00 2001 From: Palash Date: Thu, 23 Jun 2022 15:26:44 +0530 Subject: [PATCH 5/7] test: test pipeline for unit test is configured (#1277) * test: test pipeline is configured Co-authored-by: Palash gupta --- .github/workflows/build.yaml | 2 + frontend/jest.setup.ts | 1 + frontend/package.json | 1 + .../__snapshots__/NotFound.test.tsx.snap | 106 +++++++++++++++++- .../TraceFlameGraph.test.tsx.snap | 24 +++- frontend/tsconfig.json | 3 +- frontend/yarn.lock | 7 ++ 7 files changed, 134 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index f9096698cc..8f346bf882 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -17,6 +17,8 @@ jobs: run: cd frontend && yarn install - name: Run ESLint run: cd frontend && npm run lint + - name: Run Jest + run: cd frontend && npm run jest - name: TSC run: yarn tsc working-directory: ./frontend diff --git a/frontend/jest.setup.ts b/frontend/jest.setup.ts index 6557f780cf..b3b8061422 100644 --- a/frontend/jest.setup.ts +++ b/frontend/jest.setup.ts @@ -2,3 +2,4 @@ * Adds custom matchers from the react testing library to all tests */ import '@testing-library/jest-dom'; +import 'jest-styled-components'; diff --git a/frontend/package.json b/frontend/package.json index ebaffb5fae..f93bc9684c 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -159,6 +159,7 @@ "husky": "^7.0.4", "is-ci": "^3.0.1", "jest-playwright-preset": "^1.7.0", + "jest-styled-components": "^7.0.8", "less-plugin-npm-import": "^2.1.0", "lint-staged": "^12.3.7", "portfinder-sync": "^0.0.2", diff --git a/frontend/src/components/NotFound/__snapshots__/NotFound.test.tsx.snap b/frontend/src/components/NotFound/__snapshots__/NotFound.test.tsx.snap index 0e9ce92e30..9da91a31bd 100644 --- a/frontend/src/components/NotFound/__snapshots__/NotFound.test.tsx.snap +++ b/frontend/src/components/NotFound/__snapshots__/NotFound.test.tsx.snap @@ -2,8 +2,102 @@ exports[`Not Found page test should render Not Found page without errors 1`] = ` -

Ah, seems like we reached a dead end!

Page Not Found

diff --git a/frontend/src/container/TraceFlameGraph/__tests__/__snapshots__/TraceFlameGraph.test.tsx.snap b/frontend/src/container/TraceFlameGraph/__tests__/__snapshots__/TraceFlameGraph.test.tsx.snap index 39a3638956..c8c24ebfd4 100644 --- a/frontend/src/container/TraceFlameGraph/__tests__/__snapshots__/TraceFlameGraph.test.tsx.snap +++ b/frontend/src/container/TraceFlameGraph/__tests__/__snapshots__/TraceFlameGraph.test.tsx.snap @@ -2,12 +2,30 @@ exports[`loads and displays greeting 1`] = ` -
diff --git a/frontend/tsconfig.json b/frontend/tsconfig.json index b3aa27fe50..a10bce6e81 100644 --- a/frontend/tsconfig.json +++ b/frontend/tsconfig.json @@ -35,6 +35,7 @@ "playwright.config.ts", "./commitlint.config.js", "./webpack.config.js", - "./webpack.config.prod.js" + "./webpack.config.prod.js", + "./jest.setup.ts" ] } diff --git a/frontend/yarn.lock b/frontend/yarn.lock index 2227658f6b..3a254370a1 100644 --- a/frontend/yarn.lock +++ b/frontend/yarn.lock @@ -8128,6 +8128,13 @@ jest-snapshot@^27.5.1: pretty-format "^27.5.1" semver "^7.3.2" +jest-styled-components@^7.0.8: + version "7.0.8" + resolved "https://registry.yarnpkg.com/jest-styled-components/-/jest-styled-components-7.0.8.tgz#9ea3b43f002de060b4638fde3b422d14b3e3ec9f" + integrity sha512-0KE54d0yIzKcvtOv8eikyjG3rFRtKYUyQovaoha3nondtZzXYGB3bhsvYgEegU08Iry0ndWx2+g9f5ZzD4I+0Q== + dependencies: + css "^3.0.0" + jest-util@^26.6.2: version "26.6.2" resolved "https://registry.yarnpkg.com/jest-util/-/jest-util-26.6.2.tgz#907535dbe4d5a6cb4c47ac9b926f6af29576cbc1" From afbcde5edc9f8cac44122593ae1963c3f1c5c3e2 Mon Sep 17 00:00:00 2001 From: Ankit Nayan Date: Thu, 23 Jun 2022 15:29:15 +0530 Subject: [PATCH 6/7] fix: added 404 for error in getRule api (#1309) * fix: added multiple error checks in getRule api --- .../app/clickhouseReader/reader.go | 36 +++++++++++++++---- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/pkg/query-service/app/clickhouseReader/reader.go b/pkg/query-service/app/clickhouseReader/reader.go index 1258060c41..f405c69f6d 100644 --- a/pkg/query-service/app/clickhouseReader/reader.go +++ b/pkg/query-service/app/clickhouseReader/reader.go @@ -592,21 +592,45 @@ func (r *ClickHouseReader) GetRulesFromDB() (*[]model.RuleResponseItem, *model.A func (r *ClickHouseReader) GetRule(id string) (*model.RuleResponseItem, *model.ApiError) { - idInt, _ := strconv.Atoi(id) + idInt, err := strconv.Atoi(id) + if err != nil { + zap.S().Debug("Error in parsing param: ", err) + return nil, &model.ApiError{Typ: model.ErrorBadData, Err: err} + } rule := &model.RuleResponseItem{} - query := fmt.Sprintf("SELECT id, updated_at, data FROM rules WHERE id=%d", idInt) - - err := r.localDB.Get(rule, query) - - zap.S().Info(query) + query := "SELECT id, updated_at, data FROM rules WHERE id=?" + rows, err := r.localDB.Query(query, idInt) if err != nil { zap.S().Debug("Error in processing sql query: ", err) return nil, &model.ApiError{Typ: model.ErrorInternal, Err: err} } + count := 0 + // iterate over each row + for rows.Next() { + err = rows.Scan(&rule.Id, &rule.UpdatedAt, &rule.Data) + if err != nil { + zap.S().Debug(err) + return nil, &model.ApiError{Typ: model.ErrorInternal, Err: err} + } + count += 1 + + } + + if count == 0 { + err = fmt.Errorf("no rule with id %d found", idInt) + zap.S().Debug(err) + return nil, &model.ApiError{Typ: model.ErrorNotFound, Err: err} + } + if count > 1 { + err = fmt.Errorf("multiple rules with id %d found", idInt) + zap.S().Debug(err) + return nil, &model.ApiError{Typ: model.ErrorConflict, Err: err} + } + return rule, nil } From 64927acd976259c85dad26b6b5ea935b24f81501 Mon Sep 17 00:00:00 2001 From: Ankit Nayan Date: Thu, 23 Jun 2022 15:33:31 +0530 Subject: [PATCH 7/7] updated codeowners for query-service --- .github/CODEOWNERS | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index b717ca9eee..2781d2a0c6 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -4,3 +4,4 @@ * @ankitnayan /frontend/ @palashgdev @pranshuchittora /deploy/ @prashant-shahi +/pkg/query-service/ @srikanthccv @makeavish @nityanandagohain