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
f2574f49
Unverified
Commit
f2574f49
authored
Nov 28, 2019
by
Andrej Ocenas
Committed by
GitHub
Nov 28, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prometheus: Fix caching for default labels request (#20718)
parent
130fb02b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
7 deletions
+36
-7
public/app/plugins/datasource/prometheus/language_provider.test.ts
+27
-3
public/app/plugins/datasource/prometheus/language_provider.ts
+9
-4
No files found.
public/app/plugins/datasource/prometheus/
specs/
language_provider.test.ts
→
public/app/plugins/datasource/prometheus/language_provider.test.ts
View file @
f2574f49
import
Plain
from
'slate-plain-serializer'
;
import
{
Editor
as
SlateEditor
}
from
'slate'
;
import
LanguageProvider
from
'.
.
/language_provider'
;
import
{
PrometheusDatasource
}
from
'.
.
/datasource'
;
import
LanguageProvider
from
'./language_provider'
;
import
{
PrometheusDatasource
}
from
'./datasource'
;
import
{
HistoryItem
}
from
'@grafana/data'
;
import
{
PromQuery
}
from
'../types'
;
import
{
PromQuery
}
from
'./types'
;
import
Mock
=
jest
.
Mock
;
describe
(
'Language completion provider'
,
()
=>
{
const
datasource
:
PrometheusDatasource
=
({
...
...
@@ -411,5 +412,28 @@ describe('Language completion provider', () => {
},
]);
});
it
(
'does not re-fetch default labels'
,
async
()
=>
{
const
datasource
:
PrometheusDatasource
=
({
metadataRequest
:
jest
.
fn
(()
=>
({
data
:
{
data
:
[]
as
any
[]
}
})),
getTimeRange
:
jest
.
fn
(()
=>
({
start
:
0
,
end
:
1
})),
}
as
any
)
as
PrometheusDatasource
;
const
instance
=
new
LanguageProvider
(
datasource
);
const
value
=
Plain
.
deserialize
(
'{}'
);
const
ed
=
new
SlateEditor
({
value
});
const
valueWithSelection
=
ed
.
moveForward
(
1
).
value
;
const
args
=
{
text
:
''
,
prefix
:
''
,
wrapperClasses
:
[
'context-labels'
],
value
:
valueWithSelection
,
};
await
instance
.
provideCompletionItems
(
args
);
// one call for 2 default labels job, instance
expect
((
datasource
.
metadataRequest
as
Mock
).
mock
.
calls
.
length
).
toBe
(
2
);
await
instance
.
provideCompletionItems
(
args
);
expect
((
datasource
.
metadataRequest
as
Mock
).
mock
.
calls
.
length
).
toBe
(
2
);
});
});
});
public/app/plugins/datasource/prometheus/language_provider.ts
View file @
f2574f49
...
...
@@ -308,12 +308,17 @@ export default class PromQlLanguageProvider extends LanguageProvider {
const
existingKeys
=
parsedSelector
?
parsedSelector
.
labelKeys
:
[];
// Query labels for selector
if
(
selector
&&
(
!
this
.
labelValues
[
selector
]
||
this
.
timeRangeChanged
())
)
{
if
(
selector
)
{
if
(
selector
===
EMPTY_SELECTOR
)
{
// Query label values for default labels
await
Promise
.
all
(
DEFAULT_KEYS
.
map
(
key
=>
this
.
fetchLabelValues
(
key
)));
// For empty selector we do not need to check range
if
(
!
this
.
labelValues
[
selector
])
{
// Query label values for default labels
await
Promise
.
all
(
DEFAULT_KEYS
.
map
(
key
=>
this
.
fetchLabelValues
(
key
)));
}
}
else
{
await
this
.
fetchSeriesLabels
(
selector
,
!
containsMetric
);
if
(
!
this
.
labelValues
[
selector
]
||
this
.
timeRangeChanged
())
{
await
this
.
fetchSeriesLabels
(
selector
,
!
containsMetric
);
}
}
}
...
...
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