mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Prometheus: Add off switch for metric/label name lookup (#24034)
* Prometheus: Add off switch for metric/label name lookup This will help users with amounts of metric name data that is too much for a browser to handle. Autocomplete will be disabled and metrics chooser hidden, since obviously both rely on this data. Fixes #22702 * Use onUpdateDatasourceJsonDataOptionChecked ... from `@grafana/data`. Refactor naming to faciliate its use and stick with prop names as passed down from `ConfigEditor`. PLUS: - Rephrase switch label, add a tooltip and reduce the size of the to what "Custom query parameters" originally was. - Change `languageProvider` type in `PromQueryField`. * Put language provider back in Functions and history still work, even when metrics lookup gets disabled. Also: Rewording of setting. * Display a message when lookup got disabled manually * Call property for setting disableMetricsLookup * Show disabled metrics chooser instead of warning
This commit is contained in:
committed by
GitHub
parent
42ba13b346
commit
de0e1b2c58
@@ -25,13 +25,19 @@ const HISTOGRAM_GROUP = '__histograms__';
|
||||
const PRISM_SYNTAX = 'promql';
|
||||
export const RECORDING_RULES_GROUP = '__recording_rules__';
|
||||
|
||||
function getChooserText(hasSyntax: boolean, metrics: string[]) {
|
||||
function getChooserText(metricsLookupDisabled: boolean, hasSyntax: boolean, metrics: string[]) {
|
||||
if (metricsLookupDisabled) {
|
||||
return '(Disabled)';
|
||||
}
|
||||
|
||||
if (!hasSyntax) {
|
||||
return 'Loading metrics...';
|
||||
}
|
||||
|
||||
if (metrics && metrics.length === 0) {
|
||||
return '(No metrics found)';
|
||||
}
|
||||
|
||||
return 'Metrics';
|
||||
}
|
||||
|
||||
@@ -250,12 +256,10 @@ class PromQueryField extends React.PureComponent<PromQueryFieldProps, PromQueryF
|
||||
|
||||
onUpdateLanguage = () => {
|
||||
const {
|
||||
histogramMetrics,
|
||||
metrics,
|
||||
metricsMetadata,
|
||||
lookupsDisabled,
|
||||
lookupMetricsThreshold,
|
||||
} = this.props.datasource.languageProvider;
|
||||
datasource,
|
||||
datasource: { languageProvider },
|
||||
} = this.props;
|
||||
const { histogramMetrics, metrics, metricsMetadata, lookupMetricsThreshold } = languageProvider;
|
||||
|
||||
if (!metrics) {
|
||||
return;
|
||||
@@ -274,7 +278,7 @@ class PromQueryField extends React.PureComponent<PromQueryFieldProps, PromQueryF
|
||||
|
||||
// Hint for big disabled lookups
|
||||
let hint: QueryHint;
|
||||
if (lookupsDisabled) {
|
||||
if (!datasource.lookupsDisabled && languageProvider.lookupsDisabled) {
|
||||
hint = {
|
||||
label: `Dynamic label lookup is disabled for datasources with more than ${lookupMetricsThreshold} metrics.`,
|
||||
type: 'INFO',
|
||||
@@ -308,13 +312,14 @@ class PromQueryField extends React.PureComponent<PromQueryFieldProps, PromQueryF
|
||||
|
||||
render() {
|
||||
const {
|
||||
datasource,
|
||||
datasource: { languageProvider },
|
||||
query,
|
||||
ExtraFieldElement,
|
||||
} = this.props;
|
||||
const { metricsOptions, syntaxLoaded, hint } = this.state;
|
||||
const cleanText = languageProvider ? languageProvider.cleanText : undefined;
|
||||
const chooserText = getChooserText(syntaxLoaded, metricsOptions);
|
||||
const chooserText = getChooserText(datasource.lookupsDisabled, syntaxLoaded, metricsOptions);
|
||||
const buttonDisabled = !(syntaxLoaded && metricsOptions && metricsOptions.length > 0);
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user