Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/Weaviate.Client.Tests/Integration/TestAuth.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
namespace Weaviate.Client.Tests.Integration;

using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;
using Weaviate.Client;
using Xunit;
Expand Down Expand Up @@ -76,11 +74,9 @@ public async Task TestNoAuthProvided()
{
Assert.True(await IsAuthEnabled($"localhost:{OKTA_PORT_CC}"));

var client = Connect.Local(hostname: "localhost", restPort: OKTA_PORT_CC);

await Assert.ThrowsAnyAsync<WeaviateServerException>(async () =>
var client = Assert.ThrowsAny<WeaviateServerException>(() =>
{
await client.Collections.List().ToListAsync(TestContext.Current.CancellationToken);
Connect.Local(hostname: "localhost", restPort: OKTA_PORT_CC);
});
}

Expand Down
4 changes: 4 additions & 0 deletions src/Weaviate.Client.Tests/Integration/_Integration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ protected static bool VersionIsInRange(

protected bool ServerVersionIsInRange(string minimumVersion, string? maximumVersion = null)
{
if (_weaviate.WeaviateVersion == null)
{
return false;
}
return VersionIsInRange(_weaviate.WeaviateVersion, minimumVersion, maximumVersion);
}

Expand Down
31 changes: 26 additions & 5 deletions src/Weaviate.Client.Tests/Unit/TestWellKnown.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Weaviate.Client;
using Xunit;
using System.Text;
using System.Text.Json;
using Weaviate.Client.Rest;

namespace Weaviate.Client.Tests.Unit;

Expand All @@ -24,6 +22,29 @@ protected override Task<HttpResponseMessage> SendAsync(
CancellationToken cancellationToken
)
{
// Intercept requests to the Meta endpoint and return a dummy response
if (
request.RequestUri != null
&& request.RequestUri.AbsolutePath.EndsWith(WeaviateEndpoints.Meta())
&& request.Method == HttpMethod.Get
)
{
var dummyMeta = new
{
hostname = "http://localhost:8080",
version = "1.28.0",
modules = new { },
grpcMaxMessageSize = 10485760UL,
};

var json = JsonSerializer.Serialize(dummyMeta);
var content = new StringContent(json, Encoding.UTF8, "application/json");

return Task.FromResult(
new HttpResponseMessage(HttpStatusCode.OK) { Content = content }
);
}

Requests.Add(request);
return Task.FromResult(_responder(request));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Weaviate.Client/CollectionClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public partial class CollectionClient
{
public const uint ITERATOR_CACHE_SIZE = 100;

public System.Version WeaviateVersion => _client.WeaviateVersion;
public System.Version? WeaviateVersion => _client.WeaviateVersion;

private readonly WeaviateClient _client;

Expand Down
2 changes: 1 addition & 1 deletion src/Weaviate.Client/Models/MetaInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public struct MetaInfo
public string Hostname { get; set; }
public System.Version Version { get; set; }
public Dictionary<string, object> Modules { get; set; }
public int GrpcMaxMessageSize { get; set; }
public ulong? GrpcMaxMessageSize { get; set; }

public static Version? ParseWeaviateVersion(string versionString)
{
Expand Down
33 changes: 20 additions & 13 deletions src/Weaviate.Client/WeaviateClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.Extensions.Logging;
using Weaviate.Client.Grpc;
using Weaviate.Client.Rest;
using Weaviate.Client.Rest.Dto;

[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Weaviate.Client.Tests")]

Expand Down Expand Up @@ -118,7 +119,9 @@ public partial class WeaviateClient : IDisposable

return new Models.MetaInfo
{
GrpcMaxMessageSize = meta?.GrpcMaxMessageSize ?? 0,
GrpcMaxMessageSize = meta?.GrpcMaxMessageSize is not null
? Convert.ToUInt64(meta?.GrpcMaxMessageSize)
: null,
Hostname = meta?.Hostname ?? string.Empty,
Version =
Models.MetaInfo.ParseWeaviateVersion(meta?.Version ?? string.Empty)
Expand All @@ -130,32 +133,33 @@ public partial class WeaviateClient : IDisposable
};
}

private System.Version? _weaviateVersion;
private readonly SemaphoreSlim _versionSemaphore = new(1, 1);
private Models.MetaInfo? _metaCache;

public async Task<System.Version> GetWeaviateVersionAsync()
private async Task<Models.MetaInfo?> GetMetaCached()
{
if (_weaviateVersion != null)
return _weaviateVersion;
if (_metaCache != null)
return _metaCache.Value;

await _versionSemaphore.WaitAsync();
await _metaCacheSemaphore.WaitAsync();
try
{
if (_weaviateVersion == null)
if (_metaCache == null)
{
var meta = await GetMeta();
_weaviateVersion = meta.Version;
_metaCache = meta;
}
}
finally
{
_versionSemaphore.Release();
_metaCacheSemaphore.Release();
}

return _weaviateVersion;
return _metaCache.Value;
}

public System.Version WeaviateVersion => GetWeaviateVersionAsync().GetAwaiter().GetResult();
private readonly SemaphoreSlim _metaCacheSemaphore = new(1, 1);
public Models.MetaInfo? Meta => GetMetaCached().GetAwaiter().GetResult();
public System.Version? WeaviateVersion => Meta?.Version;

/// <summary>
/// Returns true if the Weaviate process is live.
Expand Down Expand Up @@ -267,11 +271,14 @@ public WeaviateClient(
}

RestClient = new WeaviateRestClient(Configuration.RestUri, httpClient);

GrpcClient = new WeaviateGrpcClient(
Configuration.GrpcUri,
wcdHost,
_tokenService,
Configuration.Headers
Configuration.Headers,
null,
Meta?.GrpcMaxMessageSize ?? null
);

Cluster = new ClusterClient(RestClient);
Expand Down
10 changes: 9 additions & 1 deletion src/Weaviate.Client/gRPC/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public WeaviateGrpcClient(
string? wcdHost,
ITokenService? tokenService,
Dictionary<string, string>? headers = null,
ILogger<WeaviateGrpcClient>? logger = null
ILogger<WeaviateGrpcClient>? logger = null,
ulong? maxMessageSize = null
)
{
_logger =
Expand All @@ -50,6 +51,13 @@ public WeaviateGrpcClient(

var options = new GrpcChannelOptions();

if (maxMessageSize != null)
{
options.MaxReceiveMessageSize = (int)maxMessageSize;

options.MaxSendMessageSize = (int)maxMessageSize;
}

if (tokenService != null)
{
var credentials = CallCredentials.FromInterceptor(
Expand Down