From ecaee88efe911562b6ccf00c1a23de76f7f39327 Mon Sep 17 00:00:00 2001 From: David Kaltschmidt Date: Fri, 23 Nov 2018 11:43:21 +0100 Subject: [PATCH 1/2] Sort Prometheus range suggestions by length - add sortText property to range completion items --- .../datasource/prometheus/language_provider.ts | 6 +++--- public/app/plugins/datasource/prometheus/promql.ts | 13 ++++++++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/public/app/plugins/datasource/prometheus/language_provider.ts b/public/app/plugins/datasource/prometheus/language_provider.ts index 5fd8fcebaaf..8dc7928780b 100644 --- a/public/app/plugins/datasource/prometheus/language_provider.ts +++ b/public/app/plugins/datasource/prometheus/language_provider.ts @@ -9,8 +9,8 @@ import { TypeaheadOutput, } from 'app/types/explore'; -import { parseSelector, processLabels, RATE_RANGES } from './language_utils'; -import PromqlSyntax, { FUNCTIONS } from './promql'; +import { parseSelector, processLabels } from './language_utils'; +import PromqlSyntax, { FUNCTIONS, RATE_RANGES } from './promql'; const DEFAULT_KEYS = ['job', 'instance']; const EMPTY_SELECTOR = '{}'; @@ -171,7 +171,7 @@ export default class PromQlLanguageProvider extends LanguageProvider { suggestions: [ { label: 'Range vector', - items: [...RATE_RANGES].map(wrapLabel), + items: [...RATE_RANGES], }, ], }; diff --git a/public/app/plugins/datasource/prometheus/promql.ts b/public/app/plugins/datasource/prometheus/promql.ts index 065e6bb08cc..41463877a8f 100644 --- a/public/app/plugins/datasource/prometheus/promql.ts +++ b/public/app/plugins/datasource/prometheus/promql.ts @@ -1,8 +1,19 @@ /* tslint:disable max-line-length */ +import { CompletionItem } from 'app/types/explore'; + +export const RATE_RANGES: CompletionItem[] = [ + { label: '1m', sortText: '00:01:00' }, + { label: '5m', sortText: '00:05:00' }, + { label: '10m', sortText: '00:10:00' }, + { label: '30m', sortText: '00:30:00' }, + { label: '1h', sortText: '01:00:00' }, + { label: '1d', sortText: '24:00:00' }, +]; + export const OPERATORS = ['by', 'group_left', 'group_right', 'ignoring', 'on', 'offset', 'without']; -const AGGREGATION_OPERATORS = [ +const AGGREGATION_OPERATORS: CompletionItem[] = [ { label: 'sum', insertText: 'sum', From 575d8884724399b0229ab24bab608dab56e504e0 Mon Sep 17 00:00:00 2001 From: David Kaltschmidt Date: Fri, 23 Nov 2018 16:53:46 +0100 Subject: [PATCH 2/2] Fix tests to account for sortText --- .../prometheus/specs/language_provider.test.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/public/app/plugins/datasource/prometheus/specs/language_provider.test.ts b/public/app/plugins/datasource/prometheus/specs/language_provider.test.ts index d3eb6de3087..1d114a7ef28 100644 --- a/public/app/plugins/datasource/prometheus/specs/language_provider.test.ts +++ b/public/app/plugins/datasource/prometheus/specs/language_provider.test.ts @@ -76,9 +76,16 @@ describe('Language completion provider', () => { }); expect(result.context).toBe('context-range'); expect(result.refresher).toBeUndefined(); - expect(result.suggestions).toEqual([ + expect(result.suggestions).toMatchObject([ { - items: [{ label: '1m' }, { label: '5m' }, { label: '10m' }, { label: '30m' }, { label: '1h' }], + items: [ + { label: '1m' }, + { label: '5m' }, + { label: '10m' }, + { label: '30m' }, + { label: '1h' }, + { label: '1d' }, + ], label: 'Range vector', }, ]);