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
refactor: PostableRule struct (#9448)
Abhishek Kumar Singh1a193015a79d
diff --git a/pkg/types/ruletypes/api_params.go b/pkg/types/ruletypes/api_params.goindex f206b64860..c135e67db3 100644--- a/pkg/types/ruletypes/api_params.go+++ b/pkg/types/ruletypes/api_params.go@@ -180,7 +180,9 @@ func (ns *NotificationSettings) UnmarshalJSON(data []byte) error {return nil}-func (r *PostableRule) processRuleDefaults() error {+// processRuleDefaults applies the default values+// for the rule options that are blank or unset.+func (r *PostableRule) processRuleDefaults() {if r.SchemaVersion == "" {r.SchemaVersion = DefaultSchemaVersion@@ -195,11 +197,12 @@ func (r *PostableRule) processRuleDefaults() error {}if r.RuleCondition != nil {- if r.RuleCondition.CompositeQuery.QueryType == v3.QueryTypeBuilder {+ switch r.RuleCondition.CompositeQuery.QueryType {+ case v3.QueryTypeBuilder:if r.RuleType == "" {r.RuleType = RuleTypeThreshold}- } else if r.RuleCondition.CompositeQuery.QueryType == v3.QueryTypePromQL {+ case v3.QueryTypePromQL:r.RuleType = RuleTypeProm}@@ -250,8 +253,6 @@ func (r *PostableRule) processRuleDefaults() error {}}}-- return r.Validate()}func (r *PostableRule) MarshalJSON() ([]byte, error) {@@ -281,7 +282,8 @@ func (r *PostableRule) UnmarshalJSON(bytes []byte) error {if err := json.Unmarshal(bytes, aux); err != nil {return signozError.NewInvalidInputf(signozError.CodeInvalidInput, "failed to parse json: %v", err)}- return r.processRuleDefaults()+ r.processRuleDefaults()+ return r.validate()}func isValidLabelName(ln string) bool {@@ -339,17 +341,16 @@ func isAllQueriesDisabled(compositeQuery *v3.CompositeQuery) bool {return true}-func (r *PostableRule) Validate() error {+func (r *PostableRule) validate() error {var errs []errorif r.RuleCondition == nil {// will get panic if we try to access CompositeQuery, so return herereturn signozError.NewInvalidInputf(signozError.CodeInvalidInput, "rule condition is required")- } else {- if r.RuleCondition.CompositeQuery == nil {- errs = append(errs, signozError.NewInvalidInputf(signozError.CodeInvalidInput, "composite metric query is required"))- }+ }+ if r.RuleCondition.CompositeQuery == nil {+ errs = append(errs, signozError.NewInvalidInputf(signozError.CodeInvalidInput, "composite query is required"))}if isAllQueriesDisabled(r.RuleCondition.CompositeQuery) {