diff --git a/.github/workflows/stage-3-build-images-devtest.yaml b/.github/workflows/stage-3-build-images-devtest.yaml index 1e53565ea4..f2e53a907b 100644 --- a/.github/workflows/stage-3-build-images-devtest.yaml +++ b/.github/workflows/stage-3-build-images-devtest.yaml @@ -117,8 +117,14 @@ jobs: run: | echo "The branch is: ${GITHUB_REF}" - PR_NUM=$(gh api repos/${{ github.repository }}/commits/${{ github.sha }}/pulls --jq '.[0].number') - PR_NUM_TAG="pr${PR_NUM}" + PR_NUM=$(gh api repos/${{ github.repository }}/commits/${{ github.sha }}/pulls --jq '.[0].number' 2>/dev/null || true) + if [ -n "${PR_NUM}" ] && [ "${PR_NUM}" != "null" ]; then + PR_NUM_TAG="pr${PR_NUM}" + echo "Tag source: PR (${PR_NUM})" + else + PR_NUM_TAG="${GITHUB_REF_NAME//\//-}" + echo "Tag source: fallback ref (${GITHUB_REF_NAME})" + fi SHORT_COMMIT_HASH=$(git rev-parse --short ${GITHUB_SHA}) @@ -149,8 +155,14 @@ jobs: GH_TOKEN: ${{ github.token }} run: | - PR_NUM=$(gh api repos/${{ github.repository }}/commits/${{ github.sha }}/pulls --jq '.[0].number') - PR_NUM_TAG="pr${PR_NUM}" + PR_NUM=$(gh api repos/${{ github.repository }}/commits/${{ github.sha }}/pulls --jq '.[0].number' 2>/dev/null || true) + if [ -n "${PR_NUM}" ] && [ "${PR_NUM}" != "null" ]; then + PR_NUM_TAG="pr${PR_NUM}" + echo "Tag source: PR (${PR_NUM})" + else + PR_NUM_TAG="${GITHUB_REF_NAME//\//-}" + echo "Tag source: fallback ref (${GITHUB_REF_NAME})" + fi IMAGE_TAG="latest" if [[ ${{steps.detect-base-image-changes.outputs.BASE_IMAGE_CHANGE}} == 'true' ]]; then @@ -213,8 +225,14 @@ jobs: ENVIRONMENT_TAG: ${{ inputs.environment_tag }} continue-on-error: false run: | - PR_NUM=$(gh api repos/${{ github.repository }}/commits/${{ github.sha }}/pulls --jq '.[0].number') - PR_NUM_TAG="pr${PR_NUM}" + PR_NUM=$(gh api repos/${{ github.repository }}/commits/${{ github.sha }}/pulls --jq '.[0].number' 2>/dev/null || true) + if [ -n "${PR_NUM}" ] && [ "${PR_NUM}" != "null" ]; then + PR_NUM_TAG="pr${PR_NUM}" + echo "Tag source: PR (${PR_NUM})" + else + PR_NUM_TAG="${GITHUB_REF_NAME//\//-}" + echo "Tag source: fallback ref (${GITHUB_REF_NAME})" + fi DEVTEST_PR_NUM_TAG="devtest_${PR_NUM_TAG}" echo "The branch is: ${GITHUB_REF}" diff --git a/application/CohortManager/compose.cohort-distribution.yaml b/application/CohortManager/compose.cohort-distribution.yaml index b12599b7b2..f832c6ac6d 100644 --- a/application/CohortManager/compose.cohort-distribution.yaml +++ b/application/CohortManager/compose.cohort-distribution.yaml @@ -12,6 +12,7 @@ services: BASE_IMAGE: ${FUNCTION_BASE_IMAGE} environment: - ServiceBusConnectionString_internal=Endpoint=sb://service-bus;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true; + - ServiceBusConnectionString_client_internal=Endpoint=sb://service-bus;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true; - CohortDistributionTopic=cohort-distribution-topic - DistributeParticipantSubscription=distribute-participant-sub - AzureWebJobsStorage=${AZURITE_CONNECTION_STRING} diff --git a/application/CohortManager/compose.core.yaml b/application/CohortManager/compose.core.yaml index 7801a3ec64..756b3b685e 100644 --- a/application/CohortManager/compose.core.yaml +++ b/application/CohortManager/compose.core.yaml @@ -67,6 +67,7 @@ services: - ManageNemsSubscriptionUnsubscribeURL=http://manage-nems-subscription:9081/api/Unsubscribe - ManageNemsSubscriptionSubscribeURL=http://manage-nems-subscription:9081/api/Subscribe - DemographicDataServiceURL=http://participant-demographic-data-service:7993/api/ParticipantDemographicDataService + - ServiceBusConnectionString_internal=Endpoint=sb://service-bus;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true; - ServiceBusConnectionString_client_internal=Endpoint=sb://service-bus;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true; - ParticipantManagementTopic=participant-management-topic @@ -94,6 +95,7 @@ services: - batchDivisionFactor=5 - ScreeningLkpDataServiceURL=http://screening-lkp-data-service:8996/api/ScreeningLkpDataService - inboundBlobName=inbound + - ServiceBusConnectionString_internal=Endpoint=sb://service-bus;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true; - ServiceBusConnectionString_client_internal=Endpoint=sb://service-bus;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true; - fileExceptions=file-exceptions - ParticipantManagementTopic=participant-management-topic @@ -194,6 +196,7 @@ services: BASE_IMAGE: ${FUNCTION_BASE_IMAGE} profiles: [ui] environment: + - ServiceBusConnectionString_internal=Endpoint=sb://service-bus;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true; - ServiceBusConnectionString_client_internal=Endpoint=sb://service-bus;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true; - ServiceNowParticipantManagementTopic=servicenow-participant-management-topic - RetrievePdsDemographicURL=http://retrieve-pds-demographic:8082/api/RetrievePDSDemographic @@ -210,7 +213,8 @@ services: environment: - AzureWebJobsStorage=${AZURITE_CONNECTION_STRING} - DtOsDatabaseConnectionString=Server=db,1433;Database=${DB_NAME};User Id=SA;Password=${PASSWORD};TrustServerCertificate=True - - ServiceBusConnectionString=Endpoint=sb://service-bus;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true; + - ServiceBusConnectionString_internal=Endpoint=sb://service-bus;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true; + - ServiceBusConnectionString_client_internal=Endpoint=sb://service-bus;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true; - AuditTopicName=participant-audit-topic - AuditSubscription=audit-writer-sub @@ -231,6 +235,8 @@ services: - DemographicDataServiceURL=http://participant-demographic-data-service:7993/api/ParticipantDemographicDataService/ - ExceptionManagementDataServiceURL=http://exception-management-data-service:7911/api/ExceptionManagementDataService/ - GPPracticeDataServiceURL=http://localhost:7999/api/GPPracticeDataService/ + - ServiceBusConnectionString_internal=Endpoint=sb://service-bus;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true; + - ServiceBusConnectionString_client_internal=Endpoint=sb://service-bus;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true; update-exception: container_name: update-exception @@ -326,6 +332,7 @@ services: - AuthTokenURL=https://int.api.service.nhs.uk/oauth2/token - LocalPrivateKeyFileName=RetrievePdsDemographic-DEV1.pem.key - ParticipantManagementTopic=participant-management-topic + - ServiceBusConnectionString_internal=Endpoint=sb://service-bus;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true; - ServiceBusConnectionString_client_internal=Endpoint=sb://service-bus;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true; - ClientId=Get-private-key-from-NHS-dev-portal - UseFakePDSServices=true @@ -430,6 +437,7 @@ services: - ServiceNowClientSecret=MockClientSecret-123 - ServiceNowRefreshToken=MockRefreshToken-123 - ServiceNowParticipantManagementTopic=servicenow-participant-management-topic + - ServiceBusConnectionString_internal=Endpoint=sb://service-bus;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true; - ServiceBusConnectionString_client_internal=Endpoint=sb://service-bus;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true; ports: - 9092:9092 diff --git a/application/CohortManager/src/Functions/AuditServices/AuditWriter/AuditConfig.cs b/application/CohortManager/src/Functions/AuditServices/AuditWriter/AuditConfig.cs index 0bff129799..39f0762a81 100644 --- a/application/CohortManager/src/Functions/AuditServices/AuditWriter/AuditConfig.cs +++ b/application/CohortManager/src/Functions/AuditServices/AuditWriter/AuditConfig.cs @@ -5,7 +5,7 @@ namespace NHS.CohortManager.AuditServices; public class AuditConfig { [Required] - public required string ServiceBusConnectionString { get; set; } + public required string ServiceBusConnectionString_client_internal { get; set; } [Required] public required string AzureWebJobsStorage { get; set; } [Required] diff --git a/application/CohortManager/src/Functions/AuditServices/AuditWriter/AuditWriter.cs b/application/CohortManager/src/Functions/AuditServices/AuditWriter/AuditWriter.cs index b0a2a2f75f..0067b5db7f 100644 --- a/application/CohortManager/src/Functions/AuditServices/AuditWriter/AuditWriter.cs +++ b/application/CohortManager/src/Functions/AuditServices/AuditWriter/AuditWriter.cs @@ -24,7 +24,7 @@ public AuditWriter(DataServicesContext dbContext, ILogger logger) [Function(nameof(AuditWriter))] public async Task Run( - [ServiceBusTrigger(topicName: "%AuditTopicName%", subscriptionName: "%AuditSubscription%", Connection = "ServiceBusConnectionString")] string messageText, FunctionContext context) + [ServiceBusTrigger(topicName: "%AuditTopicName%", subscriptionName: "%AuditSubscription%", Connection = "ServiceBusConnectionString_internal")] string messageText, FunctionContext context) { ParticipantAuditMessage? audit; try diff --git a/application/CohortManager/src/Functions/AuditServices/AuditWriter/Program.cs b/application/CohortManager/src/Functions/AuditServices/AuditWriter/Program.cs index 08e5fb6688..5fe18b0d6e 100644 --- a/application/CohortManager/src/Functions/AuditServices/AuditWriter/Program.cs +++ b/application/CohortManager/src/Functions/AuditServices/AuditWriter/Program.cs @@ -1,7 +1,4 @@ using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.DependencyInjection; -using DataServices.Core; -using DataServices.Database; using HealthChecks.Extensions; using Common; using NHS.CohortManager.AuditServices; @@ -9,11 +6,10 @@ var host = new HostBuilder() .ConfigureFunctionsWorkerDefaults() .AddConfiguration(out AuditConfig auditConfig) - .AddDataServicesHandler() - .AddServiceBusClient(auditConfig.ServiceBusConnectionString) + .AddServiceBusClient(auditConfig.ServiceBusConnectionString_client_internal) .ConfigureServices(services => { - services.AddDatabaseHealthCheck("AuditWriter"); + services.AddBasicHealthCheck("AuditWriter"); }) .AddTelemetry() .Build(); diff --git a/application/CohortManager/src/Functions/CaasIntegration/RetrieveMeshFile/host.json b/application/CohortManager/src/Functions/CaasIntegration/RetrieveMeshFile/host.json index 8c03a44dc0..7c5d32adab 100644 --- a/application/CohortManager/src/Functions/CaasIntegration/RetrieveMeshFile/host.json +++ b/application/CohortManager/src/Functions/CaasIntegration/RetrieveMeshFile/host.json @@ -10,7 +10,8 @@ }, "logLevel": { "HealthChecks": "Error", - "HealthChecks.Extensions": "Error" + "HealthChecks.Extensions": "Error", + "Function.health": "Error" } } } diff --git a/application/CohortManager/src/Functions/CaasIntegration/receiveCaasFile/host.json b/application/CohortManager/src/Functions/CaasIntegration/receiveCaasFile/host.json index 08a47f7b67..b856e5c9ce 100644 --- a/application/CohortManager/src/Functions/CaasIntegration/receiveCaasFile/host.json +++ b/application/CohortManager/src/Functions/CaasIntegration/receiveCaasFile/host.json @@ -11,7 +11,8 @@ }, "logLevel": { "HealthChecks": "Error", - "HealthChecks.Extensions": "Error" + "HealthChecks.Extensions": "Error", + "Function.health": "Error" } }, "concurrency": { diff --git a/application/CohortManager/src/Functions/CohortDistributionServices/DistributeParticipant/host.json b/application/CohortManager/src/Functions/CohortDistributionServices/DistributeParticipant/host.json index 3aaec09232..766298f4fa 100644 --- a/application/CohortManager/src/Functions/CohortDistributionServices/DistributeParticipant/host.json +++ b/application/CohortManager/src/Functions/CohortDistributionServices/DistributeParticipant/host.json @@ -7,11 +7,12 @@ "isEnabled": true, "excludedTypes": "Request" }, - "enableLiveMetricsFilters": true, - "logLevel": { - "HealthChecks": "Error", - "HealthChecks.Extensions": "Error" - } + "enableLiveMetricsFilters": true + }, + "logLevel": { + "HealthChecks": "Error", + "HealthChecks.Extensions": "Error", + "Function.health": "Error" } }, "concurrency": { diff --git a/application/CohortManager/src/Functions/CohortDistributionServices/RetrieveCohortDistribution/host.json b/application/CohortManager/src/Functions/CohortDistributionServices/RetrieveCohortDistribution/host.json index 72404b633c..e8b5adcd9a 100644 --- a/application/CohortManager/src/Functions/CohortDistributionServices/RetrieveCohortDistribution/host.json +++ b/application/CohortManager/src/Functions/CohortDistributionServices/RetrieveCohortDistribution/host.json @@ -11,7 +11,8 @@ }, "logLevel": { "HealthChecks": "Error", - "HealthChecks.Extensions": "Error" + "HealthChecks.Extensions": "Error", + "Function.health": "Error" } } } diff --git a/application/CohortManager/src/Functions/CohortDistributionServices/RetrieveCohortRequestAudit/host.json b/application/CohortManager/src/Functions/CohortDistributionServices/RetrieveCohortRequestAudit/host.json index 72404b633c..e8b5adcd9a 100644 --- a/application/CohortManager/src/Functions/CohortDistributionServices/RetrieveCohortRequestAudit/host.json +++ b/application/CohortManager/src/Functions/CohortDistributionServices/RetrieveCohortRequestAudit/host.json @@ -11,7 +11,8 @@ }, "logLevel": { "HealthChecks": "Error", - "HealthChecks.Extensions": "Error" + "HealthChecks.Extensions": "Error", + "Function.health": "Error" } } } diff --git a/application/CohortManager/src/Functions/CohortDistributionServices/TransformDataService/host.json b/application/CohortManager/src/Functions/CohortDistributionServices/TransformDataService/host.json index 72404b633c..e8b5adcd9a 100644 --- a/application/CohortManager/src/Functions/CohortDistributionServices/TransformDataService/host.json +++ b/application/CohortManager/src/Functions/CohortDistributionServices/TransformDataService/host.json @@ -11,7 +11,8 @@ }, "logLevel": { "HealthChecks": "Error", - "HealthChecks.Extensions": "Error" + "HealthChecks.Extensions": "Error", + "Function.health": "Error" } } } diff --git a/application/CohortManager/src/Functions/DemographicServices/DemographicDurableFunction/HealthCheckFunction.cs b/application/CohortManager/src/Functions/DemographicServices/DemographicDurableFunction/HealthCheckFunction.cs index d22aad015a..7f1b4872be 100644 --- a/application/CohortManager/src/Functions/DemographicServices/DemographicDurableFunction/HealthCheckFunction.cs +++ b/application/CohortManager/src/Functions/DemographicServices/DemographicDurableFunction/HealthCheckFunction.cs @@ -1,7 +1,7 @@ namespace NHS.CohortManager.DemographicServices; -using System.Net; using System.Threading.Tasks; +using HealthChecks.Extensions; using Microsoft.Azure.Functions.Worker; using Microsoft.Azure.Functions.Worker.Http; using Microsoft.Extensions.Diagnostics.HealthChecks; @@ -18,15 +18,6 @@ public HealthCheckFunction(HealthCheckService healthCheckService) [Function("health")] public async Task Run([HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpRequestData req) { - var healthReport = await _healthCheckService.CheckHealthAsync(); - - var response = req.CreateResponse(healthReport.Status == HealthStatus.Healthy ? HttpStatusCode.OK : HttpStatusCode.ServiceUnavailable); - await response.WriteAsJsonAsync(new - { - status = healthReport.Status.ToString(), - details = healthReport.Entries - }); - - return response; + return await HealthCheckServiceExtensions.CreateHealthCheckResponseAsync(req, _healthCheckService); } } diff --git a/application/CohortManager/src/Functions/DemographicServices/DemographicDurableFunction/host.json b/application/CohortManager/src/Functions/DemographicServices/DemographicDurableFunction/host.json index 477ce788c6..d1c8b44dfa 100644 --- a/application/CohortManager/src/Functions/DemographicServices/DemographicDurableFunction/host.json +++ b/application/CohortManager/src/Functions/DemographicServices/DemographicDurableFunction/host.json @@ -10,7 +10,8 @@ }, "logLevel": { "HealthChecks": "Error", - "HealthChecks.Extensions": "Error" + "HealthChecks.Extensions": "Error", + "Function.health": "Error" } }, "extensions": { diff --git a/application/CohortManager/src/Functions/DemographicServices/ManageCaasSubscription/host.json b/application/CohortManager/src/Functions/DemographicServices/ManageCaasSubscription/host.json new file mode 100644 index 0000000000..c06a745ac0 --- /dev/null +++ b/application/CohortManager/src/Functions/DemographicServices/ManageCaasSubscription/host.json @@ -0,0 +1,18 @@ +{ + "version": "2.0", + "functionTimeout": "01:00:00", + "logging": { + "applicationInsights": { + "samplingSettings": { + "isEnabled": true, + "excludedTypes": "Request" + }, + "enableLiveMetricsFilters": true + }, + "logLevel": { + "HealthChecks": "Error", + "HealthChecks.Extensions": "Error", + "Function.health": "Error" + } + } +} diff --git a/application/CohortManager/src/Functions/DemographicServices/ManageNemsSubscription/host.json b/application/CohortManager/src/Functions/DemographicServices/ManageNemsSubscription/host.json index 623a1a499f..c06a745ac0 100644 --- a/application/CohortManager/src/Functions/DemographicServices/ManageNemsSubscription/host.json +++ b/application/CohortManager/src/Functions/DemographicServices/ManageNemsSubscription/host.json @@ -11,7 +11,8 @@ }, "logLevel": { "HealthChecks": "Error", - "HealthChecks.Extensions": "Error" + "HealthChecks.Extensions": "Error", + "Function.health": "Error" } } } diff --git a/application/CohortManager/src/Functions/DemographicServices/RetrievePDSDemographic/HealthCheckFunction.cs b/application/CohortManager/src/Functions/DemographicServices/RetrievePDSDemographic/HealthCheckFunction.cs index d22aad015a..7f1b4872be 100644 --- a/application/CohortManager/src/Functions/DemographicServices/RetrievePDSDemographic/HealthCheckFunction.cs +++ b/application/CohortManager/src/Functions/DemographicServices/RetrievePDSDemographic/HealthCheckFunction.cs @@ -1,7 +1,7 @@ namespace NHS.CohortManager.DemographicServices; -using System.Net; using System.Threading.Tasks; +using HealthChecks.Extensions; using Microsoft.Azure.Functions.Worker; using Microsoft.Azure.Functions.Worker.Http; using Microsoft.Extensions.Diagnostics.HealthChecks; @@ -18,15 +18,6 @@ public HealthCheckFunction(HealthCheckService healthCheckService) [Function("health")] public async Task Run([HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpRequestData req) { - var healthReport = await _healthCheckService.CheckHealthAsync(); - - var response = req.CreateResponse(healthReport.Status == HealthStatus.Healthy ? HttpStatusCode.OK : HttpStatusCode.ServiceUnavailable); - await response.WriteAsJsonAsync(new - { - status = healthReport.Status.ToString(), - details = healthReport.Entries - }); - - return response; + return await HealthCheckServiceExtensions.CreateHealthCheckResponseAsync(req, _healthCheckService); } } diff --git a/application/CohortManager/src/Functions/DemographicServices/RetrievePDSDemographic/host.json b/application/CohortManager/src/Functions/DemographicServices/RetrievePDSDemographic/host.json index 623a1a499f..c06a745ac0 100644 --- a/application/CohortManager/src/Functions/DemographicServices/RetrievePDSDemographic/host.json +++ b/application/CohortManager/src/Functions/DemographicServices/RetrievePDSDemographic/host.json @@ -11,7 +11,8 @@ }, "logLevel": { "HealthChecks": "Error", - "HealthChecks.Extensions": "Error" + "HealthChecks.Extensions": "Error", + "Function.health": "Error" } } } diff --git a/application/CohortManager/src/Functions/ExceptionHandling/CreateException/CreateException.cs b/application/CohortManager/src/Functions/ExceptionHandling/CreateException/CreateException.cs index 7a8550150c..50128fe34a 100644 --- a/application/CohortManager/src/Functions/ExceptionHandling/CreateException/CreateException.cs +++ b/application/CohortManager/src/Functions/ExceptionHandling/CreateException/CreateException.cs @@ -53,7 +53,7 @@ public async Task RunAsync([HttpTrigger(AuthorizationLevel.Ano [Function("RunCreateException")] public async Task Run( - [ServiceBusTrigger(topicName: "%CreateExceptionTopic%", subscriptionName: "%ExceptionSubscription%", Connection = "ServiceBusConnectionString", AutoCompleteMessages = false)] + [ServiceBusTrigger(topicName: "%CreateExceptionTopic%", subscriptionName: "%ExceptionSubscription%", Connection = "ServiceBusConnectionString_internal", AutoCompleteMessages = false)] ServiceBusReceivedMessage message, ServiceBusMessageActions messageActions) { diff --git a/application/CohortManager/src/Functions/ExceptionHandling/CreateException/CreateExceptionConfig.cs b/application/CohortManager/src/Functions/ExceptionHandling/CreateException/CreateExceptionConfig.cs index 19a96de8ea..6ebef39eba 100644 --- a/application/CohortManager/src/Functions/ExceptionHandling/CreateException/CreateExceptionConfig.cs +++ b/application/CohortManager/src/Functions/ExceptionHandling/CreateException/CreateExceptionConfig.cs @@ -8,4 +8,6 @@ public class CreateExceptionConfig public required string ExceptionManagementDataServiceURL {get; set;} [Required] public required string DemographicDataServiceURL {get; set;} + [Required] + public required string ServiceBusConnectionString_client_internal { get; set; } } diff --git a/application/CohortManager/src/Functions/ExceptionHandling/CreateException/HealthCheckFunction.cs b/application/CohortManager/src/Functions/ExceptionHandling/CreateException/HealthCheckFunction.cs index 230e295a1d..5111364524 100644 --- a/application/CohortManager/src/Functions/ExceptionHandling/CreateException/HealthCheckFunction.cs +++ b/application/CohortManager/src/Functions/ExceptionHandling/CreateException/HealthCheckFunction.cs @@ -1,7 +1,7 @@ namespace NHS.CohortManager.ExceptionService; -using System.Net; using System.Threading.Tasks; +using HealthChecks.Extensions; using Microsoft.Azure.Functions.Worker; using Microsoft.Azure.Functions.Worker.Http; using Microsoft.Extensions.Diagnostics.HealthChecks; @@ -18,15 +18,6 @@ public HealthCheckFunction(HealthCheckService healthCheckService) [Function("health")] public async Task Run([HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpRequestData req) { - var healthReport = await _healthCheckService.CheckHealthAsync(); - - var response = req.CreateResponse(healthReport.Status == HealthStatus.Healthy ? HttpStatusCode.OK : HttpStatusCode.ServiceUnavailable); - await response.WriteAsJsonAsync(new - { - status = healthReport.Status.ToString(), - details = healthReport.Entries - }); - - return response; + return await HealthCheckServiceExtensions.CreateHealthCheckResponseAsync(req, _healthCheckService); } } diff --git a/application/CohortManager/src/Functions/ExceptionHandling/CreateException/Program.cs b/application/CohortManager/src/Functions/ExceptionHandling/CreateException/Program.cs index b4cdb3fa46..911287d998 100644 --- a/application/CohortManager/src/Functions/ExceptionHandling/CreateException/Program.cs +++ b/application/CohortManager/src/Functions/ExceptionHandling/CreateException/Program.cs @@ -13,6 +13,7 @@ .AddDataService(config.ExceptionManagementDataServiceURL) .AddDataService(config.DemographicDataServiceURL) .Build() + .AddServiceBusClient(config.ServiceBusConnectionString_client_internal) .ConfigureFunctionsWebApplication() .ConfigureServices(services => { diff --git a/application/CohortManager/src/Functions/ExceptionHandling/CreateException/host.json b/application/CohortManager/src/Functions/ExceptionHandling/CreateException/host.json index 623a1a499f..c06a745ac0 100644 --- a/application/CohortManager/src/Functions/ExceptionHandling/CreateException/host.json +++ b/application/CohortManager/src/Functions/ExceptionHandling/CreateException/host.json @@ -11,7 +11,8 @@ }, "logLevel": { "HealthChecks": "Error", - "HealthChecks.Extensions": "Error" + "HealthChecks.Extensions": "Error", + "Function.health": "Error" } } } diff --git a/application/CohortManager/src/Functions/ExceptionHandling/UpdateException/HealthCheckFunction.cs b/application/CohortManager/src/Functions/ExceptionHandling/UpdateException/HealthCheckFunction.cs index 230e295a1d..5111364524 100644 --- a/application/CohortManager/src/Functions/ExceptionHandling/UpdateException/HealthCheckFunction.cs +++ b/application/CohortManager/src/Functions/ExceptionHandling/UpdateException/HealthCheckFunction.cs @@ -1,7 +1,7 @@ namespace NHS.CohortManager.ExceptionService; -using System.Net; using System.Threading.Tasks; +using HealthChecks.Extensions; using Microsoft.Azure.Functions.Worker; using Microsoft.Azure.Functions.Worker.Http; using Microsoft.Extensions.Diagnostics.HealthChecks; @@ -18,15 +18,6 @@ public HealthCheckFunction(HealthCheckService healthCheckService) [Function("health")] public async Task Run([HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpRequestData req) { - var healthReport = await _healthCheckService.CheckHealthAsync(); - - var response = req.CreateResponse(healthReport.Status == HealthStatus.Healthy ? HttpStatusCode.OK : HttpStatusCode.ServiceUnavailable); - await response.WriteAsJsonAsync(new - { - status = healthReport.Status.ToString(), - details = healthReport.Entries - }); - - return response; + return await HealthCheckServiceExtensions.CreateHealthCheckResponseAsync(req, _healthCheckService); } } diff --git a/application/CohortManager/src/Functions/ExceptionHandling/UpdateException/host.json b/application/CohortManager/src/Functions/ExceptionHandling/UpdateException/host.json index 623a1a499f..c06a745ac0 100644 --- a/application/CohortManager/src/Functions/ExceptionHandling/UpdateException/host.json +++ b/application/CohortManager/src/Functions/ExceptionHandling/UpdateException/host.json @@ -11,7 +11,8 @@ }, "logLevel": { "HealthChecks": "Error", - "HealthChecks.Extensions": "Error" + "HealthChecks.Extensions": "Error", + "Function.health": "Error" } } } diff --git a/application/CohortManager/src/Functions/NemsSubscriptionService/NemsMeshRetrieval/host.json b/application/CohortManager/src/Functions/NemsSubscriptionService/NemsMeshRetrieval/host.json index 8c03a44dc0..7c5d32adab 100644 --- a/application/CohortManager/src/Functions/NemsSubscriptionService/NemsMeshRetrieval/host.json +++ b/application/CohortManager/src/Functions/NemsSubscriptionService/NemsMeshRetrieval/host.json @@ -10,7 +10,8 @@ }, "logLevel": { "HealthChecks": "Error", - "HealthChecks.Extensions": "Error" + "HealthChecks.Extensions": "Error", + "Function.health": "Error" } } } diff --git a/application/CohortManager/src/Functions/NemsSubscriptionService/ProcessNemsUpdate/host.json b/application/CohortManager/src/Functions/NemsSubscriptionService/ProcessNemsUpdate/host.json index 623a1a499f..c06a745ac0 100644 --- a/application/CohortManager/src/Functions/NemsSubscriptionService/ProcessNemsUpdate/host.json +++ b/application/CohortManager/src/Functions/NemsSubscriptionService/ProcessNemsUpdate/host.json @@ -11,7 +11,8 @@ }, "logLevel": { "HealthChecks": "Error", - "HealthChecks.Extensions": "Error" + "HealthChecks.Extensions": "Error", + "Function.health": "Error" } } } diff --git a/application/CohortManager/src/Functions/ParticipantManagementServices/DeleteParticipant/DeleteParticipant.csproj b/application/CohortManager/src/Functions/ParticipantManagementServices/DeleteParticipant/DeleteParticipant.csproj index 171909514d..154dbbc20c 100644 --- a/application/CohortManager/src/Functions/ParticipantManagementServices/DeleteParticipant/DeleteParticipant.csproj +++ b/application/CohortManager/src/Functions/ParticipantManagementServices/DeleteParticipant/DeleteParticipant.csproj @@ -8,8 +8,11 @@ enable + + + @@ -30,4 +33,4 @@ - + \ No newline at end of file diff --git a/application/CohortManager/src/Functions/ParticipantManagementServices/DeleteParticipant/Program.cs b/application/CohortManager/src/Functions/ParticipantManagementServices/DeleteParticipant/Program.cs index fdabb4ae9f..6c331f4ee3 100644 --- a/application/CohortManager/src/Functions/ParticipantManagementServices/DeleteParticipant/Program.cs +++ b/application/CohortManager/src/Functions/ParticipantManagementServices/DeleteParticipant/Program.cs @@ -8,9 +8,10 @@ using NHS.Screening.DeleteParticipant; var host = new HostBuilder() - .ConfigureFunctionsWorkerDefaults() .AddConfiguration(out DeleteParticipantConfig config) + .ConfigureFunctionsWebApplication() .AddDataServicesHandler() + .AddDataService(config.ParticipantDemographicDataServiceUrl) .AddDataService(config.CohortDistributionDataServiceUrl) .Build() .ConfigureServices(services => @@ -20,9 +21,10 @@ // Register health checks services.AddBasicHealthCheck("DeleteParticipant"); }) - .AddTelemetry() .AddExceptionHandler() .AddHttpClient() + .AddTelemetry() .Build(); + await host.RunAsync(); diff --git a/application/CohortManager/src/Functions/ParticipantManagementServices/DeleteParticipant/host.json b/application/CohortManager/src/Functions/ParticipantManagementServices/DeleteParticipant/host.json index 623a1a499f..c06a745ac0 100644 --- a/application/CohortManager/src/Functions/ParticipantManagementServices/DeleteParticipant/host.json +++ b/application/CohortManager/src/Functions/ParticipantManagementServices/DeleteParticipant/host.json @@ -11,7 +11,8 @@ }, "logLevel": { "HealthChecks": "Error", - "HealthChecks.Extensions": "Error" + "HealthChecks.Extensions": "Error", + "Function.health": "Error" } } } diff --git a/application/CohortManager/src/Functions/ParticipantManagementServices/ManageParticipant/host.json b/application/CohortManager/src/Functions/ParticipantManagementServices/ManageParticipant/host.json index 31e8111d7f..7fc671df61 100644 --- a/application/CohortManager/src/Functions/ParticipantManagementServices/ManageParticipant/host.json +++ b/application/CohortManager/src/Functions/ParticipantManagementServices/ManageParticipant/host.json @@ -19,7 +19,8 @@ }, "logLevel": { "HealthChecks": "Error", - "HealthChecks.Extensions": "Error" + "HealthChecks.Extensions": "Error", + "Function.health": "Error" } } } diff --git a/application/CohortManager/src/Functions/ParticipantManagementServices/ManageServiceNowParticipant/host.json b/application/CohortManager/src/Functions/ParticipantManagementServices/ManageServiceNowParticipant/host.json index 623a1a499f..c06a745ac0 100644 --- a/application/CohortManager/src/Functions/ParticipantManagementServices/ManageServiceNowParticipant/host.json +++ b/application/CohortManager/src/Functions/ParticipantManagementServices/ManageServiceNowParticipant/host.json @@ -11,7 +11,8 @@ }, "logLevel": { "HealthChecks": "Error", - "HealthChecks.Extensions": "Error" + "HealthChecks.Extensions": "Error", + "Function.health": "Error" } } } diff --git a/application/CohortManager/src/Functions/ParticipantManagementServices/RemoveDummyGPCode/Properties/launchSettings.json b/application/CohortManager/src/Functions/ParticipantManagementServices/RemoveDummyGPCode/Properties/launchSettings.json index fd7fb010a9..600a530d35 100644 --- a/application/CohortManager/src/Functions/ParticipantManagementServices/RemoveDummyGPCode/Properties/launchSettings.json +++ b/application/CohortManager/src/Functions/ParticipantManagementServices/RemoveDummyGPCode/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "ManageServiceNowParticipant": { "commandName": "Project", - "commandLineArgs": "--port 9092", + "commandLineArgs": "--port 9093", "launchBrowser": false } } diff --git a/application/CohortManager/src/Functions/ParticipantManagementServices/RemoveDummyGPCode/host.json b/application/CohortManager/src/Functions/ParticipantManagementServices/RemoveDummyGPCode/host.json new file mode 100644 index 0000000000..c06a745ac0 --- /dev/null +++ b/application/CohortManager/src/Functions/ParticipantManagementServices/RemoveDummyGPCode/host.json @@ -0,0 +1,18 @@ +{ + "version": "2.0", + "functionTimeout": "01:00:00", + "logging": { + "applicationInsights": { + "samplingSettings": { + "isEnabled": true, + "excludedTypes": "Request" + }, + "enableLiveMetricsFilters": true + }, + "logLevel": { + "HealthChecks": "Error", + "HealthChecks.Extensions": "Error", + "Function.health": "Error" + } + } +} diff --git a/application/CohortManager/src/Functions/ParticipantManagementServices/UpdateBlockedFlag/host.json b/application/CohortManager/src/Functions/ParticipantManagementServices/UpdateBlockedFlag/host.json index 623a1a499f..c06a745ac0 100644 --- a/application/CohortManager/src/Functions/ParticipantManagementServices/UpdateBlockedFlag/host.json +++ b/application/CohortManager/src/Functions/ParticipantManagementServices/UpdateBlockedFlag/host.json @@ -11,7 +11,8 @@ }, "logLevel": { "HealthChecks": "Error", - "HealthChecks.Extensions": "Error" + "HealthChecks.Extensions": "Error", + "Function.health": "Error" } } } diff --git a/application/CohortManager/src/Functions/ScreeningValidationService/LookupValidation/HealthCheckFunction.cs b/application/CohortManager/src/Functions/ScreeningValidationService/LookupValidation/HealthCheckFunction.cs index fee1bee78c..4664adb692 100644 --- a/application/CohortManager/src/Functions/ScreeningValidationService/LookupValidation/HealthCheckFunction.cs +++ b/application/CohortManager/src/Functions/ScreeningValidationService/LookupValidation/HealthCheckFunction.cs @@ -44,4 +44,4 @@ await response.WriteAsJsonAsync(new } return response; } -} \ No newline at end of file +} diff --git a/application/CohortManager/src/Functions/ScreeningValidationService/LookupValidation/host.json b/application/CohortManager/src/Functions/ScreeningValidationService/LookupValidation/host.json index 959cf8e420..8ccdd03b80 100644 --- a/application/CohortManager/src/Functions/ScreeningValidationService/LookupValidation/host.json +++ b/application/CohortManager/src/Functions/ScreeningValidationService/LookupValidation/host.json @@ -16,7 +16,8 @@ "Host.Results": "Information", "DataServices.Client": "Information", "HealthChecks": "Error", - "HealthChecks.Extensions": "Error" + "HealthChecks.Extensions": "Error", + "Function.health": "Error" } } } diff --git a/application/CohortManager/src/Functions/ScreeningValidationService/RemoveValidationException/HealthCheckFunction.cs b/application/CohortManager/src/Functions/ScreeningValidationService/RemoveValidationException/HealthCheckFunction.cs index 3a1718f2ed..ba97264c44 100644 --- a/application/CohortManager/src/Functions/ScreeningValidationService/RemoveValidationException/HealthCheckFunction.cs +++ b/application/CohortManager/src/Functions/ScreeningValidationService/RemoveValidationException/HealthCheckFunction.cs @@ -1,7 +1,7 @@ namespace NHS.CohortManager.ScreeningValidationService; -using System.Net; using System.Threading.Tasks; +using HealthChecks.Extensions; using Microsoft.Azure.Functions.Worker; using Microsoft.Azure.Functions.Worker.Http; using Microsoft.Extensions.Diagnostics.HealthChecks; @@ -18,15 +18,6 @@ public HealthCheckFunction(HealthCheckService healthCheckService) [Function("health")] public async Task Run([HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpRequestData req) { - var healthReport = await _healthCheckService.CheckHealthAsync(); - - var response = req.CreateResponse(healthReport.Status == HealthStatus.Healthy ? HttpStatusCode.OK : HttpStatusCode.ServiceUnavailable); - await response.WriteAsJsonAsync(new - { - status = healthReport.Status.ToString(), - details = healthReport.Entries - }); - - return response; + return await HealthCheckServiceExtensions.CreateHealthCheckResponseAsync(req, _healthCheckService); } } \ No newline at end of file diff --git a/application/CohortManager/src/Functions/ScreeningValidationService/RemoveValidationException/host.json b/application/CohortManager/src/Functions/ScreeningValidationService/RemoveValidationException/host.json index 623a1a499f..c06a745ac0 100644 --- a/application/CohortManager/src/Functions/ScreeningValidationService/RemoveValidationException/host.json +++ b/application/CohortManager/src/Functions/ScreeningValidationService/RemoveValidationException/host.json @@ -11,7 +11,8 @@ }, "logLevel": { "HealthChecks": "Error", - "HealthChecks.Extensions": "Error" + "HealthChecks.Extensions": "Error", + "Function.health": "Error" } } } diff --git a/application/CohortManager/src/Functions/ScreeningValidationService/StaticValidation/host.json b/application/CohortManager/src/Functions/ScreeningValidationService/StaticValidation/host.json index 623a1a499f..c06a745ac0 100644 --- a/application/CohortManager/src/Functions/ScreeningValidationService/StaticValidation/host.json +++ b/application/CohortManager/src/Functions/ScreeningValidationService/StaticValidation/host.json @@ -11,7 +11,8 @@ }, "logLevel": { "HealthChecks": "Error", - "HealthChecks.Extensions": "Error" + "HealthChecks.Extensions": "Error", + "Function.health": "Error" } } } diff --git a/application/CohortManager/src/Functions/ServiceNowIntegration/ServiceNowCohortLookup/host.json b/application/CohortManager/src/Functions/ServiceNowIntegration/ServiceNowCohortLookup/host.json index e0814cc150..c06a745ac0 100644 --- a/application/CohortManager/src/Functions/ServiceNowIntegration/ServiceNowCohortLookup/host.json +++ b/application/CohortManager/src/Functions/ServiceNowIntegration/ServiceNowCohortLookup/host.json @@ -1,13 +1,18 @@ { - "version": "2.0", - "functionTimeout": "01:00:00", - "logging": { - "applicationInsights": { - "samplingSettings": { - "isEnabled": true, - "excludedTypes": "Request" - }, - "enableLiveMetricsFilters": true - } + "version": "2.0", + "functionTimeout": "01:00:00", + "logging": { + "applicationInsights": { + "samplingSettings": { + "isEnabled": true, + "excludedTypes": "Request" + }, + "enableLiveMetricsFilters": true + }, + "logLevel": { + "HealthChecks": "Error", + "HealthChecks.Extensions": "Error", + "Function.health": "Error" } + } } diff --git a/application/CohortManager/src/Functions/ServiceNowIntegration/ServiceNowMessageHandler/host.json b/application/CohortManager/src/Functions/ServiceNowIntegration/ServiceNowMessageHandler/host.json index 623a1a499f..c06a745ac0 100644 --- a/application/CohortManager/src/Functions/ServiceNowIntegration/ServiceNowMessageHandler/host.json +++ b/application/CohortManager/src/Functions/ServiceNowIntegration/ServiceNowMessageHandler/host.json @@ -11,7 +11,8 @@ }, "logLevel": { "HealthChecks": "Error", - "HealthChecks.Extensions": "Error" + "HealthChecks.Extensions": "Error", + "Function.health": "Error" } } } diff --git a/application/CohortManager/src/Functions/Shared/Common/ExceptionServiceBusConfig.cs b/application/CohortManager/src/Functions/Shared/Common/ExceptionServiceBusConfig.cs index 9f9fa14e9b..46b9e0933a 100644 --- a/application/CohortManager/src/Functions/Shared/Common/ExceptionServiceBusConfig.cs +++ b/application/CohortManager/src/Functions/Shared/Common/ExceptionServiceBusConfig.cs @@ -5,10 +5,10 @@ namespace Common; public class ExceptionServiceBusConfig { [Required] - public required string ServiceBusConnectionString { get; set; } + public required string ServiceBusConnectionString_client_internal { get; set; } [Required] public required string CreateExceptionTopic { get; set; } public bool UseServiceBus { get; set; } = false; -} \ No newline at end of file +} diff --git a/application/CohortManager/src/Functions/Shared/Common/Extensions/ExceptionHandlerServiceExtension.cs b/application/CohortManager/src/Functions/Shared/Common/Extensions/ExceptionHandlerServiceExtension.cs index 13ca1c2643..ac02d106cf 100644 --- a/application/CohortManager/src/Functions/Shared/Common/Extensions/ExceptionHandlerServiceExtension.cs +++ b/application/CohortManager/src/Functions/Shared/Common/Extensions/ExceptionHandlerServiceExtension.cs @@ -19,7 +19,7 @@ public static IHostBuilder AddExceptionHandler(this IHostBuilder hostBuilder) if (useServiceBus) { hostBuilder.AddConfiguration(out ExceptionServiceBusConfig config); - hostBuilder.AddKeyedAzureQueues(config.UseServiceBus, config.ServiceBusConnectionString, "Exception"); + hostBuilder.AddKeyedAzureQueues(config.UseServiceBus, config.ServiceBusConnectionString_client_internal, "Exception"); return hostBuilder.ConfigureServices(_ => { _.AddSingleton(); diff --git a/application/CohortManager/src/Functions/Shared/Common/Extensions/TelemetryExtension.cs b/application/CohortManager/src/Functions/Shared/Common/Extensions/TelemetryExtension.cs index 2cda1f3197..9cbf365b24 100644 --- a/application/CohortManager/src/Functions/Shared/Common/Extensions/TelemetryExtension.cs +++ b/application/CohortManager/src/Functions/Shared/Common/Extensions/TelemetryExtension.cs @@ -9,15 +9,15 @@ public static class TelemetryExtension { public static IHostBuilder AddTelemetry(this IHostBuilder hostBuilder) { - return hostBuilder.ConfigureServices(_ => + return hostBuilder.ConfigureServices(sc => { - _.AddApplicationInsightsTelemetryWorkerService(); - _.ConfigureFunctionsApplicationInsights(); - _.ConfigureTelemetryModule((module, o) => + sc.AddApplicationInsightsTelemetryWorkerService(); + sc.ConfigureFunctionsApplicationInsights(); + sc.ConfigureTelemetryModule((module, o) => { module.SetComponentCorrelationHttpHeaders = true; }); - _.AddApplicationInsightsTelemetryProcessor(); + sc.AddApplicationInsightsTelemetryProcessor(); }); } diff --git a/application/CohortManager/src/Functions/Shared/Common/HealthCheckTelemetryFilter.cs b/application/CohortManager/src/Functions/Shared/Common/HealthCheckTelemetryFilter.cs index 90f33a2128..7151690ed4 100644 --- a/application/CohortManager/src/Functions/Shared/Common/HealthCheckTelemetryFilter.cs +++ b/application/CohortManager/src/Functions/Shared/Common/HealthCheckTelemetryFilter.cs @@ -15,25 +15,60 @@ public HealthCheckFilterTelemetryProcessor(ITelemetryProcessor next) public void Process(ITelemetry item) { - if (item is RequestTelemetry request && - request.Url.AbsolutePath.Contains("/health", StringComparison.OrdinalIgnoreCase)) + if (IsHealthCheckTelemetry(item) && !IsException(item)) { return; } - if (item is DependencyTelemetry dependency && - dependency.Data?.Contains("/health") == true) + _next.Process(item); + } + + private static bool IsHealthCheckTelemetry(ITelemetry item) + { + //request telemetry is emitted by the host process and does not flow through this processor, + //so we won't see those here to filter on. We can only filter on dependency and trace telemetry emitted by the worker process. + //this is confirmed by microsoft support in this GitHub issue https://github.com/Azure/azure-functions-dotnet-worker/issues/2024 + if (item is RequestTelemetry request) { - return; + return request.Name?.Equals("health", StringComparison.OrdinalIgnoreCase) == true || + request.Url?.AbsolutePath.Contains("/health", StringComparison.OrdinalIgnoreCase) == true; } - if (item is TraceTelemetry trace && - trace.Properties.TryGetValue("CategoryName", out var categoryName) && - categoryName.Contains("Health", StringComparison.OrdinalIgnoreCase)) + if (item is DependencyTelemetry dependency) { - return; + return dependency.Data?.Contains("/health", StringComparison.OrdinalIgnoreCase) == true || + dependency.Name?.Contains("health", StringComparison.OrdinalIgnoreCase) == true; } - _next.Process(item); + if (item is TraceTelemetry trace) + { + if (trace.Message?.Contains("Functions.health", StringComparison.OrdinalIgnoreCase) == true) + { + return true; + } + + if (trace.Properties.TryGetValue("CategoryName", out var categoryName) && + categoryName.Contains("Health", StringComparison.OrdinalIgnoreCase)) + { + return true; + } + } + + return false; + } + + private static bool IsException(ITelemetry item) + { + if (item is RequestTelemetry request) + { + return !request.Success.GetValueOrDefault(true); + } + + if (item is TraceTelemetry trace) + { + return trace.SeverityLevel >= SeverityLevel.Error; + } + + return item is ExceptionTelemetry; } } diff --git a/application/CohortManager/src/Functions/screeningDataServices/BsSelectRequestAudit/host.json b/application/CohortManager/src/Functions/screeningDataServices/BsSelectRequestAudit/host.json index 623a1a499f..c06a745ac0 100644 --- a/application/CohortManager/src/Functions/screeningDataServices/BsSelectRequestAudit/host.json +++ b/application/CohortManager/src/Functions/screeningDataServices/BsSelectRequestAudit/host.json @@ -11,7 +11,8 @@ }, "logLevel": { "HealthChecks": "Error", - "HealthChecks.Extensions": "Error" + "HealthChecks.Extensions": "Error", + "Function.health": "Error" } } } diff --git a/application/CohortManager/src/Functions/screeningDataServices/CohortDistributionDataService/host.json b/application/CohortManager/src/Functions/screeningDataServices/CohortDistributionDataService/host.json index 623a1a499f..c06a745ac0 100644 --- a/application/CohortManager/src/Functions/screeningDataServices/CohortDistributionDataService/host.json +++ b/application/CohortManager/src/Functions/screeningDataServices/CohortDistributionDataService/host.json @@ -11,7 +11,8 @@ }, "logLevel": { "HealthChecks": "Error", - "HealthChecks.Extensions": "Error" + "HealthChecks.Extensions": "Error", + "Function.health": "Error" } } } diff --git a/application/CohortManager/src/Functions/screeningDataServices/ExceptionManagementDataService/host.json b/application/CohortManager/src/Functions/screeningDataServices/ExceptionManagementDataService/host.json index 623a1a499f..c06a745ac0 100644 --- a/application/CohortManager/src/Functions/screeningDataServices/ExceptionManagementDataService/host.json +++ b/application/CohortManager/src/Functions/screeningDataServices/ExceptionManagementDataService/host.json @@ -11,7 +11,8 @@ }, "logLevel": { "HealthChecks": "Error", - "HealthChecks.Extensions": "Error" + "HealthChecks.Extensions": "Error", + "Function.health": "Error" } } } diff --git a/application/CohortManager/src/Functions/screeningDataServices/GeneCodeLkpDataService/host.json b/application/CohortManager/src/Functions/screeningDataServices/GeneCodeLkpDataService/host.json index 623a1a499f..c06a745ac0 100644 --- a/application/CohortManager/src/Functions/screeningDataServices/GeneCodeLkpDataService/host.json +++ b/application/CohortManager/src/Functions/screeningDataServices/GeneCodeLkpDataService/host.json @@ -11,7 +11,8 @@ }, "logLevel": { "HealthChecks": "Error", - "HealthChecks.Extensions": "Error" + "HealthChecks.Extensions": "Error", + "Function.health": "Error" } } } diff --git a/application/CohortManager/src/Functions/screeningDataServices/GetValidationExceptions/host.json b/application/CohortManager/src/Functions/screeningDataServices/GetValidationExceptions/host.json index 623a1a499f..c06a745ac0 100644 --- a/application/CohortManager/src/Functions/screeningDataServices/GetValidationExceptions/host.json +++ b/application/CohortManager/src/Functions/screeningDataServices/GetValidationExceptions/host.json @@ -11,7 +11,8 @@ }, "logLevel": { "HealthChecks": "Error", - "HealthChecks.Extensions": "Error" + "HealthChecks.Extensions": "Error", + "Function.health": "Error" } } } diff --git a/application/CohortManager/src/Functions/screeningDataServices/HigherRiskReferralReasonLkpDataService/host.json b/application/CohortManager/src/Functions/screeningDataServices/HigherRiskReferralReasonLkpDataService/host.json index 623a1a499f..c06a745ac0 100644 --- a/application/CohortManager/src/Functions/screeningDataServices/HigherRiskReferralReasonLkpDataService/host.json +++ b/application/CohortManager/src/Functions/screeningDataServices/HigherRiskReferralReasonLkpDataService/host.json @@ -11,7 +11,8 @@ }, "logLevel": { "HealthChecks": "Error", - "HealthChecks.Extensions": "Error" + "HealthChecks.Extensions": "Error", + "Function.health": "Error" } } } diff --git a/application/CohortManager/src/Functions/screeningDataServices/NemsSubscriptionDataService/host.json b/application/CohortManager/src/Functions/screeningDataServices/NemsSubscriptionDataService/host.json index 623a1a499f..c06a745ac0 100644 --- a/application/CohortManager/src/Functions/screeningDataServices/NemsSubscriptionDataService/host.json +++ b/application/CohortManager/src/Functions/screeningDataServices/NemsSubscriptionDataService/host.json @@ -11,7 +11,8 @@ }, "logLevel": { "HealthChecks": "Error", - "HealthChecks.Extensions": "Error" + "HealthChecks.Extensions": "Error", + "Function.health": "Error" } } } diff --git a/application/CohortManager/src/Functions/screeningDataServices/ParticipantDemographicDataService/host.json b/application/CohortManager/src/Functions/screeningDataServices/ParticipantDemographicDataService/host.json index 623a1a499f..c06a745ac0 100644 --- a/application/CohortManager/src/Functions/screeningDataServices/ParticipantDemographicDataService/host.json +++ b/application/CohortManager/src/Functions/screeningDataServices/ParticipantDemographicDataService/host.json @@ -11,7 +11,8 @@ }, "logLevel": { "HealthChecks": "Error", - "HealthChecks.Extensions": "Error" + "HealthChecks.Extensions": "Error", + "Function.health": "Error" } } } diff --git a/application/CohortManager/src/Functions/screeningDataServices/ParticipantManagementDataService/host.json b/application/CohortManager/src/Functions/screeningDataServices/ParticipantManagementDataService/host.json index 623a1a499f..c06a745ac0 100644 --- a/application/CohortManager/src/Functions/screeningDataServices/ParticipantManagementDataService/host.json +++ b/application/CohortManager/src/Functions/screeningDataServices/ParticipantManagementDataService/host.json @@ -11,7 +11,8 @@ }, "logLevel": { "HealthChecks": "Error", - "HealthChecks.Extensions": "Error" + "HealthChecks.Extensions": "Error", + "Function.health": "Error" } } } diff --git a/application/CohortManager/src/Functions/screeningDataServices/ReferenceDataService/host.json b/application/CohortManager/src/Functions/screeningDataServices/ReferenceDataService/host.json index 8c03a44dc0..7c5d32adab 100644 --- a/application/CohortManager/src/Functions/screeningDataServices/ReferenceDataService/host.json +++ b/application/CohortManager/src/Functions/screeningDataServices/ReferenceDataService/host.json @@ -10,7 +10,8 @@ }, "logLevel": { "HealthChecks": "Error", - "HealthChecks.Extensions": "Error" + "HealthChecks.Extensions": "Error", + "Function.health": "Error" } } } diff --git a/application/CohortManager/src/Functions/screeningDataServices/ScreeningLkpDataService/host.json b/application/CohortManager/src/Functions/screeningDataServices/ScreeningLkpDataService/host.json index 623a1a499f..c06a745ac0 100644 --- a/application/CohortManager/src/Functions/screeningDataServices/ScreeningLkpDataService/host.json +++ b/application/CohortManager/src/Functions/screeningDataServices/ScreeningLkpDataService/host.json @@ -11,7 +11,8 @@ }, "logLevel": { "HealthChecks": "Error", - "HealthChecks.Extensions": "Error" + "HealthChecks.Extensions": "Error", + "Function.health": "Error" } } } diff --git a/application/CohortManager/src/Functions/screeningDataServices/ServiceNowCasesDataService/host.json b/application/CohortManager/src/Functions/screeningDataServices/ServiceNowCasesDataService/host.json index 9ee27be75d..c06a745ac0 100644 --- a/application/CohortManager/src/Functions/screeningDataServices/ServiceNowCasesDataService/host.json +++ b/application/CohortManager/src/Functions/screeningDataServices/ServiceNowCasesDataService/host.json @@ -1,13 +1,18 @@ { - "version": "2.0", - "functionTimeout": "01:00:00", - "logging": { - "applicationInsights": { - "samplingSettings": { - "isEnabled": true, - "excludedTypes": "Request" - }, - "enableLiveMetricsFilters": true - } + "version": "2.0", + "functionTimeout": "01:00:00", + "logging": { + "applicationInsights": { + "samplingSettings": { + "isEnabled": true, + "excludedTypes": "Request" + }, + "enableLiveMetricsFilters": true + }, + "logLevel": { + "HealthChecks": "Error", + "HealthChecks.Extensions": "Error", + "Function.health": "Error" } -} \ No newline at end of file + } +} diff --git a/infrastructure/tf-audit/ingestion_transformations.tf b/infrastructure/tf-audit/ingestion_transformations.tf new file mode 100644 index 0000000000..87bb2a0b7e --- /dev/null +++ b/infrastructure/tf-audit/ingestion_transformations.tf @@ -0,0 +1,44 @@ +resource "azapi_resource" "app_requests_workspace_transform" { + count = var.law.app_requests_transform_enabled ? 1 : 0 + + type = "Microsoft.Insights/dataCollectionRules@2022-06-01" + name = "${module.regions_config[local.primary_region].names.log-analytics-workspace}-apprequests-transform" + location = local.primary_region + parent_id = "/subscriptions/${var.TARGET_SUBSCRIPTION_ID}/resourceGroups/${azurerm_resource_group.audit[local.primary_region].name}" + + body = { + kind = "WorkspaceTransforms" + properties = { + destinations = { + logAnalytics = [ + { + workspaceResourceId = module.log_analytics_workspace_audit[local.primary_region].id + name = "workspace" + } + ] + } + dataFlows = [ + { + streams = ["Microsoft-Table-AppRequests"] + destinations = ["workspace"] + transformKql = var.law.app_requests_transform_kql + } + ] + } + } +} + +resource "azapi_update_resource" "law_default_dcr" { + count = var.law.app_requests_transform_enabled ? 1 : 0 + + type = "Microsoft.OperationalInsights/workspaces@2023-09-01" + resource_id = module.log_analytics_workspace_audit[local.primary_region].id + + body = { + properties = { + defaultDataCollectionRuleResourceId = azapi_resource.app_requests_workspace_transform[0].id + } + } + + depends_on = [azapi_resource.app_requests_workspace_transform] +} diff --git a/infrastructure/tf-audit/providers.tf b/infrastructure/tf-audit/providers.tf index c260ae8753..da79b566cd 100644 --- a/infrastructure/tf-audit/providers.tf +++ b/infrastructure/tf-audit/providers.tf @@ -10,6 +10,10 @@ terraform { source = "hashicorp/azuread" version = "2.53.1" } + azapi = { + source = "azure/azapi" + version = "~> 2.0" + } random = "~> 3.5.1" } } @@ -26,3 +30,5 @@ provider "azurerm" { } provider "azuread" {} + +provider "azapi" {} diff --git a/infrastructure/tf-audit/variables.tf b/infrastructure/tf-audit/variables.tf index 185bf3732a..fa60796722 100644 --- a/infrastructure/tf-audit/variables.tf +++ b/infrastructure/tf-audit/variables.tf @@ -79,11 +79,13 @@ variable "app_insights" { variable "law" { description = "Configuration of the Log Analytics Workspace" type = object({ - name = optional(string, "cohman") - law_sku = optional(string, "PerGB2018") - retention_days = optional(number, 30) - export_enabled = optional(bool, false) - export_table_names = optional(list(string), []) + name = optional(string, "cohman") + law_sku = optional(string, "PerGB2018") + retention_days = optional(number, 30) + export_enabled = optional(bool, false) + export_table_names = optional(list(string), []) + app_requests_transform_enabled = optional(bool, true) + app_requests_transform_kql = optional(string, "source | where not(tolower(Name) == \"health\" and tostring(Url) endswith \"/api/health\" and tostring(Properties[\"Category\"]) == \"Host.Results\")") }) } diff --git a/infrastructure/tf-core/environments/development.tfvars b/infrastructure/tf-core/environments/development.tfvars index 3ae6c6fcd1..f6f2629677 100644 --- a/infrastructure/tf-core/environments/development.tfvars +++ b/infrastructure/tf-core/environments/development.tfvars @@ -549,6 +549,10 @@ function_apps = { env_var_name = "ExceptionFunctionURL" function_app_key = "CreateException" }, + { + env_var_name = "ParticipantDemographicDataServiceURL" + function_app_key = "ParticipantDemographicDataService" + }, { env_var_name = "CohortDistributionDataServiceURL" function_app_key = "CohortDistributionDataService" diff --git a/infrastructure/tf-core/environments/integration.tfvars b/infrastructure/tf-core/environments/integration.tfvars index bb051878f6..8325d12f00 100644 --- a/infrastructure/tf-core/environments/integration.tfvars +++ b/infrastructure/tf-core/environments/integration.tfvars @@ -529,6 +529,10 @@ function_apps = { env_var_name = "ExceptionFunctionURL" function_app_key = "CreateException" }, + { + env_var_name = "ParticipantDemographicDataServiceURL" + function_app_key = "ParticipantDemographicDataService" + }, { env_var_name = "CohortDistributionDataServiceURL" function_app_key = "CohortDistributionDataService" diff --git a/infrastructure/tf-core/environments/nft.tfvars b/infrastructure/tf-core/environments/nft.tfvars index b34887810e..4ea913cc3a 100644 --- a/infrastructure/tf-core/environments/nft.tfvars +++ b/infrastructure/tf-core/environments/nft.tfvars @@ -526,6 +526,10 @@ function_apps = { env_var_name = "ExceptionFunctionURL" function_app_key = "CreateException" }, + { + env_var_name = "ParticipantDemographicDataServiceURL" + function_app_key = "ParticipantDemographicDataService" + }, { env_var_name = "CohortDistributionDataServiceURL" function_app_key = "CohortDistributionDataService" diff --git a/infrastructure/tf-core/environments/preprod.tfvars b/infrastructure/tf-core/environments/preprod.tfvars index 8e8509d600..d582abad8a 100644 --- a/infrastructure/tf-core/environments/preprod.tfvars +++ b/infrastructure/tf-core/environments/preprod.tfvars @@ -539,6 +539,10 @@ function_apps = { env_var_name = "ExceptionFunctionURL" function_app_key = "CreateException" }, + { + env_var_name = "ParticipantDemographicDataServiceURL" + function_app_key = "ParticipantDemographicDataService" + }, { env_var_name = "CohortDistributionDataServiceURL" function_app_key = "CohortDistributionDataService" diff --git a/infrastructure/tf-core/environments/production.tfvars b/infrastructure/tf-core/environments/production.tfvars index 366a1f8b4b..2939d18446 100644 --- a/infrastructure/tf-core/environments/production.tfvars +++ b/infrastructure/tf-core/environments/production.tfvars @@ -560,6 +560,10 @@ function_apps = { env_var_name = "ExceptionFunctionURL" function_app_key = "CreateException" }, + { + env_var_name = "ParticipantDemographicDataServiceURL" + function_app_key = "ParticipantDemographicDataService" + }, { env_var_name = "CohortDistributionDataServiceURL" function_app_key = "CohortDistributionDataService" diff --git a/infrastructure/tf-core/environments/sandbox.tfvars b/infrastructure/tf-core/environments/sandbox.tfvars index 764500d932..8db46bca58 100644 --- a/infrastructure/tf-core/environments/sandbox.tfvars +++ b/infrastructure/tf-core/environments/sandbox.tfvars @@ -531,6 +531,10 @@ function_apps = { env_var_name = "ExceptionFunctionURL" function_app_key = "CreateException" }, + { + env_var_name = "ParticipantDemographicDataServiceURL" + function_app_key = "ParticipantDemographicDataService" + }, { env_var_name = "CohortDistributionDataServiceURL" function_app_key = "CohortDistributionDataService"