diff --git a/src/domains/ecommerce-common/00_alerts.tf b/src/domains/ecommerce-common/00_alerts.tf index d91ceeddc7..ffbc3b6075 100644 --- a/src/domains/ecommerce-common/00_alerts.tf +++ b/src/domains/ecommerce-common/00_alerts.tf @@ -254,4 +254,48 @@ AzureDiagnostics operator = "GreaterThanOrEqual" threshold = 2 } +} + +# eCommerce user stats last payment method put availability +resource "azurerm_monitor_scheduled_query_rules_alert" "ecommerce_user_stats_last_payment_method_put_availability_alert" { + count = var.env_short == "p" ? 1 : 0 + + name = "ecommerce-user-stats-last-payment-method-put-availability-alert" + resource_group_name = azurerm_resource_group.rg_ecommerce_alerts[0].name + location = var.location + + action { + action_group = [data.azurerm_monitor_action_group.email.id, data.azurerm_monitor_action_group.slack.id] + email_subject = "[eCommerce] User stats service - PUT lastPaymentMethodUsed availability less that 99%" + custom_webhook_payload = jsonencode({ + //alert properties https://docs.opsgenie.com/docs/alert-api + "message" = "[eCommerce] User stats service - PUT lastPaymentMethodUsed availability less that 99%" + "alias" = "ecommerce-user-stats-last-payment-method-put-availability-alert" + "tags" = "availability" + "entity" = "eCommerce" + "priority" = "P3" + }) + } + data_source_id = data.azurerm_api_management.apim.id + description = "eCommerce User stats service PUT lastPaymentMethodUsed availability less that 99%" + enabled = true + query = (<<-QUERY +AzureDiagnostics +| where url_s startswith 'https://api.platform.pagopa.it/ecommerce/user-stats-service/v1/user/lastPaymentMethodUsed' +| where method_s == "PUT" +| summarize + Total=count(), + Success=countif(responseCode_d < 400 and DurationMs < 250) + by Time = bin(TimeGenerated, 15m) +| extend Availability=((Success * 1.0) / Total) * 100 +| where toint(Availability) < 99 + QUERY + ) + severity = 1 + frequency = 30 + time_window = 30 + trigger { + operator = "GreaterThanOrEqual" + threshold = 2 + } } \ No newline at end of file diff --git a/src/domains/ecommerce-common/README.md b/src/domains/ecommerce-common/README.md index 9db290738c..bf5c3d5a8f 100644 --- a/src/domains/ecommerce-common/README.md +++ b/src/domains/ecommerce-common/README.md @@ -90,6 +90,7 @@ | [azurerm_monitor_scheduled_query_rules_alert.ecommerce_transactions_service_auth_request_ko](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/monitor_scheduled_query_rules_alert) | resource | | [azurerm_monitor_scheduled_query_rules_alert.ecommerce_transactions_service_user_receipts_ko](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/monitor_scheduled_query_rules_alert) | resource | | [azurerm_monitor_scheduled_query_rules_alert.ecommerce_transient_enqueue_rate_alert](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/monitor_scheduled_query_rules_alert) | resource | +| [azurerm_monitor_scheduled_query_rules_alert.ecommerce_user_stats_last_payment_method_put_availability_alert](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/monitor_scheduled_query_rules_alert) | resource | | [azurerm_private_dns_a_record.ingress](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/private_dns_a_record) | resource | | [azurerm_private_endpoint.storage_deadletter_private_endpoint](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/private_endpoint) | resource | | [azurerm_private_endpoint.storage_transient_private_endpoint](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/private_endpoint) | resource |