HDDS-1870. ConcurrentModification at PrometheusMetricsSink (#1179)
This commit is contained in:
parent
ec1d453846
commit
f4df97fd89
@ -21,8 +21,8 @@
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
@ -44,7 +44,7 @@ public class PrometheusMetricsSink implements MetricsSink {
|
|||||||
/**
|
/**
|
||||||
* Cached output lines for each metrics.
|
* 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 =
|
private static final Pattern SPLIT_PATTERN =
|
||||||
Pattern.compile("(?<!(^|[A-Z_]))(?=[A-Z])|(?<!^)(?=[A-Z][a-z])");
|
Pattern.compile("(?<!(^|[A-Z_]))(?=[A-Z])|(?<!^)(?=[A-Z][a-z])");
|
||||||
@ -65,9 +65,13 @@ public void putMetrics(MetricsRecord metricsRecord) {
|
|||||||
metricsRecord.name(), metrics.name());
|
metricsRecord.name(), metrics.name());
|
||||||
|
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
builder.append("# TYPE " + key + " " +
|
builder.append("# TYPE ")
|
||||||
metrics.type().toString().toLowerCase() + "\n");
|
.append(key)
|
||||||
builder.append(key + "{");
|
.append(" ")
|
||||||
|
.append(metrics.type().toString().toLowerCase())
|
||||||
|
.append("\n")
|
||||||
|
.append(key)
|
||||||
|
.append("{");
|
||||||
String sep = "";
|
String sep = "";
|
||||||
|
|
||||||
//add tags
|
//add tags
|
||||||
@ -76,13 +80,17 @@ public void putMetrics(MetricsRecord metricsRecord) {
|
|||||||
|
|
||||||
//ignore specific tag which includes sub-hierarchy
|
//ignore specific tag which includes sub-hierarchy
|
||||||
if (!tagName.equals("numopenconnectionsperuser")) {
|
if (!tagName.equals("numopenconnectionsperuser")) {
|
||||||
builder.append(
|
builder.append(sep)
|
||||||
sep + tagName + "=\"" + tag.value() + "\"");
|
.append(tagName)
|
||||||
|
.append("=\"")
|
||||||
|
.append(tag.value())
|
||||||
|
.append("\"");
|
||||||
sep = ",";
|
sep = ",";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
builder.append("} ");
|
builder.append("} ");
|
||||||
builder.append(metrics.value());
|
builder.append(metrics.value());
|
||||||
|
builder.append("\n");
|
||||||
metricLines.put(key, builder.toString());
|
metricLines.put(key, builder.toString());
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -121,7 +129,7 @@ public void init(SubsetConfiguration subsetConfiguration) {
|
|||||||
|
|
||||||
public void writeMetrics(Writer writer) throws IOException {
|
public void writeMetrics(Writer writer) throws IOException {
|
||||||
for (String line : metricLines.values()) {
|
for (String line : metricLines.values()) {
|
||||||
writer.write(line + "\n");
|
writer.write(line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user