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
c99d6bd5
Unverified
Commit
c99d6bd5
authored
Apr 25, 2018
by
David
Committed by
GitHub
Apr 25, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #11678 from grafana/davkal/11673-silent-response
Add silent option to backend requests
parents
f2b5b6f2
707700ac
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
15 deletions
+44
-15
public/app/core/services/backend_srv.ts
+6
-3
public/app/plugins/datasource/prometheus/datasource.ts
+14
-8
public/app/plugins/datasource/prometheus/metric_find_query.ts
+4
-4
public/app/plugins/datasource/prometheus/specs/datasource.jest.ts
+20
-0
No files found.
public/app/core/services/backend_srv.ts
View file @
c99d6bd5
...
...
@@ -170,7 +170,9 @@ export class BackendSrv {
return
this
.
$http
(
options
)
.
then
(
response
=>
{
appEvents
.
emit
(
'ds-request-response'
,
response
);
if
(
!
options
.
silent
)
{
appEvents
.
emit
(
'ds-request-response'
,
response
);
}
return
response
;
})
.
catch
(
err
=>
{
...
...
@@ -201,8 +203,9 @@ export class BackendSrv {
if
(
err
.
data
&&
!
err
.
data
.
message
&&
_
.
isString
(
err
.
data
.
error
))
{
err
.
data
.
message
=
err
.
data
.
error
;
}
appEvents
.
emit
(
'ds-request-error'
,
err
);
if
(
!
options
.
silent
)
{
appEvents
.
emit
(
'ds-request-error'
,
err
);
}
throw
err
;
})
.
finally
(()
=>
{
...
...
public/app/plugins/datasource/prometheus/datasource.ts
View file @
c99d6bd5
...
...
@@ -5,6 +5,7 @@ import kbn from 'app/core/utils/kbn';
import
*
as
dateMath
from
'app/core/utils/datemath'
;
import
PrometheusMetricFindQuery
from
'./metric_find_query'
;
import
{
ResultTransformer
}
from
'./result_transformer'
;
import
{
BackendSrv
}
from
'app/core/services/backend_srv'
;
export
function
prometheusRegularEscape
(
value
)
{
return
value
.
replace
(
/'/g
,
"
\\\\
'"
);
...
...
@@ -29,7 +30,7 @@ export class PrometheusDatasource {
resultTransformer: ResultTransformer;
/** @ngInject */
constructor(instanceSettings, private $q, private backendSrv, private templateSrv, private timeSrv) {
constructor(instanceSettings, private $q, private backendSrv
: BackendSrv
, private templateSrv, private timeSrv) {
this.type = '
prometheus
';
this.editorSrc = '
app
/
features
/
prometheus
/
partials
/
query
.
editor
.
html
';
this.name = instanceSettings.name;
...
...
@@ -43,13 +44,13 @@ export class PrometheusDatasource {
this.resultTransformer = new ResultTransformer(templateSrv);
}
_request(
method, url, data?, requestId?
) {
_request(
url, data?, options?: any
) {
var options: any = {
url: this.url + url,
method:
m
ethod,
requestId: requestId
,
method:
this.httpM
ethod,
...options
,
};
if (method === '
GET
') {
if (
options.
method === '
GET
') {
if (!_.isEmpty(data)) {
options.url =
options.url +
...
...
@@ -81,6 +82,11 @@ export class PrometheusDatasource {
return this.backendSrv.datasourceRequest(options);
}
// Use this for tab completion features, wont publish response to other components
metadataRequest(url) {
return this._request(url, null, { method: '
GET
', silent: true });
}
interpolateQueryExpr(value, variable, defaultFormatFn) {
// if no multi or include all do not regexEscape
if (!variable.multi && !variable.includeAll) {
...
...
@@ -206,7 +212,7 @@ export class PrometheusDatasource {
end: end,
step: query.step,
};
return this._request(
this.httpMethod, url, data, query.requestId
);
return this._request(
url, data, { requestId: query.requestId }
);
}
performInstantQuery(query, time) {
...
...
@@ -215,7 +221,7 @@ export class PrometheusDatasource {
query: query.expr,
time: time,
};
return this._request(
this.httpMethod, url, data, query.requestId
);
return this._request(
url, data, { requestId: query.requestId }
);
}
performSuggestQuery(query, cache = false) {
...
...
@@ -229,7 +235,7 @@ export class PrometheusDatasource {
);
}
return this.
_request('
GET
',
url).then(result => {
return this.
metadataRequest(
url).then(result => {
this.metricsNameCache = {
data: result.data.data,
expire: Date.now() + 60 * 1000,
...
...
public/app/plugins/datasource/prometheus/metric_find_query.ts
View file @
c99d6bd5
...
...
@@ -46,7 +46,7 @@ export default class PrometheusMetricFindQuery {
// return label values globally
url
=
'/api/v1/label/'
+
label
+
'/values'
;
return
this
.
datasource
.
_request
(
'GET'
,
url
).
then
(
function
(
result
)
{
return
this
.
datasource
.
metadataRequest
(
url
).
then
(
function
(
result
)
{
return
_
.
map
(
result
.
data
.
data
,
function
(
value
)
{
return
{
text
:
value
};
});
...
...
@@ -56,7 +56,7 @@ export default class PrometheusMetricFindQuery {
var
end
=
this
.
datasource
.
getPrometheusTime
(
this
.
range
.
to
,
true
);
url
=
'/api/v1/series?match[]='
+
encodeURIComponent
(
metric
)
+
'&start='
+
start
+
'&end='
+
end
;
return
this
.
datasource
.
_request
(
'GET'
,
url
).
then
(
function
(
result
)
{
return
this
.
datasource
.
metadataRequest
(
url
).
then
(
function
(
result
)
{
var
_labels
=
_
.
map
(
result
.
data
.
data
,
function
(
metric
)
{
return
metric
[
label
]
||
''
;
}).
filter
(
function
(
label
)
{
...
...
@@ -76,7 +76,7 @@ export default class PrometheusMetricFindQuery {
metricNameQuery
(
metricFilterPattern
)
{
var
url
=
'/api/v1/label/__name__/values'
;
return
this
.
datasource
.
_request
(
'GET'
,
url
).
then
(
function
(
result
)
{
return
this
.
datasource
.
metadataRequest
(
url
).
then
(
function
(
result
)
{
return
_
.
chain
(
result
.
data
.
data
)
.
filter
(
function
(
metricName
)
{
var
r
=
new
RegExp
(
metricFilterPattern
);
...
...
@@ -120,7 +120,7 @@ export default class PrometheusMetricFindQuery {
var
url
=
'/api/v1/series?match[]='
+
encodeURIComponent
(
query
)
+
'&start='
+
start
+
'&end='
+
end
;
var
self
=
this
;
return
this
.
datasource
.
_request
(
'GET'
,
url
).
then
(
function
(
result
)
{
return
this
.
datasource
.
metadataRequest
(
url
).
then
(
function
(
result
)
{
return
_
.
map
(
result
.
data
.
data
,
function
(
metric
)
{
return
{
text
:
self
.
datasource
.
getOriginalMetricName
(
metric
),
...
...
public/app/plugins/datasource/prometheus/specs/datasource.jest.ts
View file @
c99d6bd5
...
...
@@ -14,6 +14,7 @@ describe('PrometheusDatasource', () => {
};
ctx
.
backendSrvMock
=
{};
ctx
.
templateSrvMock
=
{
replace
:
a
=>
a
,
};
...
...
@@ -23,6 +24,25 @@ describe('PrometheusDatasource', () => {
ctx
.
ds
=
new
PrometheusDatasource
(
instanceSettings
,
q
,
ctx
.
backendSrvMock
,
ctx
.
templateSrvMock
,
ctx
.
timeSrvMock
);
});
describe
(
'Datasource metadata requests'
,
()
=>
{
it
(
'should perform a GET request with the default config'
,
()
=>
{
ctx
.
backendSrvMock
.
datasourceRequest
=
jest
.
fn
();
ctx
.
ds
.
metadataRequest
(
'/foo'
);
expect
(
ctx
.
backendSrvMock
.
datasourceRequest
.
mock
.
calls
.
length
).
toBe
(
1
);
expect
(
ctx
.
backendSrvMock
.
datasourceRequest
.
mock
.
calls
[
0
][
0
].
method
).
toBe
(
'GET'
);
});
it
(
'should still perform a GET request with the DS HTTP method set to POST'
,
()
=>
{
ctx
.
backendSrvMock
.
datasourceRequest
=
jest
.
fn
();
const
postSettings
=
_
.
cloneDeep
(
instanceSettings
);
postSettings
.
jsonData
.
httpMethod
=
'POST'
;
const
ds
=
new
PrometheusDatasource
(
postSettings
,
q
,
ctx
.
backendSrvMock
,
ctx
.
templateSrvMock
,
ctx
.
timeSrvMock
);
ds
.
metadataRequest
(
'/foo'
);
expect
(
ctx
.
backendSrvMock
.
datasourceRequest
.
mock
.
calls
.
length
).
toBe
(
1
);
expect
(
ctx
.
backendSrvMock
.
datasourceRequest
.
mock
.
calls
[
0
][
0
].
method
).
toBe
(
'GET'
);
});
});
describe
(
'When converting prometheus histogram to heatmap format'
,
()
=>
{
beforeEach
(()
=>
{
ctx
.
query
=
{
...
...
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