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

Add Http Service Resource #1030

Merged
merged 7 commits into from
Dec 9, 2023
Merged

Conversation

Kahbazi
Copy link
Member

@Kahbazi Kahbazi commented Nov 24, 2023

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

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label Nov 24, 2023
@Kahbazi
Copy link
Member Author

Kahbazi commented Nov 27, 2023

@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
Copy link
Member

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

@davidfowl
Copy link
Member

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

@@ -1,5 +1,7 @@
var builder = DistributedApplication.CreateBuilder(args);

var petstore = builder.AddHttpService("petstore", new Uri("https://petstore.swagger.io"));
Copy link
Member 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
Member

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
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

@@ -0,0 +1,29 @@
{
Copy link
Member 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
Copy link
Member Author

Kahbazi commented Dec 1, 2023

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
Member

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
Member 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
Member

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
Member 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?

@Kahbazi Kahbazi marked this pull request as ready for review December 1, 2023 16:27
@DamianEdwards
Copy link
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
Copy link
Member Author

Kahbazi commented Dec 6, 2023

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

@davidfowl
Copy link
Member

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

@mitchdenny mitchdenny merged commit f7bd7c2 into dotnet:main Dec 9, 2023
8 checks passed
@mitchdenny
Copy link
Member

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

@davidfowl
Copy link
Member

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