Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store properties in db instead of git #203

Closed
K-RAD opened this issue Jul 27, 2015 · 19 comments
Closed

Store properties in db instead of git #203

K-RAD opened this issue Jul 27, 2015 · 19 comments
Milestone

Comments

@K-RAD
Copy link

K-RAD commented Jul 27, 2015

Spring-Cloud-Config looks like a very interesting option and we're considering using it in our project.

However, what we don't like is the fact that the properties are stored on Git.
If they were stored in a database it would've been way better in our view. Git is less trackable, there's less security and permissions to push/change them there, it can be down more often than db and so on. Oh, and business knows db, not git.

Will this be available at some point?

@spencergibb
Copy link
Member

@K-RAD pull requests are welcome. We aren't planning it at the moment. There are also other implementations that don't use config server: spring-cloud-consul and spring-cloud-zookeeper. Some of the reasons we chose git are that it already implements versioning and history, which a db doesn't have by default. Your business may not know git, but in general, most developers do.

@mreyes
Copy link

mreyes commented Nov 12, 2015

Hi, Spencer

I am facing the need to implement a database backend for Spring-Cloud-Config. Up until today I have reviewed the implementation of NativeEnvironmentRepository in the spring cloud-config-server project , and looks that the key component for this purpose is the ConfigFileApplicationListener so would it be a good approach to implement that listener but accessing a DB?

Another way that occurred to me was to implement the PropertySourceLocator with access to a DB... however, how this would update the environment variables if any changes during the application runtime?

Any guidance or hint on how to proceed or even if this would be the best approach?

Thanks

@spencergibb
Copy link
Member

ConfigFileApplicationListener is from spring boot. I don't think that's a good place to start. You need to implement EnvironmentRepository from config server.

venilnoronha added a commit to venilnoronha/spring-cloud-config that referenced this issue Nov 27, 2015
venilnoronha added a commit to venilnoronha/spring-cloud-config that referenced this issue Nov 27, 2015
venilnoronha added a commit to venilnoronha/spring-cloud-config that referenced this issue Nov 27, 2015
venilnoronha added a commit to venilnoronha/spring-cloud-config that referenced this issue Nov 27, 2015
venilnoronha added a commit to venilnoronha/spring-cloud-config that referenced this issue Nov 27, 2015
venilnoronha added a commit to venilnoronha/spring-cloud-config that referenced this issue Nov 27, 2015
venilnoronha added a commit to venilnoronha/spring-cloud-config that referenced this issue Nov 28, 2015
@igor-dmitriev
Copy link

Hi there, is there any guide how to create a custom environment repository??? It would be awesome to have an example, for instance with Map as environment storage.

@ryanjbaxter
Copy link
Contributor

There is no guide, but there are plenty of examples in the source code

@igor-dmitriev
Copy link

You know, they are not simple, it shouldn't be hard to do. Actually I've found this - spring-attic/spring-cloud-config-server-mongodb@ecedae0#diff-b109c993c15a6bd4f1aceeb3716c7a85 (MongoDB EnvironmentRepository). And I read it like an example how to implement a custom implementation

@spencergibb
Copy link
Member

it shouldn't be hard to do

The EnvironmentRepository has a single method.

@yangzii0920
Copy link

Actually I've found this
@igor-dmitriev Have your tried out this? Does it work for you?

@igor-dmitriev
Copy link

@yangzii0920 yeap, I did it, it works, take a look at my test implementation - https://github.com/igor-dmitriev/spring-cloud-config-poc.

@yangzii0920
Copy link

@igor-dmitriev Had a look. Is it cloud config w custom environment repository? I actually wanted to ask if you have tried out the one with MongoDB that you found.

@igor-dmitriev
Copy link

igor-dmitriev commented May 4, 2017

@yangzii0920 exactly. I've just used that MongoDB implementation as an example to create my own custom one

@rodrigovelaz
Copy link

rodrigovelaz commented Aug 30, 2017

Hello everyone,

I developed a project that implements a DbEnvironmentRepository using a SQL database
In order to use this library you have to:

  1. Add the dependency:
<dependency>
	<groupId>org.rodrigovelaz</groupId>
	<artifactId>spring-cloud-config-server-db</artifactId>
	<version>1.0.0</version>
</dependency>

  1. Set the active profile as "db" (Similar to "native" profile):

spring.profiles.active=db

  1. Configure the datasource (Just like any spring-boot application)

Oracle example

spring.datasource.url=jdbc:oracle:thin:@<IP>:<PORT>/<SERVICE>
spring.datasource.username=username
spring.datasource.password=password
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.Oracle10gDialect

  1. Create a table for each application and environment that you need

4.1. table name must be: application-environment
4.2. fields must be: long id, string property, string value

Oracle example:

application: x-service
environment: dev

  CREATE TABLE "X-SERVICE-DEV" 
   (	"ID" NUMBER(38,0), 
	"PROPERTY" VARCHAR2(256 CHAR), 
	"VALUE" VARCHAR2(500 CHAR)
   );

Any comment is welcome!

Regards,
Rodrigo

@dsyer dsyer removed the help wanted label Sep 21, 2017
@dsyer dsyer added this to the 1.4.0.RC1 milestone Sep 21, 2017
@dsyer
Copy link
Contributor

dsyer commented Sep 22, 2017

Closed in e362f39. More features could be added (e.g. it's read only for now). But the basics are there, and I think that sets the bar for the contract (how to interpret the HTTP request and turn it into SQL).

@dsyer dsyer closed this as completed Sep 22, 2017
@jvmlet
Copy link

jvmlet commented Nov 29, 2017

Does it mean that refresh event is not implemented yet? Are you planning to provide crud rest API that will trigger the refresh event after updating the DB ?

@spencergibb
Copy link
Member

Does it mean that refresh event is not implemented yet?

Refresh is orthogonal. Posting to /refresh will still work.

Are you planning to provide crud rest API that will trigger the refresh event after updating the DB?

Besides /refresh, no.

@PaulGobin
Copy link

PaulGobin commented Nov 29, 2017

Hi guys- I have my config server pulling configurations from svn, works great, I have a need to add the jdbc config which I did based on the sample test cases. However, spring boot micoservice is not getting these configurations, the one that's listed in the table.

Here is my condig server application yaml file:

spring:
  cloud:
    config:
      server:
        default-label: dev  
        bootstrap: true
        jdbc:
          sql: SELECT APPLICATION, PROFILE, LABEL, KY , VALUE FROM PROPERTIES where APPLICATION=? and PROFILE=? and LABEL=?
          order: 1          
        svn:
          uri: http://xxxx/svn/oss/config-repo/config-service
          username: xxx
          password: strongpassword
          order:  2
        
  profiles:
    active: jdbc, subversion

Here is my Database:

CREATE TABLE [dbo].[PROPERTIES](
	[ID] [bigint] IDENTITY(1,1) NOT NULL,
	[APPLICATION] [varchar](500) NOT NULL,
	[PROFILE] [varchar](500) NOT NULL,
	[LABEL] [varchar](500) NOT NULL,
	[KY] [varchar](500) NOT NULL,
	[VALUE] [varchar](500) NOT NULL)

sample values in the table:

**ID | APPLICATION    | PROFILE | LABEL | KY |                                       VALUE**
5  | bvn-sms-service | dev        | dev     | chat.service.endpoint.url  | https://MyChat.com

and here is my client

 @Value("${chat.service.endpoint.url}")
        private String chatEndpoint;

This value is not set when its in the database, however, when I add it to the SVN repo, this value is set correctly. So it works when set in the svn yaml file but not when it's set in the database PROPERTIES table.

Any help to resolve this issue would be much appreciated.

@spencergibb
Copy link
Member

@PaulGobin asking question on a closed issue isn't how we use the issue tracker. Probably best to ask questions on gitter or open a new issue if you think there's a bug.

@PaulGobin
Copy link

Sorry Spencer- Actually, just a quick comment, I reviewed the JdbcEnvironmentRepository code and I found my issue, the SQL I had set in the yaml file was SELECT APPLICATION, PROFILE, LABEL, KY , VALUE FROM PROPERTIES where APPLICATION=? and PROFILE=? and LABEL=?

it should have been:
SELECT KY, VALUE from PROPERTIES where APPLICATION=? and PROFILE=? and LABEL=?

thanks

@mar-celohenrique
Copy link

@spencergibb exist some way to provide the refreshscope to config server using DB's approach?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests