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/15 02:07:43 UTC
[solr] branch main updated: SOLR-16950 SimpleTracer propagation for manual transaction ids (#1906)
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 6d7b68af634 SOLR-16950 SimpleTracer propagation for manual transaction ids (#1906)
6d7b68af634 is described below
commit 6d7b68af6349e7e72754b7a64442e41c3736b084
Author: Alex D <st...@apache.org>
AuthorDate: Thu Sep 14 19:07:38 2023 -0700
SOLR-16950 SimpleTracer propagation for manual transaction ids (#1906)
---
solr/CHANGES.txt | 2 +
.../TestSimplePropagatorDistributedTracing.java | 141 +++++++++++++++------
.../org/apache/solr/client/solrj/SolrRequest.java | 10 ++
.../solr/client/solrj/request/UpdateRequest.java | 1 +
4 files changed, 117 insertions(+), 37 deletions(-)
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 4e46e13a900..67ddcdd211d 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -130,6 +130,8 @@ Improvements
* SOLR-16938: Auto configure tracer without a <tracerConfig> tag in solr.xml (Alex Deparvu)
+* SOLR-16950: SimpleTracer propagation for manual transaction ids
+
Optimizations
---------------------
diff --git a/solr/core/src/test/org/apache/solr/util/tracing/TestSimplePropagatorDistributedTracing.java b/solr/core/src/test/org/apache/solr/util/tracing/TestSimplePropagatorDistributedTracing.java
index 0213fce7b9a..86693edf12d 100644
--- a/solr/core/src/test/org/apache/solr/util/tracing/TestSimplePropagatorDistributedTracing.java
+++ b/solr/core/src/test/org/apache/solr/util/tracing/TestSimplePropagatorDistributedTracing.java
@@ -20,11 +20,17 @@ package org.apache.solr.util.tracing;
import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.trace.TracerProvider;
import java.io.IOException;
+import java.util.List;
+import java.util.Optional;
+import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.impl.CloudHttp2SolrClient;
+import org.apache.solr.client.solrj.impl.CloudLegacySolrClient;
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;
@@ -55,49 +61,95 @@ public class TestSimplePropagatorDistributedTracing extends SolrCloudTestCase {
}
@Test
- public void test() throws IOException, SolrServerException {
+ public void testQueryRequest() throws IOException, SolrServerException {
CloudSolrClient cloudClient = cluster.getSolrClient();
+ cloudClient.add(COLLECTION, sdoc("id", "1"));
+ cloudClient.add(COLLECTION, sdoc("id", "2"));
+ cloudClient.add(COLLECTION, sdoc("id", "3"));
- // 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);
+ try (LogListener reqLog = LogListener.info(SolrCore.class.getName() + ".Request")) {
+
+ try (SolrClient testClient = newCloudLegacySolrClient()) {
+ // verify all query events have the same auto-generated trace id
+ var r1 = testClient.query(COLLECTION, new SolrQuery("*:*"));
+ assertEquals(0, r1.getStatus());
+ assertSameTraceId(reqLog, null);
+
+ // verify all query events have the same 'custom' trace id
+ String traceId = "tidTestQueryRequest1";
+ var q = new QueryRequest(new SolrQuery("*:*"));
+ q.addHeader(SimplePropagator.TRACE_ID, traceId);
+ var r2 = q.process(testClient, COLLECTION);
+ assertEquals(0, r2.getStatus());
+ assertSameTraceId(reqLog, traceId);
}
- // TODO this doesn't work due to solr client creating the UpdateRequest without headers
- // // verify all events have the same 'custom' traceid
- // String traceId = "tidTestSimplePropagatorDistributedTracing0";
- // 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);
+ try (SolrClient testClient = newCloudHttp2SolrClient()) {
+ // verify all query events have the same auto-generated trace id
+ var r1 = testClient.query(COLLECTION, new SolrQuery("*:*"));
+ assertEquals(0, r1.getStatus());
+ assertSameTraceId(reqLog, null);
+
+ // verify all query events have the same 'custom' trace id
+ String traceId = "tidTestQueryRequest2";
+ var q = new QueryRequest(new SolrQuery("*:*"));
+ q.addHeader(SimplePropagator.TRACE_ID, traceId);
+ var r2 = q.process(testClient, COLLECTION);
+ assertEquals(0, r2.getStatus());
+ assertSameTraceId(reqLog, traceId);
+ }
}
+ }
- // Searching has trace ids
- try (LogListener reqLog = LogListener.info(SolrCore.class.getName() + ".Request")) {
- // verify all query events have the same auto-generated traceid
- var r1 = cloudClient.query(COLLECTION, new SolrQuery("*:*"));
- assertEquals(0, r1.getStatus());
- assertSameTraceId(reqLog, null);
-
- // verify all query events have the same 'custom' traceid
- String traceId = "tidTestSimplePropagatorDistributedTracing1";
- var q = new QueryRequest(new SolrQuery("*:*"));
- q.addHeader(SimplePropagator.TRACE_ID, traceId);
- var r2 = q.process(cloudClient, COLLECTION);
- assertEquals(0, r2.getStatus());
- assertSameTraceId(reqLog, traceId);
+ @Test
+ public void testUpdateRequest() throws IOException, SolrServerException {
+ try (LogListener reqLog = LogListener.info(LogUpdateProcessorFactory.class.getName())) {
+
+ try (SolrClient testClient = newCloudLegacySolrClient()) {
+ // verify all indexing events have trace id present
+ testClient.add(COLLECTION, sdoc("id", "1"));
+ testClient.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' trace id
+ String traceId = "tidTestUpdateRequest1";
+ UpdateRequest u = new UpdateRequest();
+ u.add(sdoc("id", "5"));
+ u.add(sdoc("id", "7"));
+ u.addHeader(SimplePropagator.TRACE_ID, traceId);
+ var r1 = u.process(testClient, COLLECTION);
+ assertEquals(0, r1.getStatus());
+ assertSameTraceId(reqLog, traceId);
+ }
+
+ try (SolrClient testClient = newCloudHttp2SolrClient()) {
+ // verify all indexing events have trace id present
+ testClient.add(COLLECTION, sdoc("id", "2"));
+ testClient.add(COLLECTION, sdoc("id", "4"));
+ 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' trace id
+ String traceId = "tidTestUpdateRequest2";
+ UpdateRequest u = new UpdateRequest();
+ u.add(sdoc("id", "6"));
+ u.add(sdoc("id", "8"));
+ u.addHeader(SimplePropagator.TRACE_ID, traceId);
+ var r1 = u.process(testClient, COLLECTION);
+ assertEquals(0, r1.getStatus());
+ assertSameTraceId(reqLog, traceId);
+ }
}
}
@@ -114,4 +166,19 @@ public class TestSimplePropagatorDistributedTracing extends SolrCloudTestCase {
assertEquals(traceId, evTraceId);
}
}
+
+ private CloudSolrClient newCloudLegacySolrClient() {
+ return new CloudLegacySolrClient.Builder(
+ List.of(cluster.getZkServer().getZkAddress()), Optional.empty())
+ .build();
+ }
+
+ private CloudHttp2SolrClient newCloudHttp2SolrClient() {
+ var builder =
+ new CloudHttp2SolrClient.Builder(
+ List.of(cluster.getZkServer().getZkAddress()), Optional.empty());
+ var client = builder.build();
+ client.connect();
+ return client;
+ }
}
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/SolrRequest.java b/solr/solrj/src/java/org/apache/solr/client/solrj/SolrRequest.java
index 269c74ff04e..f433b6c34d0 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/SolrRequest.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/SolrRequest.java
@@ -270,6 +270,16 @@ public abstract class SolrRequest<T extends SolrResponse> implements Serializabl
headers.put(key, value);
}
+ public void addHeaders(Map<String, String> headers) {
+ if (headers == null) {
+ return;
+ }
+ if (this.headers == null) {
+ this.headers = new HashMap<>();
+ }
+ this.headers.putAll(headers);
+ }
+
public Map<String, String> getHeaders() {
if (headers == null) return null;
return Collections.unmodifiableMap(headers);
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/request/UpdateRequest.java b/solr/solrj/src/java/org/apache/solr/client/solrj/request/UpdateRequest.java
index 3534558bba2..c04990accee 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/request/UpdateRequest.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/request/UpdateRequest.java
@@ -271,6 +271,7 @@ public class UpdateRequest extends AbstractUpdateRequest {
updateRequest.setPath(getPath());
updateRequest.setBasicAuthCredentials(getBasicAuthUser(), getBasicAuthPassword());
updateRequest.setResponseParser(getResponseParser());
+ updateRequest.addHeaders(getHeaders());
request = reqSupplier.get(updateRequest, urls);
routes.put(leaderUrl, request);
}