Compare commits

...

12 Commits

Author SHA1 Message Date
Naman Verma
02edef8406 fix: follow already set validation patterns 2026-11-25 21:04:14 +05:30
Abhi Kumar
08d7bbc32f refactor(dashboard): name the default distribution percentiles 2026-11-25 18:53:13 +05:30
Abhi Kumar
542fd1432d chore(api): regenerate the frontend api clients 2026-11-25 18:53:13 +05:30
Abhi Kumar
f0b805ce21 chore(api): regenerate openapi spec 2026-11-25 18:53:13 +05:30
Abhi Kumar
e802abaf74 test(dashboard): decode the distribution dashboard without copying its spec 2026-11-25 18:53:13 +05:30
Abhi Kumar
0cd4b05cc3 refactor(dashboard): resolve distribution stack and percentile defaults on the backend
Distribution reuses StackMode, defaulting to normal when written. Unset percentiles are written
as enabled at [50, 90, 99], so both fields are required and the frontend stops knowing them.
2026-11-25 18:53:13 +05:30
Abhi Kumar
2733421a05 refactor(dashboard): keep distribution stacking under visualization
Matches the area chart, which keeps its stack mode there. The enum stays
separate: distribution defaults to normal, area to none.
2026-11-25 18:53:13 +05:30
Naman Verma
be0baa98fa chore: follow established pattern for validations 2026-11-25 18:53:13 +05:30
Naman Verma
3f4a28f86d chore: move validations to the correct types 2026-11-25 18:53:13 +05:30
Abhi Kumar
53887f9788 refactor(dashboard): name distribution spec receivers by role 2026-11-25 18:53:13 +05:30
Abhi Kumar
0fef6d1a6f chore: regenerate openapi specs 2026-11-25 18:53:13 +05:30
Abhi Kumar
5eb5a23269 feat(dashboard): add distribution panel spec 2026-11-25 18:53:13 +05:30
8 changed files with 987 additions and 68 deletions

View File

@@ -4523,6 +4523,121 @@ components:
required:
- name
type: object
DashboardtypesDistributionAxes:
properties:
x:
allOf:
- $ref: '#/components/schemas/DashboardtypesDistributionXAxis'
description: The bucket axis.
"y":
allOf:
- $ref: '#/components/schemas/DashboardtypesDistributionYAxis'
description: The count axis.
type: object
DashboardtypesDistributionChartAppearance:
properties:
percentiles:
allOf:
- $ref: '#/components/schemas/DashboardtypesDistributionPercentiles'
description: Percentile markers drawn across the bucket axis.
type: object
DashboardtypesDistributionPanelSpec:
properties:
axes:
allOf:
- $ref: '#/components/schemas/DashboardtypesDistributionAxes'
description: The X (bucket) axis range and Y (count) axis scale.
chartAppearance:
allOf:
- $ref: '#/components/schemas/DashboardtypesDistributionChartAppearance'
description: Percentile markers.
formatting:
allOf:
- $ref: '#/components/schemas/DashboardtypesPanelFormatting'
description: Unit and decimal precision of the bucket bounds; counts take
no unit.
legend:
allOf:
- $ref: '#/components/schemas/DashboardtypesLegend'
description: Legend placement and series colors.
visualization:
allOf:
- $ref: '#/components/schemas/DashboardtypesDistributionVisualization'
description: The time range the bucket counts are summed over, and how groups
stack.
type: object
DashboardtypesDistributionPercentileValues:
items:
format: double
type: number
maxItems: 5
type: array
uniqueItems: true
DashboardtypesDistributionPercentiles:
properties:
enabled:
description: Whether percentile markers are drawn. Null draws them.
nullable: true
type: boolean
values:
allOf:
- $ref: '#/components/schemas/DashboardtypesDistributionPercentileValues'
description: The percentiles to mark, each greater than 0 and less than
100, at most 5, no repeats. Null or omitted marks 50, 90 and 99; [] marks
none.
required:
- values
type: object
DashboardtypesDistributionStackMode:
enum:
- normal
- none
- percent
type: string
DashboardtypesDistributionVisualization:
properties:
stack:
allOf:
- $ref: '#/components/schemas/DashboardtypesDistributionStackMode'
description: 'How groups combine in a bucket: normal (default) stacks them,
none draws them side by side, percent stacks them as shares of the bucket.'
timePreference:
allOf:
- $ref: '#/components/schemas/DashboardtypesTimePreference'
description: 'The time range the panel queries: global_time (default) follows
the dashboard range; last_5_min, last_15_min, last_30_min, last_1_hr,
last_6_hr, last_1_day, last_3_days, last_1_week or last_1_month pin a
fixed window.'
required:
- stack
type: object
DashboardtypesDistributionXAxis:
properties:
max:
description: Buckets wholly above this value are hidden. Null shows them
all.
nullable: true
type: number
min:
description: Buckets wholly below this value are hidden. Null shows them
all.
nullable: true
type: number
type: object
DashboardtypesDistributionYAxis:
properties:
scale:
allOf:
- $ref: '#/components/schemas/DashboardtypesDistributionYScale'
description: 'How counts are spaced: linear (default) or log.'
required:
- scale
type: object
DashboardtypesDistributionYScale:
enum:
- linear
- log
type: string
DashboardtypesDynamicVariableSignal:
enum:
- traces
@@ -5518,6 +5633,7 @@ components:
mapping:
signoz/AreaChartPanel: '#/components/schemas/DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesAreaChartPanelSpec'
signoz/BarChartPanel: '#/components/schemas/DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesBarChartPanelSpec'
signoz/DistributionPanel: '#/components/schemas/DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesDistributionPanelSpec'
signoz/GeoMapPanel: '#/components/schemas/DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesGeoMapPanelSpec'
signoz/HeatmapPanel: '#/components/schemas/DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesHeatmapPanelSpec'
signoz/HistogramPanel: '#/components/schemas/DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesHistogramPanelSpec'
@@ -5544,6 +5660,7 @@ components:
- $ref: '#/components/schemas/DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesScatterPlotPanelSpec'
- $ref: '#/components/schemas/DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesGeoMapPanelSpec'
- $ref: '#/components/schemas/DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesTopListPanelSpec'
- $ref: '#/components/schemas/DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesDistributionPanelSpec'
type: object
DashboardtypesPanelPluginKind:
enum:
@@ -5560,6 +5677,7 @@ components:
- signoz/ScatterPlotPanel
- signoz/GeoMapPanel
- signoz/TopListPanel
- signoz/DistributionPanel
type: string
DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesAreaChartPanelSpec:
properties:
@@ -5591,6 +5709,21 @@ components:
- kind
- spec
type: object
DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesDistributionPanelSpec:
properties:
kind:
description: The panel kind.
enum:
- signoz/DistributionPanel
type: string
spec:
allOf:
- $ref: '#/components/schemas/DashboardtypesDistributionPanelSpec'
description: The options for this panel kind. {} accepts every default.
required:
- kind
- spec
type: object
DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesGeoMapPanelSpec:
properties:
kind:
@@ -5774,9 +5907,9 @@ components:
- $ref: '#/components/schemas/DashboardtypesPanelPlugin'
description: 'The visualization: kind is one of signoz/TimeSeriesPanel,
signoz/BarChartPanel, signoz/AreaChartPanel, signoz/NumberPanel, signoz/PieChartPanel,
signoz/TablePanel, signoz/HistogramPanel, signoz/ListPanel, signoz/TextPanel
or signoz/HeatmapPanel, and spec holds that kind''s options ({} accepts
every default).'
signoz/TablePanel, signoz/HistogramPanel, signoz/ListPanel, signoz/TextPanel,
signoz/HeatmapPanel or signoz/DistributionPanel, and spec holds that kind''s
options ({} accepts every default).'
queries:
description: The queries the panel runs. Use exactly one entry for a data
panel and [] for signoz/TextPanel. To run several named queries or formulas,
@@ -5912,8 +6045,8 @@ components:
- $ref: '#/components/schemas/Querybuildertypesv5RequestType'
description: 'The result shape the panel requests: time_series for time
series, bar, area and histogram panels, scalar for number, table and pie
panels, raw for list panels, heatmap for heatmap panels, trace for trace
panels.'
panels, raw for list panels, heatmap for heatmap panels, distribution
for distribution panels, trace for trace panels.'
spec:
allOf:
- $ref: '#/components/schemas/DashboardtypesQuerySpec'
@@ -6070,9 +6203,9 @@ components:
(builder query over AI observability traces), signoz/CompositeQuery (several
named queries and formulas), signoz/Formula, signoz/PromQLQuery, signoz/ClickHouseSQL
or signoz/TraceOperator, and spec holds that kind''s query. Pie and table
panels reject signoz/PromQLQuery; heatmap panels reject signoz/AIBuilderQuery
and signoz/TraceOperator; list panels accept only signoz/BuilderQuery
and signoz/AIBuilderQuery.'
panels reject signoz/PromQLQuery; heatmap and distribution panels reject
signoz/AIBuilderQuery and signoz/TraceOperator; list panels accept only
signoz/BuilderQuery and signoz/AIBuilderQuery.'
required:
- plugin
type: object

View File

@@ -7248,6 +7248,123 @@ export interface DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDa
spec: DashboardtypesTopListPanelSpecDTO;
}
/**
* The panel kind.
*/
export enum DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesDistributionPanelSpecDTOKind {
'signoz/DistributionPanel' = 'signoz/DistributionPanel',
}
export interface DashboardtypesDistributionXAxisDTO {
/**
* @type number,null
* @description Buckets wholly above this value are hidden. Null shows them all.
*/
max?: number | null;
/**
* @type number,null
* @description Buckets wholly below this value are hidden. Null shows them all.
*/
min?: number | null;
}
export enum DashboardtypesDistributionYScaleDTO {
linear = 'linear',
log = 'log',
}
export interface DashboardtypesDistributionYAxisDTO {
/**
* @description How counts are spaced: linear (default) or log.
*/
scale: DashboardtypesDistributionYScaleDTO;
}
export interface DashboardtypesDistributionAxesDTO {
/**
* @description The bucket axis.
*/
x?: DashboardtypesDistributionXAxisDTO;
/**
* @description The count axis.
*/
y?: DashboardtypesDistributionYAxisDTO;
}
/**
* @maxItems 5
*/
export type DashboardtypesDistributionPercentileValuesDTO = number[];
export interface DashboardtypesDistributionPercentilesDTO {
/**
* @type boolean,null
* @description Whether percentile markers are drawn. Null draws them.
*/
enabled?: boolean | null;
/**
* @description The percentiles to mark, each greater than 0 and less than 100, at most 5, no repeats. Null or omitted marks 50, 90 and 99; [] marks none.
*/
values: DashboardtypesDistributionPercentileValuesDTO;
}
export interface DashboardtypesDistributionChartAppearanceDTO {
/**
* @description Percentile markers drawn across the bucket axis.
*/
percentiles?: DashboardtypesDistributionPercentilesDTO;
}
export enum DashboardtypesDistributionStackModeDTO {
normal = 'normal',
none = 'none',
percent = 'percent',
}
export interface DashboardtypesDistributionVisualizationDTO {
/**
* @description How groups combine in a bucket: normal (default) stacks them, none draws them side by side, percent stacks them as shares of the bucket.
*/
stack: DashboardtypesDistributionStackModeDTO;
/**
* @description The time range the panel queries: global_time (default) follows the dashboard range; last_5_min, last_15_min, last_30_min, last_1_hr, last_6_hr, last_1_day, last_3_days, last_1_week or last_1_month pin a fixed window.
*/
timePreference?: DashboardtypesTimePreferenceDTO;
}
export interface DashboardtypesDistributionPanelSpecDTO {
/**
* @description The X (bucket) axis range and Y (count) axis scale.
*/
axes?: DashboardtypesDistributionAxesDTO;
/**
* @description Percentile markers.
*/
chartAppearance?: DashboardtypesDistributionChartAppearanceDTO;
/**
* @description Unit and decimal precision of the bucket bounds; counts take no unit.
*/
formatting?: DashboardtypesPanelFormattingDTO;
/**
* @description Legend placement and series colors.
*/
legend?: DashboardtypesLegendDTO;
/**
* @description The time range the bucket counts are summed over, and how groups stack.
*/
visualization?: DashboardtypesDistributionVisualizationDTO;
}
export interface DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesDistributionPanelSpecDTO {
/**
* @enum signoz/DistributionPanel
* @type string
* @description The panel kind.
*/
kind: DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesDistributionPanelSpecDTOKind;
/**
* @description The options for this panel kind. {} accepts every default.
*/
spec: DashboardtypesDistributionPanelSpecDTO;
}
export type DashboardtypesPanelPluginDTO =
| DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesTimeSeriesPanelSpecDTO
| DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesBarChartPanelSpecDTO
@@ -7261,7 +7378,8 @@ export type DashboardtypesPanelPluginDTO =
| DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesHeatmapPanelSpecDTO
| DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesScatterPlotPanelSpecDTO
| DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesGeoMapPanelSpecDTO
| DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesTopListPanelSpecDTO;
| DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesTopListPanelSpecDTO
| DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesDistributionPanelSpecDTO;
export enum Querybuildertypesv5RequestTypeDTO {
scalar = 'scalar',
@@ -7750,14 +7868,14 @@ export interface DashboardtypesQuerySpecDTO {
*/
name?: string;
/**
* @description The query: kind is one of signoz/BuilderQuery, signoz/AIBuilderQuery (builder query over AI observability traces), signoz/CompositeQuery (several named queries and formulas), signoz/Formula, signoz/PromQLQuery, signoz/ClickHouseSQL or signoz/TraceOperator, and spec holds that kind's query. Pie and table panels reject signoz/PromQLQuery; heatmap panels reject signoz/AIBuilderQuery and signoz/TraceOperator; list panels accept only signoz/BuilderQuery and signoz/AIBuilderQuery.
* @description The query: kind is one of signoz/BuilderQuery, signoz/AIBuilderQuery (builder query over AI observability traces), signoz/CompositeQuery (several named queries and formulas), signoz/Formula, signoz/PromQLQuery, signoz/ClickHouseSQL or signoz/TraceOperator, and spec holds that kind's query. Pie and table panels reject signoz/PromQLQuery; heatmap and distribution panels reject signoz/AIBuilderQuery and signoz/TraceOperator; list panels accept only signoz/BuilderQuery and signoz/AIBuilderQuery.
*/
plugin: DashboardtypesQueryPluginDTO;
}
export interface DashboardtypesQueryDTO {
/**
* @description The result shape the panel requests: time_series for time series, bar, area and histogram panels, scalar for number, table and pie panels, raw for list panels, heatmap for heatmap panels, trace for trace panels.
* @description The result shape the panel requests: time_series for time series, bar, area and histogram panels, scalar for number, table and pie panels, raw for list panels, heatmap for heatmap panels, distribution for distribution panels, trace for trace panels.
*/
kind: Querybuildertypesv5RequestTypeDTO;
/**
@@ -7777,7 +7895,7 @@ export interface DashboardtypesPanelSpecDTO {
*/
links?: DashboardtypesLinkDTO[] | null;
/**
* @description The visualization: kind is one of signoz/TimeSeriesPanel, signoz/BarChartPanel, signoz/AreaChartPanel, signoz/NumberPanel, signoz/PieChartPanel, signoz/TablePanel, signoz/HistogramPanel, signoz/ListPanel, signoz/TextPanel or signoz/HeatmapPanel, and spec holds that kind's options ({} accepts every default).
* @description The visualization: kind is one of signoz/TimeSeriesPanel, signoz/BarChartPanel, signoz/AreaChartPanel, signoz/NumberPanel, signoz/PieChartPanel, signoz/TablePanel, signoz/HistogramPanel, signoz/ListPanel, signoz/TextPanel, signoz/HeatmapPanel or signoz/DistributionPanel, and spec holds that kind's options ({} accepts every default).
*/
plugin: DashboardtypesPanelPluginDTO;
/**
@@ -8550,6 +8668,7 @@ export enum DashboardtypesPanelPluginKindDTO {
'signoz/ScatterPlotPanel' = 'signoz/ScatterPlotPanel',
'signoz/GeoMapPanel' = 'signoz/GeoMapPanel',
'signoz/TopListPanel' = 'signoz/TopListPanel',
'signoz/DistributionPanel' = 'signoz/DistributionPanel',
}
/**
* The RFC 6902 operations, applied in order against the dashboard's postable shape.

View File

@@ -669,6 +669,269 @@ func TestValidateHeatmapDashboard(t *testing.T) {
assert.Equal(t, request, rereadRequest)
}
func TestValidateDistributionDashboard(t *testing.T) {
data, err := os.ReadFile("testdata/perses_distribution_panel.json")
require.NoError(t, err, "reading example file")
dashboard := &DashboardV2{}
require.NoError(t, json.Unmarshal(data, &dashboard.Spec), "unmarshal and validate failed")
spec := &dashboard.Spec
require.IsType(t, &DistributionPanelSpec{}, spec.Panels["p1"].Spec.Plugin.Spec)
panelSpec := spec.Panels["p1"].Spec.Plugin.Spec.(*DistributionPanelSpec)
xMin, enabled := 10.0, true
assert.Equal(t, &DistributionPanelSpec{
Visualization: DistributionVisualization{BasicVisualization: BasicVisualization{TimePreference: TimePreferenceGlobalTime}, Stack: DistributionStackModeNone},
Formatting: PanelFormatting{Unit: "s", DecimalPrecision: PrecisionOption3},
Axes: DistributionAxes{X: DistributionXAxis{Min: &xMin}, Y: DistributionYAxis{Scale: DistributionYScaleLog}},
Legend: Legend{Position: LegendPositionRight, Mode: LegendModeList},
ChartAppearance: DistributionChartAppearance{Percentiles: DistributionPercentiles{Enabled: &enabled, Values: DistributionPercentileValues{75, 99.9}}},
}, panelSpec)
request, err := dashboard.GetPanelQuery(1, 2, "p1")
require.NoError(t, err, "building the panel's query failed")
assert.Equal(t, qb.RequestTypeDistribution, request.RequestType)
assert.NoError(t, request.Validate(), "the request built from the panel is not a valid distribution request")
// the panel read back out of storage draws the same distribution
stored, err := json.Marshal(spec)
require.NoError(t, err, "marshal dashboard failed")
reread := &DashboardV2{}
require.NoError(t, json.Unmarshal(stored, &reread.Spec), "the stored dashboard does not validate")
assert.Equal(t, panelSpec, reread.Spec.Panels["p1"].Spec.Plugin.Spec)
rereadRequest, err := reread.GetPanelQuery(1, 2, "p1")
require.NoError(t, err, "building the stored panel's query failed")
assert.Equal(t, request, rereadRequest)
}
func TestDistributionPanelSpecDefaults(t *testing.T) {
testCases := []struct {
name string
spec string
}{
{name: "EmptySpec", spec: `{}`},
{name: "EmptyVisualization", spec: `{"visualization": {}}`},
{name: "EmptyChartAppearance", spec: `{"chartAppearance": {}}`},
{name: "EmptyPercentiles", spec: `{"chartAppearance": {"percentiles": {}}}`},
}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
var plugin PanelPlugin
require.NoError(t, json.Unmarshal([]byte(`{"kind": "signoz/DistributionPanel", "spec": `+testCase.spec+`}`), &plugin))
spec := plugin.Spec.(*DistributionPanelSpec)
assert.Equal(t, "normal", spec.Visualization.Stack.ValueOrDefault())
assert.Nil(t, spec.Axes.X.Min)
assert.Nil(t, spec.Axes.X.Max)
assert.Equal(t, "linear", spec.Axes.Y.Scale.ValueOrDefault())
assert.Nil(t, spec.ChartAppearance.Percentiles.Enabled, "an omitted enabled stays null so the renderer draws the markers")
assert.Equal(t, DistributionPercentileValues{50, 90, 99}, spec.ChartAppearance.Percentiles.Values.ValueOrDefault())
stored, err := json.Marshal(spec)
require.NoError(t, err)
assert.Equal(t, `{"visualization":{"timePreference":"global_time","stack":"normal"},"formatting":{"unit":"","decimalPrecision":"2"},"axes":{"x":{"min":null,"max":null},"y":{"scale":"linear"}},"legend":{"position":"bottom","mode":"list","customColors":null},"chartAppearance":{"percentiles":{"enabled":null,"values":[50,90,99]}}}`, string(stored))
})
}
}
func TestDistributionPanelSpecPercentileValues(t *testing.T) {
testCases := []struct {
name string
spec string
expectedPercentilesJSON string
}{
{name: "Disabled_ValuesDefaulted", spec: `{"chartAppearance": {"percentiles": {"enabled": false}}}`, expectedPercentilesJSON: `{"enabled":false,"values":[50,90,99]}`},
{name: "EmptyValues_MarksNone", spec: `{"chartAppearance": {"percentiles": {"values": []}}}`, expectedPercentilesJSON: `{"enabled":null,"values":[]}`},
{name: "NullValues_Defaulted", spec: `{"chartAppearance": {"percentiles": {"enabled": null, "values": null}}}`, expectedPercentilesJSON: `{"enabled":null,"values":[50,90,99]}`},
{name: "ExplicitValues_EchoedInOrder", spec: `{"chartAppearance": {"percentiles": {"enabled": true, "values": [99.9, 50]}}}`, expectedPercentilesJSON: `{"enabled":true,"values":[99.9,50]}`},
}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
var plugin PanelPlugin
require.NoError(t, json.Unmarshal([]byte(`{"kind": "signoz/DistributionPanel", "spec": `+testCase.spec+`}`), &plugin))
spec := plugin.Spec.(*DistributionPanelSpec)
stored, err := json.Marshal(spec.ChartAppearance.Percentiles)
require.NoError(t, err)
assert.Equal(t, testCase.expectedPercentilesJSON, string(stored))
})
}
}
func TestDistributionPanelSpecXMinEqualsMax(t *testing.T) {
var plugin PanelPlugin
require.NoError(t, json.Unmarshal([]byte(`{"kind": "signoz/DistributionPanel", "spec": {"axes": {"x": {"min": 10, "max": 10}}}}`), &plugin))
spec := plugin.Spec.(*DistributionPanelSpec)
require.NotNil(t, spec.Axes.X.Min)
require.NotNil(t, spec.Axes.X.Max)
assert.Equal(t, 10.0, *spec.Axes.X.Min)
assert.Equal(t, 10.0, *spec.Axes.X.Max)
}
func TestDistributionPanelSpecRejections(t *testing.T) {
testCases := []struct {
name string
spec string
expectedMessage string
}{
{
name: "XMin_AboveMax",
spec: `{"axes": {"x": {"min": 20, "max": 10}}}`,
expectedMessage: "axes.x.min 20 is greater than axes.x.max 10",
},
{
name: "YScale_Unknown",
spec: `{"axes": {"y": {"scale": "symlog"}}}`,
expectedMessage: "invalid distribution y scale",
},
{
name: "UnknownField",
spec: `{"axes": {"y": {"softMax": 10}}}`,
expectedMessage: "unknown field \"softMax\"",
},
{
name: "Percentile_Zero",
spec: `{"chartAppearance": {"percentiles": {"values": [0, 50]}}}`,
expectedMessage: "invalid percentile 0: must be greater than 0 and less than 100",
},
{
name: "Percentile_Hundred",
spec: `{"chartAppearance": {"percentiles": {"values": [100]}}}`,
expectedMessage: "invalid percentile 100: must be greater than 0 and less than 100",
},
{
name: "Percentile_Duplicate",
spec: `{"chartAppearance": {"percentiles": {"values": [90, 90]}}}`,
expectedMessage: "invalid percentiles: 90 is listed more than once",
},
{
name: "Stack_Empty",
spec: `{"visualization": {"stack": ""}}`,
expectedMessage: "invalid distribution stack mode \"\": must be `normal`, `none`, or `percent`",
},
{
name: "Percentiles_UnknownField",
spec: `{"chartAppearance": {"percentiles": {"show": true}}}`,
expectedMessage: "unknown field \"show\"",
},
{
name: "XAxis_UnknownField",
spec: `{"axes": {"x": {"softMin": 0}}}`,
expectedMessage: "unknown field \"softMin\"",
},
{
name: "Percentiles_MoreThanFive",
spec: `{"chartAppearance": {"percentiles": {"values": [10, 25, 50, 75, 90, 99]}}}`,
expectedMessage: "invalid percentiles: at most 5, got 6",
},
{
name: "Percentiles_NotAList",
spec: `{"chartAppearance": {"percentiles": {"values": 50}}}`,
expectedMessage: "cannot unmarshal number into Go value of type []float64",
},
}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
var plugin PanelPlugin
err := json.Unmarshal([]byte(`{"kind": "signoz/DistributionPanel", "spec": `+testCase.spec+`}`), &plugin)
require.Error(t, err)
assert.Contains(t, err.Error(), testCase.expectedMessage)
})
}
}
func TestDistributionPanelQueryKinds(t *testing.T) {
testCases := []struct {
name string
queryPluginKind string
queryPluginSpec string
expectedAllowed bool
}{
{
name: "MetricsBuilder_Allowed",
queryPluginKind: "signoz/BuilderQuery",
queryPluginSpec: `{"name": "A", "signal": "metrics", "aggregations": [
{"metricName": "http.server.request.duration", "timeAggregation": "increase", "spaceAggregation": "sum"}
]}`,
expectedAllowed: true,
},
{
name: "PromQL_Allowed",
queryPluginKind: "signoz/PromQLQuery",
queryPluginSpec: `{"name": "A", "query": "sum by (le) (increase(signoz_latency_bucket[5m]))"}`,
expectedAllowed: true,
},
{
name: "ClickHouseSQL_Allowed",
queryPluginKind: "signoz/ClickHouseSQL",
queryPluginSpec: `{"name": "A", "query": "SELECT ts, bucket, value FROM cells"}`,
expectedAllowed: true,
},
{
name: "Formula_Allowed",
queryPluginKind: "signoz/Formula",
queryPluginSpec: `{"name": "F1", "expression": "A / B"}`,
expectedAllowed: true,
},
{
name: "Composite_Allowed",
queryPluginKind: "signoz/CompositeQuery",
queryPluginSpec: `{"queries": [
{"type": "builder_query", "spec": {"name": "A", "signal": "metrics", "disabled": true, "aggregations": [
{"metricName": "http.server.request.duration", "timeAggregation": "increase", "spaceAggregation": "sum"}
]}},
{"type": "builder_formula", "spec": {"name": "F1", "expression": "A * 2"}}
]}`,
expectedAllowed: true,
},
{
name: "TraceOperator_Refused",
queryPluginKind: "signoz/TraceOperator",
queryPluginSpec: `{"name": "T1", "expression": "A => B"}`,
expectedAllowed: false,
},
}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
data := fmt.Sprintf(`{
"variables": [],
"panels": {
"p1": {
"kind": "Panel",
"spec": {
"links": [],
"plugin": {"kind": "signoz/DistributionPanel", "spec": {}},
"queries": [{
"kind": "distribution",
"spec": {
"plugin": {"kind": %q, "spec": %s}
}
}]
}
}
},
"links": [],
"layouts": []
}`, testCase.queryPluginKind, testCase.queryPluginSpec)
_, err := unmarshalDashboard([]byte(data))
if testCase.expectedAllowed {
require.NoError(t, err)
return
}
require.Error(t, err)
assert.Contains(t, err.Error(), "is not supported by panel kind")
})
}
}
func TestInvalidateOneInvalidPanel(t *testing.T) {
data := []byte(`{
"variables": [],

View File

@@ -28,19 +28,20 @@ type PanelPlugin struct {
// (and strips the duplicate parent properties) after reflection.
func (PanelPlugin) PrepareJSONSchema(s *jsonschema.Schema) error {
return markDiscriminator(s, "kind", map[string]string{
string(PanelKindTimeSeries): schemaRef("DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesTimeSeriesPanelSpec"),
string(PanelKindBarChart): schemaRef("DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesBarChartPanelSpec"),
string(PanelKindAreaChart): schemaRef("DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesAreaChartPanelSpec"),
string(PanelKindNumber): schemaRef("DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesNumberPanelSpec"),
string(PanelKindPieChart): schemaRef("DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesPieChartPanelSpec"),
string(PanelKindTable): schemaRef("DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesTablePanelSpec"),
string(PanelKindHistogram): schemaRef("DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesHistogramPanelSpec"),
string(PanelKindList): schemaRef("DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesListPanelSpec"),
string(PanelKindText): schemaRef("DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesTextPanelSpec"),
string(PanelKindHeatmap): schemaRef("DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesHeatmapPanelSpec"),
string(PanelKindScatterPlot): schemaRef("DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesScatterPlotPanelSpec"),
string(PanelKindGeoMap): schemaRef("DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesGeoMapPanelSpec"),
string(PanelKindTopList): schemaRef("DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesTopListPanelSpec"),
string(PanelKindTimeSeries): schemaRef("DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesTimeSeriesPanelSpec"),
string(PanelKindBarChart): schemaRef("DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesBarChartPanelSpec"),
string(PanelKindAreaChart): schemaRef("DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesAreaChartPanelSpec"),
string(PanelKindNumber): schemaRef("DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesNumberPanelSpec"),
string(PanelKindPieChart): schemaRef("DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesPieChartPanelSpec"),
string(PanelKindTable): schemaRef("DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesTablePanelSpec"),
string(PanelKindHistogram): schemaRef("DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesHistogramPanelSpec"),
string(PanelKindList): schemaRef("DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesListPanelSpec"),
string(PanelKindText): schemaRef("DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesTextPanelSpec"),
string(PanelKindHeatmap): schemaRef("DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesHeatmapPanelSpec"),
string(PanelKindScatterPlot): schemaRef("DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesScatterPlotPanelSpec"),
string(PanelKindGeoMap): schemaRef("DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesGeoMapPanelSpec"),
string(PanelKindTopList): schemaRef("DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesTopListPanelSpec"),
string(PanelKindDistribution): schemaRef("DashboardtypesPanelPluginVariantGithubComSigNozSignozPkgTypesDashboardtypesDistributionPanelSpec"),
})
}
@@ -77,6 +78,7 @@ func (PanelPlugin) JSONSchemaOneOf() []any {
PanelPluginVariant[ScatterPlotPanelSpec]{Kind: string(PanelKindScatterPlot)},
PanelPluginVariant[GeoMapPanelSpec]{Kind: string(PanelKindGeoMap)},
PanelPluginVariant[TopListPanelSpec]{Kind: string(PanelKindTopList)},
PanelPluginVariant[DistributionPanelSpec]{Kind: string(PanelKindDistribution)},
}
}
@@ -240,19 +242,20 @@ func (v VariablePluginVariant[S]) PrepareJSONSchema(s *jsonschema.Schema) error
var (
panelPluginSpecs = map[PanelPluginKind]func() any{
PanelKindTimeSeries: func() any { return new(TimeSeriesPanelSpec) },
PanelKindBarChart: func() any { return new(BarChartPanelSpec) },
PanelKindAreaChart: func() any { return new(AreaChartPanelSpec) },
PanelKindNumber: func() any { return new(NumberPanelSpec) },
PanelKindPieChart: func() any { return new(PieChartPanelSpec) },
PanelKindTable: func() any { return new(TablePanelSpec) },
PanelKindHistogram: func() any { return new(HistogramPanelSpec) },
PanelKindList: func() any { return new(ListPanelSpec) },
PanelKindText: func() any { return new(TextPanelSpec) },
PanelKindHeatmap: func() any { return new(HeatmapPanelSpec) },
PanelKindScatterPlot: func() any { return new(ScatterPlotPanelSpec) },
PanelKindGeoMap: func() any { return new(GeoMapPanelSpec) },
PanelKindTopList: func() any { return new(TopListPanelSpec) },
PanelKindTimeSeries: func() any { return new(TimeSeriesPanelSpec) },
PanelKindBarChart: func() any { return new(BarChartPanelSpec) },
PanelKindAreaChart: func() any { return new(AreaChartPanelSpec) },
PanelKindNumber: func() any { return new(NumberPanelSpec) },
PanelKindPieChart: func() any { return new(PieChartPanelSpec) },
PanelKindTable: func() any { return new(TablePanelSpec) },
PanelKindHistogram: func() any { return new(HistogramPanelSpec) },
PanelKindList: func() any { return new(ListPanelSpec) },
PanelKindText: func() any { return new(TextPanelSpec) },
PanelKindHeatmap: func() any { return new(HeatmapPanelSpec) },
PanelKindScatterPlot: func() any { return new(ScatterPlotPanelSpec) },
PanelKindGeoMap: func() any { return new(GeoMapPanelSpec) },
PanelKindTopList: func() any { return new(TopListPanelSpec) },
PanelKindDistribution: func() any { return new(DistributionPanelSpec) },
}
queryPluginSpecs = map[QueryPluginKind]func() any{
QueryKindBuilder: func() any { return new(BuilderQuerySpec) },
@@ -269,19 +272,20 @@ var (
VariableKindCustom: func() any { return new(CustomVariableSpec) },
}
allowedQueryKinds = map[PanelPluginKind][]QueryPluginKind{
PanelKindTimeSeries: {QueryKindBuilder, QueryKindAIBuilder, QueryKindComposite, QueryKindFormula, QueryKindTraceOperator, QueryKindPromQL, QueryKindClickHouseSQL},
PanelKindBarChart: {QueryKindBuilder, QueryKindAIBuilder, QueryKindComposite, QueryKindFormula, QueryKindTraceOperator, QueryKindPromQL, QueryKindClickHouseSQL},
PanelKindAreaChart: {QueryKindBuilder, QueryKindAIBuilder, QueryKindComposite, QueryKindFormula, QueryKindTraceOperator, QueryKindPromQL, QueryKindClickHouseSQL},
PanelKindNumber: {QueryKindBuilder, QueryKindAIBuilder, QueryKindComposite, QueryKindFormula, QueryKindTraceOperator, QueryKindPromQL, QueryKindClickHouseSQL},
PanelKindHistogram: {QueryKindBuilder, QueryKindAIBuilder, QueryKindComposite, QueryKindFormula, QueryKindTraceOperator, QueryKindPromQL, QueryKindClickHouseSQL},
PanelKindPieChart: {QueryKindBuilder, QueryKindAIBuilder, QueryKindComposite, QueryKindFormula, QueryKindTraceOperator, QueryKindClickHouseSQL},
PanelKindTable: {QueryKindBuilder, QueryKindAIBuilder, QueryKindComposite, QueryKindFormula, QueryKindTraceOperator, QueryKindClickHouseSQL},
PanelKindList: {QueryKindBuilder, QueryKindAIBuilder},
PanelKindText: {},
PanelKindHeatmap: {QueryKindBuilder, QueryKindComposite, QueryKindFormula, QueryKindPromQL, QueryKindClickHouseSQL},
PanelKindScatterPlot: {QueryKindBuilder, QueryKindComposite, QueryKindFormula, QueryKindClickHouseSQL},
PanelKindGeoMap: {QueryKindBuilder, QueryKindComposite, QueryKindFormula, QueryKindClickHouseSQL},
PanelKindTopList: {QueryKindBuilder, QueryKindComposite, QueryKindFormula, QueryKindTraceOperator, QueryKindClickHouseSQL},
PanelKindTimeSeries: {QueryKindBuilder, QueryKindAIBuilder, QueryKindComposite, QueryKindFormula, QueryKindTraceOperator, QueryKindPromQL, QueryKindClickHouseSQL},
PanelKindBarChart: {QueryKindBuilder, QueryKindAIBuilder, QueryKindComposite, QueryKindFormula, QueryKindTraceOperator, QueryKindPromQL, QueryKindClickHouseSQL},
PanelKindAreaChart: {QueryKindBuilder, QueryKindAIBuilder, QueryKindComposite, QueryKindFormula, QueryKindTraceOperator, QueryKindPromQL, QueryKindClickHouseSQL},
PanelKindNumber: {QueryKindBuilder, QueryKindAIBuilder, QueryKindComposite, QueryKindFormula, QueryKindTraceOperator, QueryKindPromQL, QueryKindClickHouseSQL},
PanelKindHistogram: {QueryKindBuilder, QueryKindAIBuilder, QueryKindComposite, QueryKindFormula, QueryKindTraceOperator, QueryKindPromQL, QueryKindClickHouseSQL},
PanelKindPieChart: {QueryKindBuilder, QueryKindAIBuilder, QueryKindComposite, QueryKindFormula, QueryKindTraceOperator, QueryKindClickHouseSQL},
PanelKindTable: {QueryKindBuilder, QueryKindAIBuilder, QueryKindComposite, QueryKindFormula, QueryKindTraceOperator, QueryKindClickHouseSQL},
PanelKindList: {QueryKindBuilder, QueryKindAIBuilder},
PanelKindText: {},
PanelKindHeatmap: {QueryKindBuilder, QueryKindComposite, QueryKindFormula, QueryKindPromQL, QueryKindClickHouseSQL},
PanelKindScatterPlot: {QueryKindBuilder, QueryKindComposite, QueryKindFormula, QueryKindClickHouseSQL},
PanelKindGeoMap: {QueryKindBuilder, QueryKindComposite, QueryKindFormula, QueryKindClickHouseSQL},
PanelKindTopList: {QueryKindBuilder, QueryKindComposite, QueryKindFormula, QueryKindTraceOperator, QueryKindClickHouseSQL},
PanelKindDistribution: {QueryKindBuilder, QueryKindComposite, QueryKindFormula, QueryKindPromQL, QueryKindClickHouseSQL},
}
)

View File

@@ -70,7 +70,7 @@ func (k *PanelKind) UnmarshalJSON(data []byte) error {
type PanelSpec struct {
Display Display `json:"display" required:"true" description:"The panel title and description."`
Plugin PanelPlugin `json:"plugin" required:"true" description:"The visualization: kind is one of signoz/TimeSeriesPanel, signoz/BarChartPanel, signoz/AreaChartPanel, signoz/NumberPanel, signoz/PieChartPanel, signoz/TablePanel, signoz/HistogramPanel, signoz/ListPanel, signoz/TextPanel or signoz/HeatmapPanel, and spec holds that kind's options ({} accepts every default)."`
Plugin PanelPlugin `json:"plugin" required:"true" description:"The visualization: kind is one of signoz/TimeSeriesPanel, signoz/BarChartPanel, signoz/AreaChartPanel, signoz/NumberPanel, signoz/PieChartPanel, signoz/TablePanel, signoz/HistogramPanel, signoz/ListPanel, signoz/TextPanel, signoz/HeatmapPanel or signoz/DistributionPanel, and spec holds that kind's options ({} accepts every default)."`
Queries []Query `json:"queries" required:"true" nullable:"false" description:"The queries the panel runs. Use exactly one entry for a data panel and [] for signoz/TextPanel. To run several named queries or formulas, use one entry whose spec.plugin.kind is signoz/CompositeQuery and put the constituent queries in its plugin spec."`
Links []Link `json:"links,omitzero" description:"Context links offered in the data point drilldown menu of the panel, with dashboard variables resolved in the URL."`
}
@@ -92,13 +92,13 @@ type Link struct {
// ══════════════════════════════════════════════
type Query struct {
Kind qb.RequestType `json:"kind" required:"true" description:"The result shape the panel requests: time_series for time series, bar, area and histogram panels, scalar for number, table and pie panels, raw for list panels, heatmap for heatmap panels, trace for trace panels."`
Kind qb.RequestType `json:"kind" required:"true" description:"The result shape the panel requests: time_series for time series, bar, area and histogram panels, scalar for number, table and pie panels, raw for list panels, heatmap for heatmap panels, distribution for distribution panels, trace for trace panels."`
Spec QuerySpec `json:"spec" required:"true" description:"The query content: an optional name and the query plugin."`
}
type QuerySpec struct {
Name string `json:"name,omitempty" description:"An optional label for the query. The name queries refer to each other by lives in the plugin spec."`
Plugin QueryPlugin `json:"plugin" required:"true" description:"The query: kind is one of signoz/BuilderQuery, signoz/AIBuilderQuery (builder query over AI observability traces), signoz/CompositeQuery (several named queries and formulas), signoz/Formula, signoz/PromQLQuery, signoz/ClickHouseSQL or signoz/TraceOperator, and spec holds that kind's query. Pie and table panels reject signoz/PromQLQuery; heatmap panels reject signoz/AIBuilderQuery and signoz/TraceOperator; list panels accept only signoz/BuilderQuery and signoz/AIBuilderQuery."`
Plugin QueryPlugin `json:"plugin" required:"true" description:"The query: kind is one of signoz/BuilderQuery, signoz/AIBuilderQuery (builder query over AI observability traces), signoz/CompositeQuery (several named queries and formulas), signoz/Formula, signoz/PromQLQuery, signoz/ClickHouseSQL or signoz/TraceOperator, and spec holds that kind's query. Pie and table panels reject signoz/PromQLQuery; heatmap and distribution panels reject signoz/AIBuilderQuery and signoz/TraceOperator; list panels accept only signoz/BuilderQuery and signoz/AIBuilderQuery."`
}
// ══════════════════════════════════════════════

View File

@@ -190,23 +190,24 @@ func (AIBuilderQuerySpec) PrepareJSONSchema(s *jsonschema.Schema) error {
type PanelPluginKind string
const (
PanelKindTimeSeries PanelPluginKind = "signoz/TimeSeriesPanel"
PanelKindBarChart PanelPluginKind = "signoz/BarChartPanel"
PanelKindAreaChart PanelPluginKind = "signoz/AreaChartPanel"
PanelKindNumber PanelPluginKind = "signoz/NumberPanel"
PanelKindPieChart PanelPluginKind = "signoz/PieChartPanel"
PanelKindTable PanelPluginKind = "signoz/TablePanel"
PanelKindHistogram PanelPluginKind = "signoz/HistogramPanel"
PanelKindList PanelPluginKind = "signoz/ListPanel"
PanelKindText PanelPluginKind = "signoz/TextPanel"
PanelKindHeatmap PanelPluginKind = "signoz/HeatmapPanel"
PanelKindScatterPlot PanelPluginKind = "signoz/ScatterPlotPanel"
PanelKindGeoMap PanelPluginKind = "signoz/GeoMapPanel"
PanelKindTopList PanelPluginKind = "signoz/TopListPanel"
PanelKindTimeSeries PanelPluginKind = "signoz/TimeSeriesPanel"
PanelKindBarChart PanelPluginKind = "signoz/BarChartPanel"
PanelKindAreaChart PanelPluginKind = "signoz/AreaChartPanel"
PanelKindNumber PanelPluginKind = "signoz/NumberPanel"
PanelKindPieChart PanelPluginKind = "signoz/PieChartPanel"
PanelKindTable PanelPluginKind = "signoz/TablePanel"
PanelKindHistogram PanelPluginKind = "signoz/HistogramPanel"
PanelKindList PanelPluginKind = "signoz/ListPanel"
PanelKindText PanelPluginKind = "signoz/TextPanel"
PanelKindHeatmap PanelPluginKind = "signoz/HeatmapPanel"
PanelKindScatterPlot PanelPluginKind = "signoz/ScatterPlotPanel"
PanelKindGeoMap PanelPluginKind = "signoz/GeoMapPanel"
PanelKindTopList PanelPluginKind = "signoz/TopListPanel"
PanelKindDistribution PanelPluginKind = "signoz/DistributionPanel"
)
func (PanelPluginKind) Enum() []any {
return []any{PanelKindTimeSeries, PanelKindBarChart, PanelKindAreaChart, PanelKindNumber, PanelKindPieChart, PanelKindTable, PanelKindHistogram, PanelKindList, PanelKindText, PanelKindHeatmap, PanelKindScatterPlot, PanelKindGeoMap, PanelKindTopList}
return []any{PanelKindTimeSeries, PanelKindBarChart, PanelKindAreaChart, PanelKindNumber, PanelKindPieChart, PanelKindTable, PanelKindHistogram, PanelKindList, PanelKindText, PanelKindHeatmap, PanelKindScatterPlot, PanelKindGeoMap, PanelKindTopList, PanelKindDistribution}
}
func (k PanelPluginKind) rendersWithoutQuery() bool {
@@ -396,6 +397,59 @@ func (c HeatmapColors) validate() error {
return nil
}
type DistributionPanelSpec struct {
Visualization DistributionVisualization `json:"visualization" description:"The time range the bucket counts are summed over, and how groups stack."`
Formatting PanelFormatting `json:"formatting" description:"Unit and decimal precision of the bucket bounds; counts take no unit."`
Axes DistributionAxes `json:"axes" description:"The X (bucket) axis range and Y (count) axis scale."`
Legend Legend `json:"legend" description:"Legend placement and series colors."`
ChartAppearance DistributionChartAppearance `json:"chartAppearance" description:"Percentile markers."`
}
// DistributionAxes has no soft bounds: X min and max hide whole buckets rather
// than extend the axis, and Y is a count axis with its own scale.
type DistributionAxes struct {
X DistributionXAxis `json:"x" description:"The bucket axis."`
Y DistributionYAxis `json:"y" description:"The count axis."`
}
// DistributionXAxis draws every bucket equally wide, whatever its bounds.
type DistributionXAxis struct {
Min *float64 `json:"min" description:"Buckets wholly below this value are hidden. Null shows them all."`
Max *float64 `json:"max" description:"Buckets wholly above this value are hidden. Null shows them all."`
}
func (axis *DistributionXAxis) UnmarshalJSON(data []byte) error {
dec := json.NewDecoder(bytes.NewReader(data))
dec.DisallowUnknownFields()
type alias DistributionXAxis
var tmp alias
if err := dec.Decode(&tmp); err != nil {
return errors.WrapInvalidInputf(err, ErrCodeDashboardInvalidInput, "invalid axes.x")
}
*axis = DistributionXAxis(tmp)
return axis.validate()
}
func (axis DistributionXAxis) validate() error {
if axis.Min != nil && axis.Max != nil && *axis.Min > *axis.Max {
return errors.NewInvalidInputf(ErrCodeDashboardInvalidInput, "axes.x.min %v is greater than axes.x.max %v", *axis.Min, *axis.Max)
}
return nil
}
type DistributionYAxis struct {
Scale DistributionYScale `json:"scale" required:"true" description:"How counts are spaced: linear (default) or log."`
}
type DistributionChartAppearance struct {
Percentiles DistributionPercentiles `json:"percentiles" description:"Percentile markers drawn across the bucket axis."`
}
type DistributionPercentiles struct {
Enabled *bool `json:"enabled" description:"Whether percentile markers are drawn. Null draws them."`
Values DistributionPercentileValues `json:"values" required:"true" nullable:"false" description:"The percentiles to mark, each greater than 0 and less than 100, at most 5, no repeats. Null or omitted marks 50, 90 and 99; [] marks none."`
}
type TextPanelSpec struct {
Mode TextMode `json:"mode" description:"How text is interpreted. Only markdown is supported."`
Text string `json:"text" description:"The content to render."`
@@ -713,6 +767,11 @@ type BarChartVisualization struct {
StackedBarChart bool `json:"stackedBarChart" description:"Whether the series are stacked on top of each other."`
}
type DistributionVisualization struct {
BasicVisualization
Stack DistributionStackMode `json:"stack" required:"true" description:"How groups combine in a bucket: normal (default) stacks them, none draws them side by side, percent stacks them as shares of the bucket."`
}
type AreaChartVisualization struct {
BasicVisualization
FillSpans bool `json:"fillSpans" description:"Whether intervals with no data are drawn as zero instead of a gap."`
@@ -1252,6 +1311,45 @@ func (sm *StackMode) UnmarshalJSON(data []byte) error {
}
}
// DistributionStackMode repeats StackMode's values with normal as the default.
type DistributionStackMode struct{ valuer.String }
var (
DistributionStackModeNormal = DistributionStackMode{valuer.NewString("normal")} // default
DistributionStackModeNone = DistributionStackMode{valuer.NewString("none")}
DistributionStackModePercent = DistributionStackMode{valuer.NewString("percent")}
)
func (DistributionStackMode) Enum() []any {
return []any{DistributionStackModeNormal, DistributionStackModeNone, DistributionStackModePercent}
}
func (mode DistributionStackMode) ValueOrDefault() string {
if mode.IsZero() {
return DistributionStackModeNormal.StringValue()
}
return mode.StringValue()
}
func (mode DistributionStackMode) MarshalJSON() ([]byte, error) {
return json.Marshal(mode.ValueOrDefault())
}
func (mode *DistributionStackMode) UnmarshalJSON(data []byte) error {
var v string
if err := json.Unmarshal(data, &v); err != nil {
return errors.WrapInvalidInputf(err, ErrCodeDashboardInvalidInput, "invalid distribution stack mode: must be a string, one of `normal`, `none`, or `percent`")
}
parsed := DistributionStackMode{valuer.NewString(v)}
switch parsed {
case DistributionStackModeNormal, DistributionStackModeNone, DistributionStackModePercent:
*mode = parsed
return nil
default:
return errors.NewInvalidInputf(ErrCodeDashboardInvalidInput, "invalid distribution stack mode %q: must be `normal`, `none`, or `percent`", v)
}
}
// FillOpacity is the alpha of an area fill, in 0–1 because that is what the
// chart layer consumes directly. Unlike the enums in this section it has no
// ValueOrDefault: 0 is a legitimate value, so the kind default lives at render
@@ -1683,6 +1781,89 @@ func (s *HeatmapYScale) UnmarshalJSON(data []byte) error {
}
}
type DistributionYScale struct{ valuer.String }
var (
DistributionYScaleLinear = DistributionYScale{valuer.NewString("linear")} // default
DistributionYScaleLog = DistributionYScale{valuer.NewString("log")}
)
func (DistributionYScale) Enum() []any {
return []any{DistributionYScaleLinear, DistributionYScaleLog}
}
func (scale DistributionYScale) ValueOrDefault() string {
if scale.IsZero() {
return DistributionYScaleLinear.StringValue()
}
return scale.StringValue()
}
func (scale DistributionYScale) MarshalJSON() ([]byte, error) {
return json.Marshal(scale.ValueOrDefault())
}
func (scale *DistributionYScale) UnmarshalJSON(data []byte) error {
var v string
if err := json.Unmarshal(data, &v); err != nil {
return errors.WrapInvalidInputf(err, ErrCodeDashboardInvalidInput, "invalid distribution y scale: must be a string, one of `linear` or `log`")
}
parsed := DistributionYScale{valuer.NewString(v)}
switch parsed {
case DistributionYScaleLinear, DistributionYScaleLog:
*scale = parsed
return nil
default:
return errors.NewInvalidInputf(ErrCodeDashboardInvalidInput, "invalid distribution y scale %q: must be `linear` or `log`", v)
}
}
const maxDistributionPercentiles = 5
var defaultDistributionPercentiles = DistributionPercentileValues{50, 90, 99}
// DistributionPercentileValues is the list of percentiles a distribution panel
// marks. Nil takes the default; an empty list marks none.
type DistributionPercentileValues []float64
func (DistributionPercentileValues) PrepareJSONSchema(s *jsonschema.Schema) error {
s.WithMaxItems(maxDistributionPercentiles).WithUniqueItems(true)
return nil
}
func (values DistributionPercentileValues) ValueOrDefault() DistributionPercentileValues {
if values == nil {
return slices.Clone(defaultDistributionPercentiles)
}
return values
}
func (values DistributionPercentileValues) MarshalJSON() ([]byte, error) {
return json.Marshal([]float64(values.ValueOrDefault()))
}
func (values *DistributionPercentileValues) UnmarshalJSON(data []byte) error {
var v []float64
if err := json.Unmarshal(data, &v); err != nil {
return errors.WrapInvalidInputf(err, ErrCodeDashboardInvalidInput, "invalid percentiles: must be a list of at most %d numbers, each greater than 0 and less than 100", maxDistributionPercentiles)
}
if len(v) > maxDistributionPercentiles {
return errors.NewInvalidInputf(ErrCodeDashboardInvalidInput, "invalid percentiles: at most %d, got %d", maxDistributionPercentiles, len(v))
}
seen := make(map[float64]struct{}, len(v))
for _, value := range v {
if value <= 0 || value >= 100 {
return errors.NewInvalidInputf(ErrCodeDashboardInvalidInput, "invalid percentile %v: must be greater than 0 and less than 100", value)
}
if _, ok := seen[value]; ok {
return errors.NewInvalidInputf(ErrCodeDashboardInvalidInput, "invalid percentiles: %v is listed more than once", value)
}
seen[value] = struct{}{}
}
*values = v
return nil
}
type HeatmapColorScale struct{ valuer.String }
var (

View File

@@ -0,0 +1,95 @@
{
"display": {
"name": "latency",
"description": "how request duration is distributed over the range"
},
"variables": [],
"panels": {
"p1": {
"kind": "Panel",
"spec": {
"display": {
"name": "request duration",
"description": ""
},
"plugin": {
"kind": "signoz/DistributionPanel",
"spec": {
"visualization": {
"timePreference": "global_time",
"stack": "none"
},
"formatting": {
"unit": "s",
"decimalPrecision": "3"
},
"axes": {
"x": {
"min": 10
},
"y": {
"scale": "log"
}
},
"legend": {
"position": "right",
"mode": "list"
},
"chartAppearance": {
"percentiles": {
"enabled": true,
"values": [75, 99.9]
}
}
}
},
"links": [],
"queries": [
{
"kind": "distribution",
"spec": {
"plugin": {
"kind": "signoz/BuilderQuery",
"spec": {
"name": "A",
"signal": "metrics",
"aggregations": [
{
"metricName": "http.server.request.duration",
"timeAggregation": "increase",
"spaceAggregation": "sum"
}
],
"groupBy": [
{
"name": "service.name"
}
]
}
}
}
}
]
}
}
},
"links": [],
"layouts": [
{
"kind": "Grid",
"spec": {
"items": [
{
"x": 0,
"y": 0,
"width": 12,
"height": 8,
"content": {
"$ref": "#/spec/panels/p1"
}
}
]
}
}
]
}

View File

@@ -2255,3 +2255,127 @@ def test_dashboard_v2_rejects_explicit_empty_enum(
)
assert response.status_code == HTTPStatus.BAD_REQUEST, response.text
assert response.json()["error"]["code"] == "dashboard_invalid_input", response.text
# ─── distribution panel: a full spec echoes, explicit empties stay, {} fills ──
DISTRIBUTION_FULL_SPEC = {
"visualization": {"timePreference": "last_1_hr", "stack": "percent"},
"formatting": {"unit": "s", "decimalPrecision": "3"},
"axes": {"x": {"min": 10, "max": 2000}, "y": {"scale": "log"}},
"legend": {"position": "right", "mode": "list", "customColors": {"frontend": "#1f77b4"}},
"chartAppearance": {"percentiles": {"enabled": True, "values": [99.9, 50]}},
}
@pytest.mark.parametrize(
("sent_spec", "expected_spec"),
[
# Every option set, none at its default: the read echoes the spec as is.
pytest.param(DISTRIBUTION_FULL_SPEC, DISTRIBUTION_FULL_SPEC, id="full_spec_echoes"),
# Explicit empties ("" unit, {} colors, [] percentiles, false toggle) come
# back as sent, never dropped or defaulted.
pytest.param(
{
"formatting": {"unit": ""},
"axes": {"x": {}},
"legend": {"customColors": {}},
"chartAppearance": {"percentiles": {"enabled": False, "values": []}},
},
{
"visualization": {"timePreference": "global_time", "stack": "normal"},
"formatting": {"unit": "", "decimalPrecision": "2"},
"axes": {"x": {"min": None, "max": None}, "y": {"scale": "linear"}},
"legend": {"position": "bottom", "mode": "list", "customColors": {}},
"chartAppearance": {"percentiles": {"enabled": False, "values": []}},
},
id="explicit_empties_stay",
),
# Omitted percentile values read back as the default; the omitted toggle,
# bounds and colors read back as null.
pytest.param(
{},
{
"visualization": {"timePreference": "global_time", "stack": "normal"},
"formatting": {"unit": "", "decimalPrecision": "2"},
"axes": {"x": {"min": None, "max": None}, "y": {"scale": "linear"}},
"legend": {"position": "bottom", "mode": "list", "customColors": None},
"chartAppearance": {"percentiles": {"enabled": None, "values": [50, 90, 99]}},
},
id="omitted_fills_defaults",
),
],
)
def test_dashboard_v2_distribution_panel_round_trips(
signoz: SigNoz,
create_user_admin: Operation, # pylint: disable=unused-argument
get_token: Callable[[str, str], str],
sent_spec: dict,
expected_spec: dict,
):
token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
headers = {"Authorization": f"Bearer {token}"}
dashboard = {
"schemaVersion": "v6",
"name": f"distribution-{uuid.uuid4().hex[:8]}",
"tags": [],
"spec": {
"variables": [],
"layouts": [],
"display": {"name": "Distribution"},
"links": [],
"panels": {
"p": {
"kind": "Panel",
"spec": {
"display": {"name": "p"},
"links": [],
"plugin": {"kind": "signoz/DistributionPanel", "spec": sent_spec},
"queries": [
{
"kind": "distribution",
"spec": {
"plugin": {
"kind": "signoz/BuilderQuery",
"spec": {
"name": "A",
"signal": "metrics",
"aggregations": [{"metricName": "http.server.request.duration", "timeAggregation": "increase", "spaceAggregation": "sum"}],
"groupBy": [{"name": "service.name"}],
},
}
},
}
],
},
}
},
},
}
response = requests.post(
signoz.self.host_configs["8080"].get(BASE_URL),
json=dashboard,
headers=headers,
timeout=5,
)
assert response.status_code == HTTPStatus.CREATED, response.text
dashboard_id = response.json()["data"]["id"]
try:
response = requests.get(
signoz.self.host_configs["8080"].get(f"{BASE_URL}/{dashboard_id}"),
headers=headers,
timeout=5,
)
assert response.status_code == HTTPStatus.OK, response.text
panel = response.json()["data"]["spec"]["panels"]["p"]["spec"]
assert panel["plugin"]["spec"] == expected_spec
assert panel["queries"][0]["kind"] == "distribution"
finally:
requests.delete(
signoz.self.host_configs["8080"].get(f"{BASE_URL}/{dashboard_id}"),
headers=headers,
timeout=5,
)