Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
d1767144
Commit
d1767144
authored
Apr 09, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reworking configuration loading and overriding
parent
a991cda2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
234 additions
and
105 deletions
+234
-105
.bra.toml
+4
-4
build.go
+1
-1
conf/defaults.ini
+6
-11
main.go
+5
-6
pkg/services/sqlstore/sqlstore.go
+1
-1
pkg/setting/setting.go
+157
-78
pkg/setting/setting_test.go
+57
-3
tasks/build_task.js
+1
-1
tests/config-files/override.ini
+2
-0
No files found.
.bra.toml
View file @
d1767144
[run]
[run]
init_cmds
=
[
init_cmds
=
[
[
"go"
,
"build"
,
"-o"
,
"./bin/grafana"
],
[
"go"
,
"build"
,
"-o"
,
"./bin/grafana
-server
"
],
[
"./bin/grafana
"
,
"web
"
]
["./bin/grafana
-server
"]
]
]
watch_all
=
true
watch_all
=
true
watch_dirs
=
[
watch_dirs
=
[
...
@@ -12,6 +12,6 @@ watch_dirs = [
...
@@ -12,6 +12,6 @@ watch_dirs = [
watch_exts
=
[
".go"
,
".ini"
]
watch_exts
=
[
".go"
,
".ini"
]
build_delay
=
1500
build_delay
=
1500
cmds
=
[
cmds
=
[
[
"go"
,
"build"
,
"-o"
,
"./bin/grafana"
],
[
"go"
,
"build"
,
"-o"
,
"./bin/grafana
-server
"
],
[
"./bin/grafana
"
,
"web
"
]
["./bin/grafana
-server
"]
]
]
build.go
View file @
d1767144
...
@@ -209,7 +209,7 @@ func test(pkg string) {
...
@@ -209,7 +209,7 @@ func test(pkg string) {
}
}
func
build
(
pkg
string
,
tags
[]
string
)
{
func
build
(
pkg
string
,
tags
[]
string
)
{
binary
:=
"./bin/grafana"
binary
:=
"./bin/grafana
-server
"
if
goos
==
"windows"
{
if
goos
==
"windows"
{
binary
+=
".exe"
binary
+=
".exe"
}
}
...
...
conf/defaults.ini
View file @
d1767144
app_name
=
Grafana
app_name
=
Grafana
app_mode
=
production
app_mode
=
production
[paths]
; data_path
; data_path
; where rendered png images are temporarily stored
; where rendered png images are temporarily stored
; file based sessions are stored here (if file based session is configured below)
; file based sessions are stored here (if file based session is configured below)
; the database is stored here if sqlite3 database is used
; the database is stored here if sqlite3 database is used
; can be overriden from command line --data-path
data
=
data
; defaults to `data` path relative to working directory
logs
=
data/log
data_path
=
[server]
[server]
; protocol (http or https)
; protocol (http or https)
...
@@ -21,7 +21,7 @@ domain = localhost
...
@@ -21,7 +21,7 @@ domain = localhost
; the full public facing url
; the full public facing url
root_url
=
%(protocol)s://%(domain)s:%(http_port)s/
root_url
=
%(protocol)s://%(domain)s:%(http_port)s/
router_logging
=
false
router_logging
=
false
; the path relative
to the binary where the static (html/js/css) files are plac
ed
; the path relative
home path where frontend assets are locat
ed
static_root_path
=
public
static_root_path
=
public
; enable gzip
; enable gzip
enable_gzip
=
false
enable_gzip
=
false
...
@@ -47,7 +47,7 @@ user = root
...
@@ -47,7 +47,7 @@ user = root
password
=
password
=
; For "postgres" only, either "disable", "require" or "verify-full"
; For "postgres" only, either "disable", "require" or "verify-full"
ssl_mode
=
disable
ssl_mode
=
disable
; For "sqlite3" only, path relative to data_
dir
setting
; For "sqlite3" only, path relative to data_
path
setting
path
=
grafana.db
path
=
grafana.db
[session]
[session]
...
@@ -55,7 +55,7 @@ path = grafana.db
...
@@ -55,7 +55,7 @@ path = grafana.db
provider
=
file
provider
=
file
; Provider config options
; Provider config options
; memory: not have any config yet
; 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`
; 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`
; mysql: go-sql-driver/mysql dsn config string, e.g. `user:password@tcp(127.0.0.1)/database_name`
provider_config
=
sessions
provider_config
=
sessions
...
@@ -117,11 +117,6 @@ token_url = https://accounts.google.com/o/oauth2/token
...
@@ -117,11 +117,6 @@ token_url = https://accounts.google.com/o/oauth2/token
; allowed_domains = mycompany.com othercompany.com
; allowed_domains = mycompany.com othercompany.com
[log]
[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"
; Either "console", "file", default is "console"
; Use comma to separate multiple modes, e.g. "console, file"
; Use comma to separate multiple modes, e.g. "console, file"
mode
=
console, file
mode
=
console, file
...
...
main.go
View file @
d1767144
...
@@ -64,15 +64,14 @@ func main() {
...
@@ -64,15 +64,14 @@ func main() {
}
}
func
initRuntime
()
{
func
initRuntime
()
{
setting
.
NewConfigContext
(
&
setting
.
CommandLineArgs
{})
setting
.
NewConfigContext
(
&
setting
.
CommandLineArgs
{
Config
:
*
configFile
,
Args
:
flag
.
Args
(),
})
log
.
Info
(
"Starting Grafana"
)
log
.
Info
(
"Starting Grafana"
)
log
.
Info
(
"Version: %v, Commit: %v, Build date: %v"
,
setting
.
BuildVersion
,
setting
.
BuildCommit
,
time
.
Unix
(
setting
.
BuildStamp
,
0
))
log
.
Info
(
"Version: %v, Commit: %v, Build date: %v"
,
setting
.
BuildVersion
,
setting
.
BuildCommit
,
time
.
Unix
(
setting
.
BuildStamp
,
0
))
setting
.
LogLoadedConfigFiles
()
setting
.
LogConfigurationInfo
()
log
.
Info
(
"Working Path: %s"
,
setting
.
WorkPath
)
log
.
Info
(
"Data Path: %s"
,
setting
.
DataPath
)
log
.
Info
(
"Log Path: %s"
,
setting
.
LogRootPath
)
sqlstore
.
NewEngine
()
sqlstore
.
NewEngine
()
sqlstore
.
EnsureAdminUser
()
sqlstore
.
EnsureAdminUser
()
...
...
pkg/services/sqlstore/sqlstore.go
View file @
d1767144
...
@@ -86,7 +86,7 @@ func SetEngine(engine *xorm.Engine, enableLog bool) (err error) {
...
@@ -86,7 +86,7 @@ func SetEngine(engine *xorm.Engine, enableLog bool) (err error) {
}
}
if
enableLog
{
if
enableLog
{
logPath
:=
path
.
Join
(
setting
.
Log
Root
Path
,
"xorm.log"
)
logPath
:=
path
.
Join
(
setting
.
Log
s
Path
,
"xorm.log"
)
os
.
MkdirAll
(
path
.
Dir
(
logPath
),
os
.
ModePerm
)
os
.
MkdirAll
(
path
.
Dir
(
logPath
),
os
.
ModePerm
)
f
,
err
:=
os
.
Create
(
logPath
)
f
,
err
:=
os
.
Create
(
logPath
)
...
...
pkg/setting/setting.go
View file @
d1767144
This diff is collapsed.
Click to expand it.
pkg/setting/setting_test.go
View file @
d1767144
...
@@ -10,12 +10,12 @@ import (
...
@@ -10,12 +10,12 @@ import (
func
TestLoadingSettings
(
t
*
testing
.
T
)
{
func
TestLoadingSettings
(
t
*
testing
.
T
)
{
WorkDir
,
_
=
filepath
.
Abs
(
"../../"
)
HomePath
,
_
=
filepath
.
Abs
(
"../../"
)
Convey
(
"Testing loading settings from ini file"
,
t
,
func
()
{
Convey
(
"Testing loading settings from ini file"
,
t
,
func
()
{
Convey
(
"Given the default ini files"
,
func
()
{
Convey
(
"Given the default ini files"
,
func
()
{
NewConfigContext
(
""
)
NewConfigContext
(
&
CommandLineArgs
{}
)
So
(
AppName
,
ShouldEqual
,
"Grafana"
)
So
(
AppName
,
ShouldEqual
,
"Grafana"
)
So
(
AdminUser
,
ShouldEqual
,
"admin"
)
So
(
AdminUser
,
ShouldEqual
,
"admin"
)
...
@@ -23,9 +23,63 @@ func TestLoadingSettings(t *testing.T) {
...
@@ -23,9 +23,63 @@ func TestLoadingSettings(t *testing.T) {
Convey
(
"Should be able to override via environment variables"
,
func
()
{
Convey
(
"Should be able to override via environment variables"
,
func
()
{
os
.
Setenv
(
"GF_SECURITY_ADMIN_USER"
,
"superduper"
)
os
.
Setenv
(
"GF_SECURITY_ADMIN_USER"
,
"superduper"
)
NewConfigContext
(
""
)
NewConfigContext
(
&
CommandLineArgs
{}
)
So
(
AdminUser
,
ShouldEqual
,
"superduper"
)
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"
)
})
})
})
})
...
...
tasks/build_task.js
View file @
d1767144
...
@@ -55,7 +55,7 @@ module.exports = function(grunt) {
...
@@ -55,7 +55,7 @@ module.exports = function(grunt) {
grunt
.
config
(
'copy.backend_bin'
,
{
grunt
.
config
(
'copy.backend_bin'
,
{
cwd
:
'bin'
,
cwd
:
'bin'
,
expand
:
true
,
expand
:
true
,
src
:
[
'grafana'
],
src
:
[
'grafana
-server
'
],
options
:
{
mode
:
true
},
options
:
{
mode
:
true
},
dest
:
'<%= tempDir %>/bin/'
dest
:
'<%= tempDir %>/bin/'
});
});
...
...
tests/config-files/override.ini
0 → 100644
View file @
d1767144
[paths]
data
=
/tmp/override
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment