Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Alirexaa
Copy link
Contributor

@Alirexaa Alirexaa commented Sep 18, 2024

Description

Adds WaitFor support for Qdrant

Related: #5645

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?
    • Yes
      • Link to aspire-docs issue:
    • No
Microsoft Reviewers: Open in CodeFlow

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Sep 18, 2024
@davidfowl davidfowl requested review from mitchdenny and sebastienros and removed request for radical and sebastienros September 18, 2024 18:35
ConnectionString = connectionString
};

if (connectionBuilder.ContainsKey("Endpoint") && Uri.TryCreate(connectionBuilder["Endpoint"].ToString(), UriKind.Absolute, out var serviceUri))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this hasn't been done anywhere else but maybe we could start using TryGetValue to save a lookup. Aspire will be so much faster after that ;)

Suggested change
if (connectionBuilder.ContainsKey("Endpoint") && Uri.TryCreate(connectionBuilder["Endpoint"].ToString(), UriKind.Absolute, out var serviceUri))
if (connectionBuilder.TryGetValue("Endpoint", out var endpoint) && Uri.TryCreate(endpoint.ToString(), UriKind.Absolute, out var serviceUri))

var factory = sp.GetRequiredService<IHttpClientFactory>();
var client = factory.CreateClient();
client.BaseAddress = endpoint;
if (key is not null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it technically possible that this client has any default headers coming from other configuration?

Suggested change
if (key is not null)
if (key is not null && !client.DefaultRequestHeaders.Contains("Api-Key"))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used named clients, so we don't need this.

@sebastienros
Copy link
Member

Digging a little more into the HttpClient usage here, I wonder if it would be better to resolve it in CheckHealthAsync instead and dispose it in this same method to follow a better IHttpClientFactory pattern instead of keeping a long-lived instance around. And then the named client could be configured on registration like this:

builder.Services.AddHttpClient(
    "qdrant-healthchecks",
    client =>
    {
        // Set the base address of the named client.
        client.BaseAddress = ...;

        client.DefaultRequestHeaders.Add("Api-Key", ...)
    });

@Alirexaa
Copy link
Contributor Author

Digging a little more into the HttpClient usage here, I wonder if it would be better to resolve it in CheckHealthAsync instead and dispose it in this same method to follow a better IHttpClientFactory pattern instead of keeping a long-lived instance around. And then the named client could be configured on registration like this:

builder.Services.AddHttpClient(
    "qdrant-healthchecks",
    client =>
    {
        // Set the base address of the named client.
        client.BaseAddress = ...;

        client.DefaultRequestHeaders.Add("Api-Key", ...)
    });

We haven't base address before application start, so we can't use ServiceCollection to add named client.
We subscribe ConnectionStringAvailableEvent to get base address and in this step we can't add service in ServiceCollection

@davidfowl
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mitchdenny
Copy link
Member

@Alirexaa we are looking to snap a branch for .NET Aspire 9.0 at the end of this week? Did you have a chance to look at @davidfowl's feedback on http factory?

}

var factory = sp.GetRequiredService<IHttpClientFactory>();
var client = factory.CreateClient("qdrant-healthchecks");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make sure that this works with multiple Qdrant instances.

@Alirexaa
Copy link
Contributor Author

@Alirexaa we are looking to snap a branch for .NET Aspire 9.0 at the end of this week? Did you have a chance to look at @davidfowl's feedback on http factory?

I will look.

@davidfowl davidfowl added this to the 9.0 milestone Sep 30, 2024
@davidfowl davidfowl added the area-integrations Issues pertaining to Aspire Integrations packages label Sep 30, 2024
@davidfowl davidfowl changed the title WaitFor for Qdrant WaitFor: Add health checks for Qdrant Sep 30, 2024
@mitchdenny mitchdenny mentioned this pull request Oct 1, 2024
15 tasks
@mitchdenny
Copy link
Member

Replacing with #6044 with a few minor tweaks. I couldn't push to your branch for some reason.

@mitchdenny mitchdenny closed this Oct 1, 2024
@Alirexaa Alirexaa deleted the qdrant-waitfor branch October 1, 2024 05:50
@github-actions github-actions bot locked and limited conversation to collaborators Oct 31, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-integrations Issues pertaining to Aspire Integrations packages community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants