This is an automated email from the ASF dual-hosted git repository.
NSAmelchev pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new 225377ba754 IGNITE-29223 Fix histogram metric bounds validation
(#13766)
225377ba754 is described below
commit 225377ba7541bb34f9ee91776450667fc8511bb3
Author: Nikita Amelchev <[email protected]>
AuthorDate: Thu Oct 29 16:53:28 2026 +0300
IGNITE-29223 Fix histogram metric bounds validation (#13766)
---
docs/_docs/tools/control-script.adoc | 6 ++++++
.../java/org/apache/ignite/util/MetricCommandTest.java | 12 ++++++------
.../metric/MetricConfigureHistogramCommandArg.java | 4 ----
.../processors/metric/ConfigurableHistogramMetric.java | 3 +++
.../internal/processors/metric/GridMetricManager.java | 5 +++--
.../internal/processors/metric/MetricRegistryImpl.java | 4 ++--
.../processors/metric/impl/HistogramMetricImpl.java | 9 +++++++++
.../metric/impl/PeriodicHistogramMetricImpl.java | 11 ++++++++---
.../internal/metric/MetricsConfigurationTest.java | 18 ++++++++++++++++++
9 files changed, 55 insertions(+), 17 deletions(-)
diff --git a/docs/_docs/tools/control-script.adoc
b/docs/_docs/tools/control-script.adoc
index 6f7541afa54..ac52f55792d 100644
--- a/docs/_docs/tools/control-script.adoc
+++ b/docs/_docs/tools/control-script.adoc
@@ -1118,6 +1118,12 @@ control.bat --metric --configure-max-value
max-value-metric-name 60000
NOTE: For metric command use following format as metric name:
`<register-name>.<metric-name>`. For example: `io.datastorage.WalLoggingRate`
must be set for `WalLoggingRate` metric.
+NOTE: For the `PageTimestampHistogram` metric, the values set
+link:monitoring-metrics/system-views#pages_timestamp_histogram[time intervals]
rather than bounds:
+the interval length in milliseconds is the difference between the first two
values, the number of intervals is
+the number of values, and the other values are ignored.
+For example, `0,600000,0` sets three 10-minute intervals.
+
== Indexes Management
The commands below allow to get a specific information on indexes and to
trigger the indexes rebuild process.
diff --git
a/modules/control-utility/src/test/java/org/apache/ignite/util/MetricCommandTest.java
b/modules/control-utility/src/test/java/org/apache/ignite/util/MetricCommandTest.java
index 8af01ebcb5b..de53379c8a4 100644
---
a/modules/control-utility/src/test/java/org/apache/ignite/util/MetricCommandTest.java
+++
b/modules/control-utility/src/test/java/org/apache/ignite/util/MetricCommandTest.java
@@ -163,12 +163,6 @@ public class MetricCommandTest extends
GridCommandHandlerClusterByClassAbstractT
"Can't parse number 'not_a_number', expected type: java.lang.Long"
);
- assertContains(
- log,
- executeCommand(EXIT_CODE_INVALID_ARGUMENTS, CMD_METRIC,
CONFIGURE_HISTOGRAM, "some.metric", "3,2,1"),
- "Bounds must be sorted"
- );
-
assertContains(
log,
executeCommand(
@@ -202,6 +196,12 @@ public class MetricCommandTest extends
GridCommandHandlerClusterByClassAbstractT
assertEquals(50, bounds[0]);
assertEquals(500, bounds[1]);
+ assertContains(
+ log,
+ executeCommand(EXIT_CODE_INVALID_ARGUMENTS, CMD_METRIC,
CONFIGURE_HISTOGRAM, histogram.name(), "3,2,1"),
+ "bounds should be sorted"
+ );
+
executeCommand(EXIT_CODE_OK, CMD_METRIC, CONFIGURE_HISTOGRAM,
histogram.name(), "1,2,3");
bounds = histogram.bounds();
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/management/metric/MetricConfigureHistogramCommandArg.java
b/modules/core/src/main/java/org/apache/ignite/internal/management/metric/MetricConfigureHistogramCommandArg.java
index 7a5a1274f84..33301d6990c 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/management/metric/MetricConfigureHistogramCommandArg.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/management/metric/MetricConfigureHistogramCommandArg.java
@@ -20,7 +20,6 @@ package org.apache.ignite.internal.management.metric;
import org.apache.ignite.internal.Order;
import org.apache.ignite.internal.management.api.Argument;
import org.apache.ignite.internal.management.api.Positional;
-import org.apache.ignite.internal.util.typedef.F;
/** */
public class MetricConfigureHistogramCommandArg extends MetricCommandArg {
@@ -40,9 +39,6 @@ public class MetricConfigureHistogramCommandArg extends
MetricCommandArg {
/** */
public void newBounds(long[] bounds) {
- if (!F.isSorted(bounds))
- throw new IllegalArgumentException("Bounds must be sorted");
-
this.newBounds = bounds;
}
}
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/metric/ConfigurableHistogramMetric.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/metric/ConfigurableHistogramMetric.java
index 2a3d15ca16e..62252010c54 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/metric/ConfigurableHistogramMetric.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/metric/ConfigurableHistogramMetric.java
@@ -25,4 +25,7 @@ import org.apache.ignite.spi.metric.HistogramMetric;
public interface ConfigurableHistogramMetric extends HistogramMetric {
/** Sets bounds for this histogram. */
public void bounds(long[] bounds);
+
+ /** Checks that the bounds can be set for this histogram, throws {@link
IllegalArgumentException} otherwise. */
+ public void checkBounds(long[] bounds);
}
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/metric/GridMetricManager.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/metric/GridMetricManager.java
index c116f17a70f..dd7d7759d3b 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/metric/GridMetricManager.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/metric/GridMetricManager.java
@@ -511,13 +511,14 @@ public class GridMetricManager extends
GridManagerAdapter<MetricExporterSpi> imp
*/
public void configureHistogram(String name, long[] bounds) throws
IgniteCheckedException {
A.notNullOrEmpty(name, "name");
- A.notEmpty(bounds, "bounds");
A.notNull(metastorage, "Metastorage not ready. Node not started?");
if (ctx.isStopping())
throw new NodeStoppingException("Operation has been cancelled
(node is stopping)");
- ensureMetricRegistered(name, HistogramMetric.class);
+ ensureMetricRegistered(name, ConfigurableHistogramMetric.class);
+
+ find(name, ConfigurableHistogramMetric.class).checkBounds(bounds);
metastorage.write(metricName(HISTOGRAM_CFG_PREFIX, name), bounds);
}
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/metric/MetricRegistryImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/metric/MetricRegistryImpl.java
index d4fe5729ef2..94cb8a22c67 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/metric/MetricRegistryImpl.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/metric/MetricRegistryImpl.java
@@ -319,11 +319,11 @@ public class MetricRegistryImpl implements MetricRegistry
{
private void configureMetrics(Metric metric) {
assert !customMetric(name()) : "Custom metrics cannot be configured
yet";
- if (metric instanceof HistogramMetricImpl) {
+ if (metric instanceof ConfigurableHistogramMetric) {
long[] cfgBounds = histogramCfgProvider.apply(metric.name());
if (cfgBounds != null)
- ((HistogramMetricImpl)metric).reset(cfgBounds);
+ ((ConfigurableHistogramMetric)metric).bounds(cfgBounds);
}
else if (metric instanceof HitRateMetric) {
Long cfgRateTimeInterval = hitRateCfgProvider.apply(metric.name());
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/metric/impl/HistogramMetricImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/metric/impl/HistogramMetricImpl.java
index 25263006139..c85499090c6 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/metric/impl/HistogramMetricImpl.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/metric/impl/HistogramMetricImpl.java
@@ -22,6 +22,7 @@ import java.util.concurrent.atomic.AtomicLongArray;
import org.apache.ignite.internal.processors.metric.AbstractMetric;
import
org.apache.ignite.internal.processors.metric.ConfigurableHistogramMetric;
import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.A;
import org.jetbrains.annotations.Nullable;
/**
@@ -83,9 +84,17 @@ public class HistogramMetricImpl extends AbstractMetric
implements ConfigurableH
/** {@inheritDoc} */
@Override public void bounds(long[] bounds) {
+ checkBounds(bounds);
+
reset(bounds);
}
+ /** {@inheritDoc} */
+ @Override public void checkBounds(long[] bounds) {
+ A.notEmpty(bounds, "bounds");
+ A.ensure(F.isSorted(bounds), "bounds should be sorted");
+ }
+
/** {@inheritDoc} */
@Override public void reset() {
reset(holder.bounds);
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/metric/impl/PeriodicHistogramMetricImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/metric/impl/PeriodicHistogramMetricImpl.java
index 008173c0b94..d935bb4fda7 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/metric/impl/PeriodicHistogramMetricImpl.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/metric/impl/PeriodicHistogramMetricImpl.java
@@ -110,14 +110,19 @@ public class PeriodicHistogramMetricImpl extends
AbstractMetric implements Confi
/** {@inheritDoc} */
@Override public void bounds(long[] bounds) {
- A.notNull(bounds, "bounds");
- A.ensure(bounds.length > 1, "bounds.length > 1");
- A.ensure(bounds[0] < bounds[1], "bounds[0] < bounds[1]");
+ checkBounds(bounds);
// We need only interval between bounds and count of buckets, skip all
values except first 2.
reinit(bounds[1] - bounds[0], bounds.length);
}
+ /** {@inheritDoc} */
+ @Override public void checkBounds(long[] bounds) {
+ A.notNull(bounds, "bounds");
+ A.ensure(bounds.length > 1, "bounds.length > 1");
+ A.ensure(bounds[0] < bounds[1], "bounds[0] < bounds[1]");
+ }
+
/** {@inheritDoc} */
@Override public long[] value() {
return histogram().get2();
diff --git
a/modules/core/src/test/java/org/apache/ignite/internal/metric/MetricsConfigurationTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/metric/MetricsConfigurationTest.java
index 4bdd9989853..9a1c9ddd692 100644
---
a/modules/core/src/test/java/org/apache/ignite/internal/metric/MetricsConfigurationTest.java
+++
b/modules/core/src/test/java/org/apache/ignite/internal/metric/MetricsConfigurationTest.java
@@ -199,6 +199,10 @@ public class MetricsConfigurationTest extends
GridCommonAbstractTest {
() -> bean.configureHistogramMetric(metricName(TX_METRICS,
METRIC_SYSTEM_TIME_HISTOGRAM), new long[0]),
IllegalArgumentException.class);
+ assertThrowsWithCause(
+ () -> bean.configureHistogramMetric(metricName(TX_METRICS,
METRIC_SYSTEM_TIME_HISTOGRAM), new long[] {100, 50}),
+ IllegalArgumentException.class);
+
bean.configureHistogramMetric(metricName(TX_METRICS,
METRIC_SYSTEM_TIME_HISTOGRAM), BOUNDS);
HistogramMetric sysTime = g.context().metric().registry(TX_METRICS)
@@ -226,6 +230,11 @@ public class MetricsConfigurationTest extends
GridCommonAbstractTest {
// Check buckets count including dummy bucket.
assertEquals(PeriodicHistogramMetricImpl.DFLT_BUCKETS_CNT + 1,
histogram.bucketsCount());
+ // Buckets interval is set by the first two bounds.
+ assertThrowsWithCause(
+ () -> bean.configureHistogramMetric(metricName(registry,
metricName), new long[] {60_000L}),
+ IllegalArgumentException.class);
+
// Reconfigure with 5 buckets and 1 minute interval.
long interval = 60_000L;
long[] bounds = new long[] {0L, interval, 0L, 0L, 0L};
@@ -235,6 +244,15 @@ public class MetricsConfigurationTest extends
GridCommonAbstractTest {
assertEquals(bounds.length + 1, histogram.bucketsCount());
assertEquals(interval, histogram.bucketsInterval());
+ // Check configuration after reactivation.
+ g.cluster().state(ClusterState.INACTIVE);
+ g.cluster().state(ClusterState.ACTIVE);
+
+ histogram =
g.context().metric().registry(registry).findMetric(metricName);
+
+ assertEquals(bounds.length + 1, histogram.bucketsCount());
+ assertEquals(interval, histogram.bucketsInterval());
+
// Check configuration after restart.
stopGrid("persistent-0", false);