Skip to content

feat(observability): add merchant thresholds APIs - #14266

Open
VenuMadhav2541 wants to merge 1 commit into
feat/observability-alerts-dicts-apifrom
feat/observability-merchant-thresholds-api
Open

VenuMadhav2541 wants to merge 1 commit into
feat/observability-alerts-dicts-apifrom
feat/observability-merchant-thresholds-api

Conversation

@VenuMadhav2541

Copy link
Copy Markdown
Contributor

Summary

Adds PostgreSQL persistence and HTTP APIs for per-merchant threshold overrides in the observability service.

The implementation follows the alert_manager module structure used by the alerts-dicts APIs. IDs are generated by the application and stored as VARCHAR; no UUID or database-generated ID is used.

APIs

  • POST /alerts/alerts_manager/merchant_thresholds
    • Inserts a threshold override.
    • Upserts on (name, product, merchant_id, profile_id, is_enabled, author).
    • On conflict, updates only threshold fields, metadata, and timestamp that were supplied.
  • POST /alerts/alerts_manager/merchant_thresholds/list
    • Lists rows using optional filters for IDs, alert name, product, merchant, profile, author, enabled state, metadata values, and last_updated_at range.
  • POST /alerts/alerts_manager/merchant_thresholds/update
    • Updates all rows matching at least one supplied key filter.
    • Supports absent fields as keep, null as clear, and values as replace.
    • Supports metadata object merge.
  • POST /alerts/alerts_manager/merchant_thresholds/delete
    • Deletes rows matching the required name/product and optional merchant/profile filters.
  • DELETE /alerts/alerts_manager/merchant_thresholds/{id}
    • Deletes one row by application-generated string ID.

Database

  • Adds the merchant_thresholds migration and rollback.
  • Uses VARCHAR(64) for the application-generated primary key.
  • Adds the Diesel schema, models, queries, and conflict constraint.

Validation and Tests

  • Rejects unknown request fields and invalid empty update filters.
  • Validates text lengths and blank IDs before database access.
  • Verifies route authentication and bad-request responses.
  • cargo test -p observability passes: 96 unit tests, 6 merchant-threshold integration tests, 16 notifier tests, and doc tests.

@VenuMadhav2541
VenuMadhav2541 requested review from a team as code owners September 16, 2026 17:42
@semanticdiff-com

semanticdiff-com Bot commented Sep 16, 2026

Copy link
Copy Markdown

Review changes with  SemanticDiff

Changed Files
File Status
  crates/observability/src/db.rs  78% smaller
  crates/diesel_models/src/observability/schema.rs  50% smaller
  crates/observability/src/routes/app.rs  14% smaller
  crates/api_models/src/observability.rs  0% smaller
  crates/api_models/src/observability/alert_manager.rs  0% smaller
  crates/api_models/src/observability/alert_manager/merchant_thresholds.rs  0% smaller
  crates/diesel_models/src/observability.rs  0% smaller
  crates/diesel_models/src/observability/alert_manager.rs  0% smaller
  crates/diesel_models/src/observability/alert_manager/merchant_thresholds.rs  0% smaller
  crates/diesel_models/src/observability/query.rs  0% smaller
  crates/diesel_models/src/observability/query/alert_manager.rs  0% smaller
  crates/diesel_models/src/observability/query/alert_manager/merchant_thresholds.rs  0% smaller
  crates/observability/migrations/2026-09-16-000001_create_merchant_thresholds/up.sql Unsupported file format
  crates/observability/src/core.rs  0% smaller
  crates/observability/src/core/alert_manager.rs  0% smaller
  crates/observability/src/core/alert_manager/merchant_thresholds.rs  0% smaller
  crates/observability/src/db/alert_manager.rs  0% smaller
  crates/observability/src/db/alert_manager/merchant_thresholds.rs  0% smaller
  crates/observability/src/domain_models.rs  0% smaller
  crates/observability/src/domain_models/alert_manager.rs  0% smaller
  crates/observability/src/domain_models/alert_manager/merchant_thresholds.rs  0% smaller
  crates/observability/src/routes.rs  0% smaller
  crates/observability/src/routes/alert_manager.rs  0% smaller
  crates/observability/src/routes/alert_manager/merchant_thresholds.rs  0% smaller
  crates/observability/tests/merchant_thresholds.rs  0% smaller

@XyneSpaces

Copy link
Copy Markdown
Contributor

[blocking] crates/observability/migrations/2026-09-16-000001_create_merchant_thresholds/up.sql changes the already-defined id column from UUID DEFAULT gen_random_uuid() PRIMARY KEY to VARCHAR(64) NOT NULL PRIMARY KEY.

Editing a migration after it has been introduced means environments that already ran it will have a different schema than new ones. Please revert this change and add a new migration to alter the column type if needed.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants