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
c3a768b3
Commit
c3a768b3
authored
Jan 24, 2018
by
bergquist
Committed by
Carl Bergquist
Jan 25, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
provsioning: dont stop grafana due to missing
parent
579d2b63
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
19 deletions
+51
-19
pkg/services/provisioning/dashboards/config_reader.go
+10
-5
pkg/services/provisioning/dashboards/config_reader_test.go
+14
-3
pkg/services/provisioning/dashboards/dashboard.go
+3
-2
pkg/services/provisioning/datasources/datasources.go
+10
-6
pkg/services/provisioning/datasources/datasources_test.go
+14
-3
No files found.
pkg/services/provisioning/dashboards/config_reader.go
View file @
c3a768b3
...
@@ -5,20 +5,25 @@ import (
...
@@ -5,20 +5,25 @@ import (
"path/filepath"
"path/filepath"
"strings"
"strings"
"github.com/grafana/grafana/pkg/log"
yaml
"gopkg.in/yaml.v2"
yaml
"gopkg.in/yaml.v2"
)
)
type
configReader
struct
{
type
configReader
struct
{
path
string
path
string
log
log
.
Logger
}
}
func
(
cr
*
configReader
)
readConfig
()
([]
*
DashboardsAsConfig
,
error
)
{
func
(
cr
*
configReader
)
readConfig
()
([]
*
DashboardsAsConfig
,
error
)
{
var
dashboards
[]
*
DashboardsAsConfig
files
,
err
:=
ioutil
.
ReadDir
(
cr
.
path
)
files
,
err
:=
ioutil
.
ReadDir
(
cr
.
path
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
cr
.
log
.
Error
(
"cant read dashboard provisioning files from directory"
,
"path"
,
cr
.
path
)
return
dashboards
,
nil
}
}
var
dashboards
[]
*
DashboardsAsConfig
for
_
,
file
:=
range
files
{
for
_
,
file
:=
range
files
{
if
!
strings
.
HasSuffix
(
file
.
Name
(),
".yaml"
)
&&
!
strings
.
HasSuffix
(
file
.
Name
(),
".yml"
)
{
if
!
strings
.
HasSuffix
(
file
.
Name
(),
".yaml"
)
&&
!
strings
.
HasSuffix
(
file
.
Name
(),
".yml"
)
{
continue
continue
...
@@ -30,13 +35,13 @@ func (cr *configReader) readConfig() ([]*DashboardsAsConfig, error) {
...
@@ -30,13 +35,13 @@ func (cr *configReader) readConfig() ([]*DashboardsAsConfig, error) {
return
nil
,
err
return
nil
,
err
}
}
var
da
tasource
[]
*
DashboardsAsConfig
var
da
shCfg
[]
*
DashboardsAsConfig
err
=
yaml
.
Unmarshal
(
yamlFile
,
&
da
tasource
)
err
=
yaml
.
Unmarshal
(
yamlFile
,
&
da
shCfg
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
dashboards
=
append
(
dashboards
,
da
tasource
...
)
dashboards
=
append
(
dashboards
,
da
shCfg
...
)
}
}
for
i
:=
range
dashboards
{
for
i
:=
range
dashboards
{
...
...
pkg/services/provisioning/dashboards/config_reader_test.go
View file @
c3a768b3
...
@@ -3,6 +3,7 @@ package dashboards
...
@@ -3,6 +3,7 @@ package dashboards
import
(
import
(
"testing"
"testing"
"github.com/grafana/grafana/pkg/log"
.
"github.com/smartystreets/goconvey/convey"
.
"github.com/smartystreets/goconvey/convey"
)
)
...
@@ -16,7 +17,7 @@ func TestDashboardsAsConfig(t *testing.T) {
...
@@ -16,7 +17,7 @@ func TestDashboardsAsConfig(t *testing.T) {
Convey
(
"Can read config file"
,
func
()
{
Convey
(
"Can read config file"
,
func
()
{
cfgProvifer
:=
configReader
{
path
:
simpleDashboardConfig
}
cfgProvifer
:=
configReader
{
path
:
simpleDashboardConfig
,
log
:
log
.
New
(
"test-logger"
)
}
cfg
,
err
:=
cfgProvifer
.
readConfig
()
cfg
,
err
:=
cfgProvifer
.
readConfig
()
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"readConfig return an error %v"
,
err
)
t
.
Fatalf
(
"readConfig return an error %v"
,
err
)
...
@@ -47,16 +48,26 @@ func TestDashboardsAsConfig(t *testing.T) {
...
@@ -47,16 +48,26 @@ func TestDashboardsAsConfig(t *testing.T) {
So
(
ds2
.
Options
[
"path"
],
ShouldEqual
,
"/var/lib/grafana/dashboards"
)
So
(
ds2
.
Options
[
"path"
],
ShouldEqual
,
"/var/lib/grafana/dashboards"
)
})
})
Convey
(
"Should skip
broken config files
"
,
func
()
{
Convey
(
"Should skip
invalid path
"
,
func
()
{
cfgProvifer
:=
configReader
{
path
:
brokenConfigs
}
cfgProvifer
:=
configReader
{
path
:
"/invalid-directory"
,
log
:
log
.
New
(
"test-logger"
)
}
cfg
,
err
:=
cfgProvifer
.
readConfig
()
cfg
,
err
:=
cfgProvifer
.
readConfig
()
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"readConfig return an error %v"
,
err
)
t
.
Fatalf
(
"readConfig return an error %v"
,
err
)
}
}
So
(
len
(
cfg
),
ShouldEqual
,
0
)
So
(
len
(
cfg
),
ShouldEqual
,
0
)
})
Convey
(
"Should skip broken config files"
,
func
()
{
cfgProvifer
:=
configReader
{
path
:
brokenConfigs
,
log
:
log
.
New
(
"test-logger"
)}
cfg
,
err
:=
cfgProvifer
.
readConfig
()
if
err
!=
nil
{
t
.
Fatalf
(
"readConfig return an error %v"
,
err
)
}
So
(
len
(
cfg
),
ShouldEqual
,
0
)
})
})
})
})
}
}
pkg/services/provisioning/dashboards/dashboard.go
View file @
c3a768b3
...
@@ -14,9 +14,10 @@ type DashboardProvisioner struct {
...
@@ -14,9 +14,10 @@ type DashboardProvisioner struct {
}
}
func
Provision
(
ctx
context
.
Context
,
configDirectory
string
)
(
*
DashboardProvisioner
,
error
)
{
func
Provision
(
ctx
context
.
Context
,
configDirectory
string
)
(
*
DashboardProvisioner
,
error
)
{
log
:=
log
.
New
(
"provisioning.dashboard"
)
d
:=
&
DashboardProvisioner
{
d
:=
&
DashboardProvisioner
{
cfgReader
:
&
configReader
{
path
:
configDirectory
},
cfgReader
:
&
configReader
{
path
:
configDirectory
,
log
:
log
},
log
:
log
.
New
(
"provisioning.dashboard"
)
,
log
:
log
,
ctx
:
ctx
,
ctx
:
ctx
,
}
}
...
...
pkg/services/provisioning/datasources/datasources.go
View file @
c3a768b3
...
@@ -25,13 +25,13 @@ func Provision(configDirectory string) error {
...
@@ -25,13 +25,13 @@ func Provision(configDirectory string) error {
type
DatasourceProvisioner
struct
{
type
DatasourceProvisioner
struct
{
log
log
.
Logger
log
log
.
Logger
cfgProvider
configReader
cfgProvider
*
configReader
}
}
func
newDatasourceProvisioner
(
log
log
.
Logger
)
DatasourceProvisioner
{
func
newDatasourceProvisioner
(
log
log
.
Logger
)
DatasourceProvisioner
{
return
DatasourceProvisioner
{
return
DatasourceProvisioner
{
log
:
log
,
log
:
log
,
cfgProvider
:
configReader
{
},
cfgProvider
:
&
configReader
{
log
:
log
},
}
}
}
}
...
@@ -95,15 +95,19 @@ func (dc *DatasourceProvisioner) deleteDatasources(dsToDelete []*DeleteDatasourc
...
@@ -95,15 +95,19 @@ func (dc *DatasourceProvisioner) deleteDatasources(dsToDelete []*DeleteDatasourc
return
nil
return
nil
}
}
type
configReader
struct
{}
type
configReader
struct
{
log
log
.
Logger
}
func
(
cr
*
configReader
)
readConfig
(
path
string
)
([]
*
DatasourcesAsConfig
,
error
)
{
var
datasources
[]
*
DatasourcesAsConfig
func
(
configReader
)
readConfig
(
path
string
)
([]
*
DatasourcesAsConfig
,
error
)
{
files
,
err
:=
ioutil
.
ReadDir
(
path
)
files
,
err
:=
ioutil
.
ReadDir
(
path
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
cr
.
log
.
Error
(
"cant read datasource provisioning files from directory"
,
"path"
,
path
)
return
datasources
,
nil
}
}
var
datasources
[]
*
DatasourcesAsConfig
for
_
,
file
:=
range
files
{
for
_
,
file
:=
range
files
{
if
strings
.
HasSuffix
(
file
.
Name
(),
".yaml"
)
||
strings
.
HasSuffix
(
file
.
Name
(),
".yml"
)
{
if
strings
.
HasSuffix
(
file
.
Name
(),
".yaml"
)
||
strings
.
HasSuffix
(
file
.
Name
(),
".yml"
)
{
filename
,
_
:=
filepath
.
Abs
(
filepath
.
Join
(
path
,
file
.
Name
()))
filename
,
_
:=
filepath
.
Abs
(
filepath
.
Join
(
path
,
file
.
Name
()))
...
...
pkg/services/provisioning/datasources/datasources_test.go
View file @
c3a768b3
...
@@ -11,7 +11,7 @@ import (
...
@@ -11,7 +11,7 @@ import (
)
)
var
(
var
(
logger
log
.
Logger
=
log
.
New
(
"fake.log
ger
"
)
logger
log
.
Logger
=
log
.
New
(
"fake.log"
)
oneDatasourcesConfig
string
=
""
oneDatasourcesConfig
string
=
""
twoDatasourcesConfig
string
=
"./test-configs/two-datasources"
twoDatasourcesConfig
string
=
"./test-configs/two-datasources"
twoDatasourcesConfigPurgeOthers
string
=
"./test-configs/insert-two-delete-two"
twoDatasourcesConfigPurgeOthers
string
=
"./test-configs/insert-two-delete-two"
...
@@ -115,12 +115,23 @@ func TestDatasourceAsConfig(t *testing.T) {
...
@@ -115,12 +115,23 @@ func TestDatasourceAsConfig(t *testing.T) {
})
})
Convey
(
"broken yaml should return error"
,
func
()
{
Convey
(
"broken yaml should return error"
,
func
()
{
_
,
err
:=
configReader
{}
.
readConfig
(
brokenYaml
)
reader
:=
&
configReader
{}
_
,
err
:=
reader
.
readConfig
(
brokenYaml
)
So
(
err
,
ShouldNotBeNil
)
So
(
err
,
ShouldNotBeNil
)
})
})
Convey
(
"skip invalid directory"
,
func
()
{
cfgProvifer
:=
&
configReader
{
log
:
log
.
New
(
"test logger"
)}
cfg
,
err
:=
cfgProvifer
.
readConfig
(
"./invalid-directory"
)
if
err
!=
nil
{
t
.
Fatalf
(
"readConfig return an error %v"
,
err
)
}
So
(
len
(
cfg
),
ShouldEqual
,
0
)
})
Convey
(
"can read all properties"
,
func
()
{
Convey
(
"can read all properties"
,
func
()
{
cfgProvifer
:=
configReader
{
}
cfgProvifer
:=
&
configReader
{
log
:
log
.
New
(
"test logger"
)
}
cfg
,
err
:=
cfgProvifer
.
readConfig
(
allProperties
)
cfg
,
err
:=
cfgProvifer
.
readConfig
(
allProperties
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"readConfig return an error %v"
,
err
)
t
.
Fatalf
(
"readConfig return an error %v"
,
err
)
...
...
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