-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Ocelot.Provider.Consul: The GetDownstreamHost
method inefficiently checks the node object
#2203
Comments
I have a concern, guessing you didn't read the whole document where you can find the ready solution for curious developers and users. So please read carefully the following feature documentation:
Finally, this overridden method will help you: protected override string GetDownstreamHost(ServiceEntry entry, Node node) => entry.Service.Address; P.S. I recommend reading our official Release Notes for v23.3, where we announced a new feature:
@pkutsch Anything else? |
Well... Please note that since version 13.5.2 and #909, when the node name became the host name as Ocelot's best practice, now since v23.3, we configure Consul service building by the proposed #2067 feature aka Ocelot/src/Ocelot.Provider.Consul/DefaultConsulServiceBuilder.cs Lines 96 to 97 in da9d6fa
I know this check is not ideal and looks strange. But what do you propose? Have an idea in mind? What are the best practices for organizing Consul services into a node group? I have the following idea, which makes real sense: - => node != null ? node.Name : entry.Service.Address;
+ => !string.IsNullOrEmpty(node?.Name) && !node.Name.Equals("default") ? node.Name : entry.Service.Address; So, my idea is to identify more practical use cases when DevOps engineers organize services into a Consul node and let this be a best practice in Ocelot integration with Consul.
Yes, please! But I guess this PR will be a micro one: we are limited to the re-implementation of the virtual |
GetDownstreamHost
method inefficiently checks the node object
@pkutsch Where are you? |
@pkutsch @ggnaegi What is the default name of the single node group in Consul after installation? I mean, the default settings. Is this name empty, or does it have some predefined value? I agree that users (not C# developers) probably want a JSON option in P.S.I am not interested in engaging in any discussions here. I believe we cannot enhance further in this context. The DNS probe check should be delivered in #2208. This issue will be closed because the author has received the desired answer with the actual C# recipe |
Expected Behavior:
Ocelot.Provider.Consul works once properly configured as described at:
https://ocelot.readthedocs.io/en/latest/features/servicediscovery.html
Actual Behavior:
Posting to API Gateway with Ocelot configured throws Bad Gateway 502 error. Note that without Ocelot.Provider.Consul configured, the API Gateway works without any issue i.e. if 'DownstreamHostAndPorts' is used and no 'ServiceDiscoveryProvider' is configured in ocelot.json.
Performed VS debugging and found that the cause was at line 97 of DefaultConsulServiceBuilder.cs in Ocelot.Provider.Consul project:
=> node != null ? node.Name : entry.Service.Address;
Was able to fix the exception by replacing node.Name with node.Address.
Thought of editing the code and sending a pull request, but since I do not understand why there is a null reference check on the node object (being new to both Ocelot and Consul), I decided better to submit an issue instead, so someone with more knowledge regarding this code logic can apply a proper fix.
Versions:
.Net Core 8
Ocelot 23.3.6 (nuget package)
Ocelot.Provider.Consul 23.3.6 (nuget package)
Consul 1.20.0
Windows 10 (os of development environment)
The text was updated successfully, but these errors were encountered: