Apache Solr open-source search software
SOLR-16960 Tests should sometimes run with a Tracer (not no-op) (#1948)
Alex D1d0d75a079ff
diff --git a/solr/core/src/java/org/apache/solr/util/tracing/TraceUtils.java b/solr/core/src/java/org/apache/solr/util/tracing/TraceUtils.javaindex 80fc524556b..7e9daa37bbc 100644--- a/solr/core/src/java/org/apache/solr/util/tracing/TraceUtils.java+++ b/solr/core/src/java/org/apache/solr/util/tracing/TraceUtils.java@@ -65,11 +65,13 @@ public class TraceUtils {public static final String TAG_DB_TYPE_SOLR = "solr";+ public static final Predicate<Span> DEFAULT_IS_RECORDING = Span::isRecording;+/*** this should only be changed in the context of testing, otherwise it would risk not recording* trace data.*/- public static Predicate<Span> IS_RECORDING = Span::isRecording;+ public static Predicate<Span> IS_RECORDING = DEFAULT_IS_RECORDING;public static Tracer getGlobalTracer() {return GlobalOpenTelemetry.getTracer("solr");diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java b/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.javaindex 5d7a9e610ec..eb2eb4ef152 100644--- a/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java+++ b/solr/test-framework/src/java/org/apache/solr/cloud/MiniSolrCloudCluster.java@@ -685,6 +685,7 @@ public class MiniSolrCloudCluster {if (!externalZkServer) {zkServer.shutdown();}+ resetRecordingFlag();}}@@ -1301,23 +1302,27 @@ public class MiniSolrCloudCluster {this.disableTraceIdGeneration = true;return this;}+ }- /**- * Randomizes the tracing Span::isRecording check.- *- * <p>This will randomize the Span::isRecording check so we have better coverage of all methods- * that deal with span creation without having to enable otel module.- *- * <p>It only makes sense to call this if we are using the alwaysOn tracer, the OTEL tracer- * already has this flag turned on and randomizing it would risk not recording trace data.- *- * <p>Note. Tracing is not a SolrCloud only feature. this method is placed here for convenience- * only, any test can make use of this example for more complete coverage of the tracing- * mechanics.- */- private void injectRandomRecordingFlag() {- boolean isRecording = LuceneTestCase.rarely();- TraceUtils.IS_RECORDING = (ignored) -> isRecording;- }+ /**+ * Randomizes the tracing Span::isRecording check.+ *+ * <p>This will randomize the Span::isRecording check so we have better coverage of all methods+ * that deal with span creation without having to enable otel module.+ *+ * <p>It only makes sense to call this if we are using the alwaysOn tracer, the OTEL tracer+ * already has this flag turned on and randomizing it would risk not recording trace data.+ *+ * <p>Note. Tracing is not a SolrCloud only feature. this method is placed here for convenience+ * only, any test can make use of this example for more complete coverage of the tracing+ * mechanics.+ */+ private static void injectRandomRecordingFlag() {+ boolean isRecording = LuceneTestCase.rarely();+ TraceUtils.IS_RECORDING = (ignored) -> isRecording;+ }++ private static void resetRecordingFlag() {+ TraceUtils.IS_RECORDING = TraceUtils.DEFAULT_IS_RECORDING;}}