From 55bffc448c05b1b383b42593919d15689b98e928 Mon Sep 17 00:00:00 2001 From: Tim Hess Date: Fri, 15 Jun 2018 16:40:42 -0500 Subject: [PATCH] Move Health interfaces to Common [#154972562] --- .../HealthChecks/HealthCheckResult.cs | 42 +++++++++++++++++++ .../HealthChecks/HealthStatus.cs | 25 +++++++++++ .../HealthChecks/IHealthContributor.cs | 33 +++++++++++++++ 3 files changed, 100 insertions(+) create mode 100644 src/Steeltoe.Common/HealthChecks/HealthCheckResult.cs create mode 100644 src/Steeltoe.Common/HealthChecks/HealthStatus.cs create mode 100644 src/Steeltoe.Common/HealthChecks/IHealthContributor.cs diff --git a/src/Steeltoe.Common/HealthChecks/HealthCheckResult.cs b/src/Steeltoe.Common/HealthChecks/HealthCheckResult.cs new file mode 100644 index 0000000..db8cbb8 --- /dev/null +++ b/src/Steeltoe.Common/HealthChecks/HealthCheckResult.cs @@ -0,0 +1,42 @@ +// Copyright 2017 the original author or authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using System.Collections.Generic; + +namespace Steeltoe.Common.HealthChecks +{ + /// + /// The result of a health check + /// + public class HealthCheckResult + { + /// + /// Gets or sets the status of the check + /// + /// Used by HealthMiddleware to determine HTTP Status code + public HealthStatus Status { get; set; } = HealthStatus.UNKNOWN; + + /// + /// Gets or sets a description of the health check result + /// + /// Currently only used on check failures + public string Description { get; set; } + + /// + /// Gets or sets details of the checked item + /// + /// For parity with Spring Boot, repeat status [with a call to .ToString()] here + public Dictionary Details { get; set; } = new Dictionary(); + } +} \ No newline at end of file diff --git a/src/Steeltoe.Common/HealthChecks/HealthStatus.cs b/src/Steeltoe.Common/HealthChecks/HealthStatus.cs new file mode 100644 index 0000000..69aaf64 --- /dev/null +++ b/src/Steeltoe.Common/HealthChecks/HealthStatus.cs @@ -0,0 +1,25 @@ +// Copyright 2017 the original author or authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace Steeltoe.Common.HealthChecks +{ + public enum HealthStatus + { + UNKNOWN, + UP, + WARNING, + OUT_OF_SERVICE, + DOWN, + } +} diff --git a/src/Steeltoe.Common/HealthChecks/IHealthContributor.cs b/src/Steeltoe.Common/HealthChecks/IHealthContributor.cs new file mode 100644 index 0000000..05c1356 --- /dev/null +++ b/src/Steeltoe.Common/HealthChecks/IHealthContributor.cs @@ -0,0 +1,33 @@ +// Copyright 2017 the original author or authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace Steeltoe.Common.HealthChecks +{ + /// + /// Implement this interface and add to DI to be included in health checks + /// + public interface IHealthContributor + { + /// + /// Gets an identifier for the type of check being performed + /// + string Id { get; } + + /// + /// Check the health of a resource + /// + /// The result of checking the health of a resource + HealthCheckResult Health(); + } +}