Skip to content
Permalink
Browse files

WFLY-11801: fixes thread safety issues when adding/removing metric fa…

…mily samples suppliers
  • Loading branch information
langfr committed Mar 27, 2019
1 parent 66553ad commit e3aea37d06eca2c22cde27a9f4962bffc44a7ebb
@@ -6,6 +6,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.TreeMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.function.Supplier;

import io.prometheus.client.Collector;
@@ -18,17 +19,15 @@
// each MetricFamilySamples has list of Sample's supplier (that can be optional) if the underlying metric value is undefined.
private Map<String, List<Supplier<Optional<Sample>>>> metricFamilyMap = new HashMap();

public void addMetricFamilySamples(MetricFamilySamples mfs) {
public synchronized void addMetricFamilySamples(MetricFamilySamples mfs) {
if (!metricNames.containsKey(mfs.name)) {
metricNames.put(mfs.name, mfs);
metricFamilyMap.put(mfs.name, new ArrayList<>());
metricFamilyMap.put(mfs.name, new CopyOnWriteArrayList<>());
}
}

void addMetricFamilySampleSupplier(MetricFamilySamples mfs, Supplier<Optional<Sample>> sampleSupplier) {
if (!metricNames.containsKey(mfs.name)) {
addMetricFamilySamples(mfs);
}
addMetricFamilySamples(mfs);
metricFamilyMap.get(mfs.name).add(sampleSupplier);
}

0 comments on commit e3aea37

Please sign in to comment.
You can’t perform that action at this time.