How to manage rollbacks on spring cloud config - spring

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?

Related

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.

Spring Cloud Config without the server

The role of the Config Server while using Spring Cloud Config seems to be pretty dumb and hosting it seems to be an unnecessary overhead. Is there a way to get the Clients to directly read configs from the git repo?
You can let Spring Boot look at specific locations for the config files: https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html#boot-features-external-config-application-property-files
If you set this location to your cloned git repo (checked out on the branch you need) and solve the update from the origin repository, this might work.
It is achievable via the embedding config server approach
Do refer to Embedding The Config Server section
If you want to read the configuration for an application directly from the backend repository (instead of from the config server), you basically want an embedded config server with no endpoints. You can switch off the endpoints entirely by not using the #EnableConfigServer annotation (set spring.cloud.config.server.bootstrap=true).

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

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.

spring boot cloud config

I want to use spring cloud config to externalise application properties. I have configured config-server and client, but i don't want to use git(enterprise) as source, this is due to the fact that git may be down for the maintenance. Therefore, i thought about releasing application properties to nexus as application.properties.tar.gz and do the following:
1.) When config-server starts, download the release version from nexus and then unpack the tar.gz to a file system on the server where config-server is running.
2.) The config server which will pick the unpacked properties files.
Please note that the nexus url, application.properties.tar.gz version and location are all passed as VM options to config server.
Is this a sensible option? if this not best option, please could you suggest any other options?
Thanks
kankalam
Unless the Git server is down for maintenance so frequently, I wouldn't go with that option, it seems to be an overkill. Also the Nexus server might go down, so there's no advantage on doing that.
The config server does not read the configuration from the repo once and again, the repository is cloned when configuration is requested. From the docs:
The default strategy for locating property sources is to clone a git
repository (at spring.cloud.config.server.git.uri) and use it to
initialize a mini SpringApplication. The mini-application’s
Environment is used to enumerate property sources and publish them via
a JSON endpoint.
With that in mind, you need to check that the git server you use is available before you start the application or before you refresh its context. If you think it might be a problem, you still have two options:
Set up a dedicated Git server for your application (Check out Gogs as a lightweight option).
Go the "native" way and load the files from the file system. This way you don't have a version control of the configuration files, but you could do it separately into your project.

Properties change with out a server restart

I have externalized all my application needed property files from webapps in tomcat. Now i can simply change a property file value without a need of rebuilding the war file and deploy it again. However each change to property file is associated with server recyling.
Is there a way how the recycling can be avoided for a property file change.
I am using spring to read the property files for few webapps and java property traditional way for few webapps.
Please suggest how to acheive
You may want to consider spring-cloud-config-server or spring-cloud-consul all of these options supports distributed properties management as well as value changes refresh without a need to recycle app servers.
And you can use #RefreshScope for Spring #Beans that want to be reinitialized when configuration changes, they also provide the following Management endpoints out of the box and many more as explained on the project git page
/refresh for refreshing the #RefreshScope beans
/restart for restarting the Spring context (disabled by default)
This is supported by either option (spring-cloud-config-server or spring-cloud-consul)
You may also give cfg4j a try. It supports reloading configuration from local files as well as remote services (git repository, Consul, etc.).

Resources