SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.
TypeScript apmapplication-monitoringdistributed-tracinggogood-first-issuejaegerloglogsmetricsmonitoringnextjsobservabilityopen-sourceopentelemetryprometheusreactreactjsself-hostedtracingtypescript
fix: make span gaps accept day and week as units (#12065)
Naman Vermacede9ffc4c57
diff --git a/pkg/types/dashboardtypes/perses_dashboard_convertors_test.go b/pkg/types/dashboardtypes/perses_dashboard_convertors_test.goindex a3d306d3c6..71f52a18db 100644--- a/pkg/types/dashboardtypes/perses_dashboard_convertors_test.go+++ b/pkg/types/dashboardtypes/perses_dashboard_convertors_test.go@@ -38,7 +38,7 @@ func newTestDashboardV2(t *testing.T, orgID valuer.UUID, source Source) *DashboaLineInterpolation: LineInterpolationSpline,LineStyle: LineStyleSolid,FillMode: FillModeSolid,- SpanGaps: SpanGaps{FillLessThan: valuer.MustParseTextDuration("60s")},+ SpanGaps: SpanGaps{FillLessThan: "60s"},},Legend: Legend{Position: LegendPositionBottom, Mode: LegendModeList},},diff --git a/pkg/types/dashboardtypes/perses_dashboard_test.go b/pkg/types/dashboardtypes/perses_dashboard_test.goindex 218eb3c4ae..e86e40cea1 100644--- a/pkg/types/dashboardtypes/perses_dashboard_test.go+++ b/pkg/types/dashboardtypes/perses_dashboard_test.go@@ -6,7 +6,6 @@ import ("os""strings""testing"- "time""github.com/SigNoz/signoz/pkg/errors""github.com/perses/spec/go/dashboard"@@ -753,7 +752,7 @@ func TestInvalidateBadPanelSpecValues(t *testing.T) {"spec": {"plugin": {"kind": "signoz/TimeSeriesPanel",- "spec": {"chartAppearance": {"spanGaps": {"fillLessThan": "notaduration"}}}+ "spec": {"chartAppearance": {"spanGaps": {"fillOnlyBelow": true, "fillLessThan": "notaduration"}}}}}}@@ -1371,23 +1370,49 @@ func TestSpanGaps(t *testing.T) {t.Run("defaults", func(t *testing.T) {var sg SpanGapsassert.False(t, sg.FillOnlyBelow, "expected FillOnlyBelow default false")- assert.True(t, sg.FillLessThan.IsZero(), "expected FillLessThan default zero")+ assert.Empty(t, sg.FillLessThan, "expected FillLessThan default empty")})t.Run("fillOnlyBelow true", func(t *testing.T) {- sg := unmarshal(t, `{"fillOnlyBelow": true}`)+ sg := unmarshal(t, `{"fillOnlyBelow": true, "fillLessThan": "5m"}`)assert.True(t, sg.FillOnlyBelow)})- t.Run("fillLessThan duration", func(t *testing.T) {- sg := unmarshal(t, `{"fillOnlyBelow": false, "fillLessThan": "5m"}`)+ t.Run("fillLessThan ignored when fillOnlyBelow is false", func(t *testing.T) {+ sg := unmarshal(t, `{"fillOnlyBelow": false, "fillLessThan": ""}`)assert.False(t, sg.FillOnlyBelow)- assert.Equal(t, 5*time.Minute, sg.FillLessThan.Duration())+ assert.Empty(t, sg.FillLessThan)+ })++ t.Run("fillLessThan duration", func(t *testing.T) {+ sg := unmarshal(t, `{"fillOnlyBelow": true, "fillLessThan": "5m"}`)+ assert.True(t, sg.FillOnlyBelow)+ assert.Equal(t, "5m", sg.FillLessThan)})t.Run("fillLessThan compound duration", func(t *testing.T) {- sg := unmarshal(t, `{"fillLessThan": "1h30m"}`)- assert.Equal(t, 90*time.Minute, sg.FillLessThan.Duration())+ sg := unmarshal(t, `{"fillOnlyBelow": true, "fillLessThan": "1h30m"}`)+ assert.Equal(t, "1h30m", sg.FillLessThan)+ })++ t.Run("fillLessThan day duration", func(t *testing.T) {+ sg := unmarshal(t, `{"fillOnlyBelow": true, "fillLessThan": "1d"}`)+ assert.Equal(t, "1d", sg.FillLessThan)+ })++ t.Run("fillLessThan required when fillOnlyBelow is true", func(t *testing.T) {+ var sg SpanGaps+ require.Error(t, json.Unmarshal([]byte(`{"fillOnlyBelow": true}`), &sg))+ })++ t.Run("invalid fillLessThan rejected on unmarshal", func(t *testing.T) {+ var sg SpanGaps+ require.Error(t, json.Unmarshal([]byte(`{"fillOnlyBelow": true, "fillLessThan": "not-a-duration"}`), &sg))+ })++ t.Run("non-positive fillLessThan rejected on unmarshal", func(t *testing.T) {+ var sg SpanGaps+ require.Error(t, json.Unmarshal([]byte(`{"fillOnlyBelow": true, "fillLessThan": "0s"}`), &sg))})}diff --git a/pkg/types/dashboardtypes/perses_signoz_plugins.go b/pkg/types/dashboardtypes/perses_signoz_plugins.goindex 72febacf22..20b7903d8f 100644--- a/pkg/types/dashboardtypes/perses_signoz_plugins.go+++ b/pkg/types/dashboardtypes/perses_signoz_plugins.go@@ -8,6 +8,7 @@ import (qb "github.com/SigNoz/signoz/pkg/types/querybuildertypes/querybuildertypesv5""github.com/SigNoz/signoz/pkg/types/telemetrytypes""github.com/SigNoz/signoz/pkg/valuer"+ "github.com/prometheus/common/model""github.com/swaggest/jsonschema-go")@@ -621,8 +622,39 @@ func (fm *FillMode) UnmarshalJSON(data []byte) error {}type SpanGaps struct {- FillOnlyBelow bool `json:"fillOnlyBelow" description:"Controls whether lines connect across null values. When false (default), all gaps are connected. When true, only gaps smaller than fillLessThan are connected."`- FillLessThan valuer.TextDuration `json:"fillLessThan" description:"The maximum gap size to connect when fillOnlyBelow is true. Gaps larger than this duration are left disconnected."`+ FillOnlyBelow bool `json:"fillOnlyBelow" description:"Controls whether lines connect across null values. When false (default), all gaps are connected. When true, only gaps smaller than fillLessThan are connected."`+ FillLessThan string `json:"fillLessThan" description:"The maximum gap size to connect when fillOnlyBelow is true. Gaps larger than this duration are left disconnected."`+}++func (sg *SpanGaps) UnmarshalJSON(data []byte) error {+ type alias SpanGaps+ var tmp alias+ if err := json.Unmarshal(data, &tmp); err != nil {+ return errors.WrapInvalidInputf(err, ErrCodeDashboardInvalidInput, "invalid spanGaps")+ }+ *sg = SpanGaps(tmp)+ return sg.validate()+}++// validate enforces FillLessThan only when FillOnlyBelow is set, since that is+// the only mode in which it applies. It must then be a valid positive duration.+// prometheus's parser accepts day/week/year units (e.g. "1d"); time.ParseDuration+// caps at hours.+func (sg SpanGaps) validate() error {+ if !sg.FillOnlyBelow {+ return nil+ }+ if sg.FillLessThan == "" {+ return errors.NewInvalidInputf(ErrCodeDashboardInvalidInput, "spanGaps.fillLessThan is required when fillOnlyBelow is true")+ }+ d, err := model.ParseDuration(sg.FillLessThan)+ if err != nil {+ return errors.WrapInvalidInputf(err, ErrCodeDashboardInvalidInput, "invalid spanGaps.fillLessThan duration %q", sg.FillLessThan)+ }+ if d <= 0 {+ return errors.NewInvalidInputf(ErrCodeDashboardInvalidInput, "spanGaps.fillLessThan duration must be positive, got %q", sg.FillLessThan)+ }+ return nil}type PrecisionOption struct{ valuer.String }diff --git a/pkg/types/dashboardtypes/testdata/perses_with_sections.json b/pkg/types/dashboardtypes/testdata/perses_with_sections.jsonindex be7d7b01e9..92591421c5 100644--- a/pkg/types/dashboardtypes/testdata/perses_with_sections.json+++ b/pkg/types/dashboardtypes/testdata/perses_with_sections.json@@ -76,7 +76,7 @@"showPoints": false,"lineStyle": "solid","fillMode": "none",- "spanGaps": {"fillOnlyBelow": true}+ "spanGaps": {"fillOnlyBelow": true, "fillLessThan": "5m"}},"legend": {"position": "bottom"