Compare commits

...

1 Commits

Author SHA1 Message Date
srikanthccv
967e522fa1 fix(logs): start explorer frequency chart Y-axis at zero
The regression test is an e2e test. The jest setup maps uplot to a mock
that has no range calculation.

Co-authored-by: Christopher Demicoli <christopher.demicoli@outlook.com>
Assisted-by: Claude Fable 5.2
2026-11-20 05:09:37 +05:30
5 changed files with 85 additions and 2 deletions

View File

@@ -64,6 +64,7 @@ export function useLogsExplorerChartConfig({
maxTimeScale,
yAxisUnit,
panelType: PANEL_TYPES.BAR,
softMin: 0,
});
data.forEach((series, index) => {

View File

@@ -3,6 +3,7 @@ import { expect, type Locator, type Page } from '@playwright/test';
import { antdDriver } from '../antd';
import { allowFor, SEEDED_DATA_TIMEOUT, SEEDED_TEST_BUDGET } from '../kit';
import { chartAt, type Chart } from '../panels/chart';
import {
expressionParams,
querySearchDriver,
@@ -14,7 +15,7 @@ import { timePickerDriver, type TimePicker } from '../timepicker';
import { logDetailDriver, type LogDetail } from './detail';
import { liveTailDriver, type LiveTail } from './liveTail';
import { ROW_SELECTOR } from './rows';
import { seedOne } from './seed';
import { seedBursts, seedOne } from './seed';
import { wheelTo } from '../scroll';
export const LOGS_EXPLORER_PATH = '/logs/logs-explorer';
@@ -25,6 +26,7 @@ const FORMAT_OPTIONS = 'periscope-btn-format-options';
const ROW_PREFIX = 'logs-table-row-';
const LOG_DETAIL_DRAWER = 'log-detail-drawer';
const LIST = 'logs-list-virtuoso';
const FREQUENCY_CHART = 'logs-frequency-chart';
const RUN_QUERY = 'explorer-run-query-btn';
const ANNOUNCEMENT_DISMISSED_KEY = 'QUICK_FILTERS_SETTINGS_ANNOUNCEMENT';
const RELOAD_BUDGET_MS = 60_000;
@@ -101,6 +103,8 @@ export interface LogsExplorer {
timeSeriesCanvas(): Locator;
timeSeriesHeader(): Locator;
frequencyChart(): Locator;
/** The frequency chart's live plot: the counts it draws and its scales. */
frequency: Chart;
/** Turn the frequency chart on. It is off until a viewer enables it. */
showFrequencyChart(): Promise<void>;
queryTable(): Locator;
@@ -123,6 +127,11 @@ export interface LogsExplorer {
copyRowLink(row: Locator): Promise<string>;
/** Seed one row under `service`, `offsetMs` from now. */
seedRow(service: string, body: string, offsetMs?: number): Promise<void>;
/**
* Seed `counts[i]` rows under `service` into a frequency chart bucket of
* their own, oldest first.
*/
seedBursts(service: string, body: string, counts: number[]): Promise<void>;
toast(text: string): Locator;
reload(): Promise<void>;
/** Open `url` in a new tab of the same context. */
@@ -261,7 +270,8 @@ export function logsExplorerDriver(page: Page): LogsExplorer {
timeSeriesCanvas: () =>
page.getByTestId('time-series-graph').locator('canvas').first(),
timeSeriesHeader: () => page.getByTestId('time-series-view-header'),
frequencyChart: () => page.getByTestId('logs-frequency-chart'),
frequencyChart: () => page.getByTestId(FREQUENCY_CHART),
frequency: chartAt(page, () => page.getByTestId(FREQUENCY_CHART)),
showFrequencyChart: async () => {
const toggle = page.getByTestId('logs-frequency-chart-toggle');
if ((await toggle.getAttribute('aria-checked')) !== 'true') {
@@ -356,6 +366,9 @@ export function logsExplorerDriver(page: Page): LogsExplorer {
seedRow: (service, body, offsetMs = 0) =>
seedOne(page.request, service, body, offsetMs),
seedBursts: (service, body, counts) =>
seedBursts(page.request, service, body, counts),
toast: (text) => page.getByText(text, { exact: true }),
reload: async () => {

View File

@@ -117,6 +117,34 @@ export async function seedOne(
]);
}
// The chart step is a 300th of the window, so this gap is wider than the step
// of any window up to a day.
const BURST_GAP_MS = 5 * 60_000;
/**
* `counts[i]` rows under `service` per burst, oldest burst first. The rows of a
* burst share one timestamp, so they fall in one chart bucket, and the bursts
* sit `BURST_GAP_MS` apart, so no two share a bucket.
*/
export async function seedBursts(
request: APIRequestContext,
service: string,
body: string,
counts: number[],
): Promise<void> {
const now = Date.now();
await seedLogs(
request,
counts.flatMap((count, burst) =>
Array.from({ length: count }, () => ({
timestamp: iso(now - (counts.length - burst) * BURST_GAP_MS),
body,
resources: resources(service),
})),
),
);
}
export const withLogsSeed: WorkerLayer<{ logsSeed: LogsSeed }> = seeded(
'logsSeed',
async ({ page, workerIndex }) =>

View File

@@ -20,6 +20,11 @@ export interface Chart {
plotArea(): Locator;
/** Throws when there is no plot, usually because the panel shows No Data. */
scales(): Promise<Record<string, UPlotScaleState>>;
/**
* One array per series, as plotted: cumulative when the chart stacks. Throws
* when there is no plot.
*/
values(): Promise<(number | null)[][]>;
click(): Promise<void>;
/**
* Clicks the first series' middle data point inside the visible window,
@@ -53,6 +58,18 @@ export function chartAt(page: Page, host: () => Locator): Chart {
);
});
},
async values() {
await expect(host()).toBeVisible();
return host().evaluate((node) => {
const plot = (node as { __uplot?: unknown }).__uplot as
| { data: [number[], ...(number | null)[][]] }
| undefined;
if (!plot) {
throw new Error('no uPlot instance on the chart container');
}
return plot.data.slice(1).map((series) => Array.from(series));
});
},
async click() {
const box = await boxOf(host(), 'the chart');
await page.mouse.click(box.x + box.width / 2, box.y + box.height / 2);

View File

@@ -0,0 +1,24 @@
import { expect, serviceFilter, sideService, test } from '../../drivers/logs';
// The counts must differ: uPlot ranges equal counts from zero on its own, and
// the axis can then never start above zero.
const BURSTS = [2, 5];
test.describe('Logs Explorer — frequency chart', () => {
test('TC-01 the Y axis starts at zero when every bucket has logs', async ({
logs,
logsSeed,
}) => {
const service = sideService(logsSeed, `freq-${Date.now()}`);
const body = `${service} burst`;
await logs.seedBursts(service, body, BURSTS);
await logs.gotoUntil(body, { expression: serviceFilter(service) });
await logs.showFrequencyChart();
await expect.poll(() => logs.frequency.values()).toEqual([BURSTS]);
const { y } = await logs.frequency.scales();
expect(y.min).toBe(0);
expect(y.max).toBeGreaterThanOrEqual(Math.max(...BURSTS));
});
});