@@ -19,6 +19,7 @@ import {
1919 convertFormStateToSavedChartConfig ,
2020 convertSavedChartConfigToFormState ,
2121 getAllowedSourceKinds ,
22+ promqlExpressionPlaceholder ,
2223 validateChartForm ,
2324} from '@/components/ChartEditor/utils' ;
2425
@@ -688,6 +689,21 @@ describe('PromQL expressions', () => {
688689 } ) ;
689690 } ) ;
690691
692+ it ( 'saves a histogram heatmap' , ( ) => {
693+ expect (
694+ convertFormStateToSavedChartConfig (
695+ {
696+ ...promqlForm (
697+ [ { expression : 'sum by (le) (x_bucket)' } ] ,
698+ DisplayType . Heatmap ,
699+ ) ,
700+ heatmap : { mode : 'histogram' } ,
701+ } ,
702+ undefined ,
703+ ) ,
704+ ) . toMatchObject ( { heatmap : { mode : 'histogram' } } ) ;
705+ } ) ;
706+
691707 it ( 'queries a heatmap with its heatmap settings' , ( ) => {
692708 const result = convertFormStateToChartConfig (
693709 {
@@ -1929,6 +1945,22 @@ describe('validateChartForm', () => {
19291945 expect . objectContaining ( { path : 'series.0.valueExpression' } ) ,
19301946 ) ;
19311947 } ) ;
1948+
1949+ it ( 'requires a value expression on a builder heatmap left in histogram mode' , ( ) => {
1950+ const errors = validateChartForm (
1951+ makeForm ( {
1952+ displayType : DisplayType . Heatmap ,
1953+ source : 'source-trace' ,
1954+ heatmap : { mode : 'histogram' } ,
1955+ series : [ { ...seriesItem , valueExpression : '' } ] ,
1956+ } ) ,
1957+ traceSource ,
1958+ jest . fn ( ) ,
1959+ ) ;
1960+ expect ( errors ) . toContainEqual (
1961+ expect . objectContaining ( { path : 'series.0.valueExpression' } ) ,
1962+ ) ;
1963+ } ) ;
19321964} ) ;
19331965
19341966describe ( 'color round-trip (sql/promql Number tile)' , ( ) => {
@@ -2082,6 +2114,41 @@ describe('heatmap round-trip', () => {
20822114 } ) ;
20832115} ) ;
20842116
2117+ describe ( 'builder heatmap settings' , ( ) => {
2118+ const form : ChartEditorFormState = {
2119+ displayType : DisplayType . Heatmap ,
2120+ source : 'source-trace' ,
2121+ where : '' ,
2122+ series : [ { ...seriesItem , valueExpression : 'Duration' } ] ,
2123+ } ;
2124+
2125+ it ( 'fall back to distribution mode from PromQL-only histogram mode' , ( ) => {
2126+ const histogramForm : ChartEditorFormState = {
2127+ ...form ,
2128+ heatmap : { mode : 'histogram' , scaleType : 'log' } ,
2129+ } ;
2130+ expect (
2131+ convertFormStateToSavedChartConfig ( histogramForm , traceSource ) ,
2132+ ) . toHaveProperty ( 'heatmap' , { mode : undefined } ) ;
2133+ expect (
2134+ convertFormStateToChartConfig (
2135+ histogramForm ,
2136+ [ new Date ( 0 ) , new Date ( 1000 ) ] ,
2137+ traceSource ,
2138+ ) ,
2139+ ) . toHaveProperty ( 'heatmap' , { mode : undefined } ) ;
2140+ } ) ;
2141+
2142+ it ( 'keep series mode, without PromQL-only settings' , ( ) => {
2143+ expect (
2144+ convertFormStateToSavedChartConfig (
2145+ { ...form , heatmap : { mode : 'series' , scaleType : 'log' } } ,
2146+ traceSource ,
2147+ ) ,
2148+ ) . toHaveProperty ( 'heatmap' , { mode : 'series' } ) ;
2149+ } ) ;
2150+ } ) ;
2151+
20852152describe ( 'metric formulas (HDX-5080)' , ( ) => {
20862153 const metricSeriesItem = {
20872154 aggFn : 'avg' as const ,
@@ -2489,6 +2556,16 @@ describe('getAllowedSourceKinds', () => {
24892556 ) . toEqual ( [ SourceKind . Trace ] ) ;
24902557 } ) ;
24912558
2559+ it ( 'treats a leftover histogram mode on a builder heatmap as distribution' , ( ) => {
2560+ expect (
2561+ getAllowedSourceKinds ( {
2562+ configType : 'builder' ,
2563+ displayType : DisplayType . Heatmap ,
2564+ heatmapMode : 'histogram' ,
2565+ } ) ,
2566+ ) . toEqual ( [ SourceKind . Trace ] ) ;
2567+ } ) ;
2568+
24922569 it ( 'offers only PromQL sources on PromQL heatmap tiles' , ( ) => {
24932570 expect (
24942571 getAllowedSourceKinds ( {
@@ -2499,3 +2576,21 @@ describe('getAllowedSourceKinds', () => {
24992576 ) . toEqual ( [ SourceKind . Promql ] ) ;
25002577 } ) ;
25012578} ) ;
2579+
2580+ describe ( 'promqlExpressionPlaceholder' , ( ) => {
2581+ it . each ( [
2582+ [ 'distribution' , / _ s u m \[ 5 m \] \) \/ r a t e \( .* _ c o u n t / ] ,
2583+ [ 'series' , / ^ s u m b y \( s e r v i c e \) / ] ,
2584+ [ 'histogram' , / ^ s u m b y \( l e \) \( r a t e \( .* _ b u c k e t / ] ,
2585+ ] as const ) ( 'suggests a %s heatmap expression' , ( mode , pattern ) => {
2586+ expect ( promqlExpressionPlaceholder ( DisplayType . Heatmap , mode ) ) . toMatch (
2587+ pattern ,
2588+ ) ;
2589+ } ) ;
2590+
2591+ it ( 'suggests the same expression on every non-heatmap chart' , ( ) => {
2592+ expect ( promqlExpressionPlaceholder ( DisplayType . Line , 'histogram' ) ) . toBe (
2593+ promqlExpressionPlaceholder ( DisplayType . Number , 'distribution' ) ,
2594+ ) ;
2595+ } ) ;
2596+ } ) ;
0 commit comments