This is an automated email from the ASF dual-hosted git repository. dsmiley pushed a commit to branch branch_10x in repository https://gitbox.apache.org/repos/asf/solr.git
commit 3cbdf1db4ac6209d5325355035b75c139fe4b3e8 Author: Eric Pugh <[email protected]> AuthorDate: Thu Aug 6 09:57:47 2026 -0400 Tidy up java code in o.a.s.metrics package (#4679) (cherry picked from commit c6deb8f3e973e797974f8dae7408443ffe302463) --- .../java/org/apache/solr/core/CoreContainer.java | 2 +- .../apache/solr/metrics/SolrCoreMetricManager.java | 23 +--------------------- .../org/apache/solr/metrics/SolrMetricManager.java | 20 ++++--------------- .../apache/solr/metrics/SolrMetricProducer.java | 16 +++++++-------- .../solr/metrics/otel/MetricExporterFactory.java | 11 +++++------ .../apache/solr/blockcache/BufferStoreTest.java | 4 +++- .../org/apache/solr/search/TestCaffeineCache.java | 4 +++- .../org/apache/solr/search/TestSolrCachePerf.java | 4 +++- .../test/org/apache/solr/search/TestThinCache.java | 4 +++- .../stats/OtelInstrumentedExecutorServiceTest.java | 4 +++- 10 files changed, 34 insertions(+), 58 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/core/CoreContainer.java b/solr/core/src/java/org/apache/solr/core/CoreContainer.java index d79c3b7b794..2afae17b49e 100644 --- a/solr/core/src/java/org/apache/solr/core/CoreContainer.java +++ b/solr/core/src/java/org/apache/solr/core/CoreContainer.java @@ -411,7 +411,7 @@ public class CoreContainer { this.solrCores = SolrCores.newSolrCores(this); this.nodeKeyPair = new SolrNodeKeyPair(cfg.getCloudConfig()); OpenTelemetryConfigurator.initializeOpenTelemetrySdk(cfg, loader); - this.metricManager = new SolrMetricManager(loader, cfg.getMetricsConfig()); + this.metricManager = new SolrMetricManager(loader); this.tracer = TraceUtils.getGlobalTracer(); containerHandlers.put(PublicKeyHandler.PATH, new PublicKeyHandler(nodeKeyPair)); diff --git a/solr/core/src/java/org/apache/solr/metrics/SolrCoreMetricManager.java b/solr/core/src/java/org/apache/solr/metrics/SolrCoreMetricManager.java index a79accb7aa7..1a50e0cc1ec 100644 --- a/solr/core/src/java/org/apache/solr/metrics/SolrCoreMetricManager.java +++ b/solr/core/src/java/org/apache/solr/metrics/SolrCoreMetricManager.java @@ -163,7 +163,7 @@ public class SolrCoreMetricManager implements Closeable { * that logically belong to a single collection we convert the core name into a dot-separated * hierarchy of: collection name, shard name (with optional split) and replica name. * - * <p>For example, when the core name looks like this but it's NOT a SolrCloud collection: <code> + * <p>For example, when the core name looks like this, but it's NOT a SolrCloud collection: <code> * my_collection_shard1_1_replica1</code> then this will be used as the registry name (plus the * required <code>solr.core</code> prefix). However, if this is a SolrCloud collection <code> * my_collection</code> then the registry name will become <code> @@ -184,25 +184,4 @@ public class SolrCoreMetricManager implements Closeable { return SolrMetricManager.enforcePrefix("core." + coreName); } } - - /** - * This method is used by {@link org.apache.solr.core.CoreContainer#rename(String, String)}. - * - * @param aCore existing core with old name - * @param coreName new name - * @return new registry name - */ - public static String createRegistryName(SolrCore aCore, String coreName) { - CloudDescriptor cd = aCore.getCoreDescriptor().getCloudDescriptor(); - String replicaName = null; - if (cd != null) { - replicaName = Utils.parseMetricsReplicaName(cd.getCollectionName(), coreName); - } - return createRegistryName( - cd != null, - cd != null ? cd.getCollectionName() : null, - cd != null ? cd.getShardId() : null, - replicaName, - coreName); - } } diff --git a/solr/core/src/java/org/apache/solr/metrics/SolrMetricManager.java b/solr/core/src/java/org/apache/solr/metrics/SolrMetricManager.java index 4408eca7d45..336610c536d 100644 --- a/solr/core/src/java/org/apache/solr/metrics/SolrMetricManager.java +++ b/solr/core/src/java/org/apache/solr/metrics/SolrMetricManager.java @@ -62,13 +62,10 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.TimeUnit; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; import java.util.function.Consumer; import java.util.stream.Collectors; import org.apache.solr.common.SolrException; import org.apache.solr.common.util.IOUtils; -import org.apache.solr.core.MetricsConfig; import org.apache.solr.core.SolrCore; import org.apache.solr.core.SolrInfoBean; import org.apache.solr.core.SolrResourceLoader; @@ -95,7 +92,7 @@ import org.slf4j.LoggerFactory; * <li>Access to metric instruments such as {@link LongCounter}, {@link LongUpDownCounter}, {@link * LongGauge}, {@link LongHistogram} and observable instruments to a specific MeterProvider * instances - * <li>{@link FilterablePrometheusMetricReader} for reading and fitlering OpenTelemetry metrics in + * <li>{@link FilterablePrometheusMetricReader} for reading and filtering OpenTelemetry metrics in * Prometheus Format from all MeterProviders * <li>Enablement of optional OTLP exporter * </ul> @@ -116,19 +113,12 @@ public class SolrMetricManager { * Registry name for JVM-specific metrics. This name is also subject to overrides controlled by * system properties. This registry is shared between instances of {@link SolrMetricManager}. */ - public static final String JVM_REGISTRY = - REGISTRY_NAME_PREFIX + SolrInfoBean.Group.jvm.toString(); + public static final String JVM_REGISTRY = REGISTRY_NAME_PREFIX + SolrInfoBean.Group.jvm; - public static final String NODE_REGISTRY = - REGISTRY_NAME_PREFIX + SolrInfoBean.Group.node.toString(); - - private final Lock reportersLock = new ReentrantLock(); - private final Lock swapLock = new ReentrantLock(); + public static final String NODE_REGISTRY = REGISTRY_NAME_PREFIX + SolrInfoBean.Group.node; public static final int DEFAULT_CLOUD_REPORTER_PERIOD = 60; - private final MetricsConfig metricsConfig; - private final ConcurrentMap<String, MeterProviderAndReaders> meterProviderAndReaders = new ConcurrentHashMap<>(); @@ -153,12 +143,10 @@ public class SolrMetricManager { 1_000_000_000.0); public SolrMetricManager(MetricExporter exporter) { - metricsConfig = new MetricsConfig.MetricsConfigBuilder().build(); metricExporter = exporter; } - public SolrMetricManager(SolrResourceLoader loader, MetricsConfig metricsConfig) { - this.metricsConfig = metricsConfig; + public SolrMetricManager(SolrResourceLoader loader) { this.metricExporter = loadMetricExporter(loader); this.otelRuntimeJvmMetrics = new OtelRuntimeJvmMetrics().initialize(this, JVM_REGISTRY); } diff --git a/solr/core/src/java/org/apache/solr/metrics/SolrMetricProducer.java b/solr/core/src/java/org/apache/solr/metrics/SolrMetricProducer.java index fb6ae3102e1..3789529665d 100644 --- a/solr/core/src/java/org/apache/solr/metrics/SolrMetricProducer.java +++ b/solr/core/src/java/org/apache/solr/metrics/SolrMetricProducer.java @@ -24,14 +24,14 @@ import org.apache.solr.common.util.IOUtils; /** Used by objects that expose metrics through {@link SolrMetricManager}. */ public interface SolrMetricProducer extends AutoCloseable { - public static final AttributeKey<String> TYPE_ATTR = AttributeKey.stringKey("type"); - public static final AttributeKey<String> CATEGORY_ATTR = AttributeKey.stringKey("category"); - public static final AttributeKey<String> HANDLER_ATTR = AttributeKey.stringKey("handler"); - public static final AttributeKey<String> OPERATION_ATTR = AttributeKey.stringKey("ops"); - public static final AttributeKey<String> RESULT_ATTR = AttributeKey.stringKey("result"); - public static final AttributeKey<String> NAME_ATTR = AttributeKey.stringKey("name"); - public static final AttributeKey<String> PLUGIN_NAME_ATTR = AttributeKey.stringKey("plugin_name"); - public static final AttributeKey<String> STATE_KEY_ATTR = AttributeKey.stringKey("state"); + AttributeKey<String> TYPE_ATTR = AttributeKey.stringKey("type"); + AttributeKey<String> CATEGORY_ATTR = AttributeKey.stringKey("category"); + AttributeKey<String> HANDLER_ATTR = AttributeKey.stringKey("handler"); + AttributeKey<String> OPERATION_ATTR = AttributeKey.stringKey("ops"); + AttributeKey<String> RESULT_ATTR = AttributeKey.stringKey("result"); + AttributeKey<String> NAME_ATTR = AttributeKey.stringKey("name"); + AttributeKey<String> PLUGIN_NAME_ATTR = AttributeKey.stringKey("plugin_name"); + AttributeKey<String> STATE_KEY_ATTR = AttributeKey.stringKey("state"); /** * Unique metric tag identifies components with the same life-cycle, which should be registered / diff --git a/solr/core/src/java/org/apache/solr/metrics/otel/MetricExporterFactory.java b/solr/core/src/java/org/apache/solr/metrics/otel/MetricExporterFactory.java index e6f1f24e85c..301c1f6a840 100644 --- a/solr/core/src/java/org/apache/solr/metrics/otel/MetricExporterFactory.java +++ b/solr/core/src/java/org/apache/solr/metrics/otel/MetricExporterFactory.java @@ -21,19 +21,18 @@ import org.apache.solr.common.util.EnvUtils; public interface MetricExporterFactory { - public static final Boolean OTLP_EXPORTER_ENABLED = + Boolean OTLP_EXPORTER_ENABLED = Boolean.parseBoolean(EnvUtils.getProperty("solr.metrics.otlpExporterEnabled", "false")); - public static final String OTLP_EXPORTER_PROTOCOL = - EnvUtils.getProperty("solr.metrics.otlpExporterProtocol", "http"); + String OTLP_EXPORTER_PROTOCOL = EnvUtils.getProperty("solr.metrics.otlpExporterProtocol", "http"); - public static final int OTLP_EXPORTER_INTERVAL = + int OTLP_EXPORTER_INTERVAL = Integer.parseInt(EnvUtils.getProperty("solr.metrics.otlpExporterInterval", "60000")); - public static final String OTLP_EXPORTER_GRPC_ENDPOINT = + String OTLP_EXPORTER_GRPC_ENDPOINT = EnvUtils.getProperty("solr.metrics.otlpGrpcExporterEndpoint", "http://localhost:4317"); - public static final String OTLP_EXPORTER_HTTP_ENDPOINT = + String OTLP_EXPORTER_HTTP_ENDPOINT = EnvUtils.getProperty( "solr.metrics.otlpHttpExporterEndpoint", "http://localhost:4318/v1/metrics"); diff --git a/solr/core/src/test/org/apache/solr/blockcache/BufferStoreTest.java b/solr/core/src/test/org/apache/solr/blockcache/BufferStoreTest.java index 7e0171b0d4b..011b9bc5830 100644 --- a/solr/core/src/test/org/apache/solr/blockcache/BufferStoreTest.java +++ b/solr/core/src/test/org/apache/solr/blockcache/BufferStoreTest.java @@ -17,6 +17,7 @@ package org.apache.solr.blockcache; import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.sdk.metrics.export.MetricExporter; import io.prometheus.metrics.model.snapshots.GaugeSnapshot; import io.prometheus.metrics.model.snapshots.Labels; import org.apache.lucene.tests.util.TestUtil; @@ -41,7 +42,8 @@ public class BufferStoreTest extends SolrTestCase { @Before public void setup() { metrics = new Metrics(); - metricManager = new SolrMetricManager(null); + MetricExporter me = null; + metricManager = new SolrMetricManager(me); registry = TestUtil.randomSimpleString(random(), 2, 10); solrMetricsContext = new SolrMetricsContext(metricManager, registry); metrics.initializeMetrics(solrMetricsContext, Attributes.empty()); diff --git a/solr/core/src/test/org/apache/solr/search/TestCaffeineCache.java b/solr/core/src/test/org/apache/solr/search/TestCaffeineCache.java index 39ea9223173..ec951df0439 100644 --- a/solr/core/src/test/org/apache/solr/search/TestCaffeineCache.java +++ b/solr/core/src/test/org/apache/solr/search/TestCaffeineCache.java @@ -22,6 +22,7 @@ import com.github.benmanes.caffeine.cache.Cache; import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.RemovalCause; import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.sdk.metrics.export.MetricExporter; import io.prometheus.metrics.model.snapshots.CounterSnapshot; import io.prometheus.metrics.model.snapshots.Labels; import java.io.IOException; @@ -46,7 +47,8 @@ import org.junit.Test; /** Test for {@link CaffeineCache}. */ public class TestCaffeineCache extends SolrTestCase { - SolrMetricManager metricManager = new SolrMetricManager(null); + MetricExporter me = null; + SolrMetricManager metricManager = new SolrMetricManager(me); String registry = TestUtil.randomSimpleString(random(), 2, 10); String scope = TestUtil.randomSimpleString(random(), 2, 10); diff --git a/solr/core/src/test/org/apache/solr/search/TestSolrCachePerf.java b/solr/core/src/test/org/apache/solr/search/TestSolrCachePerf.java index 36645bdde06..26d71abbc15 100644 --- a/solr/core/src/test/org/apache/solr/search/TestSolrCachePerf.java +++ b/solr/core/src/test/org/apache/solr/search/TestSolrCachePerf.java @@ -19,6 +19,7 @@ package org.apache.solr.search; import static org.apache.solr.metrics.SolrMetricProducer.NAME_ATTR; import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.sdk.metrics.export.MetricExporter; import io.prometheus.metrics.model.snapshots.Labels; import java.io.IOException; import java.util.ArrayList; @@ -102,7 +103,8 @@ public class TestSolrCachePerf extends SolrTestCaseJ4 { boolean useCompute) throws Exception { for (Class<? extends SolrCache> clazz : IMPLS) { - SolrMetricManager metricManager = new SolrMetricManager(null); + MetricExporter me = null; + SolrMetricManager metricManager = new SolrMetricManager(me); @SuppressWarnings({"unchecked"}) SolrCache<String, String> cache = clazz.getDeclaredConstructor().newInstance(); Map<String, String> params = new HashMap<>(); diff --git a/solr/core/src/test/org/apache/solr/search/TestThinCache.java b/solr/core/src/test/org/apache/solr/search/TestThinCache.java index fb39a019913..7d668a8e9ed 100644 --- a/solr/core/src/test/org/apache/solr/search/TestThinCache.java +++ b/solr/core/src/test/org/apache/solr/search/TestThinCache.java @@ -21,6 +21,7 @@ import static org.apache.solr.metrics.SolrMetricProducer.CATEGORY_ATTR; import static org.apache.solr.metrics.SolrMetricProducer.NAME_ATTR; import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.sdk.metrics.export.MetricExporter; import io.prometheus.metrics.model.snapshots.Labels; import java.io.IOException; import java.nio.file.Files; @@ -95,7 +96,8 @@ public class TestThinCache extends SolrTestCaseJ4 { lrf = h.getRequestFactory("/select", 0, 20); } - SolrMetricManager metricManager = new SolrMetricManager(null); + MetricExporter me = null; + SolrMetricManager metricManager = new SolrMetricManager(me); String registry = TestUtil.randomSimpleString(random(), 2, 10); @Test diff --git a/solr/core/src/test/org/apache/solr/util/stats/OtelInstrumentedExecutorServiceTest.java b/solr/core/src/test/org/apache/solr/util/stats/OtelInstrumentedExecutorServiceTest.java index 336995f3aa0..ee2684996dd 100644 --- a/solr/core/src/test/org/apache/solr/util/stats/OtelInstrumentedExecutorServiceTest.java +++ b/solr/core/src/test/org/apache/solr/util/stats/OtelInstrumentedExecutorServiceTest.java @@ -19,6 +19,7 @@ package org.apache.solr.util.stats; import static com.carrotsearch.randomizedtesting.RandomizedTest.randomIntBetween; import static org.apache.solr.metrics.SolrMetricProducer.TYPE_ATTR; +import io.opentelemetry.sdk.metrics.export.MetricExporter; import io.prometheus.metrics.model.snapshots.CounterSnapshot; import io.prometheus.metrics.model.snapshots.CounterSnapshot.CounterDataPointSnapshot; import io.prometheus.metrics.model.snapshots.GaugeSnapshot; @@ -51,7 +52,8 @@ public class OtelInstrumentedExecutorServiceTest extends SolrTestCase { @Before public void setUpMetrics() { - metricsContext = new SolrMetricsContext(new SolrMetricManager(null), REGISTRY_NAME); + MetricExporter me = null; + metricsContext = new SolrMetricsContext(new SolrMetricManager(me), REGISTRY_NAME); } @After
