Spring Cloud Configuration - auto-enable Refresh Endpoint & Git monitoring - spring-boot

Questions
I am starting to learn Spring Cloud starting with Spring Config. There are two basic questions as I have to get me onto the next step in my learning process (moving on to Service Discovery via Consul).
How do I auto-enable the /refresh endpoint to POST to?
Is there a way to automatically monitor for updates in Git?
For #1 I implemented my own #RestController/#RequestMapping but none of the tutorials I was following mentioned that. I checked my Maven configuration and it matches what the samples were providing but it's not popping up.
I found a post for the second question here:
spring cloud auto refresh config server property. I was just wondering if there were any updates since November 2015 on this.
Both of these things seem to be exceedingly handy and will be directly intertwined with my Consul learning as I can push configuration updates automatically to everyone that is registered as a service. Once I get there I can work on the restarts too, but that is later.
Updates
I got an answer to #1. I had botched my dependencies configuration in my Maven module. After triple-checking the configuration it turns out it was just pilot error. Still working on #2, though - if anyone has any updates it would be appreciated.

For #1, Spring cloud config intrdouced the #RefreshScope annotation which will expose the /refresh endpoint (over HTTP or JMX)
For #2, after '/refresh', spring cloud config will take the latest git commit, For the config changes, essentially there are two ways, 1) pull the changes 2) push the changes, spring cloud bus approach is based on the rabbitmq to push the config chagnes.
Reference
Refresh Scope

For GIT updates try to go through this documentation spring-cloud-config-push-notifications and do not forget to install ngrock. Also if you just need to refresh on git commit then you do not even need cloud-bus project just config should be enough. Hope this helps.

Related

How to manage rollbacks on spring cloud config

I have a spring cloud config repository, a server and a client. Originally the functionality expected is to be able to reload properties without stopping the running service. Now if there is a rollback on the client's end, how do i ensure that it picks up an older version of the property file?
I've tried specifying the spring.cloud.config.label value but if i put in a specific tag or version, wouldn't i lose the intended functionality of the client tracking changes on the repo?

Clone only specific path - Spring Cloud Config Server

Is there any way by chance to make spring config server to clone only specific path instead of whole git repo? When I'm running it on production I may not want my entire code base repository to be cloned to some location as it is always a risk. I've done my research and couldn't figure out ways to clone only specific paths of git repo.
One solution is to host the configurations in a seperate repo. But that would defeat the purpose of one code many deploys suggestion of 12factor.net.
Another possibility is to copy the properties into config server's classpath and then to use native profile to load them. But this would defeat the purpose of Spring ConfigServer.
Also kindly do clarify What would be the best way to run spring config server on a production?
You should be separating your code base from your configuration settings.
Repo 1: Your App Code
Repo 2: Your Spring Cloud Config Server Code
Repo 3: Your configuration settings
When you're deploying, you're deploying the code. Not the configuration. A configuration change should not require a new deployment. A new deployment might require an updated configuration change, but the two are generally decoupled.
Configuration can be dynamically updated while code is running. This is completely separate from updating code and deploying the app. That's the whole point of externalized configuration.
TL;DR: You're looking at "one code many deploys" wrong. Configuration is externalized.
I took this straight from 12factor.net
Apps sometimes store config as constants in the code. This is a violation of twelve-factor, which requires strict separation of config from code. Config varies substantially across deploys, code does not.
Even though you are no longer storing them as constants but still in the same repository is not enough separation from the code. Use a separate repository for configurations.

Spring Cloud Config fails to update properties dynamically

I have a Camel Spring Boot application where I am printing the value of a property which is set using Spring Cloud Config Server (via Git commit id plugin). The issue is that the value of the property in Camel application is not updated once the value is committed to Git. I have to restart the Camel application which fails the purpose of Spring Cloud Config server. Please note that we are using Git file system in our local machine.
The name of the properties file is CamelSpringBootSample-dev.properties.
As soon as I commit, the config server publishes the updated value at the endpoint on refresh:
http://localhost:8888/CamelSpringBootSample/dev
I have also made the Camel application end point available at:
http://localhost:8181/actuator/env
Here the value of the property is not updated on refresh. However, if I restart the Camel application, the value is reflecting.
The source code for all the three projects are uploaded in github.com.
The config server: https://github.com/sreejeshraj/config-server
The Camel client project (which uses the config server to configure itself): https://github.com/sreejeshraj/camel-config-server
Please do not get misled by the repository name camel-config-server. This is the client of config server, but I accidentally named it incorrectly, apologies.
The local git repository where the configuration properties are stored: https://github.com/sreejeshraj/Git-Config
Please note that I have used the annotation #RefreshScope in my Spring bean component class.
Can you please help me with this? Thanks in advance.
You have to set:
management.endpoints.web.exposure.include=refresh
in bootstrap.properties or bootstrap.yml.
and trigger the /actuator/refresh endpoint.
See #RefreshScope and /refresh not working
Note that as said in the comments, Camel does not update its values when a Spring beans is refreshed and there is no plan to implement this feature. (https://issues.apache.org/jira/browse/CAMEL-13892). You probably could find a solution through Spring Cloud Bus.
As #ortomala-lokni already pointed out, you need to refresh your configuration consumers after an update happened.
If you want a centralized solution for this task (for refreshing many components automatically), take a look at Spring Cloud Bus.
This page gives a quite good overview about the subject.
I had a situation where I had both application.properties and bootstrap.properties file in my client. I that case you should specify spring.application.name and spring.cloud.config.server.git.uri inside bootstrap.yml. I didn't refresh properties having spring.application.name inside applicaiton.properties.

Git : managing the config files on the master/staging

This may be obvious to some and I have been trying to maintain config files for the spring application. I have spring.xml and springpath.xml so the content is different for each production and dev environment.
When I merge master to my dev branch that merges nicely and then commit the code. Create a pull request for GitHub, at this stage both config files get merged and I end up having dev config files into the master branch too, which is bit annoying.
Is there a better to handle this, please?
thanks
I have solved similar issue by using the Spring Cloud Config, where i have different configuration is maintained for development, staging and production.
All the config are maintained in git (not Github; but definitely not a killer difference). Spring Cloud Config server and config client can help you to get the configuration from git server based on profile that you supply when running the app.
Note:
Since i am using Spring boot, things were really smooth and easy.

Microservices configuration server

It's well understood that in a microservices architecture, configuration must be externalized.
Tools like zookeeper, etcd or consul are excellent options to store that configuration. However a new layer on top of those services is required in order to provide new functionalities that are fundamental in a configuration server. Ex. versioning; change history; "draft" / published configuration, etc...
I've found spring config server, which is an interesting project and addresses all these concerns using git for handling the above mentioned requirements. However, I'd like avoid using git due to additional required setup. ex. replication, etc...
Do you know any other options other then spring config server?
Our findings have been the same - configuration must be externalized and the notion of "code as config" through the lessons learned from implementing time consuming Puppet/Chef systems.
We're building a microservices and API orchestration system at LunchBadger. We also uses git - but it's encapsulated into our system that we provide as a service, because we want configuration to be externalized AND dovetail into whatever CI/CD pipeline infrastructure you may have or are looking to adopt. We also provide visualization on top of microservices and APIs so that you can get an idea of the topology of your once monolithic app in the form of many microservices.
You can look into Microconfig.IO and it's Microconfig Server. It's deployed via docker and configured via 3 env vars. It still use git repo for config storage, but that's actually a proper way to go. As a bonus you get a powerful templating functionality designed explicitly to handle app configuration

Resources