From 90f5337e7b6653eb642a36f79074e001a0025e56 Mon Sep 17 00:00:00 2001
From: Simone infante <52280205+infantesimone@users.noreply.github.com>
Date: Mon, 16 Dec 2024 21:39:03 +0100
Subject: [PATCH] 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
---
.../04_apim_ecommerce_healthcheck.tf | 48 ++++++
src/domains/ecommerce-app/README.md | 2 +
.../v1/_base_policy.xml.tpl | 90 +++++++++++
.../v1/_openapi.json.tpl | 153 ++++++++++++++++++
.../api/healthcheck/v1/_base_policy.xml.tpl | 5 -
5 files changed, 293 insertions(+), 5 deletions(-)
create mode 100644 src/domains/ecommerce-app/04_apim_ecommerce_healthcheck.tf
create mode 100644 src/domains/ecommerce-app/api/ecommerce-healthcheck/v1/_base_policy.xml.tpl
create mode 100644 src/domains/ecommerce-app/api/ecommerce-healthcheck/v1/_openapi.json.tpl
diff --git a/src/domains/ecommerce-app/04_apim_ecommerce_healthcheck.tf b/src/domains/ecommerce-app/04_apim_ecommerce_healthcheck.tf
new file mode 100644
index 000000000..9d07c3724
--- /dev/null
+++ b/src/domains/ecommerce-app/04_apim_ecommerce_healthcheck.tf
@@ -0,0 +1,48 @@
+#################################################
+## API ecommerce healthcheck service ##
+#################################################
+locals {
+ apim_ecommerce_healthcheck_service_api = {
+ display_name = "eCommerce pagoPA - healthcheck API"
+ description = "API to support ecommerce healthcheck"
+ path = "ecommerce-healthcheck"
+ subscription_required = true
+ service_url = null
+ }
+}
+
+# Healthcheck service APIs
+resource "azurerm_api_management_api_version_set" "ecommerce_healthcheck_api" {
+ name = "${local.project}-healtcheck-api"
+ resource_group_name = local.pagopa_apim_rg
+ api_management_name = local.pagopa_apim_name
+ display_name = local.apim_ecommerce_healthcheck_service_api.display_name
+ versioning_scheme = "Segment"
+}
+
+module "apim_ecommerce_healthcheck_api_v1" {
+ source = "./.terraform/modules/__v3__/api_management_api"
+
+ name = "${local.project}-healtcheck-api"
+ api_management_name = local.pagopa_apim_name
+ resource_group_name = local.pagopa_apim_rg
+ product_ids = ["statuspage_nodo_pagamenti"]
+ subscription_required = local.apim_ecommerce_healthcheck_service_api.subscription_required
+ version_set_id = azurerm_api_management_api_version_set.ecommerce_healthcheck_api.id
+ api_version = "v1"
+
+ description = local.apim_ecommerce_healthcheck_service_api.description
+ display_name = local.apim_ecommerce_healthcheck_service_api.display_name
+ path = local.apim_ecommerce_healthcheck_service_api.path
+ protocols = ["https"]
+ service_url = local.apim_ecommerce_healthcheck_service_api.service_url
+
+ content_format = "openapi"
+ content_value = templatefile("./api/ecommerce-healthcheck/v1/_openapi.json.tpl", {
+ hostname = local.apim_hostname
+ })
+
+ xml_content = templatefile("./api/ecommerce-healthcheck/v1/_base_policy.xml.tpl", {
+ hostname = local.ecommerce_hostname
+ })
+}
\ No newline at end of file
diff --git a/src/domains/ecommerce-app/README.md b/src/domains/ecommerce-app/README.md
index fd6f825b7..16aa49c21 100644
--- a/src/domains/ecommerce-app/README.md
+++ b/src/domains/ecommerce-app/README.md
@@ -18,6 +18,7 @@
| [apim\_ecommerce\_checkout\_api\_v1](#module\_apim\_ecommerce\_checkout\_api\_v1) | ./.terraform/modules/__v3__/api_management_api | n/a |
| [apim\_ecommerce\_checkout\_api\_v2](#module\_apim\_ecommerce\_checkout\_api\_v2) | ./.terraform/modules/__v3__/api_management_api | n/a |
| [apim\_ecommerce\_checkout\_product](#module\_apim\_ecommerce\_checkout\_product) | ./.terraform/modules/__v3__/api_management_product | n/a |
+| [apim\_ecommerce\_healthcheck\_api\_v1](#module\_apim\_ecommerce\_healthcheck\_api\_v1) | ./.terraform/modules/__v3__/api_management_api | n/a |
| [apim\_ecommerce\_helpdesk\_commands\_product](#module\_apim\_ecommerce\_helpdesk\_commands\_product) | ./.terraform/modules/__v3__/api_management_product | n/a |
| [apim\_ecommerce\_helpdesk\_product](#module\_apim\_ecommerce\_helpdesk\_product) | ./.terraform/modules/__v3__/api_management_product | n/a |
| [apim\_ecommerce\_io\_api\_v2](#module\_apim\_ecommerce\_io\_api\_v2) | ./.terraform/modules/__v3__/api_management_api | n/a |
@@ -106,6 +107,7 @@
| [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 |
| [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 |
| [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 |
+| [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 |
| [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 |
| [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 |
| [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 |
diff --git a/src/domains/ecommerce-app/api/ecommerce-healthcheck/v1/_base_policy.xml.tpl b/src/domains/ecommerce-app/api/ecommerce-healthcheck/v1/_base_policy.xml.tpl
new file mode 100644
index 000000000..a81e6a6ee
--- /dev/null
+++ b/src/domains/ecommerce-app/api/ecommerce-healthcheck/v1/_base_policy.xml.tpl
@@ -0,0 +1,90 @@
+
+
+
+
+
+
+
+
+ https://${hostname}/pagopa-ecommerce-transactions-service/actuator/health/liveness
+
+ GET
+
+
+
+
+ https://${hostname}/pagopa-ecommerce-payment-methods-service/actuator/health/liveness
+
+ GET
+
+
+
+
+ https://${hostname}/pagopa-ecommerce-payment-requests-service/actuator/health/liveness
+
+ GET
+
+
+
+
+ https://${hostname}/pagopa-ecommerce-user-stats-service/actuator/health/liveness
+
+ GET
+
+
+
+
+ https://${hostname}/pagopa-ecommerce-event-dispatcher/actuator/health/liveness
+
+ GET
+
+
+
+
+ https://${hostname}/pagopa-ecommerce-transactions-scheduler-service/actuator/health/liveness
+
+ GET
+
+
+
+
+
+
+
+
+ @{
+ var services = new[] {
+ "transactionServiceLiveness",
+ "paymentMethodServiceLiveness",
+ "paymentRequestServiceLiveness",
+ "userStatServiceLiveness",
+ "eventDispatcherServiceLiveness",
+ "transactionSchedulerServiceLiveness"
+ };
+
+ var combinedResults = new JObject();
+
+ bool allUp = true;
+
+ foreach (var service in services) {
+ var parsedResponse = ((IResponse)context.Variables[service]).Body.As();
+ combinedResults[service] = parsedResponse;
+
+ if ((string)parsedResponse["status"] != "UP") {
+ allUp = false;
+ }
+ }
+
+ var response = new JObject();
+
+ response["status"] = allUp ? "UP" : "DOWN";
+ response["details"] = combinedResults;
+
+ return response.ToString();
+ }
+
+
+
+
+
+
diff --git a/src/domains/ecommerce-app/api/ecommerce-healthcheck/v1/_openapi.json.tpl b/src/domains/ecommerce-app/api/ecommerce-healthcheck/v1/_openapi.json.tpl
new file mode 100644
index 000000000..5410954ae
--- /dev/null
+++ b/src/domains/ecommerce-app/api/ecommerce-healthcheck/v1/_openapi.json.tpl
@@ -0,0 +1,153 @@
+{
+ "openapi": "3.0.3",
+ "info": {
+ "version": "0.0.1,",
+ "title": "eCommerce pagoPA - healthcheck",
+ "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",
+ "contact": {
+ "name": "pagoPA - Touchpoints team"
+ }
+ },
+ "tags": [
+ {
+ "name": "eCommerceHealthcheck",
+ "description": "Api's to handle eCommerce healtcheck"
+ }
+ ],
+ "servers": [
+ {
+ "url": "https://${hostname}"
+ }
+ ],
+ "paths": {
+ "/liveness": {
+ "get": {
+ "tags": [
+ "eCommerceHealthcheck"
+ ],
+ "summary": "API to support Liveness Check",
+ "operationId": "eCommerceHealthcheckLiveness",
+ "responses": {
+ "200": {
+ "description": "Healthcheck Liveness info",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/EcommerceHealthcheckLivenessResponse"
+ }
+ }
+ }
+ },
+ "401": {
+ "description": "Unauthorized",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/ProblemJson"
+ },
+ "example": {
+ "type": "https://example.com/problem/",
+ "title": "string",
+ "status": 401,
+ "detail": "Unauthorized"
+ }
+ }
+ }
+ },
+ "500": {
+ "description": "Internal server error",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/ProblemJson"
+ },
+ "example": {
+ "type": "https://example.com/problem/",
+ "title": "string",
+ "status": 500,
+ "detail": "Internal server error"
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "components": {
+ "schemas": {
+ "EcommerceHealthcheckLivenessResponse": {
+ "type": "object",
+ "properties": {
+ "status": {
+ "type": "string",
+ "enum": [
+ "UP",
+ "DOWN"
+ ],
+ "description": "The overall status of all services."
+ },
+ "details": {
+ "type": "object",
+ "description": "Detailed status of each ecommerce service (additionalProperties).",
+ "additionalProperties": {
+ "type": "object",
+ "properties": {
+ "status": {
+ "type": "string",
+ "enum": [
+ "UP",
+ "DOWN"
+ ],
+ "description": "The status of the individual service."
+ }
+ }
+ }
+ }
+ },
+ "required": [
+ "status"
+ ]
+ },
+ "ProblemJson": {
+ "description": "Body definition for error responses containing failure details",
+ "type": "object",
+ "properties": {
+ "type": {
+ "type": "string",
+ "format": "uri",
+ "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).",
+ "default": "about:blank",
+ "example": "https://example.com/problem/constraint-violation"
+ },
+ "title": {
+ "type": "string",
+ "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"
+ },
+ "status": {
+ "$ref": "#/components/schemas/HttpStatusCode"
+ },
+ "detail": {
+ "type": "string",
+ "description": "A human readable explanation specific to this occurrence of the\nproblem.",
+ "example": "There was an error processing the request"
+ },
+ "instance": {
+ "type": "string",
+ "format": "uri",
+ "description": "An absolute URI that identifies the specific occurrence of the problem.\nIt may or may not yield further information if dereferenced."
+ }
+ }
+ },
+ "HttpStatusCode": {
+ "type": "integer",
+ "format": "int32",
+ "description": "The HTTP status code generated by the origin server for this occurrence\nof the problem.",
+ "minimum": 100,
+ "maximum": 600,
+ "exclusiveMaximum": true,
+ "example": 502
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/domains/pay-wallet-app/api/healthcheck/v1/_base_policy.xml.tpl b/src/domains/pay-wallet-app/api/healthcheck/v1/_base_policy.xml.tpl
index 3e194be1e..291d0eb93 100644
--- a/src/domains/pay-wallet-app/api/healthcheck/v1/_base_policy.xml.tpl
+++ b/src/domains/pay-wallet-app/api/healthcheck/v1/_base_policy.xml.tpl
@@ -66,11 +66,6 @@
return response.ToString();
}
-
-
-
-
-