HADOOP-16496. Apply HDDS-1870 (ConcurrentModification at PrometheusMetricsSink) to Hadoop common.
This closes #1317 Reviewed-by: Bharat Viswanadham <bharat@apache.org>
This commit is contained in:
parent
10b4997b42
commit
30ce8546f1
@ -26,8 +26,8 @@
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -42,7 +42,7 @@ public class PrometheusMetricsSink implements MetricsSink {
|
||||
/**
|
||||
* Cached output lines for each metrics.
|
||||
*/
|
||||
private Map<String, String> metricLines = new HashMap<>();
|
||||
private final Map<String, String> metricLines = new ConcurrentHashMap<>();
|
||||
|
||||
private static final Pattern SPLIT_PATTERN =
|
||||
Pattern.compile("(?<!(^|[A-Z_]))(?=[A-Z])|(?<!^)(?=[A-Z][a-z])");
|
||||
@ -61,9 +61,13 @@ public void putMetrics(MetricsRecord metricsRecord) {
|
||||
metricsRecord.name(), metrics.name());
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("# TYPE " + key + " " +
|
||||
metrics.type().toString().toLowerCase() + "\n");
|
||||
builder.append(key + "{");
|
||||
builder.append("# TYPE ")
|
||||
.append(key)
|
||||
.append(" ")
|
||||
.append(metrics.type().toString().toLowerCase())
|
||||
.append("\n")
|
||||
.append(key)
|
||||
.append("{");
|
||||
String sep = "";
|
||||
|
||||
//add tags
|
||||
@ -72,13 +76,17 @@ public void putMetrics(MetricsRecord metricsRecord) {
|
||||
|
||||
//ignore specific tag which includes sub-hierarchy
|
||||
if (!tagName.equals("numopenconnectionsperuser")) {
|
||||
builder.append(
|
||||
sep + tagName + "=\"" + tag.value() + "\"");
|
||||
builder.append(sep)
|
||||
.append(tagName)
|
||||
.append("=\"")
|
||||
.append(tag.value())
|
||||
.append("\"");
|
||||
sep = ",";
|
||||
}
|
||||
}
|
||||
builder.append("} ");
|
||||
builder.append(metrics.value());
|
||||
builder.append("\n");
|
||||
metricLines.put(key, builder.toString());
|
||||
|
||||
}
|
||||
@ -110,7 +118,7 @@ public void init(SubsetConfiguration subsetConfiguration) {
|
||||
|
||||
public void writeMetrics(Writer writer) throws IOException {
|
||||
for (String line : metricLines.values()) {
|
||||
writer.write(line + "\n");
|
||||
writer.write(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user