Search in sources :

Example 16 with MetricsMap

use of org.apache.solr.metrics.MetricsMap in project lucene-solr by apache.

the class ExitableDirectoryReaderTest method testQueryResults.

// When looking at a problem raised on the user's list I ran across this anomaly with timeAllowed
// This tests for the second query NOT returning partial results, along with some other
@Test
public void testQueryResults() throws Exception {
    String q = "name:e*";
    SolrCore core = h.getCore();
    MetricsMap queryCacheStats = (MetricsMap) core.getCoreMetricManager().getRegistry().getMetrics().get("CACHE.searcher.queryResultCache");
    Map<String, Object> nl = queryCacheStats.getValue();
    long inserts = (long) nl.get("inserts");
    String response = JQ(req("q", q, "indent", "true", "timeAllowed", "1", "sleep", sleep));
    // The queryResultCache should NOT get an entry here.
    nl = queryCacheStats.getValue();
    assertEquals("Should NOT have inserted partial results!", inserts, (long) nl.get("inserts"));
    Map res = (Map) ObjectBuilder.fromJSON(response);
    Map body = (Map) (res.get("response"));
    Map header = (Map) (res.get("responseHeader"));
    assertTrue("Should have fewer docs than " + NUM_DOCS, (long) (body.get("numFound")) < NUM_DOCS);
    assertTrue("Should have partial results", (Boolean) (header.get(SolrQueryResponse.RESPONSE_HEADER_PARTIAL_RESULTS_KEY)));
    response = JQ(req("q", q, "indent", "true", "timeAllowed", longTimeout));
    // Check that we did insert this one.
    Map<String, Object> nl2 = queryCacheStats.getValue();
    assertEquals("Hits should still be 0", (long) nl.get("hits"), (long) nl2.get("hits"));
    assertTrue("Inserts should be bumped", inserts < (long) nl2.get("inserts"));
    res = (Map) ObjectBuilder.fromJSON(response);
    body = (Map) (res.get("response"));
    header = (Map) (res.get("responseHeader"));
    assertEquals("Should have exactly " + NUM_DOCS, NUM_DOCS, (long) (body.get("numFound")));
    Boolean test = (Boolean) (header.get(SolrQueryResponse.RESPONSE_HEADER_PARTIAL_RESULTS_KEY));
    if (test != null) {
        assertFalse("Should NOT have partial results", test);
    }
}
Also used : MetricsMap(org.apache.solr.metrics.MetricsMap) Map(java.util.Map) MetricsMap(org.apache.solr.metrics.MetricsMap) Test(org.junit.Test)

Example 17 with MetricsMap

use of org.apache.solr.metrics.MetricsMap in project lucene-solr by apache.

the class MockInfoBean method initializeMetrics.

@Override
public void initializeMetrics(SolrMetricManager manager, String registryName, String scope) {
    registry = manager.registry(registryName);
    MetricsMap metricsMap = new MetricsMap((detailed, map) -> {
        map.put("Integer", 123);
        map.put("Double", 567.534);
        map.put("Long", 32352463l);
        map.put("Short", (short) 32768);
        map.put("Byte", (byte) 254);
        map.put("Float", 3.456f);
        map.put("String", "testing");
        map.put("Object", new Object());
    });
    manager.registerGauge(this, registryName, metricsMap, true, getClass().getSimpleName(), getCategory().toString(), scope);
}
Also used : MetricsMap(org.apache.solr.metrics.MetricsMap)

Example 18 with MetricsMap

use of org.apache.solr.metrics.MetricsMap in project lucene-solr by apache.

the class TestSolrFieldCacheBean method assertEntryListIncluded.

private void assertEntryListIncluded(boolean checkJmx) {
    SolrFieldCacheBean mbean = new SolrFieldCacheBean();
    Random r = random();
    String registryName = TestUtil.randomSimpleString(r, 1, 10);
    SolrMetricManager metricManager = h.getCoreContainer().getMetricManager();
    mbean.initializeMetrics(metricManager, registryName, null);
    MetricsMap metricsMap = (MetricsMap) metricManager.registry(registryName).getMetrics().get("CACHE.fieldCache");
    Map<String, Object> metrics = checkJmx ? metricsMap.getValue(true) : metricsMap.getValue();
    assertTrue(((Number) metrics.get("entries_count")).longValue() > 0);
    assertNotNull(metrics.get("total_size"));
    assertNotNull(metrics.get("entry#0"));
}
Also used : MetricsMap(org.apache.solr.metrics.MetricsMap) Random(java.util.Random) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager)

Example 19 with MetricsMap

use of org.apache.solr.metrics.MetricsMap in project lucene-solr by apache.

the class TestSolrQueryParser method testFilter.

@Test
public void testFilter() throws Exception {
    // normal test "solrconfig.xml" has autowarm set to 2...
    for (int i = 0; i < 10; i++) {
        assertJQ(req("q", "*:* " + i, "fq", "filter(just_to_clear_the_cache) filter(id:10000" + i + ") filter(id:10001" + i + ")"), "/response/numFound==0");
    }
    assertU(adoc("id", "777"));
    delI("777");
    // arg... commit no longer "commits" unless there has been a change.
    assertU(commit());
    final MetricsMap filterCacheStats = (MetricsMap) h.getCore().getCoreMetricManager().getRegistry().getMetrics().get("CACHE.searcher.filterCache");
    assertNotNull(filterCacheStats);
    final MetricsMap queryCacheStats = (MetricsMap) h.getCore().getCoreMetricManager().getRegistry().getMetrics().get("CACHE.searcher.queryResultCache");
    assertNotNull(queryCacheStats);
    long inserts = (Long) filterCacheStats.getValue().get("inserts");
    long hits = (Long) filterCacheStats.getValue().get("hits");
    assertJQ(req("q", "doesnotexist filter(id:1) filter(qqq_s:X) filter(abcdefg)"), "/response/numFound==2");
    inserts += 3;
    assertEquals(inserts, ((Long) filterCacheStats.getValue().get("inserts")).longValue());
    assertEquals(hits, ((Long) filterCacheStats.getValue().get("hits")).longValue());
    assertJQ(req("q", "doesnotexist2 filter(id:1) filter(qqq_s:X) filter(abcdefg)"), "/response/numFound==2");
    hits += 3;
    assertEquals(inserts, ((Long) filterCacheStats.getValue().get("inserts")).longValue());
    assertEquals(hits, ((Long) filterCacheStats.getValue().get("hits")).longValue());
    // make sure normal "fq" parameters also hit the cache the same way
    assertJQ(req("q", "doesnotexist3", "fq", "id:1", "fq", "qqq_s:X", "fq", "abcdefg"), "/response/numFound==0");
    hits += 3;
    assertEquals(inserts, ((Long) filterCacheStats.getValue().get("inserts")).longValue());
    assertEquals(hits, ((Long) filterCacheStats.getValue().get("hits")).longValue());
    // try a query deeply nested in a FQ
    assertJQ(req("q", "*:* doesnotexist4", "fq", "(id:* +(filter(id:1) filter(qqq_s:X) filter(abcdefg)) )"), "/response/numFound==2");
    // +1 for top level fq
    inserts += 1;
    hits += 3;
    assertEquals(inserts, ((Long) filterCacheStats.getValue().get("inserts")).longValue());
    assertEquals(hits, ((Long) filterCacheStats.getValue().get("hits")).longValue());
    // retry the complex FQ and make sure hashCode/equals works as expected w/ filter queries
    assertJQ(req("q", "*:* doesnotexist5", "fq", "(id:* +(filter(id:1) filter(qqq_s:X) filter(abcdefg)) )"), "/response/numFound==2");
    // top-level fq should have been found.
    hits += 1;
    assertEquals(inserts, ((Long) filterCacheStats.getValue().get("inserts")).longValue());
    assertEquals(hits, ((Long) filterCacheStats.getValue().get("hits")).longValue());
    // try nested filter with multiple top-level args (i.e. a boolean query)
    assertJQ(req("q", "*:* +filter(id:1 filter(qqq_s:X) abcdefg)"), "/response/numFound==2");
    // the inner filter
    hits += 1;
    // the outer filter
    inserts += 1;
    assertEquals(inserts, ((Long) filterCacheStats.getValue().get("inserts")).longValue());
    assertEquals(hits, ((Long) filterCacheStats.getValue().get("hits")).longValue());
    // test the score for a filter, and that default score is 0
    assertJQ(req("q", "+filter(*:*) +filter(id:1)", "fl", "id,score", "sort", "id asc"), "/response/docs/[0]/score==0.0");
    assertJQ(req("q", "+filter(*:*)^=10 +filter(id:1)", "fl", "id,score", "sort", "id asc"), "/response/docs/[0]/score==10.0");
}
Also used : MetricsMap(org.apache.solr.metrics.MetricsMap) Test(org.junit.Test)

Example 20 with MetricsMap

use of org.apache.solr.metrics.MetricsMap in project lucene-solr by apache.

the class TestFastLRUCache method testSimple.

public void testSimple() throws IOException {
    FastLRUCache sc = new FastLRUCache();
    sc.initializeMetrics(metricManager, registry, scope);
    Map l = new HashMap();
    l.put("size", "100");
    l.put("initialSize", "10");
    l.put("autowarmCount", "25");
    CacheRegenerator cr = new NoOpRegenerator();
    Object o = sc.init(l, null, cr);
    sc.setState(SolrCache.State.LIVE);
    for (int i = 0; i < 101; i++) {
        sc.put(i + 1, "" + (i + 1));
    }
    assertEquals("25", sc.get(25));
    assertEquals(null, sc.get(110));
    MetricsMap metrics = sc.getMetricsMap();
    Map<String, Object> nl = metrics.getValue();
    assertEquals(2L, nl.get("lookups"));
    assertEquals(1L, nl.get("hits"));
    assertEquals(101L, nl.get("inserts"));
    // first item put in should be the first out
    assertEquals(null, sc.get(1));
    FastLRUCache scNew = new FastLRUCache();
    scNew.initializeMetrics(metricManager, registry, scope);
    scNew.init(l, o, cr);
    scNew.warm(null, sc);
    scNew.setState(SolrCache.State.LIVE);
    sc.close();
    scNew.put(103, "103");
    assertEquals("90", scNew.get(90));
    assertEquals(null, scNew.get(50));
    nl = scNew.getMetricsMap().getValue();
    assertEquals(2L, nl.get("lookups"));
    assertEquals(1L, nl.get("hits"));
    assertEquals(1L, nl.get("inserts"));
    assertEquals(0L, nl.get("evictions"));
    assertEquals(5L, nl.get("cumulative_lookups"));
    assertEquals(2L, nl.get("cumulative_hits"));
    assertEquals(102L, nl.get("cumulative_inserts"));
    scNew.close();
}
Also used : MetricsMap(org.apache.solr.metrics.MetricsMap) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap) MetricsMap(org.apache.solr.metrics.MetricsMap)

Aggregations

MetricsMap (org.apache.solr.metrics.MetricsMap)26 SolrMetricManager (org.apache.solr.metrics.SolrMetricManager)10 Map (java.util.Map)8 Test (org.junit.Test)7 MetricRegistry (com.codahale.metrics.MetricRegistry)5 MethodHandles (java.lang.invoke.MethodHandles)5 HashSet (java.util.HashSet)5 Set (java.util.Set)5 SolrException (org.apache.solr.common.SolrException)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 HashMap (java.util.HashMap)4 Random (java.util.Random)4 List (java.util.List)3 TimeUnit (java.util.concurrent.TimeUnit)3 IOException (java.io.IOException)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)2 Gauge (com.codahale.metrics.Gauge)1 JmxReporter (com.codahale.metrics.JmxReporter)1