Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

バックエンドサーバーのヘルスチェック用APIを追加する #543

Conversation

fkoyama
Copy link
Contributor

@fkoyama fkoyama commented Oct 20, 2023

ヘルスチェック用APIを追加しました。

Copy link
Contributor

@tsuna-can-se tsuna-can-se left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

全体的に機能を正しい場所に配置するように変更していきたいと思います。現状だとDbHealthCheckクラス内にインフラストラクチャ層の実装が入り込んでいるので、この部分をアーキテクチャ上の正しい場所に移動します。またクラス名も「DbHealthCheck」から「DatabaseHealthCheck」としましょう。このあたりの修正をかけると、DatabaseHealthCheckクラスのフィールドから接続文字列は消せるはずです。また、「Microsoft.Data.SqlClient」名前空間の参照も消えるはずです。

データベースにアクセスできるか検査する機能は、Dressca.EfInfrastructureプロジェクトに移動します。名前は仮でDresscaHealthCheckerとしてます。実装も大幅に変更し、DresscaDbContextを利用してヘルスチェックのロジックを実装する形にします。DresscaDbContext.Database.CanConnectAsyncとかExecuteSqlRawAsyncとかを使えばよいと思いますが、何をもって「正常」と判断するかは一旦お任せします。

DresscaHealthCheckerは内部で利用するDresscaDbContextをDIコンテナーから取得する都合上、DresscaHealthChecker自身をDIコンテナーに登録したいです。EfInfrastructureServicesExtensionに登録するロジックを追加すればよいはずです。

image

DatabaseHealthCheckをインフラストラクチャ層に持たせることも一瞬考えたんですが、インフラストラクチャ層の参照するパッケージが増えてしまうのを嫌い、最も忠実なこの形で考えてみました。

@fkoyama
Copy link
Contributor Author

fkoyama commented Oct 26, 2023

@tsuna-can-se
ヘルスチェック機能の配置を修正しました。ご確認お願いいたします。

@fkoyama
Copy link
Contributor Author

fkoyama commented Oct 27, 2023

@tsuna-can-se
IApiDescriptionProviderを使用する形式に修正しました。ご確認お願いいたします。

Copy link
Contributor

@tsuna-can-se tsuna-can-se left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

機能実装の方を優先してコメントします。Open API仕様書の方は後程確認します。

@tsuna-can-se tsuna-can-se added the target: Dressca サンプルアプリケーションDresscaに関係がある label Oct 31, 2023
@tsuna-can-se tsuna-can-se added this to the v0.5 milestone Oct 31, 2023
Copy link

Test Result 📝

Test was a success.
Completed in 8716ms with 162 passed, 0 failed and 0 skipped.

Coverage 📐

Summary
Generated on: 11/14/2023 - 05:27:51
Coverage date: 11/14/2023 - 05:27:45 - 11/14/2023 - 05:27:47
Parser: MultiReport (2x Cobertura)
Assemblies: 7
Classes: 99
Files: 101
Line coverage: 25.1% (1127 of 4488)
Covered lines: 1127
Uncovered lines: 3361
Coverable lines: 4488
Total lines: 8767
Branch coverage: 47.6% (162 of 340)
Covered branches: 162
Total branches: 340
Method coverage: Feature is only available for sponsors
Tag: 355_6859597049
Dressca.ApplicationCore - 84.9%
Name Line Branch
Dressca.ApplicationCore 84.9% 70.8%
Dressca.ApplicationCore.Accounting.Account 100% 100%
Dressca.ApplicationCore.Accounting.AccountItem 100%
Dressca.ApplicationCore.ApplicationCoreServicesExtensions 100%
Dressca.ApplicationCore.Assets.Asset 82.6% 62.5%
Dressca.ApplicationCore.Assets.AssetApplicationService 100% 70%
Dressca.ApplicationCore.Assets.AssetNotFoundException 50%
Dressca.ApplicationCore.Assets.AssetTypes 100% 100%
Dressca.ApplicationCore.Baskets.Basket 96.1% 100%
Dressca.ApplicationCore.Baskets.BasketApplicationService 100% 88.8%
Dressca.ApplicationCore.Baskets.BasketItem 86.3% 75%
Dressca.ApplicationCore.Baskets.BasketNotFoundException 50%
Dressca.ApplicationCore.Catalog.CatalogApplicationService 100% 50%
Dressca.ApplicationCore.Catalog.CatalogBrand 90.9% 100%
Dressca.ApplicationCore.Catalog.CatalogCategory 90.9% 100%
Dressca.ApplicationCore.Catalog.CatalogDomainService 100% 66.6%
Dressca.ApplicationCore.Catalog.CatalogItem 56.7% 37.5%
Dressca.ApplicationCore.Catalog.CatalogItemAsset 73.6% 50%
Dressca.ApplicationCore.Ordering.Address 61.1% 100%
Dressca.ApplicationCore.Ordering.CatalogItemOrdered 90% 100%
Dressca.ApplicationCore.Ordering.EmptyBasketOnCheckoutException 100%
Dressca.ApplicationCore.Ordering.Order 86.1% 75%
Dressca.ApplicationCore.Ordering.OrderApplicationService 100% 75%
Dressca.ApplicationCore.Ordering.OrderItem 75% 37.5%
Dressca.ApplicationCore.Ordering.OrderItemAsset 73.6% 66.6%
Dressca.ApplicationCore.Ordering.OrderNotFoundException 50%
Dressca.ApplicationCore.Ordering.ShipTo 58.3% 50%
Dressca.ApplicationCore.Resources.Messages 84.6% 100%
Dressca.EfInfrastructure - 9.8%
Name Line Branch
Dressca.EfInfrastructure 9.8% 9%
Dressca.EfInfrastructure.Configurations.Assets.AssetConfiguration 100%
Dressca.EfInfrastructure.Configurations.Baskets.BasketConfiguration 100%
Dressca.EfInfrastructure.Configurations.Baskets.BasketItemConfiguration 100%
Dressca.EfInfrastructure.Configurations.Catalog.CatalogBrandConfiguration 100%
Dressca.EfInfrastructure.Configurations.Catalog.CatalogCategoryConfiguratio
n
100%
Dressca.EfInfrastructure.Configurations.Catalog.CatalogItemAssetConfigurati
on
100%
Dressca.EfInfrastructure.Configurations.Catalog.CatalogItemConfiguration 100%
Dressca.EfInfrastructure.Configurations.Ordering.OrderConfiguration 100%
Dressca.EfInfrastructure.Configurations.Ordering.OrderItemAssetConfiguratio
n
100%
Dressca.EfInfrastructure.Configurations.Ordering.OrderItemConfiguration 100%
Dressca.EfInfrastructure.DresscaDbContext 56.7% 50%
Dressca.EfInfrastructure.EfAssetRepository 0% 0%
Dressca.EfInfrastructure.EfBasketRepository 0% 0%
Dressca.EfInfrastructure.EfCatalogBrandRepository 0% 0%
Dressca.EfInfrastructure.EfCatalogCategoryRepository 0% 0%
Dressca.EfInfrastructure.EfCatalogRepository 0% 0%
Dressca.EfInfrastructure.EfInfrastructureServicesExtension 81.8% 50%
Dressca.EfInfrastructure.EfOrderRepository 0% 0%
Dressca.EfInfrastructure.HealthChecksBuilderExtensions 62.5%
Dressca.EfInfrastructure.Migrations.AddNowPrintingAsset 0%
Dressca.EfInfrastructure.Migrations.DresscaDbContextModelSnapshot 0%
Dressca.EfInfrastructure.Migrations.InitialCreate 0%
Dressca.EfInfrastructure.Resources.Messages 0% 0%
Dressca.Store.Assets.StaticFiles - 9.8%
Name Line Branch
Dressca.Store.Assets.StaticFiles 9.8% 0%
Dressca.Store.Assets.StaticFiles.Resources.Messages 0% 0%
Dressca.Store.Assets.StaticFiles.StaticFileAssetStore 0% 0%
Dressca.Store.Assets.StaticFiles.StaticFileAssetStoreServicesExtension 100%
Dressca.SystemCommon - 86.4%
Name Line Branch
Dressca.SystemCommon 86.4% 90%
Dressca.SystemCommon.BusinessError 100% 83.3%
Dressca.SystemCommon.BusinessErrorCollection 88.8% 100%
Dressca.SystemCommon.BusinessException 93.7% 100%
Dressca.SystemCommon.ObjectExtensions 80% 50%
Dressca.SystemCommon.Resources.Messages 55.5% 100%
Dressca.TestLibrary - 47.2%
Name Line Branch
Dressca.TestLibrary 47.2% 33.3%
Dressca.TestLibrary.Xunit.Logging.XunitLogger 70.5% 75%
Dressca.TestLibrary.Xunit.Logging.XunitLoggerFactory 44.7% 12.5%
Dressca.TestLibrary.Xunit.Logging.XunitLoggerProvider 31.5% 33.3%
Dressca.Web - 24.7%
Name Line Branch
Dressca.Web 24.7% 21.8%
Dressca.Web.Assets.AssetExtensions 87.5% 50%
Dressca.Web.Baskets.BuyerIdFilterAttribute 0% 0%
Dressca.Web.Baskets.HttpContextExtensions 100% 100%
Dressca.Web.Controllers.ActionNameHelper 0% 0%
Dressca.Web.Controllers.ApiModel.FindCatalogItemsQuery 0%
Dressca.Web.Controllers.AssetsController 0% 0%
Dressca.Web.Controllers.BasketItemsController 0% 0%
Dressca.Web.Controllers.CatalogBrandsController 0% 0%
Dressca.Web.Controllers.CatalogCategoriesController 0% 0%
Dressca.Web.Controllers.CatalogItemsController 0% 0%
Dressca.Web.Controllers.ErrorController 0% 0%
Dressca.Web.Controllers.OrdersController 0% 0%
Dressca.Web.HealthChecks.HealthCheckDescriptionProvider 8.6%
Dressca.Web.Mapper.BasketItemMapper 0% 0%
Dressca.Web.Mapper.BasketMapper 0% 0%
Dressca.Web.Mapper.CatalogBrandMapper 0% 0%
Dressca.Web.Mapper.CatalogCategoryMapper 0% 0%
Dressca.Web.Mapper.CatalogItemMapper 0% 0%
Dressca.Web.Mapper.DtoMapperServicesExtension 100%
Dressca.Web.Mapper.OrderMapper 0% 0%
Dressca.Web.Resources.Messages 37% 100%
Dressca.Web.Runtime.BusinessExceptionDevelopmentFilter 100% 50%
Dressca.Web.Runtime.BusinessExceptionFilter 100% 50%
Dressca.Web.Runtime.BusinessExceptionFilterBase 100% 83.3%
Program 79.7% 66.6%
Dressca.Web.Dto - 0%
Name Line Branch
Dressca.Web.Dto 0% 0%
Dressca.Web.Dto.Accounting.AccountResponse 0%
Dressca.Web.Dto.Baskets.BasketItemResponse 0%
Dressca.Web.Dto.Baskets.BasketResponse 0%
Dressca.Web.Dto.Baskets.PostBasketItemsRequest 0%
Dressca.Web.Dto.Baskets.PutBasketItemsRequest 0%
Dressca.Web.Dto.Catalog.CatalogBrandResponse 0%
Dressca.Web.Dto.Catalog.CatalogCategoryResponse 0%
Dressca.Web.Dto.Catalog.CatalogItemResponse 0%
Dressca.Web.Dto.Catalog.CatalogItemSummaryResponse 0%
Dressca.Web.Dto.Ordering.OrderItemResponse 0%
Dressca.Web.Dto.Ordering.OrderResponse 0%
Dressca.Web.Dto.Ordering.PostOrderRequest 0%
Dressca.Web.Dto.PagedList`1 0% 0%

@tsuna-can-se tsuna-can-se changed the title feature/バックエンドサーバーのヘルスチェック用APIを追加する バックエンドサーバーのヘルスチェック用APIを追加する Nov 14, 2023
@tsuna-can-se tsuna-can-se merged commit c7a72e5 into main Nov 14, 2023
6 checks passed
@tsuna-can-se tsuna-can-se deleted the feature/バックエンドサーバーのヘルスチェック用APIを追加する branch November 14, 2023 05:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
target: Dressca サンプルアプリケーションDresscaに関係がある
Projects
None yet
Development

Successfully merging this pull request may close these issues.

バックエンドサーバーのヘルスチェック用APIを追加する
2 participants