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

add methods for health checks #41

Merged
merged 6 commits into from
Apr 2, 2020
Merged

add methods for health checks #41

merged 6 commits into from
Apr 2, 2020

Conversation

wi-y
Copy link
Contributor

@wi-y wi-y commented Mar 23, 2020

  • added methods for health checks
  • a developer can add CheckHealth() to Functions.cs wrapped in a try/catch to check health of fhir server

Copy link
Member

@dustinburson dustinburson left a comment

Choose a reason for hiding this comment

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

Overall I like the design and where you have the code. Before completion I would like to see HealthCheck data class moved to the data namespace, adding a cancellation token & make async, and some simple unit tests for the different exceptions you service is responding too. Other comments are optional. Let me know if you would like to discuss further, Thanks!

{
public abstract class FhirHealthService
{
public abstract Task<FhirHealthCheckStatus> CheckHealth();
Copy link
Member

Choose a reason for hiding this comment

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

This should probably be updated to take a cancellation token since this will be asynchronous. You can set it to default if you would like but it should be an option.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

catch (Exception ex)
{
return Task.FromResult(new FhirHealthCheckStatus(ex.Message, 500));
throw;
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to throw here? I would think we want to record the issue and be done. Was there a specific case you wanted to throw for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really, I only added it originally because of the linter. I went ahead and removed the throw


namespace Microsoft.Health.Fhir.Ingest.Service
{
public class R4FhirHealthService :
Copy link
Member

Choose a reason for hiding this comment

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

Can we have unit tests with mocks of the exceptions to test the various outputs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added tests


namespace Microsoft.Health.Fhir.Ingest.Service
{
public abstract class FhirHealthService
Copy link
Member

Choose a reason for hiding this comment

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

Thoughts on the public method just returning Task and taking an ILogger for telemetry recording? In this instance you would still have version of CheckHealth returning the FhirHealthCheckStatus but it would be a protected abstract member that the implementer needs to specify. Then the public method of Task Name(ILogger, CancelationToken) would record the result in a standard way in the logger so the upstream implementer doesn't need to. Only thing you need in the function definition is the instance of the Health Check & the ILogger which you can get with DI on the function signature. This also makes the use of the abstract class more appropriate. Right now the abstract class doesn't have any implementation outside a contract and could just be an interface.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense, but I'm not sure I would like to address this at this moment

Copy link
Member

Choose a reason for hiding this comment

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

Okay, it can be part of the next step.

sp =>
{
var fhirClient = sp.GetRequiredService<IFhirClient>();
var resourceIdentityOptions = sp.GetRequiredService<IOptions<ResourceIdentityOptions>>();
return ResourceIdentityServiceFactory.Instance.Create(resourceIdentityOptions.Value, fhirClient);
});
builder.Services.AddSingleton<IMemoryCache>(sp => new MemoryCache(Options.Create<MemoryCacheOptions>(new MemoryCacheOptions { SizeLimit = 5000 })));
builder.Services.AddSingleton<FhirImportService, R4FhirImportService>();
builder.Services.TryAddSingleton<IMemoryCache>(sp => new MemoryCache(Options.Create<MemoryCacheOptions>(new MemoryCacheOptions { SizeLimit = 5000 })));
Copy link
Member

Choose a reason for hiding this comment

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

Looks good, thanks for making this change!

@wi-y wi-y requested a review from dustinburson April 2, 2020 17:03
Copy link
Member

@dustinburson dustinburson left a comment

Choose a reason for hiding this comment

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

Looks good


namespace Microsoft.Health.Fhir.Ingest.Service
{
public abstract class FhirHealthService
Copy link
Member

Choose a reason for hiding this comment

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

Okay, it can be part of the next step.

_fhirHealthService = EnsureArg.IsNotNull(fhirHealthService, nameof(fhirHealthService));
}

public async Task<FhirHealthCheckStatus> CheckHealth(CancellationToken token = default)
Copy link
Member

Choose a reason for hiding this comment

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

standard convention is to have an Async suffix on Async methods.

@wi-y wi-y merged commit d5e6272 into master Apr 2, 2020
@dustinburson dustinburson deleted the personal/wiy/health-check branch November 8, 2022 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants