Skip to content

Commit 152c466

Browse files
feat(paymen-wallet): PPABV-60 add new healthcheck for payment wallet (#2654)
* feat: add new healthcheck for payment wallet * do: update readme for payment-wallet * chore: rate limit * fix: endpotin for liveness * chore: add ignore-for-error for send-request * feat: add 502 for down * feat: add product refs
1 parent 13334b2 commit 152c466

File tree

4 files changed

+288
-0
lines changed

4 files changed

+288
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#################################################
2+
## API wallet healthcheck service ##
3+
#################################################
4+
locals {
5+
apim_payment_wallet_healthcheck_service_api = {
6+
display_name = "wallet pagoPA - healthcheck API"
7+
description = "API to support system healthcheck"
8+
path = "payment-wallet-healthcheck"
9+
subscription_required = true
10+
service_url = null
11+
}
12+
}
13+
14+
# Healthcheck service APIs
15+
resource "azurerm_api_management_api_version_set" "pay_wallet_healthcheck_api" {
16+
name = "${local.project}-healtcheck-api"
17+
resource_group_name = local.pagopa_apim_rg
18+
api_management_name = local.pagopa_apim_name
19+
display_name = local.apim_payment_wallet_healthcheck_service_api.display_name
20+
versioning_scheme = "Segment"
21+
}
22+
23+
module "apim_pay_wallet_healthcheck_api_v1" {
24+
source = "./.terraform/modules/__v3__/api_management_api"
25+
26+
name = "${local.project}-healtcheck-api"
27+
api_management_name = local.pagopa_apim_name
28+
resource_group_name = local.pagopa_apim_rg
29+
product_ids = ["statuspage_nodo_pagamenti"]
30+
subscription_required = local.apim_payment_wallet_healthcheck_service_api.subscription_required
31+
version_set_id = azurerm_api_management_api_version_set.pay_wallet_healthcheck_api.id
32+
api_version = "v1"
33+
34+
description = local.apim_payment_wallet_healthcheck_service_api.description
35+
display_name = local.apim_payment_wallet_healthcheck_service_api.display_name
36+
path = local.apim_payment_wallet_healthcheck_service_api.path
37+
protocols = ["https"]
38+
service_url = local.apim_payment_wallet_healthcheck_service_api.service_url
39+
40+
content_format = "openapi"
41+
content_value = templatefile("./api/healthcheck/v1/_openapi.json.tpl", {
42+
hostname = local.apim_hostname
43+
})
44+
45+
xml_content = templatefile("./api/healthcheck/v1/_base_policy.xml.tpl", {
46+
hostname = local.payment_wallet_hostname
47+
})
48+
}

src/domains/pay-wallet-app/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
| <a name="module___v3__"></a> [\_\_v3\_\_](#module\_\_\_v3\_\_) | git::https://github.com/pagopa/terraform-azurerm-v3 | 3fc1dafaf4354e24ca8673005ec0caf4106343a3 |
2121
| <a name="module_apim_io_payment_wallet_api_v1"></a> [apim\_io\_payment\_wallet\_api\_v1](#module\_apim\_io\_payment\_wallet\_api\_v1) | ./.terraform/modules/__v3__/api_management_api | n/a |
2222
| <a name="module_apim_io_payment_wallet_product"></a> [apim\_io\_payment\_wallet\_product](#module\_apim\_io\_payment\_wallet\_product) | ./.terraform/modules/__v3__/api_management_product | n/a |
23+
| <a name="module_apim_pay_wallet_healthcheck_api_v1"></a> [apim\_pay\_wallet\_healthcheck\_api\_v1](#module\_apim\_pay\_wallet\_healthcheck\_api\_v1) | ./.terraform/modules/__v3__/api_management_api | n/a |
2324
| <a name="module_apim_payment_wallet_for_ecommerce_api_v1"></a> [apim\_payment\_wallet\_for\_ecommerce\_api\_v1](#module\_apim\_payment\_wallet\_for\_ecommerce\_api\_v1) | ./.terraform/modules/__v3__/api_management_api | n/a |
2425
| <a name="module_apim_payment_wallet_migrations_api_v1"></a> [apim\_payment\_wallet\_migrations\_api\_v1](#module\_apim\_payment\_wallet\_migrations\_api\_v1) | ./.terraform/modules/__v3__/api_management_api | n/a |
2526
| <a name="module_apim_payment_wallet_migrations_for_cstar_api_v1"></a> [apim\_payment\_wallet\_migrations\_for\_cstar\_api\_v1](#module\_apim\_payment\_wallet\_migrations\_for\_cstar\_api\_v1) | ./.terraform/modules/__v3__/api_management_api | n/a |
@@ -46,6 +47,7 @@
4647
| [azurerm_api_management_api_operation_policy.update_applications_for_io](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/api_management_api_operation_policy) | resource |
4748
| [azurerm_api_management_api_version_set.io_payment_wallet_api](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/api_management_api_version_set) | resource |
4849
| [azurerm_api_management_api_version_set.npg_notifications_api](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/api_management_api_version_set) | resource |
50+
| [azurerm_api_management_api_version_set.pay_wallet_healthcheck_api](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/api_management_api_version_set) | resource |
4951
| [azurerm_api_management_api_version_set.payment_wallet_for_ecommerce_api](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/api_management_api_version_set) | resource |
5052
| [azurerm_api_management_api_version_set.payment_wallet_migrations_api](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/api_management_api_version_set) | resource |
5153
| [azurerm_api_management_api_version_set.payment_wallet_migrations_for_cstar_api](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/api_management_api_version_set) | resource |
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<policies>
2+
<inbound>
3+
<base />
4+
5+
<rate-limit-by-key calls="10" renewal-period="10" counter-key="@(context.Request.Headers.GetValueOrDefault("X-Forwarded-For"))" />
6+
7+
<send-request ignore-error="true" mode="new" response-variable-name="walletServiceLiveness" timeout="10">
8+
<set-url>
9+
https://${hostname}/pagopa-wallet-service/actuator/health/liveness
10+
</set-url>
11+
<set-method>GET</set-method>
12+
</send-request>
13+
14+
<send-request ignore-error="true" mode="new" response-variable-name="walletEventDispatcherServiceLiveness" timeout="10">
15+
<set-url>
16+
https://${hostname}/pagopa-wallet-event-dispatcher-service/actuator/health/liveness
17+
</set-url>
18+
<set-method>GET</set-method>
19+
</send-request>
20+
21+
<send-request ignore-error="true" mode="new" response-variable-name="walletCdcServiceLiveness" timeout="10">
22+
<set-url>
23+
https://${hostname}/pagopa-payment-wallet-cdc-service/actuator/health/liveness
24+
</set-url>
25+
<set-method>GET</set-method>
26+
</send-request>
27+
28+
<send-request ignore-error="true" mode="new" response-variable-name="walletSchedulerServiceLiveness" timeout="10">
29+
<set-url>
30+
https://${hostname}/pagopa-payment-wallet-scheduler-service/actuator/health/liveness
31+
</set-url>
32+
<set-method>GET</set-method>
33+
</send-request>
34+
</inbound>
35+
<backend>
36+
</backend>
37+
<outbound>
38+
<base />
39+
<set-body>
40+
@{
41+
var services = new[] {
42+
"walletServiceLiveness",
43+
"walletEventDispatcherServiceLiveness",
44+
"walletCdcServiceLiveness",
45+
"walletSchedulerServiceLiveness"
46+
};
47+
48+
var combinedResults = new JObject();
49+
50+
bool allUp = true;
51+
52+
foreach (var service in services) {
53+
var parsedResponse = ((IResponse)context.Variables[service]).Body.As<JObject>();
54+
combinedResults[service] = parsedResponse;
55+
56+
if ((string)parsedResponse["status"] != "UP") {
57+
allUp = false;
58+
}
59+
}
60+
61+
var response = new JObject();
62+
63+
response["status"] = allUp ? "UP" : "DOWN";
64+
response["details"] = combinedResults;
65+
66+
return response.ToString();
67+
}
68+
</set-body>
69+
<choose>
70+
<when condition="@(context.Response.Body.As<JObject>()["status"].ToString() == "DOWN")">
71+
<set-status code="502" reason="Bad Gateway" />
72+
</when>
73+
</choose>
74+
</outbound>
75+
<on-error>
76+
<base />
77+
</on-error>
78+
</policies>
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
{
2+
"openapi": "3.0.3",
3+
"info": {
4+
"version": "0.0.1,",
5+
"title": "Payment Wallet pagoPA - healthcheck",
6+
"description": "The Healthcheck API is used to monitor the operational status of a REST API by providing endpoints for liveness and readiness checks.\n- Liveness Check: This endpoint verifies that the API is running and able to process requests.\n- Readiness Check: This endpoint confirms that the API is fully initialized and ready to handle traffic. It ensures that all necessary resources, such as databases or external services, are available before the API starts accepting requests.\n",
7+
"contact": {
8+
"name": "pagoPA - Touchpoints team"
9+
}
10+
},
11+
"tags": [
12+
{
13+
"name": "PaymentWalletHealthcheck",
14+
"description": "Api's to handle payment wallet healtcheck"
15+
}
16+
],
17+
"servers": [
18+
{
19+
"url": "https://${hostname}"
20+
}
21+
],
22+
"paths": {
23+
"/liveness": {
24+
"get": {
25+
"tags": [
26+
"PaymentWalletHealthcheck"
27+
],
28+
"summary": "API to support Liveness Check",
29+
"operationId": "PaymentWalletHealthcheckLiveness",
30+
"responses": {
31+
"200": {
32+
"description": "Healthcheck Liveness info",
33+
"content": {
34+
"application/json": {
35+
"schema": {
36+
"$ref": "#/components/schemas/PaymentWalletHealthcheckLivenessResponse"
37+
}
38+
}
39+
}
40+
},
41+
"401": {
42+
"description": "Unauthorized",
43+
"content": {
44+
"application/json": {
45+
"schema": {
46+
"$ref": "#/components/schemas/ProblemJson"
47+
},
48+
"example": {
49+
"type": "https://example.com/problem/",
50+
"title": "string",
51+
"status": 401,
52+
"detail": "Unauthorized"
53+
}
54+
}
55+
}
56+
},
57+
"500": {
58+
"description": "Internal server error",
59+
"content": {
60+
"application/json": {
61+
"schema": {
62+
"$ref": "#/components/schemas/ProblemJson"
63+
},
64+
"example": {
65+
"type": "https://example.com/problem/",
66+
"title": "string",
67+
"status": 500,
68+
"detail": "Internal server error"
69+
}
70+
}
71+
}
72+
}
73+
}
74+
}
75+
}
76+
},
77+
"components": {
78+
"schemas": {
79+
"PaymentWalletHealthcheckLivenessResponse": {
80+
"type": "object",
81+
"properties": {
82+
"status": {
83+
"type": "string",
84+
"enum": [
85+
"UP",
86+
"DOWN"
87+
],
88+
"description": "The overall status of all services."
89+
},
90+
"details": {
91+
"type": "object",
92+
"description": "Detailed status of each payment wallet service (additionalProperties).",
93+
"additionalProperties": {
94+
"type": "object",
95+
"properties": {
96+
"status": {
97+
"type": "string",
98+
"enum": [
99+
"UP",
100+
"DOWN"
101+
],
102+
"description": "The status of the individual service."
103+
},
104+
"groups": {
105+
"type": "array",
106+
"items": {
107+
"type": "string"
108+
},
109+
"description": "Groups associated with the service status (e.g., liveness, readiness)."
110+
}
111+
}
112+
}
113+
}
114+
},
115+
"required": [
116+
"status"
117+
]
118+
},
119+
"ProblemJson": {
120+
"description": "Body definition for error responses containing failure details",
121+
"type": "object",
122+
"properties": {
123+
"type": {
124+
"type": "string",
125+
"format": "uri",
126+
"description": "An absolute URI that identifies the problem type. When dereferenced,\nit SHOULD provide human-readable documentation for the problem type\n(e.g., using HTML).",
127+
"default": "about:blank",
128+
"example": "https://example.com/problem/constraint-violation"
129+
},
130+
"title": {
131+
"type": "string",
132+
"description": "A short, summary of the problem type. Written in english and readable\nfor engineers (usually not suited for non technical stakeholders and\nnot localized); example: Service Unavailable"
133+
},
134+
"status": {
135+
"$ref": "#/components/schemas/HttpStatusCode"
136+
},
137+
"detail": {
138+
"type": "string",
139+
"description": "A human readable explanation specific to this occurrence of the\nproblem.",
140+
"example": "There was an error processing the request"
141+
},
142+
"instance": {
143+
"type": "string",
144+
"format": "uri",
145+
"description": "An absolute URI that identifies the specific occurrence of the problem.\nIt may or may not yield further information if dereferenced."
146+
}
147+
}
148+
},
149+
"HttpStatusCode": {
150+
"type": "integer",
151+
"format": "int32",
152+
"description": "The HTTP status code generated by the origin server for this occurrence\nof the problem.",
153+
"minimum": 100,
154+
"maximum": 600,
155+
"exclusiveMaximum": true,
156+
"example": 502
157+
}
158+
}
159+
}
160+
}

0 commit comments

Comments
 (0)