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
27f07e9d
Commit
27f07e9d
authored
Dec 16, 2014
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Progress on data source admin
parent
b70a3f09
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
107 additions
and
73 deletions
+107
-73
Makefile
+1
-0
grafana
+1
-1
pkg/api/api.go
+2
-1
pkg/api/api_datasources.go
+17
-1
pkg/bus/bus.go
+17
-18
pkg/bus/bus_test.go
+6
-6
pkg/components/renderer/renderer_test.go
+33
-32
pkg/models/datasource.go
+10
-0
pkg/stores/sqlstore/sqlstore.go
+14
-13
pkg/stores/sqlstore/sqlstore_datasource.go
+6
-1
No files found.
Makefile
View file @
27f07e9d
...
@@ -4,6 +4,7 @@ all: build
...
@@ -4,6 +4,7 @@ all: build
build
:
build
:
go build
-o
bin/grafana .
go build
-o
bin/grafana .
go
test
./pkg/...
lint
:
lint
:
@
gofmt
-w
.
&&
go tool vet pkg/
**
/
*
.go
&&
echo
"
$(GOLINT)
"
@
gofmt
-w
.
&&
go tool vet pkg/
**
/
*
.go
&&
echo
"
$(GOLINT)
"
...
...
grafana
@
adb1502e
Subproject commit
b3b096e204a8ad6eb2aba6b98802589ab3d1fa28
Subproject commit
adb1502e728e5a312a6e4dc680edbd1f75219ea1
pkg/api/api.go
View file @
27f07e9d
...
@@ -27,7 +27,8 @@ func Register(m *macaron.Macaron) {
...
@@ -27,7 +27,8 @@ func Register(m *macaron.Macaron) {
// datasources
// datasources
m
.
Get
(
"/admin/datasources/"
,
auth
,
Index
)
m
.
Get
(
"/admin/datasources/"
,
auth
,
Index
)
m
.
Get
(
"/api/admin/datasources/"
,
auth
,
GetDataSources
)
m
.
Get
(
"/api/admin/datasource/list"
,
auth
,
GetDataSources
)
m
.
Post
(
"/api/admin/datasource/add"
,
auth
,
AddDataSource
)
// user register
// user register
m
.
Get
(
"/register/*_"
,
Index
)
m
.
Get
(
"/register/*_"
,
Index
)
...
...
pkg/api/api_datasources.go
View file @
27f07e9d
...
@@ -8,10 +8,26 @@ import (
...
@@ -8,10 +8,26 @@ import (
func
GetDataSources
(
c
*
middleware
.
Context
)
{
func
GetDataSources
(
c
*
middleware
.
Context
)
{
query
:=
m
.
GetDataSourcesQuery
{
AccountId
:
c
.
Account
.
Id
}
query
:=
m
.
GetDataSourcesQuery
{
AccountId
:
c
.
Account
.
Id
}
err
:=
bus
.
SendQuery
(
&
query
)
err
:=
bus
.
Dispatch
(
&
query
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JsonApiErr
(
500
,
"Failed to query datasources"
,
err
)
c
.
JsonApiErr
(
500
,
"Failed to query datasources"
,
err
)
return
return
}
}
}
}
func
AddDataSource
(
c
*
middleware
.
Context
)
{
cmd
:=
m
.
AddDataSourceCommand
{}
if
!
c
.
JsonBody
(
&
cmd
)
{
c
.
JsonApiErr
(
400
,
"bad request"
,
nil
)
return
}
err
:=
bus
.
Dispatch
(
&
cmd
)
if
err
!=
nil
{
c
.
JsonApiErr
(
500
,
"Failed to add datasource"
,
err
)
return
}
}
pkg/bus/bus.go
View file @
27f07e9d
...
@@ -6,16 +6,16 @@ import (
...
@@ -6,16 +6,16 @@ import (
"reflect"
"reflect"
)
)
type
QueryHandler
interface
{}
type
HandlerFunc
interface
{}
type
Query
interface
{}
type
Msg
interface
{}
type
Bus
interface
{
type
Bus
interface
{
SendQuery
(
query
Query
)
error
Dispatch
(
msg
Msg
)
error
Add
QueryHandler
(
handler
QueryHandler
)
Add
Handler
(
handler
HandlerFunc
)
}
}
type
InProcBus
struct
{
type
InProcBus
struct
{
handler
Index
map
[
string
]
QueryHandler
handler
s
map
[
string
]
HandlerFunc
}
}
// temp stuff, not sure how to handle bus instance, and init yet
// temp stuff, not sure how to handle bus instance, and init yet
...
@@ -23,21 +23,20 @@ var globalBus = New()
...
@@ -23,21 +23,20 @@ var globalBus = New()
func
New
()
Bus
{
func
New
()
Bus
{
bus
:=
&
InProcBus
{}
bus
:=
&
InProcBus
{}
bus
.
handler
Index
=
make
(
map
[
string
]
QueryHandler
)
bus
.
handler
s
=
make
(
map
[
string
]
HandlerFunc
)
return
bus
return
bus
}
}
func
(
b
*
InProcBus
)
SendQuery
(
query
Query
)
error
{
func
(
b
*
InProcBus
)
Dispatch
(
msg
Msg
)
error
{
var
queryName
=
reflect
.
TypeOf
(
query
)
.
Elem
()
.
Name
()
var
msgName
=
reflect
.
TypeOf
(
msg
)
.
Elem
()
.
Name
()
fmt
.
Printf
(
"sending query for type: %v
\n
"
,
queryName
)
var
handler
=
b
.
handler
Index
[
query
Name
]
var
handler
=
b
.
handler
s
[
msg
Name
]
if
handler
==
nil
{
if
handler
==
nil
{
return
errors
.
New
(
"handler not found"
)
return
errors
.
New
(
"handler not found"
)
}
}
var
params
=
make
([]
reflect
.
Value
,
1
)
var
params
=
make
([]
reflect
.
Value
,
1
)
params
[
0
]
=
reflect
.
ValueOf
(
query
)
params
[
0
]
=
reflect
.
ValueOf
(
msg
)
ret
:=
reflect
.
ValueOf
(
handler
)
.
Call
(
params
)
ret
:=
reflect
.
ValueOf
(
handler
)
.
Call
(
params
)
err
:=
ret
[
0
]
.
Interface
()
err
:=
ret
[
0
]
.
Interface
()
...
@@ -48,18 +47,18 @@ func (b *InProcBus) SendQuery(query Query) error {
...
@@ -48,18 +47,18 @@ func (b *InProcBus) SendQuery(query Query) error {
}
}
}
}
func
(
b
*
InProcBus
)
Add
QueryHandler
(
handler
QueryHandler
)
{
func
(
b
*
InProcBus
)
Add
Handler
(
handler
HandlerFunc
)
{
handlerType
:=
reflect
.
TypeOf
(
handler
)
handlerType
:=
reflect
.
TypeOf
(
handler
)
queryTypeName
:=
handlerType
.
In
(
0
)
.
Elem
()
.
Name
()
queryTypeName
:=
handlerType
.
In
(
0
)
.
Elem
()
.
Name
()
fmt
.
Printf
(
"QueryType %v
\n
"
,
queryTypeName
)
fmt
.
Printf
(
"QueryType %v
\n
"
,
queryTypeName
)
b
.
handler
Index
[
queryTypeName
]
=
handler
b
.
handler
s
[
queryTypeName
]
=
handler
}
}
// Package level functions
// Package level functions
func
Add
QueryHandler
(
implName
string
,
handler
QueryHandler
)
{
func
Add
Handler
(
implName
string
,
handler
HandlerFunc
)
{
globalBus
.
Add
Query
Handler
(
handler
)
globalBus
.
AddHandler
(
handler
)
}
}
func
SendQuery
(
query
Query
)
error
{
func
Dispatch
(
msg
Msg
)
error
{
return
globalBus
.
SendQuery
(
query
)
return
globalBus
.
Dispatch
(
msg
)
}
}
pkg/bus/bus_test.go
View file @
27f07e9d
...
@@ -10,14 +10,14 @@ type TestQuery struct {
...
@@ -10,14 +10,14 @@ type TestQuery struct {
Resp
string
Resp
string
}
}
func
TestHandlerReturnsError
(
t
*
testing
.
T
)
{
func
Test
Query
HandlerReturnsError
(
t
*
testing
.
T
)
{
bus
:=
New
()
bus
:=
New
()
bus
.
Add
Query
Handler
(
func
(
query
*
TestQuery
)
error
{
bus
.
AddHandler
(
func
(
query
*
TestQuery
)
error
{
return
errors
.
New
(
"handler error"
)
return
errors
.
New
(
"handler error"
)
})
})
err
:=
bus
.
SendQuery
(
&
TestQuery
{})
err
:=
bus
.
Dispatch
(
&
TestQuery
{})
if
err
==
nil
{
if
err
==
nil
{
t
.
Fatal
(
"Send query failed "
+
err
.
Error
())
t
.
Fatal
(
"Send query failed "
+
err
.
Error
())
...
@@ -26,16 +26,16 @@ func TestHandlerReturnsError(t *testing.T) {
...
@@ -26,16 +26,16 @@ func TestHandlerReturnsError(t *testing.T) {
}
}
}
}
func
TestHandlerReturn
(
t
*
testing
.
T
)
{
func
Test
Query
HandlerReturn
(
t
*
testing
.
T
)
{
bus
:=
New
()
bus
:=
New
()
bus
.
Add
Query
Handler
(
func
(
q
*
TestQuery
)
error
{
bus
.
AddHandler
(
func
(
q
*
TestQuery
)
error
{
q
.
Resp
=
"hello from handler"
q
.
Resp
=
"hello from handler"
return
nil
return
nil
})
})
query
:=
&
TestQuery
{}
query
:=
&
TestQuery
{}
err
:=
bus
.
SendQuery
(
query
)
err
:=
bus
.
Dispatch
(
query
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
"Send query failed "
+
err
.
Error
())
t
.
Fatal
(
"Send query failed "
+
err
.
Error
())
...
...
pkg/components/renderer/renderer_test.go
View file @
27f07e9d
package
renderer
package
renderer
import
(
//
"io/ioutil"
// import (
"os"
// "io/ioutil"
"testing"
// "os"
// "testing"
.
"github.com/smartystreets/goconvey/convey"
//
)
// . "github.com/smartystreets/goconvey/convey"
// )
func
TestPhantomRender
(
t
*
testing
.
T
)
{
//
// func TestPhantomRender(t *testing.T) {
Convey
(
"Can render url"
,
t
,
func
()
{
//
tempDir
,
_
:=
ioutil
.
TempDir
(
""
,
"img"
)
// Convey("Can render url", t, func() {
png
,
err
:=
RenderToPng
(
"http://www.google.com"
)
// tempDir, _ := ioutil.TempDir("", "img")
So
(
err
,
ShouldBeNil
)
// ipng, err := RenderToPng("http://www.google.com")
So
(
exists
(
png
),
ShouldEqual
,
true
)
// So(err, ShouldBeNil)
// So(exists(png), ShouldEqual, true)
//_, err = os.Stat(store.getFilePathForDashboard("hello"))
//
//So(err, ShouldBeNil)
// //_, err = os.Stat(store.getFilePathForDashboard("hello"))
})
// //So(err, ShouldBeNil)
// })
}
//
// }
func
exists
(
path
string
)
bool
{
//
_
,
err
:=
os
.
Stat
(
path
)
// func exists(path string) bool {
if
err
==
nil
{
// _, err := os.Stat(path)
return
true
// if err == nil {
}
// return true
if
os
.
IsNotExist
(
err
)
{
// }
return
false
// if os.IsNotExist(err) {
}
// return false
return
false
// }
}
// return false
// }
pkg/models/datasource.go
View file @
27f07e9d
...
@@ -33,3 +33,13 @@ type GetDataSourcesQuery struct {
...
@@ -33,3 +33,13 @@ type GetDataSourcesQuery struct {
AccountId
int64
AccountId
int64
Resp
[]
*
DataSource
Resp
[]
*
DataSource
}
}
type
AddDataSourceCommand
struct
{
AccountId
int64
Name
string
Type
DsType
Access
DsAccess
Url
string
Password
string
User
string
}
pkg/stores/sqlstore/sqlstore.go
View file @
27f07e9d
...
@@ -6,7 +6,7 @@ import (
...
@@ -6,7 +6,7 @@ import (
"path"
"path"
"strings"
"strings"
"github.com/torkelo/grafana-pro/pkg/models"
m
"github.com/torkelo/grafana-pro/pkg/models"
"github.com/torkelo/grafana-pro/pkg/setting"
"github.com/torkelo/grafana-pro/pkg/setting"
"github.com/go-xorm/xorm"
"github.com/go-xorm/xorm"
...
@@ -27,18 +27,19 @@ var (
...
@@ -27,18 +27,19 @@ var (
)
)
func
Init
()
{
func
Init
()
{
tables
=
append
(
tables
,
new
(
models
.
Account
),
new
(
models
.
Dashboard
),
new
(
models
.
Collaborator
))
tables
=
append
(
tables
,
new
(
m
.
Account
),
new
(
m
.
Dashboard
),
new
(
m
.
Collaborator
),
new
(
m
.
DataSource
))
models
.
SaveAccount
=
SaveAccount
models
.
GetAccount
=
GetAccount
m
.
SaveAccount
=
SaveAccount
models
.
GetAccountByLogin
=
GetAccountByLogin
m
.
GetAccount
=
GetAccount
models
.
GetOtherAccountsFor
=
GetOtherAccountsFor
m
.
GetAccountByLogin
=
GetAccountByLogin
models
.
GetDashboard
=
GetDashboard
m
.
GetOtherAccountsFor
=
GetOtherAccountsFor
models
.
SaveDashboard
=
SaveDashboard
m
.
GetDashboard
=
GetDashboard
models
.
SearchQuery
=
SearchQuery
m
.
SaveDashboard
=
SaveDashboard
models
.
DeleteDashboard
=
DeleteDashboard
m
.
SearchQuery
=
SearchQuery
models
.
GetCollaboratorsForAccount
=
GetCollaboratorsForAccount
m
.
DeleteDashboard
=
DeleteDashboard
models
.
AddCollaborator
=
AddCollaborator
m
.
GetCollaboratorsForAccount
=
GetCollaboratorsForAccount
m
.
AddCollaborator
=
AddCollaborator
}
}
func
LoadModelsConfig
()
{
func
LoadModelsConfig
()
{
...
...
pkg/stores/sqlstore/sqlstore_datasource.go
View file @
27f07e9d
...
@@ -7,9 +7,14 @@ import (
...
@@ -7,9 +7,14 @@ import (
)
)
func
init
()
{
func
init
()
{
bus
.
AddQueryHandler
(
"sql"
,
GetDataSourcesQuery
)
bus
.
AddHandler
(
"sql"
,
GetDataSourcesQuery
)
bus
.
AddHandler
(
"sql"
,
AddDataSource
)
}
}
func
GetDataSourcesQuery
(
query
*
m
.
GetDataSourcesQuery
)
error
{
func
GetDataSourcesQuery
(
query
*
m
.
GetDataSourcesQuery
)
error
{
return
errors
.
New
(
"Hello from query handler"
)
return
errors
.
New
(
"Hello from query handler"
)
}
}
func
AddDataSource
(
cmd
*
m
.
AddDataSourceCommand
)
error
{
return
errors
.
New
(
"Hello from command handler"
)
}
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