Skip to content

Commit 1c870cc

Browse files
authored
Add Health check (#71)
1 parent 1957051 commit 1c870cc

3 files changed

Lines changed: 48 additions & 1 deletion

File tree

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ protos
1111

1212
*.sln.DotSettings.user
1313
output
14+
.vs

‎src/Qdrant.Client/QdrantClient.cs‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Runtime.InteropServices;
22
using Google.Protobuf.Collections;
3+
using Grpc.Core;
34
using Microsoft.Extensions.Logging;
45
using Microsoft.Extensions.Logging.Abstractions;
56
using Qdrant.Client.Grpc;
@@ -93,7 +94,6 @@ private QdrantClient(
9394
_collectionsClient = grpcClient.Collections;
9495
_pointsClient = grpcClient.Points;
9596
_snapshotsClient = grpcClient.Snapshots;
96-
9797
_grpcTimeout = grpcTimeout;
9898
_logger = loggerFactory?.CreateLogger("Qdrant.Client") ?? NullLogger.Instance;
9999
}
@@ -4288,6 +4288,21 @@ public async Task<DeleteShardKeyResponse> DeleteShardKeyAsync(
42884288

42894289
#endregion Cluster management
42904290

4291+
/// <summary>
4292+
/// Asynchronously checks the health of the Qdrant service.
4293+
/// </summary>
4294+
/// The token to monitor for cancellation requests. The default value is <see cref="CancellationToken.None" />.
4295+
/// <returns>
4296+
/// A task that represents the asynchronous operation. The task result contains
4297+
/// a <see cref="HealthCheckReply"/> indicating the health status of the Qdrant service.
4298+
/// </returns>
4299+
/// <exception cref="RpcException">occurs when server is unavailable</exception>
4300+
public async Task<HealthCheckReply> HealthAsync(CancellationToken cancellationToken = default) =>
4301+
await _grpcClient.Qdrant.HealthCheckAsync(
4302+
new HealthCheckRequest(),
4303+
deadline: _grpcTimeout == default ? null : DateTime.UtcNow.Add(_grpcTimeout),
4304+
cancellationToken: cancellationToken).ConfigureAwait(false);
4305+
42914306
private static void Populate<T>(RepeatedField<T> repeatedField, ReadOnlyMemory<T> memory)
42924307
{
42934308
if (MemoryMarshal.TryGetArray(memory, out var segment) &&
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using FluentAssertions;
2+
using Grpc.Core;
3+
using Xunit;
4+
5+
namespace Qdrant.Client
6+
{
7+
public class HealthCheckTests : IClassFixture<QdrantFixture>
8+
{
9+
private readonly QdrantClient _client;
10+
11+
public HealthCheckTests(QdrantFixture qdrantFixture) => _client = qdrantFixture.CreateClient();
12+
13+
[Fact]
14+
public async Task Server_Should_Be_Healthy()
15+
{
16+
var response = await _client.HealthAsync();
17+
18+
response.Title.Should().NotBeNullOrEmpty();
19+
response.Version.Should().NotBeNullOrEmpty();
20+
}
21+
[Fact]
22+
public async Task Server_Should_Be_UnHealthy()
23+
{
24+
var client = new QdrantClient("localhost", 9999);
25+
;
26+
27+
await Assert.ThrowsAsync<RpcException>(async () => await client.HealthAsync());
28+
}
29+
30+
}
31+
}

0 commit comments

Comments
 (0)