OnlyConfig is a distributed, easy-to-use and powerful configure system.
Key characteristics
- Distributed configure: Supporting as many applications as you want with strong reliability, performance, flexibility.
- Easy-to-use: Speed up your development from tiny applications to large.
- Flexible: Custom your own server and client to extend the possibility of configuration.
- Minimum dependencies: Simplify dependencies, less complexity.
- Frequently upgrade: supporting more requirements in reality, latest go version with dependencies and modern software and hardware
[TOC]
[LOGO]
- Setup
postgresql
database. - Create database and import database ddl files in the
docs
folder. - Start
OnlyConfig
server
./onlyconfig -http=:8800 -postgres=postgres://admin:admin127.0.0.1:5432/onlyconfig
- Suggested usage - using struct as configure container
package main
import (
"context"
"github.com/goodplayer/onlyconfig/client"
)
// Define the configure container to use
type ConfigureContainer struct {
Str string `json:"str"`
Int int `json:"int"`
Bool bool `json:"bool"`
}
func main() {
// Create the configure client with server list and options
c := client.NewClient([]string{"http://127.0.0.1:8800"}, client.ClientOptions{
// Add any selector parameters according to the settings on server side
SelectorApp: "app1",
SelectorEnvironment: "env1",
SelectorDatacenter: "dc1",
})
// Create advanced client
ca := client.NewClientAdv(c)
// Register a container with json marshalling and container prototype. Specify the group and key of the configuration.
// The returned type of container is *atomic.Value . This will guarantee concurrent safe while updating to and reading from the container.
atomicContainer, _ := ca.RegisterJsonContainer("group_json", "key_json", new(ConfigureContainer))
// Start the client and register the stop function if needed
c.StartClient()
defer c.StopClient()
// Waiting for all registered configurations loaded for the first time in order for the application to use
c.WaitStartupConfigureLoaded(context.Background())
// Use the configuration in the application - retrieving the container everytime
var container = atomicContainer.Load().(*ConfigureContainer)
}
- Start web manager
./webmgr -http=:8880 -postgres=postgres://admin:admin127.0.0.1:5432/onlyconfig
- Open browser and add configurations to the app
- OnlyConfig server
- OnlyConfig server: postgresql database storage
- OnlyConfig client: Go language
- Supporting configure client in https://github.com/meidoworks/nekoq-component
- OnlyConfig web manager
- OnlyConfig agent
- OnlyConfig cmd
- OnlyConfig cleanjob
TBD
TBD
go get ./...
go build
- Suggested usage - using struct as configure container
TBD
- General usage - using general api
TBD
Note
- Configure callback should not raise any panic which will cause client background update task exit
TBD
- Levels of configuration(As selectors)
- Environment: default envs including DEV, UAT, PreProduction, PROD, etc.
- Datacenter
- Namespace(groups of an application)
- App
- Configure key properties
- Group
- Key
- Value
- Version(auto generated)
- Configure content type(supporting validation before publishing)
- General(text)
- Json
- Toml
- Yaml
- Properties
- Xml
- Html
Pending implemented items - TBD
- Link public namespaces to apps as reference configurations
- Release history/Rollback
- Multi-datacenter comparison/publish
- Role based management: user, owner, administrator
- Special handling for production or specific env: reviewing, different appearance
- Better role/naming control: including namespace naming format, etc.
- More configure content editor support
- Support binary file as configure
Note
- Currently, items including application, environment, datacenter, namespace and others could not be deleted due to the
possibility to cause production issues. If the records are required to be removed(for example offline an
application or a datacenter), a manual cleanup task is required. Please refer to
cleanjob
tool.
OnlyAgent is an independent agent to pull configurations from onlyconfig server and write them to files.
The purpose is to support configuration usage in the applications that don't have available clients in the programming languages.
./onlyagent -sel dc=dc1,env=DEV -optsel beta=1 -group group1 -key key1 -output application.yaml -hook pwd -server http://127.0.0.1:8800 -server http://127.0.0.2:8800
Prepare configuration file, for example: demo.toml
[[config_list]]
selectors = "dc=dc1,env=DEV"
optional_selectors = "beta=1"
group = "group1"
key = "key1"
output = "application.yaml"
hook = "pwd"
[[config_list]]
selectors = "dc=dc2"
optional_selectors = "beta=2"
group = "group2"
key = "key2"
output = "application2.properties"
Start agent
./onlyagent -config demo.toml -server http://127.0.0.1:8800 -server http://127.0.0.2:8800
Hook
is used as a callback when configurations are written to files and ready to load.
Hook
in the parameter or configure file should be an executable file, including commands or scripts or etc.
When the hook is invoked, the following environment variables are set for the hook to consume:
- ONLYAGENT_GROUP
- ONLYAGENT_KEY
- ONLYAGENT_SEL
- ONLYAGENT_OPTSEL
Note: There is a hard time limit for the hook to be running, which is 60s and cannot be changed. Please ensure that the hook can complete its task within the time.
Run agent:
go run . -sel app=onlyconfig,dc=default,env=PROD -group GeneralOrg.onlyconfig -key notice -output application.log -hook "D:\hook.bat" -server http://10.11.0.7:8800
Output file:
application.log
Hook file:
D:\hook.bat
In the hook file, the following environment variables are set:
ONLYAGENT_GROUP=GeneralOrg.onlyconfig
ONLYAGENT_KEY=notice
ONLYAGENT_SEL=app=onlyconfig,dc=default,env=PROD
ONLYAGENT_OPTSEL=
TBD
TBD
TBD