Commit d1767144 by Torkel Ödegaard

Reworking configuration loading and overriding

parent a991cda2
[run]
init_cmds = [
["go", "build", "-o", "./bin/grafana"],
["./bin/grafana", "web"]
["go", "build", "-o", "./bin/grafana-server"],
["./bin/grafana-server"]
]
watch_all = true
watch_dirs = [
......@@ -12,6 +12,6 @@ watch_dirs = [
watch_exts = [".go", ".ini"]
build_delay = 1500
cmds = [
["go", "build", "-o", "./bin/grafana"],
["./bin/grafana", "web"]
["go", "build", "-o", "./bin/grafana-server"],
["./bin/grafana-server"]
]
......@@ -209,7 +209,7 @@ func test(pkg string) {
}
func build(pkg string, tags []string) {
binary := "./bin/grafana"
binary := "./bin/grafana-server"
if goos == "windows" {
binary += ".exe"
}
......
app_name = Grafana
app_mode = production
[paths]
; data_path
; where rendered png images are temporarily stored
; file based sessions are stored here (if file based session is configured below)
; the database is stored here if sqlite3 database is used
; can be overriden from command line --data-path
; defaults to `data` path relative to working directory
data_path =
data = data
logs = data/log
[server]
; protocol (http or https)
......@@ -21,7 +21,7 @@ domain = localhost
; the full public facing url
root_url = %(protocol)s://%(domain)s:%(http_port)s/
router_logging = false
; the path relative to the binary where the static (html/js/css) files are placed
; the path relative home path where frontend assets are located
static_root_path = public
; enable gzip
enable_gzip = false
......@@ -47,7 +47,7 @@ user = root
password =
; For "postgres" only, either "disable", "require" or "verify-full"
ssl_mode = disable
; For "sqlite3" only, path relative to data_dir setting
; For "sqlite3" only, path relative to data_path setting
path = grafana.db
[session]
......@@ -55,7 +55,7 @@ path = grafana.db
provider = file
; Provider config options
; memory: not have any config yet
; file: session dir path, is relative to grafana data_dir
; file: session dir path, is relative to grafana data_path
; redis: config like redis server addr, poolSize, password, e.g. `127.0.0.1:6379,100,grafana`
; mysql: go-sql-driver/mysql dsn config string, e.g. `user:password@tcp(127.0.0.1)/database_name`
provider_config = sessions
......@@ -117,11 +117,6 @@ token_url = https://accounts.google.com/o/oauth2/token
; allowed_domains = mycompany.com othercompany.com
[log]
; root_path
; for deb or rpm package installs this is specified via command line
; change it in /etc/default/grafana, it defaults to /var/log/grafana
; for non package installs (running manually) defaults to `log` dir under data_dir
root_path =
; Either "console", "file", default is "console"
; Use comma to separate multiple modes, e.g. "console, file"
mode = console, file
......
......@@ -64,15 +64,14 @@ func main() {
}
func initRuntime() {
setting.NewConfigContext(&setting.CommandLineArgs{})
setting.NewConfigContext(&setting.CommandLineArgs{
Config: *configFile,
Args: flag.Args(),
})
log.Info("Starting Grafana")
log.Info("Version: %v, Commit: %v, Build date: %v", setting.BuildVersion, setting.BuildCommit, time.Unix(setting.BuildStamp, 0))
setting.LogLoadedConfigFiles()
log.Info("Working Path: %s", setting.WorkPath)
log.Info("Data Path: %s", setting.DataPath)
log.Info("Log Path: %s", setting.LogRootPath)
setting.LogConfigurationInfo()
sqlstore.NewEngine()
sqlstore.EnsureAdminUser()
......
......@@ -86,7 +86,7 @@ func SetEngine(engine *xorm.Engine, enableLog bool) (err error) {
}
if enableLog {
logPath := path.Join(setting.LogRootPath, "xorm.log")
logPath := path.Join(setting.LogsPath, "xorm.log")
os.MkdirAll(path.Dir(logPath), os.ModePerm)
f, err := os.Create(logPath)
......
......@@ -10,12 +10,12 @@ import (
func TestLoadingSettings(t *testing.T) {
WorkDir, _ = filepath.Abs("../../")
HomePath, _ = filepath.Abs("../../")
Convey("Testing loading settings from ini file", t, func() {
Convey("Given the default ini files", func() {
NewConfigContext("")
NewConfigContext(&CommandLineArgs{})
So(AppName, ShouldEqual, "Grafana")
So(AdminUser, ShouldEqual, "admin")
......@@ -23,9 +23,63 @@ func TestLoadingSettings(t *testing.T) {
Convey("Should be able to override via environment variables", func() {
os.Setenv("GF_SECURITY_ADMIN_USER", "superduper")
NewConfigContext("")
NewConfigContext(&CommandLineArgs{})
So(AdminUser, ShouldEqual, "superduper")
So(DataPath, ShouldEqual, filepath.Join(HomePath, "data"))
So(LogsPath, ShouldEqual, filepath.Join(DataPath, "log"))
})
Convey("Should get property map from command line args array", func() {
props := getCommandLineProperties([]string{"cfg:test=value", "cfg:map.test=1"})
So(len(props), ShouldEqual, 2)
So(props["test"], ShouldEqual, "value")
So(props["map.test"], ShouldEqual, "1")
})
Convey("Should be able to override via command line", func() {
NewConfigContext(&CommandLineArgs{
Args: []string{"cfg:paths.data=/tmp/data", "cfg:paths.logs=/tmp/logs"},
})
So(DataPath, ShouldEqual, "/tmp/data")
So(LogsPath, ShouldEqual, "/tmp/logs")
})
Convey("Should be able to override defaults via command line", func() {
NewConfigContext(&CommandLineArgs{
Args: []string{"cfg:default.paths.data=/tmp/data"},
})
So(DataPath, ShouldEqual, "/tmp/data")
})
Convey("Defaults can be overriden in specified config file", func() {
NewConfigContext(&CommandLineArgs{
Args: []string{"cfg:default.paths.data=/tmp/data"},
Config: filepath.Join(HomePath, "tests/config-files/override.ini"),
})
So(DataPath, ShouldEqual, "/tmp/override")
})
Convey("Command line overrides specified config file", func() {
NewConfigContext(&CommandLineArgs{
Args: []string{"cfg:paths.data=/tmp/data"},
Config: filepath.Join(HomePath, "tests/config-files/override.ini"),
})
So(DataPath, ShouldEqual, "/tmp/data")
})
Convey("Can use environment variables in config values", func() {
os.Setenv("GF_DATA_PATH", "/tmp/env_override")
NewConfigContext(&CommandLineArgs{
Args: []string{"cfg:paths.data=${GF_DATA_PATH}"},
})
So(DataPath, ShouldEqual, "/tmp/env_override")
})
})
......
......@@ -55,7 +55,7 @@ module.exports = function(grunt) {
grunt.config('copy.backend_bin', {
cwd: 'bin',
expand: true,
src: ['grafana'],
src: ['grafana-server'],
options: { mode: true},
dest: '<%= tempDir %>/bin/'
});
......
[paths]
data = /tmp/override
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment