Apache Solr open-source search software
SOLR-18124: Trace index replication with a span (#4963)
David Smiley6d6504668e3c
diff --git a/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java b/solr/core/src/java/org/apache/solr/handler/IndexFetcher.javaindex b6fa1146959..2652f2add4c 100644--- a/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java+++ b/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java@@ -37,6 +37,7 @@ import static org.apache.solr.handler.admin.api.ReplicationAPIBase.FILE_STREAM;import static org.apache.solr.handler.admin.api.ReplicationAPIBase.GENERATION;import static org.apache.solr.handler.admin.api.ReplicationAPIBase.OFFSET;+import io.opentelemetry.api.trace.Span;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;@@ -499,6 +500,9 @@ public class IndexFetcher {log.info("Leader's generation: {}", latestGeneration);log.info("Leader's version: {}", latestVersion);+ Span.current()+ .setAttribute("replication.leader", leaderCoreUrl)+ .setAttribute("replication.leaderGeneration", latestGeneration);// TODO: make sure that getLatestCommit only returns commit points for the main index (i.e. no// side-car indexes)@@ -576,6 +580,7 @@ public class IndexFetcher {if (log.isInfoEnabled()) {log.info("Number of files in latest index in leader: {}", filesToDownload.size());}+ Span.current().setAttribute("replication.leaderFiles", filesToDownload.size());// Create the sync servicefsyncService =@@ -687,6 +692,9 @@ public class IndexFetcher {timeTakenSeconds,bytesDownloadedPerSecond,tmpIndexDir);+ Span.current()+ .setAttribute("replication.fullCopy", isFullCopyNeeded)+ .setAttribute("replication.bytesDownloaded", bytesDownloaded);Collection<Map<String, Object>> modifiedConfFiles =getModifiedConfFiles(confFilesToDownload);diff --git a/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java b/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.javaindex ddd9793932b..6278a33fbfb 100644--- a/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java+++ b/solr/core/src/java/org/apache/solr/handler/ReplicationHandler.java@@ -33,6 +33,8 @@ import static org.apache.solr.handler.admin.api.ReplicationAPIBase.TLOG_FILE;import io.opentelemetry.api.common.Attributes;import io.opentelemetry.api.metrics.ObservableDoubleMeasurement;import io.opentelemetry.api.metrics.ObservableLongMeasurement;+import io.opentelemetry.api.trace.Span;+import io.opentelemetry.api.trace.StatusCode;import java.io.FileNotFoundException;import java.io.IOException;import java.io.InputStream;@@ -115,6 +117,7 @@ import org.apache.solr.util.NumberUtils;import org.apache.solr.util.RefCounted;import org.apache.solr.util.plugin.SolrCoreAware;import org.apache.solr.util.stats.MetricUtils;+import org.apache.solr.util.tracing.TraceUtils;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.slf4j.MDC;@@ -497,9 +500,28 @@ public class ReplicationHandler extends RequestHandlerBaseprivate volatile IndexFetcher currentIndexFetcher;+ public IndexFetchResult doFetch(SolrParams solrParams, boolean forceReplication) {+ final Span span = TraceUtils.getGlobalTracer().spanBuilder("replication").startSpan();+ TraceUtils.setDbInstance(span, core.getName());+ try (var scope = span.makeCurrent()) {+ assert scope != null; // prevent javac warning about scope being unused+ IndexFetchResult result = doFetchInternal(solrParams, forceReplication);+ span.setAttribute("replication.result", result.getMessage());+ if (!result.getSuccessful()) {+ span.setStatus(StatusCode.ERROR);+ }+ if (result.getException() != null) {+ span.recordException(result.getException());+ }+ return result;+ } finally {+ span.end();+ }+ }+@SuppressWarnings("ReferenceEquality") // detecting the shared pollingIndexFetcher vs. a one-off, by identity- public IndexFetchResult doFetch(SolrParams solrParams, boolean forceReplication) {+ private IndexFetchResult doFetchInternal(SolrParams solrParams, boolean forceReplication) {String leaderUrl = solrParams.get(LEADER_URL, null);if (!indexFetchLock.tryLock()) return IndexFetchResult.LOCK_OBTAIN_FAILED;if (core.getCoreContainer().isShutDown()) {