Prometheus: disable dynamic label lookup on big datasources (#20936)

* Prometheus: disable dynamic label lookup on big datasources

- when a prometheus datasource has more than 10000 metrics, label lookup
for the query field is disabled
- installations of that size have slow typehead lookup times and make
the editor sluggish

* Raise dynamic lookup threshold to 10000 metrics

* Run start tasks again
This commit is contained in:
David
2019-12-09 17:02:17 +01:00
committed by GitHub
parent 7665dcc867
commit 1a2dad9d0c
3 changed files with 93 additions and 25 deletions

View File

@@ -23,7 +23,6 @@ import { PrometheusDatasource } from '../datasource';
import PromQlLanguageProvider from '../language_provider';
const HISTOGRAM_GROUP = '__histograms__';
const METRIC_MARK = 'metric';
const PRISM_SYNTAX = 'promql';
export const RECORDING_RULES_GROUP = '__recording_rules__';
@@ -138,6 +137,7 @@ class PromQueryField extends React.PureComponent<PromQueryFieldProps, PromQueryF
componentDidMount() {
if (this.languageProvider) {
Prism.languages[PRISM_SYNTAX] = this.languageProvider.syntax;
this.refreshMetrics(makePromiseCancelable(this.languageProvider.start()));
}
this.refreshHint();
@@ -228,17 +228,11 @@ class PromQueryField extends React.PureComponent<PromQueryFieldProps, PromQueryF
};
onUpdateLanguage = () => {
const { histogramMetrics, metrics } = this.languageProvider;
const { histogramMetrics, metrics, lookupsDisabled, lookupMetricsThreshold } = this.languageProvider;
if (!metrics) {
return;
}
Prism.languages[PRISM_SYNTAX] = this.languageProvider.syntax;
Prism.languages[PRISM_SYNTAX][METRIC_MARK] = {
alias: 'variable',
pattern: new RegExp(`(?:^|\\s)(${metrics.join('|')})(?:$|\\s)`),
};
// Build metrics tree
const metricsByPrefix = groupMetricsByPrefix(metrics);
const histogramOptions = histogramMetrics.map((hm: any) => ({ label: hm, value: hm }));
@@ -250,7 +244,16 @@ class PromQueryField extends React.PureComponent<PromQueryFieldProps, PromQueryF
]
: metricsByPrefix;
this.setState({ metricsOptions, syntaxLoaded: true });
// Hint for big disabled lookups
let hint: QueryHint;
if (lookupsDisabled) {
hint = {
label: `Dynamic label lookup is disabled for datasources with more than ${lookupMetricsThreshold} metrics.`,
type: 'INFO',
};
}
this.setState({ hint, metricsOptions, syntaxLoaded: true });
};
onTypeahead = async (typeahead: TypeaheadInput): Promise<TypeaheadOutput> => {