Skip to content

Commit 11840af

Browse files
authored
SOLR-17934: Remove Request ID based tracing (#3709)
1 parent 890444d commit 11840af

File tree

9 files changed

+18
-228
lines changed

9 files changed

+18
-228
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# See https://github.com/apache/solr/blob/main/dev-docs/changelog.adoc
2+
title: Remove Request ID based tracing.
3+
type: removed
4+
authors:
5+
- name: Eric Pugh
6+
links:
7+
- name: SOLR-17934
8+
url: https://issues.apache.org/jira/browse/SOLR-17934
9+
issues:
10+
- 17934

solr/core/src/java/org/apache/solr/handler/component/DebugComponent.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public class DebugComponent extends SearchComponent {
7373
public void prepare(ResponseBuilder rb) throws IOException {
7474
if (rb.isDebugTrack() && rb.isDistrib) {
7575
rb.setNeedDocList(true);
76-
doDebugTrack(rb);
76+
rb.addDebug(new SimpleOrderedMap<>(), "track");
7777
}
7878
}
7979

@@ -140,11 +140,6 @@ public void process(ResponseBuilder rb) throws IOException {
140140
}
141141
}
142142

143-
private void doDebugTrack(ResponseBuilder rb) {
144-
final String rid = rb.req.getParams().get(CommonParams.REQUEST_ID);
145-
rb.addDebug(rid, "track", CommonParams.REQUEST_ID); // to see it in the response
146-
}
147-
148143
@Override
149144
public void modifyRequest(ResponseBuilder rb, SearchComponent who, ShardRequest sreq) {
150145
if (!rb.isDebug()) return;
@@ -176,7 +171,6 @@ public void modifyRequest(ResponseBuilder rb, SearchComponent who, ShardRequest
176171
}
177172
if (rb.isDebugTrack()) {
178173
sreq.params.add(CommonParams.DEBUG, CommonParams.TRACK);
179-
sreq.params.set(CommonParams.REQUEST_ID, rb.req.getParams().get(CommonParams.REQUEST_ID));
180174
sreq.params.set(
181175
CommonParams.REQUEST_PURPOSE, SolrPluginUtils.getRequestPurpose(sreq.purpose));
182176
}

solr/core/src/java/org/apache/solr/handler/component/ResponseBuilder.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,9 @@ public void setDebugResults(boolean debugResults) {
344344
}
345345

346346
public NamedList<Object> getDebugInfo() {
347+
if (debugInfo == null) {
348+
debugInfo = new SimpleOrderedMap<>();
349+
}
347350
return debugInfo;
348351
}
349352

solr/core/src/java/org/apache/solr/handler/component/SearchHandler.java

Lines changed: 1 addition & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import java.util.Objects;
4242
import java.util.Optional;
4343
import java.util.Set;
44-
import java.util.concurrent.atomic.AtomicLong;
4544
import java.util.concurrent.atomic.AtomicReference;
4645
import java.util.stream.Collectors;
4746
import org.apache.lucene.index.ExitableDirectoryReader;
@@ -57,13 +56,11 @@
5756
import org.apache.solr.common.params.ShardParams;
5857
import org.apache.solr.common.util.NamedList;
5958
import org.apache.solr.common.util.SimpleOrderedMap;
60-
import org.apache.solr.common.util.StrUtils;
6159
import org.apache.solr.core.CloseHook;
6260
import org.apache.solr.core.CoreContainer;
6361
import org.apache.solr.core.PluginInfo;
6462
import org.apache.solr.core.SolrCore;
6563
import org.apache.solr.handler.RequestHandlerBase;
66-
import org.apache.solr.logging.MDCLoggingContext;
6764
import org.apache.solr.metrics.SolrMetricsContext;
6865
import org.apache.solr.pkg.PackageAPI;
6966
import org.apache.solr.pkg.PackageListeners;
@@ -86,7 +83,6 @@
8683
import org.apache.solr.util.plugin.SolrCoreAware;
8784
import org.slf4j.Logger;
8885
import org.slf4j.LoggerFactory;
89-
import org.slf4j.MDC;
9086

9187
/** Refer SOLR-281 */
9288
public class SearchHandler extends RequestHandlerBase
@@ -99,27 +95,6 @@ public class SearchHandler extends RequestHandlerBase
9995

10096
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
10197

102-
/**
103-
* A counter to ensure that no RID is equal, even if they fall in the same millisecond
104-
*
105-
* @deprecated this was replaced by the auto-generated trace ids
106-
*/
107-
@Deprecated(since = "9.4")
108-
private static final AtomicLong ridCounter = new AtomicLong();
109-
110-
/**
111-
* An opt-out flag to prevent the addition of {@link CommonParams#REQUEST_ID} tracing on
112-
* distributed queries
113-
*
114-
* <p>Defaults to 'false' if not specified.
115-
*
116-
* @see CommonParams#DISABLE_REQUEST_ID
117-
* @deprecated this was replaced by the auto-generated trace ids
118-
*/
119-
@Deprecated(since = "9.4")
120-
private static final boolean DISABLE_REQUEST_ID_DEFAULT =
121-
Boolean.getBoolean("solr.disableRequestId");
122-
12398
private HandlerMetrics metricsShard = HandlerMetrics.NO_OP;
12499

125100
protected volatile List<SearchComponent> components;
@@ -250,8 +225,7 @@ public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throw
250225
}
251226

252227
rb.isDistrib = isDistrib(req, rb); // can change later nonetheless
253-
tagRequestWithRequestId(rb);
254-
228+
255229
boolean dbg = req.getParams().getBool(CommonParams.DEBUG_QUERY, false);
256230
rb.setDebug(dbg);
257231
if (dbg == false) { // if it's true, we are doing everything anyway.
@@ -868,62 +842,6 @@ private static void throwSolrException(Throwable shardResponseException) throws
868842
}
869843
}
870844

871-
private void tagRequestWithRequestId(ResponseBuilder rb) {
872-
final boolean ridTaggingDisabled =
873-
rb.req.getParams().getBool(CommonParams.DISABLE_REQUEST_ID, DISABLE_REQUEST_ID_DEFAULT);
874-
if (!ridTaggingDisabled) {
875-
String rid = getOrGenerateRequestId(rb.req);
876-
877-
// NOTE: SearchHandler explicitly never clears/removes this MDC value...
878-
// We want it to live for the entire request, beyond the scope of SearchHandler's processing,
879-
// and trust SolrDispatchFilter to clean it up at the end of the request.
880-
//
881-
// Examples:
882-
// - ERROR logging of Exceptions propogated up to our base class
883-
// - SolrCore.RequestLog
884-
// - ERRORs that may be logged during response writing
885-
MDC.put(CommonParams.REQUEST_ID, rid);
886-
887-
if (StrUtils.isBlank(rb.req.getParams().get(CommonParams.REQUEST_ID))) {
888-
ModifiableSolrParams params = new ModifiableSolrParams(rb.req.getParams());
889-
params.add(CommonParams.REQUEST_ID, rid); // add rid to the request so that shards see it
890-
rb.req.setParams(params);
891-
}
892-
if (rb.isDistrib) {
893-
rb.rsp.addToLog(CommonParams.REQUEST_ID, rid); // to see it in the logs of the landing core
894-
}
895-
}
896-
}
897-
898-
/**
899-
* Returns a String to use as an identifier for this request.
900-
*
901-
* <p>If the provided {@link SolrQueryRequest} contains a non-blank {@link
902-
* CommonParams#REQUEST_ID} param value this is used. This is especially useful for users who
903-
* deploy Solr as one component in a larger ecosystem, and want to use an external ID utilized by
904-
* other components as well. If no {@link CommonParams#REQUEST_ID} value is present, one is
905-
* generated from scratch for the request.
906-
*
907-
* <p>Callers are responsible for storing the returned value in the {@link SolrQueryRequest}
908-
* object if they want to ensure that ID generation is not redone on subsequent calls.
909-
*/
910-
public static String getOrGenerateRequestId(SolrQueryRequest req) {
911-
String rid = req.getParams().get(CommonParams.REQUEST_ID);
912-
if (StrUtils.isNotBlank(rid)) {
913-
return rid;
914-
}
915-
String traceId = MDCLoggingContext.getTraceId();
916-
if (StrUtils.isNotBlank(traceId)) {
917-
return traceId;
918-
}
919-
return generateRid(req);
920-
}
921-
922-
private static String generateRid(SolrQueryRequest req) {
923-
String hostName = req.getCoreContainer().getHostName();
924-
return hostName + "-" + ridCounter.getAndIncrement();
925-
}
926-
927845
//////////////////////// SolrInfoMBeans methods //////////////////////
928846

929847
@Override

solr/core/src/test/org/apache/solr/handler/TestRequestId.java

Lines changed: 0 additions & 91 deletions
This file was deleted.

solr/core/src/test/org/apache/solr/handler/component/DebugComponentTest.java

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.apache.solr.SolrTestCaseJ4;
2424
import org.apache.solr.common.params.CommonParams;
2525
import org.apache.solr.common.params.ModifiableSolrParams;
26-
import org.apache.solr.common.util.NamedList;
2726
import org.apache.solr.request.SolrQueryRequest;
2827
import org.apache.solr.response.SolrQueryResponse;
2928
import org.junit.BeforeClass;
@@ -32,8 +31,6 @@
3231
/** */
3332
public class DebugComponentTest extends SolrTestCaseJ4 {
3433

35-
private static final String ANY_RID = "ANY_RID";
36-
3734
@BeforeClass
3835
public static void beforeClass() throws Exception {
3936
initCore("solrconfig.xml", "schema.xml");
@@ -166,8 +163,7 @@ public void testModifyRequestTrack() {
166163
List<SearchComponent> components = new ArrayList<>(1);
167164
components.add(component);
168165
for (int i = 0; i < 10; i++) {
169-
SolrQueryRequest req =
170-
req("q", "test query", "distrib", "true", CommonParams.REQUEST_ID, "123456-my_rid");
166+
SolrQueryRequest req = req("q", "test query", "distrib", "true");
171167
SolrQueryResponse resp = new SolrQueryResponse();
172168
ResponseBuilder rb = new ResponseBuilder(req, resp, components);
173169
ShardRequest sreq = new ShardRequest();
@@ -192,8 +188,6 @@ public void testModifyRequestTrack() {
192188
// the purpose must be added as readable param to be included in the shard logs
193189
assertEquals(
194190
"GET_FIELDS,GET_DEBUG,SET_TERM_STATS", sreq.params.get(CommonParams.REQUEST_PURPOSE));
195-
// the rid must be added to be included in the shard logs
196-
assertEquals("123456-my_rid", sreq.params.get(CommonParams.REQUEST_ID));
197191
// close requests - this method obtains a searcher in order to access its StatsCache
198192
req.close();
199193
}
@@ -210,7 +204,6 @@ public void testPrepare() throws IOException {
210204
req = req("q", "test query", "distrib", "true");
211205
rb = new ResponseBuilder(req, new SolrQueryResponse(), components);
212206
rb.isDistrib = true;
213-
addRequestId(rb, ANY_RID);
214207

215208
// expecting the same results with debugQuery=true or debug=track
216209
if (random().nextBoolean()) {
@@ -224,15 +217,13 @@ public void testPrepare() throws IOException {
224217
rb.setDebugResults(random().nextBoolean());
225218
}
226219
component.prepare(rb);
227-
ensureTrackRecordsRid(rb, ANY_RID);
228220
}
229221

230-
req = req("q", "test query", "distrib", "true", CommonParams.REQUEST_ID, "123");
222+
req = req("q", "test query", "distrib", "true");
231223
rb = new ResponseBuilder(req, new SolrQueryResponse(), components);
232224
rb.isDistrib = true;
233225
rb.setDebug(true);
234226
component.prepare(rb);
235-
ensureTrackRecordsRid(rb, "123");
236227
}
237228

238229
//
@@ -285,21 +276,8 @@ public void testQueryToString() {
285276
"//str[@name='parsedquery'][contains(.,'3.0')]");
286277
}
287278

288-
@SuppressWarnings("unchecked")
289-
private void ensureTrackRecordsRid(ResponseBuilder rb, String expectedRid) {
290-
final String rid =
291-
(String) ((NamedList<Object>) rb.getDebugInfo().get("track")).get(CommonParams.REQUEST_ID);
292-
assertEquals("Expecting " + expectedRid + " but found " + rid, expectedRid, rid);
293-
}
294-
295-
private void addRequestId(ResponseBuilder rb, String requestId) {
296-
ModifiableSolrParams params = new ModifiableSolrParams(rb.req.getParams());
297-
params.add(CommonParams.REQUEST_ID, requestId);
298-
rb.req.setParams(params);
299-
}
300-
301279
@Test
302-
public void testDistributedStageResolution() throws IOException {
280+
public void testDistributedStageResolution() {
303281
final DebugComponent debugComponent = new DebugComponent();
304282
assertEquals(
305283
"PARSE_QUERY", debugComponent.getDistributedStageName(ResponseBuilder.STAGE_PARSE_QUERY));

solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ public void testSimpleSearch() throws Exception {
121121
QueryResponse response = collection1.query(query);
122122
NamedList<Object> track = (NamedList<Object>) response.getDebugMap().get("track");
123123
assertNotNull(track);
124-
assertNotNull(track.get("rid"));
125124
assertNotNull(track.get("EXECUTE_QUERY"));
126125
assertNotNull(((NamedList<Object>) track.get("EXECUTE_QUERY")).get(shard1));
127126
assertNotNull(((NamedList<Object>) track.get("EXECUTE_QUERY")).get(shard2));

solr/solrj/src/java/org/apache/solr/common/params/CommonParams.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -277,26 +277,6 @@ public static EchoParamStyle get(String v) {
277277
*/
278278
String COST = "cost";
279279

280-
/**
281-
* Request ID parameter added to all distributed queries (that do not opt out)
282-
*
283-
* @see #DISABLE_REQUEST_ID
284-
* @deprecated this was replaced by the auto-generated trace ids
285-
*/
286-
@Deprecated(since = "9.4")
287-
String REQUEST_ID = "rid";
288-
289-
/**
290-
* An opt-out flag to prevent the addition of {@link #REQUEST_ID} tracing on distributed queries
291-
*
292-
* <p>Defaults to 'false' if not specified.
293-
*
294-
* @see #REQUEST_ID
295-
* @deprecated this was replaced by the auto-generated trace ids
296-
*/
297-
@Deprecated(since = "9.4")
298-
String DISABLE_REQUEST_ID = "disableRequestId";
299-
300280
/**
301281
* Parameter to control the distributed term statistics request for current query when distributed
302282
* IDF is enabled in solrconfig

solr/solrj/src/resources/EnvToSyspropMappings.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
AWS_PROFILE=aws.profile
88
SOLR_ALWAYS_ON_TRACE_ID=solr.alwaysOnTraceId
99
SOLR_AUTH_JWT_ALLOW_OUTBOUND_HTTP=solr.auth.jwt.allowOutboundHttp
10-
SOLR_DISABLE_REQUEST_ID=solr.disableRequestId
1110
SOLR_HIDDEN_SYS_PROPS=solr.hiddenSysProps
1211
SOLR_HOME=solr.solr.home
1312
SOLR_HOST_ADVERTISE=host

0 commit comments

Comments
 (0)