hashicorp / consul

Consul is a distributed, highly available, and data center aware solution to connect and configure applications across dynamic, distributed infrastructure.
https://www.consul.io
Other
28.26k stars 4.41k forks source link

Parameter to remove end-of-line Spaces #9454

Closed pangpang20 closed 3 years ago

pangpang20 commented 3 years ago

Feature Description

When I used Consul Key/Value to config my configuration files, I hope that there is a function to remove end-of-line spaces. This feature is very important, especially when you accidentally configure the port, if you configure a space after the port, you will not be able to connect to Consul.

Use Case(s)

For example, when I have the following configuration file: key: test/test01:prod/data value: server.port=28080 (note: there is a space at the end) spring.cloud.consul.discovery.health-check-interval=10s spring.cloud.consul.discovery.port=28080 ... and other parameters

I will get the following error message in my application: Caused by: java.lang.IllegalArgumentException: Consul service ids must not be empty, must start with a letter, end with a letter or digit, and have as interior characters only letters, digits, and hyphen: dap-index:172.16.1.124:28080 at org.springframework.cloud.consul.serviceregistry.ConsulAutoRegistration.normalizeForDns(ConsulAutoRegistration.java:178) ~[spring-cloud-consul-discovery-2.1.5.RELEASE.jar!/:2.1.5.RELEASE] at org.springframework.cloud.consul.serviceregistry.ConsulAutoRegistration.getInstanceId(ConsulAutoRegistration.java:172) ~[spring-cloud-consul-discovery-2.1.5.RELEASE.jar!/:2.1.5.RELEASE]


This error message is clear, but it is not easy to find the problem because the space after server.port is not easily detected.

jsosulska commented 3 years ago

Hi @pangpang20

Thanks for posting. Unfortunately, I was not able to replicate this. It sounds like it could potentially be an issue with how spring-cloud-consul sets up and inserts the data into the KV. Consul KV simply stores what is inserted in it, so if the original data submitted contains a whitespace, Consul KV will preserve that. Trying to add additional functionality to "parse" the content of the value and make opinionated changes is hard to maintain moving forward.

Feel free to reach out on our Discuss Forums with your questions or issues. Our community is large, kind, and filled with a variety of users, so maybe others who use spring-cloud-consul could provide you with their experiences and answers as well.

Happy coding!