You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by st...@apache.org on 2023/09/12 22:13:39 UTC

[solr] branch main updated: SOLR-15367 Convert "rid" functionality into a default Tracer (#1898)

This is an automated email from the ASF dual-hosted git repository.

stillalex pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/main by this push:
     new 04e92d7734f SOLR-15367 Convert "rid" functionality into a default Tracer (#1898)
04e92d7734f is described below

commit 04e92d7734f7304fbcb66a2b34099942223d8719
Author: Alex D <st...@apache.org>
AuthorDate: Tue Sep 12 15:13:34 2023 -0700

    SOLR-15367 Convert "rid" functionality into a default Tracer (#1898)
---
 solr/CHANGES.txt                                   |  4 +--
 .../solr/handler/component/SearchHandler.java      | 32 ++++++++++++++++++++--
 .../org/apache/solr/logging/MDCLoggingContext.java |  4 +++
 .../apache/solr/util/tracing/SimplePropagator.java |  4 +--
 .../pages/distributed-tracing.adoc                 |  9 ++++++
 .../pages/major-changes-in-solr-9.adoc             |  5 ++++
 .../apache/solr/common/params/CommonParams.java    |  4 +++
 7 files changed, 55 insertions(+), 7 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 86eeec69ea1..d9b09f16e59 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -19,8 +19,6 @@ Improvements
 
 * SOLR-16536: Replace OpenTracing instrumentation with OpenTelemetry (Alex Deparvu, janhoy)
 
-* SOLR-15367: Convert "rid" functionality into a default Tracer (Alex Deparvu, David Smiley)
-
 Optimizations
 ---------------------
 (No changes)
@@ -76,6 +74,8 @@ New Features
 
 * SOLR-15771: bin/auth creates reasonable roles and permissions for security: 'search', 'index', 'admin', and 'superadmin' and assigns user superadmin role. (Eric Pugh, janhoy)
 
+* SOLR-15367: Convert "rid" functionality into a default Tracer (Alex Deparvu, David Smiley)
+
 Improvements
 ---------------------
 * SOLR-16490: `/admin/cores?action=backupcore` now has a v2 equivalent, available at
diff --git a/solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java b/solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java
index be35ad99a1d..995e6a3c684 100644
--- a/solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java
+++ b/solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java
@@ -52,6 +52,7 @@ import org.apache.solr.core.CoreContainer;
 import org.apache.solr.core.PluginInfo;
 import org.apache.solr.core.SolrCore;
 import org.apache.solr.handler.RequestHandlerBase;
+import org.apache.solr.logging.MDCLoggingContext;
 import org.apache.solr.metrics.MetricsMap;
 import org.apache.solr.metrics.SolrMetricsContext;
 import org.apache.solr.pkg.PackageAPI;
@@ -86,9 +87,27 @@ public class SearchHandler extends RequestHandlerBase
 
   private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
-  /** A counter to ensure that no RID is equal, even if they fall in the same millisecond */
+  /**
+   * A counter to ensure that no RID is equal, even if they fall in the same millisecond
+   *
+   * @deprecated this was replaced by the auto-generated trace ids
+   */
+  @Deprecated(since = "9.4")
   private static final AtomicLong ridCounter = new AtomicLong();
 
+  /**
+   * An opt-out flag to prevent the addition of {@link CommonParams#REQUEST_ID} tracing on
+   * distributed queries
+   *
+   * <p>Defaults to 'false' if not specified.
+   *
+   * @see CommonParams#DISABLE_REQUEST_ID
+   * @deprecated this was replaced by the auto-generated trace ids
+   */
+  @Deprecated(since = "9.4")
+  private static final boolean DISABLE_REQUEST_ID_DEFAULT =
+      Boolean.getBoolean("solr.disableRequestId");
+
   private HandlerMetrics metricsShard = HandlerMetrics.NO_OP;
   private final Map<String, Counter> shardPurposes = new ConcurrentHashMap<>();
 
@@ -626,7 +645,7 @@ public class SearchHandler extends RequestHandlerBase
 
   private void tagRequestWithRequestId(ResponseBuilder rb) {
     final boolean ridTaggingDisabled =
-        rb.req.getParams().getBool(CommonParams.DISABLE_REQUEST_ID, false);
+        rb.req.getParams().getBool(CommonParams.DISABLE_REQUEST_ID, DISABLE_REQUEST_ID_DEFAULT);
     if (!ridTaggingDisabled) {
       String rid = getOrGenerateRequestId(rb.req);
 
@@ -665,7 +684,14 @@ public class SearchHandler extends RequestHandlerBase
    */
   public static String getOrGenerateRequestId(SolrQueryRequest req) {
     String rid = req.getParams().get(CommonParams.REQUEST_ID);
-    return StrUtils.isNotBlank(rid) ? rid : generateRid(req);
+    if (StrUtils.isNotBlank(rid)) {
+      return rid;
+    }
+    String traceId = MDCLoggingContext.getTraceId();
+    if (StrUtils.isNotBlank(traceId)) {
+      return traceId;
+    }
+    return generateRid(req);
   }
 
   private static String generateRid(SolrQueryRequest req) {
diff --git a/solr/core/src/java/org/apache/solr/logging/MDCLoggingContext.java b/solr/core/src/java/org/apache/solr/logging/MDCLoggingContext.java
index bebebf00945..28f4ee0e7b8 100644
--- a/solr/core/src/java/org/apache/solr/logging/MDCLoggingContext.java
+++ b/solr/core/src/java/org/apache/solr/logging/MDCLoggingContext.java
@@ -58,6 +58,10 @@ public class MDCLoggingContext {
     }
   }
 
+  public static String getTraceId() {
+    return MDC.get(TRACE_ID);
+  }
+
   public static void setShard(String shard) {
     if (shard != null) {
       MDC.put(SHARD_ID_PROP, shard);
diff --git a/solr/core/src/java/org/apache/solr/util/tracing/SimplePropagator.java b/solr/core/src/java/org/apache/solr/util/tracing/SimplePropagator.java
index 01a72e0a1ff..aa029899347 100644
--- a/solr/core/src/java/org/apache/solr/util/tracing/SimplePropagator.java
+++ b/solr/core/src/java/org/apache/solr/util/tracing/SimplePropagator.java
@@ -45,11 +45,11 @@ public class SimplePropagator implements TextMapPropagator {
   private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
   private static final String TRACE_HOST_NAME =
-      System.getProperty("trace_host_name", System.getProperty("host"));
+      System.getProperty("solr.traceHostName", System.getProperty("host"));
   private static final TextMapPropagator INSTANCE = new SimplePropagator();
   private static final ContextKey<String> TRACE_ID_KEY = ContextKey.named("trace_id");
 
-  static final String TRACE_ID = System.getProperty("TRACE_ID", "X-Trace-Id");
+  static final String TRACE_ID = System.getProperty("solr.traceIdHeader", "X-Trace-Id");
   private static final List<String> FIELDS = List.of(TRACE_ID);
 
   private static final AtomicLong traceCounter = new AtomicLong(0);
diff --git a/solr/solr-ref-guide/modules/deployment-guide/pages/distributed-tracing.adoc b/solr/solr-ref-guide/modules/deployment-guide/pages/distributed-tracing.adoc
index e51d7fbed15..18cac7c8695 100644
--- a/solr/solr-ref-guide/modules/deployment-guide/pages/distributed-tracing.adoc
+++ b/solr/solr-ref-guide/modules/deployment-guide/pages/distributed-tracing.adoc
@@ -25,6 +25,15 @@ A sampled distributed tracing query request displayed in Jaeger UI looks like th
 .Tracing of a Solr query
 image::distributed-tracing/query-request-tracing.png[]
 
+== Always-on Trace Id generation
+
+Solr includes an always-on trace id generator. This will inject trace id headers for every Solr request, propagating the client supplied value or generating a new id as needed and replaces the existing `rid` mechanism.
+
+The header name it uses for propagation is `X-Trace-Id`, this can be changed by updating the system property `solr.traceIdHeader`.
+
+This plugin will not be enabled if another Tracing mechanism is setup via Solr config.
+This plugin can be disabled by setting the `solr.alwaysOnTraceId` system property to `false`.
+
 == Modules and Configuration
 
 The `TracerConfigurator` is a class used to provide an instance of `io.opentracing.Tracer` based on configuration in `solr.xml`.
diff --git a/solr/solr-ref-guide/modules/upgrade-notes/pages/major-changes-in-solr-9.adoc b/solr/solr-ref-guide/modules/upgrade-notes/pages/major-changes-in-solr-9.adoc
index 002f6cd3e23..cfe1d8b9b7f 100644
--- a/solr/solr-ref-guide/modules/upgrade-notes/pages/major-changes-in-solr-9.adoc
+++ b/solr/solr-ref-guide/modules/upgrade-notes/pages/major-changes-in-solr-9.adoc
@@ -85,6 +85,11 @@ see the  xref:deployment-guide:securing-solr.adoc#network-configuration[Network
 This will enable client and server hostName check settings to be governed by the same environment variable.
 If users want separate client/server settings, they can manually override the `solr.jetty.ssl.sniHostCheck` option in `SOLR_OPTS`.
 
+=== Deprecations
+* The `rid` request id query parameter has been deprecated in favor of the always-on trace generation.
+To disable the `rid` generation set the system property `solr.disableRequestId` to `true`.
+To disable the always-on trace generation set the system property `solr.alwaysOnTraceId` to `false`.
+
 == Solr 9.3
 === Binary Releases
 * Solr now comes with two xref:deployment-guide:installing-solr.adoc#available-solr-packages[binary releases] and xref:deployment-guide:solr-in-docker.adoc#available-images[docker images], **full** and **slim**.
diff --git a/solr/solrj/src/java/org/apache/solr/common/params/CommonParams.java b/solr/solrj/src/java/org/apache/solr/common/params/CommonParams.java
index 740be2e128f..e6408744846 100644
--- a/solr/solrj/src/java/org/apache/solr/common/params/CommonParams.java
+++ b/solr/solrj/src/java/org/apache/solr/common/params/CommonParams.java
@@ -268,7 +268,9 @@ public interface CommonParams {
    * Request ID parameter added to all distributed queries (that do not opt out)
    *
    * @see #DISABLE_REQUEST_ID
+   * @deprecated this was replaced by the auto-generated trace ids
    */
+  @Deprecated(since = "9.4")
   String REQUEST_ID = "rid";
 
   /**
@@ -277,7 +279,9 @@ public interface CommonParams {
    * <p>Defaults to 'false' if not specified.
    *
    * @see #REQUEST_ID
+   * @deprecated this was replaced by the auto-generated trace ids
    */
+  @Deprecated(since = "9.4")
   String DISABLE_REQUEST_ID = "disableRequestId";
 
   /** Request Purpose parameter added to each internal shard request when using debug=track */