Skip to content

Commit

Permalink
Merge pull request #140 from Cinimex-Informatica/feature/issue139_inc…
Browse files Browse the repository at this point in the history
…orrect_work

Fixed bug related to incorrect work with MQ 9.0.0.x
  • Loading branch information
echerniak authored Oct 31, 2019
2 parents c8fa8af + e38ee8f commit 648e0c3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@

import io.prometheus.client.CollectorRegistry;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.*;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -79,7 +72,7 @@ public static Function<List<Double>, Double> getConversionFunction(String update
return MetricManagerUtils::division;
case "mqobject_get_average_destructive_mqget_persistent_and_non_persistent_message_size_bytes":
return MetricManagerUtils::averageSum;
case "mqobject_get_queue_queue_fill_percentage":
case "mqobject_queue_queue_fill_percentage":
return MetricManagerUtils::divisionInPercentage;
default:
return MetricManagerUtils::defaultConversion;
Expand Down Expand Up @@ -124,19 +117,22 @@ public static Map<List<String>, List<Double>> getMetricsUsedToUpdate(Set<String>
if (!arrayListDoubleMap.isEmpty()) mapWithValues.put(metricFamilySamples.name, arrayListDoubleMap);
});

List<Map<List<String>, Double>> listWithValues = metricsNamesUsedToUpdate.stream()
.map(mapWithValues::get)
.collect(Collectors.toList());
Map<List<String>, List<Double>> params = new HashMap<>();
listWithValues.forEach(l -> l.forEach((k, v) -> {
if (!params.containsKey(k)) params.put(k, new ArrayList<>(Collections.singletonList(v)));
else {
List<Double> paramList = params.get(k);
paramList.add(v);
params.replace(k, paramList);

if (mapWithValues.size() == metricsNamesUsedToUpdate.size()) {
List<Map<List<String>, Double>> listWithValues = metricsNamesUsedToUpdate.stream()
.map(mapWithValues::get)
.collect(Collectors.toList());
listWithValues.forEach(l -> l.forEach((k, v) -> {
if (!params.containsKey(k)) params.put(k, new ArrayList<>(Collections.singletonList(v)));
else {
List<Double> paramList = params.get(k);
paramList.add(v);
params.replace(k, paramList);
}
}
}
));
));
}
return params;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@
import ru.cinimex.exporter.mq.pcf.PCFElement;
import ru.cinimex.exporter.mq.pcf.PCFElementRow;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;

import static ru.cinimex.exporter.prometheus.metrics.MetricsReference.getAdditionalMqObjectMetricsReference;
import static ru.cinimex.exporter.prometheus.metrics.MetricManagerUtils.*;
import static ru.cinimex.exporter.prometheus.metrics.MetricsReference.getAdditionalMqObjectMetricsReference;

/**
* Class is used to manage work of all metrics.
Expand Down Expand Up @@ -65,7 +60,7 @@ public static void initMetrics(List<PCFElement> elements, List<MQObject.MQType>
default:
logger.error(
"Error during metrics initialization: Unknown metric type! Make sure it is one " + "of: {}",
(Object[]) MetricsReference.Metric.Type.values());
MetricsReference.Metric.Type.values());
}
}
}
Expand Down Expand Up @@ -115,9 +110,11 @@ public static void updateAdditionalMetrics(Set<String> parsedQuery) {
private static void complexUpdateMetrics(
Map<List<String>, List<Double>> metricsUsedToUpdate,
String updatedMetricName) {
metricsUsedToUpdate.forEach((k, l) -> updateMetric(
updatedMetricName, getConversionFunction(updatedMetricName).apply(l), k.toArray(new String[0])));
logger.trace("Additional metrics {} was updated", updatedMetricName);
if (metricsUsedToUpdate != null) {
metricsUsedToUpdate.forEach((k, l) -> updateMetric(
updatedMetricName, getConversionFunction(updatedMetricName).apply(l), k.toArray(new String[0])));
logger.trace("Additional metrics {} were updated", updatedMetricName);
}
}

/**
Expand Down

0 comments on commit 648e0c3

Please sign in to comment.