-
Notifications
You must be signed in to change notification settings - Fork 415
feat: adds log explorer component #2283
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
Merged
+1,881
−321
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2a7ec9a
feat: adds log explorer component
eblairmckee 8b94a9f
fix: type
eblairmckee 1a694b6
fix: converted to react-query for historical logs, and integrated jul…
eblairmckee 41e7613
fix: lint
eblairmckee 137cb89
Merge branch 'master' into pr2/log-explorer-molecule
eblairmckee 7f8fe8b
fix: fix lint issue after mobx removal
eblairmckee af622f2
fix: react doctor fixes
eblairmckee eead313
Merge branch 'master' into pr2/log-explorer-molecule
eblairmckee 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -13,7 +13,9 @@ import { ConnectError } from '@connectrpc/connect'; | |
| import { Alert, AlertIcon, Box, Button, createStandaloneToast, DataTable, Flex, SearchField } from '@redpanda-data/ui'; | ||
| import { Link } from '@tanstack/react-router'; | ||
| import type { ColumnDef, SortingState } from '@tanstack/react-table'; | ||
| import { Button as RegistryButton } from 'components/redpanda-ui/components/button'; | ||
| import { isEmbedded, isFeatureFlagEnabled } from 'config'; | ||
| import { RefreshCcw } from 'lucide-react'; | ||
| import { useCallback, useEffect, useMemo, useRef, useState } from 'react'; | ||
| import { toast as sonnerToast } from 'sonner'; | ||
| import { formatToastErrorMessageGRPC } from 'utils/toast.utils'; | ||
|
|
@@ -40,6 +42,7 @@ import { | |
| import type { TopicMessage } from '../../../state/rest-interfaces'; | ||
| import { PartitionOffsetOrigin } from '../../../state/ui'; | ||
| import { sanitizeString } from '../../../utils/filter-helper'; | ||
| import { isFilterMatch } from '../../../utils/message-table-helpers'; | ||
| import { DefaultSkeleton, QuickTable, TimestampDisplay } from '../../../utils/tsx-utils'; | ||
| import { decodeURIComponentPercents, delay, encodeBase64 } from '../../../utils/utils'; | ||
| import PageContent from '../../misc/page-content'; | ||
|
|
@@ -259,7 +262,7 @@ const PipelineEditor = (p: { pipeline: Pipeline }) => { | |
| ); | ||
| }; | ||
|
|
||
| export const LogsTab = (p: { pipeline: Pipeline }) => { | ||
| export const LogsTab = ({ pipeline, variant = 'card' }: { pipeline: Pipeline; variant?: 'ghost' | 'card' }) => { | ||
| const topicName = '__redpanda.connect.logs'; | ||
| const topic = api.topics?.first((x) => x.topicName === topicName); | ||
|
|
||
|
|
@@ -273,18 +276,19 @@ export const LogsTab = (p: { pipeline: Pipeline }) => { | |
| const searchRef = useRef<MessageSearch | null>(null); | ||
| const [refreshCount, setRefreshCount] = useState(0); | ||
|
|
||
| // biome-ignore lint/correctness/useExhaustiveDependencies: intentional to force message search to re-run when pipeline.id and refreshCount changes | ||
| useEffect(() => { | ||
| searchRef.current?.stopSearch(); | ||
| const search = createMessageSearch(); | ||
| searchRef.current = search; | ||
| queueMicrotask(() => setLogState({ messages: [], isComplete: false })); | ||
| executeMessageSearch(search, topicName, p.pipeline.id).finally(() => { | ||
| executeMessageSearch(search, topicName, pipeline.id).finally(() => { | ||
| setLogState({ messages: [...search.messages], isComplete: true }); | ||
| }); | ||
| return () => { | ||
| search.stopSearch(); | ||
| }; | ||
| }, [refreshCount]); | ||
| }, [refreshCount, pipeline.id]); | ||
|
|
||
| useEffect(() => { | ||
| const interval = setInterval(() => { | ||
|
|
@@ -320,7 +324,9 @@ export const LogsTab = (p: { pipeline: Pipeline }) => { | |
| if (loadedMessages && loadedMessages.length === 1) { | ||
| setLogState((prev) => { | ||
| const idx = prev.messages.findIndex((x) => x.partitionID === partitionID && x.offset === offset); | ||
| if (idx === -1) return prev; | ||
| if (idx === -1) { | ||
| return prev; | ||
| } | ||
| const updated = [...prev.messages]; | ||
| updated[idx] = loadedMessages[0]; | ||
| return { ...prev, messages: updated }; | ||
|
|
@@ -348,11 +354,7 @@ export const LogsTab = (p: { pipeline: Pipeline }) => { | |
| header: 'Value', | ||
| accessorKey: 'value', | ||
| cell: ({ row: { original } }) => ( | ||
| <MessagePreview | ||
| isCompactTopic={isCompactTopic} | ||
| msg={original} | ||
| previewFields={() => []} | ||
| /> | ||
| <MessagePreview isCompactTopic={isCompactTopic} msg={original} previewFields={() => []} /> | ||
| ), | ||
| size: Number.MAX_SAFE_INTEGER, | ||
| }, | ||
|
|
@@ -364,11 +366,7 @@ export const LogsTab = (p: { pipeline: Pipeline }) => { | |
| ({ row: { original } }: { row: { original: TopicMessage } }) => ( | ||
| <ExpandedMessage | ||
| loadLargeMessage={() => | ||
| loadLargeMessage( | ||
| searchRef.current?.searchRequest?.topicName ?? '', | ||
| original.partitionID, | ||
| original.offset | ||
| ) | ||
| loadLargeMessage(searchRef.current?.searchRequest?.topicName ?? '', original.partitionID, original.offset) | ||
| } | ||
| msg={original} | ||
| /> | ||
|
|
@@ -377,26 +375,27 @@ export const LogsTab = (p: { pipeline: Pipeline }) => { | |
| ); | ||
|
|
||
| const filteredMessages = useMemo( | ||
| () => messages.filter((x) => { | ||
| if (!logsQuickSearch) { | ||
| return true; | ||
| } | ||
| return isFilterMatch(logsQuickSearch, x); | ||
| }), | ||
| () => | ||
| messages.filter((x) => { | ||
| if (!logsQuickSearch) { | ||
| return true; | ||
| } | ||
| return isFilterMatch(logsQuickSearch, x); | ||
| }), | ||
| [messages, logsQuickSearch] | ||
| ); | ||
|
|
||
| return ( | ||
| <> | ||
| <Box my="1rem">The logs below are for the last five hours.</Box> | ||
|
|
||
| <Section minWidth="800px"> | ||
| <Flex mb="6"> | ||
| <Section borderColor={variant === 'ghost' ? 'transparent' : undefined} minWidth="800px" overflowY="auto"> | ||
| <div className="mb-6 flex items-center justify-between gap-2"> | ||
| <SearchField searchText={logsQuickSearch} setSearchText={setLogsQuickSearch} width="230px" /> | ||
| <Button ml="auto" onClick={() => setRefreshCount((c) => c + 1)} variant="outline"> | ||
| Refresh logs | ||
| </Button> | ||
| </Flex> | ||
| <RegistryButton onClick={() => setRefreshCount((c) => c + 1)} size="icon" variant="ghost"> | ||
| <RefreshCcw /> | ||
| </RegistryButton> | ||
| </div> | ||
|
|
||
| <DataTable<TopicMessage> | ||
| columns={messageTableColumns} | ||
|
|
@@ -415,20 +414,6 @@ export const LogsTab = (p: { pipeline: Pipeline }) => { | |
| ); | ||
| }; | ||
|
|
||
| function isFilterMatch(str: string, m: TopicMessage) { | ||
| const lowerStr = str.toLowerCase(); | ||
| if (m.offset.toString().toLowerCase().includes(lowerStr)) { | ||
| return true; | ||
| } | ||
| if (m.keyJson?.toLowerCase().includes(lowerStr)) { | ||
| return true; | ||
| } | ||
| if (m.valueJson?.toLowerCase().includes(lowerStr)) { | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
Comment on lines
-418
to
-430
Contributor
Author
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. extracted to shared util |
||
|
|
||
| function executeMessageSearch(search: MessageSearch, topicName: string, pipelineId: string) { | ||
| const filterCode: string = `return key == "${pipelineId}";`; | ||
|
|
||
|
|
||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -104,6 +104,7 @@ import { appGlobal } from '../../../../state/app-global'; | |
| import { useTopicSettingsStore } from '../../../../stores/topic-settings-store'; | ||
| import { IsDev } from '../../../../utils/env'; | ||
| import { sanitizeString, wrapFilterFragment } from '../../../../utils/filter-helper'; | ||
| import { trimSlidingWindow } from '../../../../utils/message-table-helpers'; | ||
| import { sortingParser } from '../../../../utils/sorting-parser'; | ||
| import { getTopicFilters, setTopicFilters } from '../../../../utils/topic-filters-session'; | ||
| import { | ||
|
|
@@ -327,52 +328,6 @@ async function loadLargeMessage({ | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Pure function for sliding-window trimming of messages. | ||
| * Keeps at most maxResults + pageSize messages in the window, | ||
| * trimming only pages before the user's current view. | ||
| */ | ||
| function trimSlidingWindow({ | ||
| messages, | ||
| maxResults, | ||
| pageSize, | ||
| currentGlobalPage, | ||
| windowStartPage, | ||
| virtualStartIndex, | ||
| }: { | ||
| messages: TopicMessage[]; | ||
| maxResults: number; | ||
| pageSize: number; | ||
| currentGlobalPage: number; | ||
| windowStartPage: number; | ||
| virtualStartIndex: number; | ||
| }): { messages: TopicMessage[]; windowStartPage: number; virtualStartIndex: number; trimCount: number } { | ||
| const maxWindowSize = maxResults + pageSize; | ||
|
|
||
| if (maxResults < pageSize || messages.length <= maxWindowSize) { | ||
| return { messages, windowStartPage, virtualStartIndex, trimCount: 0 }; | ||
| } | ||
|
|
||
| const excess = messages.length - maxWindowSize; | ||
| const currentLocalPage = Math.max(0, currentGlobalPage - windowStartPage); | ||
|
|
||
| // Never trim the page the user is currently viewing or the one before it | ||
| const maxPagesToTrim = Math.max(0, currentLocalPage - 1); | ||
| const pagesToTrim = Math.min(Math.floor(excess / pageSize), maxPagesToTrim); | ||
| const trimCount = pagesToTrim * pageSize; | ||
|
|
||
| if (trimCount === 0) { | ||
| return { messages, windowStartPage, virtualStartIndex, trimCount: 0 }; | ||
| } | ||
|
|
||
| return { | ||
| messages: messages.slice(trimCount), | ||
| windowStartPage: windowStartPage + pagesToTrim, | ||
| virtualStartIndex: virtualStartIndex + trimCount, | ||
| trimCount, | ||
| }; | ||
| } | ||
|
|
||
|
Comment on lines
-335
to
-375
Contributor
Author
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. extracted to shared util |
||
| // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: this is because of the refactoring effort, the scope will be minimised eventually | ||
| export const TopicMessageView: FC<TopicMessageViewProps> = (props) => { | ||
| 'use no memo'; | ||
|
|
||
This file contains hidden or 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
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.
adding variant so we can embed legacy version when feature flag for new log explorer is off