-
Notifications
You must be signed in to change notification settings - Fork 412
observability: new page based on dataplane observability API #2205
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
Open
nicolaferraro
wants to merge
14
commits into
master
Choose a base branch
from
nf/observability-api
base: master
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 all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f1abc1d
observability: add charts lib
nicolaferraro 17f679c
observability: pass feature flags from embedding app
nicolaferraro 144a773
observability: import chart from ui lib
nicolaferraro f8d5d10
observability: add hooks for API call
nicolaferraro e440fae
observability: add new observability page
nicolaferraro fe48999
observability: add route conditional to feature flag
nicolaferraro 66dc700
observability: fix route-showing logic
nicolaferraro 78e8eb1
observability: switch to using the new UI registry
nicolaferraro 8e07663
observability: use conversion utils
nicolaferraro d713e21
observability: regen routeTree
nicolaferraro 1c675d4
observability: first pass on comments
nicolaferraro 67a1902
observability: move some code to utils
nicolaferraro bbc0d52
observability: apply unit conversion to Y axis
nicolaferraro 3d3f765
observability: use a common time-range approach with transcripts
nicolaferraro 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
192 changes: 192 additions & 0 deletions
192
frontend/src/components/pages/observability/metric-chart.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,192 @@ | ||
| /** | ||
| * Copyright 2026 Redpanda Data, Inc. | ||
| * | ||
| * Use of this software is governed by the Business Source License | ||
| * included in the file https://github.com/redpanda-data/redpanda/blob/dev/licenses/bsl.md | ||
| * | ||
| * As of the Change Date specified in that file, in accordance with | ||
| * the Business Source License, use of this software will be governed | ||
| * by the Apache License, Version 2.0 | ||
| */ | ||
|
|
||
| import { timestampFromMs } from '@bufbuild/protobuf/wkt'; | ||
| import type { FC } from 'react'; | ||
| import { useMemo } from 'react'; | ||
| import { useExecuteRangeQuery } from 'react-query/api/observability'; | ||
| import { CartesianGrid, Line, LineChart, XAxis, YAxis } from 'recharts'; | ||
|
|
||
| import { CHART_COLORS, transformTimeSeriesData } from './utils/chart-data'; | ||
| import { formatWithUnit } from '../../../utils/unit'; | ||
| import { Alert, AlertDescription } from '../../redpanda-ui/components/alert'; | ||
| import { | ||
| ChartContainer, | ||
| ChartLegend, | ||
| ChartLegendContent, | ||
| ChartTooltip, | ||
| ChartTooltipContent, | ||
| } from '../../redpanda-ui/components/chart'; | ||
| import { Skeleton } from '../../redpanda-ui/components/skeleton'; | ||
| import { Heading } from '../../redpanda-ui/components/typography'; | ||
|
|
||
| type MetricChartProps = { | ||
| queryName: string; | ||
| timeRange: { | ||
| start: Date; | ||
| end: Date; | ||
| }; | ||
| }; | ||
|
|
||
| export const MetricChart: FC<MetricChartProps> = ({ queryName, timeRange }) => { | ||
| const { data, isLoading, isError } = useExecuteRangeQuery({ | ||
| queryName, | ||
| params: { | ||
| start: timestampFromMs(timeRange.start.getTime()), | ||
| end: timestampFromMs(timeRange.end.getTime()), | ||
| filters: {}, | ||
| }, | ||
| }); | ||
|
|
||
| // Transform the time series data into chart format | ||
| const chartData = useMemo(() => transformTimeSeriesData(data?.results || []), [data]); | ||
|
|
||
| // Extract series names for creating lines | ||
| const seriesNames = useMemo(() => { | ||
| if (!data?.results) { | ||
| return []; | ||
| } | ||
| return data.results | ||
| .map((series) => series.name || 'value') | ||
| .filter((name, index, self) => self.indexOf(name) === index); | ||
| }, [data]); | ||
|
|
||
| // Chart configuration | ||
| const chartConfig = useMemo(() => { | ||
| const config: Record<string, { label: string; color: string }> = {}; | ||
|
|
||
| for (let i = 0; i < seriesNames.length; i++) { | ||
| config[seriesNames[i]] = { | ||
| label: seriesNames[i], | ||
| color: CHART_COLORS[i % CHART_COLORS.length], | ||
| }; | ||
| } | ||
|
|
||
| return config; | ||
| }, [seriesNames]); | ||
|
|
||
| if (isLoading) { | ||
| return ( | ||
| <div className="rounded-md border border-gray-200 p-4"> | ||
| <Skeleton className="mt-2 h-[200px]" /> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| if (isError || !data) { | ||
| return ( | ||
| <div className="rounded-md border border-gray-200 p-4"> | ||
| <Alert className="mt-2" variant="warning"> | ||
| <AlertDescription>Failed to load data for this metric</AlertDescription> | ||
| </Alert> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| if (chartData.length === 0) { | ||
| return ( | ||
| <div className="rounded-md border border-gray-200 p-4"> | ||
| {data.metadata?.description ? ( | ||
| <Heading className="mb-4" level={4}> | ||
| {data.metadata.description} | ||
| </Heading> | ||
| ) : null} | ||
| <Alert className="mt-2" variant="info"> | ||
| <AlertDescription>No data available for this time range</AlertDescription> | ||
| </Alert> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <div className="rounded-md border border-gray-200 p-4"> | ||
| {data.metadata?.description ? ( | ||
| <Heading className="mb-4" level={3}> | ||
| {data.metadata.description} | ||
| </Heading> | ||
| ) : null} | ||
|
|
||
| <ChartContainer className="mt-4 h-[250px] w-full" config={chartConfig}> | ||
| <LineChart accessibilityLayer data={chartData}> | ||
| <CartesianGrid strokeDasharray="3 3" vertical={false} /> | ||
| <XAxis | ||
| axisLine={false} | ||
| dataKey="timestamp" | ||
| tickFormatter={(value) => { | ||
| const date = new Date(value); | ||
| return date.toLocaleTimeString('en-US', { | ||
| hour: '2-digit', | ||
| minute: '2-digit', | ||
| timeZone: 'UTC', | ||
| }); | ||
| }} | ||
| tickLine={false} | ||
| tickMargin={10} | ||
| /> | ||
| <YAxis | ||
| axisLine={false} | ||
| tickFormatter={(value) => formatWithUnit(value, data.metadata?.unit)} | ||
| tickLine={false} | ||
| width={80} | ||
| /> | ||
| <ChartTooltip | ||
| content={ | ||
| <ChartTooltipContent | ||
| className="min-w-[200px]" | ||
| formatter={(value, name, item) => { | ||
| const indicatorColor = item.payload.fill || item.color; | ||
| const formattedValue = typeof value === 'number' ? formatWithUnit(value, data.metadata?.unit) : value; | ||
| return ( | ||
| <div className="flex w-full items-center gap-3"> | ||
| <div className="h-2.5 w-2.5 shrink-0 rounded-[2px]" style={{ backgroundColor: indicatorColor }} /> | ||
| <span className="text-muted-foreground">{name}</span> | ||
| <span className="ml-auto font-medium font-mono tabular-nums">{formattedValue}</span> | ||
| </div> | ||
| ); | ||
| }} | ||
| hideLabel={false} | ||
| labelFormatter={(_value, payload) => { | ||
| const timestamp = payload?.[0]?.payload?.timestamp; | ||
| if (!timestamp || typeof timestamp !== 'number') { | ||
| return ''; | ||
| } | ||
| const date = new Date(timestamp); | ||
| if (!date.getTime()) { | ||
| return ''; | ||
| } | ||
| return date.toLocaleString('en-US', { | ||
| month: 'short', | ||
| day: 'numeric', | ||
| hour: '2-digit', | ||
| minute: '2-digit', | ||
| timeZone: 'UTC', | ||
| timeZoneName: 'short', | ||
| }); | ||
| }} | ||
| /> | ||
| } | ||
| /> | ||
| {seriesNames.map((seriesName) => ( | ||
| <Line | ||
| dataKey={seriesName} | ||
| dot={false} | ||
| key={seriesName} | ||
| stroke={chartConfig[seriesName]?.color} | ||
| strokeWidth={2} | ||
| type="linear" | ||
| /> | ||
| ))} | ||
| <ChartLegend content={<ChartLegendContent />} /> | ||
| </LineChart> | ||
| </ChartContainer> | ||
| </div> | ||
| ); | ||
| }; |
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.
Let's use recharts v3 shadcn-ui/ui#7669 which will require components to be upgraded.
We can do that in a followup PR