Are multiple GIt hosts in the Spring Cloud config server possible? - spring

With the recent outage of Microsoft's Azure Services our team is brain storming ways to add redundancy and fault tolerance to our apps.
In the documentation on Spring.IO there are multiple ways of using Git, SVN, or vault together but Im interested in using Two Git host.
setting the Composite profile maybe what Im looking for but that sounds like if I'm trying to override values from all the repositories listed and Im looking for a complete fail-over option.
My use case is how to configure the config server so that if a host goes down and we cannot retrieve our config file to fail over to our second GIT host.
IS this possible and what would the configuration look like?
My guess is something like this with ordering.
spring:
profiles:
cloud:
config:
server:
git:
uri: bitbucket.com
order: 1
git:
uri: github.com
order: 1

The answer is to use the composite feature:
spring:
profiles:
active: composite
cloud:
config:
server:
composite:
-
type: git
uri: file:///path/to/rex/git/repo
-
type: git
uri: file:///path/to/walter/git/repo

Related

How to access multiple application yml from difference service on configure server(Spring)

I have configured "configure-server" by fetching all configuration from gitlab repository.
Currently, when application(config-server) start it fetch all application properties in git repo.
In case, I have two client application A,B
which has difference application properties like
aplication-a.yml
aplication-b.yml
when application A start, I just only want configure-service fetch only application-a.yml from git repositry.
Here is application configure:
Configure Server
server:
port: 9000
spring:
application:
name: CONFIG-SERVER
cloud:
config:
server:
git:
uri: https://gitlab.com/mama/cloud-configure-server.git
clone-on-start: true
default-label: main
Application A
spring:
cloud:
config:
enabled: true
uri: http://localhost:9000
How to tell configure-service fetch only application-a.yml from git repository?
In case, I don't want to fetch all?
Thank you!!

Adding multiple repositories to Spring cloud config server

I need to add two config repositories to my config server. But, it picks only one config repository. Can anyone please help me to fix this problem.
Config Server bootstrap.yml
server:
port: 8899
spring:
cloud:
config:
server:
git:
uri: https://github.com/pocuser9x/wednest-config-store
search-paths:
- 'wednest-config-store/*service'
repos:
uri: https://github.com/pocuser9x/secure-config-store
In https://github.com/pocuser9x/wednest-config-store I have below files
event-service.yml
event-service-dev.yml
event-service-stg.yml
These files are picking correctly.
In https://github.com/pocuser9x/secure-config-store I have below file
event-service-prod.yml
This file is not picking.
I think what you are looking for is the composite repo feature. It is documented here.
For you, this would be something like:
spring:
profiles:
active: composite
cloud:
config:
server:
composite:
-
type: git
uri: https://github.com/pocuser9x/wednest-config-store
search-paths:
'wednest-config-store/*service'
-
type: git
uri: https://github.com/pocuser9x/secure-config-store
One note is that the documentation shows profile set as above, but I found a need to use "include" instead of "active". Include is additive.
profiles:
include: composite

No such label error with spring cloud config server with composite config of two git repos

We have a spring cloud config server with a composite configuration like this:
spring:
profiles:
active: composite
cloud:
config:
server:
composite:
-
type: git
uri: "https://github.comcast.com/config-org/{application}"
username: "mainUsername"
password: "mainPassword"
searchPaths: "*"
-
type: git
uri: "https://github.comcast.com/config-org/shared-repo"
username: "sharedUsername"
password: "sharedPassword"
searchPaths: "*"
health:
enabled: false
Here's the issue we're running into. Given that there is a repository named xsp-reference-service, when the cloud config client makes a request to the config server with a label for a branch that exists in the application (xsp-reference-service) repository, but not in the shared (shared-repo) repository, we get this:
{
"timestamp": "2019-12-04T16:18:43.886+0000",
"status": 404,
"error": "Not Found",
"message": "No such label: schrodingers_branch",
"path": "/xsp-reference-service/dev/schrodingers_branch"
}
Is there a way we can either tell Spring Cloud Config Server to not worry about the missing branch in the shared repository (fail gracefully)? If not, can we force cloud config server to use a default label (branch name) if the provided one does not exist? I'll even take suggestions on maybe a different setup that would serve our use case better. Any comments are welcome.
I don't have the required rep to comment nor do I know how to tell Spring Cloud Config Server to gracefully fail. That being said, I was able to find some information here[1].
Two important points from the above documentation:
Any type of failure when retrieving values from an environment
repository results in a failure for the entire composite environment.
When using a composite environment, it is important that all
repositories contain the same labels. If you have an environment
similar to those in the preceding examples and you request
configuration data with the master label but the Subversion repository
does not contain a branch called master, the entire request fails.
It might be in your best interest to revisit your design with having a shared repo. One alternative could be to use Spring Vault[2]. Then (taken from the same above link) you can define distinct types of repositories and no longer have this composite labeling problem.
spring:
profiles:
active: git, vault
cloud:
config:
server:
git:
uri: file:///path/to/git/repo
order: 2
vault:
host: 127.0.0.1
port: 8200
order: 1
1: https://cloud.spring.io/spring-cloud-config/multi/multi__spring_cloud_config_server.html#composite-environment-repositories
2: https://spring.io/projects/spring-vault

Spring Config Server: pick git credentials from Vault

I'm able to set up a git repository a config backend:
spring:
cloud:
config:
server:
git:
# username: user
# password: '{cipher}passwd'
I think it's not a good practive to provide user and password straightforwardly herewith on bootstrap.yml file.
I'd like they are picked up from Vault.
Is it possible?
You can use spring cloud vault to do so, Spring offers a start guide here

How to ask Spring Cloud Config server to checkout configuration from specific branch?

I have following Spring cloud config application.yml:
spring:
application:
name: configserver
cloud:
config:
server:
git:
uri: https://xyz#bitbucket.org/xyz/microservices-configs.git
username: xyz
password: xyz
basedir: target/configs
server:
port: 8881
Following is my bootstrap.yml of user microservice:
spring:
application:
name: userservice
cloud:
config:
uri: http://localhost:8881/
Scenario - 1
When I hit config server in browser like this:
http://localhost:8881/development/userservice-development.yml
It serves file properly. and when I look at basedir i.e. target/config, I see:
- userservice.yml
- gateway.yml
Exactly what I wanted, Since I added this two files only in development branch.
Scenario - 2
When I run my userservice microservice project using following command:
mvn clean spring-boot:run -Dspring.profiles.active=development
It fetches the right file from git, but it checkout from master branch ! but not from the development branch as I am expecting. am I expecting right ? (FYI I have both development and production yml in master branch)
So the question is, how do we go for using config server ? Is there any configuration which we can set to fetch yml from that particular branch only ? I believe we need to set some label, because as per documentation, default label is master. Can anyone let me know how do we go for setting label in above scenario ?
According to the documentation, the configuration you want to set in your config client is:
spring.cloud.config.label=mybranch
Where mybranch is an existing branch in your git repo.
You can specify the default branch (more generally, Git label) that a config server uses if a client does not specify the label, via property spring.cloud.config.server.git.default-label, perhaps this is what you are after? Certainly solves the issue for me!
If only use the branch in a yml file just configure:
spring:
cloud:
config:
server:
git:
uri: https://gitlab.com/somerepo.git
username: someuser
password: somepass
default-label: branchname
Config server designed to use profile to separate environment.
Example:
/{application}/{profile}[/{label}]
/{application}-{profile}.yml
/{label}/{application}-{profile}.yml
/{application}-{profile}.properties
/{label}/{application}-{profile}.properties
The branching make configuration inconsistency.
Concept of config server is based on 12-factor config (http://12factor.net/config ) .
Check it out for detail reason.

Resources