Skip to content

chore: validate alert payload before saving#9872

Closed
abhishekhugetech wants to merge 119 commits intomainfrom
fix/validate_alert_payload_before_saving
Closed

chore: validate alert payload before saving#9872
abhishekhugetech wants to merge 119 commits intomainfrom
fix/validate_alert_payload_before_saving

Conversation

@abhishekhugetech
Copy link
Copy Markdown
Contributor

@abhishekhugetech abhishekhugetech commented Dec 26, 2025

📄 Summary

We're breaking the PR into smaller PRs for limiting the surface area for review and reducing blast radius.


✅ Changes

  • Feature: Brief description
  • Bug fix: Brief description

🏷️ Required: Add Relevant Labels

⚠️ Manually add appropriate labels in the PR sidebar
Please select one or more labels (as applicable):

ex:

  • frontend
  • backend
  • devops
  • bug
  • enhancement
  • ui
  • test

👥 Reviewers

Tag the relevant teams for review:

  • frontend / backend / devops

🧪 How to Test

  1. ...
  2. ...
  3. ...

🔍 Related Issues

Closes #


📸 Screenshots / Screen Recording (if applicable / mandatory for UI related changes)


📋 Checklist

  • Dev Review
  • Test cases added (Unit/ Integration / E2E)
  • Manually tested the changes

👀 Notes for Reviewers

  • Disabling alerts won't work if existing alert has wrong values present (old alerts)
  • We had to apply the value for CH query template as the queries in template format were syntactically incorrect
  • For validating the CH query we're using the clickhouse-sql-parser which doesn't complexly validates the syntax of CH queries, need to find some more robust approach to validate the CH query

Note

Strengthens backend validation and error handling for alerts/rules and queries.

  • Add CompositeQuery.Validate() with unit checks, PromQL and ClickHouse SQL syntax validation, and "no all-disabled" enforcement; new helpers in validation.go with tests
  • Validate formula/functions/join specs (Function.Validate, FunctionName.Validate, JoinType.Validate, QueryBuilderJoin.Validate, QueryBuilderFormula.Validate); export GetQueryIdentifier
  • Validate rule payloads on create/edit/patch/test in rules manager; return BadRequest on invalid inputs; add stricter RuleCondition/PostableRule validations (alert/rule type, version, seasonality, selectedQuery)
  • HTTP handlers now propagate existing *model.ApiError directly
  • Replace AssignReservedVarsV3 with AssignReservedVars and update all call sites (parser, threshold rules); pre-render CH templates before parsing
  • Add unit validation utilities in converter (Unit.Validate, IsValidUnit)
  • Minor error wrapping improvement and test updates

Written by Cursor Bugbot for commit b8da56b. This will update automatically on new commits. Configure here.

abhishekhugetech and others added 30 commits November 10, 2025 20:05
…iven columnName till the very end to return the origin column with given name
Comment thread pkg/types/ruletypes/api_params.go
Comment thread pkg/types/ruletypes/alerting.go
Comment thread pkg/query-service/rules/manager.go
Comment thread pkg/query-service/model/v3/v3.go
Base automatically changed from feat/exclude_new_series_from_alert to main January 9, 2026 17:56
@srikanthccv
Copy link
Copy Markdown
Member

This turned out to be pretty big, and too many touching parts. I am wondering if we should break this down.

Comment thread pkg/query-service/model/v3/validation.go Outdated
Comment thread pkg/query-service/model/v3/v3.go
Comment thread pkg/query-service/converter/converter.go
Comment thread pkg/query-service/model/v3/validation.go
}
}
return nil
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ClickHouse validation uses different variable patterns than runtime

High Severity

The validateClickHouseQuery function only handles Go template syntax ({{.key}}), but runtime code in parser.go first replaces {{key}} (without dot), [[key]], and $key patterns via string replacement before Go template execution. Queries using {{start_timestamp}} (the common pattern without the dot) will fail validation with "failed to execute clickhouse query template" because Go templates interpret {{start_timestamp}} as a function call rather than a variable access. This rejects valid queries that work correctly at runtime.

Fix in Cursor Fix in Web

Comment thread pkg/types/ruletypes/api_params.go
}
if strings.TrimSpace(q.On) == "" {
return errors.NewInvalidInputf(errors.CodeInvalidInput, "on is required")
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cross join validation incorrectly requires ON clause

Medium Severity

The QueryBuilderJoin.Validate() method requires the On field to be non-empty for all join types. However, JoinTypeCross (cross join) is a supported join type that in SQL doesn't require an ON clause - it produces a Cartesian product. Valid cross joins without an On clause would fail validation with "on is required" error.

Fix in Cursor Fix in Web

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

return errors.NewInvalidInputf(errors.CodeInvalidInput, "on is required")
}
return nil
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Join query references not validated against existing queries

Medium Severity

The QueryBuilderJoin.Validate() method validates that Left.Name and Right.Name are non-empty, but does not validate that these names reference queries that actually exist in the composite query. In contrast, QueryBuilderTraceOperator.ValidateTraceOperator() receives the queries list and validates all referenced queries exist. A join referencing non-existent queries like "X" and "Y" would pass validation but fail at query execution time with a confusing error instead of a clear validation message.

Additional Locations (1)

Fix in Cursor Fix in Web

@srikanthccv
Copy link
Copy Markdown
Member

Will be addressed as part of https://github.com/SigNoz/engineering-pod/issues/3199

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants