mirror of https://github.com/apache/lucene.git
SOLR-267: Logging updates, now logs how many hits, plus some other logging changes to reduce double logging
git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@649066 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e2583ca6dd
commit
f0a4b30cdc
|
@ -355,7 +355,10 @@ Bug Fixes
|
|||
when no RequestHandler is mapped to "/update") now logs error correctly.
|
||||
(hossman)
|
||||
|
||||
26. SOLR-509: Moved firstSearcher event notification to the end of the SolrCore constructor (Koji Sekiguchi via gsingers)
|
||||
27. SOLR-267: Changed logging to report number of hits, and also provide a mechanism to add log messages to be output by the SolrCore via a NamedList toLog
|
||||
member variable. (Will Johnson, yseeley, gsingers)
|
||||
|
||||
28. SOLR-509: Moved firstSearcher event notification to the end of the SolrCore constructor (Koji Sekiguchi via gsingers)
|
||||
|
||||
Other Changes
|
||||
1. SOLR-135: Moved common classes to org.apache.solr.common and altered the
|
||||
|
|
|
@ -128,7 +128,7 @@ public final class SolrCore {
|
|||
|
||||
/**
|
||||
* Gets the configuration resource name used by this core instance.
|
||||
* @see getConfigResource
|
||||
* @see #getConfigResource()
|
||||
*/
|
||||
@Deprecated
|
||||
public String getConfigFile() {
|
||||
|
@ -151,7 +151,7 @@ public final class SolrCore {
|
|||
|
||||
/**
|
||||
* Gets the schema resource name used by this core instance.
|
||||
* @see getSchemaResource
|
||||
* @see #getSchemaResource()
|
||||
*/
|
||||
@Deprecated
|
||||
public String getSchemaFile() {
|
||||
|
@ -498,7 +498,7 @@ public final class SolrCore {
|
|||
* Returns a Request object based on the admin/pingQuery section
|
||||
* of the Solr config file.
|
||||
*
|
||||
* @use {@link PingRequestHandler} instead
|
||||
* @use {@link org.apache.solr.handler.PingRequestHandler} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public SolrQueryRequest getPingQueryRequest() {
|
||||
|
@ -948,12 +948,23 @@ public final class SolrCore {
|
|||
// setup response header and handle request
|
||||
final NamedList<Object> responseHeader = new SimpleOrderedMap<Object>();
|
||||
rsp.add("responseHeader", responseHeader);
|
||||
NamedList toLog = rsp.getToLog();
|
||||
//toLog.add("core", getName());
|
||||
toLog.add("webapp", req.getContext().get("webapp"));
|
||||
toLog.add("path", req.getContext().get("path"));
|
||||
toLog.add("params", "{" + req.getParamString() + "}");
|
||||
handler.handleRequest(req,rsp);
|
||||
setResponseHeaderValues(handler,responseHeader,req,rsp);
|
||||
|
||||
log.info(logid+"" + req.getContext().get("path") + " "
|
||||
setResponseHeaderValues(handler,req,rsp);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i=0; i<toLog.size(); i++) {
|
||||
String name = toLog.getName(i);
|
||||
Object val = toLog.getVal(i);
|
||||
sb.append(name).append("=").append(val).append(" ");
|
||||
}
|
||||
log.info(logid + sb.toString());
|
||||
/*log.info(logid+"" + req.getContext().get("path") + " "
|
||||
+ req.getParamString()+ " 0 "+
|
||||
(int)(rsp.getEndTime() - req.getStartTime()));
|
||||
(int)(rsp.getEndTime() - req.getStartTime()));*/
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
|
@ -966,12 +977,14 @@ public final class SolrCore {
|
|||
execute(handler, req, rsp);
|
||||
}
|
||||
|
||||
protected void setResponseHeaderValues(SolrRequestHandler handler, NamedList<Object> responseHeader,SolrQueryRequest req, SolrQueryResponse rsp) {
|
||||
protected void setResponseHeaderValues(SolrRequestHandler handler, SolrQueryRequest req, SolrQueryResponse rsp) {
|
||||
// TODO should check that responseHeader has not been replaced by handler
|
||||
|
||||
NamedList responseHeader = rsp.getResponseHeader();
|
||||
final int qtime=(int)(rsp.getEndTime() - req.getStartTime());
|
||||
responseHeader.add("status",rsp.getException()==null ? 0 : 500);
|
||||
responseHeader.add("QTime",qtime);
|
||||
rsp.getToLog().add("status",rsp.getException()==null ? 0 : 500);
|
||||
rsp.getToLog().add("QTime",qtime);
|
||||
|
||||
SolrParams params = req.getParams();
|
||||
if( params.getBool(CommonParams.HEADER_ECHO_HANDLER, false) ) {
|
||||
|
|
|
@ -165,7 +165,7 @@ public class QueryComponent extends SearchComponent
|
|||
}
|
||||
|
||||
rsp.add("response",rb.getResults().docList);
|
||||
|
||||
rsp.getToLog().add("hits", rb.getResults().docList.size());
|
||||
|
||||
boolean fsv = req.getParams().getBool(ResponseBuilder.FIELD_SORT_VALUES,false);
|
||||
if(fsv){
|
||||
|
|
|
@ -62,6 +62,11 @@ public class SolrQueryResponse {
|
|||
*/
|
||||
protected NamedList values = new SimpleOrderedMap();
|
||||
|
||||
/**
|
||||
* Container for storing information that should be logged by Solr before returning.
|
||||
*/
|
||||
protected NamedList toLog = new SimpleOrderedMap();
|
||||
|
||||
protected Set<String> defaultReturnFields;
|
||||
|
||||
// error if this is set...
|
||||
|
@ -73,6 +78,11 @@ public class SolrQueryResponse {
|
|||
String errMsg;
|
||||
***/
|
||||
|
||||
public SolrQueryResponse() {
|
||||
add("responseHeader", new SimpleOrderedMap<Object>());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets data to be returned in this response
|
||||
* @see <a href="#returnable_data">Note on Returnable Data</a>
|
||||
|
@ -168,5 +178,27 @@ public class SolrQueryResponse {
|
|||
return this.endtime;
|
||||
}
|
||||
|
||||
/** Repsonse header to be logged */
|
||||
public NamedList getResponseHeader() {
|
||||
SimpleOrderedMap<Object> header = (SimpleOrderedMap<Object>) values.get("responseHeader");
|
||||
return header;
|
||||
}
|
||||
|
||||
/** Add a value to be logged.
|
||||
*
|
||||
* @param name name of the thing to log
|
||||
* @param val value of the thing to log
|
||||
*/
|
||||
public void addToLog(String name, Object val) {
|
||||
toLog.add(name, val);
|
||||
}
|
||||
|
||||
/** Get loggable items.
|
||||
*
|
||||
* @return things to log
|
||||
*/
|
||||
public NamedList getToLog() {
|
||||
return toLog;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -42,12 +42,12 @@ public class JSONWriterTest extends AbstractSolrTestCase {
|
|||
rsp.add("data2", Double.NEGATIVE_INFINITY);
|
||||
rsp.add("data3", Float.POSITIVE_INFINITY);
|
||||
w.write(buf, req, rsp);
|
||||
assertEquals(buf.toString(), "{'data1':float('NaN'),'data2':-float('Inf'),'data3':float('Inf')}");
|
||||
assertEquals(buf.toString(), "{'responseHeader':{},'data1':float('NaN'),'data2':-float('Inf'),'data3':float('Inf')}");
|
||||
|
||||
w = new RubyResponseWriter();
|
||||
buf = new StringWriter();
|
||||
w.write(buf, req, rsp);
|
||||
assertEquals(buf.toString(), "{'data1'=>(0.0/0.0),'data2'=>-(1.0/0.0),'data3'=>(1.0/0.0)}");
|
||||
assertEquals(buf.toString(), "{'responseHeader'=>{},'data1'=>(0.0/0.0),'data2'=>-(1.0/0.0),'data3'=>(1.0/0.0)}");
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ import javax.servlet.http.HttpServletRequest;
|
|||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.solr.common.SolrException;
|
||||
import org.apache.solr.common.util.NamedList;
|
||||
import org.apache.solr.common.params.CommonParams;
|
||||
import org.apache.solr.core.MultiCore;
|
||||
import org.apache.solr.core.SolrConfig;
|
||||
|
@ -271,6 +272,15 @@ public class SolrDispatchFilter implements Filter
|
|||
* Content-Type)
|
||||
*/
|
||||
this.execute( req, handler, solrReq, solrRsp );
|
||||
// add info to http headers
|
||||
try {
|
||||
NamedList solrRspHeader = solrRsp.getResponseHeader();
|
||||
for (int i=0; i<solrRspHeader.size(); i++) {
|
||||
((javax.servlet.http.HttpServletResponse) response).addHeader(("Solr-" + solrRspHeader.getName(i)), String.valueOf(solrRspHeader.getVal(i)));
|
||||
}
|
||||
} catch (ClassCastException cce) {
|
||||
log.log(Level.WARNING, "exception adding response header log information", cce);
|
||||
}
|
||||
if( solrRsp.getException() != null ) {
|
||||
sendError( (HttpServletResponse)response, solrRsp.getException() );
|
||||
}
|
||||
|
@ -323,6 +333,8 @@ public class SolrDispatchFilter implements Filter
|
|||
protected void execute( HttpServletRequest req, SolrRequestHandler handler, SolrQueryRequest sreq, SolrQueryResponse rsp) {
|
||||
// a custom filter could add more stuff to the request before passing it on.
|
||||
// for example: sreq.getContext().put( "HttpServletRequest", req );
|
||||
// used for logging query stats in SolrCore.execute()
|
||||
sreq.getContext().put( "webapp", req.getContextPath() );
|
||||
sreq.getCore().execute( handler, sreq, rsp );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue