Skip to content

Commit

Permalink
uniquify list of labels
Browse files Browse the repository at this point in the history
  • Loading branch information
mtanda committed Jan 25, 2022
1 parent fc7bb7c commit 1b4ed42
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions public/app/plugins/datasource/cloud-monitoring/datasource.ts
Expand Up @@ -179,19 +179,24 @@ export default class CloudMonitoringDatasource extends DataSourceWithBackend<
const dataQueryResponse = toDataQueryResponse({
data: data,
});
return dataQueryResponse?.data
const labels = dataQueryResponse?.data
.map((f) => f.meta?.custom?.labels)
.filter((p) => !!p)
.reduce((acc, labels) => {
for (let key in labels) {
if (acc[key]) {
acc[key].push(...labels[key]);
} else {
acc[key] = labels[key];
if (!acc[key]) {
acc[key] = new Set<string>();
}
acc[key].add(labels[key]);
}
return acc;
}, {});
return Object.fromEntries(
Object.entries(labels).map((l: any) => {
l[1] = Array.from(l[1]);
return l;
})
);
})
)
);
Expand Down

0 comments on commit 1b4ed42

Please sign in to comment.