generated from pagopa/terraform-infrastructure-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(healtcheck-ecommerce): PPABV-60 New api to support healthcheck e…
…commerce (#2656) * feat: new api to support healthcheck ecommerce * docs: update readme * chore: add ignore-for-error for send-request * fix(healthcheck); minor fix
- Loading branch information
1 parent
152c466
commit 90f5337
Showing
5 changed files
with
293 additions
and
5 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
src/domains/ecommerce-app/04_apim_ecommerce_healthcheck.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
src/domains/ecommerce-app/api/ecommerce-healthcheck/v1/_base_policy.xml.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<policies> | ||
<inbound> | ||
<base /> | ||
|
||
<rate-limit-by-key calls="10" renewal-period="10" counter-key="@(context.Request.Headers.GetValueOrDefault("X-Forwarded-For"))" /> | ||
|
||
<send-request ignore-error="true" mode="new" response-variable-name="transactionServiceLiveness" timeout="10"> | ||
<set-url> | ||
https://${hostname}/pagopa-ecommerce-transactions-service/actuator/health/liveness | ||
</set-url> | ||
<set-method>GET</set-method> | ||
</send-request> | ||
|
||
<send-request ignore-error="true" mode="new" response-variable-name="paymentMethodServiceLiveness" timeout="10"> | ||
<set-url> | ||
https://${hostname}/pagopa-ecommerce-payment-methods-service/actuator/health/liveness | ||
</set-url> | ||
<set-method>GET</set-method> | ||
</send-request> | ||
|
||
<send-request ignore-error="true" mode="new" response-variable-name="paymentRequestServiceLiveness" timeout="10"> | ||
<set-url> | ||
https://${hostname}/pagopa-ecommerce-payment-requests-service/actuator/health/liveness | ||
</set-url> | ||
<set-method>GET</set-method> | ||
</send-request> | ||
|
||
<send-request ignore-error="true" mode="new" response-variable-name="userStatServiceLiveness" timeout="10"> | ||
<set-url> | ||
https://${hostname}/pagopa-ecommerce-user-stats-service/actuator/health/liveness | ||
</set-url> | ||
<set-method>GET</set-method> | ||
</send-request> | ||
|
||
<send-request ignore-error="true" mode="new" response-variable-name="eventDispatcherServiceLiveness" timeout="10"> | ||
<set-url> | ||
https://${hostname}/pagopa-ecommerce-event-dispatcher/actuator/health/liveness | ||
</set-url> | ||
<set-method>GET</set-method> | ||
</send-request> | ||
|
||
<send-request ignore-error="true" mode="new" response-variable-name="transactionSchedulerServiceLiveness" timeout="10"> | ||
<set-url> | ||
https://${hostname}/pagopa-ecommerce-transactions-scheduler-service/actuator/health/liveness | ||
</set-url> | ||
<set-method>GET</set-method> | ||
</send-request> | ||
|
||
</inbound> | ||
<backend> | ||
</backend> | ||
<outbound> | ||
<base /> | ||
<set-body> | ||
@{ | ||
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<JObject>(); | ||
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(); | ||
} | ||
</set-body> | ||
</outbound> | ||
<on-error> | ||
<base /> | ||
</on-error> | ||
</policies> |
153 changes: 153 additions & 0 deletions
153
src/domains/ecommerce-app/api/ecommerce-healthcheck/v1/_openapi.json.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters