Skip to content

Commit 4d8057a

Browse files
authored
SOLR-17458: OTEL metrics: some renames (#3826)
Units: index & disk size metric units changes from bytes (long) to megabytes (double). Affects: solr_disk_space, solr_core_disk_space, solr_core_index_size, solr_core_replication_index_size, solr_core_indexsearcher_index_commit_size Renames: * solr_executor to solr_core_executor or solr_node_executor * solr_replication to solr_core_replication * solr_field_cache to solr_core_field_cache * solr_searcher to solr_core_indexsearcher * solr_indexwriter to solr_core_indexwriter * solr_searcher_timer to solr_core_indexsearcher_open_time and solr_core_indexsearcher_open_warmup_time * attribute executor_name to name When aggregating core metrics to the node level: * don't strip off these attributes: internal, replica_type * keep solr_core prefix, even when aggregated to node, since they relate to cores Moved instrumentedExecutorService() to SolrMetricsContext
1 parent 92aff63 commit 4d8057a

33 files changed

+230
-207
lines changed

solr/core/src/java/org/apache/solr/cluster/placement/impl/MetricImpl.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
/** Base class for {@link Metric} implementations. */
2424
public abstract class MetricImpl<T> implements Metric<T> {
2525

26-
public static final double GB = 1024 * 1024 * 1024;
27-
2826
/**
2927
* Identity converter. It returns the raw value unchanged IFF the value's type can be cast to the
3028
* generic type of this attribute, otherwise it returns null.
@@ -40,25 +38,25 @@ public abstract class MetricImpl<T> implements Metric<T> {
4038
};
4139

4240
/**
43-
* Bytes to gigabytes converter. Supports converting number or string representations of raw
44-
* values expressed in bytes.
41+
* Megabytes to gigabytes converter. Supports converting number or string representations of raw
42+
* values expressed in megabytes.
4543
*/
46-
public static final Function<Object, Double> BYTES_TO_GB_CONVERTER =
44+
public static final Function<Object, Double> MB_TO_GB_CONVERTER =
4745
v -> {
48-
double sizeInBytes;
46+
double sizeInMB;
4947
if (!(v instanceof Number)) {
5048
if (v == null) {
5149
return null;
5250
}
5351
try {
54-
sizeInBytes = Double.parseDouble(String.valueOf(v));
52+
sizeInMB = Double.parseDouble(String.valueOf(v));
5553
} catch (Exception nfe) {
5654
return null;
5755
}
5856
} else {
59-
sizeInBytes = ((Number) v).doubleValue();
57+
sizeInMB = ((Number) v).doubleValue();
6058
}
61-
return sizeInBytes / GB;
59+
return sizeInMB / 1024.0;
6260
};
6361

6462
protected final String name;

solr/core/src/java/org/apache/solr/cluster/placement/impl/NodeMetricImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ public class NodeMetricImpl<T> extends MetricImpl<T> implements NodeMetric<T> {
2626

2727
/** Total disk space in GB. */
2828
public static final NodeMetricImpl<Double> TOTAL_DISK_GB =
29-
new NodeMetricImpl<>("totaldisk", BYTES_TO_GB_CONVERTER);
29+
new NodeMetricImpl<>("totaldisk", MB_TO_GB_CONVERTER);
3030

3131
/** Free (usable) disk space in GB. */
3232
public static final NodeMetricImpl<Double> FREE_DISK_GB =
33-
new NodeMetricImpl<>("freedisk", BYTES_TO_GB_CONVERTER);
33+
new NodeMetricImpl<>("freedisk", MB_TO_GB_CONVERTER);
3434

3535
/** Number of all cores. */
3636
public static final NodeMetricImpl<Integer> NUM_CORES =

solr/core/src/java/org/apache/solr/cluster/placement/impl/ReplicaMetricImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
public class ReplicaMetricImpl<T> extends MetricImpl<T> implements ReplicaMetric<T> {
2727
/** Replica index size in GB. */
2828
public static final ReplicaMetricImpl<Double> INDEX_SIZE_GB =
29-
new ReplicaMetricImpl<>("sizeGB", "solr_core_index_size_bytes", BYTES_TO_GB_CONVERTER);
29+
new ReplicaMetricImpl<>("sizeGB", "solr_core_index_size_megabytes", MB_TO_GB_CONVERTER);
3030

3131
public ReplicaMetricImpl(String name, String internalName) {
3232
super(name, internalName);

solr/core/src/java/org/apache/solr/core/CoreContainer.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -913,17 +913,17 @@ private void loadInternal() {
913913
Path dataHome =
914914
cfg.getSolrDataHome() != null ? cfg.getSolrDataHome() : cfg.getCoreRootDirectory();
915915

916-
solrMetricsContext.observableLongGauge(
916+
solrMetricsContext.observableDoubleGauge(
917917
"solr_disk_space",
918918
"Disk metrics for Solr's data home directory (" + dataHome + ")",
919919
measurement -> {
920920
try {
921921
var fileStore = Files.getFileStore(dataHome);
922922
measurement.record(
923-
fileStore.getTotalSpace(),
923+
MetricUtils.bytesToMegabytes(fileStore.getTotalSpace()),
924924
containerAttrs.toBuilder().put(TYPE_ATTR, "total_space").build());
925925
measurement.record(
926-
fileStore.getUsableSpace(),
926+
MetricUtils.bytesToMegabytes(fileStore.getUsableSpace()),
927927
containerAttrs.toBuilder().put(TYPE_ATTR, "usable_space").build());
928928
} catch (IOException e) {
929929
throw new SolrException(
@@ -932,21 +932,21 @@ private void loadInternal() {
932932
e);
933933
}
934934
},
935-
OtelUnit.BYTES);
935+
OtelUnit.MEGABYTES);
936936

937937
SolrFieldCacheBean fieldCacheBean = new SolrFieldCacheBean();
938938
fieldCacheBean.initializeMetrics(
939939
solrMetricsContext, Attributes.of(CATEGORY_ATTR, SolrInfoBean.Category.CACHE.toString()));
940940

941941
// setup executor to load cores in parallel
942942
coreLoadExecutor =
943-
MetricUtils.instrumentedExecutorService(
943+
solrMetricsContext.instrumentedExecutorService(
944944
ExecutorUtil.newMDCAwareFixedThreadPool(
945945
cfg.getCoreLoadThreadCount(isZooKeeperAware()),
946946
new SolrNamedThreadFactory("coreLoadExecutor")),
947-
solrMetricsContext,
948-
SolrInfoBean.Category.CONTAINER,
949-
"coreLoadExecutor");
947+
"solr_node_executor",
948+
"coreLoadExecutor",
949+
SolrInfoBean.Category.CONTAINER);
950950

951951
coreSorter =
952952
loader.newInstance(

solr/core/src/java/org/apache/solr/core/SolrCore.java

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@
181181
import org.apache.solr.util.plugin.NamedListInitializedPlugin;
182182
import org.apache.solr.util.plugin.PluginInfoInitialized;
183183
import org.apache.solr.util.plugin.SolrCoreAware;
184+
import org.apache.solr.util.stats.MetricUtils;
184185
import org.apache.zookeeper.KeeperException;
185186
import org.apache.zookeeper.data.Stat;
186187
import org.eclipse.jetty.io.RuntimeIOException;
@@ -489,7 +490,7 @@ public IndexReaderFactory getIndexReaderFactory() {
489490
}
490491

491492
/**
492-
* Recalculates the index size.
493+
* Calculates the index size.
493494
*
494495
* <p>Should only be called from {@code getIndexSize}.
495496
*
@@ -515,6 +516,7 @@ private long calculateIndexSize() {
515516
return size;
516517
}
517518

519+
/** The index size in bytes, of the index that the current searcher is pointed to. */
518520
public long getIndexSize() {
519521
SolrRequestInfo requestInfo = SolrRequestInfo.getRequestInfo();
520522
if (requestInfo != null) {
@@ -1345,10 +1347,6 @@ public void initializeMetrics(SolrMetricsContext parentContext, Attributes attri
13451347
.put(CATEGORY_ATTR, Category.CORE.toString())
13461348
.build();
13471349

1348-
var baseSearcherTimerMetric =
1349-
parentContext.longHistogram(
1350-
"solr_searcher_timer", "Timer for opening new searchers", OtelUnit.MILLISECONDS);
1351-
13521350
newSearcherCounter =
13531351
new AttributedLongCounter(
13541352
parentContext.longCounter(
@@ -1370,13 +1368,19 @@ public void initializeMetrics(SolrMetricsContext parentContext, Attributes attri
13701368

13711369
newSearcherTimer =
13721370
new AttributedLongTimer(
1373-
baseSearcherTimerMetric,
1374-
Attributes.builder().putAll(baseSearcherAttributes).put(TYPE_ATTR, "new").build());
1371+
parentContext.longHistogram(
1372+
"solr_core_indexsearcher_open_time",
1373+
"Time to open new searchers",
1374+
OtelUnit.MILLISECONDS),
1375+
baseSearcherAttributes);
13751376

13761377
newSearcherWarmupTimer =
13771378
new AttributedLongTimer(
1378-
baseSearcherTimerMetric,
1379-
Attributes.builder().putAll(baseSearcherAttributes).put(TYPE_ATTR, "warmup").build());
1379+
parentContext.longHistogram(
1380+
"solr_core_indexsearcher_open_warmup_time",
1381+
"Time to warmup new searchers",
1382+
OtelUnit.MILLISECONDS),
1383+
baseSearcherAttributes);
13801384

13811385
observables.add(
13821386
parentContext.observableLongGauge(
@@ -1387,10 +1391,10 @@ public void initializeMetrics(SolrMetricsContext parentContext, Attributes attri
13871391
})));
13881392

13891393
observables.add(
1390-
parentContext.observableLongGauge(
1394+
parentContext.observableDoubleGauge(
13911395
"solr_core_disk_space",
13921396
"Solr core disk space metrics",
1393-
(observableLongMeasurement -> {
1397+
(observableDoubleMeasurement -> {
13941398

13951399
// initialize disk total / free metrics
13961400
Path dataDirPath = Path.of(dataDir);
@@ -1405,29 +1409,32 @@ public void initializeMetrics(SolrMetricsContext parentContext, Attributes attri
14051409
.put(TYPE_ATTR, "usable_space")
14061410
.build();
14071411
try {
1408-
observableLongMeasurement.record(
1409-
Files.getFileStore(dataDirPath).getTotalSpace(), totalSpaceAttributes);
1412+
observableDoubleMeasurement.record(
1413+
MetricUtils.bytesToMegabytes(Files.getFileStore(dataDirPath).getTotalSpace()),
1414+
totalSpaceAttributes);
14101415
} catch (IOException e) {
1411-
observableLongMeasurement.record(0L, totalSpaceAttributes);
1416+
observableDoubleMeasurement.record(0.0, totalSpaceAttributes);
14121417
}
14131418
try {
1414-
observableLongMeasurement.record(
1415-
Files.getFileStore(dataDirPath).getUsableSpace(), usableSpaceAttributes);
1419+
observableDoubleMeasurement.record(
1420+
MetricUtils.bytesToMegabytes(Files.getFileStore(dataDirPath).getUsableSpace()),
1421+
usableSpaceAttributes);
14161422
} catch (IOException e) {
1417-
observableLongMeasurement.record(0L, usableSpaceAttributes);
1423+
observableDoubleMeasurement.record(0.0, usableSpaceAttributes);
14181424
}
14191425
}),
1420-
OtelUnit.BYTES));
1426+
OtelUnit.MEGABYTES));
14211427

14221428
observables.add(
1423-
parentContext.observableLongGauge(
1429+
parentContext.observableDoubleGauge(
14241430
"solr_core_index_size",
14251431
"Index size for a Solr core",
1426-
(observableLongMeasurement -> {
1432+
(observableDoubleMeasurement -> {
14271433
if (!isClosed())
1428-
observableLongMeasurement.record(getIndexSize(), baseGaugeCoreAttributes);
1434+
observableDoubleMeasurement.record(
1435+
MetricUtils.bytesToMegabytes(getIndexSize()), baseGaugeCoreAttributes);
14291436
}),
1430-
OtelUnit.BYTES));
1437+
OtelUnit.MEGABYTES));
14311438

14321439
parentContext.observableLongGauge(
14331440
"solr_core_segments",

solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
import io.opentelemetry.api.common.Attributes;
3434
import io.opentelemetry.api.metrics.BatchCallback;
35+
import io.opentelemetry.api.metrics.ObservableDoubleMeasurement;
3536
import io.opentelemetry.api.metrics.ObservableLongMeasurement;
3637
import java.io.FileNotFoundException;
3738
import java.io.IOException;
@@ -114,6 +115,7 @@
114115
import org.apache.solr.util.PropertiesInputStream;
115116
import org.apache.solr.util.RefCounted;
116117
import org.apache.solr.util.plugin.SolrCoreAware;
118+
import org.apache.solr.util.stats.MetricUtils;
117119
import org.slf4j.Logger;
118120
import org.slf4j.LoggerFactory;
119121
import org.slf4j.MDC;
@@ -850,59 +852,64 @@ public void initializeMetrics(SolrMetricsContext parentContext, Attributes attri
850852
.build();
851853
super.initializeMetrics(parentContext, replicationAttributes);
852854

853-
ObservableLongMeasurement indexSizeMetric =
854-
solrMetricsContext.longGaugeMeasurement(
855-
"solr_replication_index_size", "Size of the index in bytes", OtelUnit.BYTES);
855+
ObservableDoubleMeasurement indexSizeMetric =
856+
solrMetricsContext.doubleGaugeMeasurement(
857+
"solr_core_replication_index_size",
858+
"Size of the index in megabytes",
859+
OtelUnit.MEGABYTES);
856860

857861
ObservableLongMeasurement indexVersionMetric =
858862
solrMetricsContext.longGaugeMeasurement(
859-
"solr_replication_index_version", "Current index version");
863+
"solr_core_replication_index_version", "Current index version");
860864

861865
ObservableLongMeasurement indexGenerationMetric =
862866
solrMetricsContext.longGaugeMeasurement(
863-
"solr_replication_index_generation", "Current index generation");
867+
"solr_core_replication_index_generation", "Current index generation");
864868

865869
ObservableLongMeasurement isLeaderMetric =
866870
solrMetricsContext.longGaugeMeasurement(
867-
"solr_replication_is_leader", "Whether this node is a leader (1) or not (0)");
871+
"solr_core_replication_is_leader", "Whether this node is a leader (1) or not (0)");
868872

869873
ObservableLongMeasurement isFollowerMetric =
870874
solrMetricsContext.longGaugeMeasurement(
871-
"solr_replication_is_follower", "Whether this node is a follower (1) or not (0)");
875+
"solr_core_replication_is_follower", "Whether this node is a follower (1) or not (0)");
872876

873877
ObservableLongMeasurement replicationEnabledMetric =
874878
solrMetricsContext.longGaugeMeasurement(
875-
"solr_replication_is_enabled", "Whether replication is enabled (1) or not (0)");
879+
"solr_core_replication_is_enabled", "Whether replication is enabled (1) or not (0)");
876880

877881
ObservableLongMeasurement isPollingDisabledMetric =
878882
solrMetricsContext.longGaugeMeasurement(
879-
"solr_replication_is_polling_disabled", "Whether polling is disabled (1) or not (0)");
883+
"solr_core_replication_is_polling_disabled",
884+
"Whether polling is disabled (1) or not (0)");
880885

881886
ObservableLongMeasurement isReplicatingMetric =
882887
solrMetricsContext.longGaugeMeasurement(
883-
"solr_replication_is_replicating", "Whether replication is in progress (1) or not (0)");
888+
"solr_core_replication_is_replicating",
889+
"Whether replication is in progress (1) or not (0)");
884890

885891
ObservableLongMeasurement timeElapsedMetric =
886892
solrMetricsContext.longGaugeMeasurement(
887-
"solr_replication_time_elapsed",
893+
"solr_core_replication_time_elapsed",
888894
"Time elapsed during replication in seconds",
889895
OtelUnit.SECONDS);
890896

891897
ObservableLongMeasurement bytesDownloadedMetric =
892898
solrMetricsContext.longGaugeMeasurement(
893-
"solr_replication_downloaded_size",
899+
"solr_core_replication_downloaded_size",
894900
"Total bytes downloaded during replication",
895901
OtelUnit.BYTES);
896902

897903
ObservableLongMeasurement downloadSpeedMetric =
898904
solrMetricsContext.longGaugeMeasurement(
899-
"solr_replication_download_speed", "Download speed in bytes per second");
905+
"solr_core_replication_download_speed", "Download speed in bytes per second");
900906

901907
metricsCallback =
902908
solrMetricsContext.batchCallback(
903909
() -> {
904910
if (core != null && !core.isClosed()) {
905-
indexSizeMetric.record(core.getIndexSize(), replicationAttributes);
911+
indexSizeMetric.record(
912+
MetricUtils.bytesToMegabytes(core.getIndexSize()), replicationAttributes);
906913

907914
CommitVersionInfo vInfo = getIndexVersion();
908915
if (vInfo != null) {

solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@
7979
import org.apache.solr.response.SolrQueryResponse;
8080
import org.apache.solr.security.AuthorizationContext;
8181
import org.apache.solr.security.PermissionNameProvider;
82-
import org.apache.solr.util.stats.MetricUtils;
8382
import org.apache.solr.util.tracing.TraceUtils;
8483
import org.slf4j.Logger;
8584
import org.slf4j.LoggerFactory;
@@ -131,18 +130,18 @@ public final void init(NamedList<?> args) {
131130
public void initializeMetrics(SolrMetricsContext parentContext, Attributes attributes) {
132131
super.initializeMetrics(parentContext, attributes);
133132
coreAdminAsyncTracker.standardExecutor =
134-
MetricUtils.instrumentedExecutorService(
133+
solrMetricsContext.instrumentedExecutorService(
135134
coreAdminAsyncTracker.standardExecutor,
136-
solrMetricsContext,
137-
getCategory(),
138-
"parallelCoreAdminExecutor");
135+
"solr_node_executor",
136+
"asyncCoreAdminExecutor",
137+
getCategory());
139138

140139
coreAdminAsyncTracker.expensiveExecutor =
141-
MetricUtils.instrumentedExecutorService(
140+
solrMetricsContext.instrumentedExecutorService(
142141
coreAdminAsyncTracker.expensiveExecutor,
143-
solrMetricsContext,
144-
getCategory(),
145-
"parallelCoreExpensiveAdminExecutor");
142+
"solr_node_executor",
143+
"asyncCoreExpensiveAdminExecutor",
144+
getCategory());
146145
}
147146

148147
@Override

solr/core/src/java/org/apache/solr/handler/component/HttpShardHandlerFactory.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
import org.apache.solr.security.HttpClientBuilderPlugin;
6262
import org.apache.solr.update.UpdateShardHandlerConfig;
6363
import org.apache.solr.util.stats.InstrumentedHttpListenerFactory;
64-
import org.apache.solr.util.stats.MetricUtils;
6564
import org.slf4j.Logger;
6665
import org.slf4j.LoggerFactory;
6766

@@ -436,7 +435,7 @@ public void initializeMetrics(SolrMetricsContext parentContext, Attributes attri
436435
solrMetricsContext = parentContext.getChildContext(this);
437436
httpListenerFactory.initializeMetrics(solrMetricsContext, Attributes.empty());
438437
commExecutor =
439-
MetricUtils.instrumentedExecutorService(
440-
commExecutor, solrMetricsContext, SolrInfoBean.Category.QUERY, "httpShardExecutor");
438+
solrMetricsContext.instrumentedExecutorService(
439+
commExecutor, "solr_core_executor", "httpShardExecutor", SolrInfoBean.Category.QUERY);
441440
}
442441
}

0 commit comments

Comments
 (0)