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
69d63165
Commit
69d63165
authored
Dec 13, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
style(mqe): instance dependencies in ctor func
parent
549c3ab7
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
29 deletions
+34
-29
pkg/tsdb/mqe/model_parser.go
+4
-0
pkg/tsdb/mqe/mqe.go
+16
-17
pkg/tsdb/mqe/token_client.go
+12
-8
pkg/tsdb/mqe/token_client_test.go
+2
-4
No files found.
pkg/tsdb/mqe/model_parser.go
View file @
69d63165
...
...
@@ -6,6 +6,10 @@ import (
"github.com/grafana/grafana/pkg/tsdb"
)
func
NewQueryParser
()
*
MQEQueryParser
{
return
&
MQEQueryParser
{}
}
type
MQEQueryParser
struct
{}
func
(
qp
*
MQEQueryParser
)
Parse
(
model
*
simplejson
.
Json
,
dsInfo
*
models
.
DataSource
,
queryContext
*
tsdb
.
QueryContext
)
(
*
MQEQuery
,
error
)
{
...
...
pkg/tsdb/mqe/mqe.go
View file @
69d63165
...
...
@@ -23,9 +23,11 @@ import (
type
MQEExecutor
struct
{
*
models
.
DataSource
QueryParser
*
MQEQueryParser
ResponseParser
*
MQEResponseParser
HttpClient
*
http
.
Client
queryParser
*
MQEQueryParser
responseParser
*
MQEResponseParser
httpClient
*
http
.
Client
log
log
.
Logger
tokenClient
*
TokenClient
}
func
NewMQEExecutor
(
dsInfo
*
models
.
DataSource
)
(
tsdb
.
Executor
,
error
)
{
...
...
@@ -36,18 +38,15 @@ func NewMQEExecutor(dsInfo *models.DataSource) (tsdb.Executor, error) {
return
&
MQEExecutor
{
DataSource
:
dsInfo
,
QueryParser
:
&
MQEQueryParser
{},
ResponseParser
:
&
MQEResponseParser
{},
HttpClient
:
httpclient
,
httpClient
:
httpclient
,
log
:
log
.
New
(
"tsdb.mqe"
),
queryParser
:
NewQueryParser
(),
responseParser
:
NewResponseParser
(),
tokenClient
:
NewTokenClient
(
dsInfo
),
},
nil
}
var
(
glog
log
.
Logger
)
func
init
()
{
glog
=
log
.
New
(
"tsdb.mqe"
)
tsdb
.
RegisterExecutor
(
"mqe-datasource"
,
NewMQEExecutor
)
}
...
...
@@ -59,14 +58,14 @@ type QueryToSend struct {
func
(
e
*
MQEExecutor
)
Execute
(
ctx
context
.
Context
,
queries
tsdb
.
QuerySlice
,
queryContext
*
tsdb
.
QueryContext
)
*
tsdb
.
BatchResult
{
result
:=
&
tsdb
.
BatchResult
{}
availableSeries
,
err
:=
NewTokenClient
(
e
.
HttpClient
)
.
GetTokenData
(
ctx
,
e
.
DataSource
)
availableSeries
,
err
:=
e
.
tokenClient
.
GetTokenData
(
ctx
)
if
err
!=
nil
{
return
result
.
WithError
(
err
)
}
var
mqeQueries
[]
*
MQEQuery
for
_
,
v
:=
range
queries
{
q
,
err
:=
e
.
Q
ueryParser
.
Parse
(
v
.
Model
,
e
.
DataSource
,
queryContext
)
q
,
err
:=
e
.
q
ueryParser
.
Parse
(
v
.
Model
,
e
.
DataSource
,
queryContext
)
if
err
!=
nil
{
return
result
.
WithError
(
err
)
}
...
...
@@ -85,16 +84,16 @@ func (e *MQEExecutor) Execute(ctx context.Context, queries tsdb.QuerySlice, quer
queryResult
:=
&
tsdb
.
QueryResult
{}
for
_
,
v
:=
range
rawQueries
{
g
log
.
Info
(
"Mqe executor"
,
"query"
,
v
)
e
.
log
.
Info
(
"Mqe executor"
,
"query"
,
v
)
req
,
err
:=
e
.
createRequest
(
v
.
RawQuery
)
resp
,
err
:=
ctxhttp
.
Do
(
ctx
,
e
.
H
ttpClient
,
req
)
resp
,
err
:=
ctxhttp
.
Do
(
ctx
,
e
.
h
ttpClient
,
req
)
if
err
!=
nil
{
return
result
.
WithError
(
err
)
}
series
,
err
:=
e
.
R
esponseParser
.
Parse
(
resp
,
v
.
QueryRef
)
series
,
err
:=
e
.
r
esponseParser
.
Parse
(
resp
,
v
.
QueryRef
)
if
err
!=
nil
{
return
result
.
WithError
(
err
)
}
...
...
@@ -132,6 +131,6 @@ func (e *MQEExecutor) createRequest(query string) (*http.Request, error) {
req
.
SetBasicAuth
(
e
.
BasicAuthUser
,
e
.
BasicAuthPassword
)
}
g
log
.
Debug
(
"Mqe request"
,
"url"
,
req
.
URL
.
String
())
e
.
log
.
Debug
(
"Mqe request"
,
"url"
,
req
.
URL
.
String
())
return
req
,
nil
}
pkg/tsdb/mqe/token_client.go
View file @
69d63165
...
...
@@ -17,12 +17,16 @@ import (
type
TokenClient
struct
{
tlog
log
.
Logger
Datasource
*
models
.
DataSource
HttpClient
*
http
.
Client
}
func
NewTokenClient
(
httpClient
*
http
.
Client
)
*
TokenClient
{
func
NewTokenClient
(
datasource
*
models
.
DataSource
)
*
TokenClient
{
httpClient
,
_
:=
datasource
.
GetHttpClient
()
return
&
TokenClient
{
tlog
:
log
.
New
(
"tsdb.mqe.tokenclient"
),
Datasource
:
datasource
,
HttpClient
:
httpClient
,
}
}
...
...
@@ -30,22 +34,22 @@ func NewTokenClient(httpClient *http.Client) *TokenClient {
var
cache
map
[
int64
]
*
TokenBody
=
map
[
int64
]
*
TokenBody
{}
//Replace this stupid cache with internal cache from grafana master before merging
func
(
client
*
TokenClient
)
GetTokenData
(
ctx
context
.
Context
,
datasource
*
models
.
DataSource
)
(
*
TokenBody
,
error
)
{
_
,
excist
:=
cache
[
d
atasource
.
Id
]
func
(
client
*
TokenClient
)
GetTokenData
(
ctx
context
.
Context
)
(
*
TokenBody
,
error
)
{
_
,
excist
:=
cache
[
client
.
D
atasource
.
Id
]
if
!
excist
{
b
,
err
:=
client
.
RequestTokenData
(
ctx
,
datasource
)
b
,
err
:=
client
.
RequestTokenData
(
ctx
)
if
err
!=
nil
{
return
nil
,
err
}
cache
[
d
atasource
.
Id
]
=
b
cache
[
client
.
D
atasource
.
Id
]
=
b
}
return
cache
[
d
atasource
.
Id
],
nil
return
cache
[
client
.
D
atasource
.
Id
],
nil
}
func
(
client
*
TokenClient
)
RequestTokenData
(
ctx
context
.
Context
,
datasource
*
models
.
DataSource
)
(
*
TokenBody
,
error
)
{
u
,
_
:=
url
.
Parse
(
d
atasource
.
Url
)
func
(
client
*
TokenClient
)
RequestTokenData
(
ctx
context
.
Context
)
(
*
TokenBody
,
error
)
{
u
,
_
:=
url
.
Parse
(
client
.
D
atasource
.
Url
)
u
.
Path
=
path
.
Join
(
u
.
Path
,
"token"
)
req
,
err
:=
http
.
NewRequest
(
http
.
MethodGet
,
u
.
String
(),
nil
)
...
...
pkg/tsdb/mqe/token_client_test.go
View file @
69d63165
...
...
@@ -4,8 +4,6 @@ import (
"context"
"testing"
"net/http"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/models"
.
"github.com/smartystreets/goconvey/convey"
...
...
@@ -18,9 +16,9 @@ func TestTokenClient(t *testing.T) {
Url
:
""
,
}
client
:=
NewTokenClient
(
http
.
DefaultClient
)
client
:=
NewTokenClient
(
dsInfo
)
body
,
err
:=
client
.
RequestTokenData
(
context
.
TODO
()
,
dsInfo
)
body
,
err
:=
client
.
RequestTokenData
(
context
.
TODO
())
So
(
err
,
ShouldBeNil
)
//So(len(body.Functions), ShouldBeGreaterThan, 1)
...
...
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