mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Add sum aggregation query suggestion
Implements rudimentary support for placeholder values inside a string with the `PlaceholdersBuffer` class. The latter helps the newly added sum aggregation query suggestion to automatically focus on the label so users can easily choose from the available typeahead options. Related: #13615
This commit is contained in:
@@ -2,6 +2,11 @@ import _ from 'lodash';
|
||||
|
||||
import { QueryHint } from 'app/types/explore';
|
||||
|
||||
/**
|
||||
* Number of time series results needed before starting to suggest sum aggregation hints
|
||||
*/
|
||||
export const SUM_HINT_THRESHOLD_COUNT = 20;
|
||||
|
||||
export function getQueryHints(query: string, series?: any[], datasource?: any): QueryHint[] {
|
||||
const hints = [];
|
||||
|
||||
@@ -90,5 +95,24 @@ export function getQueryHints(query: string, series?: any[], datasource?: any):
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (series.length >= SUM_HINT_THRESHOLD_COUNT) {
|
||||
const simpleMetric = query.trim().match(/^\w+$/);
|
||||
if (simpleMetric) {
|
||||
hints.push({
|
||||
type: 'ADD_SUM',
|
||||
label: 'Many time series results returned.',
|
||||
fix: {
|
||||
label: 'Consider aggregating with sum().',
|
||||
action: {
|
||||
type: 'ADD_SUM',
|
||||
query: query,
|
||||
preventSubmit: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return hints.length > 0 ? hints : null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user