epugh commented on code in PR #5238: URL: https://github.com/apache/solr/pull/5238#discussion_r4407789728
########## solr/core/src/test-files/solr/configsets/search-request-listener/conf/schema.xml: ########## Review Comment: Do you need a custom schema file? Can you use existing??? ########## solr/core/src/java/org/apache/solr/handler/component/SearchRequestInfo.java: ########## @@ -0,0 +1,85 @@ +/* + * 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.handler.component; + +import java.util.List; +import org.apache.solr.request.SolrQueryRequest; +import org.apache.solr.request.SolrRequestInfo; +import org.apache.solr.response.SolrQueryResponse; +import org.apache.solr.util.ThreadCpuTimer; + +/** + * A completed search request, as passed to {@link SearchRequestListener}. Listeners must not retain + * or modify {@code req}, {@code rsp} or {@code rb}; copy what they need. + * + * @param req the request + * @param rsp the response + * @param rb null if the handler failed before creating it or it belongs to another request + * @param handlerPath the path the request log uses + * @param elapsedMs time since the request started + * @param cpuTimeMs null unless {@code solr.log.cputime=true}; includes the CPU shards reported when + * distributed + * @param hits null if not available + * @param shardCount number of shards targeted; 0 for a non-distributed request + * @param failure the exception set on the response, if any + * @param partialResults whether the response header marks the results as partial, for example after + * a timeout + * @lucene.experimental + */ +public record SearchRequestInfo( + SolrQueryRequest req, + SolrQueryResponse rsp, + ResponseBuilder rb, + String handlerPath, + long elapsedMs, + Long cpuTimeMs, + Long hits, + int shardCount, + Throwable failure, + boolean partialResults) { + + static SearchRequestInfo from(SolrQueryRequest req, SolrQueryResponse rsp) { Review Comment: Like don't we want our architecture/approach cover both? ########## changelog/unreleased/SOLR-11994-search-request-listener.yml: ########## @@ -0,0 +1,8 @@ +title: Add a SearchRequestListener hook so modules can observe each completed search a client sends, on the node that coordinated it. Review Comment: Have you seen my UBI draft pr that also wants to see search query and its results? Could it hook in here? ########## solr/core/src/test/org/apache/solr/handler/component/SearchRequestListenerTest.java: ########## @@ -0,0 +1,402 @@ +/* + * 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.handler.component; + +import java.util.ArrayList; +import java.util.List; +import java.util.Queue; +import java.util.Set; +import java.util.concurrent.ConcurrentLinkedQueue; +import org.apache.solr.client.solrj.SolrClient; +import org.apache.solr.client.solrj.SolrRequest; +import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer; +import org.apache.solr.client.solrj.request.CollectionAdminRequest; +import org.apache.solr.client.solrj.request.QueryRequest; +import org.apache.solr.client.solrj.request.SolrPing; +import org.apache.solr.client.solrj.request.SolrQuery; +import org.apache.solr.client.solrj.request.UpdateRequest; +import org.apache.solr.client.solrj.request.V2Request; +import org.apache.solr.client.solrj.response.InputStreamResponseParser; +import org.apache.solr.client.solrj.response.QueryResponse; +import org.apache.solr.cloud.SolrCloudTestCase; +import org.apache.solr.common.SolrException; +import org.apache.solr.common.cloud.Replica; +import org.apache.solr.common.params.ModifiableSolrParams; +import org.apache.solr.common.util.NamedList; +import org.apache.solr.common.util.SimpleOrderedMap; +import org.apache.solr.core.SolrCore; +import org.apache.solr.embedded.JettySolrRunner; +import org.apache.solr.request.SolrQueryRequest; +import org.apache.solr.request.SolrQueryRequestBase; +import org.apache.solr.request.SolrRequestInfo; +import org.apache.solr.response.SolrQueryResponse; +import org.apache.solr.search.CallerSpecificQueryLimit; +import org.apache.solr.util.TestInjection; +import org.apache.solr.util.ThreadCpuTimer; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +public class SearchRequestListenerTest extends SolrCloudTestCase { + private static final String COLLECTION = "listener"; + private static final String DISPATCH_COLLECTION = "listener_dispatch"; + private static final int NUM_SHARDS = 2; + private static final Queue<Event> events = new ConcurrentLinkedQueue<>(); + + private static final List<SearchRequestListener> listeners = new ArrayList<>(); + + private record Event(String node, SearchRequestInfo info) {} + + @BeforeClass + public static void setupCluster() throws Exception { + configureCluster(2) + .addConfig("conf", configset("cloud-minimal")) + .addConfig("dispatch", configset("search-request-listener")) + .configure(); + createCollection(COLLECTION); + createCollection(DISPATCH_COLLECTION, "dispatch"); + } + + @Before + public void registerListeners() { + events.clear(); + addListeners(false); + } + + @After + public void removeListeners() { + for (JettySolrRunner jetty : cluster.getJettySolrRunners()) { + listeners.forEach(jetty.getCoreContainer()::removeSearchRequestListener); + } + listeners.clear(); + } + + private static void createCollection(String name) throws Exception { + createCollection(name, "conf"); + } + + private static void createCollection(String name, String config) throws Exception { + CollectionAdminRequest.createCollection(name, config, NUM_SHARDS, 1) + .processAndWait(cluster.getSolrClient(), DEFAULT_TIMEOUT); + cluster.waitForActiveCollection(name, NUM_SHARDS, NUM_SHARDS); + new UpdateRequest() + .add("id", "1") + .add("id", "2") + .add("id", "3") + .commit(cluster.getSolrClient(), name); + } + + private static void addListeners(boolean withThrowingListener) { + for (JettySolrRunner jetty : cluster.getJettySolrRunners()) { + String node = jetty.getNodeName(); + if (withThrowingListener) { + addListener( + jetty, + info -> { + throw new RuntimeException("listener failure"); + }); + } + addListener(jetty, info -> events.add(new Event(node, info))); + } + } + + private static void addListener(JettySolrRunner jetty, SearchRequestListener listener) { + listeners.add(listener); + jetty.getCoreContainer().addSearchRequestListener(listener); + } + + private static SolrClient nodeClient() { Review Comment: Do we not have a existing helper? ########## solr/core/src/test-files/solr/configsets/search-request-listener/conf/solrconfig.xml: ########## Review Comment: Do you need custom solrcongrig?!! ########## solr/core/src/java/org/apache/solr/handler/component/SearchRequestInfo.java: ########## @@ -0,0 +1,85 @@ +/* + * 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.handler.component; + +import java.util.List; +import org.apache.solr.request.SolrQueryRequest; +import org.apache.solr.request.SolrRequestInfo; +import org.apache.solr.response.SolrQueryResponse; +import org.apache.solr.util.ThreadCpuTimer; + +/** + * A completed search request, as passed to {@link SearchRequestListener}. Listeners must not retain + * or modify {@code req}, {@code rsp} or {@code rb}; copy what they need. + * + * @param req the request + * @param rsp the response + * @param rb null if the handler failed before creating it or it belongs to another request + * @param handlerPath the path the request log uses + * @param elapsedMs time since the request started + * @param cpuTimeMs null unless {@code solr.log.cputime=true}; includes the CPU shards reported when + * distributed + * @param hits null if not available + * @param shardCount number of shards targeted; 0 for a non-distributed request + * @param failure the exception set on the response, if any + * @param partialResults whether the response header marks the results as partial, for example after + * a timeout + * @lucene.experimental + */ +public record SearchRequestInfo( + SolrQueryRequest req, + SolrQueryResponse rsp, + ResponseBuilder rb, + String handlerPath, + long elapsedMs, + Long cpuTimeMs, + Long hits, + int shardCount, + Throwable failure, + boolean partialResults) { + + static SearchRequestInfo from(SolrQueryRequest req, SolrQueryResponse rsp) { Review Comment: How could a slow ingest be modeled? -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
