Skip to content

Commit

Permalink
IGNITE-18434 Fixed histogram metric configuration restore on node res…
Browse files Browse the repository at this point in the history
…tart (#11028)
  • Loading branch information
Vladsz83 authored Nov 7, 2023
1 parent abdfc99 commit 15e18b5
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -269,16 +269,7 @@ public LongAdderWithDelegateMetric longAdderMetric(
* @see HitRateMetric
*/
public HitRateMetric hitRateMetric(String name, @Nullable String desc, long rateTimeInterval, int size) {
String fullName = metricName(regName, name);

HitRateMetric metric = addMetric(name, new HitRateMetric(fullName, desc, rateTimeInterval, size));

Long cfgRateTimeInterval = hitRateCfgProvider.apply(fullName);

if (cfgRateTimeInterval != null)
metric.reset(cfgRateTimeInterval, DFLT_SIZE);

return metric;
return addMetric(name, new HitRateMetric(metricName(regName, name), desc, rateTimeInterval, size));
}

/**
Expand All @@ -302,16 +293,7 @@ public BooleanMetricImpl booleanMetric(String name, @Nullable String desc) {
* @return {@link HistogramMetricImpl}
*/
public HistogramMetricImpl histogram(String name, long[] bounds, @Nullable String desc) {
String fullName = metricName(regName, name);

HistogramMetricImpl metric = addMetric(name, new HistogramMetricImpl(fullName, desc, bounds));

long[] cfgBounds = histogramCfgProvider.apply(fullName);

if (cfgBounds != null)
metric.reset(cfgBounds);

return metric;
return addMetric(name, new HistogramMetricImpl(metricName(regName, name), desc, bounds));
}

/**
Expand All @@ -330,9 +312,29 @@ private <T extends Metric> T addMetric(String name, T metric) {
if (old != null)
return old;

configureMetrics(metric);

return metric;
}

/**
* Assigns metric settings if {@code metric} is configurable.
*/
private void configureMetrics(Metric metric) {
if (metric instanceof HistogramMetricImpl) {
long[] cfgBounds = histogramCfgProvider.apply(metric.name());

if (cfgBounds != null)
((HistogramMetricImpl)metric).reset(cfgBounds);
}
else if (metric instanceof HitRateMetric) {
Long cfgRateTimeInterval = hitRateCfgProvider.apply(metric.name());

if (cfgRateTimeInterval != null)
((HitRateMetric)metric).reset(cfgRateTimeInterval, DFLT_SIZE);
}
}

/** {@inheritDoc} */
@Override public String name() {
return regName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.ignite.internal.processors.metric.impl.HistogramMetricImpl;
import org.apache.ignite.internal.processors.metric.impl.HitRateMetric;
import org.apache.ignite.internal.processors.metric.impl.PeriodicHistogramMetricImpl;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.mxbean.MetricsMxBean;
import org.apache.ignite.spi.metric.HistogramMetric;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
Expand All @@ -39,6 +40,8 @@
import static org.apache.ignite.internal.processors.metric.GridMetricManager.TX_METRICS;
import static org.apache.ignite.internal.processors.metric.impl.MetricUtils.cacheMetricsRegistryName;
import static org.apache.ignite.internal.processors.metric.impl.MetricUtils.metricName;
import static org.apache.ignite.internal.processors.pool.PoolProcessor.TASK_EXEC_TIME;
import static org.apache.ignite.internal.processors.pool.PoolProcessor.THREAD_POOLS;
import static org.apache.ignite.testframework.GridTestUtils.assertThrowsWithCause;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertNotEquals;
Expand All @@ -59,9 +62,18 @@ public class MetricsConfigurationTest extends GridCommonAbstractTest {

/** {@inheritDoc} */
@Override protected void beforeTest() throws Exception {
super.beforeTest();

cleanPersistenceDir();
}

/** {@inheritDoc} */
@Override protected void afterTest() throws Exception {
super.afterTest();

stopAllGrids();
}

/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
Expand Down Expand Up @@ -306,6 +318,34 @@ public void testConfigRemovedOnCacheRemove() throws Exception {
});
}

/**
* Tests that histogram configuration is read again after node restart.
*/
@Test
public void testHistogramConfigIsKeptAfterNodeRestart() throws Exception {
IgniteEx ignite = startGrid("persistent-0");

ignite.cluster().state(ClusterState.ACTIVE);

String regName = metricName(THREAD_POOLS, "StripedExecutor");

HistogramMetric hist = ignite.context().metric().registry(regName).findMetric(TASK_EXEC_TIME);

assertFalse(F.arrayEq(BOUNDS, hist.bounds()));

ignite.context().metric().configureHistogram(metricName(regName, TASK_EXEC_TIME), BOUNDS);

assertTrue(F.arrayEq(BOUNDS, hist.bounds()));

stopGrid("persistent-0", false);

ignite = startGrid("persistent-0");

hist = ignite.context().metric().registry(regName).findMetric(TASK_EXEC_TIME);

assertTrue(F.arrayEq(BOUNDS, hist.bounds()));
}

/** Tests metric configuration removed on registry remove. */
@Test
public void testConfigRemovedOnCacheGroupRemove() throws Exception {
Expand Down

0 comments on commit 15e18b5

Please sign in to comment.