Skip to content

Add Http Service Resource#1030

Merged
mitchdenny merged 7 commits into
microsoft:mainfrom
Kahbazi:kahbazi/AddHttpService
Dec 9, 2023
Merged

Add Http Service Resource#1030
mitchdenny merged 7 commits into
microsoft:mainfrom
Kahbazi:kahbazi/AddHttpService

Conversation

@Kahbazi

@Kahbazi Kahbazi commented Nov 24, 2023

Copy link
Copy Markdown
Contributor

I tried my best to understand the structure of the project and I successfully add a http service reference and get it working but
it needs clean-up. Also, I'm not sure if I use the correct annotation.

I have couple of questions:

  • What annotation should I use to expose the http service?
  • What manifest should look like for http service?
  • Should we able to determine the http version of the service?
  • Is there any public API that I should Add?
  • Which public API should I use for the sample and where to show it in UI?

I will add the tests once the implementation gets approved.

Fixes #775

@ghost ghost added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label Nov 24, 2023
Comment thread src/Aspire.Hosting/HttpService/IHttpServiceResource.cs Outdated
Comment thread src/Aspire.Hosting/HttpService/HttpServiceBuilderExtensions.cs Outdated
@Kahbazi

Kahbazi commented Nov 27, 2023

Copy link
Copy Markdown
Contributor Author

@DamianEdwards @davidfowl Since this is planned to be in Preview2, could I have this PR reviewed please, I have free time on Thursday and Friday and I would like to finish this issue in time.

@davidfowl davidfowl requested a review from mitchdenny November 28, 2023 05:39
Comment thread src/Aspire.Hosting/HttpService/HttpServiceBuilderExtensions.cs Outdated
Comment thread src/Aspire.Hosting/HttpService/HttpServiceResource.cs Outdated
Comment thread src/Aspire.Hosting/Extensions/ResourceBuilderExtensions.cs Outdated
@Kahbazi Kahbazi force-pushed the kahbazi/AddHttpService branch from e8e6735 to 330f315 Compare November 30, 2023 15:41
@davidfowl

Copy link
Copy Markdown
Contributor

Can you generate the manifest for the app you modified (we'll likely undo that change before this gets merged).

@davidfowl

Copy link
Copy Markdown
Contributor

Looking at this PR I wonder why we even need HttpServiceResource. Maybe WithReference taking a URI is all we need. In the manifest, we would just hard code the url. Thoughts?

cc @mitchdenny @DamianEdwards

Comment thread samples/eShopLite/AppHost/Program.cs Outdated
@@ -1,5 +1,7 @@
var builder = DistributedApplication.CreateBuilder(args);

var petstore = builder.AddHttpService("petstore", new Uri("https://petstore.swagger.io"));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Any thoughts on what public API should be in the sample?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

None. We should bake write a test instead.

@davidfowl

Copy link
Copy Markdown
Contributor

Let’s treat this like it’s not a custom resource at all. It’s just a way to reference and environment variable in the format service discovery expects

@@ -0,0 +1,29 @@
{

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@davidfowl Here's the new manifest.json. I don't have docker on my machine so the manifest is only for the front end app and the http service. I will redo the program.cs change before the merge.

@Kahbazi

Kahbazi commented Dec 1, 2023

Copy link
Copy Markdown
Contributor Author

Let’s treat this like it’s not a custom resource at all. It’s just a way to reference and environment variable in the format service discovery expects

@davidfowl Do you mean like this?

builder.AddProject<Projects.MyFrontend>("frontend")
    .WithReference("petstore", new Uri("https://petstore.swagger.io"));

@davidfowl

Copy link
Copy Markdown
Contributor

Yep

"env": {
"OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES": "true",
"OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EVENT_LOG_ATTRIBUTES": "true",
"services__petstore": "https://petstore.swagger.io/"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm in favor of having the http service as a resource itself and I wanted to share my thoughts. If I understand correctly, we have to use manifest to do our own deployment. Having a specific resource for Http Service gives us the benefit to identify the external http services in order to allow firewall for those addresses.

Also we use different http service address in development and production for external services, and if multiple project reference that http service, I guess it will be easier to change the manifest from the http resource rather than env of multiple projects.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What would a deployment tool do this with this resource?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

To be fair I don't see any scenario that not having the http resource have any limitations in the deploy but having it at the resource gives me a view of all my applications reference and dependencies and I can easily set the http service URL in one place instead of possibly multiple environment variables of my projects.

If I understand the Redis resource correctly, I can argue that the Redis behaves the same when a connection string is presented. In this case I don't want the deploy to setup a new instance of Redis, I want my app to connect to an existing Redis, right?

Comment thread src/Aspire.Hosting/Extensions/ResourceBuilderExtensions.cs
@Kahbazi Kahbazi marked this pull request as ready for review December 1, 2023 16:27
@DamianEdwards

Copy link
Copy Markdown
Member

Let’s treat this like it’s not a custom resource at all. It’s just a way to reference and environment variable in the format service discovery expects

Not sure about this yet. This would introduce overloads of WithReference that take primitives other than other resources, yes? I'm a bit concerned that without using a resource type it will muddy the line of when something should be a resource or not. E.g. how would we represent the different between a reference to an HTTP service vs. a gRPC service, which likely require different configuration by the tool reading the manifest?

@Kahbazi

Kahbazi commented Dec 6, 2023

Copy link
Copy Markdown
Contributor Author

@davidfowl @DamianEdwards @mitchdenny Any other feedback that should be done in the PR?

@davidfowl

Copy link
Copy Markdown
Contributor

Undo the sample changes and this will be good to go.

@mitchdenny mitchdenny merged commit f7bd7c2 into microsoft:main Dec 9, 2023
@mitchdenny

Copy link
Copy Markdown
Member

Merged. @davidfowl do you want to take this in preview 2?

@davidfowl

Copy link
Copy Markdown
Contributor

Yep

@Kahbazi Kahbazi deleted the kahbazi/AddHttpService branch December 9, 2023 07:16
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for expressing existing external HTTP services as resources in the hosting project

4 participants