Skip to content

Commit 90f5337

Browse files
feat(healtcheck-ecommerce): PPABV-60 New api to support healthcheck ecommerce (#2656)
* feat: new api to support healthcheck ecommerce * docs: update readme * chore: add ignore-for-error for send-request * fix(healthcheck); minor fix
1 parent 152c466 commit 90f5337

File tree

5 files changed

+293
-5
lines changed

5 files changed

+293
-5
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#################################################
2+
## API ecommerce healthcheck service ##
3+
#################################################
4+
locals {
5+
apim_ecommerce_healthcheck_service_api = {
6+
display_name = "eCommerce pagoPA - healthcheck API"
7+
description = "API to support ecommerce healthcheck"
8+
path = "ecommerce-healthcheck"
9+
subscription_required = true
10+
service_url = null
11+
}
12+
}
13+
14+
# Healthcheck service APIs
15+
resource "azurerm_api_management_api_version_set" "ecommerce_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_ecommerce_healthcheck_service_api.display_name
20+
versioning_scheme = "Segment"
21+
}
22+
23+
module "apim_ecommerce_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_ecommerce_healthcheck_service_api.subscription_required
31+
version_set_id = azurerm_api_management_api_version_set.ecommerce_healthcheck_api.id
32+
api_version = "v1"
33+
34+
description = local.apim_ecommerce_healthcheck_service_api.description
35+
display_name = local.apim_ecommerce_healthcheck_service_api.display_name
36+
path = local.apim_ecommerce_healthcheck_service_api.path
37+
protocols = ["https"]
38+
service_url = local.apim_ecommerce_healthcheck_service_api.service_url
39+
40+
content_format = "openapi"
41+
content_value = templatefile("./api/ecommerce-healthcheck/v1/_openapi.json.tpl", {
42+
hostname = local.apim_hostname
43+
})
44+
45+
xml_content = templatefile("./api/ecommerce-healthcheck/v1/_base_policy.xml.tpl", {
46+
hostname = local.ecommerce_hostname
47+
})
48+
}

src/domains/ecommerce-app/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
| <a name="module_apim_ecommerce_checkout_api_v1"></a> [apim\_ecommerce\_checkout\_api\_v1](#module\_apim\_ecommerce\_checkout\_api\_v1) | ./.terraform/modules/__v3__/api_management_api | n/a |
1919
| <a name="module_apim_ecommerce_checkout_api_v2"></a> [apim\_ecommerce\_checkout\_api\_v2](#module\_apim\_ecommerce\_checkout\_api\_v2) | ./.terraform/modules/__v3__/api_management_api | n/a |
2020
| <a name="module_apim_ecommerce_checkout_product"></a> [apim\_ecommerce\_checkout\_product](#module\_apim\_ecommerce\_checkout\_product) | ./.terraform/modules/__v3__/api_management_product | n/a |
21+
| <a name="module_apim_ecommerce_healthcheck_api_v1"></a> [apim\_ecommerce\_healthcheck\_api\_v1](#module\_apim\_ecommerce\_healthcheck\_api\_v1) | ./.terraform/modules/__v3__/api_management_api | n/a |
2122
| <a name="module_apim_ecommerce_helpdesk_commands_product"></a> [apim\_ecommerce\_helpdesk\_commands\_product](#module\_apim\_ecommerce\_helpdesk\_commands\_product) | ./.terraform/modules/__v3__/api_management_product | n/a |
2223
| <a name="module_apim_ecommerce_helpdesk_product"></a> [apim\_ecommerce\_helpdesk\_product](#module\_apim\_ecommerce\_helpdesk\_product) | ./.terraform/modules/__v3__/api_management_product | n/a |
2324
| <a name="module_apim_ecommerce_io_api_v2"></a> [apim\_ecommerce\_io\_api\_v2](#module\_apim\_ecommerce\_io\_api\_v2) | ./.terraform/modules/__v3__/api_management_api | n/a |
@@ -106,6 +107,7 @@
106107
| [azurerm_api_management_api_version_set.apim_ecommerce_redirect_outcome_api_v1](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/api_management_api_version_set) | resource |
107108
| [azurerm_api_management_api_version_set.apim_ecommerce_webview_api](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/api_management_api_version_set) | resource |
108109
| [azurerm_api_management_api_version_set.ecommerce_checkout_api_v1](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/api_management_api_version_set) | resource |
110+
| [azurerm_api_management_api_version_set.ecommerce_healthcheck_api](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/api_management_api_version_set) | resource |
109111
| [azurerm_api_management_api_version_set.ecommerce_io_api_v1](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/api_management_api_version_set) | resource |
110112
| [azurerm_api_management_api_version_set.ecommerce_io_outcomes_api](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/api_management_api_version_set) | resource |
111113
| [azurerm_api_management_api_version_set.ecommerce_io_webview_pay_v1](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/api_management_api_version_set) | resource |
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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="transactionServiceLiveness" timeout="10">
8+
<set-url>
9+
https://${hostname}/pagopa-ecommerce-transactions-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="paymentMethodServiceLiveness" timeout="10">
15+
<set-url>
16+
https://${hostname}/pagopa-ecommerce-payment-methods-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="paymentRequestServiceLiveness" timeout="10">
22+
<set-url>
23+
https://${hostname}/pagopa-ecommerce-payment-requests-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="userStatServiceLiveness" timeout="10">
29+
<set-url>
30+
https://${hostname}/pagopa-ecommerce-user-stats-service/actuator/health/liveness
31+
</set-url>
32+
<set-method>GET</set-method>
33+
</send-request>
34+
35+
<send-request ignore-error="true" mode="new" response-variable-name="eventDispatcherServiceLiveness" timeout="10">
36+
<set-url>
37+
https://${hostname}/pagopa-ecommerce-event-dispatcher/actuator/health/liveness
38+
</set-url>
39+
<set-method>GET</set-method>
40+
</send-request>
41+
42+
<send-request ignore-error="true" mode="new" response-variable-name="transactionSchedulerServiceLiveness" timeout="10">
43+
<set-url>
44+
https://${hostname}/pagopa-ecommerce-transactions-scheduler-service/actuator/health/liveness
45+
</set-url>
46+
<set-method>GET</set-method>
47+
</send-request>
48+
49+
</inbound>
50+
<backend>
51+
</backend>
52+
<outbound>
53+
<base />
54+
<set-body>
55+
@{
56+
var services = new[] {
57+
"transactionServiceLiveness",
58+
"paymentMethodServiceLiveness",
59+
"paymentRequestServiceLiveness",
60+
"userStatServiceLiveness",
61+
"eventDispatcherServiceLiveness",
62+
"transactionSchedulerServiceLiveness"
63+
};
64+
65+
var combinedResults = new JObject();
66+
67+
bool allUp = true;
68+
69+
foreach (var service in services) {
70+
var parsedResponse = ((IResponse)context.Variables[service]).Body.As<JObject>();
71+
combinedResults[service] = parsedResponse;
72+
73+
if ((string)parsedResponse["status"] != "UP") {
74+
allUp = false;
75+
}
76+
}
77+
78+
var response = new JObject();
79+
80+
response["status"] = allUp ? "UP" : "DOWN";
81+
response["details"] = combinedResults;
82+
83+
return response.ToString();
84+
}
85+
</set-body>
86+
</outbound>
87+
<on-error>
88+
<base />
89+
</on-error>
90+
</policies>
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
{
2+
"openapi": "3.0.3",
3+
"info": {
4+
"version": "0.0.1,",
5+
"title": "eCommerce 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": "eCommerceHealthcheck",
14+
"description": "Api's to handle eCommerce healtcheck"
15+
}
16+
],
17+
"servers": [
18+
{
19+
"url": "https://${hostname}"
20+
}
21+
],
22+
"paths": {
23+
"/liveness": {
24+
"get": {
25+
"tags": [
26+
"eCommerceHealthcheck"
27+
],
28+
"summary": "API to support Liveness Check",
29+
"operationId": "eCommerceHealthcheckLiveness",
30+
"responses": {
31+
"200": {
32+
"description": "Healthcheck Liveness info",
33+
"content": {
34+
"application/json": {
35+
"schema": {
36+
"$ref": "#/components/schemas/EcommerceHealthcheckLivenessResponse"
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+
"EcommerceHealthcheckLivenessResponse": {
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 ecommerce 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+
}
105+
}
106+
}
107+
},
108+
"required": [
109+
"status"
110+
]
111+
},
112+
"ProblemJson": {
113+
"description": "Body definition for error responses containing failure details",
114+
"type": "object",
115+
"properties": {
116+
"type": {
117+
"type": "string",
118+
"format": "uri",
119+
"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).",
120+
"default": "about:blank",
121+
"example": "https://example.com/problem/constraint-violation"
122+
},
123+
"title": {
124+
"type": "string",
125+
"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"
126+
},
127+
"status": {
128+
"$ref": "#/components/schemas/HttpStatusCode"
129+
},
130+
"detail": {
131+
"type": "string",
132+
"description": "A human readable explanation specific to this occurrence of the\nproblem.",
133+
"example": "There was an error processing the request"
134+
},
135+
"instance": {
136+
"type": "string",
137+
"format": "uri",
138+
"description": "An absolute URI that identifies the specific occurrence of the problem.\nIt may or may not yield further information if dereferenced."
139+
}
140+
}
141+
},
142+
"HttpStatusCode": {
143+
"type": "integer",
144+
"format": "int32",
145+
"description": "The HTTP status code generated by the origin server for this occurrence\nof the problem.",
146+
"minimum": 100,
147+
"maximum": 600,
148+
"exclusiveMaximum": true,
149+
"example": 502
150+
}
151+
}
152+
}
153+
}

src/domains/pay-wallet-app/api/healthcheck/v1/_base_policy.xml.tpl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,6 @@
6666
return response.ToString();
6767
}
6868
</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>
7469
</outbound>
7570
<on-error>
7671
<base />

0 commit comments

Comments
 (0)