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
b5e1a8d7
Unverified
Commit
b5e1a8d7
authored
Oct 12, 2018
by
Torkel Ödegaard
Committed by
GitHub
Oct 12, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #13638 from grafana/minor-setting-refactoring
minor setting refactorings
parents
c1fd4265
d6292f83
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
31 deletions
+37
-31
pkg/services/sqlstore/sqlstore.go
+1
-1
pkg/setting/setting.go
+24
-18
pkg/setting/setting_test.go
+12
-12
No files found.
pkg/services/sqlstore/sqlstore.go
View file @
b5e1a8d7
...
...
@@ -233,7 +233,7 @@ func (ss *SqlStore) buildConnectionString() (string, error) {
case
migrator
.
SQLITE
:
// special case for tests
if
!
filepath
.
IsAbs
(
ss
.
dbCfg
.
Path
)
{
ss
.
dbCfg
.
Path
=
filepath
.
Join
(
s
ettin
g
.
DataPath
,
ss
.
dbCfg
.
Path
)
ss
.
dbCfg
.
Path
=
filepath
.
Join
(
s
s
.
Cf
g
.
DataPath
,
ss
.
dbCfg
.
Path
)
}
os
.
MkdirAll
(
path
.
Dir
(
ss
.
dbCfg
.
Path
),
os
.
ModePerm
)
cnnstr
=
"file:"
+
ss
.
dbCfg
.
Path
+
"?cache=shared&mode=rwc"
...
...
pkg/setting/setting.go
View file @
b5e1a8d7
...
...
@@ -54,14 +54,11 @@ var (
ApplicationName
string
// Paths
LogsPath
string
HomePath
string
DataPath
string
PluginsPath
string
CustomInitPath
=
"conf/custom.ini"
// Log settings.
LogModes
[]
string
LogConfigs
[]
util
.
DynMap
// Http server options
...
...
@@ -187,11 +184,18 @@ var (
ImageUploadProvider
string
)
// TODO move all global vars to this struct
type
Cfg
struct
{
Raw
*
ini
.
File
// HTTP Server Settings
AppUrl
string
AppSubUrl
string
// Paths
ProvisioningPath
string
DataPath
string
LogsPath
string
// SMTP email settings
Smtp
SmtpSettings
...
...
@@ -411,7 +415,7 @@ func loadSpecifedConfigFile(configFile string, masterFile *ini.File) error {
return
nil
}
func
loadConfiguration
(
args
*
CommandLineArgs
)
(
*
ini
.
File
,
error
)
{
func
(
cfg
*
Cfg
)
loadConfiguration
(
args
*
CommandLineArgs
)
(
*
ini
.
File
,
error
)
{
var
err
error
// load config defaults
...
...
@@ -442,7 +446,7 @@ func loadConfiguration(args *CommandLineArgs) (*ini.File, error) {
// load specified config file
err
=
loadSpecifedConfigFile
(
args
.
Config
,
parsedFile
)
if
err
!=
nil
{
initLogging
(
parsedFile
)
cfg
.
initLogging
(
parsedFile
)
log
.
Fatal
(
3
,
err
.
Error
())
}
...
...
@@ -459,8 +463,8 @@ func loadConfiguration(args *CommandLineArgs) (*ini.File, error) {
evalConfigValues
(
parsedFile
)
// update data path and logging config
DataPath
=
makeAbsolute
(
parsedFile
.
Section
(
"paths"
)
.
Key
(
"data"
)
.
String
(),
HomePath
)
initLogging
(
parsedFile
)
cfg
.
DataPath
=
makeAbsolute
(
parsedFile
.
Section
(
"paths"
)
.
Key
(
"data"
)
.
String
(),
HomePath
)
cfg
.
initLogging
(
parsedFile
)
return
parsedFile
,
err
}
...
...
@@ -517,7 +521,7 @@ func NewCfg() *Cfg {
func
(
cfg
*
Cfg
)
Load
(
args
*
CommandLineArgs
)
error
{
setHomePath
(
args
)
iniFile
,
err
:=
loadConfiguration
(
args
)
iniFile
,
err
:=
cfg
.
loadConfiguration
(
args
)
if
err
!=
nil
{
return
err
}
...
...
@@ -538,6 +542,8 @@ func (cfg *Cfg) Load(args *CommandLineArgs) error {
cfg
.
ProvisioningPath
=
makeAbsolute
(
iniFile
.
Section
(
"paths"
)
.
Key
(
"provisioning"
)
.
String
(),
HomePath
)
server
:=
iniFile
.
Section
(
"server"
)
AppUrl
,
AppSubUrl
=
parseAppUrlAndSubUrl
(
server
)
cfg
.
AppUrl
=
AppUrl
cfg
.
AppSubUrl
=
AppSubUrl
Protocol
=
HTTP
if
server
.
Key
(
"protocol"
)
.
MustString
(
"http"
)
==
"https"
{
...
...
@@ -662,7 +668,7 @@ func (cfg *Cfg) Load(args *CommandLineArgs) error {
log
.
Fatal
(
4
,
"Invalid callback_url(%s): %s"
,
cfg
.
RendererCallbackUrl
,
err
)
}
}
cfg
.
ImagesDir
=
filepath
.
Join
(
DataPath
,
"png"
)
cfg
.
ImagesDir
=
filepath
.
Join
(
cfg
.
DataPath
,
"png"
)
cfg
.
PhantomDir
=
filepath
.
Join
(
HomePath
,
"tools/phantomjs"
)
cfg
.
TempDataLifetime
=
iniFile
.
Section
(
"paths"
)
.
Key
(
"temp_data_lifetime"
)
.
MustDuration
(
time
.
Second
*
3600
*
24
)
cfg
.
MetricsEndpointEnabled
=
iniFile
.
Section
(
"metrics"
)
.
Key
(
"enabled"
)
.
MustBool
(
true
)
...
...
@@ -720,7 +726,7 @@ func (cfg *Cfg) readSessionConfig() {
SessionOptions
.
IDLength
=
16
if
SessionOptions
.
Provider
==
"file"
{
SessionOptions
.
ProviderConfig
=
makeAbsolute
(
SessionOptions
.
ProviderConfig
,
DataPath
)
SessionOptions
.
ProviderConfig
=
makeAbsolute
(
SessionOptions
.
ProviderConfig
,
cfg
.
DataPath
)
os
.
MkdirAll
(
path
.
Dir
(
SessionOptions
.
ProviderConfig
),
os
.
ModePerm
)
}
...
...
@@ -731,15 +737,15 @@ func (cfg *Cfg) readSessionConfig() {
SessionConnMaxLifetime
=
cfg
.
Raw
.
Section
(
"session"
)
.
Key
(
"conn_max_lifetime"
)
.
MustInt64
(
14400
)
}
func
initLogging
(
file
*
ini
.
File
)
{
func
(
cfg
*
Cfg
)
initLogging
(
file
*
ini
.
File
)
{
// split on comma
LogModes
=
strings
.
Split
(
file
.
Section
(
"log"
)
.
Key
(
"mode"
)
.
MustString
(
"console"
),
","
)
logModes
:
=
strings
.
Split
(
file
.
Section
(
"log"
)
.
Key
(
"mode"
)
.
MustString
(
"console"
),
","
)
// also try space
if
len
(
L
ogModes
)
==
1
{
L
ogModes
=
strings
.
Split
(
file
.
Section
(
"log"
)
.
Key
(
"mode"
)
.
MustString
(
"console"
),
" "
)
if
len
(
l
ogModes
)
==
1
{
l
ogModes
=
strings
.
Split
(
file
.
Section
(
"log"
)
.
Key
(
"mode"
)
.
MustString
(
"console"
),
" "
)
}
LogsPath
=
makeAbsolute
(
file
.
Section
(
"paths"
)
.
Key
(
"logs"
)
.
String
(),
HomePath
)
log
.
ReadLoggingConfig
(
LogModes
,
LogsPath
,
file
)
cfg
.
LogsPath
=
makeAbsolute
(
file
.
Section
(
"paths"
)
.
Key
(
"logs"
)
.
String
(),
HomePath
)
log
.
ReadLoggingConfig
(
logModes
,
cfg
.
LogsPath
,
file
)
}
func
(
cfg
*
Cfg
)
LogConfigSources
()
{
...
...
@@ -763,8 +769,8 @@ func (cfg *Cfg) LogConfigSources() {
}
logger
.
Info
(
"Path Home"
,
"path"
,
HomePath
)
logger
.
Info
(
"Path Data"
,
"path"
,
DataPath
)
logger
.
Info
(
"Path Logs"
,
"path"
,
LogsPath
)
logger
.
Info
(
"Path Data"
,
"path"
,
cfg
.
DataPath
)
logger
.
Info
(
"Path Logs"
,
"path"
,
cfg
.
LogsPath
)
logger
.
Info
(
"Path Plugins"
,
"path"
,
PluginsPath
)
logger
.
Info
(
"Path Provisioning"
,
"path"
,
cfg
.
ProvisioningPath
)
logger
.
Info
(
"App mode "
+
Env
)
...
...
pkg/setting/setting_test.go
View file @
b5e1a8d7
...
...
@@ -30,8 +30,8 @@ func TestLoadingSettings(t *testing.T) {
cfg
.
Load
(
&
CommandLineArgs
{
HomePath
:
"../../"
})
So
(
AdminUser
,
ShouldEqual
,
"superduper"
)
So
(
DataPath
,
ShouldEqual
,
filepath
.
Join
(
HomePath
,
"data"
))
So
(
LogsPath
,
ShouldEqual
,
filepath
.
Join
(
DataPath
,
"log"
))
So
(
cfg
.
DataPath
,
ShouldEqual
,
filepath
.
Join
(
HomePath
,
"data"
))
So
(
cfg
.
LogsPath
,
ShouldEqual
,
filepath
.
Join
(
cfg
.
DataPath
,
"log"
))
})
Convey
(
"Should replace password when defined in environment"
,
func
()
{
...
...
@@ -76,8 +76,8 @@ func TestLoadingSettings(t *testing.T) {
HomePath
:
"../../"
,
Args
:
[]
string
{
`cfg:paths.data=c:\tmp\data`
,
`cfg:paths.logs=c:\tmp\logs`
},
})
So
(
DataPath
,
ShouldEqual
,
`c:\tmp\data`
)
So
(
LogsPath
,
ShouldEqual
,
`c:\tmp\logs`
)
So
(
cfg
.
DataPath
,
ShouldEqual
,
`c:\tmp\data`
)
So
(
cfg
.
LogsPath
,
ShouldEqual
,
`c:\tmp\logs`
)
}
else
{
cfg
:=
NewCfg
()
cfg
.
Load
(
&
CommandLineArgs
{
...
...
@@ -85,8 +85,8 @@ func TestLoadingSettings(t *testing.T) {
Args
:
[]
string
{
"cfg:paths.data=/tmp/data"
,
"cfg:paths.logs=/tmp/logs"
},
})
So
(
DataPath
,
ShouldEqual
,
"/tmp/data"
)
So
(
LogsPath
,
ShouldEqual
,
"/tmp/logs"
)
So
(
cfg
.
DataPath
,
ShouldEqual
,
"/tmp/data"
)
So
(
cfg
.
LogsPath
,
ShouldEqual
,
"/tmp/logs"
)
}
})
...
...
@@ -112,7 +112,7 @@ func TestLoadingSettings(t *testing.T) {
Args
:
[]
string
{
`cfg:default.paths.data=c:\tmp\data`
},
})
So
(
DataPath
,
ShouldEqual
,
`c:\tmp\override`
)
So
(
cfg
.
DataPath
,
ShouldEqual
,
`c:\tmp\override`
)
}
else
{
cfg
:=
NewCfg
()
cfg
.
Load
(
&
CommandLineArgs
{
...
...
@@ -121,7 +121,7 @@ func TestLoadingSettings(t *testing.T) {
Args
:
[]
string
{
"cfg:default.paths.data=/tmp/data"
},
})
So
(
DataPath
,
ShouldEqual
,
"/tmp/override"
)
So
(
cfg
.
DataPath
,
ShouldEqual
,
"/tmp/override"
)
}
})
...
...
@@ -134,7 +134,7 @@ func TestLoadingSettings(t *testing.T) {
Args
:
[]
string
{
`cfg:paths.data=c:\tmp\data`
},
})
So
(
DataPath
,
ShouldEqual
,
`c:\tmp\data`
)
So
(
cfg
.
DataPath
,
ShouldEqual
,
`c:\tmp\data`
)
}
else
{
cfg
:=
NewCfg
()
cfg
.
Load
(
&
CommandLineArgs
{
...
...
@@ -143,7 +143,7 @@ func TestLoadingSettings(t *testing.T) {
Args
:
[]
string
{
"cfg:paths.data=/tmp/data"
},
})
So
(
DataPath
,
ShouldEqual
,
"/tmp/data"
)
So
(
cfg
.
DataPath
,
ShouldEqual
,
"/tmp/data"
)
}
})
...
...
@@ -156,7 +156,7 @@ func TestLoadingSettings(t *testing.T) {
Args
:
[]
string
{
"cfg:paths.data=${GF_DATA_PATH}"
},
})
So
(
DataPath
,
ShouldEqual
,
`c:\tmp\env_override`
)
So
(
cfg
.
DataPath
,
ShouldEqual
,
`c:\tmp\env_override`
)
}
else
{
os
.
Setenv
(
"GF_DATA_PATH"
,
"/tmp/env_override"
)
cfg
:=
NewCfg
()
...
...
@@ -165,7 +165,7 @@ func TestLoadingSettings(t *testing.T) {
Args
:
[]
string
{
"cfg:paths.data=${GF_DATA_PATH}"
},
})
So
(
DataPath
,
ShouldEqual
,
"/tmp/env_override"
)
So
(
cfg
.
DataPath
,
ShouldEqual
,
"/tmp/env_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