Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addressing port/endpoint issues on Qdrant #3422

Merged
merged 5 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion playground/Qdrant/Qdrant.AppHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

var builder = DistributedApplication.CreateBuilder(args);

var qdrant = builder.AddQdrant("qdrant")
var qdrant = builder.AddQdrant("qdrant", httpPort:5503)
.WithDataVolume("qdrant_data");

builder.AddProject<Projects.Qdrant_ApiService>("apiservice")
Expand Down
10 changes: 6 additions & 4 deletions src/Aspire.Hosting.Qdrant/QdrantBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,22 @@ public static class QdrantBuilderExtensions
/// <param name="builder">The <see cref="IDistributedApplicationBuilder"/>.</param>
/// <param name="name">The name of the resource. This name will be used as the connection string name when referenced in a dependency</param>
/// <param name="apiKey">The parameter used to provide the API Key for the Qdrant resource. If <see langword="null"/> a random key will be generated as {name}-Key.</param>
/// <param name="port">The host port of Qdrant database.</param>
/// <param name="gRpcPort">The host port of gRPC endpoint of Qdrant database.</param>
/// <param name="httpPort">The host port of REST endpoint of Qdrant database.</param>
/// <returns>A reference to the <see cref="IResourceBuilder{QdrantServerResource}"/>.</returns>
public static IResourceBuilder<QdrantServerResource> AddQdrant(this IDistributedApplicationBuilder builder,
string name,
IResourceBuilder<ParameterResource>? apiKey = null,
int? port = null)
int? gRpcPort = null,
int? httpPort = null)
{
var apiKeyParameter = apiKey?.Resource ??
ParameterResourceBuilderExtensions.CreateDefaultPasswordParameter(builder, $"{name}-Key", special: false);
var qdrant = new QdrantServerResource(name, apiKeyParameter);
return builder.AddResource(qdrant)
.WithImage(QdrantContainerImageTags.Image, QdrantContainerImageTags.Tag)
.WithHttpEndpoint(port: port, targetPort: QdrantPortGrpc, name: QdrantServerResource.PrimaryEndpointName)
.WithHttpEndpoint(port: port, targetPort: QdrantPortHttp, name: QdrantServerResource.RestEndpointName)
.WithHttpEndpoint(port: gRpcPort, targetPort: QdrantPortGrpc, name: QdrantServerResource.PrimaryEndpointName)
.WithHttpEndpoint(port: httpPort, targetPort: QdrantPortHttp, name: QdrantServerResource.RestEndpointName)
.WithEnvironment(context =>
{
context.EnvironmentVariables[ApiKeyEnvVarName] = qdrant.ApiKeyParameter;
Expand Down
10 changes: 8 additions & 2 deletions src/Aspire.Hosting.Qdrant/QdrantServerResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,23 @@ public QdrantServerResource(string name, ParameterResource apiKey) : base(name)
}

private EndpointReference? _primaryEndpoint;
private EndpointReference? _restEndpoint;

/// <summary>
/// Gets the parameter that contains the Qdrant API key.
/// </summary>
public ParameterResource ApiKeyParameter { get; }

/// <summary>
/// Gets the primary endpoint for the Qdrant database.
/// Gets the gRPC endpoint for the Qdrant database.
/// </summary>
public EndpointReference PrimaryEndpoint => _primaryEndpoint ??= new(this, PrimaryEndpointName);

/// <summary>
/// Gets the REST endpoint for the Qdrant database.
/// </summary>
public EndpointReference RestEndpoint => _restEndpoint ??= new(this, RestEndpointName);

/// <summary>
/// Gets the connection string expression for the Qdrant gRPC endpoint.
/// </summary>
Expand All @@ -46,5 +52,5 @@ public QdrantServerResource(string name, ParameterResource apiKey) : base(name)
/// </summary>
public ReferenceExpression RestConnectionStringExpression =>
ReferenceExpression.Create(
$"Endpoint={PrimaryEndpoint.Property(EndpointProperty.Scheme)}://{PrimaryEndpoint.Property(EndpointProperty.Host)}:6333;Key={ApiKeyParameter}");
$"Endpoint={RestEndpoint.Property(EndpointProperty.Scheme)}://{RestEndpoint.Property(EndpointProperty.Host)}:{RestEndpoint.Property(EndpointProperty.Port)};Key={ApiKeyParameter}");
}
3 changes: 2 additions & 1 deletion tests/Aspire.Hosting.Tests/Qdrant/AddQdrantTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public async Task QdrantClientAppWithReferenceContainsConnectionStrings()
public async Task VerifyManifest()
{
var appBuilder = DistributedApplication.CreateBuilder(new DistributedApplicationOptions() { Args = new string[] { "--publisher", "manifest" } } );
var qdrant = appBuilder.AddQdrant("qdrant");
var qdrant = appBuilder.AddQdrant("qdrant", httpPort:5503);

var serverManifest = await ManifestUtils.GetManifest(qdrant.Resource); // using this method does not get any ExecutionContext.IsPublishMode changes

Expand All @@ -198,6 +198,7 @@ public async Task VerifyManifest()
"scheme": "http",
"protocol": "tcp",
"transport": "http",
"port": 5503,
"targetPort": 6333
}
}
Expand Down