Search in sources :

Example 31 with MetricRegistry

use of com.codahale.metrics.MetricRegistry in project lucene-solr by apache.

the class PeerSyncReplicationTest method test.

@Test
public void test() throws Exception {
    handle.clear();
    handle.put("timestamp", SKIPVAL);
    waitForThingsToLevelOut(30);
    del("*:*");
    // index enough docs and commit to establish frame of reference for PeerSync
    for (int i = 0; i < 100; i++) {
        indexDoc(id, docId, i1, 50, tlong, 50, t1, "document number " + docId++);
    }
    commit();
    waitForThingsToLevelOut(30);
    try {
        checkShardConsistency(false, true);
        long cloudClientDocs = cloudClient.query(new SolrQuery("*:*")).getResults().getNumFound();
        assertEquals(docId, cloudClientDocs);
        CloudJettyRunner initialLeaderJetty = shardToLeaderJetty.get("shard1");
        List<CloudJettyRunner> otherJetties = getOtherAvailableJetties(initialLeaderJetty);
        CloudJettyRunner neverLeader = otherJetties.get(otherJetties.size() - 1);
        otherJetties.remove(neverLeader);
        // first shutdown a node that will never be a leader
        forceNodeFailures(singletonList(neverLeader));
        // node failure and recovery via PeerSync
        log.info("Forcing PeerSync");
        CloudJettyRunner nodePeerSynced = forceNodeFailureAndDoPeerSync(false);
        // add a few more docs
        indexDoc(id, docId, i1, 50, tlong, 50, t1, "document number " + docId++);
        indexDoc(id, docId, i1, 50, tlong, 50, t1, "document number " + docId++);
        commit();
        cloudClientDocs = cloudClient.query(new SolrQuery("*:*")).getResults().getNumFound();
        assertEquals(docId, cloudClientDocs);
        // now shutdown all other nodes except for 'nodeShutDownForFailure'
        otherJetties.remove(nodePeerSynced);
        forceNodeFailures(otherJetties);
        waitForThingsToLevelOut(30);
        checkShardConsistency(false, true);
        // now shutdown the original leader
        log.info("Now shutting down initial leader");
        forceNodeFailures(singletonList(initialLeaderJetty));
        log.info("Updating mappings from zk");
        waitForNewLeader(cloudClient, "shard1", (Replica) initialLeaderJetty.client.info, new TimeOut(15, SECONDS));
        updateMappingsFromZk(jettys, clients, true);
        assertEquals("PeerSynced node did not become leader", nodePeerSynced, shardToLeaderJetty.get("shard1"));
        // bring up node that was down all along, and let it PeerSync from the node that was forced to PeerSynce  
        bringUpDeadNodeAndEnsureNoReplication(neverLeader, false);
        waitTillNodesActive();
        checkShardConsistency(false, true);
        // bring back all the nodes including initial leader 
        // (commented as reports Maximum concurrent create/delete watches above limit violation and reports thread leaks)
        /*for(int i = 0 ; i < nodesDown.size(); i++) {
        bringUpDeadNodeAndEnsureNoReplication(shardToLeaderJetty.get("shard1"), neverLeader, false);
      }
      checkShardConsistency(false, true);*/
        // make sure leader has not changed after bringing initial leader back
        assertEquals(nodePeerSynced, shardToLeaderJetty.get("shard1"));
        // assert metrics
        MetricRegistry registry = nodePeerSynced.jetty.getCoreContainer().getMetricManager().registry("solr.core.collection1");
        Map<String, Metric> metrics = registry.getMetrics();
        assertTrue("REPLICATION.time present", metrics.containsKey("REPLICATION.time"));
        assertTrue("REPLICATION.errors present", metrics.containsKey("REPLICATION.errors"));
        Timer timer = (Timer) metrics.get("REPLICATION.time");
        assertEquals(1L, timer.getCount());
        Counter counter = (Counter) metrics.get("REPLICATION.errors");
        assertEquals(0L, counter.getCount());
        success = true;
    } finally {
        System.clearProperty("solr.disableFingerprint");
    }
}
Also used : Counter(com.codahale.metrics.Counter) Timer(com.codahale.metrics.Timer) TimeOut(org.apache.solr.util.TimeOut) MetricRegistry(com.codahale.metrics.MetricRegistry) Metric(com.codahale.metrics.Metric) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Test(org.junit.Test)

Example 32 with MetricRegistry

use of com.codahale.metrics.MetricRegistry in project lucene-solr by apache.

the class SolrIndexMetricsTest method testIndexMetricsWithDetails.

@Test
public void testIndexMetricsWithDetails() throws Exception {
    // test mergeDetails override too
    System.setProperty("solr.tests.metrics.merge", "false");
    System.setProperty("solr.tests.metrics.mergeDetails", "true");
    initCore("solrconfig-indexmetrics.xml", "schema.xml");
    addDocs();
    MetricRegistry registry = h.getCoreContainer().getMetricManager().registry(h.getCore().getCoreMetricManager().getRegistryName());
    assertNotNull(registry);
    Map<String, Metric> metrics = registry.getMetrics();
    assertTrue(metrics.entrySet().stream().filter(e -> e.getKey().startsWith("INDEX")).count() >= 12);
    // check basic index meters
    Timer timer = (Timer) metrics.get("INDEX.merge.minor");
    assertTrue("minorMerge: " + timer.getCount(), timer.getCount() >= 3);
    timer = (Timer) metrics.get("INDEX.merge.major");
    assertEquals("majorMerge: " + timer.getCount(), 0, timer.getCount());
    // check detailed meters
    Meter meter = (Meter) metrics.get("INDEX.merge.major.docs");
    assertEquals("majorMergeDocs: " + meter.getCount(), 0, meter.getCount());
    meter = (Meter) metrics.get("INDEX.flush");
    assertTrue("flush: " + meter.getCount(), meter.getCount() > 10);
}
Also used : Meter(com.codahale.metrics.Meter) MetricRegistry(com.codahale.metrics.MetricRegistry) Map(java.util.Map) After(org.junit.After) Metric(com.codahale.metrics.Metric) Timer(com.codahale.metrics.Timer) Test(org.junit.Test) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrTestCaseJ4(org.apache.solr.SolrTestCaseJ4) SolrInputDocument(org.apache.solr.common.SolrInputDocument) Timer(com.codahale.metrics.Timer) Meter(com.codahale.metrics.Meter) MetricRegistry(com.codahale.metrics.MetricRegistry) Metric(com.codahale.metrics.Metric) Test(org.junit.Test)

Example 33 with MetricRegistry

use of com.codahale.metrics.MetricRegistry in project lucene-solr by apache.

the class MetricUtilsTest method testMetrics.

@Test
public void testMetrics() throws Exception {
    MetricRegistry registry = new MetricRegistry();
    Counter counter = registry.counter("counter");
    counter.inc();
    Timer timer = registry.timer("timer");
    Timer.Context ctx = timer.time();
    Thread.sleep(150);
    ctx.stop();
    Meter meter = registry.meter("meter");
    meter.mark();
    Histogram histogram = registry.histogram("histogram");
    histogram.update(10);
    AggregateMetric am = new AggregateMetric();
    registry.register("aggregate", am);
    am.set("foo", 10);
    am.set("bar", 1);
    am.set("bar", 2);
    Gauge<String> gauge = () -> "foobar";
    registry.register("gauge", gauge);
    Gauge<Long> error = () -> {
        throw new InternalError("Memory Pool not found error");
    };
    registry.register("memory.expected.error", error);
    MetricUtils.toMaps(registry, Collections.singletonList(MetricFilter.ALL), MetricFilter.ALL, MetricUtils.PropertyFilter.ALL, false, false, false, false, (k, o) -> {
        Map v = (Map) o;
        if (k.startsWith("counter")) {
            assertEquals(1L, v.get("count"));
        } else if (k.startsWith("gauge")) {
            assertEquals("foobar", v.get("value"));
        } else if (k.startsWith("timer")) {
            assertEquals(1L, v.get("count"));
            assertTrue(((Number) v.get("min_ms")).intValue() > 100);
        } else if (k.startsWith("meter")) {
            assertEquals(1L, v.get("count"));
        } else if (k.startsWith("histogram")) {
            assertEquals(1L, v.get("count"));
        } else if (k.startsWith("aggregate")) {
            assertEquals(2, v.get("count"));
            Map<String, Object> values = (Map<String, Object>) v.get("values");
            assertNotNull(values);
            assertEquals(2, values.size());
            Map<String, Object> update = (Map<String, Object>) values.get("foo");
            assertEquals(10, update.get("value"));
            assertEquals(1, update.get("updateCount"));
            update = (Map<String, Object>) values.get("bar");
            assertEquals(2, update.get("value"));
            assertEquals(2, update.get("updateCount"));
        } else if (k.startsWith("memory.expected.error")) {
            assertNull(v);
        }
    });
    // test compact format
    MetricUtils.toMaps(registry, Collections.singletonList(MetricFilter.ALL), MetricFilter.ALL, MetricUtils.PropertyFilter.ALL, false, false, true, false, (k, o) -> {
        if (k.startsWith("counter")) {
            assertTrue(o instanceof Long);
            assertEquals(1L, o);
        } else if (k.startsWith("gauge")) {
            assertTrue(o instanceof String);
            assertEquals("foobar", o);
        } else if (k.startsWith("timer")) {
            assertTrue(o instanceof Map);
            Map v = (Map) o;
            assertEquals(1L, v.get("count"));
            assertTrue(((Number) v.get("min_ms")).intValue() > 100);
        } else if (k.startsWith("meter")) {
            assertTrue(o instanceof Map);
            Map v = (Map) o;
            assertEquals(1L, v.get("count"));
        } else if (k.startsWith("histogram")) {
            assertTrue(o instanceof Map);
            Map v = (Map) o;
            assertEquals(1L, v.get("count"));
        } else if (k.startsWith("aggregate")) {
            assertTrue(o instanceof Map);
            Map v = (Map) o;
            assertEquals(2, v.get("count"));
            Map<String, Object> values = (Map<String, Object>) v.get("values");
            assertNotNull(values);
            assertEquals(2, values.size());
            Map<String, Object> update = (Map<String, Object>) values.get("foo");
            assertEquals(10, update.get("value"));
            assertEquals(1, update.get("updateCount"));
            update = (Map<String, Object>) values.get("bar");
            assertEquals(2, update.get("value"));
            assertEquals(2, update.get("updateCount"));
        } else if (k.startsWith("memory.expected.error")) {
            assertNull(o);
        } else {
            Map v = (Map) o;
            assertEquals(1L, v.get("count"));
        }
    });
}
Also used : Histogram(com.codahale.metrics.Histogram) Meter(com.codahale.metrics.Meter) MetricRegistry(com.codahale.metrics.MetricRegistry) AggregateMetric(org.apache.solr.metrics.AggregateMetric) Counter(com.codahale.metrics.Counter) Timer(com.codahale.metrics.Timer) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 34 with MetricRegistry

use of com.codahale.metrics.MetricRegistry in project lucene-solr by apache.

the class SolrCoreMetricManagerTest method assertRegistered.

private void assertRegistered(String scope, Map<String, Counter> newMetrics, SolrCoreMetricManager coreMetricManager) {
    if (scope == null || newMetrics == null) {
        return;
    }
    String filter = "." + scope + ".";
    MetricRegistry registry = metricManager.registry(coreMetricManager.getRegistryName());
    assertEquals(newMetrics.size(), registry.getMetrics().keySet().stream().filter(s -> s.contains(filter)).count());
    Map<String, Metric> registeredMetrics = registry.getMetrics().entrySet().stream().filter(e -> e.getKey() != null && e.getKey().contains(filter)).collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue()));
    for (Map.Entry<String, Metric> entry : registeredMetrics.entrySet()) {
        String name = entry.getKey();
        Metric expectedMetric = entry.getValue();
        Metric actualMetric = registry.getMetrics().get(name);
        assertNotNull(actualMetric);
        assertEquals(expectedMetric, actualMetric);
    }
}
Also used : CoreAdminParams(org.apache.solr.common.params.CoreAdminParams) MetricRegistry(com.codahale.metrics.MetricRegistry) FieldType(org.apache.solr.schema.FieldType) TestUtil(org.apache.lucene.util.TestUtil) Metric(com.codahale.metrics.Metric) MockMetricReporter(org.apache.solr.metrics.reporters.MockMetricReporter) IOException(java.io.IOException) HashMap(java.util.HashMap) Random(java.util.Random) Test(org.junit.Test) Collectors(java.util.stream.Collectors) SolrTestCaseJ4(org.apache.solr.SolrTestCaseJ4) SolrInfoBean(org.apache.solr.core.SolrInfoBean) Map(java.util.Map) After(org.junit.After) Counter(com.codahale.metrics.Counter) PluginInfo(org.apache.solr.core.PluginInfo) Before(org.junit.Before) MetricRegistry(com.codahale.metrics.MetricRegistry) Metric(com.codahale.metrics.Metric) HashMap(java.util.HashMap) Map(java.util.Map)

Example 35 with MetricRegistry

use of com.codahale.metrics.MetricRegistry in project lucene-solr by apache.

the class SolrMetricManagerTest method testRegisterAll.

@Test
public void testRegisterAll() throws Exception {
    Random r = random();
    SolrMetricManager metricManager = new SolrMetricManager();
    Map<String, Counter> metrics = SolrMetricTestUtils.getRandomMetrics(r, true);
    MetricRegistry mr = new MetricRegistry();
    for (Map.Entry<String, Counter> entry : metrics.entrySet()) {
        mr.register(entry.getKey(), entry.getValue());
    }
    String registryName = TestUtil.randomSimpleString(r, 1, 10);
    assertEquals(0, metricManager.registry(registryName).getMetrics().size());
    metricManager.registerAll(registryName, mr, false);
    // this should simply skip existing names
    metricManager.registerAll(registryName, mr, true);
    // this should produce error
    try {
        metricManager.registerAll(registryName, mr, false);
        fail("registerAll with duplicate metric names should fail");
    } catch (IllegalArgumentException e) {
    // expected
    }
}
Also used : Counter(com.codahale.metrics.Counter) Random(java.util.Random) MetricRegistry(com.codahale.metrics.MetricRegistry) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

MetricRegistry (com.codahale.metrics.MetricRegistry)505 Test (org.junit.Test)177 Before (org.junit.Before)61 Test (org.junit.jupiter.api.Test)45 VerifiableProperties (com.github.ambry.config.VerifiableProperties)42 ArrayList (java.util.ArrayList)33 Counter (com.codahale.metrics.Counter)30 File (java.io.File)29 Properties (java.util.Properties)28 List (java.util.List)23 Metric (com.codahale.metrics.Metric)22 Map (java.util.Map)22 IOException (java.io.IOException)21 HashMap (java.util.HashMap)20 Size (com.github.joschi.jadconfig.util.Size)17 CountDownLatch (java.util.concurrent.CountDownLatch)17 TimeUnit (java.util.concurrent.TimeUnit)17 Timer (com.codahale.metrics.Timer)15 DefaultTaggedMetricRegistry (com.palantir.tritium.metrics.registry.DefaultTaggedMetricRegistry)15 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)15