Compare commits

...

3 Commits

Author SHA1 Message Date
Naman Verma
86fe6af241 fix: make right the default for secondary axis 2026-12-01 23:49:06 +05:30
Abhi Kumar
46f7998185 chore(api): regenerate openapi spec 2026-12-01 19:45:11 +05:30
Abhi Kumar
2f671cc9a7 feat(dashboards): add secondary y axes to the time series specs
Axes gains side and secondary[]; TimeSeries, Area and Bar thresholds name an
axis by id. The zero value of side is left for every axis; the editor seeds
right on a new secondary axis.
2026-12-01 19:45:09 +05:30
6 changed files with 651 additions and 38 deletions

View File

@@ -4209,9 +4209,10 @@ components:
- $ref: '#/components/schemas/DashboardtypesLegend'
description: Legend placement and series colors.
thresholds:
description: Horizontal reference lines drawn at fixed values.
description: Horizontal reference lines drawn at fixed values, each on the
primary axis or a secondary axis it names.
items:
$ref: '#/components/schemas/DashboardtypesThresholdWithLabel'
$ref: '#/components/schemas/DashboardtypesAxisThreshold'
nullable: true
type: array
visualization:
@@ -4248,6 +4249,19 @@ components:
isLogScale:
description: Whether the Y axis uses a logarithmic scale.
type: boolean
secondary:
description: Further Y axes. Series on none of them use the primary axis.
Axes on one side stack outward in array order; only the primary axis draws
gridlines.
items:
$ref: '#/components/schemas/DashboardtypesSecondaryAxis'
nullable: true
type: array
side:
allOf:
- $ref: '#/components/schemas/DashboardtypesAxisSide'
description: 'The plot edge the primary Y axis is drawn on: left (default)
or right.'
softMax:
description: The highest value the Y axis always shows; data above it still
extends the axis. Null fits the data.
@@ -4259,6 +4273,18 @@ components:
nullable: true
type: number
type: object
DashboardtypesAxisChartAppearance:
properties:
lineInterpolation:
allOf:
- $ref: '#/components/schemas/DashboardtypesLineInterpolation'
description: 'How points are joined: linear, spline, step_after or step_before.
Omit to inherit the panel.'
lineStyle:
allOf:
- $ref: '#/components/schemas/DashboardtypesLineStyle'
description: 'The line stroke: solid or dashed. Omit to inherit the panel.'
type: object
DashboardtypesAxisScale:
enum:
- auto
@@ -4266,6 +4292,38 @@ components:
- log
- symlog
type: string
DashboardtypesAxisSide:
enum:
- left
- right
type: string
DashboardtypesAxisThreshold:
properties:
axis:
description: Id of the secondary axis the line is drawn on. Empty means
the primary axis.
type: string
color:
description: 'The CSS color of the line, for example #F1575F, which matches
the SigNoz red preset; CSS named colors such as red also work.'
type: string
label:
description: The caption shown on the line.
type: string
unit:
description: The unit id of value, such as ms or percent. Empty means the
panel's unit, or the column's unit for a table threshold. Prefer the panel's
unit; a different unit works only when it converts to it, such as s against
a panel in ms.
type: string
value:
description: The value the line is drawn at, in unit.
format: double
type: number
required:
- value
- color
type: object
DashboardtypesBarChartPanelSpec:
properties:
axes:
@@ -4281,9 +4339,10 @@ components:
- $ref: '#/components/schemas/DashboardtypesLegend'
description: Legend placement and series colors.
thresholds:
description: Horizontal reference lines drawn at fixed values.
description: Horizontal reference lines drawn at fixed values, each on the
primary axis or a secondary axis it names.
items:
$ref: '#/components/schemas/DashboardtypesThresholdWithLabel'
$ref: '#/components/schemas/DashboardtypesAxisThreshold'
nullable: true
type: array
visualization:
@@ -6240,6 +6299,55 @@ components:
- value
- color
type: object
DashboardtypesSecondaryAxis:
properties:
chartAppearance:
allOf:
- $ref: '#/components/schemas/DashboardtypesAxisChartAppearance'
description: Set fields override the panel's chartAppearance for every series
on this axis. Bar ignores it.
id:
description: Unique within the panel; thresholds[].axis refers to it.
type: string
isLogScale:
description: Whether the axis uses a logarithmic scale.
type: boolean
series:
description: 'Column keys drawn on this axis: the query name for a builder
query with one aggregation (A), the query name dotted with the aggregation
expression for several (A.p99(duration_nano)), or a formula name (F1).
A key may appear on one axis only; a key the query no longer produces
is ignored.'
items:
type: string
nullable: true
type: array
side:
allOf:
- $ref: '#/components/schemas/DashboardtypesSecondaryAxisSide'
description: 'The plot edge the axis is drawn on: right (default) or left.'
softMax:
description: The highest value the axis always shows; data above it still
extends the axis. Null fits the data.
nullable: true
type: number
softMin:
description: The lowest value the axis always shows; data below it still
extends the axis. Null fits the data.
nullable: true
type: number
unit:
description: The unit id of the axis and of every series on it, such as
ms or percent. Values are labelled in it, not converted.
type: string
required:
- id
type: object
DashboardtypesSecondaryAxisSide:
enum:
- right
- left
type: string
DashboardtypesSource:
enum:
- user
@@ -6416,29 +6524,6 @@ components:
- text
- background
type: string
DashboardtypesThresholdWithLabel:
properties:
color:
description: 'The CSS color of the line, for example #F1575F, which matches
the SigNoz red preset; CSS named colors such as red also work.'
type: string
label:
description: The caption shown on the line.
type: string
unit:
description: The unit id of value, such as ms or percent. Empty means the
panel's unit, or the column's unit for a table threshold. Prefer the panel's
unit; a different unit works only when it converts to it, such as s against
a panel in ms.
type: string
value:
description: The value the line is drawn at, in unit.
format: double
type: number
required:
- value
- color
type: object
DashboardtypesTimePreference:
enum:
- global_time
@@ -6494,9 +6579,10 @@ components:
- $ref: '#/components/schemas/DashboardtypesLegend'
description: Legend placement and series colors.
thresholds:
description: Horizontal reference lines drawn at fixed values.
description: Horizontal reference lines drawn at fixed values, each on the
primary axis or a secondary axis it names.
items:
$ref: '#/components/schemas/DashboardtypesThresholdWithLabel'
$ref: '#/components/schemas/DashboardtypesAxisThreshold'
nullable: true
type: array
visualization:

View File

@@ -41,6 +41,7 @@ func newTestDashboardV2(t *testing.T, orgID valuer.UUID, source Source) *Dashboa
FillMode: FillModeSolid,
SpanGaps: SpanGaps{FillLessThan: "60s"},
},
Axes: Axes{Side: AxisSideLeft},
Legend: Legend{Position: LegendPositionBottom, Mode: LegendModeList},
},
},

View File

@@ -3212,3 +3212,156 @@ func TestNewDashboardV2RejectsReservedName(t *testing.T) {
})
}
}
func wrapTimeSeriesPanelSpec(kind, panelSpec string) []byte {
return []byte(`{
"variables": [],
"panels": {
"p1": {
"kind": "Panel",
"spec": {
"links": [],
"plugin": {"kind": "` + kind + `", "spec": ` + panelSpec + `},
"queries": [{"kind": "time_series", "spec": {"plugin": {"kind": "signoz/PromQLQuery", "spec": {"name": "A", "query": "up"}}}}]
}
}
},
"links": [],
"layouts": []
}`)
}
func TestMultipleYAxesPanelSpec(t *testing.T) {
d, err := unmarshalDashboard(wrapTimeSeriesPanelSpec("signoz/TimeSeriesPanel", `{
"formatting": {"unit": "reqps"},
"axes": {
"softMin": 0,
"side": "left",
"secondary": [
{"id": "lat", "unit": "ms", "side": "right", "softMin": 0, "softMax": 1000, "series": ["B", "C.p99(duration_ms)"], "chartAppearance": {"lineInterpolation": "step_after"}},
{"id": "pct", "unit": "percent", "isLogScale": true, "series": ["F1"], "chartAppearance": {"lineStyle": "dashed"}}
]
},
"thresholds": [
{"value": 1000, "color": "#25E192", "label": "Capacity"},
{"value": 500, "color": "#F1575F", "label": "p99 SLO", "axis": "lat"},
{"value": 0.8, "unit": "s", "color": "#F1575F", "axis": "lat"}
]
}`))
require.NoError(t, err)
spec := d.Panels["p1"].Spec.Plugin.Spec.(*TimeSeriesPanelSpec)
softMin, softMax := float64(0), float64(1000)
stepAfter, dashed := LineInterpolationStepAfter, LineStyleDashed
assert.Equal(t, Axes{
SoftMin: &softMin,
Side: AxisSideLeft,
Secondary: []SecondaryAxis{
{ID: "lat", Unit: "ms", Side: SecondaryAxisSideRight, SoftMin: &softMin, SoftMax: &softMax, Series: []string{"B", "C.p99(duration_ms)"}, ChartAppearance: &AxisChartAppearance{LineInterpolation: &stepAfter}},
{ID: "pct", Unit: "percent", IsLogScale: true, Series: []string{"F1"}, ChartAppearance: &AxisChartAppearance{LineStyle: &dashed}},
},
}, spec.Axes)
assert.Equal(t, "right", spec.Axes.Secondary[1].Side.ValueOrDefault(), "expected secondary axis side default right")
assert.Equal(t, []AxisThreshold{
{ThresholdWithLabel: ThresholdWithLabel{Value: 1000, Color: "#25E192", Label: "Capacity"}},
{ThresholdWithLabel: ThresholdWithLabel{Value: 500, Color: "#F1575F", Label: "p99 SLO"}, Axis: "lat"},
{ThresholdWithLabel: ThresholdWithLabel{Value: 0.8, Unit: "s", Color: "#F1575F"}, Axis: "lat"},
}, spec.Thresholds)
// Enum zero values marshal as their defaults, so the round trip is compared as JSON.
stored, err := json.Marshal(d)
require.NoError(t, err)
reread, err := unmarshalDashboard(stored)
require.NoError(t, err)
restored, err := json.Marshal(reread)
require.NoError(t, err)
assert.JSONEq(t, string(stored), string(restored))
}
// Without side or secondary the axes read as one left axis; a threshold without axis sits on it.
func TestMultipleYAxesDefaults(t *testing.T) {
for _, kind := range []string{"signoz/TimeSeriesPanel", "signoz/AreaChartPanel", "signoz/BarChartPanel"} {
t.Run(kind, func(t *testing.T) {
d, err := unmarshalDashboard(wrapTimeSeriesPanelSpec(kind, `{"axes": {"softMin": 0, "isLogScale": true}, "thresholds": [{"value": 1, "color": "red"}]}`))
require.NoError(t, err)
stored, err := json.Marshal(d.Panels["p1"].Spec.Plugin.Spec)
require.NoError(t, err)
assert.Contains(t, string(stored), `"side":"left"`)
assert.Contains(t, string(stored), `"secondary":null`)
assert.Contains(t, string(stored), `"axis":""`)
})
}
}
func TestInvalidateMultipleYAxesValues(t *testing.T) {
testCases := []struct {
name string
panelKind string
panelSpec string
expectedErrorSubstring string
}{
{
name: "SecondaryID_Missing",
panelKind: "signoz/TimeSeriesPanel",
panelSpec: `{"axes": {"secondary": [{"unit": "ms"}]}}`,
expectedErrorSubstring: "Field validation for 'ID' failed on the 'required' tag",
},
{
name: "SecondaryID_Duplicate",
panelKind: "signoz/AreaChartPanel",
panelSpec: `{"axes": {"secondary": [{"id": "a"}, {"id": "a"}]}}`,
expectedErrorSubstring: `axes.secondary[1].id "a" is already used by another axis`,
},
{
name: "SeriesKey_OnTwoAxes",
panelKind: "signoz/BarChartPanel",
panelSpec: `{"axes": {"secondary": [{"id": "a", "series": ["B"]}, {"id": "b", "series": ["C", "B"]}]}}`,
expectedErrorSubstring: `axes.secondary[1].series: "B" is already on axis "a"`,
},
{
name: "ThresholdAxis_Unknown",
panelKind: "signoz/TimeSeriesPanel",
panelSpec: `{"axes": {"secondary": [{"id": "a"}]}, "thresholds": [{"value": 1, "color": "red", "axis": "b"}]}`,
expectedErrorSubstring: `thresholds[0].axis "b" matches no axes.secondary id`,
},
{
name: "AxisSide_Unknown",
panelKind: "signoz/TimeSeriesPanel",
panelSpec: `{"axes": {"side": "top"}}`,
expectedErrorSubstring: "invalid axis side \"top\": must be `left` or `right`",
},
{
name: "AxisSide_ExplicitEmpty",
panelKind: "signoz/TimeSeriesPanel",
panelSpec: `{"axes": {"side": ""}}`,
expectedErrorSubstring: "invalid axis side \"\": must be `left` or `right`",
},
{
name: "SecondaryAxisSide_Unknown",
panelKind: "signoz/AreaChartPanel",
panelSpec: `{"axes": {"secondary": [{"id": "a", "side": "top"}]}}`,
expectedErrorSubstring: "invalid secondary axis side \"top\": must be `right` or `left`",
},
{
name: "SecondaryAppearance_ExplicitEmptyLineStyle",
panelKind: "signoz/TimeSeriesPanel",
panelSpec: `{"axes": {"secondary": [{"id": "a", "chartAppearance": {"lineStyle": ""}}]}}`,
expectedErrorSubstring: "invalid line style \"\": must be `solid` or `dashed`",
},
{
name: "SecondaryAppearance_UnknownField",
panelKind: "signoz/TimeSeriesPanel",
panelSpec: `{"axes": {"secondary": [{"id": "a", "chartAppearance": {"showPoints": true}}]}}`,
expectedErrorSubstring: "unknown field",
},
}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
_, err := unmarshalDashboard(wrapTimeSeriesPanelSpec(testCase.panelKind, testCase.panelSpec))
require.Error(t, err)
assert.Contains(t, err.Error(), testCase.expectedErrorSubstring, "unexpected error message: %s", err.Error())
})
}
}

View File

@@ -223,7 +223,11 @@ type TimeSeriesPanelSpec struct {
ChartAppearance TimeSeriesChartAppearance `json:"chartAppearance" description:"Line drawing options."`
Axes Axes `json:"axes" description:"Y axis bounds and scale."`
Legend Legend `json:"legend" description:"Legend placement and series colors."`
Thresholds []ThresholdWithLabel `json:"thresholds" validate:"dive" description:"Horizontal reference lines drawn at fixed values."`
Thresholds []AxisThreshold `json:"thresholds" validate:"dive" description:"Horizontal reference lines drawn at fixed values, each on the primary axis or a secondary axis it names."`
}
func (s TimeSeriesPanelSpec) validate() error {
return validateAxes(s.Axes, s.Thresholds)
}
type TimeSeriesChartAppearance struct {
@@ -239,7 +243,11 @@ type BarChartPanelSpec struct {
Formatting PanelFormatting `json:"formatting" description:"Unit and decimal precision of the values."`
Axes Axes `json:"axes" description:"Y axis bounds and scale."`
Legend Legend `json:"legend" description:"Legend placement and series colors."`
Thresholds []ThresholdWithLabel `json:"thresholds" validate:"dive" description:"Horizontal reference lines drawn at fixed values."`
Thresholds []AxisThreshold `json:"thresholds" validate:"dive" description:"Horizontal reference lines drawn at fixed values, each on the primary axis or a secondary axis it names."`
}
func (s BarChartPanelSpec) validate() error {
return validateAxes(s.Axes, s.Thresholds)
}
type AreaChartPanelSpec struct {
@@ -248,7 +256,11 @@ type AreaChartPanelSpec struct {
ChartAppearance AreaChartAppearance `json:"chartAppearance" description:"Line and fill drawing options."`
Axes Axes `json:"axes" description:"Y axis bounds and scale."`
Legend Legend `json:"legend" description:"Legend placement and series colors."`
Thresholds []ThresholdWithLabel `json:"thresholds" validate:"dive" description:"Horizontal reference lines drawn at fixed values."`
Thresholds []AxisThreshold `json:"thresholds" validate:"dive" description:"Horizontal reference lines drawn at fixed values, each on the primary axis or a secondary axis it names."`
}
func (s AreaChartPanelSpec) validate() error {
return validateAxes(s.Axes, s.Thresholds)
}
// AreaChartAppearance repeats the line-drawing fields rather than embedding
@@ -686,9 +698,53 @@ type TextPresentation struct {
// ══════════════════════════════════════════════
type Axes struct {
SoftMin *float64 `json:"softMin" description:"The lowest value the Y axis always shows; data below it still extends the axis. Null fits the data."`
SoftMax *float64 `json:"softMax" description:"The highest value the Y axis always shows; data above it still extends the axis. Null fits the data."`
IsLogScale bool `json:"isLogScale" description:"Whether the Y axis uses a logarithmic scale."`
SoftMin *float64 `json:"softMin" description:"The lowest value the Y axis always shows; data below it still extends the axis. Null fits the data."`
SoftMax *float64 `json:"softMax" description:"The highest value the Y axis always shows; data above it still extends the axis. Null fits the data."`
IsLogScale bool `json:"isLogScale" description:"Whether the Y axis uses a logarithmic scale."`
Side AxisSide `json:"side" description:"The plot edge the primary Y axis is drawn on: left (default) or right."`
Secondary []SecondaryAxis `json:"secondary" validate:"dive" description:"Further Y axes. Series on none of them use the primary axis. Axes on one side stack outward in array order; only the primary axis draws gridlines."`
}
type SecondaryAxis struct {
ID string `json:"id" validate:"required" required:"true" description:"Unique within the panel; thresholds[].axis refers to it."`
Unit string `json:"unit" description:"The unit id of the axis and of every series on it, such as ms or percent. Values are labelled in it, not converted."`
Side SecondaryAxisSide `json:"side" description:"The plot edge the axis is drawn on: right (default) or left."`
SoftMin *float64 `json:"softMin" description:"The lowest value the axis always shows; data below it still extends the axis. Null fits the data."`
SoftMax *float64 `json:"softMax" description:"The highest value the axis always shows; data above it still extends the axis. Null fits the data."`
IsLogScale bool `json:"isLogScale" description:"Whether the axis uses a logarithmic scale."`
Series []string `json:"series" description:"Column keys drawn on this axis: the query name for a builder query with one aggregation (A), the query name dotted with the aggregation expression for several (A.p99(duration_nano)), or a formula name (F1). A key may appear on one axis only; a key the query no longer produces is ignored."`
ChartAppearance *AxisChartAppearance `json:"chartAppearance" description:"Set fields override the panel's chartAppearance for every series on this axis. Bar ignores it."`
}
type AxisChartAppearance struct {
LineInterpolation *LineInterpolation `json:"lineInterpolation,omitempty" description:"How points are joined: linear, spline, step_after or step_before. Omit to inherit the panel."`
LineStyle *LineStyle `json:"lineStyle,omitempty" description:"The line stroke: solid or dashed. Omit to inherit the panel."`
}
func validateAxes(axes Axes, thresholds []AxisThreshold) error {
ids := make(map[string]struct{}, len(axes.Secondary))
seriesAxis := map[string]string{}
for i, axis := range axes.Secondary {
if _, dup := ids[axis.ID]; dup {
return errors.NewInvalidInputf(ErrCodeDashboardInvalidInput, "axes.secondary[%d].id %q is already used by another axis", i, axis.ID)
}
ids[axis.ID] = struct{}{}
for _, key := range axis.Series {
if owner, dup := seriesAxis[key]; dup {
return errors.NewInvalidInputf(ErrCodeDashboardInvalidInput, "axes.secondary[%d].series: %q is already on axis %q", i, key, owner)
}
seriesAxis[key] = axis.ID
}
}
for i, threshold := range thresholds {
if threshold.Axis == "" {
continue
}
if _, ok := ids[threshold.Axis]; !ok {
return errors.NewInvalidInputf(ErrCodeDashboardInvalidInput, "thresholds[%d].axis %q matches no axes.secondary id", i, threshold.Axis)
}
}
return nil
}
// HeaderOptions controls the panel card's header strip — the title/description
@@ -756,6 +812,11 @@ type ComparisonThreshold struct {
Format ThresholdFormat `json:"format" description:"What the color is applied to: text (default) or background."`
}
type AxisThreshold struct {
ThresholdWithLabel
Axis string `json:"axis" description:"Id of the secondary axis the line is drawn on. Empty means the primary axis."`
}
type ScatterPlotThreshold struct {
ThresholdWithLabel
Axis ThresholdAxis `json:"axis" description:"The axis the line marks: y (default) draws it horizontally, x vertically. Unit converts against that axis's column unit, and the axis extends to keep the line in view."`
@@ -1098,6 +1159,83 @@ func (as *AxisScale) UnmarshalJSON(data []byte) error {
}
}
// AxisSide is the plot edge a Y axis is drawn on.
type AxisSide struct{ valuer.String }
var (
AxisSideLeft = AxisSide{valuer.NewString("left")} // default
AxisSideRight = AxisSide{valuer.NewString("right")}
)
func (AxisSide) Enum() []any {
return []any{AxisSideLeft, AxisSideRight}
}
func (as AxisSide) ValueOrDefault() string {
if as.IsZero() {
return AxisSideLeft.StringValue()
}
return as.StringValue()
}
func (as AxisSide) MarshalJSON() ([]byte, error) {
return json.Marshal(as.ValueOrDefault())
}
func (as *AxisSide) UnmarshalJSON(data []byte) error {
var v string
if err := json.Unmarshal(data, &v); err != nil {
return errors.WrapInvalidInputf(err, ErrCodeDashboardInvalidInput, "invalid axis side: must be a string, one of `left` or `right`")
}
val := AxisSide{valuer.NewString(v)}
switch val {
case AxisSideLeft, AxisSideRight:
*as = val
return nil
default:
return errors.NewInvalidInputf(ErrCodeDashboardInvalidInput, "invalid axis side %q: must be `left` or `right`", v)
}
}
// SecondaryAxisSide repeats AxisSide with the opposite default: a secondary
// axis sits across the plot from the primary one unless moved.
type SecondaryAxisSide struct{ valuer.String }
var (
SecondaryAxisSideRight = SecondaryAxisSide{valuer.NewString("right")} // default
SecondaryAxisSideLeft = SecondaryAxisSide{valuer.NewString("left")}
)
func (SecondaryAxisSide) Enum() []any {
return []any{SecondaryAxisSideRight, SecondaryAxisSideLeft}
}
func (ss SecondaryAxisSide) ValueOrDefault() string {
if ss.IsZero() {
return SecondaryAxisSideRight.StringValue()
}
return ss.StringValue()
}
func (ss SecondaryAxisSide) MarshalJSON() ([]byte, error) {
return json.Marshal(ss.ValueOrDefault())
}
func (ss *SecondaryAxisSide) UnmarshalJSON(data []byte) error {
var v string
if err := json.Unmarshal(data, &v); err != nil {
return errors.WrapInvalidInputf(err, ErrCodeDashboardInvalidInput, "invalid secondary axis side: must be a string, one of `right` or `left`")
}
val := SecondaryAxisSide{valuer.NewString(v)}
switch val {
case SecondaryAxisSideRight, SecondaryAxisSideLeft:
*ss = val
return nil
default:
return errors.NewInvalidInputf(ErrCodeDashboardInvalidInput, "invalid secondary axis side %q: must be `right` or `left`", v)
}
}
// ThresholdAxis is the axis a scatter plot threshold line marks: `y` draws it
// horizontally, `x` vertically.
type ThresholdAxis struct{ valuer.String }

View File

@@ -392,12 +392,12 @@ func mapV1SpanGaps(raw any) SpanGaps {
return SpanGaps{FillOnlyBelow: false}
}
func (d *v1Decoder) mapV1ThresholdsWithLabel(w map[string]any) []ThresholdWithLabel {
func (d *v1Decoder) mapV1ThresholdsWithLabel(w map[string]any) []AxisThreshold {
rawSlice := d.readObjects(w, "thresholds")
if len(rawSlice) == 0 {
return nil
}
out := make([]ThresholdWithLabel, 0, len(rawSlice))
out := make([]AxisThreshold, 0, len(rawSlice))
for _, t := range rawSlice {
color := d.readString(t, "thresholdColor")
if color == "" {
@@ -406,7 +406,7 @@ func (d *v1Decoder) mapV1ThresholdsWithLabel(w map[string]any) []ThresholdWithLa
continue
}
value := d.readFloat(t, "thresholdValue")
out = append(out, ThresholdWithLabel{Value: value, Unit: d.readString(t, "thresholdUnit"), Color: color, Label: d.readString(t, "thresholdLabel")})
out = append(out, AxisThreshold{ThresholdWithLabel: ThresholdWithLabel{Value: value, Unit: d.readString(t, "thresholdUnit"), Color: color, Label: d.readString(t, "thresholdLabel")}})
}
if len(out) == 0 {
return nil

View File

@@ -2255,3 +2255,238 @@ 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
# ─── secondary y axes ────────────────────────────────────────────────────────
@pytest.mark.parametrize(
"plugin_spec, message",
[
({"axes": {"side": ""}}, 'invalid axis side "": must be `left` or `right`'),
({"axes": {"secondary": [{"id": "a", "side": ""}]}}, 'invalid secondary axis side "": must be `right` or `left`'),
(
{"axes": {"secondary": [{"id": "a", "chartAppearance": {"lineStyle": ""}}]}},
'invalid line style "": must be `solid` or `dashed`',
),
(
{"axes": {"secondary": [{"id": "a", "chartAppearance": {"lineInterpolation": ""}}]}},
'invalid line interpolation "": must be `linear`, `spline`, `step_after`, or `step_before`',
),
],
ids=["primary_side", "secondary_side", "secondary_line_style", "secondary_line_interpolation"],
)
def test_dashboard_v2_rejects_explicit_empty_axis_enum(
signoz: SigNoz,
create_user_admin: Operation, # pylint: disable=unused-argument
get_token: Callable[[str, str], str],
plugin_spec: dict,
message: str,
):
token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
response = requests.post(
signoz.self.host_configs["8080"].get(BASE_URL),
json={
"schemaVersion": "v6",
"name": f"axes-{uuid.uuid4().hex[:8]}",
"tags": [],
"spec": {
"variables": [],
"layouts": [],
"display": {"name": "Axes"},
"links": [],
"panels": {
"ts": {
"kind": "Panel",
"spec": {
"display": {"name": "ts"},
"links": [],
"plugin": {"kind": "signoz/TimeSeriesPanel", "spec": plugin_spec},
"queries": [
{
"kind": "time_series",
"spec": {
"plugin": {
"kind": "signoz/BuilderQuery",
"spec": {"name": "A", "signal": "logs", "aggregations": [{"expression": "count()"}]},
}
},
}
],
},
}
},
},
},
headers={"Authorization": f"Bearer {token}"},
timeout=5,
)
assert response.status_code == HTTPStatus.BAD_REQUEST, response.text
assert response.json()["error"]["code"] == "dashboard_invalid_input", response.text
assert message in response.json()["error"]["message"], response.text
def test_dashboard_v2_secondary_axes_round_trip(
signoz: SigNoz,
create_user_admin: Operation, # pylint: disable=unused-argument
get_token: Callable[[str, str], str],
):
token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
headers = {"Authorization": f"Bearer {token}"}
query = {
"kind": "time_series",
"spec": {
"plugin": {
"kind": "signoz/BuilderQuery",
"spec": {"name": "A", "signal": "logs", "aggregations": [{"expression": "count()"}]},
}
},
}
response = requests.post(
signoz.self.host_configs["8080"].get(BASE_URL),
json={
"schemaVersion": "v6",
"name": f"axes-{uuid.uuid4().hex[:8]}",
"tags": [],
"spec": {
"variables": [],
"layouts": [],
"display": {"name": "Axes"},
"links": [],
"panels": {
"ts": {
"kind": "Panel",
"spec": {
"display": {"name": "ts"},
"links": [],
"plugin": {
"kind": "signoz/TimeSeriesPanel",
"spec": {
"axes": {
"softMin": 0,
"secondary": [
{
"id": "lat",
"unit": "ms",
"softMax": 1000,
"series": ["B", "C.p99(duration_ms)"],
"chartAppearance": {"lineStyle": "dashed"},
},
{
"id": "pct",
"unit": "",
"side": "left",
"softMin": None,
"isLogScale": True,
"series": [],
"chartAppearance": {},
},
{"id": "bare"},
],
},
"thresholds": [
{"value": 500, "color": "#F1575F", "label": "p99 SLO", "axis": "lat"},
{"value": 1000, "unit": "", "color": "#25E192", "label": "", "axis": ""},
{"value": 2000, "color": "#25E192"},
],
},
},
"queries": [query],
},
},
"bar": {
"kind": "Panel",
"spec": {
"display": {"name": "bar"},
"links": [],
"plugin": {"kind": "signoz/BarChartPanel", "spec": {"axes": {"side": "right", "secondary": []}}},
"queries": [query],
},
},
"area": {
"kind": "Panel",
"spec": {
"display": {"name": "area"},
"links": [],
"plugin": {"kind": "signoz/AreaChartPanel", "spec": {}},
"queries": [query],
},
},
},
},
},
headers=headers,
timeout=5,
)
assert response.status_code == HTTPStatus.CREATED, response.text
dashboard_id = response.json()["data"]["id"]
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
panels = response.json()["data"]["spec"]["panels"]
ts = panels["ts"]["spec"]["plugin"]["spec"]
assert ts["axes"] == {
"softMin": 0,
"softMax": None,
"isLogScale": False,
"side": "left",
"secondary": [
{
"id": "lat",
"unit": "ms",
"side": "right",
"softMin": None,
"softMax": 1000,
"isLogScale": False,
"series": ["B", "C.p99(duration_ms)"],
"chartAppearance": {"lineStyle": "dashed"},
},
{
"id": "pct",
"unit": "",
"side": "left",
"softMin": None,
"softMax": None,
"isLogScale": True,
"series": [],
"chartAppearance": {},
},
{
"id": "bare",
"unit": "",
"side": "right",
"softMin": None,
"softMax": None,
"isLogScale": False,
"series": None,
"chartAppearance": None,
},
],
}
assert ts["thresholds"] == [
{"value": 500, "unit": "", "color": "#F1575F", "label": "p99 SLO", "axis": "lat"},
{"value": 1000, "unit": "", "color": "#25E192", "label": "", "axis": ""},
{"value": 2000, "unit": "", "color": "#25E192", "label": "", "axis": ""},
]
assert panels["bar"]["spec"]["plugin"]["spec"]["axes"] == {
"softMin": None,
"softMax": None,
"isLogScale": False,
"side": "right",
"secondary": [],
}
assert panels["area"]["spec"]["plugin"]["spec"]["axes"] == {
"softMin": None,
"softMax": None,
"isLogScale": False,
"side": "left",
"secondary": None,
}