Skip to content

Commit

Permalink
feat: [PAGOPA-2425] add alert on D-WISP's redirect API availability (#…
Browse files Browse the repository at this point in the history
…2616)

* [PAGOPA-2425] feat: add alert on D-WISP's redirect API availability

* [PAGOPA-2425] feat: add alert on D-WISP's redirect API availability

* [PAGOPA-2425] fix: removing D-WISP client errors from alert

* [PAGOPA-2425] feat: tuning on D-WISP's /payments alert
  • Loading branch information
andrea-deri authored Dec 2, 2024
1 parent 4f303eb commit df0a659
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
49 changes: 48 additions & 1 deletion src/domains/nodo-app/00_alert_wisp_dismantling.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,53 @@ AzureDiagnostics
}
}

// Query explanation: https://pagopa.atlassian.net/wiki/spaces/I/pages/574751186/Razionalizzazione+Alert
resource "azurerm_monitor_scheduled_query_rules_alert" "opex_pagopa-wisp-converter-redirect-availability" {
count = var.env_short == "p" ? 1 : 0
resource_group_name = "dashboards"
name = "pagopa-${var.env_short}-opex_pagopa-wisp-converter-redirect-availability"
location = var.location

action {
action_group = [data.azurerm_monitor_action_group.email.id, data.azurerm_monitor_action_group.slack.id, data.azurerm_monitor_action_group.opsgenie[0].id]
email_subject = "Alert pagopa-wisp-converter-redirect-availability"
custom_webhook_payload = "{}"
}

data_source_id = data.azurerm_api_management.apim.id
description = "Availability for https://api.platform.pagopa.it/wisp-converter/redirect/api/v1/payments is less than or equal to threshold - https://portal.azure.com/?l=en.en-us#@pagopait.onmicrosoft.com/dashboard/arm/subscriptions/b9fc9419-6097-45fe-9f74-ba0641c91912/resourcegroups/dashboards/providers/microsoft.portal/dashboards/pagopa-p-opex_pagopa-wisp-converter"
enabled = true
query = (<<-QUERY
let lowTrafficThreshold = 70; // the lower threshold that can be calculated regarding the number of invocations
let highTrafficThreshold = 95; // the upper threshold that can be calculated regarding the number of invocations
let trafficMin = 100; // the minimum number of invocations (traffic) below which 'lowTrafficThreshold' guideline is used
let trafficLinear = 500; // the minimum number of invocations (traffic) above which 'highTrafficThreshold' guideline is used
let thresholdDelta = trafficLinear - trafficMin; // the difference of the traffic guideline on which the expected availability is calculated
let availabilityDelta = highTrafficThreshold - lowTrafficThreshold; // the difference of the threshold limits on which the expected availability is calculated
// -----------------------------------------
AzureDiagnostics
| where url_s startswith "https://api.platform.pagopa.it/wisp-converter/redirect/api/v1/payments"
| summarize
total=count(),
success=count(responseCode_d == 302)
by timeslot = bin(TimeGenerated, 5m)
| extend trafficUp = total - trafficMin
| extend deltaRatio = todouble(todouble(trafficUp) / todouble(thresholdDelta))
| extend expectedAvailability = iff(total >= trafficLinear, toreal(highTrafficThreshold), iff(total <= trafficMin, toreal(lowTrafficThreshold), (deltaRatio * (availabilityDelta)) + lowTrafficThreshold))
| extend availability = ((success * 1.0) / total) * 100
| project timeslot, availability, threshold=expectedAvailability
| where availability < threshold
QUERY
)
severity = 1
frequency = 5
time_window = 10
trigger {
operator = "GreaterThanOrEqual"
threshold = 2
}
}

// These API invoking and result are logged only on application insight
// [receiptKo, receiptOk, createTimer, deleteTimer]
resource "azurerm_monitor_scheduled_query_rules_alert" "opex_pagopa-wisp-converter-ai-availability" {
Expand Down Expand Up @@ -126,7 +173,7 @@ resource "azurerm_monitor_scheduled_query_rules_alert" "opex_pagopa-wisp-convert
let errorsToExclude = dynamic([
"WIC-1300", // payment position already paid
"WIC-2001", // RPT timer creation
"WIC-3001", "WIC-3002", "WIC-3003", "WIC-3004", "WIC-3005", "WIC-3006" // client errors
"WIC-3004" // CLIENT_CHECKOUT error
]);
traces
| where cloud_RoleName == "pagopawispconverter"
Expand Down
1 change: 1 addition & 0 deletions src/domains/nodo-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@
| [azurerm_monitor_scheduled_query_rules_alert.opex_pagopa-wisp-converter-ai-availability](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/monitor_scheduled_query_rules_alert) | resource |
| [azurerm_monitor_scheduled_query_rules_alert.opex_pagopa-wisp-converter-ai-error](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/monitor_scheduled_query_rules_alert) | resource |
| [azurerm_monitor_scheduled_query_rules_alert.opex_pagopa-wisp-converter-availability](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/monitor_scheduled_query_rules_alert) | resource |
| [azurerm_monitor_scheduled_query_rules_alert.opex_pagopa-wisp-converter-redirect-availability](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/monitor_scheduled_query_rules_alert) | resource |
| [azurerm_monitor_scheduled_query_rules_alert.opex_pagopa-wisp-converter-wic-error](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/monitor_scheduled_query_rules_alert) | resource |
| [azurerm_resource_group.nodo_re_to_datastore_rg](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) | resource |
| [azurerm_resource_group.vmss_rg](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) | resource |
Expand Down

0 comments on commit df0a659

Please sign in to comment.