From 318032de747812d59b9ade3f8dc45744b99e7b04 Mon Sep 17 00:00:00 2001 From: diwanshu Date: Thu, 24 Aug 2023 08:40:09 -0700 Subject: [PATCH] Fix blacklist rule metric name --- .../carbonj/service/engine/MetricList.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/carbonj.service/src/main/java/com/demandware/carbonj/service/engine/MetricList.java b/carbonj.service/src/main/java/com/demandware/carbonj/service/engine/MetricList.java index c1570318..bda4482c 100644 --- a/carbonj.service/src/main/java/com/demandware/carbonj/service/engine/MetricList.java +++ b/carbonj.service/src/main/java/com/demandware/carbonj/service/engine/MetricList.java @@ -22,6 +22,7 @@ import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; +import java.util.stream.IntStream; /** * List of metrics that should receive special treatment (used for blocking or allowing metric names). @@ -171,16 +172,16 @@ public void reload() private List> parseConfig(List lines) { + List> patternCounterPairs = new ArrayList<>(); // Create an empty list to hold pairs of Pattern and Counter - List> patternCounterPairs = lines.stream() - .map(String::trim) - .filter(line -> line.length() > 0 && !line.startsWith("#")) - .map(line -> { - Pattern pattern = Pattern.compile(line); - Counter counter = metricRegistry.counter( MetricRegistry.name( name, "blacklist" ) ); - return Pair.of(pattern, counter); // Create and return the Pair - }) - .collect(Collectors.toList()); + for (int i = 0; i < lines.size(); i++) { + String line = lines.get(i).trim(); + if (!line.isEmpty() && !line.startsWith("#")) { + Pattern pattern = Pattern.compile(line); + Counter counter = metricRegistry.counter( MetricRegistry.name( name, "blacklist-" + (i + 1) ) ); + patternCounterPairs.add(Pair.of(pattern, counter)); // Create and return the Pair + } + } // Reset the counters here if needed for (Pair pair : patternCounterPairs) {