ru.fix.aggregating.profiler.RegexpLabelSticker Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aggregating-profiler Show documentation
Show all versions of aggregating-profiler Show documentation
https://github.com/ru-fix/aggregating-profiler
package ru.fix.aggregating.profiler;
import java.util.Map;
import java.util.Set;
import java.util.HashMap;
import java.util.regex.Pattern;
/**
*
* @author Andrey Kiselev
*/
public class RegexpLabelSticker implements LabelSticker {
private final String tagName;
private final Map> labelValuesWithSelectors = new HashMap<>();
public RegexpLabelSticker(String labelName,
Map> labelValuesWithSelectors) {
this.labelValuesWithSelectors.putAll(labelValuesWithSelectors);
this.tagName = labelName;
}
@Override
public Map buildLabels(String identityName){
HashMap labels = new HashMap<>();
for(Map.Entry> entry : labelValuesWithSelectors.entrySet()) {
for(Pattern p : entry.getValue()) {
if(p.matcher(identityName).matches()) {
labels.put(tagName, entry.getKey());
return labels;
}
}
}
return labels;
}
}