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
76ab0aa0
Commit
76ab0aa0
authored
Apr 30, 2019
by
Stanislav Putrya
Committed by
Carl Bergquist
Apr 30, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tracing headers for prometheus datasource (#16724)
Prometheus: Adds tracing headers for Prometheus datasource
parent
0433af63
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
8 deletions
+37
-8
public/app/plugins/datasource/prometheus/datasource.ts
+14
-8
public/app/plugins/datasource/prometheus/specs/datasource.test.ts
+23
-0
No files found.
public/app/plugins/datasource/prometheus/datasource.ts
View file @
76ab0aa0
...
...
@@ -59,6 +59,15 @@ export class PrometheusDatasource implements DataSourceApi<PromQuery> {
return
query
.
expr
;
}
_addTracingHeaders
(
httpOptions
:
any
,
options
:
any
)
{
httpOptions
.
headers
=
options
.
headers
||
{};
const
proxyMode
=
!
this
.
url
.
match
(
/^http/
);
if
(
proxyMode
)
{
httpOptions
.
headers
[
'X-Dashboard-Id'
]
=
options
.
dashboardId
;
httpOptions
.
headers
[
'X-Panel-Id'
]
=
options
.
panelId
;
}
}
_request
(
url
,
data
?,
options
?:
any
)
{
options
=
_
.
defaults
(
options
||
{},
{
url
:
this
.
url
+
url
,
...
...
@@ -75,9 +84,7 @@ export class PrometheusDatasource implements DataSourceApi<PromQuery> {
}).
join
(
'&'
);
}
}
else
{
options
.
headers
=
{
'Content-Type'
:
'application/x-www-form-urlencoded'
,
};
options
.
headers
[
'Content-Type'
]
=
'application/x-www-form-urlencoded'
;
options
.
transformRequest
=
data
=>
{
return
$
.
param
(
data
);
};
...
...
@@ -89,9 +96,7 @@ export class PrometheusDatasource implements DataSourceApi<PromQuery> {
}
if
(
this
.
basicAuth
)
{
options
.
headers
=
{
Authorization
:
this
.
basicAuth
,
};
options
.
headers
.
Authorization
=
this
.
basicAuth
;
}
return
this
.
backendSrv
.
datasourceRequest
(
options
);
...
...
@@ -233,6 +238,7 @@ export class PrometheusDatasource implements DataSourceApi<PromQuery> {
const
adjusted
=
alignRange
(
start
,
end
,
query
.
step
);
query
.
start
=
adjusted
.
start
;
query
.
end
=
adjusted
.
end
;
this
.
_addTracingHeaders
(
query
,
options
);
return
query
;
}
...
...
@@ -261,7 +267,7 @@ export class PrometheusDatasource implements DataSourceApi<PromQuery> {
if
(
this
.
queryTimeout
)
{
data
[
'timeout'
]
=
this
.
queryTimeout
;
}
return
this
.
_request
(
url
,
data
,
{
requestId
:
query
.
requestId
});
return
this
.
_request
(
url
,
data
,
{
requestId
:
query
.
requestId
,
headers
:
query
.
headers
});
}
performInstantQuery
(
query
,
time
)
{
...
...
@@ -273,7 +279,7 @@ export class PrometheusDatasource implements DataSourceApi<PromQuery> {
if
(
this
.
queryTimeout
)
{
data
[
'timeout'
]
=
this
.
queryTimeout
;
}
return
this
.
_request
(
url
,
data
,
{
requestId
:
query
.
requestId
});
return
this
.
_request
(
url
,
data
,
{
requestId
:
query
.
requestId
,
headers
:
query
.
headers
});
}
performSuggestQuery
(
query
,
cache
=
false
)
{
...
...
public/app/plugins/datasource/prometheus/specs/datasource.test.ts
View file @
76ab0aa0
...
...
@@ -1232,4 +1232,27 @@ describe('PrometheusDatasource for POST', () => {
expect(results.data[0].target).toBe('
test
{
job
=
"testjob"
}
');
});
});
describe('
When
querying
prometheus
via
check
headers
X
-
Dashboard
-
Id
and
X
-
Panel
-
Id
', () => {
const options = { dashboardId: 1, panelId: 2 };
const httpOptions = {
headers: {},
};
it('
with
proxy
access
tracing
headers
should
be
added
', () => {
ctx.ds = new PrometheusDatasource(instanceSettings, q, backendSrv as any, templateSrv, timeSrv);
ctx.ds._addTracingHeaders(httpOptions, options);
expect(httpOptions.headers['
X
-
Dashboard
-
Id
']).toBe(1);
expect(httpOptions.headers['
X
-
Panel
-
Id
']).toBe(2);
});
it('
with
direct
access
tracing
headers
should
not
be
added
', () => {
instanceSettings.url = '
http
:
//127.0.0.1:8000';
ctx
.
ds
=
new
PrometheusDatasource
(
instanceSettings
,
q
,
backendSrv
as
any
,
templateSrv
,
timeSrv
);
ctx
.
ds
.
_addTracingHeaders
(
httpOptions
,
options
);
expect
(
httpOptions
.
headers
[
'X-Dashboard-Id'
]).
toBe
(
undefined
);
expect
(
httpOptions
.
headers
[
'X-Panel-Id'
]).
toBe
(
undefined
);
});
});
});
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