Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IGNITE-12769: histogramNames cache in MetricRegistryMBean removed. #7549

Merged
merged 3 commits into from
Mar 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.apache.ignite.internal.processors.metric.impl;

import java.util.Map;
import org.apache.ignite.internal.processors.metric.GridMetricManager;
import org.apache.ignite.internal.processors.metric.MetricRegistry;
import org.apache.ignite.internal.util.typedef.T2;
Expand Down Expand Up @@ -136,26 +135,20 @@ private static boolean ensureAllNamesNotEmpty(String... names) {
}

/**
* Gets histogram bucket names.
* Generates histogram bucket names.
*
* Example of metric names if bounds are 10,100:
* histogram_0_10 (less than 10)
* histogram_10_100 (between 10 and 100)
* histogram_100_inf (more than 100)
*
* @param metric Histogram metric.
* @param cache Map that caches computed bucket names.
* @param metric Histogram metric
* @return Histogram intervals names.
*/
public static String[] histogramBucketNames(HistogramMetric metric, Map<String, T2<long[], String[]>> cache) {
public static String[] histogramBucketNames(HistogramMetric metric) {
String name = metric.name();
long[] bounds = metric.bounds();

T2<long[], String[]> tuple = cache.get(name);

if (tuple != null && tuple.get1() == bounds)
return tuple.get2();

String[] names = new String[bounds.length + 1];

long min = 0;
Expand All @@ -168,8 +161,6 @@ public static String[] histogramBucketNames(HistogramMetric metric, Map<String,

names[bounds.length] = name + HISTOGRAM_NAME_DIVIDER + min + INF;

cache.put(name, new T2<>(bounds, names));

return names;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@
package org.apache.ignite.spi.metric.jmx;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanInfo;
import org.apache.ignite.internal.processors.metric.impl.MetricUtils;
import org.apache.ignite.internal.util.typedef.T2;
import org.apache.ignite.spi.metric.BooleanMetric;
import org.apache.ignite.spi.metric.DoubleMetric;
import org.apache.ignite.spi.metric.HistogramMetric;
Expand All @@ -48,9 +45,6 @@ public class MetricRegistryMBean extends ReadOnlyDynamicMBean {
/** Metric registry. */
ReadOnlyMetricRegistry mreg;

/** Cached histogram metrics intervals names. */
private final Map<String, T2<long[], String[]>> histogramNames = new HashMap<>();

/**
* @param mreg Metric registry.
*/
Expand Down Expand Up @@ -90,7 +84,7 @@ else if (metric instanceof ObjectMetric)

iter.forEachRemaining(metric -> {
if (metric instanceof HistogramMetric) {
String[] names = histogramBucketNames((HistogramMetric)metric, histogramNames);
String[] names = histogramBucketNames((HistogramMetric)metric);

assert names.length == ((HistogramMetric)metric).value().length;

Expand Down Expand Up @@ -152,7 +146,7 @@ else if (metric instanceof ObjectMetric)
* @param name Attribute name.
* @param mreg Metric registry to search histogram in.
* @return Specific bucket value or {@code null} if not found.
* @see MetricUtils#histogramBucketNames(HistogramMetric, Map)
* @see MetricUtils#histogramBucketNames(HistogramMetric)
*/
public static Long searchHistogram(String name, ReadOnlyMetricRegistry mreg) {
int highBoundIdx;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@
package org.apache.ignite.internal.metric;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Spliterators;
import java.util.stream.StreamSupport;
Expand Down Expand Up @@ -345,18 +343,14 @@ public void testHitRateMetric() throws Exception {
public void testHistogramNames() throws Exception {
HistogramMetricImpl h = new HistogramMetricImpl("test", null, new long[]{10, 50, 500});

Map<String, T2<long[], String[]>> cache = new HashMap<>();

String[] names = histogramBucketNames(h, cache);
String[] names = histogramBucketNames(h);

assertArrayEquals(new String[] {
"test_0_10",
"test_10_50",
"test_50_500",
"test_500_inf"
}, names);

assertTrue("Computed values should be cached", names == histogramBucketNames(h, cache));
}

/** */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.apache.ignite.internal.processors.metric.GridMetricManager;
import org.apache.ignite.internal.processors.metric.MetricRegistry;
import org.apache.ignite.internal.processors.metric.PushMetricsExporterAdapter;
import org.apache.ignite.internal.processors.metric.impl.MetricUtils;
import org.apache.ignite.internal.util.typedef.T2;
import org.apache.ignite.spi.IgniteSpiContext;
import org.apache.ignite.spi.IgniteSpiException;
Expand All @@ -58,8 +59,6 @@

import static io.opencensus.tags.TagMetadata.TagTtl.UNLIMITED_PROPAGATION;

import static org.apache.ignite.internal.processors.metric.impl.MetricUtils.histogramBucketNames;

/**
* <a href="https://opencensus.io">OpenCensus</a> monitoring exporter. <br>
* <br>
Expand Down Expand Up @@ -197,7 +196,7 @@ else if (metric instanceof DoubleMetric) {
mmap.put(msr, val);
}
else if (metric instanceof HistogramMetric) {
String[] names = histogramBucketNames((HistogramMetric)metric, histogramNames);
String[] names = histogramBucketNames((HistogramMetric)metric);
long[] vals = ((HistogramMetric)metric).value();

assert names.length == vals.length;
Expand Down Expand Up @@ -297,6 +296,26 @@ private void addView(Measure msr) {
((IgniteEx)ignite()).context().discovery().localNode().consistentId().toString());
}

/**
* @param metric Histogram metric.
* @return Histogram intervals names.
*/
private String[] histogramBucketNames(HistogramMetric metric) {
String name = metric.name();
long[] bounds = metric.bounds();

T2<long[], String[]> tuple = histogramNames.get(name);

if (tuple != null && tuple.get1() == bounds)
return tuple.get2();

String[] names = MetricUtils.histogramBucketNames(metric);

histogramNames.put(name, new T2<>(bounds, names));

return names;
}

/**
* If {@code true} then {@link #INSTANCE_NAME_TAG} will be added to each exported measure.
*
Expand Down