Skip to content

Commit cb54360

Browse files
authored
Properly support database health checks based on configuration. (#282)
Signed-off-by: Victor Chang <[email protected]>
1 parent 6e54a44 commit cb54360

File tree

12 files changed

+341
-24
lines changed

12 files changed

+341
-24
lines changed

doc/dependency_decisions.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2496,3 +2496,11 @@
24962496
:versions:
24972497
- 6.10.0
24982498
:when: 2022-10-14 23:37:56.206982078 Z
2499+
- - :approve
2500+
- AspNetCore.HealthChecks.MongoDb
2501+
- :who: mocsharp
2502+
:why: Apache-2.0 (https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/raw/master/LICENSE)
2503+
:versions:
2504+
- 6.0.2
2505+
:when: 2022-12-08 23:37:56.206982078 Z
2506+

docs/compliance/third-party-licenses.md

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,226 @@ SOFTWARE.
5959

6060

6161

62+
<details>
63+
<summary>AspNetCore.HealthChecks.MongoDb 6.0.2</summary>
64+
65+
## xunit.runner.visualstudio
66+
67+
- Version: 6.0.2
68+
- Authors: Xabaril
69+
- Project URL: https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks
70+
- Source: [NuGet](https://www.nuget.org/packages/AspNetCore.HealthChecks.MongoDb#versions-body-tab/6.0.2)
71+
- License: [MIT]( https://licenses.nuget.org/Apache-2.0)
72+
73+
74+
```
75+
Apache License
76+
Version 2.0, January 2004
77+
http://www.apache.org/licenses/
78+
79+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
80+
81+
1. Definitions.
82+
83+
"License" shall mean the terms and conditions for use, reproduction,
84+
and distribution as defined by Sections 1 through 9 of this document.
85+
86+
"Licensor" shall mean the copyright owner or entity authorized by
87+
the copyright owner that is granting the License.
88+
89+
"Legal Entity" shall mean the union of the acting entity and all
90+
other entities that control, are controlled by, or are under common
91+
control with that entity. For the purposes of this definition,
92+
"control" means (i) the power, direct or indirect, to cause the
93+
direction or management of such entity, whether by contract or
94+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
95+
outstanding shares, or (iii) beneficial ownership of such entity.
96+
97+
"You" (or "Your") shall mean an individual or Legal Entity
98+
exercising permissions granted by this License.
99+
100+
"Source" form shall mean the preferred form for making modifications,
101+
including but not limited to software source code, documentation
102+
source, and configuration files.
103+
104+
"Object" form shall mean any form resulting from mechanical
105+
transformation or translation of a Source form, including but
106+
not limited to compiled object code, generated documentation,
107+
and conversions to other media types.
108+
109+
"Work" shall mean the work of authorship, whether in Source or
110+
Object form, made available under the License, as indicated by a
111+
copyright notice that is included in or attached to the work
112+
(an example is provided in the Appendix below).
113+
114+
"Derivative Works" shall mean any work, whether in Source or Object
115+
form, that is based on (or derived from) the Work and for which the
116+
editorial revisions, annotations, elaborations, or other modifications
117+
represent, as a whole, an original work of authorship. For the purposes
118+
of this License, Derivative Works shall not include works that remain
119+
separable from, or merely link (or bind by name) to the interfaces of,
120+
the Work and Derivative Works thereof.
121+
122+
"Contribution" shall mean any work of authorship, including
123+
the original version of the Work and any modifications or additions
124+
to that Work or Derivative Works thereof, that is intentionally
125+
submitted to Licensor for inclusion in the Work by the copyright owner
126+
or by an individual or Legal Entity authorized to submit on behalf of
127+
the copyright owner. For the purposes of this definition, "submitted"
128+
means any form of electronic, verbal, or written communication sent
129+
to the Licensor or its representatives, including but not limited to
130+
communication on electronic mailing lists, source code control systems,
131+
and issue tracking systems that are managed by, or on behalf of, the
132+
Licensor for the purpose of discussing and improving the Work, but
133+
excluding communication that is conspicuously marked or otherwise
134+
designated in writing by the copyright owner as "Not a Contribution."
135+
136+
"Contributor" shall mean Licensor and any individual or Legal Entity
137+
on behalf of whom a Contribution has been received by Licensor and
138+
subsequently incorporated within the Work.
139+
140+
2. Grant of Copyright License. Subject to the terms and conditions of
141+
this License, each Contributor hereby grants to You a perpetual,
142+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
143+
copyright license to reproduce, prepare Derivative Works of,
144+
publicly display, publicly perform, sublicense, and distribute the
145+
Work and such Derivative Works in Source or Object form.
146+
147+
3. Grant of Patent License. Subject to the terms and conditions of
148+
this License, each Contributor hereby grants to You a perpetual,
149+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
150+
(except as stated in this section) patent license to make, have made,
151+
use, offer to sell, sell, import, and otherwise transfer the Work,
152+
where such license applies only to those patent claims licensable
153+
by such Contributor that are necessarily infringed by their
154+
Contribution(s) alone or by combination of their Contribution(s)
155+
with the Work to which such Contribution(s) was submitted. If You
156+
institute patent litigation against any entity (including a
157+
cross-claim or counterclaim in a lawsuit) alleging that the Work
158+
or a Contribution incorporated within the Work constitutes direct
159+
or contributory patent infringement, then any patent licenses
160+
granted to You under this License for that Work shall terminate
161+
as of the date such litigation is filed.
162+
163+
4. Redistribution. You may reproduce and distribute copies of the
164+
Work or Derivative Works thereof in any medium, with or without
165+
modifications, and in Source or Object form, provided that You
166+
meet the following conditions:
167+
168+
(a) You must give any other recipients of the Work or
169+
Derivative Works a copy of this License; and
170+
171+
(b) You must cause any modified files to carry prominent notices
172+
stating that You changed the files; and
173+
174+
(c) You must retain, in the Source form of any Derivative Works
175+
that You distribute, all copyright, patent, trademark, and
176+
attribution notices from the Source form of the Work,
177+
excluding those notices that do not pertain to any part of
178+
the Derivative Works; and
179+
180+
(d) If the Work includes a "NOTICE" text file as part of its
181+
distribution, then any Derivative Works that You distribute must
182+
include a readable copy of the attribution notices contained
183+
within such NOTICE file, excluding those notices that do not
184+
pertain to any part of the Derivative Works, in at least one
185+
of the following places: within a NOTICE text file distributed
186+
as part of the Derivative Works; within the Source form or
187+
documentation, if provided along with the Derivative Works; or,
188+
within a display generated by the Derivative Works, if and
189+
wherever such third-party notices normally appear. The contents
190+
of the NOTICE file are for informational purposes only and
191+
do not modify the License. You may add Your own attribution
192+
notices within Derivative Works that You distribute, alongside
193+
or as an addendum to the NOTICE text from the Work, provided
194+
that such additional attribution notices cannot be construed
195+
as modifying the License.
196+
197+
You may add Your own copyright statement to Your modifications and
198+
may provide additional or different license terms and conditions
199+
for use, reproduction, or distribution of Your modifications, or
200+
for any such Derivative Works as a whole, provided Your use,
201+
reproduction, and distribution of the Work otherwise complies with
202+
the conditions stated in this License.
203+
204+
5. Submission of Contributions. Unless You explicitly state otherwise,
205+
any Contribution intentionally submitted for inclusion in the Work
206+
by You to the Licensor shall be under the terms and conditions of
207+
this License, without any additional terms or conditions.
208+
Notwithstanding the above, nothing herein shall supersede or modify
209+
the terms of any separate license agreement you may have executed
210+
with Licensor regarding such Contributions.
211+
212+
6. Trademarks. This License does not grant permission to use the trade
213+
names, trademarks, service marks, or product names of the Licensor,
214+
except as required for reasonable and customary use in describing the
215+
origin of the Work and reproducing the content of the NOTICE file.
216+
217+
7. Disclaimer of Warranty. Unless required by applicable law or
218+
agreed to in writing, Licensor provides the Work (and each
219+
Contributor provides its Contributions) on an "AS IS" BASIS,
220+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
221+
implied, including, without limitation, any warranties or conditions
222+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
223+
PARTICULAR PURPOSE. You are solely responsible for determining the
224+
appropriateness of using or redistributing the Work and assume any
225+
risks associated with Your exercise of permissions under this License.
226+
227+
8. Limitation of Liability. In no event and under no legal theory,
228+
whether in tort (including negligence), contract, or otherwise,
229+
unless required by applicable law (such as deliberate and grossly
230+
negligent acts) or agreed to in writing, shall any Contributor be
231+
liable to You for damages, including any direct, indirect, special,
232+
incidental, or consequential damages of any character arising as a
233+
result of this License or out of the use or inability to use the
234+
Work (including but not limited to damages for loss of goodwill,
235+
work stoppage, computer failure or malfunction, or any and all
236+
other commercial damages or losses), even if such Contributor
237+
has been advised of the possibility of such damages.
238+
239+
9. Accepting Warranty or Additional Liability. While redistributing
240+
the Work or Derivative Works thereof, You may choose to offer,
241+
and charge a fee for, acceptance of support, warranty, indemnity,
242+
or other liability obligations and/or rights consistent with this
243+
License. However, in accepting such obligations, You may act only
244+
on Your own behalf and on Your sole responsibility, not on behalf
245+
of any other Contributor, and only if You agree to indemnify,
246+
defend, and hold each Contributor harmless for any liability
247+
incurred by, or claims asserted against, such Contributor by reason
248+
of your accepting any such warranty or additional liability.
249+
250+
END OF TERMS AND CONDITIONS
251+
252+
APPENDIX: How to apply the Apache License to your work.
253+
254+
To apply the Apache License to your work, attach the following
255+
boilerplate notice, with the fields enclosed by brackets "[]"
256+
replaced with your own identifying information. (Don't include
257+
the brackets!) The text should be enclosed in the appropriate
258+
comment syntax for the file format. We also recommend that a
259+
file or class name and description of purpose be included on the
260+
same "printed page" as the copyright notice for easier
261+
identification within third-party archives.
262+
263+
Copyright [yyyy] [name of copyright owner]
264+
265+
Licensed under the Apache License, Version 2.0 (the "License");
266+
you may not use this file except in compliance with the License.
267+
You may obtain a copy of the License at
268+
269+
http://www.apache.org/licenses/LICENSE-2.0
270+
271+
Unless required by applicable law or agreed to in writing, software
272+
distributed under the License is distributed on an "AS IS" BASIS,
273+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
274+
See the License for the specific language governing permissions and
275+
limitations under the License.
276+
```
277+
278+
</details>
279+
280+
281+
62282
<details>
63283
<summary>AWSSDK.Core 3.7.100.25</summary>
64284

src/Client/Test/packages.lock.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@
5252
"JetBrains.Annotations": "2021.3.0"
5353
}
5454
},
55+
"AspNetCore.HealthChecks.MongoDb": {
56+
"type": "Transitive",
57+
"resolved": "6.0.2",
58+
"contentHash": "0R3NVbsjMhS5fd2hGijzQNKJ0zQBv/qMC7nkpmnbtgribCj7vfNdAhSqv4lwbibffRWPW5A/7VNJMX4aPej0WQ==",
59+
"dependencies": {
60+
"Microsoft.Extensions.Diagnostics.HealthChecks": "6.0.2",
61+
"MongoDB.Driver": "2.14.1"
62+
}
63+
},
5564
"AWSSDK.Core": {
5665
"type": "Transitive",
5766
"resolved": "3.7.100.25",
@@ -1676,7 +1685,6 @@
16761685
"Karambolo.Extensions.Logging.File": "[3.3.1, )",
16771686
"Microsoft.EntityFrameworkCore": "[6.0.11, )",
16781687
"Microsoft.Extensions.DependencyInjection.Abstractions": "[6.0.0, )",
1679-
"Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore": "[6.0.11, )",
16801688
"Microsoft.Extensions.Hosting": "[6.0.1, )",
16811689
"Microsoft.Extensions.Logging": "[6.0.0, )",
16821690
"Microsoft.Extensions.Logging.Console": "[6.0.0, )",
@@ -1749,10 +1757,12 @@
17491757
"monai.deploy.informaticsgateway.database": {
17501758
"type": "Project",
17511759
"dependencies": {
1760+
"AspNetCore.HealthChecks.MongoDb": "[6.0.2, )",
17521761
"Microsoft.EntityFrameworkCore": "[6.0.11, )",
17531762
"Microsoft.Extensions.Configuration": "[6.0.1, )",
17541763
"Microsoft.Extensions.Configuration.FileExtensions": "[6.0.0, )",
17551764
"Microsoft.Extensions.Configuration.Json": "[6.0.0, )",
1765+
"Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore": "[6.0.11, )",
17561766
"Microsoft.Extensions.Options.ConfigurationExtensions": "[6.0.0, )",
17571767
"Monai.Deploy.InformaticsGateway.Api": "[1.0.0, )",
17581768
"Monai.Deploy.InformaticsGateway.Configuration": "[1.0.0, )",
@@ -1805,4 +1815,4 @@
18051815
}
18061816
}
18071817
}
1808-
}
1818+
}

src/Database/DatabaseManager.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,37 @@ public static class DatabaseManager
3232
{
3333
public const string DbType_Sqlite = "sqlite";
3434
public const string DbType_MongoDb = "mongodb";
35-
public static IServiceCollection ConfigureDatabase(this IServiceCollection services, IConfigurationSection? connectionStringConfigurationSection)
35+
36+
public static IHealthChecksBuilder AddDatabaseHealthCheck(this IHealthChecksBuilder healthChecksBuilder, IConfigurationSection? connectionStringConfigurationSection)
3637
{
3738
if (connectionStringConfigurationSection is null)
3839
{
3940
throw new ConfigurationException("No database connections found in configuration section 'ConnectionStrings'.");
4041
}
4142

43+
var databaseType = connectionStringConfigurationSection["Type"].ToLowerInvariant();
44+
45+
switch (databaseType)
46+
{
47+
case DbType_Sqlite:
48+
healthChecksBuilder.AddDbContextCheck<InformaticsGatewayContext>("SQLite Database");
49+
return healthChecksBuilder;
50+
51+
case DbType_MongoDb:
52+
healthChecksBuilder.AddMongoDb(mongodbConnectionString: connectionStringConfigurationSection[SR.DatabaseConnectionStringKey], mongoDatabaseName: connectionStringConfigurationSection[SR.DatabaseNameKey], name: "MongoDB");
53+
return healthChecksBuilder;
54+
55+
default:
56+
throw new ConfigurationException($"Unsupported database type defined: '{databaseType}'");
57+
}
58+
}
59+
60+
public static IServiceCollection ConfigureDatabase(this IServiceCollection services, IConfigurationSection? connectionStringConfigurationSection)
61+
{
62+
if (connectionStringConfigurationSection is null)
63+
{
64+
throw new ConfigurationException("No database connections found in configuration section 'ConnectionStrings'.");
65+
}
4266

4367
var databaseType = connectionStringConfigurationSection["Type"].ToLowerInvariant();
4468
switch (databaseType)
@@ -56,6 +80,7 @@ public static IServiceCollection ConfigureDatabase(this IServiceCollection servi
5680
services.AddScoped(typeof(IPayloadRepository), typeof(EntityFramework.Repositories.PayloadRepository));
5781
services.AddScoped(typeof(IDicomAssociationInfoRepository), typeof(EntityFramework.Repositories.DicomAssociationInfoRepository));
5882
return services;
83+
5984
case DbType_MongoDb:
6085
services.AddSingleton<IMongoClient, MongoClient>(s => new MongoClient(connectionStringConfigurationSection[SR.DatabaseConnectionStringKey]));
6186
services.Configure<MongoDBOptions>(connectionStringConfigurationSection);
@@ -69,6 +94,7 @@ public static IServiceCollection ConfigureDatabase(this IServiceCollection servi
6994
services.AddScoped(typeof(IDicomAssociationInfoRepository), typeof(MongoDB.Repositories.DicomAssociationInfoRepository));
7095

7196
return services;
97+
7298
default:
7399
throw new ConfigurationException($"Unsupported database type defined: '{databaseType}'");
74100
}

src/Database/EntityFramework/Configuration/SR.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public static class SR
2323
/// Name of the key for retrieve database connection string.
2424
/// </summary>
2525
public const string DatabaseConnectionStringKey = "InformaticsGatewayDatabase";
26+
public const string DatabaseNameKey = "DatabaseName";
2627

2728
}
2829
}

src/Database/Monai.Deploy.InformaticsGateway.Database.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!--
1+
<!--
22
~ Copyright 2021-2022 MONAI Consortium
33
~
44
~ Licensed under the Apache License, Version 2.0 (the "License");
@@ -61,13 +61,15 @@
6161
</ItemGroup>
6262

6363
<ItemGroup>
64+
<PackageReference Include="AspNetCore.HealthChecks.MongoDb" Version="6.0.2" />
6465
<PackageReference Include="GitVersion.MsBuild" Version="5.11.1">
6566
<PrivateAssets>All</PrivateAssets>
6667
</PackageReference>
6768
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.11" />
6869
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
6970
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="6.0.0" />
7071
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
72+
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="6.0.11" />
7173
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="6.0.0" />
7274
</ItemGroup>
7375
</Project>

0 commit comments

Comments
 (0)