-
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 4 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
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 { useEffect, 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); | ||
|
|
||
|
|
@@ -276,7 +279,7 @@ export const LogsTab = (p: { pipeline: Pipeline }) => { | |
| searchRef.current = search; | ||
| setMessages([]); | ||
| setIsComplete(false); | ||
| executeMessageSearch(search, topicName, p.pipeline.id).finally(() => { | ||
| executeMessageSearch(search, topicName, pipeline.id).finally(() => { | ||
| setIsComplete(true); | ||
| setMessages([...search.messages]); | ||
| }); | ||
|
|
@@ -361,13 +364,13 @@ export const LogsTab = (p: { pipeline: Pipeline }) => { | |
| <> | ||
| <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} | ||
|
|
@@ -397,20 +400,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 |
|---|---|---|
|
|
@@ -102,6 +102,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 { | ||
|
|
@@ -314,52 +315,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) => { | ||
| const toast = useToast(); | ||
|
|
||
147 changes: 147 additions & 0 deletions
147
frontend/src/components/ui/connect/log-explorer.test.tsx
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 |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| import { render, screen, waitFor } from 'test-utils'; | ||
| import { userEvent } from '@testing-library/user-event'; | ||
| import { TooltipProvider } from 'components/redpanda-ui/components/tooltip'; | ||
| import type { Pipeline } from '../../../protogen/redpanda/api/dataplane/v1/pipeline_pb'; | ||
| import type { TopicMessage } from '../../../state/rest-interfaces'; | ||
|
|
||
| const mockRefresh = vi.fn(); | ||
| let mockReturn: { | ||
| messages: TopicMessage[]; | ||
| phase: string | null; | ||
| error: string | null; | ||
| refresh: () => void; | ||
| }; | ||
|
|
||
| vi.mock('../../../react-query/api/logs', () => ({ | ||
| useLogSearch: () => mockReturn, | ||
| })); | ||
|
|
||
| import { LogExplorer } from './log-explorer'; | ||
|
|
||
| function makeMessage(overrides: Partial<TopicMessage> & { valuePayload?: Record<string, unknown> }): TopicMessage { | ||
| const { valuePayload, ...rest } = overrides; | ||
| const payload = valuePayload ?? { message: 'test log', level: 'INFO', path: 'root.input' }; | ||
| return { | ||
| partitionID: 0, | ||
| offset: 0, | ||
| timestamp: Date.now(), | ||
| compression: 'uncompressed', | ||
| isTransactional: false, | ||
| headers: [], | ||
| key: { payload: '', isPayloadNull: false, encoding: 'text', schemaId: 0, size: 0 }, | ||
| value: { payload, isPayloadNull: false, encoding: 'json', schemaId: 0, size: 100 }, | ||
| valueJson: JSON.stringify(payload), | ||
| valueBinHexPreview: '', | ||
| keyJson: 'pipeline-1', | ||
| keyBinHexPreview: '', | ||
| ...rest, | ||
| } as TopicMessage; | ||
| } | ||
|
|
||
| const pipeline = { id: 'pipeline-1', displayName: 'Test Pipeline' } as unknown as Pipeline; | ||
|
|
||
| function renderExplorer() { | ||
| return render( | ||
| <TooltipProvider> | ||
| <LogExplorer pipeline={pipeline} /> | ||
| </TooltipProvider>, | ||
| ); | ||
| } | ||
|
|
||
| describe('LogExplorer', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| mockReturn = { | ||
| messages: [], | ||
| phase: null, | ||
| error: null, | ||
| refresh: mockRefresh, | ||
| }; | ||
| }); | ||
|
|
||
| test('shows spinner while searching with no messages', () => { | ||
| mockReturn.phase = 'Searching...'; | ||
| renderExplorer(); | ||
| expect(screen.getByTestId('log-loading-spinner')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('shows empty state when no messages and search complete', () => { | ||
| renderExplorer(); | ||
| expect(screen.getByText('No messages')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('renders table with log entries', () => { | ||
| mockReturn.messages = [ | ||
| makeMessage({ offset: 1, valuePayload: { message: 'First log', level: 'INFO', path: 'root.input' } }), | ||
| makeMessage({ offset: 2, valuePayload: { message: 'Second log', level: 'ERROR', path: 'root.output' } }), | ||
| ]; | ||
| renderExplorer(); | ||
| expect(screen.getByText(/First log/)).toBeInTheDocument(); | ||
| expect(screen.getByText(/Second log/)).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('displays timestamps for each entry', () => { | ||
| const ts = new Date('2025-01-15T12:00:00Z').getTime(); | ||
| mockReturn.messages = [makeMessage({ offset: 1, timestamp: ts })]; | ||
| renderExplorer(); | ||
| const rows = screen.getAllByRole('row'); | ||
| // header row + 1 data row | ||
| expect(rows.length).toBeGreaterThanOrEqual(2); | ||
| }); | ||
|
|
||
| test('displays log level badges', () => { | ||
| mockReturn.messages = [ | ||
| makeMessage({ offset: 1, valuePayload: { message: 'err', level: 'ERROR', path: 'x' } }), | ||
| makeMessage({ offset: 2, valuePayload: { message: 'warn', level: 'WARN', path: 'x' } }), | ||
| ]; | ||
| renderExplorer(); | ||
| expect(screen.getByText('ERROR')).toBeInTheDocument(); | ||
| expect(screen.getByText('WARN')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('shows error alert when error is set', () => { | ||
| mockReturn.error = 'Connection refused'; | ||
| renderExplorer(); | ||
| expect(screen.getByText('Failed to load logs')).toBeInTheDocument(); | ||
| expect(screen.getByText('Connection refused')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('refresh button calls refresh', async () => { | ||
| const user = userEvent.setup(); | ||
| renderExplorer(); | ||
| const refreshBtn = screen.getByTestId('log-refresh-button'); | ||
| await user.click(refreshBtn); | ||
| expect(mockRefresh).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| test('clicking a row opens detail sheet', async () => { | ||
| const user = userEvent.setup(); | ||
| mockReturn.messages = [ | ||
| makeMessage({ offset: 42, valuePayload: { message: 'Detail test', level: 'INFO', path: 'root.input' } }), | ||
| ]; | ||
| renderExplorer(); | ||
| const dataRow = screen.getAllByRole('row')[1]; | ||
| await user.click(dataRow); | ||
| await waitFor(() => { | ||
| expect(screen.getByText('Partition')).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
| test('paginates with default 10 per page', () => { | ||
| mockReturn.messages = Array.from({ length: 15 }, (_, i) => | ||
| makeMessage({ offset: i, valuePayload: { message: `Log ${i}`, level: 'INFO', path: 'x' } }), | ||
| ); | ||
| renderExplorer(); | ||
| // Should show 10 data rows on first page (+ 1 header row) | ||
| const rows = screen.getAllByRole('row'); | ||
| expect(rows.length).toBe(11); // 1 header + 10 data | ||
| }); | ||
|
|
||
| test('table has expected column headers', () => { | ||
| renderExplorer(); | ||
| expect(screen.getByText('Timestamp')).toBeInTheDocument(); | ||
| expect(screen.getByText('Level')).toBeInTheDocument(); | ||
| expect(screen.getByText('Component')).toBeInTheDocument(); | ||
| expect(screen.getByText('Message')).toBeInTheDocument(); | ||
| }); | ||
| }); |
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