fix performance issue in processHistogramLabels() (#25813)

This commit is contained in:
Bruce Sherrod 2020-06-25 08:51:42 -07:00 committed by GitHub
parent 7f587b209f
commit af0c73720e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,17 +4,16 @@ import { addLabelToQuery } from './add_label_to_query';
export const RATE_RANGES = ['1m', '5m', '10m', '30m', '1h'];
export const processHistogramLabels = (labels: string[]) => {
const result = [];
const resultSet: Set<string> = new Set();
const regexp = new RegExp('_bucket($|:)');
for (let index = 0; index < labels.length; index++) {
const label = labels[index];
const isHistogramValue = regexp.test(label);
if (isHistogramValue) {
if (result.indexOf(label) === -1) {
result.push(label);
}
resultSet.add(label);
}
}
const result = [...resultSet];
return { values: { __name__: result } };
};