-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #155 from itsharppro/dev
- Loading branch information
Showing
28 changed files
with
963 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
35 changes: 35 additions & 0 deletions
35
src/Paralax.Diagnostics.HealthChecks/scripts/build-and-pack.sh
This file contains 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,35 @@ | ||
#!/bin/bash | ||
|
||
echo "Executing post-success scripts for branch $GITHUB_REF_NAME" | ||
echo "Starting build and NuGet package creation for Paralax.Diagnostics.HealthChecks framework..." | ||
|
||
cd src/Paralax.Diagnostics.HealthChecks/src/Paralax.Diagnostics.HealthChecks | ||
|
||
echo "Restoring NuGet packages..." | ||
dotnet restore | ||
|
||
PACKAGE_VERSION="1.0.$GITHUB_RUN_NUMBER" | ||
echo "Building and packing the Paralax.Diagnostics.HealthChecks library..." | ||
dotnet pack -c release /p:PackageVersion=$PACKAGE_VERSION --no-restore -o ./nupkg | ||
|
||
PACKAGE_PATH="./nupkg/Paralax.Diagnostics.HealthChecks.$PACKAGE_VERSION.nupkg" | ||
|
||
if [ -f "$PACKAGE_PATH" ]; then | ||
echo "Checking if the package is already signed..." | ||
if dotnet nuget verify "$PACKAGE_PATH" | grep -q 'Package is signed'; then | ||
echo "Package is already signed, skipping signing." | ||
else | ||
echo "Signing the NuGet package..." | ||
dotnet nuget sign "$PACKAGE_PATH" \ | ||
--certificate-path "$CERTIFICATE_PATH" \ | ||
--timestamper http://timestamp.digicert.com | ||
fi | ||
|
||
echo "Uploading Paralax.Diagnostics.HealthChecks package to NuGet..." | ||
dotnet nuget push "$PACKAGE_PATH" -k "$NUGET_API_KEY" \ | ||
-s https://api.nuget.org/v3/index.json --skip-duplicate | ||
echo "Package uploaded to NuGet." | ||
else | ||
echo "Error: Package $PACKAGE_PATH not found." | ||
exit 1 | ||
fi |
18 changes: 18 additions & 0 deletions
18
src/Paralax.Diagnostics.HealthChecks/scripts/test-and-collect-coverage.sh
This file contains 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,18 @@ | ||
#!/bin/bash | ||
|
||
echo "Running tests and collecting coverage for Paralax.Diagnostics.HealthChecks..." | ||
|
||
cd src/Paralax.Diagnostics.HealthChecks/tests/Paralax.Diagnostics.HealthChecks | ||
|
||
echo "Restoring NuGet packages..." | ||
dotnet restore | ||
|
||
echo "Running tests and generating code coverage report..." | ||
dotnet test --collect:"XPlat Code Coverage" --results-directory ./TestResults | ||
|
||
# Check if tests succeeded | ||
if [ $? -ne 0 ]; then | ||
echo "Tests failed. Exiting..." | ||
exit 1 | ||
fi | ||
|
7 changes: 7 additions & 0 deletions
7
src/Paralax.Diagnostics.HealthChecks/src/Paralax.Diagnostics.HealthChecks/HealthCheckBase.cs
This file contains 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,7 @@ | ||
namespace Paralax.Diagnostics.HealthChecks; | ||
|
||
public abstract class HealthCheckBase : IHealthCheck | ||
{ | ||
public abstract Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, | ||
CancellationToken cancellationToken = default); | ||
} |
14 changes: 14 additions & 0 deletions
14
...Diagnostics.HealthChecks/src/Paralax.Diagnostics.HealthChecks/HealthCheckConfiguration.cs
This file contains 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,14 @@ | ||
namespace Paralax.Diagnostics.HealthChecks; | ||
|
||
public class HealthCheckConfiguration | ||
{ | ||
public string Name { get; set; } | ||
public string Description { get; set; } | ||
public string Endpoint { get; set; } | ||
public string HttpMethod { get; set; } | ||
public string ExpectedResponse { get; set; } | ||
public int Timeout { get; set; } | ||
public int Interval { get; set; } | ||
public int Retries { get; set; } | ||
public bool Enabled { get; set; } | ||
} |
6 changes: 6 additions & 0 deletions
6
...ralax.Diagnostics.HealthChecks/src/Paralax.Diagnostics.HealthChecks/HealthCheckContext.cs
This file contains 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,6 @@ | ||
namespace Paralax.Diagnostics.HealthChecks; | ||
|
||
public class HealthCheckContext | ||
{ | ||
public string? RegistrationName { get; set; } | ||
} |
26 changes: 26 additions & 0 deletions
26
...alax.Diagnostics.HealthChecks/src/Paralax.Diagnostics.HealthChecks/HealthCheckRegistry.cs
This file contains 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,26 @@ | ||
using System.Collections.Concurrent; | ||
|
||
namespace Paralax.Diagnostics.HealthChecks; | ||
|
||
public class HealthCheckRegistry | ||
{ | ||
private readonly ConcurrentDictionary<string, IHealthCheck> _healthChecks = new(); | ||
|
||
public bool Register(string name, IHealthCheck healthCheck) | ||
{ | ||
if (string.IsNullOrWhiteSpace(name)) | ||
throw new ArgumentException("Health check name must not be null or whitespace.", nameof(name)); | ||
|
||
return _healthChecks.TryAdd(name, healthCheck); | ||
} | ||
|
||
public bool Unregister(string name) | ||
{ | ||
return _healthChecks.TryRemove(name, out var _); | ||
} | ||
|
||
public IEnumerable<string> RegisteredChecks => _healthChecks.Keys; | ||
|
||
internal ConcurrentDictionary<string, IHealthCheck> HealthChecks => _healthChecks; | ||
} | ||
|
30 changes: 30 additions & 0 deletions
30
...aralax.Diagnostics.HealthChecks/src/Paralax.Diagnostics.HealthChecks/HealthCheckResult.cs
This file contains 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 @@ | ||
namespace Paralax.Diagnostics.HealthChecks; | ||
|
||
public class HealthCheckResult | ||
{ | ||
public static HealthCheckResult Healthy(string? description = null, IReadOnlyDictionary<string, object>? data = null) => | ||
new HealthCheckResult(HealthStatus.Healthy, description, data); | ||
|
||
public static HealthCheckResult Degraded(string? description = null, IReadOnlyDictionary<string, object>? data = null) => | ||
new HealthCheckResult(HealthStatus.Degraded, description, data); | ||
|
||
public static HealthCheckResult Unhealthy(string? description = null, IReadOnlyDictionary<string, object>? data = null) => | ||
new HealthCheckResult(HealthStatus.Unhealthy, description, data); | ||
|
||
public static HealthCheckResult Busy(string? description = null, IReadOnlyDictionary<string, object>? data = null) => | ||
new HealthCheckResult(HealthStatus.Busy, description, data); | ||
|
||
public static HealthCheckResult Maintenance(string? description = null, IReadOnlyDictionary<string, object>? data = null) => | ||
new HealthCheckResult(HealthStatus.Maintenance, description, data); | ||
|
||
public HealthStatus Status { get; } | ||
public string? Description { get; } | ||
public IReadOnlyDictionary<string, object>? Data { get; } | ||
|
||
private HealthCheckResult(HealthStatus status, string? description, IReadOnlyDictionary<string, object>? data) | ||
{ | ||
Status = status; | ||
Description = description; | ||
Data = data ?? new Dictionary<string, object>(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...ralax.Diagnostics.HealthChecks/src/Paralax.Diagnostics.HealthChecks/HealthCheckService.cs
This file contains 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,24 @@ | ||
namespace Paralax.Diagnostics.HealthChecks; | ||
|
||
public class HealthCheckService | ||
{ | ||
private readonly HealthCheckRegistry _registry; | ||
|
||
public HealthCheckService(HealthCheckRegistry registry) | ||
{ | ||
_registry = registry; | ||
} | ||
|
||
public async Task<Dictionary<string, HealthCheckResult>> RunHealthChecksAsync(CancellationToken cancellationToken = default) | ||
{ | ||
var results = new Dictionary<string, HealthCheckResult>(); | ||
|
||
foreach (var healthCheck in _registry.HealthChecks) | ||
{ | ||
var context = new HealthCheckContext { RegistrationName = healthCheck.Key }; | ||
results[healthCheck.Key] = await healthCheck.Value.CheckHealthAsync(context, cancellationToken).ConfigureAwait(false); | ||
} | ||
|
||
return results; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...lthChecks/src/Paralax.Diagnostics.HealthChecks/HealthChecksServiceCollectionExtensions.cs
This file contains 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,25 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Paralax.Diagnostics.HealthChecks; | ||
|
||
public static class HealthChecksServiceCollectionExtensions | ||
{ | ||
public static IServiceCollection AddHealthChecks(this IServiceCollection services) | ||
{ | ||
var registry = new HealthCheckRegistry(); | ||
services.AddSingleton(registry); | ||
services.AddSingleton<HealthCheckService>(); | ||
|
||
return services; | ||
} | ||
|
||
public static IServiceCollection AddCheck<THealthCheck>(this IServiceCollection services, string name, HealthStatus failureStatus = HealthStatus.Unhealthy) | ||
where THealthCheck : class, IHealthCheck | ||
{ | ||
var registry = services.BuildServiceProvider().GetService<HealthCheckRegistry>(); | ||
var healthCheckInstance = ActivatorUtilities.CreateInstance<THealthCheck>(services.BuildServiceProvider()); | ||
registry?.Register(name, healthCheckInstance); | ||
|
||
return services; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/Paralax.Diagnostics.HealthChecks/src/Paralax.Diagnostics.HealthChecks/HealthStatus.cs
This file contains 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,10 @@ | ||
namespace Paralax.Diagnostics.HealthChecks; | ||
|
||
public enum HealthStatus | ||
{ | ||
Healthy, | ||
Degraded, | ||
Unhealthy, | ||
Busy, | ||
Maintenance | ||
} |
6 changes: 6 additions & 0 deletions
6
src/Paralax.Diagnostics.HealthChecks/src/Paralax.Diagnostics.HealthChecks/IHealthCheck.cs
This file contains 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,6 @@ | ||
namespace Paralax.Diagnostics.HealthChecks; | ||
|
||
public interface IHealthCheck | ||
{ | ||
Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default); | ||
} |
43 changes: 43 additions & 0 deletions
43
...HealthChecks/src/Paralax.Diagnostics.HealthChecks/Paralax.Diagnostics.HealthChecks.csproj
This file contains 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,43 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<Description>Paralax.Diagnostics.HealthChecks - healthcheks abstraction library</Description> | ||
<Authors>ITSharpPro</Authors> | ||
<Company>ITSharpPro</Company> | ||
<PackageProjectUrl>https://itsharppro.com</PackageProjectUrl> | ||
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression> | ||
<RepositoryUrl>https://github.com/ITSharpPro/Paralax</RepositoryUrl> | ||
<RepositoryType>git</RepositoryType> | ||
<PackageTags>microservices; monitoring; healthchecks; grpc; ITSharpPro</PackageTags> | ||
<PackageReleaseNotes> | ||
Initial release of Paralax.Diagnostics.HealthChecks for integrating healthchecks abstraction in microservices. | ||
</PackageReleaseNotes> | ||
<Copyright>ITSharpPro © $(Year)</Copyright> | ||
<TargetFrameworks>net8.0;net9.0</TargetFrameworks> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<LangVersion>latest</LangVersion> | ||
|
||
<PackageId>Paralax.Diagnostics.HealthChecks</PackageId> | ||
<PackageIcon>Paralax_logo_128.png</PackageIcon> | ||
<PackageReadmeFile>README.md</PackageReadmeFile> | ||
<IsPackable>true</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Include="../../../../README.md"> | ||
<Pack>True</Pack> | ||
<PackagePath>\</PackagePath> | ||
</None> | ||
|
||
<None Include="../../../../docs/logo/Paralax_logo_128.png"> | ||
<Pack>True</Pack> | ||
<PackagePath>\</PackagePath> | ||
</None> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
25 changes: 25 additions & 0 deletions
25
...cs.HealthChecks/src/Paralax.Diagnostics.HealthChecks/Paralax.Diagnostics.HealthChecks.sln
This file contains 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,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.5.002.0 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Paralax.Diagnostics.HealthChecks", "Paralax.Diagnostics.HealthChecks.csproj", "{5925B605-69FD-42EF-892B-3A83315AA496}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{5925B605-69FD-42EF-892B-3A83315AA496}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{5925B605-69FD-42EF-892B-3A83315AA496}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{5925B605-69FD-42EF-892B-3A83315AA496}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{5925B605-69FD-42EF-892B-3A83315AA496}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {592BE02A-42AB-4B9E-98B4-841442FC0206} | ||
EndGlobalSection | ||
EndGlobal |
This file contains 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,35 @@ | ||
#!/bin/bash | ||
|
||
echo "Executing post-success scripts for branch $GITHUB_REF_NAME" | ||
echo "Starting build and NuGet package creation for Paralax.OpenTelemetry framework..." | ||
|
||
cd src/Paralax.OpenTelemetry/src/Paralax.OpenTelemetry | ||
|
||
echo "Restoring NuGet packages..." | ||
dotnet restore | ||
|
||
PACKAGE_VERSION="1.0.$GITHUB_RUN_NUMBER" | ||
echo "Building and packing the Paralax.OpenTelemetry library..." | ||
dotnet pack -c release /p:PackageVersion=$PACKAGE_VERSION --no-restore -o ./nupkg | ||
|
||
PACKAGE_PATH="./nupkg/Paralax.OpenTelemetry.$PACKAGE_VERSION.nupkg" | ||
|
||
if [ -f "$PACKAGE_PATH" ]; then | ||
echo "Checking if the package is already signed..." | ||
if dotnet nuget verify "$PACKAGE_PATH" | grep -q 'Package is signed'; then | ||
echo "Package is already signed, skipping signing." | ||
else | ||
echo "Signing the NuGet package..." | ||
dotnet nuget sign "$PACKAGE_PATH" \ | ||
--certificate-path "$CERTIFICATE_PATH" \ | ||
--timestamper http://timestamp.digicert.com | ||
fi | ||
|
||
echo "Uploading Paralax.OpenTelemetry package to NuGet..." | ||
dotnet nuget push "$PACKAGE_PATH" -k "$NUGET_API_KEY" \ | ||
-s https://api.nuget.org/v3/index.json --skip-duplicate | ||
echo "Package uploaded to NuGet." | ||
else | ||
echo "Error: Package $PACKAGE_PATH not found." | ||
exit 1 | ||
fi |
18 changes: 18 additions & 0 deletions
18
src/Paralax.OpenTelemetry/scripts/test-and-collect-coverage.sh
This file contains 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,18 @@ | ||
#!/bin/bash | ||
|
||
echo "Running tests and collecting coverage for Paralax.OpenTelemetry..." | ||
|
||
cd src/Paralax.OpenTelemetry/tests/Paralax.OpenTelemetry | ||
|
||
echo "Restoring NuGet packages..." | ||
dotnet restore | ||
|
||
echo "Running tests and generating code coverage report..." | ||
dotnet test --collect:"XPlat Code Coverage" --results-directory ./TestResults | ||
|
||
# Check if tests succeeded | ||
if [ $? -ne 0 ]; then | ||
echo "Tests failed. Exiting..." | ||
exit 1 | ||
fi | ||
|
Oops, something went wrong.