diff --git a/docs/en/solution-templates/layered-web-application/cors-configuration.md b/docs/en/solution-templates/layered-web-application/cors-configuration.md index 6df207c107..73e7b6952b 100644 --- a/docs/en/solution-templates/layered-web-application/cors-configuration.md +++ b/docs/en/solution-templates/layered-web-application/cors-configuration.md @@ -8,8 +8,8 @@ "Path": "solution-templates/layered-web-application/blob-storing" }, "Next": { - "Name": "Helm Charts and Kubernetes", - "Path": "solution-templates/layered-web-application/helm-charts-and-kubernetes" + "Name": "Health Check Configuration", + "Path": "solution-templates/layered-web-application/health-check-configuration" } } ``` diff --git a/docs/en/solution-templates/layered-web-application/health-check-configuration.md b/docs/en/solution-templates/layered-web-application/health-check-configuration.md new file mode 100644 index 0000000000..cd1f69c99b --- /dev/null +++ b/docs/en/solution-templates/layered-web-application/health-check-configuration.md @@ -0,0 +1,121 @@ +# Layered Solution: Health Check Configuration + +```json +//[doc-nav] +{ + "Previous": { + "Name": "CORS Configuration", + "Path": "solution-templates/single-layer-web-application/cors-configuration" + }, + "Next": { + "Name": "Helm Charts and Kubernetes", + "Path": "solution-templates/layered-web-application/helm-charts-and-kubernetes" + } +} +``` + +Health Check is a feature that allows applications to monitor their health and diagnose potential issues. The layered solution template comes with pre-configured Health Check system. + +In the layered solution template, Health Check configuration is applied in the following cases: + +- When [MVC](https://abp.io/docs/latest/solution-templates/single-layer-web-application/web-applications#mvc) is selected as the web application type. +- When [Blazor Server](https://abp.io/docs/latest/solution-templates/single-layer-web-application/web-applications#blazor-server) is selected as the web application type. +- When [Blazor WebAssembly](https://abp.io/docs/latest/solution-templates/single-layer-web-application/web-applications#blazor-webassembly) is selected as the web application type (configured at the backend). +- When [Blazor WebApp](https://abp.io/docs/latest/solution-templates/single-layer-web-application/web-applications#blazor-webapp) is selected as the web application type (configured at the backend). +- When [Angular](https://abp.io/docs/latest/solution-templates/single-layer-web-application/web-applications#angular) is selected as the web application type (configured at the backend). +- When [No UI](https://abp.io/docs/latest/solution-templates/single-layer-web-application/web-applications#no-ui) is selected as the web application type (configured at the backend). + +### Configuration in `HealthChecksBuilderExtensions.cs` + +Health Checks are configured in the `HealthChecksBuilderExtensions` class. This class extends `IServiceCollection` to register health check services and configure health check UI endpoints. + +#### Default Configuration + +The default setup is as follows: + +```csharp +using HealthChecks.UI.Client; +using Microsoft.AspNetCore.Diagnostics.HealthChecks; + +namespace MyCompanyName.MyProjectName.HealthChecks; + +public static class HealthChecksBuilderExtensions +{ + public static void AddMyProjectNameHealthChecks(this IServiceCollection services) + { + // Add your health checks here + var healthChecksBuilder = services.AddHealthChecks(); + healthChecksBuilder.AddCheck("MyProjectName DbContext Check", tags: new string[] { "database" }); + + // Read configuration for health check URL + var configuration = services.GetConfiguration(); + var healthCheckUrl = configuration["App:HealthCheckUrl"] ?? "/health-status"; + + services.ConfigureHealthCheckEndpoint(healthCheckUrl); + + // Configure HealthChecks UI + var healthChecksUiBuilder = services.AddHealthChecksUI(settings => + { + settings.AddHealthCheckEndpoint("MyProjectName Health Status", healthCheckUrl); + }); + + // Set HealthCheck UI storage + healthChecksUiBuilder.AddInMemoryStorage(); + + services.MapHealthChecksUiEndpoints(options => + { + options.UIPath = "/health-ui"; + options.ApiPath = "/health-api"; + }); + } + + private static IServiceCollection ConfigureHealthCheckEndpoint(this IServiceCollection services, string path) + { + .... + } + + private static IServiceCollection MapHealthChecksUiEndpoints(this IServiceCollection services, Action? setupOption = null) + { + .... + } +} +``` + +### Database Health Check Implementation + +The `MyProjectNameDatabaseCheck` class is a custom implementation of a health check that verifies database connectivity using `IIdentityRoleRepository`. + +```csharp +using System; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Extensions.Diagnostics.HealthChecks; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Identity; + +namespace MyCompanyName.MyProjectName.HealthChecks; + +public class MyProjectNameDatabaseCheck : IHealthCheck, ITransientDependency +{ + protected readonly IIdentityRoleRepository IdentityRoleRepository; + + public MyProjectNameDatabaseCheck(IIdentityRoleRepository identityRoleRepository) + { + IdentityRoleRepository = identityRoleRepository; + } + + public async Task CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default) + { + try + { + await IdentityRoleRepository.GetListAsync(sorting: nameof(IdentityRole.Id), maxResultCount: 1, cancellationToken: cancellationToken); + return HealthCheckResult.Healthy($"Could connect to database and get record."); + } + catch (Exception e) + { + return HealthCheckResult.Unhealthy($"Error when trying to get database record. ", e); + } + } +} +``` + diff --git a/docs/en/solution-templates/microservice/cors-configuration.md b/docs/en/solution-templates/microservice/cors-configuration.md index 2ca44342f4..8157bb95ae 100644 --- a/docs/en/solution-templates/microservice/cors-configuration.md +++ b/docs/en/solution-templates/microservice/cors-configuration.md @@ -4,8 +4,8 @@ //[doc-nav] { "Next": { - "Name": "Communication in the Microservice solution", - "Path": "solution-templates/microservice/communication" + "Name": "Health Check Configuration", + "Path": "solution-templates/microservice/health-check-configuration" } } ```` diff --git a/docs/en/solution-templates/microservice/health-check-configuration.md b/docs/en/solution-templates/microservice/health-check-configuration.md new file mode 100644 index 0000000000..37cd515209 --- /dev/null +++ b/docs/en/solution-templates/microservice/health-check-configuration.md @@ -0,0 +1,110 @@ +# Microservice Solution: Health Check Configuration + +```json +//[doc-nav] +{ + "Next": { + "Name": "Communication in the Microservice solution", + "Path": "solution-templates/microservice/communication" + } +} +``` + +Health Check is a feature that allows applications to monitor their health and diagnose potential issues. The Microservice solution template comes with pre-configured Health Check system. + +In the Microservice solution template, Health Check configuration is applied in all the services, gateways and UI applications (except Blazor Wasm & Blazor WebApp applications UI applications). + +### Configuration in `HealthChecksBuilderExtensions.cs` + +Health Checks are configured in the `HealthChecksBuilderExtensions` class. This class extends `IServiceCollection` to register health check services and configure health check UI endpoints. + +#### Default Configuration + +The default setup is as follows: + +```csharp +using HealthChecks.UI.Client; +using Microsoft.AspNetCore.Diagnostics.HealthChecks; + +namespace MyCompanyName.MyProjectName.HealthChecks; + +public static class HealthChecksBuilderExtensions +{ + public static void AddMyProjectNameHealthChecks(this IServiceCollection services) + { + // Add your health checks here + var healthChecksBuilder = services.AddHealthChecks(); + healthChecksBuilder.AddCheck("MyProjectName DbContext Check", tags: new string[] { "database" }); + + // Read configuration for health check URL + var configuration = services.GetConfiguration(); + var healthCheckUrl = configuration["App:HealthCheckUrl"] ?? "/health-status"; + + services.ConfigureHealthCheckEndpoint(healthCheckUrl); + + // Configure HealthChecks UI + var healthChecksUiBuilder = services.AddHealthChecksUI(settings => + { + settings.AddHealthCheckEndpoint("MyProjectName Health Status", healthCheckUrl); + }); + + // Set HealthCheck UI storage + healthChecksUiBuilder.AddInMemoryStorage(); + + services.MapHealthChecksUiEndpoints(options => + { + options.UIPath = "/health-ui"; + options.ApiPath = "/health-api"; + }); + } + + private static IServiceCollection ConfigureHealthCheckEndpoint(this IServiceCollection services, string path) + { + .... + } + + private static IServiceCollection MapHealthChecksUiEndpoints(this IServiceCollection services, Action? setupOption = null) + { + .... + } +} +``` + +### Database Health Check Implementation + +The `MyProjectNameDatabaseCheck` class is a custom implementation of a health check that verifies database connectivity in the applications with database connection. Example: + +```csharp +using System; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Extensions.Diagnostics.HealthChecks; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Identity; + +namespace MyCompanyName.MyProjectName.HealthChecks; + +public class MyProjectNameDatabaseCheck : IHealthCheck, ITransientDependency +{ + protected readonly IIdentityRoleRepository IdentityRoleRepository; + + public MyProjectNameDatabaseCheck(IIdentityRoleRepository identityRoleRepository) + { + IdentityRoleRepository = identityRoleRepository; + } + + public async Task CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default) + { + try + { + await IdentityRoleRepository.GetListAsync(sorting: nameof(IdentityRole.Id), maxResultCount: 1, cancellationToken: cancellationToken); + return HealthCheckResult.Healthy($"Could connect to database and get record."); + } + catch (Exception e) + { + return HealthCheckResult.Unhealthy($"Error when trying to get database record. ", e); + } + } +} +``` + diff --git a/docs/en/solution-templates/single-layer-web-application/cors-configuration.md b/docs/en/solution-templates/single-layer-web-application/cors-configuration.md index f54c73ad79..71f1991e59 100644 --- a/docs/en/solution-templates/single-layer-web-application/cors-configuration.md +++ b/docs/en/solution-templates/single-layer-web-application/cors-configuration.md @@ -6,6 +6,10 @@ "Previous": { "Name": "BLOB Storing", "Path": "solution-templates/single-layer-web-application/blob-storing" + }, + "Next": { + "Name": "Health Check Configuration", + "Path": "solution-templates/single-layer-web-application/health-check-configuration" } } ``` diff --git a/docs/en/solution-templates/single-layer-web-application/health-check-configuration.md b/docs/en/solution-templates/single-layer-web-application/health-check-configuration.md new file mode 100644 index 0000000000..b62b544cbd --- /dev/null +++ b/docs/en/solution-templates/single-layer-web-application/health-check-configuration.md @@ -0,0 +1,115 @@ +# Single Layer Solution: Health Check Configuration + +```json +//[doc-nav] +{ + "Previous": { + "Name": "CORS Configuration", + "Path": "solution-templates/single-layer-web-application/cors-configuration" + } +} +``` + +Health Check is a feature that allows applications to monitor their health and diagnose potential issues. The single-layer solution template comes with pre-configured Health Check system. + +In the single-layer solution template, Health Check configuration is applied in the following cases: + +- When [MVC](https://abp.io/docs/latest/solution-templates/single-layer-web-application/web-applications#mvc) is selected as the web application type. +- When [Blazor Server](https://abp.io/docs/latest/solution-templates/single-layer-web-application/web-applications#blazor-server) is selected as the web application type. +- When [Angular](https://abp.io/docs/latest/solution-templates/single-layer-web-application/web-applications#angular) is selected as the web application type (configured at the backend). +- When [No UI](https://abp.io/docs/latest/solution-templates/single-layer-web-application/web-applications#no-ui) is selected as the web application type (configured at the backend). + +### Configuration in `HealthChecksBuilderExtensions.cs` + +Health Checks are configured in the `HealthChecksBuilderExtensions` class. This class extends `IServiceCollection` to register health check services and configure health check UI endpoints. + +#### Default Configuration + +The default setup is as follows: + +```csharp +using HealthChecks.UI.Client; +using Microsoft.AspNetCore.Diagnostics.HealthChecks; + +namespace MyCompanyName.MyProjectName.HealthChecks; + +public static class HealthChecksBuilderExtensions +{ + public static void AddMyProjectNameHealthChecks(this IServiceCollection services) + { + // Add your health checks here + var healthChecksBuilder = services.AddHealthChecks(); + healthChecksBuilder.AddCheck("MyProjectName DbContext Check", tags: new string[] { "database" }); + + // Read configuration for health check URL + var configuration = services.GetConfiguration(); + var healthCheckUrl = configuration["App:HealthCheckUrl"] ?? "/health-status"; + + services.ConfigureHealthCheckEndpoint(healthCheckUrl); + + // Configure HealthChecks UI + var healthChecksUiBuilder = services.AddHealthChecksUI(settings => + { + settings.AddHealthCheckEndpoint("MyProjectName Health Status", healthCheckUrl); + }); + + // Set HealthCheck UI storage + healthChecksUiBuilder.AddInMemoryStorage(); + + services.MapHealthChecksUiEndpoints(options => + { + options.UIPath = "/health-ui"; + options.ApiPath = "/health-api"; + }); + } + + private static IServiceCollection ConfigureHealthCheckEndpoint(this IServiceCollection services, string path) + { + .... + } + + private static IServiceCollection MapHealthChecksUiEndpoints(this IServiceCollection services, Action? setupOption = null) + { + .... + } +} +``` + +### Database Health Check Implementation + +The `MyProjectNameDatabaseCheck` class is a custom implementation of a health check that verifies database connectivity using `IIdentityRoleRepository`. + +```csharp +using System; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Extensions.Diagnostics.HealthChecks; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Identity; + +namespace MyCompanyName.MyProjectName.HealthChecks; + +public class MyProjectNameDatabaseCheck : IHealthCheck, ITransientDependency +{ + protected readonly IIdentityRoleRepository IdentityRoleRepository; + + public MyProjectNameDatabaseCheck(IIdentityRoleRepository identityRoleRepository) + { + IdentityRoleRepository = identityRoleRepository; + } + + public async Task CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default) + { + try + { + await IdentityRoleRepository.GetListAsync(sorting: nameof(IdentityRole.Id), maxResultCount: 1, cancellationToken: cancellationToken); + return HealthCheckResult.Healthy($"Could connect to database and get record."); + } + catch (Exception e) + { + return HealthCheckResult.Unhealthy($"Error when trying to get database record. ", e); + } + } +} +``` + diff --git a/docs/en/studio/images/monitoring-applications/overall.png b/docs/en/studio/images/monitoring-applications/overall.png index a56ed043f9..dfd0f71ae3 100644 Binary files a/docs/en/studio/images/monitoring-applications/overall.png and b/docs/en/studio/images/monitoring-applications/overall.png differ diff --git a/docs/en/studio/images/solution-runner/csharp-application-context-menu-build.png b/docs/en/studio/images/solution-runner/csharp-application-context-menu-build.png index aec7d5d0d7..5b0fe32119 100644 Binary files a/docs/en/studio/images/solution-runner/csharp-application-context-menu-build.png and b/docs/en/studio/images/solution-runner/csharp-application-context-menu-build.png differ diff --git a/docs/en/studio/images/solution-runner/csharp-application-context-menu-monitor.png b/docs/en/studio/images/solution-runner/csharp-application-context-menu-monitor.png index 42eca8cf00..bdc601c2a9 100644 Binary files a/docs/en/studio/images/solution-runner/csharp-application-context-menu-monitor.png and b/docs/en/studio/images/solution-runner/csharp-application-context-menu-monitor.png differ diff --git a/docs/en/studio/images/solution-runner/csharp-application-context-menu.png b/docs/en/studio/images/solution-runner/csharp-application-context-menu.png index 76c90a2e95..fbe7e6993d 100644 Binary files a/docs/en/studio/images/solution-runner/csharp-application-context-menu.png and b/docs/en/studio/images/solution-runner/csharp-application-context-menu.png differ diff --git a/docs/en/studio/images/solution-runner/solutioın-runner-properties.png b/docs/en/studio/images/solution-runner/solutioın-runner-properties.png index 8611f8be3d..9a6505a7d1 100644 Binary files a/docs/en/studio/images/solution-runner/solutioın-runner-properties.png and b/docs/en/studio/images/solution-runner/solutioın-runner-properties.png differ diff --git a/docs/en/studio/monitoring-applications.md b/docs/en/studio/monitoring-applications.md index 6d0c5523a3..5ef2dc0f91 100644 --- a/docs/en/studio/monitoring-applications.md +++ b/docs/en/studio/monitoring-applications.md @@ -59,6 +59,7 @@ In the data grid, details for each application are displayed. It's possible to s - `Name`: The name of the application. - `State`: The state of the application. It can take on several values such as *Scheduled*, *Starting*, *Started*, *Stopping* and *Stopped*. In the event of an application crash during its starting, the state is mark as *Scheduled*, we can cancel the starting process at that stage. +- `Health` : The health state of the application. Clicking on the icon shows the latest health check response. Displays `N/A` if the application is not running or health check is not configured for the application. - `Instances`: Indicates the count of running instances for the application. This value is particularly helpful when scaling the application within a Kubernetes, providing visibility into the number of currently active instances. - `Uptime`: The time elapsed since the application started. - `Requests`: The number of HTTP requests received by the application. diff --git a/docs/en/studio/running-applications.md b/docs/en/studio/running-applications.md index 5392250153..9188f202ae 100644 --- a/docs/en/studio/running-applications.md +++ b/docs/en/studio/running-applications.md @@ -196,16 +196,19 @@ When the C# application is connected to ABP Studio, it starts sending telemetry ![csharp-application-context-menu-monitor](images/solution-runner/csharp-application-context-menu-monitor.png) - `Browse`: ABP Studio includes a browser tool for accessing websites and running applications. You can click this option to view the application in the ABP Studio browser. However, this option is only accessible if the application is started. +- Health Status : If Health Check endpoints are defined, it allows you to browse Health UI and see the latest health check response. - `Requests`: It opens the *HTTP Requests* tab with adding the selected application filter. You can view all *HTTP Requests* received by your applications. - `Exceptions`: We can display all exceptions on this tab. It opens the *Exceptions* tab with selected application. - `Logs`: Clicking this option opens the *Logs* tab with adding the selected application filter. ### Properties -We can open the *Application Properties* window to change *Launch url*, *Kubernetes service* and *run* information. To access the *Application Properties* window, navigate to a C# application, right-click to view the context menu, and select the Properties option. +We can open the *Application Properties* window to change *Launch url*, *Health check endpoints*, *Kubernetes service* and *run* information. To access the *Application Properties* window, navigate to a C# application, right-click to view the context menu, and select the Properties option. ![solutioın-runner-properties](images/solution-runner/solutioın-runner-properties.png) +- **Health check endpoint**: Endpoint for controlling the health status of the application periodically. If the application doesn't have a endpoint for health check, you can enter `/` to use the home page of the application as health check endpoint. +- **Health UI endpoint**: Endpoint of the Health UI page of the application. - **Skip build before starting**: When enabled, application is started without build and it makes starting faster. This is useful when you are working on a single application out of multiple, so you don't need to build others everytime they start. - **Watch changes while running**: When enabled, you should see an *eye* icon next to the application name.