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
13921902
Unverified
Commit
13921902
authored
Aug 15, 2018
by
Marcus Efraimsson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set User-Agent header in all proxied datasource requests
Header value will be Grafana/%version%, i.e. Grafana/5.3.0
parent
4f704cec
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
8 deletions
+9
-8
pkg/api/pluginproxy/ds_proxy.go
+1
-1
pkg/api/pluginproxy/ds_proxy_test.go
+8
-7
No files found.
pkg/api/pluginproxy/ds_proxy.go
View file @
13921902
...
@@ -203,7 +203,7 @@ func (proxy *DataSourceProxy) getDirector() func(req *http.Request) {
...
@@ -203,7 +203,7 @@ func (proxy *DataSourceProxy) getDirector() func(req *http.Request) {
req
.
Header
.
Del
(
"X-Forwarded-Host"
)
req
.
Header
.
Del
(
"X-Forwarded-Host"
)
req
.
Header
.
Del
(
"X-Forwarded-Port"
)
req
.
Header
.
Del
(
"X-Forwarded-Port"
)
req
.
Header
.
Del
(
"X-Forwarded-Proto"
)
req
.
Header
.
Del
(
"X-Forwarded-Proto"
)
req
.
Header
.
Set
(
"User-Agent"
,
fmt
.
Sprintf
(
"Grafana/%s
Proxied-DS-Request %s"
,
setting
.
BuildVersion
,
proxy
.
ds
.
Type
))
req
.
Header
.
Set
(
"User-Agent"
,
fmt
.
Sprintf
(
"Grafana/%s
"
,
setting
.
BuildVersion
))
// set X-Forwarded-For header
// set X-Forwarded-For header
if
req
.
RemoteAddr
!=
""
{
if
req
.
RemoteAddr
!=
""
{
...
...
pkg/api/pluginproxy/ds_proxy_test.go
View file @
13921902
...
@@ -212,20 +212,21 @@ func TestDSRouteRule(t *testing.T) {
...
@@ -212,20 +212,21 @@ func TestDSRouteRule(t *testing.T) {
})
})
Convey
(
"When proxying graphite"
,
func
()
{
Convey
(
"When proxying graphite"
,
func
()
{
setting
.
BuildVersion
=
"5.3.0"
plugin
:=
&
plugins
.
DataSourcePlugin
{}
plugin
:=
&
plugins
.
DataSourcePlugin
{}
ds
:=
&
m
.
DataSource
{
Url
:
"htttp://graphite:8080"
,
Type
:
m
.
DS_GRAPHITE
}
ds
:=
&
m
.
DataSource
{
Url
:
"htttp://graphite:8080"
,
Type
:
m
.
DS_GRAPHITE
}
ctx
:=
&
m
.
ReqContext
{}
ctx
:=
&
m
.
ReqContext
{}
proxy
:=
NewDataSourceProxy
(
ds
,
plugin
,
ctx
,
"/render"
)
proxy
:=
NewDataSourceProxy
(
ds
,
plugin
,
ctx
,
"/render"
)
req
,
err
:=
http
.
NewRequest
(
http
.
MethodGet
,
"http://grafana.com/sub"
,
nil
)
So
(
err
,
ShouldBeNil
)
requestURL
,
_
:=
url
.
Parse
(
"http://grafana.com/sub"
)
proxy
.
getDirector
()(
req
)
req
:=
http
.
Request
{
URL
:
requestURL
,
Header
:
http
.
Header
{}}
proxy
.
getDirector
()(
&
req
)
Convey
(
"Can translate request url and path"
,
func
()
{
Convey
(
"Can translate request url and path"
,
func
()
{
So
(
req
.
URL
.
Host
,
ShouldEqual
,
"graphite:8080"
)
So
(
req
.
URL
.
Host
,
ShouldEqual
,
"graphite:8080"
)
So
(
req
.
URL
.
Path
,
ShouldEqual
,
"/render"
)
So
(
req
.
URL
.
Path
,
ShouldEqual
,
"/render"
)
So
(
req
.
Header
.
Get
(
"User-Agent"
),
ShouldEqual
,
"Grafana/5.3.0"
)
})
})
})
})
...
@@ -243,10 +244,10 @@ func TestDSRouteRule(t *testing.T) {
...
@@ -243,10 +244,10 @@ func TestDSRouteRule(t *testing.T) {
ctx
:=
&
m
.
ReqContext
{}
ctx
:=
&
m
.
ReqContext
{}
proxy
:=
NewDataSourceProxy
(
ds
,
plugin
,
ctx
,
""
)
proxy
:=
NewDataSourceProxy
(
ds
,
plugin
,
ctx
,
""
)
req
uestURL
,
_
:=
url
.
Parse
(
"http://grafana.com/sub"
)
req
,
err
:=
http
.
NewRequest
(
http
.
MethodGet
,
"http://grafana.com/sub"
,
nil
)
req
:=
http
.
Request
{
URL
:
requestURL
,
Header
:
http
.
Header
{}}
So
(
err
,
ShouldBeNil
)
proxy
.
getDirector
()(
&
req
)
proxy
.
getDirector
()(
req
)
Convey
(
"Should add db to url"
,
func
()
{
Convey
(
"Should add db to url"
,
func
()
{
So
(
req
.
URL
.
Path
,
ShouldEqual
,
"/db/site/"
)
So
(
req
.
URL
.
Path
,
ShouldEqual
,
"/db/site/"
)
...
...
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