forked from Ed-Fi-Alliance-OSS/AdminAPI-1.x
-
Notifications
You must be signed in to change notification settings - Fork 13
❌ DO NOT MERGE - [ADMINAPI-1260] Design: merge health check worker into AdminApi-2 #323
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
Draft
CSR2017
wants to merge
14
commits into
main
Choose a base branch
from
ADMINAPI-1260
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
1ccd9db
Add quartz.NET
CSR2017 0aa1c43
Update health check service
CSR2017 a90b19d
Delete unwanted files
CSR2017 75cb247
Update db ports
CSR2017 36ba11a
Refactor the health check service files
CSR2017 a3ff0c8
Add health check endpoint
CSR2017 34b70c0
Add health check unit tests
CSR2017 7afb474
Update dev docker .md file with powershell script details
CSR2017 a06e950
Add documentation for health check integration
CSR2017 105ffe9
Fix merge conflicts
CSR2017 f4c6f33
Fix build errors
CSR2017 465ab30
Add coverlet collector
CSR2017 81d951a
Add app http client unit tests
CSR2017 c0e2e0d
Rename the project to EdFi.Ods.AdminApi.HealthCheck
CSR2017 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...on/EdFi.Ods.AdminApi.HealthCheck.UnitTests/EdFi.Ods.AdminApi.HealthCheck.UnitTests.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="coverlet.collector"> | ||
| <PrivateAssets>all</PrivateAssets> | ||
| <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
| </PackageReference> | ||
| <PackageReference Include="FakeItEasy" /> | ||
| <PackageReference Include="Microsoft.NET.Test.Sdk" /> | ||
| <PackageReference Include="NUnit" /> | ||
| <PackageReference Include="NUnit3TestAdapter" /> | ||
| <PackageReference Include="NUnit.Analyzers"> | ||
| <PrivateAssets>all</PrivateAssets> | ||
| <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
| </PackageReference> | ||
| <PackageReference Include="Shouldly" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\EdFi.Ods.AdminApi.HealthCheck\EdFi.Ods.AdminApi.HealthCheck.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
59 changes: 59 additions & 0 deletions
59
Application/EdFi.Ods.AdminApi.HealthCheck.UnitTests/Features/OdsApi/OdsApiCallerTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // Licensed to the Ed-Fi Alliance under one or more agreements. | ||
| // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. | ||
| // See the LICENSE and NOTICES files in the project root for more information. | ||
|
|
||
| using System.Net; | ||
| using EdFi.Ods.AdminApi.HealthCheck.Helpers; | ||
| using EdFi.Ods.AdminApi.HealthCheck.Infrastructure; | ||
| using EdFi.Ods.AdminApi.HealthCheck.Features.OdsApi; | ||
| using FakeItEasy; | ||
| using NUnit.Framework; | ||
| using Shouldly; | ||
|
|
||
| namespace EdFi.Ods.AdminApi.HealthCheck.UnitTests.Features.OdsApi; | ||
|
|
||
| public class Given_an_ods_api | ||
| { | ||
| [TestFixture] | ||
| public class When_HealthCheckData_is_returned_from_api : Given_an_ods_api | ||
| { | ||
| private IOdsApiClient _odsApiClient; | ||
| private OdsApiCaller _odsApiCaller; | ||
|
|
||
| [SetUp] | ||
| public void SetUp() | ||
| { | ||
| _odsApiClient = A.Fake<IOdsApiClient>(); | ||
|
|
||
| var adminApiInstance = Testing.AdminApiInstances.First(); | ||
|
|
||
| var httpResponse1 = new HttpResponseMessage(HttpStatusCode.OK); | ||
| httpResponse1.Headers.Add(Constants.TotalCountHeader, "3"); | ||
|
|
||
| var httpResponse2 = new HttpResponseMessage(HttpStatusCode.OK); | ||
| httpResponse2.Headers.Add(Constants.TotalCountHeader, "8"); | ||
|
|
||
| var httpResponse3 = new HttpResponseMessage(HttpStatusCode.OK); | ||
| httpResponse3.Headers.Add(Constants.TotalCountHeader, "5"); | ||
|
|
||
| A.CallTo(() => _odsApiClient.OdsApiGet(A<string>.Ignored, A<string>.Ignored, A<string>.Ignored, "http://www.myserver.com/data/v3/ed-fi/firstEndPoint?offset=0&limit=0&totalCount=true")) | ||
| .Returns(new ApiResponse(HttpStatusCode.OK, string.Empty, httpResponse1.Headers)); | ||
|
|
||
| A.CallTo(() => _odsApiClient.OdsApiGet(A<string>.Ignored, A<string>.Ignored, A<string>.Ignored, "http://www.myserver.com/data/v3/ed-fi/secondEndpoint?offset=0&limit=0&totalCount=true")) | ||
| .Returns(new ApiResponse(HttpStatusCode.OK, string.Empty, httpResponse2.Headers)); | ||
|
|
||
| A.CallTo(() => _odsApiClient.OdsApiGet(A<string>.Ignored, A<string>.Ignored, A<string>.Ignored, "http://www.myserver.com/data/v3/ed-fi/thirdEndPoint?offset=0&limit=0&totalCount=true")) | ||
| .Returns(new ApiResponse(HttpStatusCode.OK, string.Empty, httpResponse3.Headers)); | ||
|
|
||
| _odsApiCaller = new OdsApiCaller(_odsApiClient, new AppSettingsOdsApiEndpoints(Testing.GetOdsApiSettings())); | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task should_return_stronglytyped_healthCheck_data() | ||
| { | ||
| var healthCheckData = await _odsApiCaller.GetHealthCheckDataAsync(Testing.AdminApiInstances.First()); | ||
| healthCheckData.ShouldBeEquivalentTo(Testing.HealthCheckData); | ||
| } | ||
| } | ||
| } |
84 changes: 84 additions & 0 deletions
84
Application/EdFi.Ods.AdminApi.HealthCheck.UnitTests/Features/OdsApi/OdsApiClientTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // Licensed to the Ed-Fi Alliance under one or more agreements. | ||
| // The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. | ||
| // See the LICENSE and NOTICES files in the project root for more information. | ||
|
|
||
| using System.Net; | ||
| using System.Net.Http.Headers; | ||
| using System.Text; | ||
| using EdFi.Ods.AdminApi.HealthCheck.Features.OdsApi; | ||
| using EdFi.Ods.AdminApi.HealthCheck.Helpers; | ||
| using EdFi.Ods.AdminApi.HealthCheck.Infrastructure; | ||
| using FakeItEasy; | ||
| using Microsoft.Extensions.Logging; | ||
| using NUnit.Framework; | ||
| using Shouldly; | ||
|
|
||
| namespace EdFi.Ods.AdminApi.HealthCheck.UnitTests.Features.OdsApi; | ||
|
|
||
| public class Given_an_ods_environment_with_single_tenant | ||
| { | ||
| private ILogger<OdsApiClient> _logger; | ||
|
|
||
| [SetUp] | ||
| public void SetUp() | ||
| { | ||
| _logger = A.Fake<ILogger<OdsApiClient>>(); | ||
| } | ||
|
|
||
| public class When_HealthCheck_data_is_requested : Given_an_ods_environment_with_single_tenant | ||
| { | ||
| [Test] | ||
| public async Task should_return_successfully() | ||
| { | ||
| var httpClient = A.Fake<IAppHttpClient>(); | ||
| var adminApiInstance = Testing.AdminApiInstances.First(); | ||
| var encodedKeySecret = Encoding.ASCII.GetBytes($"{adminApiInstance.ClientId}:{adminApiInstance.ClientSecret}"); | ||
| var headers = new HttpResponseMessage().Headers; | ||
| headers.Add(Constants.TotalCountHeader, "5"); | ||
|
|
||
| A.CallTo(() => httpClient.SendAsync( | ||
| adminApiInstance.OauthUrl, HttpMethod.Post, A<FormUrlEncodedContent>.Ignored, new AuthenticationHeaderValue("Basic", Convert.ToBase64String(encodedKeySecret)))) | ||
| .Returns(new ApiResponse(HttpStatusCode.OK, "{ \"access_token\": \"123\"}")); | ||
|
|
||
| A.CallTo(() => httpClient.SendAsync(adminApiInstance.ResourceUrl, HttpMethod.Get, null as StringContent, new AuthenticationHeaderValue("bearer", "123"))) | ||
| .Returns(new ApiResponse(HttpStatusCode.OK, string.Empty, headers)); | ||
|
|
||
| var odsApiClient = new OdsApiClient(httpClient, _logger, Testing.GetAppSettings()); | ||
|
|
||
| var response = await odsApiClient.OdsApiGet( | ||
| adminApiInstance.OauthUrl, adminApiInstance.ClientId, adminApiInstance.ClientSecret, adminApiInstance.ResourceUrl); | ||
|
|
||
| response.Headers.ShouldNotBeNull(); | ||
| response.Headers.Any(o => o.Key == Constants.TotalCountHeader).ShouldBe(true); | ||
| response.Headers.GetValues(Constants.TotalCountHeader).First().ShouldBe("5"); | ||
| } | ||
| } | ||
|
|
||
| public class When_HealthCheck_data_is_requested_without_token : Given_an_ods_environment_with_single_tenant | ||
| { | ||
| [Test] | ||
| public async Task InternalServerError_is_returned() | ||
| { | ||
| var httpClient = A.Fake<IAppHttpClient>(); | ||
| var adminApiInstance = Testing.AdminApiInstances.First(); | ||
| var encodedKeySecret = Encoding.ASCII.GetBytes($"{adminApiInstance.ClientId}:{adminApiInstance.ClientSecret}"); | ||
|
|
||
| var headers = new HttpResponseMessage().Headers; | ||
| headers.Add(Constants.TotalCountHeader, "5"); | ||
|
|
||
| A.CallTo(() => httpClient.SendAsync( | ||
| adminApiInstance.OauthUrl, HttpMethod.Post, A<FormUrlEncodedContent>.Ignored, new AuthenticationHeaderValue("Basic", Convert.ToBase64String(encodedKeySecret)))) | ||
| .Returns(new ApiResponse(HttpStatusCode.InternalServerError, string.Empty)); | ||
|
|
||
| A.CallTo(() => httpClient.SendAsync(adminApiInstance.ResourceUrl, HttpMethod.Get, null as StringContent, new AuthenticationHeaderValue("bearer", "123"))) | ||
| .Returns(new ApiResponse(HttpStatusCode.OK, string.Empty, headers)); | ||
|
|
||
| var odsApiClient = new OdsApiClient(httpClient, _logger, Testing.GetAppSettings()); | ||
|
|
||
| var response = await odsApiClient.OdsApiGet(adminApiInstance.OauthUrl, adminApiInstance.ClientId, adminApiInstance.ClientSecret, adminApiInstance.ResourceUrl); | ||
|
|
||
| response.StatusCode.ShouldBe(HttpStatusCode.InternalServerError); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could simplify all of this switching the Dockerfile to use the new "additional contexts" feature, which allows accessing files from a different parent directory.
Let's do that as a separate work item though, rather than allowing scope creep on this.