-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 celery task feature - with task graphs and details #6840
Open
SagarRajput-7
wants to merge
2
commits into
main
Choose a base branch
from
celery-task
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...end/src/components/CeleryTask/CeleryTaskConfigOptions/CeleryTaskConfigOptions.styles.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
.celery-task-filters { | ||
display: flex; | ||
justify-content: space-between; | ||
width: 100%; | ||
|
||
.celery-filters { | ||
display: flex; | ||
align-items: center; | ||
gap: 8px; | ||
|
||
.config-select-option { | ||
width: 100%; | ||
.ant-select-selector { | ||
display: flex; | ||
min-height: 32px; | ||
align-items: center; | ||
gap: 16px; | ||
min-width: 164px; | ||
|
||
border-radius: 2px; | ||
border: 1px solid var(--bg-slate-400); | ||
background: var(--bg-ink-300); | ||
} | ||
} | ||
} | ||
} | ||
|
||
.lightMode { | ||
.celery-task-filters { | ||
.celery-filters { | ||
.config-select-option { | ||
.ant-select-selector { | ||
border: 1px solid var(--bg-vanilla-300); | ||
background: var(--bg-vanilla-100); | ||
} | ||
} | ||
} | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
frontend/src/components/CeleryTask/CeleryTaskConfigOptions/CeleryTaskConfigOptions.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import './CeleryTaskConfigOptions.styles.scss'; | ||
|
||
import { Color } from '@signozhq/design-tokens'; | ||
import { Button, Select, Spin, Tooltip } from 'antd'; | ||
import { SelectMaxTagPlaceholder } from 'components/MessagingQueues/MQCommon/MQCommon'; | ||
import { QueryParams } from 'constants/query'; | ||
import useUrlQuery from 'hooks/useUrlQuery'; | ||
import { Check, Share2 } from 'lucide-react'; | ||
import { useState } from 'react'; | ||
import { useHistory, useLocation } from 'react-router-dom'; | ||
import { useCopyToClipboard } from 'react-use'; | ||
|
||
import { | ||
getValuesFromQueryParams, | ||
setQueryParamsFromOptions, | ||
} from '../CeleryUtils'; | ||
import { useCeleryFilterOptions } from '../useCeleryFilterOptions'; | ||
|
||
function CeleryTaskConfigOptions(): JSX.Element { | ||
const { handleSearch, isFetching, options } = useCeleryFilterOptions( | ||
'celery.task_name', | ||
); | ||
const history = useHistory(); | ||
const location = useLocation(); | ||
|
||
const [isURLCopied, setIsURLCopied] = useState(false); | ||
const urlQuery = useUrlQuery(); | ||
|
||
const [, handleCopyToClipboard] = useCopyToClipboard(); | ||
|
||
return ( | ||
<div className="celery-task-filters"> | ||
<div className="celery-filters"> | ||
<Select | ||
placeholder="Task Name" | ||
showSearch | ||
mode="multiple" | ||
options={options} | ||
loading={isFetching} | ||
className="config-select-option" | ||
onSearch={handleSearch} | ||
maxTagCount={4} | ||
maxTagPlaceholder={SelectMaxTagPlaceholder} | ||
value={getValuesFromQueryParams(QueryParams.taskName, urlQuery) || []} | ||
notFoundContent={ | ||
isFetching ? ( | ||
<span> | ||
<Spin size="small" /> Loading... | ||
</span> | ||
) : ( | ||
<span>No Task Name found</span> | ||
) | ||
} | ||
onChange={(value): void => { | ||
handleSearch(''); | ||
setQueryParamsFromOptions( | ||
value, | ||
urlQuery, | ||
history, | ||
location, | ||
QueryParams.taskName, | ||
); | ||
}} | ||
/> | ||
</div> | ||
<Tooltip title="Share this" arrow={false}> | ||
<Button | ||
className="periscope-btn copy-url-btn" | ||
onClick={(): void => { | ||
handleCopyToClipboard(window.location.href); | ||
setIsURLCopied(true); | ||
setTimeout(() => { | ||
setIsURLCopied(false); | ||
}, 1000); | ||
}} | ||
icon={ | ||
isURLCopied ? ( | ||
<Check size={14} color={Color.BG_FOREST_500} /> | ||
) : ( | ||
<Share2 size={14} /> | ||
) | ||
} | ||
/> | ||
</Tooltip> | ||
</div> | ||
); | ||
} | ||
|
||
export default CeleryTaskConfigOptions; |
49 changes: 49 additions & 0 deletions
49
frontend/src/components/CeleryTask/CeleryTaskConfigOptions/useGetCeleryFilters.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* eslint-disable react-hooks/exhaustive-deps */ | ||
import { DefaultOptionType } from 'antd/es/select'; | ||
import { getAttributesValues } from 'api/queryBuilder/getAttributesValues'; | ||
import { useQuery } from 'react-query'; | ||
import { DataTypes } from 'types/api/queryBuilder/queryAutocompleteResponse'; | ||
import { DataSource } from 'types/common/queryBuilder'; | ||
|
||
export type FilterOptionType = 'celery.task_name'; | ||
|
||
export interface Filters { | ||
searchText: string; | ||
attributeKey: FilterOptionType; | ||
} | ||
|
||
export interface GetAllFiltersResponse { | ||
options: DefaultOptionType[]; | ||
isFetching: boolean; | ||
} | ||
|
||
export function useGetAllFilters(props: Filters): GetAllFiltersResponse { | ||
const { searchText, attributeKey } = props; | ||
|
||
const { data, isLoading } = useQuery( | ||
['attributesValues', searchText], | ||
async () => { | ||
const { payload } = await getAttributesValues({ | ||
aggregateOperator: 'noop', | ||
dataSource: DataSource.TRACES, | ||
aggregateAttribute: '', | ||
attributeKey, | ||
searchText: searchText ?? '', | ||
filterAttributeKeyDataType: DataTypes.String, | ||
tagType: 'tag', | ||
}); | ||
|
||
if (payload) { | ||
const values = Object.values(payload).find((el) => !!el) || []; | ||
const options: DefaultOptionType[] = values.map((val: string) => ({ | ||
label: val, | ||
value: val, | ||
})); | ||
return options; | ||
} | ||
return []; | ||
}, | ||
); | ||
|
||
return { options: data ?? [], isFetching: isLoading }; | ||
} |
5 changes: 5 additions & 0 deletions
5
frontend/src/components/CeleryTask/CeleryTaskDetail/CeleryTaskDetail.style.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.celery-task-detail-drawer { | ||
.ant-drawer-body { | ||
padding: 0px; | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
frontend/src/components/CeleryTask/CeleryTaskDetail/CeleryTaskDetail.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import './CeleryTaskDetail.style.scss'; | ||
|
||
import { Color, Spacing } from '@signozhq/design-tokens'; | ||
import { Divider, Drawer, Typography } from 'antd'; | ||
import { useIsDarkMode } from 'hooks/useDarkMode'; | ||
import { X } from 'lucide-react'; | ||
|
||
import CeleryTaskGraph from '../CeleryTaskGraph/CeleryTaskGraph'; | ||
import { celerySlowestTasksTableWidgetData } from '../CeleryTaskGraph/CeleryTaskGraphUtils'; | ||
|
||
export type CeleryTaskData = { | ||
taskName: string; | ||
taskId: string; | ||
taskStatus: string; | ||
taskCreatedAt: string; | ||
taskCompletedAt: string; | ||
}; | ||
|
||
export type CeleryTaskDetailProps = { | ||
task: CeleryTaskData | null; | ||
onClose: () => void; | ||
}; | ||
|
||
export default function CeleryTaskDetail({ | ||
task, | ||
onClose, | ||
}: CeleryTaskDetailProps): JSX.Element { | ||
const isDarkMode = useIsDarkMode(); | ||
console.log(task); | ||
|
||
return ( | ||
<Drawer | ||
width="50%" | ||
title={ | ||
<> | ||
<Divider type="vertical" /> | ||
<Typography.Text className="title">{task?.taskName}</Typography.Text> | ||
</> | ||
} | ||
placement="right" | ||
onClose={onClose} | ||
open={!!task} | ||
style={{ | ||
overscrollBehavior: 'contain', | ||
background: isDarkMode ? Color.BG_INK_400 : Color.BG_VANILLA_100, | ||
}} | ||
className="celery-task-detail-drawer" | ||
destroyOnClose | ||
closeIcon={<X size={16} style={{ marginTop: Spacing.MARGIN_1 }} />} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid using inline styles for the |
||
> | ||
{task && ( | ||
<CeleryTaskGraph | ||
widgetData={celerySlowestTasksTableWidgetData} | ||
onClick={(): void => {}} | ||
/> | ||
)} | ||
</Drawer> | ||
); | ||
} |
36 changes: 36 additions & 0 deletions
36
frontend/src/components/CeleryTask/CeleryTaskGraph/CeleryTaskGraph.style.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
.celery-task-graph-grid-container { | ||
width: 100%; | ||
display: grid; | ||
grid-template-rows: 1fr; | ||
gap: 10px; | ||
|
||
.celery-task-graph-grid { | ||
display: grid; | ||
grid-template-columns: repeat(2, 1fr); | ||
align-items: flex-start; | ||
gap: 10px; | ||
width: 100%; | ||
|
||
.celery-task-graph { | ||
height: 350px !important; | ||
padding: 10px; | ||
width: 100%; | ||
box-sizing: border-box; | ||
} | ||
} | ||
|
||
.celery-task-graph-grid-bottom { | ||
display: grid; | ||
grid-template-columns: repeat(3, 1fr); | ||
align-items: flex-start; | ||
gap: 10px; | ||
width: 100%; | ||
|
||
.celery-task-graph { | ||
height: 350px !important; | ||
padding: 10px; | ||
width: 100%; | ||
box-sizing: border-box; | ||
} | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
frontend/src/components/CeleryTask/CeleryTaskGraph/CeleryTaskGraph.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { QueryParams } from 'constants/query'; | ||
import { PANEL_TYPES } from 'constants/queryBuilder'; | ||
import { ViewMenuAction } from 'container/GridCardLayout/config'; | ||
import GridCard from 'container/GridCardLayout/GridCard'; | ||
import { Card } from 'container/GridCardLayout/styles'; | ||
import { useIsDarkMode } from 'hooks/useDarkMode'; | ||
import useUrlQuery from 'hooks/useUrlQuery'; | ||
import { useCallback } from 'react'; | ||
import { useDispatch } from 'react-redux'; | ||
import { useHistory, useLocation } from 'react-router-dom'; | ||
import { UpdateTimeInterval } from 'store/actions'; | ||
import { Widgets } from 'types/api/dashboard/getAll'; | ||
|
||
import { CeleryTaskData } from '../CeleryTaskDetail/CeleryTaskDetail'; | ||
|
||
function CeleryTaskGraph({ | ||
widgetData, | ||
onClick, | ||
}: { | ||
widgetData: Widgets; | ||
onClick: (task: CeleryTaskData) => void; | ||
}): JSX.Element { | ||
const history = useHistory(); | ||
const { pathname } = useLocation(); | ||
const dispatch = useDispatch(); | ||
const urlQuery = useUrlQuery(); | ||
const isDarkMode = useIsDarkMode(); | ||
|
||
const onDragSelect = useCallback( | ||
(start: number, end: number) => { | ||
const startTimestamp = Math.trunc(start); | ||
const endTimestamp = Math.trunc(end); | ||
|
||
urlQuery.set(QueryParams.startTime, startTimestamp.toString()); | ||
urlQuery.set(QueryParams.endTime, endTimestamp.toString()); | ||
const generatedUrl = `${pathname}?${urlQuery.toString()}`; | ||
history.push(generatedUrl); | ||
|
||
if (startTimestamp !== endTimestamp) { | ||
dispatch(UpdateTimeInterval('custom', [startTimestamp, endTimestamp])); | ||
} | ||
}, | ||
[dispatch, history, pathname, urlQuery], | ||
); | ||
|
||
return ( | ||
<Card | ||
isDarkMode={isDarkMode} | ||
$panelType={PANEL_TYPES.TIME_SERIES} | ||
className="celery-task-graph" | ||
> | ||
<GridCard | ||
widget={widgetData} | ||
headerMenuList={[...ViewMenuAction]} | ||
onDragSelect={onDragSelect} | ||
onClickHandler={(arg): void => { | ||
console.log('clicked', arg); // todo-sagar: add logic to handle click | ||
onClick(arg as any); | ||
}} | ||
/> | ||
</Card> | ||
); | ||
} | ||
|
||
export default CeleryTaskGraph; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the console.log statement to clean up the code for production.