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
16107f37
Unverified
Commit
16107f37
authored
Nov 26, 2020
by
Alexandru Bumbacea
Committed by
GitHub
Nov 26, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
* prometheus fix variables fetching when customQueryParameters used #28907 (#28949)
parent
b904e0c6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
4 deletions
+36
-4
public/app/plugins/datasource/prometheus/configuration/PromSettings.tsx
+1
-1
public/app/plugins/datasource/prometheus/datasource.test.ts
+27
-1
public/app/plugins/datasource/prometheus/datasource.ts
+8
-2
No files found.
public/app/plugins/datasource/prometheus/configuration/PromSettings.tsx
View file @
16107f37
...
...
@@ -90,7 +90,7 @@ export const PromSettings = (props: Props) => {
<
FormField
label=
"Custom query parameters"
labelWidth=
{
14
}
tooltip=
"Add Custom parameters to Prometheus or Thanos queries."
tooltip=
"Add Custom parameters to
all
Prometheus or Thanos queries."
inputEl=
{
<
Input
className=
"width-25"
...
...
public/app/plugins/datasource/prometheus/datasource.test.ts
View file @
16107f37
...
...
@@ -59,7 +59,9 @@ describe('PrometheusDatasource', () => {
directUrl
:
'direct'
,
user
:
'test'
,
password
:
'mupp'
,
jsonData
:
{}
as
any
,
jsonData
:
{
customQueryParameters
:
''
,
}
as
any
,
}
as
unknown
)
as
DataSourceInstanceSettings
<
PromOptions
>
;
beforeEach
(()
=>
{
...
...
@@ -141,6 +143,30 @@ describe('PrometheusDatasource', () => {
});
});
describe
(
'When using customQueryParams'
,
()
=>
{
const
promDs
=
new
PrometheusDatasource
(
{
...
instanceSettings
,
jsonData
:
{
customQueryParameters
:
'customQuery=123'
}
as
any
},
templateSrvStub
as
any
,
timeSrvStub
as
any
);
it
(
'added to metadata request'
,
()
=>
{
promDs
.
metadataRequest
(
'/foo'
);
expect
(
fetchMock
.
mock
.
calls
.
length
).
toBe
(
1
);
expect
(
fetchMock
.
mock
.
calls
[
0
][
0
].
url
).
toBe
(
'proxied/foo?customQuery=123'
);
});
it
(
'added to query'
,
()
=>
{
promDs
.
query
({
range
:
{
from
:
time
({
seconds
:
63
}),
to
:
time
({
seconds
:
183
})
},
targets
:
[{
expr
:
'test{job="testjob"}'
,
format
:
'time_series'
}],
interval
:
'60s'
,
}
as
any
);
expect
(
fetchMock
.
mock
.
calls
.
length
).
toBe
(
1
);
expect
(
fetchMock
.
mock
.
calls
[
0
][
0
].
url
).
toBe
(
'proxied/api/v1/query_range?query=test%7Bjob%3D%22testjob%22%7D&start=60&end=180&step=60&customQuery=123'
);
});
});
describe
(
'When using adhoc filters'
,
()
=>
{
const
DEFAULT_QUERY_EXPRESSION
=
'metric{job="foo"} - metric'
;
const
target
=
{
expr
:
DEFAULT_QUERY_EXPRESSION
};
...
...
public/app/plugins/datasource/prometheus/datasource.ts
View file @
16107f37
...
...
@@ -111,7 +111,7 @@ export class PrometheusDatasource extends DataSourceApi<PromQuery, PromOptions>
if
(
data
&&
Object
.
keys
(
data
).
length
)
{
options
.
url
=
options
.
url
+
'?'
+
(
options
.
url
.
search
(
/
\?
/
)
>=
0
?
'&'
:
'?'
)
+
Object
.
entries
(
data
)
.
map
(([
k
,
v
])
=>
`
${
encodeURIComponent
(
k
)}
=
${
encodeURIComponent
(
v
)}
`
)
.
join
(
'&'
);
...
...
@@ -134,7 +134,13 @@ export class PrometheusDatasource extends DataSourceApi<PromQuery, PromOptions>
// Use this for tab completion features, wont publish response to other components
metadataRequest
<
T
=
any
>
(
url
:
string
)
{
return
this
.
_request
<
T
>
(
url
,
null
,
{
method
:
'GET'
,
hideFromInspector
:
true
}).
toPromise
();
// toPromise until we change getTagValues, getTagKeys to Observable
const
data
:
any
=
{};
for
(
const
[
key
,
value
]
of
this
.
customQueryParameters
)
{
if
(
data
[
key
]
==
null
)
{
data
[
key
]
=
value
;
}
}
return
this
.
_request
<
T
>
(
url
,
data
,
{
method
:
'GET'
,
hideFromInspector
:
true
}).
toPromise
();
// toPromise until we change getTagValues, getTagKeys to Observable
}
interpolateQueryExpr
(
value
:
string
|
string
[]
=
[],
variable
:
any
)
{
...
...
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