:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(logs): render the filter volume preview with quill charts (#82670)
Sam Pennington0e1abe2deec4
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex fa4b8dfb9619..9ee2817e68ad 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -4616,6 +4616,14 @@ snapshots:hash: v1.k794b7964.ff05bda7e439902c963d4cee0889351a3cace04ef2e149494544b1bc60794347.JKw0gsl8CIiVdeLk4DndxZFLr2oZ7kYNBIxNotCuVCQlemon-ui-visual-image-diff-viewer--small-image--light:hash: v1.k794b7964.ed31587820d0216f2281ec8e610da8cb9fe8cb45f9c13e0280f17771cf84994a.spusB2C8AKwu5Tv0KOr8pkjDxgEZw5jcOlEikYAzKWI+ logs-logsfiltervolumesparkline--volume-by-service--dark:+ hash: v1.k794b7964.e1872546be635b378270c73689340083b3af5a318a302372c8db68edfaf232df.T7cwZzY2SaTMk7nKYYhotxV3cmnDaQ1-Cy5dm3fUH2c+ logs-logsfiltervolumesparkline--volume-by-service--light:+ hash: v1.k794b7964.c6c485dd8017de3e49b707f531b9de3f4a231357d40d3637fea3b9c518ea26d2.amVC8vlIwFdYeEvtxSR8TxSDrp6AXXDr6P_1tpWLPyU+ logs-logsfiltervolumesparkline--with-rate-limit-threshold--dark:+ hash: v1.k794b7964.1d690c0916c6cb0e1cd9682b2c2ceaf072907faf864eb9c60708f20b54491d01.CSbDUiLNw1wFHNsYIjr6gY5pqrWGWK_ka7wav_H_zwo+ logs-logsfiltervolumesparkline--with-rate-limit-threshold--light:+ hash: v1.k794b7964.90511b5879e111bf4d4b3f7b31f5d24159de7590de35e110bc4d510f763cfa1a.l4VDaP9QZZgd9RbT-nWeHb00FGgojPia3OHP-Bq-pfUmcp-apps-actions--list--light:hash: v1.k794b7964.780ee2787e03d18e28952f15ba1063d3561bf506c3f27370e111aa00b6840480.kyd4ZfOZOnVnvs4zzuHttn7iaRk1OSRVc4UGm-myJEAmcp-apps-actions--multi-step--light:@@ -7827,7 +7835,7 @@ snapshots:scenes-app-settings-user--settings-user-navigation--dark:hash: v1.k794b7964.7c5a5bdb7736062bcb70e36f20fc683eb9c014a0409dddb546a345fba91894b5.lMpgtqpaZZZsixseHxd_CxR4u_ZR5SnnrrOixJUvesMscenes-app-settings-user--settings-user-navigation--light:- hash: v1.k794b7964.3acb8296dccbd1585e16658aea21430558340a74ec07c6b0bfc27f5d6e424187.r_cJHvPzf4G4BmOgDkZwZJDuDTdBGFPlbdxO_xNYNHI+ hash: v1.k794b7964.384ac6e1638edb3f361ff8d137589816bfcd3309e9861eba95a83ff6fbe57809.xxyxmKQQ4llOtJ1zB86Vos3B_NTYd4mNvlLeexQlz4Uscenes-app-settings-user--settings-user-notifications--dark:hash: v1.k794b7964.a09a57f1c0bbcebf82942edebeba7772b2f684ba235bcef3a816aec2beb4cbce.AtQZhdZeeMVvpcmyBhPvprSMZawliTZaIFE5G8M_MVgscenes-app-settings-user--settings-user-notifications--light:diff --git a/packages/quill/packages/charts/src/core/scales.test.ts b/packages/quill/packages/charts/src/core/scales.test.tsindex e08b4ddedc44..382c633bcbe1 100644--- a/packages/quill/packages/charts/src/core/scales.test.ts+++ b/packages/quill/packages/charts/src/core/scales.test.ts@@ -732,6 +732,16 @@ describe('hog-charts scales', () => {expect(result.get('s3')!.bottom).toEqual([30])})+ it('stacks a series whose key collides with Object.prototype (e.g. __proto__)', () => {+ const s1 = makeSeries({ key: '__proto__', data: [10, 20] })+ const s2 = makeSeries({ key: 's2', data: [5, 15] })+ const result = computeStackData([s1, s2], ['a', 'b'])++ expect(result.get('__proto__')!.top).toEqual([10, 20])+ expect(result.get('s2')!.top).toEqual([15, 35])+ expect(result.get('s2')!.bottom).toEqual([10, 20])+ })+it('excludes visibility.excluded series from the stack', () => {const visible = makeSeries({ key: 'v', data: [10, 20] })const hidden = makeSeries({ key: 'h', data: [100, 200], visibility: { excluded: true } })diff --git a/packages/quill/packages/charts/src/core/scales.ts b/packages/quill/packages/charts/src/core/scales.tsindex e83c69bac55c..f0de612e2e5b 100644--- a/packages/quill/packages/charts/src/core/scales.ts+++ b/packages/quill/packages/charts/src/core/scales.ts@@ -532,7 +532,9 @@ function buildStackData(for (const axisSeries of seriesByAxis.values()) {const tableData = labels.map((_, i) => {- const row: Record<string, number> = {}+ // Null-prototype: series keys come from user data (breakdown values, service names),+ // so a key like `__proto__` must land as an own property instead of the prototype setter.+ const row: Record<string, number> = Object.create(null)for (const s of axisSeries) {const raw = s.data[i] ?? 0row[s.key] = allowNegative ? raw : Math.max(0, raw)diff --git a/products/logs/frontend/components/LogsFilterPreview/LogsFilterVolumeSparkline.stories.tsx b/products/logs/frontend/components/LogsFilterPreview/LogsFilterVolumeSparkline.stories.tsxnew file mode 100644index 000000000000..1fd82d84dd3a--- /dev/null+++ b/products/logs/frontend/components/LogsFilterPreview/LogsFilterVolumeSparkline.stories.tsx@@ -0,0 +1,99 @@+import { Meta, StoryObj } from '@storybook/react'++import { mswDecorator } from '~/mocks/browser'+import { FilterLogicalOperator, UniversalFiltersGroup } from '~/types'++import { OTHER_BREAKDOWN_VALUE } from 'products/logs/frontend/sparklineOtherBreakdown'++import { LogsFilterPreviewPoint } from './logsFilterVolumePreview'+import { LogsFilterVolumeSparkline, LogsFilterVolumeSparklineProps } from './LogsFilterVolumeSparkline'++const BUCKET_MINUTES = 30+const BUCKETS = 48+const FIRST_BUCKET = Date.parse('2026-08-04T00:00:00Z')++/** Deterministic per-service shape: a steady baseline plus one afternoon spike, so the rate-limit+ * line has something to cross. */+const SERVICE_PROFILES: { service: string; baseline: number; spike: number }[] = [+ { service: 'posthog-web', baseline: 900, spike: 3200 },+ { service: 'capture', baseline: 600, spike: 900 },+ { service: 'cdp-events-consumer', baseline: 240, spike: 240 },+ { service: OTHER_BREAKDOWN_VALUE, baseline: 180, spike: 320 },+]++function buildPoints(): LogsFilterPreviewPoint[] {+ const points: LogsFilterPreviewPoint[] = []+ for (let bucket = 0; bucket < BUCKETS; bucket++) {+ const time = new Date(FIRST_BUCKET + bucket * BUCKET_MINUTES * 60_000).toISOString()+ const spiking = bucket >= 28 && bucket <= 32+ for (const { service, baseline, spike } of SERVICE_PROFILES) {+ // A slow sine wave keeps the bars uneven without a random source.+ const wave = 1 + 0.35 * Math.sin(bucket / 4)+ const count = Math.round((spiking ? spike : baseline) * wave)+ points.push({ time, service, count, bytes_uncompressed: count * 420 })+ }+ }+ return points+}++const FILTER_GROUP: UniversalFiltersGroup = {+ type: FilterLogicalOperator.And,+ values: [{ key: 'service.name', type: 'log_resource_attribute', operator: 'exact', value: 'posthog-web' } as never],+}++const meta: Meta<LogsFilterVolumeSparklineProps> = {+ title: 'Logs/LogsFilterVolumeSparkline',+ component: LogsFilterVolumeSparkline,+ decorators: [+ mswDecorator({+ post: {+ '/api/environments/:team_id/logs/sparkline': () => [200, buildPoints()],+ },+ }),+ ],+ args: {+ filterGroup: FILTER_GROUP,+ },+ parameters: {+ layout: 'padded',+ viewMode: 'story',+ mockDate: '2026-08-05',+ // Bars paint asynchronously (ResizeObserver → rAF); chromium alone keeps the snapshot stable.+ testOptions: { snapshotBrowsers: ['chromium'], waitForSelector: 'canvas[aria-label]' },+ },+ render: (args) => (+ <div className="w-[720px]">+ <LogsFilterVolumeSparkline {...args} />+ </div>+ ),+}++export default meta++type Story = StoryObj<LogsFilterVolumeSparklineProps>++/** What the drop-rule and retention editors render: stacked volume per service, no threshold. */+export const VolumeByService: Story = {+ args: {+ previewKey: 'storybook-volume-by-service',+ metric: 'count',+ },+}++/** The rate-limit case the sampling editor renders: bytes per bucket against a per-second limit+ * projected onto the bucket width, the way `LogsSamplingForm` does it. */+export const WithRateLimitThreshold: Story = {+ args: {+ previewKey: 'storybook-volume-rate-limit',+ metric: 'bytes',+ buildGoalLines: ({ bucketSeconds }) => [+ {+ // 1 KB/s × 1000 = bytes/s, × bucket width = bytes/bucket.+ value: 1000 * bucketSeconds,+ color: 'var(--danger)',+ label: 'Rate limit (1 KB/s)',+ displayLabel: true,+ },+ ],+ },+}diff --git a/products/logs/frontend/components/LogsFilterPreview/LogsFilterVolumeSparkline.test.tsx b/products/logs/frontend/components/LogsFilterPreview/LogsFilterVolumeSparkline.test.tsxindex 58fb8ecf4bde..d1b379eaefb4 100644--- a/products/logs/frontend/components/LogsFilterPreview/LogsFilterVolumeSparkline.test.tsx+++ b/products/logs/frontend/components/LogsFilterPreview/LogsFilterVolumeSparkline.test.tsx@@ -1,19 +1,13 @@import { cleanup, render, screen, waitFor } from '@testing-library/react'+import { getHogChart, setupJsdom, setupSyncRaf } from '@posthog/quill-charts/testing'+import { useMocks } from '~/mocks/jest'import { initKeaTests } from '~/test/init'import { FilterLogicalOperator, UniversalFiltersGroup } from '~/types'import { LogsFilterVolumeSparkline } from './LogsFilterVolumeSparkline'-// The chart itself is Chart.js/quill and needs a canvas; we only care about which state the-// component decides to render and what it hands the chart.-jest.mock('lib/components/Sparkline', () => ({- Sparkline: ({ loading, data }: { loading?: boolean; data: unknown[] }) => (- <div data-attr="sparkline" data-loading={loading ? 'true' : 'false'} data-series={data.length} />- ),-}))-const EMPTY_GROUP: UniversalFiltersGroup = { type: FilterLogicalOperator.And, values: [] }const NON_EMPTY_GROUP: UniversalFiltersGroup = {type: FilterLogicalOperator.And,@@ -22,9 +16,13 @@ const NON_EMPTY_GROUP: UniversalFiltersGroup = {describe('LogsFilterVolumeSparkline', () => {let sparklineCalls: number+ let cleanupJsdom: () => void+ let cleanupRaf: () => voidbeforeEach(() => {sparklineCalls = 0+ cleanupJsdom = setupJsdom()+ cleanupRaf = setupSyncRaf()useMocks({post: {'/api/environments/:team_id/logs/sparkline/': () => {@@ -44,7 +42,11 @@ describe('LogsFilterVolumeSparkline', () => {// This suite's jest setup doesn't auto-cleanup, so unmount explicitly or `screen` queries// match leftover trees from earlier tests.- afterEach(cleanup)+ afterEach(() => {+ cleanupRaf()+ cleanupJsdom()+ cleanup()+ })it('prompts for a filter and does not query when the group is empty', async () => {render(<LogsFilterVolumeSparkline filterGroup={EMPTY_GROUP} metric="bytes" />)@@ -54,9 +56,9 @@ describe('LogsFilterVolumeSparkline', () => {})it('loads on mount for a pre-filled group and renders the chart with the total', async () => {- render(<LogsFilterVolumeSparkline filterGroup={NON_EMPTY_GROUP} metric="bytes" />)+ const { container } = render(<LogsFilterVolumeSparkline filterGroup={NON_EMPTY_GROUP} metric="bytes" />)- await waitFor(() => expect(screen.getByTestId('sparkline').dataset.loading).toEqual('false'))+ await waitFor(() => expect(getHogChart(container).seriesCount).toEqual(1))expect(sparklineCalls).toEqual(1)expect(screen.getByText('6.1 KB')).toBeTruthy()})@@ -73,7 +75,7 @@ describe('LogsFilterVolumeSparkline', () => {rerender(<LogsFilterVolumeSparkline filterGroup={{ ...NON_EMPTY_GROUP }} metric="bytes" />)- await waitFor(() => expect(screen.getByTestId('sparkline')).toBeTruthy())+ await waitFor(() => expect(screen.getByText('6.1 KB')).toBeTruthy())expect(sparklineCalls).toEqual(1)})diff --git a/products/logs/frontend/components/LogsFilterPreview/LogsFilterVolumeSparkline.tsx b/products/logs/frontend/components/LogsFilterPreview/LogsFilterVolumeSparkline.tsxindex 611f682a0017..711090ead441 100644--- a/products/logs/frontend/components/LogsFilterPreview/LogsFilterVolumeSparkline.tsx+++ b/products/logs/frontend/components/LogsFilterPreview/LogsFilterVolumeSparkline.tsx@@ -1,9 +1,14 @@import { useActions, useValues } from 'kea'import { useEffect, useId, useMemo } from 'react'-import { LemonButton } from '@posthog/lemon-ui'+import { LemonButton, LemonSkeleton } from '@posthog/lemon-ui'+import type { GoalLineConfig, Series, TimeInterval, TimeSeriesBarChartConfig } from '@posthog/quill-charts'+import { TimeSeriesBarChart } from '@posthog/quill-charts'-import { Sparkline, SparklineReferenceLine } from 'lib/components/Sparkline'+import { useChartConfig, useChartTheme } from 'lib/charts/hooks'+import { resolveVariableColor } from 'lib/charts/utils/color'+import { dayjs } from 'lib/dayjs'+import { humanFriendlyNumber } from 'lib/utils/numbers'import { UniversalFiltersGroup } from '~/types'@@ -30,11 +35,20 @@ export interface LogsFilterVolumeSparklineProps {/** Overrides the auto-generated logic key; only needed by stories and tests. */previewKey?: string/** Threshold lines in the chart's own units, which depend on the resolved bucket width. */- buildReferenceLines?: (info: LogsFilterVolumeSparklineRenderInfo) => SparklineReferenceLine[] | undefined+ buildGoalLines?: (info: LogsFilterVolumeSparklineRenderInfo) => GoalLineConfig[] | undefined/** Rendered under the chart once data has loaded (rate-limit note, retention projection). */renderCaption?: (info: LogsFilterVolumeSparklineRenderInfo) => JSX.Element | null}+/** Granularity of the date ticks and the tooltip header. The backend picks the bucket width from+ * the queried range, so read it off the data rather than assuming half-hour buckets. */+function bucketInterval(bucketSeconds: number): TimeInterval {+ if (bucketSeconds >= 86400) {+ return 'day'+ }+ return bucketSeconds >= 3600 ? 'hour' : 'minute'+}+/*** Live preview of the log volume a filter group matches over the last 24h, broken down by service.* Shared by the drop-rule and retention-rule editors — one request serves both metrics, since each@@ -44,13 +58,14 @@ export function LogsFilterVolumeSparkline({filterGroup,metric,previewKey,- buildReferenceLines,+ buildGoalLines,renderCaption,}: LogsFilterVolumeSparklineProps): JSX.Element {const generatedKey = useId()const logic = logsFilterVolumePreviewLogic({ previewKey: previewKey ?? generatedKey })const { filterPreview, filterPreviewLoading } = useValues(logic)const { setPreviewRequest, refreshFilterPreview } = useActions(logic)+ const theme = useChartTheme()const hasFilters = filterGroup.values.length > 0@@ -76,9 +91,40 @@ export function LogsFilterVolumeSparkline({const formattedTotal =metric === 'bytes' ? formatBytes(seriesData.total) : `${seriesData.total.toLocaleString()} logs`- const referenceLines = buildReferenceLines?.(renderInfo)+ const goalLines = buildGoalLines?.(renderInfo)const caption = filterPreview && !filterPreviewLoading ? renderCaption?.(renderInfo) : null+ // A bar fill is painted on canvas, which can't resolve a CSS variable.+ const series = useMemo<Series[]>(+ () => seriesData.series.map((s) => (s.color ? { ...s, color: resolveVariableColor(s.color) } : s)),+ [seriesData.series]+ )+ const formatValue = metric === 'bytes' ? formatBytes : humanFriendlyNumber+ const config = useChartConfig<TimeSeriesBarChartConfig>(+ () => ({+ // Bucket timestamps carry an offset, and the settings pages around this preview read in+ // the viewer's own time.+ xAxis: { timezone: dayjs.tz.guess(), interval: bucketInterval(seriesData.bucketSeconds) },+ // Value ticks would only cost plot height here, because the header prints the total, a+ // goal line carries its own value, and the tooltip gives exact per-service numbers.+ // Hiding is label-only, so a goal line above the peak still stretches the domain.+ yAxis: { hide: true, showGrid: false },+ // Drawn by default on both edges, but the left one would frame an axis nothing labels.+ showAxisLines: { y: false },+ goalLines,+ barCornerRadius: 2,+ showCrosshair: false,+ // Up to 11 rows (top services plus "Others") overflow the tooltip's max height, so it+ // has to be pinnable for the pointer to reach it and scroll. `valueFormatter` is+ // wrapped because both formatters take a second optional argument that quill would+ // fill with the hovered entry.+ tooltip: { pinnable: true, valueFormatter: (value: number) => formatValue(value), showTotal: true },+ }),+ // `buildGoalLines` hands back a fresh array every render, so the dep is its content — an+ // unrelated re-render of the form around us shouldn't rebuild the chart's config.+ [seriesData.bucketSeconds, JSON.stringify(goalLines ?? null), formatValue]+ )+return (<div className="mt-3 flex flex-col gap-1"><div className="flex items-center justify-between text-xs text-muted">@@ -88,13 +134,14 @@ export function LogsFilterVolumeSparkline({</span>{hasFilters && !filterPreviewLoading ? <span>{formattedTotal}</span> : null}</div>- <div className="relative h-24 border border-border rounded-md bg-bg-light px-2 py-1">+ {/* Quill charts fill a *flex* parent (their root is flex-1), so the sized box is a flex column. */}+ <div className="relative h-32 flex flex-col border border-border rounded-md bg-bg-light px-2 py-1">{!hasFilters ? (<div className="h-full flex items-center justify-center text-muted text-xs">Add a filter above to preview matching log volume</div>) : filterPreviewLoading ? (- <Sparkline data={[]} labels={[]} loading className="w-full h-full" maximumIndicator={false} />+ <LemonSkeleton className="w-full h-full" />) : !filterPreview ? (<div className="h-full flex flex-col gap-1 items-center justify-center text-muted text-xs"><span>Couldn't load the volume preview.</span>@@ -102,21 +149,17 @@ export function LogsFilterVolumeSparkline({Retry</LemonButton></div>- ) : seriesData.series.length === 0 ? (+ ) : series.length === 0 ? (<div className="h-full flex items-center justify-center text-muted text-xs">No logs match these filters in the last 24h</div>) : (- <Sparkline- data={seriesData.series}+ <TimeSeriesBarChart+ series={series}labels={seriesData.labels}- className="w-full h-full"- maximumIndicator={false}- referenceLines={referenceLines}- renderTooltipValue={metric === 'bytes' ? formatBytes : undefined}- // Up to 11 rows (top services plus "Others") overflows the tooltip's max- // height, so the pointer has to be able to reach it to scroll.- interactiveTooltip+ theme={theme}+ config={config}+ dataAttr="logs-filter-volume-preview"/>)}</div>diff --git a/products/logs/frontend/components/LogsFilterPreview/logsFilterVolumePreview.test.ts b/products/logs/frontend/components/LogsFilterPreview/logsFilterVolumePreview.test.tsindex d08c42da0096..6bf18885af86 100644--- a/products/logs/frontend/components/LogsFilterPreview/logsFilterVolumePreview.test.ts+++ b/products/logs/frontend/components/LogsFilterPreview/logsFilterVolumePreview.test.ts@@ -5,6 +5,7 @@ import { OTHER_BREAKDOWN_LABEL, OTHER_BREAKDOWN_VALUE } from 'products/logs/fronimport {LogsFilterPreviewPoint,+ OTHER_BREAKDOWN_COLOR,TOP_SERVICES_LIMIT,buildSparklineSeries,formatBytes,@@ -47,9 +48,12 @@ describe('buildSparklineSeries', () => {const data = buildSparklineSeries([point(T1, 'api', 3), point(T1, 'worker', 1), point(T2, 'api', 5)], 'count')expect(data.series).toEqual([- expect.objectContaining({ name: 'api', values: [3, 5] }),- expect.objectContaining({ name: 'worker', values: [1, 0] }),+ expect.objectContaining({ label: 'api', data: [3, 5] }),+ expect.objectContaining({ label: 'worker', data: [1, 0] }),])+ // Raw bucket times, not display strings: the chart's time axis needs unique ISO labels to+ // format ticks and the tooltip header itself.+ expect(data.labels).toEqual([T1, T2])expect(data.total).toEqual(9)expect(data.chartMax).toEqual(5)expect(data.bucketSeconds).toEqual(1800)@@ -64,8 +68,8 @@ describe('buildSparklineSeries', () => {const data = buildSparklineSeries(points, 'count')expect(data.series).toHaveLength(13)- expect(data.series.map((s) => s.name)).toEqual(Array.from({ length: 13 }, (_, i) => `svc-${i}`))- expect(data.series.reduce((sum, s) => sum + s.values[0], 0)).toEqual(data.total)+ expect(data.series.map((s) => s.label)).toEqual(Array.from({ length: 13 }, (_, i) => `svc-${i}`))+ expect(data.series.reduce((sum, s) => sum + s.data[0], 0)).toEqual(data.total)})it('labels the collapsed bucket and pins it last even when it outweighs every service', () => {@@ -78,9 +82,9 @@ describe('buildSparklineSeries', () => {const data = buildSparklineSeries(points, 'count')- expect(data.series.map((s) => s.name)).toEqual(['api', OTHER_BREAKDOWN_LABEL])+ expect(data.series.map((s) => s.label)).toEqual(['api', OTHER_BREAKDOWN_LABEL])expect(data.series[1]).toEqual(- expect.objectContaining({ name: OTHER_BREAKDOWN_LABEL, color: 'muted', values: [900, 900] })+ expect.objectContaining({ label: OTHER_BREAKDOWN_LABEL, color: OTHER_BREAKDOWN_COLOR, data: [900, 900] }))expect(data.total).toEqual(1810)})@@ -99,13 +103,13 @@ describe('buildSparklineSeries', () => {// resolve to inherited values instead of a bucket and throw on `.set`.const data = buildSparklineSeries([point(T1, service, 2), point(T2, service, 3)], 'count')- expect(data.series).toEqual([expect.objectContaining({ name: service, values: [2, 3] })])+ expect(data.series).toEqual([expect.objectContaining({ label: service, data: [2, 3] })])expect(data.total).toEqual(5)})it('labels a blank service as unknown', () => {- expect(buildSparklineSeries([point(T1, '', 1)], 'count').series[0].name).toEqual('unknown')+ expect(buildSparklineSeries([point(T1, '', 1)], 'count').series[0].label).toEqual('unknown')})it('returns an empty shape for no data', () => {diff --git a/products/logs/frontend/components/LogsFilterPreview/logsFilterVolumePreview.ts b/products/logs/frontend/components/LogsFilterPreview/logsFilterVolumePreview.tsindex 4c4387a8fd99..bec9f436ff92 100644--- a/products/logs/frontend/components/LogsFilterPreview/logsFilterVolumePreview.ts+++ b/products/logs/frontend/components/LogsFilterPreview/logsFilterVolumePreview.ts@@ -1,5 +1,5 @@-import { dataColorVars } from 'lib/colors'-import { SparklineTimeSeries } from 'lib/components/Sparkline'+import type { Series } from '@posthog/quill-charts'+import { dayjs } from 'lib/dayjs'import { OTHER_BREAKDOWN_LABEL, OTHER_BREAKDOWN_VALUE } from 'products/logs/frontend/sparklineOtherBreakdown'@@ -25,9 +25,14 @@ export interface LogsFilterPreviewPoint {bytes_uncompressed?: number}+/** The collapsed "Others" row reads as an aggregate rather than as another service. Resolved to a+ * canvas-usable color by the chart — a bar fill can't take `var(--…)`. */+export const OTHER_BREAKDOWN_COLOR = 'var(--muted)'+export interface LogsFilterPreviewSeriesData {+ /** Raw bucket timestamps, one per bar. The chart's time axis formats them for display. */labels: string[]- series: SparklineTimeSeries[]+ series: Series[]total: number/** Width of one bar/bucket in seconds; needed to translate a per-second rate limit into per-bucket units. */bucketSeconds: number@@ -69,31 +74,32 @@ export function buildSparklineSeries(bucketTotals.set(point.time, (bucketTotals.get(point.time) ?? 0) + value)total += value}- const labels = timeOrder.map((t) => dayjs(t).format('D MMM HH:mm'))// Sorted by volume so colours track the biggest talkers, but deliberately not sliced: the// backend already folded everything past the top N into one bucket, ranked by this same metric.// Slicing again here would re-collapse the collapsed row and label it as a single service.const ranked = Array.from(serviceTotals.entries()).sort(([, a], [, b]) => b - a)const valuesFor = (service: string): number[] => timeOrder.map((t) => byService.get(service)?.get(t) ?? 0)- const series: SparklineTimeSeries[] = ranked+ // No explicit colour: the chart assigns the data palette by series index, which is what the+ // volume ranking above is for.+ const series: Series[] = ranked.filter(([service]) => service !== OTHER_BREAKDOWN_VALUE)- .map(([service], index) => ({- name: service,- color: dataColorVars[index % dataColorVars.length],- values: valuesFor(service),+ .map(([service]) => ({+ key: service,+ label: service,+ data: valuesFor(service),}))if (serviceTotals.has(OTHER_BREAKDOWN_VALUE)) {- // Last and muted, so it reads as an aggregate rather than as another service.series.push({- name: OTHER_BREAKDOWN_LABEL,- color: 'muted',- values: valuesFor(OTHER_BREAKDOWN_VALUE),+ key: OTHER_BREAKDOWN_VALUE,+ label: OTHER_BREAKDOWN_LABEL,+ color: OTHER_BREAKDOWN_COLOR,+ data: valuesFor(OTHER_BREAKDOWN_VALUE),})}const bucketSeconds = timeOrder.length >= 2 ? dayjs(timeOrder[1]).diff(dayjs(timeOrder[0]), 'second') : 0const chartMax = Math.max(0, ...Array.from(bucketTotals.values()))return {- labels,+ labels: timeOrder,series,total,bucketSeconds,diff --git a/products/logs/frontend/components/LogsSampling/LogsSamplingForm.tsx b/products/logs/frontend/components/LogsSampling/LogsSamplingForm.tsxindex b5aad88d1b48..8a8493d3f330 100644--- a/products/logs/frontend/components/LogsSampling/LogsSamplingForm.tsx+++ b/products/logs/frontend/components/LogsSampling/LogsSamplingForm.tsx@@ -109,7 +109,7 @@ export function LogsSamplingForm(): JSX.Element {<LogsFilterVolumeSparklinefilterGroup={samplingForm.filter_group}metric={isRateLimit ? 'bytes' : 'count'}- buildReferenceLines={({ bucketSeconds }) => {+ buildGoalLines={({ bucketSeconds }) => {const threshold = rateLimitThresholdPerBucket(bucketSeconds)if (threshold == null) {return undefined@@ -117,11 +117,11 @@ export function LogsSamplingForm(): JSX.Element {return [{value: threshold,- color: 'danger',+ color: 'var(--danger)',label: `Rate limit (${samplingForm.rate_limit_amount.trim()} ${samplingForm.rate_limit_unit})`,- labelPosition: 'end',+ displayLabel: true,},]}}