|
@@ -7,6 +7,7 @@ import {
|
|
|
LanguageProvider,
|
|
LanguageProvider,
|
|
|
TypeaheadInput,
|
|
TypeaheadInput,
|
|
|
TypeaheadOutput,
|
|
TypeaheadOutput,
|
|
|
|
|
+ HistoryItem,
|
|
|
} from 'app/types/explore';
|
|
} from 'app/types/explore';
|
|
|
import { parseSelector, labelRegexp, selectorRegexp } from 'app/plugins/datasource/prometheus/language_utils';
|
|
import { parseSelector, labelRegexp, selectorRegexp } from 'app/plugins/datasource/prometheus/language_utils';
|
|
|
import PromqlSyntax from 'app/plugins/datasource/prometheus/promql';
|
|
import PromqlSyntax from 'app/plugins/datasource/prometheus/promql';
|
|
@@ -19,9 +20,9 @@ const HISTORY_COUNT_CUTOFF = 1000 * 60 * 60 * 24; // 24h
|
|
|
|
|
|
|
|
const wrapLabel = (label: string) => ({ label });
|
|
const wrapLabel = (label: string) => ({ label });
|
|
|
|
|
|
|
|
-export function addHistoryMetadata(item: CompletionItem, history: any[]): CompletionItem {
|
|
|
|
|
|
|
+export function addHistoryMetadata(item: CompletionItem, history: HistoryItem[]): CompletionItem {
|
|
|
const cutoffTs = Date.now() - HISTORY_COUNT_CUTOFF;
|
|
const cutoffTs = Date.now() - HISTORY_COUNT_CUTOFF;
|
|
|
- const historyForItem = history.filter(h => h.ts > cutoffTs && h.query === item.label);
|
|
|
|
|
|
|
+ const historyForItem = history.filter(h => h.ts > cutoffTs && (h.query.expr as string) === item.label);
|
|
|
const count = historyForItem.length;
|
|
const count = historyForItem.length;
|
|
|
const recent = historyForItem[0];
|
|
const recent = historyForItem[0];
|
|
|
let hint = `Queried ${count} times in the last 24h.`;
|
|
let hint = `Queried ${count} times in the last 24h.`;
|
|
@@ -96,9 +97,9 @@ export default class LoggingLanguageProvider extends LanguageProvider {
|
|
|
|
|
|
|
|
if (history && history.length > 0) {
|
|
if (history && history.length > 0) {
|
|
|
const historyItems = _.chain(history)
|
|
const historyItems = _.chain(history)
|
|
|
- .uniqBy('query')
|
|
|
|
|
|
|
+ .uniqBy('query.expr')
|
|
|
.take(HISTORY_ITEM_COUNT)
|
|
.take(HISTORY_ITEM_COUNT)
|
|
|
- .map(h => h.query)
|
|
|
|
|
|
|
+ .map(h => h.query.expr)
|
|
|
.map(wrapLabel)
|
|
.map(wrapLabel)
|
|
|
.map(item => addHistoryMetadata(item, history))
|
|
.map(item => addHistoryMetadata(item, history))
|
|
|
.value();
|
|
.value();
|