microsoft / service-fabric-aspnetcore

This repo contains ASP.NET Core integration for Service Fabric Reliable Services.
Other
152 stars 49 forks source link

PathBase not updated #37

Closed wasabii closed 6 years ago

wasabii commented 6 years ago
            yield return new ServiceInstanceListener(serviceContext =>
                new KestrelCommunicationListener(
                    serviceContext,
                    (url, listener) =>
                        new WebHostBuilder()
                            .UseKestrel()
                            .ConfigureServices(services => services.AddTransient(provider => scope.Resolve<WebStartup>()))
                            .UseContentRoot(Directory.GetCurrentDirectory())
                            .UseStartup<WebStartup>()
                            .UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.UseReverseProxyIntegration)
                            .Build()));

I would expect UseServiceFabricIntegration (and the eventual ServiceFabricReverseProxyMiddleware it inserts) to set up PathBase correctly. However, its always empty. So, path ends up being /foo/bar.... and components end up referring to the incorrect path.

wasabii commented 6 years ago

So after some more thinking, I think the default behavior of leaving PathBase blank is fine... in most cases, when you intend to put the SF reverse proxy behind yet another load balancer which itself has no prefix. But if you want to use the reverse proxy itself directly, then it doesn't quite work.

amanbha commented 6 years ago

Thanks @wasabii I will close this issue then.

wasabii commented 6 years ago

I wasn't really quite done.... Sorry about that. The whole "in most cases" thing needed to be expanded upon.

UseReverseProxyIntegration strips out the /AppName/SvcName components of the path just fine. But, it doesn't make them available from that point on. So, when further steps try to compose a URL, they end up directing to the wrong place.

Adding in UseUniqueServiceUrl will then add a new PathBase: with /partitionId/replicaId.

But there's no combination that seems to preserve /AppName/SvcName, for both reverse proxy and unique service urls for stateless single instance services.

The "it works in most cases" would mean using the reverse proxy, behind a load balancer, where each service is getting it's own root URL anyways.

I'll add a new issue, since I now have a more specific ask.

@amanbha

amanbha commented 6 years ago

UseReverseProxyIntegration doesn't strip out /AppName/SvcName, it would be done by the ReverseProxy so by the time call comes to these middlewares, the path will not have it. All this ReverseProxy middleware does is adds a specific header to response for 4o4 from the service.

example: lets say a service with name fabric:/MyApp/MyService is deployed, it has a route called api/values With UseUniqueServiceUrl, url for the endoiint reported to SF runtime is ( http://machinename:port/partitionId/repilcaId/guid

To call it directly, client will resolve the service partition and send the request as http://machinename:port/partitionId/repilcaId/guid/api/values which would come to the ServiceFabricMiddleware and after adjusting the path and pathbase, call will end up at /api/values route.

To call it with ReverseProxy, call will be made as: http://:Port/MyApp/MyService/api/values?PartitionKey=&PartitionKind= ReverseProxy (not the ReverseProxyMiddleware) will resolve the service for the specified partition and send the request to http://machinename:port/partitionId/repilcaId/guid/api/values which would come to the ServiceFabricMiddleware and after adjusting the path and pathbase, call will end up at /api/values route

So it doesn't seem like an issue, I hope that answers your question.

amanbha commented 6 years ago

Thanks @wasabi. Sure, lets track on the new issue which you opened a little while ago, closing this one.