From 5a86f032f1f6b900da2196e844ce0f30ce567346 Mon Sep 17 00:00:00 2001 From: Sven Grossmann Date: Thu, 9 Jan 2025 16:29:59 +0100 Subject: [PATCH] Loki: Only hide a set of labels instead of every label starting with `__` (#98730) Loki: Only hide a set of labels --- public/app/plugins/datasource/loki/LanguageProvider.test.ts | 2 +- public/app/plugins/datasource/loki/LanguageProvider.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/public/app/plugins/datasource/loki/LanguageProvider.test.ts b/public/app/plugins/datasource/loki/LanguageProvider.test.ts index 30ae4ab9a06..4a35e193cb6 100644 --- a/public/app/plugins/datasource/loki/LanguageProvider.test.ts +++ b/public/app/plugins/datasource/loki/LanguageProvider.test.ts @@ -490,7 +490,7 @@ describe('Language completion provider', () => { const instance = new LanguageProvider(datasourceWithLabels); const labels = await instance.fetchLabels(); - expect(labels).toEqual(['bar', 'foo']); + expect(labels).toEqual(['__name__', 'bar', 'foo']); }); }); }); diff --git a/public/app/plugins/datasource/loki/LanguageProvider.ts b/public/app/plugins/datasource/loki/LanguageProvider.ts index 9dadc1c2bab..4d6af9a10b7 100644 --- a/public/app/plugins/datasource/loki/LanguageProvider.ts +++ b/public/app/plugins/datasource/loki/LanguageProvider.ts @@ -17,6 +17,7 @@ import { ParserAndLabelKeysResult, LokiQuery, LokiQueryType, LabelType } from '. const NS_IN_MS = 1000000; const EMPTY_SELECTOR = '{}'; +const HIDDEN_LABELS = ['__aggregrated_metric__', '__tenant_id__', '__stream_shard__']; export default class LokiLanguageProvider extends LanguageProvider { labelKeys: string[]; @@ -182,7 +183,7 @@ export default class LokiLanguageProvider extends LanguageProvider { const labels = Array.from(new Set(res)) .slice() .sort() - .filter((label: string) => label.startsWith('__') === false); + .filter((label: string) => HIDDEN_LABELS.includes(label) === false); this.labelKeys = labels; return this.labelKeys; }