|
@@ -1,6 +1,12 @@
|
|
|
|
|
+// Libraries
|
|
|
import _ from 'lodash';
|
|
import _ from 'lodash';
|
|
|
import moment from 'moment';
|
|
import moment from 'moment';
|
|
|
|
|
|
|
|
|
|
+// Services & Utils
|
|
|
|
|
+import { parseSelector, labelRegexp, selectorRegexp } from 'app/plugins/datasource/prometheus/language_utils';
|
|
|
|
|
+import syntax from './syntax';
|
|
|
|
|
+
|
|
|
|
|
+// Types
|
|
|
import {
|
|
import {
|
|
|
CompletionItem,
|
|
CompletionItem,
|
|
|
CompletionItemGroup,
|
|
CompletionItemGroup,
|
|
@@ -9,9 +15,7 @@ import {
|
|
|
TypeaheadOutput,
|
|
TypeaheadOutput,
|
|
|
HistoryItem,
|
|
HistoryItem,
|
|
|
} from 'app/types/explore';
|
|
} from 'app/types/explore';
|
|
|
-import { parseSelector, labelRegexp, selectorRegexp } from 'app/plugins/datasource/prometheus/language_utils';
|
|
|
|
|
-import syntax from './syntax';
|
|
|
|
|
-import { DataQuery } from '@grafana/ui/src/types';
|
|
|
|
|
|
|
+import { LokiQuery } from './types';
|
|
|
|
|
|
|
|
const DEFAULT_KEYS = ['job', 'namespace'];
|
|
const DEFAULT_KEYS = ['job', 'namespace'];
|
|
|
const EMPTY_SELECTOR = '{}';
|
|
const EMPTY_SELECTOR = '{}';
|
|
@@ -20,7 +24,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: HistoryItem[]): CompletionItem {
|
|
|
|
|
|
|
+type LokiHistoryItem = HistoryItem<LokiQuery>;
|
|
|
|
|
+
|
|
|
|
|
+export function addHistoryMetadata(item: CompletionItem, history: LokiHistoryItem[]): 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.expr as string) === 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;
|
|
@@ -155,7 +161,7 @@ export default class LokiLanguageProvider extends LanguageProvider {
|
|
|
return { context, refresher, suggestions };
|
|
return { context, refresher, suggestions };
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- async importQueries(queries: DataQuery[], datasourceType: string): Promise<DataQuery[]> {
|
|
|
|
|
|
|
+ async importQueries(queries: LokiQuery[], datasourceType: string): Promise<LokiQuery[]> {
|
|
|
if (datasourceType === 'prometheus') {
|
|
if (datasourceType === 'prometheus') {
|
|
|
return Promise.all(
|
|
return Promise.all(
|
|
|
queries.map(async query => {
|
|
queries.map(async query => {
|