ThreeMammals / Ocelot

.NET API Gateway
https://www.nuget.org/packages/Ocelot
MIT License
8.39k stars 1.64k forks source link

Consul `Node.Name` might be a DNS name #2208

Open ggnaegi opened 2 days ago

ggnaegi commented 2 days ago

Expected Behavior / New Feature

The consul service discovery provider should check if the node.Name could be a DNS/Host Name, otherwise return the service url.

Actual Behavior / Motivation for New Feature

The consul service provider doesn't check if the node.Name is a host name. Depending on service discovery configuration, the node.Name might not be a host name.

https://developer.hashicorp.com/consul/docs/agent

Node name: This is a unique name for the agent. By default, this is the hostname of the machine, but you may customize it using the -node flag.

Steps to Reproduce the Problem

  1. Change the agent name, use something that is not related to the hostname.
  2. Try to use the Consul Service Discovery

related to: https://github.com/ThreeMammals/Ocelot/issues/2203, https://github.com/ThreeMammals/Ocelot/issues/954

raman-m commented 2 days ago

Adding an extra check for the DNS name could be a solution, providing some logic to protect Ocelot from careless DevOps engineers who might write whatever they want in the configs (in nodes). 😃 Gui, please note that an additional DNS probe for the node hostname will add 100+ milliseconds or even seconds to the request processing time, but we can cache the IP. But we could propose Boolean switcher of cache and entire DNS probe.

ggnaegi commented 2 days ago

@raman-m you right, I think we should foresee an option for that matter