stillalex commented on code in PR #1854:
URL: https://github.com/apache/solr/pull/1854#discussion_r1299447062


##########
solr/core/src/test/org/apache/solr/util/tracing/TestSimplePropagatorDistributedTracing.java:
##########
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.util.tracing;
+
+import io.opentelemetry.api.GlobalOpenTelemetry;
+import io.opentelemetry.api.trace.TracerProvider;
+import java.io.IOException;
+import org.apache.solr.client.solrj.SolrQuery;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
+import org.apache.solr.client.solrj.request.CollectionAdminRequest;
+import org.apache.solr.client.solrj.request.QueryRequest;
+import org.apache.solr.client.solrj.request.UpdateRequest;
+import org.apache.solr.cloud.SolrCloudTestCase;
+import org.apache.solr.common.util.SuppressForbidden;
+import org.apache.solr.core.SolrCore;
+import org.apache.solr.logging.MDCLoggingContext;
+import org.apache.solr.update.processor.LogUpdateProcessorFactory;
+import org.apache.solr.util.LogListener;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+@SuppressForbidden(reason = "We need to use log4J2 classes directly to test 
MDC impacts")
+public class TestSimplePropagatorDistributedTracing extends SolrCloudTestCase {
+
+  private static final String COLLECTION = "collection1";
+
+  @BeforeClass
+  public static void setupCluster() throws Exception {
+    if (System.getProperty("host") == null) {
+      System.setProperty("host", "localhost");
+    }
+
+    // enable simple propagator
+    System.setProperty("solr.otel.simplePropagatorOnly", "true");
+
+    configureCluster(4).addConfig("conf", 
configset("cloud-minimal")).configure();
+
+    // tracer should be disabled
+    assertEquals(
+        "Expecting noop otel (propagating only)",
+        TracerProvider.noop(),
+        GlobalOpenTelemetry.get().getTracerProvider());
+
+    CollectionAdminRequest.createCollection(COLLECTION, "conf", 2, 2)
+        .process(cluster.getSolrClient());
+    cluster.waitForActiveCollection(COLLECTION, 2, 4);
+  }
+
+  @AfterClass
+  public static void afterClass() {
+    System.clearProperty("solr.otel.simplePropagatorOnly");
+  }
+
+  @Test
+  public void test() throws IOException, SolrServerException {
+    CloudSolrClient cloudClient = cluster.getSolrClient();
+
+    // Indexing has trace ids
+    try (LogListener reqLog = 
LogListener.info(LogUpdateProcessorFactory.class.getName())) {
+      // verify all indexing events have trace id present
+      cloudClient.add(COLLECTION, sdoc("id", "1"));
+      cloudClient.add(COLLECTION, sdoc("id", "2"));
+      cloudClient.add(COLLECTION, sdoc("id", "3"));
+      var queue = reqLog.getQueue();
+      assertFalse(queue.isEmpty());
+      while (!queue.isEmpty()) {
+        var reqEvent = queue.poll();
+        String evTraceId = 
reqEvent.getContextData().getValue(MDCLoggingContext.TRACE_ID);
+        assertNotNull(evTraceId);
+      }
+
+      // verify all events have the same 'custom' traceid
+      String traceId = "tidTestSimplePropagatorDistributedTracing";
+      var doc = sdoc("id", "4");
+      UpdateRequest u = new UpdateRequest();
+      u.add(doc);
+      u.addHeader(SimplePropagator.TRACE_ID, traceId);
+      var r1 = u.process(cloudClient, COLLECTION);
+      assertEquals(0, r1.getStatus());
+      assertSameTraceId(reqLog, traceId);

Review Comment:
   this only works if `UpdateRequest` enables header propagation, see change 
below.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org
For additional commands, e-mail: issues-h...@solr.apache.org

Reply via email to