Loki: Remove empty annotations tags (#32359)

* 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>
This commit is contained in:
Conor Evans 2021-03-26 14:16:31 +01:00 committed by GitHub
parent 8bb56fabe0
commit 3af573ea96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -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']],
},

View File

@ -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);