diff --git a/.changeset/promql-heatmap.md b/.changeset/promql-heatmap.md new file mode 100644 index 0000000000..74c5acd713 --- /dev/null +++ b/.changeset/promql-heatmap.md @@ -0,0 +1,5 @@ +--- +'@hyperdx/app': minor +--- + +feat: Support PromQL heatmaps (series-mode) diff --git a/packages/app/src/DBDashboardPage.tsx b/packages/app/src/DBDashboardPage.tsx index fe2aa54018..40520a3e07 100644 --- a/packages/app/src/DBDashboardPage.tsx +++ b/packages/app/src/DBDashboardPage.tsx @@ -39,6 +39,7 @@ import { displayTypeRequiresSource, isBuilderChartConfig, isBuilderSavedChartConfig, + isPromqlChartConfig, isPromqlSavedChartConfig, isRawSqlChartConfig, isRawSqlSavedChartConfig, @@ -50,7 +51,6 @@ import { import { isMissingFiltersMacro } from '@hyperdx/common-utils/dist/macros'; import { AlertState, - BuilderChartConfigWithDateRange, ChartConfigWithDateRange, ChartVariable, DashboardContainer as DashboardContainerSchema, @@ -177,7 +177,10 @@ import ChartContainer, { } from './components/charts/ChartContainer'; import DashboardFiltersModal from './components/DashboardFiltersModal'; import { DBBarChart } from './components/DBBarChart'; -import DBHeatmapChart, { toHeatmapQuery } from './components/DBHeatmapChart'; +import DBHeatmapChart, { + HeatmapSeriesChartConfig, + toHeatmapQuery, +} from './components/DBHeatmapChart'; import { DBPieChart } from './components/DBPieChart'; import DBSqlRowTableWithSideBar from './components/DBSqlRowTableWithSidebar'; import OnboardingModal from './components/OnboardingModal'; @@ -244,7 +247,7 @@ function HeatmapTile({ title: React.ReactNode; toolbarPrefix: React.ReactNode[]; toolbarSuffix: React.ReactNode[]; - queriedConfig: BuilderChartConfigWithDateRange; + queriedConfig: HeatmapSeriesChartConfig; source: TSource | undefined; dateRange: [Date, Date]; enabled?: boolean; @@ -262,7 +265,12 @@ function HeatmapTile({ const eventDeltasUrl = useMemo(() => { // Search page event deltas only supports trace sources and distribution mode - if (!source || !isTraceSource(source) || mode !== 'distribution') + if ( + !source || + !isTraceSource(source) || + mode !== 'distribution' || + !isBuilderChartConfig(queriedConfig) + ) return null; const url = buildEventsSearchUrl({ source, @@ -1383,7 +1391,8 @@ const Tile = ({ /> )} {effectiveQueriedConfig?.displayType === DisplayType.Heatmap && - isBuilderChartConfig(effectiveQueriedConfig) && ( + (isBuilderChartConfig(effectiveQueriedConfig) || + isPromqlChartConfig(effectiveQueriedConfig)) && ( { series: [], }); + it('saves a heatmap with only its first expression queried and no heatmap mode', () => { + const result = convertFormStateToSavedChartConfig( + { + ...promqlForm([{ expression: 'up' }], DisplayType.Heatmap), + legendTemplate: '{{pod}}', + heatmap: { mode: 'distribution' }, + granularity: '5 minute', + }, + undefined, + ); + expect(result).toMatchObject({ + configType: 'promql', + displayType: DisplayType.Heatmap, + promqlExpression: [{ expression: 'up' }], + legendTemplate: '{{pod}}', + granularity: '5 minute', + }); + expect(result).not.toHaveProperty('heatmap'); + }); + it('saves the form rows as the expression list', () => { expect( convertFormStateToSavedChartConfig( @@ -1841,6 +1870,21 @@ describe('validateChartForm', () => { expect(errors).toContainEqual(expect.objectContaining({ path: 'series' })); }); + it('does not require a value expression on a PromQL heatmap', () => { + const errors = validateChartForm( + makeForm({ + configType: 'promql', + displayType: DisplayType.Heatmap, + source: 'source-promql', + promqlExpressions: [{ expression: 'up' }], + series: [{ ...seriesItem, valueExpression: '' }], + }), + promqlSource, + jest.fn(), + ); + expect(errors).toHaveLength(0); + }); + it('rejects heatmap chart without a value expression', () => { const setError = jest.fn(); const errors = validateChartForm( @@ -2407,12 +2451,22 @@ describe('getAllowedSourceKinds', () => { }, ); - it('narrows to traces on heatmap tiles', () => { + it('narrows to traces on builder heatmap tiles', () => { expect( getAllowedSourceKinds({ - configType: 'promql', + configType: 'builder', displayType: DisplayType.Heatmap, }), ).toEqual([SourceKind.Trace]); }); + + it('offers only PromQL sources on PromQL heatmap tiles', () => { + expect( + getAllowedSourceKinds({ + configType: 'promql', + displayType: DisplayType.Heatmap, + heatmapMode: 'distribution', + }), + ).toEqual([SourceKind.Promql]); + }); }); diff --git a/packages/app/src/components/ChartEditor/utils.ts b/packages/app/src/components/ChartEditor/utils.ts index 9d26e1e050..0709cf6974 100644 --- a/packages/app/src/components/ChartEditor/utils.ts +++ b/packages/app/src/components/ChartEditor/utils.ts @@ -187,7 +187,25 @@ export const isStringSelectDisplayType = ( displayType === DisplayType.Search || displayType === DisplayType.EventPatterns; -export const isPromqlDisplayType = isRawSqlDisplayType; +export const isPromqlDisplayType = ( + displayType: DisplayType | undefined, +): displayType is + | DisplayType.Table + | DisplayType.Line + | DisplayType.StackedBar + | DisplayType.StackedLine + | DisplayType.Pie + | DisplayType.Bar + | DisplayType.Number + | DisplayType.Heatmap => + displayType === DisplayType.Table || + displayType === DisplayType.Line || + displayType === DisplayType.StackedBar || + displayType === DisplayType.StackedLine || + displayType === DisplayType.Pie || + displayType === DisplayType.Bar || + displayType === DisplayType.Number || + displayType === DisplayType.Heatmap; const NON_PROMQL_SOURCE_KINDS = Object.values(SourceKind).filter( kind => kind !== SourceKind.Promql, @@ -553,6 +571,8 @@ export const validateChartForm = ( const isRawSqlChart = form.configType === 'sql' && isRawSqlDisplayType(form.displayType); + const isPromqlChart = + form.configType === 'promql' && isPromqlDisplayType(form.displayType); // Validate connection is selected for raw SQL charts if (isRawSqlChart && !form.connection) { @@ -731,6 +751,7 @@ export const validateChartForm = ( // validated like any other builder series above. if ( !isRawSqlChart && + !isPromqlChart && form.displayType === DisplayType.Heatmap && getHeatmapMode(form) === 'distribution' && Array.isArray(form.series) && diff --git a/packages/app/src/components/DBEditTimeChartForm/ChartPreviewPanel.tsx b/packages/app/src/components/DBEditTimeChartForm/ChartPreviewPanel.tsx index 66e06af4c5..d6ead0b592 100644 --- a/packages/app/src/components/DBEditTimeChartForm/ChartPreviewPanel.tsx +++ b/packages/app/src/components/DBEditTimeChartForm/ChartPreviewPanel.tsx @@ -1,5 +1,8 @@ import { useCallback, useMemo, useState } from 'react'; -import { isBuilderChartConfig } from '@hyperdx/common-utils/dist/guards'; +import { + isBuilderChartConfig, + isPromqlChartConfig, +} from '@hyperdx/common-utils/dist/guards'; import { BuilderChartConfigWithDateRange, BuilderChartConfigWithOptTimestamp, @@ -26,6 +29,7 @@ import DBHeatmapChart, { buildHeatmapBucketConfig, buildHeatmapSeriesConfig, HEATMAP_N_BUCKETS, + HeatmapSeriesChartConfig, resolveHeatmapGranularity, toHeatmapQuery, } from '@/components/DBHeatmapChart'; @@ -64,7 +68,7 @@ function HeatmapPreview({ config, minGranularitySeconds, }: { - config: BuilderChartConfigWithDateRange; + config: HeatmapSeriesChartConfig; minGranularitySeconds: number | undefined; }) { return ( @@ -344,7 +348,8 @@ export function ChartPreviewPanel({ )} {queryReady && queriedConfig != null && - isBuilderChartConfig(queriedConfig) && + (isBuilderChartConfig(queriedConfig) || + isPromqlChartConfig(queriedConfig)) && activeTab === 'heatmap' && ( [ + { label: 'Builder', value: 'builder' }, + ...(isRawSqlDisplayType(displayType) + ? [{ label: 'SQL', value: 'sql' }] + : []), + ...(IS_PROMQL_ENABLED && isPromqlDisplayType(displayType) + ? [{ label: 'PromQL', value: 'promql' }] + : []), + ], + [displayType], + ); + return (
@@ -1093,21 +1111,19 @@ export default function EditTimeChartForm({ placeholder="My Chart Name" data-testid="chart-name-input" /> - {isRawSqlDisplayType(displayType) && ( + {configTypeOptions.length > 1 && ( ( option.value === value) + ? value + : 'builder' + } onChange={onChange} - data={[ - { label: 'Builder', value: 'builder' }, - { label: 'SQL', value: 'sql' }, - ...(IS_PROMQL_ENABLED - ? [{ label: 'PromQL', value: 'promql' }] - : []), - ]} + data={configTypeOptions} /> )} /> diff --git a/packages/app/src/components/DBEditTimeChartForm/__tests__/utils.test.ts b/packages/app/src/components/DBEditTimeChartForm/__tests__/utils.test.ts index d10df4f89f..55c9a14a9b 100644 --- a/packages/app/src/components/DBEditTimeChartForm/__tests__/utils.test.ts +++ b/packages/app/src/components/DBEditTimeChartForm/__tests__/utils.test.ts @@ -327,6 +327,18 @@ describe('buildRenderedPromqlExpression', () => { ); }); + it("expands macros with a heatmap's finer auto granularity", () => { + expect( + buildRenderedPromqlExpression( + promqlConfig({ + displayType: DisplayType.Heatmap, + granularity: 'auto', + promqlExpression: [{ expression: 'rate(up[$__interval])' }], + }), + )?.expressions?.[0].expression, + ).toBe('rate(up[900s])'); + }); + it('expands macros with the granularity a table queries with', () => { const seventyMinutes: [Date, Date] = [ new Date('2024-01-01T00:00:00Z'), diff --git a/packages/app/src/components/DBEditTimeChartForm/utils.ts b/packages/app/src/components/DBEditTimeChartForm/utils.ts index 34ed6a2206..785ad572f9 100644 --- a/packages/app/src/components/DBEditTimeChartForm/utils.ts +++ b/packages/app/src/components/DBEditTimeChartForm/utils.ts @@ -48,6 +48,10 @@ import { tryExpandConfigVariables, } from '@/ChartUtils'; import { ChartEditorFormState } from '@/components/ChartEditor/types'; +import { + buildHeatmapSeriesConfig, + resolveHeatmapGranularity, +} from '@/components/DBHeatmapChart/heatmapQueries'; import { getMinGranularitySeconds } from '@/hooks/useChartConfig'; import { getFirstTimestampValueExpression } from '@/source'; import { getMetricTableName } from '@/utils'; @@ -287,6 +291,13 @@ function toQueriedPromqlConfig( const converted = convertToTimeChartConfig(config); return isPromqlChartConfig(converted) ? converted : config; } + if (config.displayType === DisplayType.Heatmap) { + const converted = buildHeatmapSeriesConfig( + config, + resolveHeatmapGranularity(config), + ); + return isPromqlChartConfig(converted) ? converted : config; + } return config; } diff --git a/packages/app/src/components/DBHeatmapChart/__tests__/heatmapQueries.test.ts b/packages/app/src/components/DBHeatmapChart/__tests__/heatmapQueries.test.ts index c3891ac9f0..42e0903e9e 100644 --- a/packages/app/src/components/DBHeatmapChart/__tests__/heatmapQueries.test.ts +++ b/packages/app/src/components/DBHeatmapChart/__tests__/heatmapQueries.test.ts @@ -1,9 +1,11 @@ import { BuilderChartConfigWithDateRange, DisplayType, + PromqlConfigWithDateRange, } from '@hyperdx/common-utils/dist/types'; import { + buildHeatmapSeriesConfig, resolveHeatmapGranularity, toHeatmapQuery, } from '@/components/DBHeatmapChart/heatmapQueries'; @@ -62,3 +64,29 @@ describe('toHeatmapQuery', () => { }, ); }); + +describe('PromQL heatmaps', () => { + const config: PromqlConfigWithDateRange = { + configType: 'promql', + displayType: DisplayType.Heatmap, + promqlExpression: [{ expression: 'up' }, { expression: 'down' }], + connection: 'test-connection', + dateRange: [new Date(T0 + 90_000), new Date(T0 + HOUR + 90_000)], + granularity: '5 minute', + legendTemplate: '{{job}}', + }; + + it('are always series heatmaps', () => { + expect(toHeatmapQuery(config)).toEqual({ mode: 'series', config }); + }); + + it('query at the heatmap granularity over a bucket-aligned range', () => { + expect(buildHeatmapSeriesConfig(config, '5 minute')).toMatchObject({ + configType: 'promql', + promqlExpression: config.promqlExpression, + legendTemplate: '{{job}}', + granularity: '5 minute', + dateRange: [new Date(T0), new Date(T0 + HOUR + 5 * 60_000)], + }); + }); +}); diff --git a/packages/app/src/components/DBHeatmapChart/__tests__/useSeriesHeatmapData.test.ts b/packages/app/src/components/DBHeatmapChart/__tests__/useSeriesHeatmapData.test.ts index 53c32da3f1..9a810da34f 100644 --- a/packages/app/src/components/DBHeatmapChart/__tests__/useSeriesHeatmapData.test.ts +++ b/packages/app/src/components/DBHeatmapChart/__tests__/useSeriesHeatmapData.test.ts @@ -1,6 +1,8 @@ +import { ResponseJSON } from '@hyperdx/common-utils/dist/clickhouse'; import { BuilderChartConfigWithDateRange, DisplayType, + PromqlConfigWithDateRange, } from '@hyperdx/common-utils/dist/types'; import { renderHook } from '@testing-library/react'; @@ -53,7 +55,12 @@ const seriesResponse = { ], }; -function mockSeriesQuery(response = seriesResponse) { +function mockSeriesQuery( + response: Pick< + ResponseJSON>, + 'meta' | 'data' + > = seriesResponse, +) { mockUseQueriedChartConfig.mockImplementation((_config, options) => options?.queryKey?.[0] === 'heatmap_series' ? { @@ -185,4 +192,43 @@ describe('useSeriesHeatmapData', () => { expect(result.current.error).toBeInstanceOf(Error); }); + + it('builds one row per PromQL series', () => { + mockSeriesQuery({ + meta: [ + { name: '__hdx_time_bucket', type: 'DateTime64(3)' }, + { name: 'value', type: 'Float64' }, + { name: 'series_name', type: 'String' }, + ], + data: [ + { + __hdx_time_bucket: new Date(T0).toISOString(), + value: 0.5, + series_name: 'pod-2', + }, + { + __hdx_time_bucket: new Date(T0).toISOString(), + value: 1.5, + series_name: 'pod-10', + }, + ], + }); + const promqlConfig: PromqlConfigWithDateRange = { + configType: 'promql', + displayType: DisplayType.Heatmap, + promqlExpression: [{ expression: 'up' }], + connection: 'test-connection', + dateRange, + granularity: 'auto', + }; + const { result } = renderHook(() => + useSeriesHeatmapData({ config: promqlConfig, enabled: true }), + ); + + expect(result.current.view.grid.yAxis).toEqual({ + type: 'series', + labels: ['pod-10', 'pod-2'], + }); + expect(result.current.view.grid.cells.slice(0, 2)).toEqual([1.5, 0.5]); + }); }); diff --git a/packages/app/src/components/DBHeatmapChart/heatmapQueries.ts b/packages/app/src/components/DBHeatmapChart/heatmapQueries.ts index 74c12f44fe..1a7a114e39 100644 --- a/packages/app/src/components/DBHeatmapChart/heatmapQueries.ts +++ b/packages/app/src/components/DBHeatmapChart/heatmapQueries.ts @@ -1,9 +1,14 @@ import { getHeatmapMode } from '@hyperdx/common-utils/dist/core/heatmap'; import { getAlignedDateRange } from '@hyperdx/common-utils/dist/core/utils'; +import { + isBuilderChartConfig, + isPromqlChartConfig, +} from '@hyperdx/common-utils/dist/guards'; import { BuilderChartConfigWithDateRange, ChartConfigWithDateRange, DisplayType, + PromqlConfigWithDateRange, SQLInterval, } from '@hyperdx/common-utils/dist/types'; @@ -36,10 +41,15 @@ export type HeatmapChartConfig = { with?: BuilderChartConfigWithDateRange['with']; }; +/** The configs a series-mode heatmap can query. */ +export type HeatmapSeriesChartConfig = + | BuilderChartConfigWithDateRange + | PromqlConfigWithDateRange; + /** * What a heatmap queries, by mode. Distribution heatmaps bucket a value - * expression server-side; series heatmaps query one builder series per time - * bucket and draw a row per series. + * expression server-side; series heatmaps query one builder series or PromQL + * expression per time bucket and draw a row per series. */ export type HeatmapQuery = | { @@ -49,7 +59,7 @@ export type HeatmapQuery = } | { mode: 'series'; - config: BuilderChartConfigWithDateRange; + config: HeatmapSeriesChartConfig; }; const HEATMAP_AUTO_GRANULARITY_BUCKETS = 245; @@ -74,10 +84,9 @@ export function resolveHeatmapGranularity({ ); } -export function toHeatmapQuery( - config: BuilderChartConfigWithDateRange, -): HeatmapQuery { - if (getHeatmapMode(config) === 'series') { +/** PromQL heatmaps only support series mode. */ +export function toHeatmapQuery(config: HeatmapSeriesChartConfig): HeatmapQuery { + if (isPromqlChartConfig(config) || getHeatmapMode(config) === 'series') { return { mode: 'series', config }; } @@ -104,18 +113,19 @@ export function toHeatmapQuery( } /** - * The time-chart query behind a series-mode heatmap: `select[0]` and the - * group by, bucketed at the heatmap's granularity. + * The time-chart query behind a series-mode heatmap, bucketed at the heatmap's + * granularity: `select[0]` and the group by for a builder config, or the first + * expression's range query for PromQL. */ export function buildHeatmapSeriesConfig( - config: BuilderChartConfigWithDateRange, + config: HeatmapSeriesChartConfig, granularity: SQLInterval, ): ChartConfigWithDateRange { return convertToTimeChartConfig({ ...config, - select: Array.isArray(config.select) - ? config.select.slice(0, 1) - : config.select, + ...(isBuilderChartConfig(config) && Array.isArray(config.select) + ? { select: config.select.slice(0, 1) } + : {}), granularity, // Heatmaps have no series limit control, a default is applied automatically seriesLimit: undefined, diff --git a/packages/app/src/components/DBHeatmapChart/index.ts b/packages/app/src/components/DBHeatmapChart/index.ts index 3621cf7602..f0b63103d7 100644 --- a/packages/app/src/components/DBHeatmapChart/index.ts +++ b/packages/app/src/components/DBHeatmapChart/index.ts @@ -3,6 +3,7 @@ export { default } from './DBHeatmapChart'; export { HEATMAP_DURATION_NUMBER_FORMAT } from './heatmapAxis'; export { HEATMAP_N_BUCKETS } from './heatmapBounds'; export type { HeatmapScaleType } from './heatmapGrid'; +export type { HeatmapSeriesChartConfig } from './heatmapQueries'; export { buildHeatmapBoundsConfig, buildHeatmapBucketConfig, diff --git a/packages/app/src/components/DBHeatmapChart/useSeriesHeatmapData.ts b/packages/app/src/components/DBHeatmapChart/useSeriesHeatmapData.ts index 8f4dbd93e6..f418f88d26 100644 --- a/packages/app/src/components/DBHeatmapChart/useSeriesHeatmapData.ts +++ b/packages/app/src/components/DBHeatmapChart/useSeriesHeatmapData.ts @@ -1,11 +1,13 @@ import { useMemo } from 'react'; import { ResponseJSON } from '@hyperdx/common-utils/dist/clickhouse'; -import { BuilderChartConfigWithDateRange } from '@hyperdx/common-utils/dist/types'; import { formatResponseForTimeChart } from '@/ChartUtils'; import { useQueriedChartConfig } from '@/hooks/useChartConfig'; -import { buildHeatmapSeriesConfig } from './heatmapQueries'; +import { + buildHeatmapSeriesConfig, + HeatmapSeriesChartConfig, +} from './heatmapQueries'; import { gridFromSeries, HeatmapSeries } from './heatmapSeriesGrid'; import { HeatmapData, @@ -56,7 +58,7 @@ export function useSeriesHeatmapData({ config, enabled, }: { - config: BuilderChartConfigWithDateRange; + config: HeatmapSeriesChartConfig; enabled: boolean; }): HeatmapData { const { granularity, generatedTsBuckets, fromMs, toMs } = diff --git a/packages/app/src/utils/__tests__/promqlChartQuery.test.ts b/packages/app/src/utils/__tests__/promqlChartQuery.test.ts index 6b9ade9d8a..a2b057d4e3 100644 --- a/packages/app/src/utils/__tests__/promqlChartQuery.test.ts +++ b/packages/app/src/utils/__tests__/promqlChartQuery.test.ts @@ -317,4 +317,59 @@ describe('queryPromqlChartConfig', () => { expect.objectContaining({ limit: undefined }), ); }); + + it('runs a heatmap as a range query of its first expression', async () => { + jest + .mocked(prometheusApi.queryRange) + .mockReset() + .mockResolvedValue({ + status: 'success', + data: { + resultType: 'matrix', + result: [ + { + metric: { job: 'api', instance: 'a' }, + values: [[dateRange[0].getTime() / 1000, '1']], + }, + ], + }, + }); + + const result = await queryPromqlChartConfig( + { + configType: 'promql', + displayType: DisplayType.Heatmap, + connection: 'conn', + granularity: '5 minute', + legendTemplate: '{{job}}', + promqlExpression: [ + { + expression: 'rate(up{job="$job"}[$__interval])', + queryType: 'instant', + }, + { expression: 'down' }, + ], + variables: [{ name: 'job', values: ['api'] }], + }, + dateRange, + new AbortController().signal, + {}, + ); + + expect(prometheusApi.query).not.toHaveBeenCalled(); + expect(prometheusApi.queryRange).toHaveBeenCalledTimes(1); + expect(prometheusApi.queryRange).toHaveBeenCalledWith( + expect.objectContaining({ + query: 'rate(up{job="api"}[300s])', + step: '300s', + }), + ); + expect(result.data).toEqual([ + { + __hdx_time_bucket: dateRange[0].toISOString(), + value: 1, + series_name: 'api', + }, + ]); + }); }); diff --git a/packages/app/tests/e2e/features/promql-heatmap.spec.ts b/packages/app/tests/e2e/features/promql-heatmap.spec.ts new file mode 100644 index 0000000000..9d2db47213 --- /dev/null +++ b/packages/app/tests/e2e/features/promql-heatmap.spec.ts @@ -0,0 +1,81 @@ +/** + * PromQL heatmaps are series heatmaps: one row per series of a range query, + * named by the legend template. There is no distribution mode to pick. + * + * The seed gives `e2e_service_up` one series per `SERVICES` entry, labelled + * `service`, one sample of 1 a minute. + */ +import { DisplayType } from '@hyperdx/common-utils/dist/types'; + +import { HeatmapComponent } from '../components/HeatmapComponent'; +import { DashboardPage } from '../page-objects/DashboardPage'; +import { SERVICES } from '../seed-clickhouse'; +import { expect, test } from '../utils/base-test'; +import { E2E_PROMQL_METRIC_NAME, PROMQL_SOURCE_NAME } from '../utils/constants'; + +// Ends in `)` rather than inside the selector so the autocomplete popup closes. +const EXPRESSION = `last_over_time(${E2E_PROMQL_METRIC_NAME}{service!=""}[$__interval])`; + +test.describe('PromQL heatmaps', { tag: ['@dashboard', '@full-stack'] }, () => { + test('draws a row per series, and persists', async ({ page }) => { + test.setTimeout(120000); + + const dashboardPage = new DashboardPage(page); + const editor = dashboardPage.chartEditor; + const servicePattern = new RegExp(`^(${SERVICES.join('|')})$`); + + const assertRendersServices = async (heatmap: HeatmapComponent) => { + await expect(heatmap.canvas.first()).toBeVisible({ timeout: 30000 }); + await expect(heatmap.notEnoughDataText).toHaveCount(0); + await heatmap.hoverPopulatedCell(); + expect(SERVICES).toContain(await heatmap.hoveredSeriesName()); + await expect(await heatmap.hoverSeriesAxisLabel()).toHaveText( + servicePattern, + ); + }; + + await test.step('Create a PromQL heatmap tile', async () => { + await dashboardPage.goto(); + await dashboardPage.createNewDashboard(); + await dashboardPage.addTile(); + await expect(editor.nameInput).toBeVisible(); + await editor.waitForDataToLoad(); + await editor.setChartType(DisplayType.Heatmap); + await editor.switchToPromqlMode(); + await editor.selectSource(PROMQL_SOURCE_NAME); + await editor.setChartName('PromQL heatmap tile'); + await editor.replacePromqlExpression(EXPRESSION); + await editor.setLegendTemplate('{{service}}'); + await editor.runQuery(false); + }); + + await test.step('The editor offers no heatmap mode or instant query', async () => { + await expect(page.getByTestId('heatmap-mode-control')).toHaveCount(0); + await expect(page.getByTestId('promql-query-type-control-0')).toHaveCount( + 0, + ); + await expect(editor.granularityPicker).toBeVisible(); + }); + + await test.step('The preview draws a row per series', async () => { + await assertRendersServices( + new HeatmapComponent(page, page.getByTestId('tile-editor-form')), + ); + await editor.openGeneratedPromql(); + await expect + .poll(() => editor.getGeneratedPromqlText()) + .toMatch(/^last_over_time\(.+\[\d+s\]\)$/); + }); + + await test.step('The saved tile renders, and still renders after reload', async () => { + await editor.save(); + await expect(dashboardPage.getTiles()).toHaveCount(1, { + timeout: 10000, + }); + await expect(dashboardPage.getTileError()).toHaveCount(0); + await assertRendersServices(dashboardPage.getTileHeatmap()); + await dashboardPage.reload(); + await assertRendersServices(dashboardPage.getTileHeatmap()); + }); + }); +});