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
0e9a6dce
Commit
0e9a6dce
authored
Sep 14, 2018
by
Torkel Ödegaard
Committed by
Marcus Efraimsson
Sep 14, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use datasource cache for backend tsdb/query endpoint (#13266)
fix: use datasource cache for backend datasources
parent
06855d2b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
15 deletions
+13
-15
pkg/api/api.go
+1
-1
pkg/api/dataproxy.go
+5
-7
pkg/api/metrics.go
+7
-7
No files found.
pkg/api/api.go
View file @
0e9a6dce
...
...
@@ -320,7 +320,7 @@ func (hs *HTTPServer) registerRoutes() {
apiRoute
.
Get
(
"/search/"
,
Search
)
// metrics
apiRoute
.
Post
(
"/tsdb/query"
,
bind
(
dtos
.
MetricRequest
{}),
Wrap
(
QueryMetrics
))
apiRoute
.
Post
(
"/tsdb/query"
,
bind
(
dtos
.
MetricRequest
{}),
Wrap
(
hs
.
QueryMetrics
))
apiRoute
.
Get
(
"/tsdb/testdata/scenarios"
,
Wrap
(
GetTestDataScenarios
))
apiRoute
.
Get
(
"/tsdb/testdata/gensql"
,
reqGrafanaAdmin
,
Wrap
(
GenerateSQLTestData
))
apiRoute
.
Get
(
"/tsdb/testdata/random-walk"
,
Wrap
(
GetTestDataRandomWalk
))
...
...
pkg/api/dataproxy.go
View file @
0e9a6dce
...
...
@@ -13,19 +13,20 @@ import (
const
HeaderNameNoBackendCache
=
"X-Grafana-NoCache"
func
(
hs
*
HTTPServer
)
getDatasourceByID
(
id
int64
,
orgID
int64
,
nocache
bool
)
(
*
m
.
DataSource
,
error
)
{
func
(
hs
*
HTTPServer
)
getDatasourceFromCache
(
id
int64
,
c
*
m
.
ReqContext
)
(
*
m
.
DataSource
,
error
)
{
nocache
:=
c
.
Req
.
Header
.
Get
(
HeaderNameNoBackendCache
)
==
"true"
cacheKey
:=
fmt
.
Sprintf
(
"ds-%d"
,
id
)
if
!
nocache
{
if
cached
,
found
:=
hs
.
cache
.
Get
(
cacheKey
);
found
{
ds
:=
cached
.
(
*
m
.
DataSource
)
if
ds
.
OrgId
==
orgID
{
if
ds
.
OrgId
==
c
.
OrgId
{
return
ds
,
nil
}
}
}
query
:=
m
.
GetDataSourceByIdQuery
{
Id
:
id
,
OrgId
:
orgID
}
query
:=
m
.
GetDataSourceByIdQuery
{
Id
:
id
,
OrgId
:
c
.
OrgId
}
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -37,10 +38,7 @@ func (hs *HTTPServer) getDatasourceByID(id int64, orgID int64, nocache bool) (*m
func
(
hs
*
HTTPServer
)
ProxyDataSourceRequest
(
c
*
m
.
ReqContext
)
{
c
.
TimeRequest
(
metrics
.
M_DataSource_ProxyReq_Timer
)
nocache
:=
c
.
Req
.
Header
.
Get
(
HeaderNameNoBackendCache
)
==
"true"
ds
,
err
:=
hs
.
getDatasourceByID
(
c
.
ParamsInt64
(
":id"
),
c
.
OrgId
,
nocache
)
ds
,
err
:=
hs
.
getDatasourceFromCache
(
c
.
ParamsInt64
(
":id"
),
c
)
if
err
!=
nil
{
c
.
JsonApiErr
(
500
,
"Unable to load datasource meta data"
,
err
)
return
...
...
pkg/api/metrics.go
View file @
0e9a6dce
...
...
@@ -13,21 +13,21 @@ import (
)
// POST /api/tsdb/query
func
QueryMetrics
(
c
*
m
.
ReqContext
,
reqDto
dtos
.
MetricRequest
)
Response
{
func
(
hs
*
HTTPServer
)
QueryMetrics
(
c
*
m
.
ReqContext
,
reqDto
dtos
.
MetricRequest
)
Response
{
timeRange
:=
tsdb
.
NewTimeRange
(
reqDto
.
From
,
reqDto
.
To
)
if
len
(
reqDto
.
Queries
)
==
0
{
return
Error
(
400
,
"No queries found in query"
,
nil
)
}
d
sID
,
err
:=
reqDto
.
Queries
[
0
]
.
Get
(
"datasourceId"
)
.
Int64
()
d
atasourceId
,
err
:=
reqDto
.
Queries
[
0
]
.
Get
(
"datasourceId"
)
.
Int64
()
if
err
!=
nil
{
return
Error
(
400
,
"Query missing datasourceId"
,
nil
)
}
ds
Query
:=
m
.
GetDataSourceByIdQuery
{
Id
:
dsID
,
OrgId
:
c
.
OrgId
}
if
err
:=
bus
.
Dispatch
(
&
dsQuery
);
err
!=
nil
{
return
Error
(
500
,
"
failed to fetch data source
"
,
err
)
ds
,
err
:=
hs
.
getDatasourceFromCache
(
datasourceId
,
c
)
if
err
!=
nil
{
return
Error
(
500
,
"
Unable to load datasource meta data
"
,
err
)
}
request
:=
&
tsdb
.
TsdbQuery
{
TimeRange
:
timeRange
}
...
...
@@ -38,11 +38,11 @@ func QueryMetrics(c *m.ReqContext, reqDto dtos.MetricRequest) Response {
MaxDataPoints
:
query
.
Get
(
"maxDataPoints"
)
.
MustInt64
(
100
),
IntervalMs
:
query
.
Get
(
"intervalMs"
)
.
MustInt64
(
1000
),
Model
:
query
,
DataSource
:
ds
Query
.
Result
,
DataSource
:
ds
,
})
}
resp
,
err
:=
tsdb
.
HandleRequest
(
c
ontext
.
Background
(),
dsQuery
.
Result
,
request
)
resp
,
err
:=
tsdb
.
HandleRequest
(
c
.
Req
.
Context
(),
ds
,
request
)
if
err
!=
nil
{
return
Error
(
500
,
"Metric request error"
,
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