mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Explore: fix metric selector for additional rows
- race condition in language provider leads to only one row getting selector options - fixed by always returning the start task promise
This commit is contained in:
parent
74c9defede
commit
edd575b552
@ -95,9 +95,9 @@ class LoggingQueryField extends React.PureComponent<LoggingQueryFieldProps, Logg
|
|||||||
this.languageProvider
|
this.languageProvider
|
||||||
.start()
|
.start()
|
||||||
.then(remaining => {
|
.then(remaining => {
|
||||||
remaining.map(task => task.then(this.onReceiveMetrics).catch(() => {}));
|
remaining.map(task => task.then(this.onUpdateLanguage).catch(() => {}));
|
||||||
})
|
})
|
||||||
.then(() => this.onReceiveMetrics());
|
.then(() => this.onUpdateLanguage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ class LoggingQueryField extends React.PureComponent<LoggingQueryFieldProps, Logg
|
|||||||
|
|
||||||
this.languageProvider
|
this.languageProvider
|
||||||
.fetchLabelValues(targetOption.value)
|
.fetchLabelValues(targetOption.value)
|
||||||
.then(this.onReceiveMetrics)
|
.then(this.onUpdateLanguage)
|
||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -147,7 +147,7 @@ class LoggingQueryField extends React.PureComponent<LoggingQueryFieldProps, Logg
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
onReceiveMetrics = () => {
|
onUpdateLanguage = () => {
|
||||||
Prism.languages[PRISM_SYNTAX] = this.languageProvider.getSyntax();
|
Prism.languages[PRISM_SYNTAX] = this.languageProvider.getSyntax();
|
||||||
const { logLabelOptions } = this.languageProvider;
|
const { logLabelOptions } = this.languageProvider;
|
||||||
this.setState({
|
this.setState({
|
||||||
|
@ -47,7 +47,6 @@ export default class LoggingLanguageProvider extends LanguageProvider {
|
|||||||
this.datasource = datasource;
|
this.datasource = datasource;
|
||||||
this.labelKeys = {};
|
this.labelKeys = {};
|
||||||
this.labelValues = {};
|
this.labelValues = {};
|
||||||
this.started = false;
|
|
||||||
|
|
||||||
Object.assign(this, initialValues);
|
Object.assign(this, initialValues);
|
||||||
}
|
}
|
||||||
@ -63,11 +62,10 @@ export default class LoggingLanguageProvider extends LanguageProvider {
|
|||||||
};
|
};
|
||||||
|
|
||||||
start = () => {
|
start = () => {
|
||||||
if (!this.started) {
|
if (!this.startTask) {
|
||||||
this.started = true;
|
this.startTask = this.fetchLogLabels();
|
||||||
return this.fetchLogLabels();
|
|
||||||
}
|
}
|
||||||
return Promise.resolve([]);
|
return this.startTask;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Keep this DOM-free for testing
|
// Keep this DOM-free for testing
|
||||||
|
@ -134,9 +134,9 @@ class PromQueryField extends React.PureComponent<PromQueryFieldProps, PromQueryF
|
|||||||
this.languageProvider
|
this.languageProvider
|
||||||
.start()
|
.start()
|
||||||
.then(remaining => {
|
.then(remaining => {
|
||||||
remaining.map(task => task.then(this.onReceiveMetrics).catch(() => {}));
|
remaining.map(task => task.then(this.onUpdateLanguage).catch(() => {}));
|
||||||
})
|
})
|
||||||
.then(() => this.onReceiveMetrics());
|
.then(() => this.onUpdateLanguage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,7 +176,7 @@ class PromQueryField extends React.PureComponent<PromQueryFieldProps, PromQueryF
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
onReceiveMetrics = () => {
|
onUpdateLanguage = () => {
|
||||||
const { histogramMetrics, metrics } = this.languageProvider;
|
const { histogramMetrics, metrics } = this.languageProvider;
|
||||||
if (!metrics) {
|
if (!metrics) {
|
||||||
return;
|
return;
|
||||||
|
@ -46,7 +46,7 @@ export default class PromQlLanguageProvider extends LanguageProvider {
|
|||||||
labelKeys?: { [index: string]: string[] }; // metric -> [labelKey,...]
|
labelKeys?: { [index: string]: string[] }; // metric -> [labelKey,...]
|
||||||
labelValues?: { [index: string]: { [index: string]: string[] } }; // metric -> labelKey -> [labelValue,...]
|
labelValues?: { [index: string]: { [index: string]: string[] } }; // metric -> labelKey -> [labelValue,...]
|
||||||
metrics?: string[];
|
metrics?: string[];
|
||||||
started: boolean;
|
startTask: Promise<any>;
|
||||||
|
|
||||||
constructor(datasource: any, initialValues?: any) {
|
constructor(datasource: any, initialValues?: any) {
|
||||||
super();
|
super();
|
||||||
@ -56,7 +56,6 @@ export default class PromQlLanguageProvider extends LanguageProvider {
|
|||||||
this.labelKeys = {};
|
this.labelKeys = {};
|
||||||
this.labelValues = {};
|
this.labelValues = {};
|
||||||
this.metrics = [];
|
this.metrics = [];
|
||||||
this.started = false;
|
|
||||||
|
|
||||||
Object.assign(this, initialValues);
|
Object.assign(this, initialValues);
|
||||||
}
|
}
|
||||||
@ -72,11 +71,10 @@ export default class PromQlLanguageProvider extends LanguageProvider {
|
|||||||
};
|
};
|
||||||
|
|
||||||
start = () => {
|
start = () => {
|
||||||
if (!this.started) {
|
if (!this.startTask) {
|
||||||
this.started = true;
|
this.startTask = this.fetchMetricNames().then(() => [this.fetchHistogramMetrics()]);
|
||||||
return this.fetchMetricNames().then(() => [this.fetchHistogramMetrics()]);
|
|
||||||
}
|
}
|
||||||
return Promise.resolve([]);
|
return this.startTask;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Keep this DOM-free for testing
|
// Keep this DOM-free for testing
|
||||||
|
@ -86,10 +86,11 @@ export abstract class LanguageProvider {
|
|||||||
datasource: any;
|
datasource: any;
|
||||||
request: (url) => Promise<any>;
|
request: (url) => Promise<any>;
|
||||||
/**
|
/**
|
||||||
* Returns a promise that resolves with a task list when main syntax is loaded.
|
* Returns startTask that resolves with a task list when main syntax is loaded.
|
||||||
* Task list consists of secondary promises that load more detailed language features.
|
* Task list consists of secondary promises that load more detailed language features.
|
||||||
*/
|
*/
|
||||||
start: () => Promise<any[]>;
|
start: () => Promise<any[]>;
|
||||||
|
startTask?: Promise<any[]>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TypeaheadInput {
|
export interface TypeaheadInput {
|
||||||
|
Loading…
Reference in New Issue
Block a user