Skip to content

Commit

Permalink
Merge pull request grafana#13927 from grafana/davkal/explore-start-task
Browse files Browse the repository at this point in the history
Explore: fix metric selector for additional rows
  • Loading branch information
davkal authored Nov 5, 2018
2 parents 24e5922 + edd575b commit 0df14f3
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ class LoggingQueryField extends React.PureComponent<LoggingQueryFieldProps, Logg
this.languageProvider
.start()
.then(remaining => {
remaining.map(task => task.then(this.onReceiveMetrics).catch(() => {}));
remaining.map(task => task.then(this.onUpdateLanguage).catch(() => {}));
})
.then(() => this.onReceiveMetrics());
.then(() => this.onUpdateLanguage());
}
}

Expand All @@ -119,7 +119,7 @@ class LoggingQueryField extends React.PureComponent<LoggingQueryFieldProps, Logg

this.languageProvider
.fetchLabelValues(targetOption.value)
.then(this.onReceiveMetrics)
.then(this.onUpdateLanguage)
.catch(() => {});
};

Expand Down Expand Up @@ -147,7 +147,7 @@ class LoggingQueryField extends React.PureComponent<LoggingQueryFieldProps, Logg
}
};

onReceiveMetrics = () => {
onUpdateLanguage = () => {
Prism.languages[PRISM_SYNTAX] = this.languageProvider.getSyntax();
const { logLabelOptions } = this.languageProvider;
this.setState({
Expand Down
8 changes: 3 additions & 5 deletions public/app/plugins/datasource/logging/language_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export default class LoggingLanguageProvider extends LanguageProvider {
this.datasource = datasource;
this.labelKeys = {};
this.labelValues = {};
this.started = false;

Object.assign(this, initialValues);
}
Expand All @@ -63,11 +62,10 @@ export default class LoggingLanguageProvider extends LanguageProvider {
};

start = () => {
if (!this.started) {
this.started = true;
return this.fetchLogLabels();
if (!this.startTask) {
this.startTask = this.fetchLogLabels();
}
return Promise.resolve([]);
return this.startTask;
};

// Keep this DOM-free for testing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ class PromQueryField extends React.PureComponent<PromQueryFieldProps, PromQueryF
this.languageProvider
.start()
.then(remaining => {
remaining.map(task => task.then(this.onReceiveMetrics).catch(() => {}));
remaining.map(task => task.then(this.onUpdateLanguage).catch(() => {}));
})
.then(() => this.onReceiveMetrics());
.then(() => this.onUpdateLanguage());
}
}

Expand Down Expand Up @@ -176,7 +176,7 @@ class PromQueryField extends React.PureComponent<PromQueryFieldProps, PromQueryF
}
};

onReceiveMetrics = () => {
onUpdateLanguage = () => {
const { histogramMetrics, metrics } = this.languageProvider;
if (!metrics) {
return;
Expand Down
10 changes: 4 additions & 6 deletions public/app/plugins/datasource/prometheus/language_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default class PromQlLanguageProvider extends LanguageProvider {
labelKeys?: { [index: string]: string[] }; // metric -> [labelKey,...]
labelValues?: { [index: string]: { [index: string]: string[] } }; // metric -> labelKey -> [labelValue,...]
metrics?: string[];
started: boolean;
startTask: Promise<any>;

constructor(datasource: any, initialValues?: any) {
super();
Expand All @@ -56,7 +56,6 @@ export default class PromQlLanguageProvider extends LanguageProvider {
this.labelKeys = {};
this.labelValues = {};
this.metrics = [];
this.started = false;

Object.assign(this, initialValues);
}
Expand All @@ -72,11 +71,10 @@ export default class PromQlLanguageProvider extends LanguageProvider {
};

start = () => {
if (!this.started) {
this.started = true;
return this.fetchMetricNames().then(() => [this.fetchHistogramMetrics()]);
if (!this.startTask) {
this.startTask = this.fetchMetricNames().then(() => [this.fetchHistogramMetrics()]);
}
return Promise.resolve([]);
return this.startTask;
};

// Keep this DOM-free for testing
Expand Down
3 changes: 2 additions & 1 deletion public/app/types/explore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,11 @@ export abstract class LanguageProvider {
datasource: 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.
*/
start: () => Promise<any[]>;
startTask?: Promise<any[]>;
}

export interface TypeaheadInput {
Expand Down

0 comments on commit 0df14f3

Please sign in to comment.