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
629eab0b
Commit
629eab0b
authored
Jun 10, 2018
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bus: dont mix ctx/classic handlers
parent
e2275701
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
17 additions
and
41 deletions
+17
-41
pkg/api/dashboard.go
+1
-1
pkg/bus/bus.go
+1
-13
pkg/bus/bus_test.go
+11
-10
pkg/services/sqlstore/stats.go
+2
-16
pkg/services/sqlstore/stats_test.go
+2
-1
No files found.
pkg/api/dashboard.go
View file @
629eab0b
...
...
@@ -103,7 +103,7 @@ func GetDashboard(c *m.ReqContext) Response {
}
isDashboardProvisioned
:=
&
m
.
IsDashboardProvisionedQuery
{
DashboardId
:
dash
.
Id
}
err
=
bus
.
Dispatch
Ctx
(
c
.
Req
.
Context
(),
isDashboardProvisioned
)
err
=
bus
.
Dispatch
(
isDashboardProvisioned
)
if
err
!=
nil
{
return
Error
(
500
,
"Error while checking if dashboard is provisioned"
,
err
)
}
...
...
pkg/bus/bus.go
View file @
629eab0b
...
...
@@ -76,25 +76,13 @@ func (b *InProcBus) SetTransactionManager(tm TransactionManager) {
func
(
b
*
InProcBus
)
DispatchCtx
(
ctx
context
.
Context
,
msg
Msg
)
error
{
var
msgName
=
reflect
.
TypeOf
(
msg
)
.
Elem
()
.
Name
()
// we prefer to use the handler that support context.Context
var
handler
=
b
.
handlersWithCtx
[
msgName
]
var
withCtx
=
true
// fallback to use classic handlers
if
handler
==
nil
{
withCtx
=
false
handler
=
b
.
handlers
[
msgName
]
}
if
handler
==
nil
{
return
ErrHandlerNotFound
}
var
params
=
[]
reflect
.
Value
{}
if
withCtx
{
params
=
append
(
params
,
reflect
.
ValueOf
(
ctx
))
}
params
=
append
(
params
,
reflect
.
ValueOf
(
ctx
))
params
=
append
(
params
,
reflect
.
ValueOf
(
msg
))
ret
:=
reflect
.
ValueOf
(
handler
)
.
Call
(
params
)
...
...
pkg/bus/bus_test.go
View file @
629eab0b
...
...
@@ -33,22 +33,23 @@ func TestDispatchCtxCanUseNormalHandlers(t *testing.T) {
t
.
Errorf
(
"expected bus to return HandlerNotFound is no handler is registered"
)
}
bus
.
AddHandler
(
handler
)
bus
.
AddHandlerCtx
(
handlerWithCtx
)
t
.
Run
(
"when a normal handler is registered"
,
func
(
t
*
testing
.
T
)
{
bus
.
AddHandler
(
handler
)
bus
.
DispatchCtx
(
context
.
Background
(),
&
testQuery
{})
bus
.
Dispatch
(
&
testQuery
{})
if
handlerCallCount
!=
1
{
t
.
Errorf
(
"Expected normal handler to be called
once"
)
t
.
Errorf
(
"Expected normal handler to be called
1 time. was called %d"
,
handlerCallCount
)
}
})
t
.
Run
(
"when a ctx handler is registered"
,
func
(
t
*
testing
.
T
)
{
bus
.
AddHandlerCtx
(
handlerWithCtx
)
bus
.
DispatchCtx
(
context
.
Background
(),
&
testQuery
{})
t
.
Run
(
"when a ctx handler is registered"
,
func
(
t
*
testing
.
T
)
{
bus
.
DispatchCtx
(
context
.
Background
(),
&
testQuery
{})
if
handlerWithCtxCallCount
!=
1
{
t
.
Errorf
(
"Expected ctx handler to be called once"
)
}
})
if
handlerWithCtxCallCount
!=
1
{
t
.
Errorf
(
"Expected ctx handler to be called 1 time. was called %d"
,
handlerWithCtxCallCount
)
}
})
}
...
...
pkg/services/sqlstore/stats.go
View file @
629eab0b
...
...
@@ -13,8 +13,7 @@ func init() {
bus
.
AddHandler
(
"sql"
,
GetDataSourceStats
)
bus
.
AddHandler
(
"sql"
,
GetDataSourceAccessStats
)
bus
.
AddHandler
(
"sql"
,
GetAdminStats
)
bus
.
AddHandler
(
"sql"
,
GetSystemUserCountStats
)
bus
.
AddHandlerCtx
(
"sql"
,
GetSystemUserCountStatsCtx
)
bus
.
AddHandlerCtx
(
"sql"
,
GetSystemUserCountStats
)
}
var
activeUserTimeLimit
=
time
.
Hour
*
24
*
30
...
...
@@ -135,7 +134,7 @@ func GetAdminStats(query *m.GetAdminStatsQuery) error {
return
err
}
func
GetSystemUserCountStats
Ctx
(
ctx
context
.
Context
,
query
*
m
.
GetSystemUserCountStatsQuery
)
error
{
func
GetSystemUserCountStats
(
ctx
context
.
Context
,
query
*
m
.
GetSystemUserCountStatsQuery
)
error
{
return
withDbSession
(
ctx
,
func
(
sess
*
DBSession
)
error
{
var
rawSql
=
`SELECT COUNT(id) AS Count FROM `
+
dialect
.
Quote
(
"user"
)
...
...
@@ -150,16 +149,3 @@ func GetSystemUserCountStatsCtx(ctx context.Context, query *m.GetSystemUserCount
return
err
})
}
func
GetSystemUserCountStats
(
query
*
m
.
GetSystemUserCountStatsQuery
)
error
{
var
rawSql
=
`SELECT COUNT(id) AS Count FROM `
+
dialect
.
Quote
(
"user"
)
var
stats
m
.
SystemUserCountStats
_
,
err
:=
x
.
SQL
(
rawSql
)
.
Get
(
&
stats
)
if
err
!=
nil
{
return
err
}
query
.
Result
=
&
stats
return
err
}
pkg/services/sqlstore/stats_test.go
View file @
629eab0b
package
sqlstore
import
(
"context"
"testing"
m
"github.com/grafana/grafana/pkg/models"
...
...
@@ -20,7 +21,7 @@ func TestStatsDataAccess(t *testing.T) {
Convey
(
"Get system user count stats should not results in error"
,
func
()
{
query
:=
m
.
GetSystemUserCountStatsQuery
{}
err
:=
GetSystemUserCountStats
(
&
query
)
err
:=
GetSystemUserCountStats
(
context
.
Background
(),
&
query
)
So
(
err
,
ShouldBeNil
)
})
...
...
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