Loki: Remove empty annotations tags (#32359) (#32490)

* Loki - filter labels with empty values

Signed-off-by: Conor Evans <coevans@tcd.ie>

* Apply prettier change

Signed-off-by: Conor Evans <coevans@tcd.ie>

* Apply Piotr's suggestion - swap map/filter statements

Signed-off-by: Conor Evans <coevans@tcd.ie>
(cherry picked from commit 3af573ea96)

Co-authored-by: Conor Evans <43791257+conorevans@users.noreply.github.com>
This commit is contained in:
Grot (@grafanabot)
2021-04-07 11:10:48 +02:00
committed by GitHub
co-authored by Conor Evans
parent b692d2fd4c
commit 48d280b999
2 changed files with 9 additions and 1 deletions
@@ -469,7 +469,9 @@ describe('LokiDatasource', () => {
},
{
stream: {
label: '', // empty value gets filtered
label2: 'value2',
label3: ' ', // whitespace value gets trimmed then filtered
},
values: [['1549024057498000000', 'hello 2']],
},
@@ -511,7 +511,13 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> {
const tags: string[] = [];
for (const field of frame.fields) {
if (field.labels) {
tags.push.apply(tags, [...new Set(Object.values(field.labels).map((label: string) => label.trim()))]);
tags.push.apply(tags, [
...new Set(
Object.values(field.labels)
.map((label: string) => label.trim())
.filter((label: string) => label !== '')
),
]);
}
}
const view = new DataFrameView<{ ts: string; line: string }>(frame);