Skip to content

Commit

Permalink
Release 2.3 (#38)
Browse files Browse the repository at this point in the history
Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
IharYakimush and dependabot[bot] authored Jul 15, 2024
1 parent c06f4a2 commit a15a4eb
Show file tree
Hide file tree
Showing 107 changed files with 3,459 additions and 383 deletions.
14 changes: 14 additions & 0 deletions Epam.Kafka.sln
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Docker", "Docker", "{FEEEFB
tests\kafka-stop.cmd = tests\kafka-stop.cmd
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Epam.Kafka.HealthChecks", "src\Epam.Kafka.HealthChecks\Epam.Kafka.HealthChecks.csproj", "{F698E1DF-EF50-4358-86A1-D43A60692094}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Epam.Kafka.HealthChecks.Tests", "tests\Epam.Kafka.HealthChecks.Tests\Epam.Kafka.HealthChecks.Tests.csproj", "{1A03484B-86A4-4FBA-936C-E8F6C0C03992}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -115,6 +119,14 @@ Global
{9BF7230E-5647-44F5-A7E5-CAA5C80A5A94}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9BF7230E-5647-44F5-A7E5-CAA5C80A5A94}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9BF7230E-5647-44F5-A7E5-CAA5C80A5A94}.Release|Any CPU.Build.0 = Release|Any CPU
{F698E1DF-EF50-4358-86A1-D43A60692094}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F698E1DF-EF50-4358-86A1-D43A60692094}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F698E1DF-EF50-4358-86A1-D43A60692094}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F698E1DF-EF50-4358-86A1-D43A60692094}.Release|Any CPU.Build.0 = Release|Any CPU
{1A03484B-86A4-4FBA-936C-E8F6C0C03992}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1A03484B-86A4-4FBA-936C-E8F6C0C03992}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1A03484B-86A4-4FBA-936C-E8F6C0C03992}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1A03484B-86A4-4FBA-936C-E8F6C0C03992}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -134,6 +146,8 @@ Global
{222BCFF6-0433-4BE2-B19F-800790CC9261} = {837928B6-19AD-471C-A875-912C7F1F97C7}
{CC45261E-D51D-43F4-829D-34BDC3D68EEE} = {A5013F6E-5A4E-4FC5-8A20-96AEB83BA9C7}
{FEEEFBBD-B549-459A-A5F2-3F608EC1BF39} = {222BCFF6-0433-4BE2-B19F-800790CC9261}
{F698E1DF-EF50-4358-86A1-D43A60692094} = {E0525F24-5B2C-4D26-A93F-6817B1540C87}
{1A03484B-86A4-4FBA-936C-E8F6C0C03992} = {837928B6-19AD-471C-A875-912C7F1F97C7}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {12AADABB-DDF0-4214-9300-49F6F55819DA}
Expand Down
20 changes: 12 additions & 8 deletions sample/Epam.Kafka.Sample.Net462/Epam.Kafka.Sample.Net462.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>packages\EntityFramework.6.4.4\lib\net45\EntityFramework.SqlServer.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.Bcl.AsyncInterfaces.6.0.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51">
<HintPath>packages\Microsoft.Bcl.AsyncInterfaces.8.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Extensions.Configuration, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.Extensions.Configuration.6.0.0\lib\net461\Microsoft.Extensions.Configuration.dll</HintPath>
Expand Down Expand Up @@ -161,8 +162,9 @@
<Reference Include="System.Diagnostics.DiagnosticSource, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>packages\System.Diagnostics.DiagnosticSource.6.0.0\lib\net461\System.Diagnostics.DiagnosticSource.dll</HintPath>
</Reference>
<Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>packages\System.Memory.4.5.4\lib\net461\System.Memory.dll</HintPath>
<Reference Include="System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51">
<HintPath>packages\System.Memory.4.5.5\lib\net461\System.Memory.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Net.Http, Version=4.1.1.3, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>packages\System.Net.Http.4.3.4\lib\net46\System.Net.Http.dll</HintPath>
Expand Down Expand Up @@ -190,11 +192,13 @@
<Reference Include="System.Security.Cryptography.X509Certificates, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net461\System.Security.Cryptography.X509Certificates.dll</HintPath>
</Reference>
<Reference Include="System.Text.Encodings.Web, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>packages\System.Text.Encodings.Web.6.0.0\lib\net461\System.Text.Encodings.Web.dll</HintPath>
<Reference Include="System.Text.Encodings.Web, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51">
<HintPath>packages\System.Text.Encodings.Web.8.0.0\lib\net462\System.Text.Encodings.Web.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Text.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>packages\System.Text.Json.6.0.0\lib\net461\System.Text.Json.dll</HintPath>
<Reference Include="System.Text.Json, Version=8.0.0.4, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51">
<HintPath>packages\System.Text.Json.8.0.4\lib\net462\System.Text.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
Expand Down
8 changes: 4 additions & 4 deletions sample/Epam.Kafka.Sample.Net462/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<package id="Effort.EF6" version="2.2.17" targetFramework="net462" />
<package id="EntityFramework" version="6.4.4" targetFramework="net462" />
<package id="librdkafka.redist" version="2.4.0" targetFramework="net462" />
<package id="Microsoft.Bcl.AsyncInterfaces" version="6.0.0" targetFramework="net462" />
<package id="Microsoft.Bcl.AsyncInterfaces" version="8.0.0" targetFramework="net462" />
<package id="Microsoft.Extensions.Configuration" version="6.0.0" targetFramework="net462" />
<package id="Microsoft.Extensions.Configuration.Abstractions" version="6.0.0" targetFramework="net462" />
<package id="Microsoft.Extensions.Configuration.Binder" version="6.0.0" targetFramework="net462" />
Expand Down Expand Up @@ -35,7 +35,7 @@
<package id="NMemory" version="3.1.4" targetFramework="net462" />
<package id="System.Buffers" version="4.5.1" targetFramework="net462" />
<package id="System.Diagnostics.DiagnosticSource" version="6.0.0" targetFramework="net462" />
<package id="System.Memory" version="4.5.4" targetFramework="net462" />
<package id="System.Memory" version="4.5.5" targetFramework="net462" />
<package id="System.Net.Http" version="4.3.4" targetFramework="net462" />
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net462" />
<package id="System.Runtime.CompilerServices.Unsafe" version="6.0.0" targetFramework="net462" />
Expand All @@ -44,8 +44,8 @@
<package id="System.Security.Cryptography.Encoding" version="4.3.0" targetFramework="net462" />
<package id="System.Security.Cryptography.Primitives" version="4.3.0" targetFramework="net462" />
<package id="System.Security.Cryptography.X509Certificates" version="4.3.0" targetFramework="net462" />
<package id="System.Text.Encodings.Web" version="6.0.0" targetFramework="net462" />
<package id="System.Text.Json" version="6.0.0" targetFramework="net462" />
<package id="System.Text.Encodings.Web" version="8.0.0" targetFramework="net462" />
<package id="System.Text.Json" version="8.0.4" targetFramework="net462" />
<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net462" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net462" />
</packages>
1 change: 1 addition & 0 deletions sample/Epam.Kafka.Sample/Epam.Kafka.Sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Epam.Kafka.HealthChecks\Epam.Kafka.HealthChecks.csproj" />
<ProjectReference Include="..\..\src\Epam.Kafka.PubSub.EntityFrameworkCore\Epam.Kafka.PubSub.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\..\src\Epam.Kafka\Epam.Kafka.csproj" />
</ItemGroup>
Expand Down
15 changes: 11 additions & 4 deletions sample/Epam.Kafka.Sample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using Confluent.Kafka;

using Epam.Kafka.HealthChecks;
using Epam.Kafka.PubSub;
using Epam.Kafka.PubSub.Common.Pipeline;
using Epam.Kafka.PubSub.EntityFrameworkCore;
Expand All @@ -25,25 +26,31 @@ private static void Main(string[] args)
{
IHostBuilder hostBuilder = Host.CreateDefaultBuilder(args);

hostBuilder.ConfigureServices((context,services) =>
hostBuilder.ConfigureServices((context, services) =>
{
// view health check results in console for demo purposes only.
services.AddSingleton<IHealthCheckPublisher, ConsoleHealthCheckPublisher>();

// view metrics in console for demo purposes only
services.AddOpenTelemetry().WithMetrics(mb =>
mb.AddMeter(PipelineMonitor.StatusMeterName, PipelineMonitor.HealthMeterName).AddConsoleExporter());
services.AddOpenTelemetry()
.WithMetrics(mb => mb
.AddMeter(PipelineMonitor.StatusMeterName, PipelineMonitor.HealthMeterName)
.AddConsoleExporter());

KafkaBuilder kafkaBuilder = services.AddKafka()
.WithConfigPlaceholders("<EnvironmentName>", context.HostingEnvironment.EnvironmentName);

kafkaBuilder.WithPubSubSummaryHealthCheck();

kafkaBuilder.WithClusterConfig("Sandbox").Configure(options =>
{
// For demo purposes run Mock server instead of real one and create required topics.
// Also it is possible to run real kafka cluster in docker using provided 'docker-compose.yml' file.
options.ClientConfig.BootstrapServers = RunMockServer();

}).WithHealthCheck().Configure(options =>
{
options.SkipAdminClient = true;
});

services.AddDbContext<SampleDbContext>(x => x.UseInMemoryDatabase("sample"));
Expand Down
5 changes: 3 additions & 2 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
<PackageTags>epam kafka</PackageTags>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<NeutralLanguage>en</NeutralLanguage>

<PackageReleaseNotes>https://github.com/epam/epam-kafka/releases</PackageReleaseNotes>
<VersionPrefix>0</VersionPrefix>
<Version>2.2.$(VersionPrefix)</Version>
<Version>2.3.$(VersionPrefix)</Version>
</PropertyGroup>

<ItemGroup>
Expand All @@ -37,6 +37,7 @@

<ItemGroup>
<InternalsVisibleTo Include="$(AssemblyName).Tests" />
<InternalsVisibleTo Include="$(AssemblyName).HealthChecks" />
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" />
</ItemGroup>
</Project>
138 changes: 138 additions & 0 deletions src/Epam.Kafka.HealthChecks/ClusterHealthCheck.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
// Copyright © 2024 EPAM Systems

using Confluent.Kafka;
using Confluent.Kafka.Admin;
using Confluent.SchemaRegistry;
using Epam.Kafka.Internals;
using Epam.Kafka.Options;

using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.Options;

namespace Epam.Kafka.HealthChecks;

internal sealed class ClusterHealthCheck : IHealthCheck, IObserver<Error>
{
private readonly IKafkaFactory _kafkaFactory;
private readonly IOptionsMonitor<ClusterHealthCheckOptions> _optionsMonitor;
private readonly IOptionsMonitor<KafkaClusterOptions> _clusterOptionsMonitor;
private readonly List<Error> _errors = new();

public const string NamePrefix = "Epam.Kafka.Cluster.";

public ClusterHealthCheck(
IKafkaFactory kafkaFactory,
IOptionsMonitor<ClusterHealthCheckOptions> optionsMonitor,
IOptionsMonitor<KafkaClusterOptions> clusterOptionsMonitor)
{
this._kafkaFactory = kafkaFactory ?? throw new ArgumentNullException(nameof(kafkaFactory));
this._optionsMonitor = optionsMonitor ?? throw new ArgumentNullException(nameof(optionsMonitor));
this._clusterOptionsMonitor = clusterOptionsMonitor ?? throw new ArgumentNullException(nameof(clusterOptionsMonitor));
}

public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context,
CancellationToken cancellationToken = new CancellationToken())
{
string description = "Not used by application.";
HealthStatus status = HealthStatus.Healthy;

string name = context.Registration.Name.Substring(NamePrefix.Length);

ClusterHealthCheckOptions options = this._optionsMonitor.Get(name);

if (options.IncludeUnused || this._kafkaFactory is not KafkaFactory kf || kf.UsedClusters.Contains(name))
{
description = "AdminClient: ";

if (options.SkipAdminClient)
{
description += "check skipped.";
}
else
{
#pragma warning disable CA1031 // Not applicable for this health checks

try
{
using IClient client = this._kafkaFactory.GetOrCreateClient(name);

using IDisposable subscription = ((IObservable<Error>)client).Subscribe(this);

using IAdminClient adminClient = client.CreateDependentAdminClient();

await adminClient
.DescribeClusterAsync(new DescribeClusterOptions
{ RequestTimeout = context.Registration.Timeout })
.ConfigureAwait(false);

if (this._errors.Count > 0)
{
status = HealthStatus.Degraded;
description += string.Join(", ", this._errors) + ".";
}
else
{
description += "OK.";
}
}
catch (Exception e)
{
status = context.Registration.FailureStatus;

if (this._errors.Count > 0)
{
description += string.Join(", ", this._errors) + ".";
}
else
{
description += $"{e.Message}.";
}
}
}

if (options.SkipSchemaRegistry)
{
description += " SchemaRegistry: check skipped.";
}
else
{
try
{
if (this._clusterOptionsMonitor.Get(name).SchemaRegistryConfig.Any())
{
ISchemaRegistryClient sr = this._kafkaFactory.GetOrCreateSchemaRegistryClient(name);
await sr.GetCompatibilityAsync().ConfigureAwait(false);
description += " SchemaRegistry: OK.";
}
else
{
description += " SchemaRegistry: not configured.";
}
}
catch (Exception e)
{
status = context.Registration.FailureStatus;
description += $" SchemaRegistry: {e.Message}.";
}
}

#pragma warning restore CA1031
}

return new HealthCheckResult(status, description);
}

public void OnNext(Error value)
{
this._errors.Add(value);
}

public void OnError(Exception error)
{
}

public void OnCompleted()
{
this._errors.Clear();
}
}
28 changes: 28 additions & 0 deletions src/Epam.Kafka.HealthChecks/ClusterHealthCheckOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright © 2024 EPAM Systems

using Microsoft.Extensions.Options;

namespace Epam.Kafka.HealthChecks;

/// <summary>
/// Options for kafka cluster health checks.
/// </summary>
public sealed class ClusterHealthCheckOptions : IOptions<ClusterHealthCheckOptions>
{
/// <summary>
/// Whether schema registry check should be skipped. Default <code>false</code>.
/// </summary>
public bool SkipSchemaRegistry { get; set; }

/// <summary>
/// Whether admin client check should be skipped. Default <code>false</code>.
/// </summary>
public bool SkipAdminClient { get; set; }

/// <summary>
/// Whether cluster will be checked even if was not used at least 1 time by default <see cref="IKafkaFactory"/> implementation. Default <code>false</code>.
/// </summary>
public bool IncludeUnused { get; set; }

ClusterHealthCheckOptions IOptions<ClusterHealthCheckOptions>.Value => this;
}
20 changes: 20 additions & 0 deletions src/Epam.Kafka.HealthChecks/Epam.Kafka.HealthChecks.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net6.0;netstandard2.0;net462</TargetFrameworks>
<Description>Health check extensions for [Epam.Kafka](https://www.nuget.org/packages/Epam.Kafka) package.</Description>
</PropertyGroup>


<ItemGroup Condition="'$(TargetFramework)' == 'net6.0' or '$(TargetFramework)' == 'net462' or '$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="6.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Epam.Kafka\Epam.Kafka.csproj" />
</ItemGroup>
</Project>
Loading

0 comments on commit a15a4eb

Please sign in to comment.