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(ruletypes): round-trip empty notificationSettings fields (#12138)
Pandey5ee1ca7d0506
diff --git a/docs/api/openapi.yml b/docs/api/openapi.ymlindex 3741f977d7..f4e75b52b6 100644--- a/docs/api/openapi.yml+++ b/docs/api/openapi.yml@@ -7571,6 +7571,7 @@ components:groupBy:items:type: string+ nullable: truetype: arraynewGroupEvalDelay:type: string@@ -7642,6 +7643,7 @@ components:alertStates:items:$ref: '#/components/schemas/RuletypesAlertState'+ nullable: truetype: arrayenabled:type: booleandiff --git a/frontend/src/api/generated/services/sigNoz.schemas.ts b/frontend/src/api/generated/services/sigNoz.schemas.tsindex 39bc0012ac..45225fccc4 100644--- a/frontend/src/api/generated/services/sigNoz.schemas.ts+++ b/frontend/src/api/generated/services/sigNoz.schemas.ts@@ -8675,9 +8675,9 @@ export interface RuletypesGettableTestRuleDTO {export interface RuletypesRenotifyDTO {/**- * @type array+ * @type array,null*/- alertStates?: RuletypesAlertStateDTO[];+ alertStates?: RuletypesAlertStateDTO[] | null;/*** @type boolean*/@@ -8690,9 +8690,9 @@ export interface RuletypesRenotifyDTO {export interface RuletypesNotificationSettingsDTO {/**- * @type array+ * @type array,null*/- groupBy?: string[];+ groupBy?: string[] | null;/*** @type string*/diff --git a/pkg/types/ruletypes/api_params.go b/pkg/types/ruletypes/api_params.goindex ed4d24de81..fc58406e90 100644--- a/pkg/types/ruletypes/api_params.go+++ b/pkg/types/ruletypes/api_params.go@@ -76,9 +76,9 @@ type PostableRule struct {}type NotificationSettings struct {- GroupBy []string `json:"groupBy,omitempty"`+ GroupBy []string `json:"groupBy,omitzero"`Renotify *Renotify `json:"renotify,omitempty"`- UsePolicy bool `json:"usePolicy,omitempty"`+ UsePolicy bool `json:"usePolicy"`// NewGroupEvalDelay is the grace period for new series to be excluded from alerts evaluationNewGroupEvalDelay valuer.TextDuration `json:"newGroupEvalDelay,omitzero"`}@@ -86,7 +86,7 @@ type NotificationSettings struct {type Renotify struct {Enabled bool `json:"enabled"`ReNotifyInterval valuer.TextDuration `json:"interval,omitzero"`- AlertStates []AlertState `json:"alertStates,omitempty"`+ AlertStates []AlertState `json:"alertStates,omitzero"`}func (ns *NotificationSettings) GetAlertManagerNotificationConfig() alertmanagertypes.NotificationConfig {diff --git a/pkg/types/ruletypes/roundtrip_test.go b/pkg/types/ruletypes/roundtrip_test.goindex 5daac5a444..b544982019 100644--- a/pkg/types/ruletypes/roundtrip_test.go+++ b/pkg/types/ruletypes/roundtrip_test.go@@ -153,9 +153,10 @@ func TestV2MinimalReadShape(t *testing.T) {var ns map[string]json.RawMessagerequire.NoError(t, json.Unmarshal(body["notificationSettings"], &ns))- for _, field := range []string{"renotify", "groupBy", "newGroupEvalDelay", "usePolicy"} {+ for _, field := range []string{"renotify", "groupBy", "newGroupEvalDelay"} {assert.NotContains(t, ns, field, "notificationSettings.%s", field)}+ assert.JSONEq(t, `false`, string(ns["usePolicy"]))assert.JSONEq(t, `false`, string(body["disabled"]))assert.JSONEq(t, `"v5"`, string(body["version"]))@@ -205,6 +206,11 @@ func TestRenotifyRoundTrip(t *testing.T) {settings: `{"renotify": {"enabled": false}}`,wantRenotify: `{"enabled": false}`,},+ {+ name: "explicitly empty alert states are echoed",+ settings: `{"renotify": {"enabled": true, "alertStates": []}}`,+ wantRenotify: `{"enabled": true, "alertStates": []}`,+ },{name: "enabled renotify with states is echoed",settings: `{"renotify": {"enabled": true, "interval": "30m", "alertStates": ["firing"]}}`,@@ -226,6 +232,59 @@ func TestRenotifyRoundTrip(t *testing.T) {}}+func TestGroupByRoundTrip(t *testing.T) {+ base := `{+ "alert": "cpu high",+ "alertType": "METRIC_BASED_ALERT",+ "ruleType": "threshold_rule",+ "schemaVersion": "v2alpha1",+ "condition": {+ "compositeQuery": {+ "queries": [{"type": "promql", "spec": {"name": "A", "query": "up"}}],+ "panelType": "graph",+ "queryType": "promql"+ },+ "thresholds": {"kind": "basic", "spec": [{"name": "critical", "target": 90, "matchType": "at_least_once", "op": "above"}]}+ },+ "evaluation": {"kind": "rolling", "spec": {"evalWindow": "5m", "frequency": "1m"}},+ "notificationSettings": %s+ }`++ cases := []struct {+ name string+ settings string+ wantGroupBy string+ }{+ {+ name: "unset group by stays absent",+ settings: `{"usePolicy": false}`,+ },+ {+ name: "explicitly empty group by is echoed",+ settings: `{"groupBy": []}`,+ wantGroupBy: `[]`,+ },+ {+ name: "populated group by is echoed",+ settings: `{"groupBy": ["service.name", "deployment.environment"]}`,+ wantGroupBy: `["service.name", "deployment.environment"]`,+ },+ }++ for _, tc := range cases {+ t.Run(tc.name, func(t *testing.T) {+ body := readBody(t, strings.Replace(base, "%s", tc.settings, 1))+ var ns map[string]json.RawMessage+ require.NoError(t, json.Unmarshal(body["notificationSettings"], &ns))+ if tc.wantGroupBy == "" {+ assert.NotContains(t, ns, "groupBy")+ } else {+ assert.JSONEq(t, tc.wantGroupBy, string(ns["groupBy"]))+ }+ })+ }+}+func TestPatchMergePreservesUnpatchedFields(t *testing.T) {stored := `{"alert": "cpu high",