Revision 56601
Added by Katerina Iatropoulou over 4 years ago
SolrResultSet.java | ||
---|---|---|
8 | 8 |
import eu.dnetlib.data.search.utils.solr.SolrResultsFormatter; |
9 | 9 |
import eu.dnetlib.domain.EPR; |
10 | 10 |
import gr.uoa.di.driver.enabling.resultset.ResultSet; |
11 |
import io.micrometer.core.instrument.Timer; |
|
12 |
import io.micrometer.prometheus.PrometheusMeterRegistry; |
|
11 | 13 |
import org.apache.commons.lang.StringEscapeUtils; |
12 | 14 |
import org.apache.log4j.Logger; |
13 | 15 |
import org.apache.solr.client.solrj.SolrClient; |
... | ... | |
28 | 30 |
/** |
29 | 31 |
* Created by antleb on 2/4/14. |
30 | 32 |
*/ |
33 |
|
|
31 | 34 |
public class SolrResultSet implements ResultSet<String> { |
32 | 35 |
|
33 | 36 |
private Logger logger = Logger.getLogger(getClass()); |
... | ... | |
38 | 41 |
private NamedList<String> queryOpts = new NamedList<String>(); |
39 | 42 |
long size = -1; |
40 | 43 |
|
44 |
private PrometheusMeterRegistry registry; |
|
41 | 45 |
|
42 |
public SolrResultSet(EPR epr, CloudSolrClient cloudSolrClient) throws IOException, CQLParseException { |
|
46 |
public SolrResultSet(EPR epr, CloudSolrClient cloudSolrClient, PrometheusMeterRegistry registry) throws IOException, CQLParseException {
|
|
43 | 47 |
logger.debug("Setting solr client " + cloudSolrClient); |
44 | 48 |
this.epr = epr; |
45 | 49 |
this.solrClient = cloudSolrClient; |
... | ... | |
50 | 54 |
String interpretation = epr.getParameter("interpretation"); |
51 | 55 |
|
52 | 56 |
((CloudSolrClient)solrClient).setDefaultCollection(mdformat + "-" + layout + "-" + interpretation); |
57 |
|
|
58 |
this.registry = registry; |
|
53 | 59 |
} |
54 | 60 |
|
55 | 61 |
@Override |
... | ... | |
105 | 111 |
queryOpts.add("rows", to + 1+""); |
106 | 112 |
|
107 | 113 |
try { |
114 |
|
|
108 | 115 |
rsp = solrClient.query(SolrParams.toSolrParams(queryOpts)); |
116 |
|
|
109 | 117 |
facetFields = rsp.getFacetFields(); |
110 | 118 |
SolrDocumentList docs = rsp.getResults(); |
111 | 119 |
|
... | ... | |
170 | 178 |
queryOpts.add("start", from*to + ""); |
171 | 179 |
queryOpts.add("rows", to +""); |
172 | 180 |
|
181 |
long startTime = System.nanoTime(); |
|
182 |
|
|
173 | 183 |
try { |
174 |
long startTime = System.nanoTime(); |
|
184 |
io.micrometer.core.instrument.Timer.Sample timer = Timer.start(registry); |
|
185 |
rsp = solrClient.query(SolrParams.toSolrParams(queryOpts)); |
|
186 |
timer.stop(registry.timer("solr.server.response.duration")); |
|
175 | 187 |
|
176 |
rsp = solrClient.query(SolrParams.toSolrParams(queryOpts)); |
|
188 |
|
|
177 | 189 |
long estimatedTime = System.nanoTime() - startTime; |
178 | 190 |
logger.info("Solrj time " + estimatedTime/1000000 + " milliseconds for query:" + queryOpts.get("q") + |
179 | 191 |
" and facets " + queryOpts.getAll("facet.field") + " and fq " + queryOpts.getAll("fq") + " from: " |
... | ... | |
262 | 274 |
Map<String,List<String>> response = new HashMap<String, List<String>>(); |
263 | 275 |
|
264 | 276 |
//logger.debug("refine results " + refineSolrResults); |
265 |
//logger.debug("search results " + searchSolrResults); |
|
277 |
//logger.info("search results SIZE " + searchSolrResults.size()); |
|
278 |
//logger.info("search results " + searchSolrResults); |
|
266 | 279 |
|
280 |
|
|
267 | 281 |
response.put("refine",refineSolrResults); |
268 | 282 |
response.put("search", searchSolrResults); |
269 | 283 |
|
... | ... | |
274 | 288 |
|
275 | 289 |
} catch (IOException ioe) { |
276 | 290 |
logger.error("Error calling Solr.", ioe); |
291 |
|
|
277 | 292 |
} |
293 |
|
|
278 | 294 |
return null; |
279 | 295 |
} |
280 | 296 |
|
Also available in: Unified diff
Adding metrics with micrometer