Search in sources :

Example 16 with Metric

use of com.codahale.metrics.Metric 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 17 with Metric

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

the class SolrCloudReportersTest method testExplicitConfiguration.

@Test
public void testExplicitConfiguration() throws Exception {
    String solrXml = IOUtils.toString(SolrCloudReportersTest.class.getResourceAsStream("/solr/solr-solrreporter.xml"), "UTF-8");
    configureCluster(2).withSolrXml(solrXml).configure();
    cluster.uploadConfigSet(Paths.get(TEST_PATH().toString(), "configsets", "minimal", "conf"), "test");
    System.out.println("ZK: " + cluster.getZkServer().getZkAddress());
    CollectionAdminRequest.createCollection("test_collection", "test", 2, 2).setMaxShardsPerNode(4).process(cluster.getSolrClient());
    waitForState("Expected test_collection with 2 shards and 2 replicas", "test_collection", clusterShape(2, 2));
    Thread.sleep(15000);
    cluster.getJettySolrRunners().forEach(jetty -> {
        CoreContainer cc = jetty.getCoreContainer();
        for (String name : cc.getLoadedCoreNames()) {
            SolrCore core = cc.getCore(name);
            try {
                String registryName = core.getCoreMetricManager().getRegistryName();
                String leaderRegistryName = core.getCoreMetricManager().getLeaderRegistryName();
                String coreName = core.getName();
                String collectionName = core.getCoreDescriptor().getCollectionName();
                String coreNodeName = core.getCoreDescriptor().getCloudDescriptor().getCoreNodeName();
                String replicaName = coreName.substring(coreName.indexOf("_replica_") + 1);
                String shardId = core.getCoreDescriptor().getCloudDescriptor().getShardId();
                assertEquals("solr.core." + collectionName + "." + shardId + "." + replicaName, registryName);
                assertEquals("solr.collection." + collectionName + "." + shardId + ".leader", leaderRegistryName);
            } finally {
                if (core != null) {
                    core.close();
                }
            }
        }
        SolrMetricManager metricManager = cc.getMetricManager();
        Map<String, SolrMetricReporter> reporters = metricManager.getReporters("solr.cluster");
        assertEquals(reporters.toString(), 1, reporters.size());
        SolrMetricReporter reporter = reporters.get("test");
        assertNotNull(reporter);
        assertTrue(reporter.toString(), reporter instanceof SolrClusterReporter);
        SolrClusterReporter sor = (SolrClusterReporter) reporter;
        assertEquals(5, sor.getPeriod());
        for (String registryName : metricManager.registryNames(".*\\.shard[0-9]\\.replica.*")) {
            reporters = metricManager.getReporters(registryName);
            assertEquals(reporters.toString(), 1 + jmxReporter, reporters.size());
            reporter = null;
            for (String name : reporters.keySet()) {
                if (name.startsWith("test")) {
                    reporter = reporters.get(name);
                }
            }
            assertNotNull(reporter);
            assertTrue(reporter.toString(), reporter instanceof SolrShardReporter);
            SolrShardReporter srr = (SolrShardReporter) reporter;
            assertEquals(5, srr.getPeriod());
        }
        for (String registryName : metricManager.registryNames(".*\\.leader")) {
            leaderRegistries++;
            reporters = metricManager.getReporters(registryName);
            assertEquals(reporters.toString(), 0, reporters.size());
            Map<String, Metric> metrics = metricManager.registry(registryName).getMetrics();
            String key = "QUERY./select.requests";
            assertTrue(key, metrics.containsKey(key));
            assertTrue(key, metrics.get(key) instanceof AggregateMetric);
            key = "UPDATE./update/json.requests";
            assertTrue(key, metrics.containsKey(key));
            assertTrue(key, metrics.get(key) instanceof AggregateMetric);
        }
        if (metricManager.registryNames().contains("solr.cluster")) {
            clusterRegistries++;
            Map<String, Metric> metrics = metricManager.registry("solr.cluster").getMetrics();
            String key = "jvm.memory.heap.init";
            assertTrue(key, metrics.containsKey(key));
            assertTrue(key, metrics.get(key) instanceof AggregateMetric);
            key = "leader.test_collection.shard1.UPDATE./update/json.requests.max";
            assertTrue(key, metrics.containsKey(key));
            assertTrue(key, metrics.get(key) instanceof AggregateMetric);
        }
    });
    assertEquals("leaderRegistries", 2, leaderRegistries);
    assertEquals("clusterRegistries", 1, clusterRegistries);
}
Also used : CoreContainer(org.apache.solr.core.CoreContainer) SolrCore(org.apache.solr.core.SolrCore) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager) AggregateMetric(org.apache.solr.metrics.AggregateMetric) Metric(com.codahale.metrics.Metric) AggregateMetric(org.apache.solr.metrics.AggregateMetric) SolrMetricReporter(org.apache.solr.metrics.SolrMetricReporter) Test(org.junit.Test)

Example 18 with Metric

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

the class SolrShardReporterTest method test.

@Test
public void test() throws Exception {
    waitForRecoveriesToFinish("control_collection", jettys.get(0).getCoreContainer().getZkController().getZkStateReader(), false);
    waitForRecoveriesToFinish("collection1", jettys.get(0).getCoreContainer().getZkController().getZkStateReader(), false);
    printLayout();
    // wait for at least two reports
    Thread.sleep(10000);
    ClusterState state = jettys.get(0).getCoreContainer().getZkController().getClusterState();
    for (JettySolrRunner jetty : jettys) {
        CoreContainer cc = jetty.getCoreContainer();
        SolrMetricManager metricManager = cc.getMetricManager();
        for (final String coreName : cc.getLoadedCoreNames()) {
            CoreDescriptor cd = cc.getCoreDescriptor(coreName);
            if (cd.getCloudDescriptor() == null) {
                // not a cloud collection
                continue;
            }
            CloudDescriptor cloudDesc = cd.getCloudDescriptor();
            DocCollection docCollection = state.getCollection(cloudDesc.getCollectionName());
            String replicaName = SolrCoreMetricManager.parseReplicaName(cloudDesc.getCollectionName(), coreName);
            if (replicaName == null) {
                replicaName = cloudDesc.getCoreNodeName();
            }
            String registryName = SolrCoreMetricManager.createRegistryName(true, cloudDesc.getCollectionName(), cloudDesc.getShardId(), replicaName, null);
            String leaderRegistryName = SolrCoreMetricManager.createLeaderRegistryName(true, cloudDesc.getCollectionName(), cloudDesc.getShardId());
            boolean leader = cloudDesc.isLeader();
            Slice slice = docCollection.getSlice(cloudDesc.getShardId());
            int numReplicas = slice.getReplicas().size();
            if (leader) {
                assertTrue(metricManager.registryNames() + " doesn't contain " + leaderRegistryName, metricManager.registryNames().contains(leaderRegistryName));
                Map<String, Metric> metrics = metricManager.registry(leaderRegistryName).getMetrics();
                metrics.forEach((k, v) -> {
                    assertTrue("Unexpected type of " + k + ": " + v.getClass().getName() + ", " + v, v instanceof AggregateMetric);
                    AggregateMetric am = (AggregateMetric) v;
                    if (!k.startsWith("REPLICATION.peerSync")) {
                        assertEquals(coreName + "::" + registryName + "::" + k + ": " + am.toString(), numReplicas, am.size());
                    }
                });
            } else {
                assertFalse(metricManager.registryNames() + " contains " + leaderRegistryName + " but it's not a leader!", metricManager.registryNames().contains(leaderRegistryName));
                Map<String, Metric> metrics = metricManager.registry(leaderRegistryName).getMetrics();
                metrics.forEach((k, v) -> {
                    assertTrue("Unexpected type of " + k + ": " + v.getClass().getName() + ", " + v, v instanceof AggregateMetric);
                    AggregateMetric am = (AggregateMetric) v;
                    if (!k.startsWith("REPLICATION.peerSync")) {
                        assertEquals(coreName + "::" + registryName + "::" + k + ": " + am.toString(), 1, am.size());
                    }
                });
            }
            assertTrue(metricManager.registryNames() + " doesn't contain " + registryName, metricManager.registryNames().contains(registryName));
        }
    }
    SolrMetricManager metricManager = controlJetty.getCoreContainer().getMetricManager();
    assertTrue(metricManager.registryNames().contains("solr.cluster"));
}
Also used : ClusterState(org.apache.solr.common.cloud.ClusterState) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) CoreDescriptor(org.apache.solr.core.CoreDescriptor) AggregateMetric(org.apache.solr.metrics.AggregateMetric) CloudDescriptor(org.apache.solr.cloud.CloudDescriptor) CoreContainer(org.apache.solr.core.CoreContainer) Slice(org.apache.solr.common.cloud.Slice) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager) AggregateMetric(org.apache.solr.metrics.AggregateMetric) Metric(com.codahale.metrics.Metric) DocCollection(org.apache.solr.common.cloud.DocCollection) Test(org.junit.Test)

Example 19 with Metric

use of com.codahale.metrics.Metric 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 20 with Metric

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

the class SolrMetricManagerTest method testSimpleMetrics.

@Test
public void testSimpleMetrics() throws Exception {
    Random r = random();
    SolrMetricManager metricManager = new SolrMetricManager();
    String registryName = TestUtil.randomSimpleString(r, 1, 10);
    metricManager.counter(null, registryName, "simple_counter", "foo", "bar");
    metricManager.timer(null, registryName, "simple_timer", "foo", "bar");
    metricManager.meter(null, registryName, "simple_meter", "foo", "bar");
    metricManager.histogram(null, registryName, "simple_histogram", "foo", "bar");
    Map<String, Metric> metrics = metricManager.registry(registryName).getMetrics();
    assertEquals(4, metrics.size());
    for (Map.Entry<String, Metric> entry : metrics.entrySet()) {
        assertTrue(entry.getKey().startsWith("foo.bar.simple_"));
    }
}
Also used : Random(java.util.Random) Metric(com.codahale.metrics.Metric) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

Metric (com.codahale.metrics.Metric)58 Test (org.junit.Test)27 MetricRegistry (com.codahale.metrics.MetricRegistry)16 Map (java.util.Map)16 HashMap (java.util.HashMap)13 Counter (com.codahale.metrics.Counter)10 Gauge (com.codahale.metrics.Gauge)10 Timer (com.codahale.metrics.Timer)10 MetricFilter (com.codahale.metrics.MetricFilter)8 MetricFilter (com.kixeye.chassis.support.metrics.MetricFilter)8 Meter (com.codahale.metrics.Meter)7 Histogram (com.codahale.metrics.Histogram)4 SolrMetricManager (org.apache.solr.metrics.SolrMetricManager)4 Timed (com.codahale.metrics.annotation.Timed)3 ApiOperation (io.swagger.annotations.ApiOperation)3 ApiResponses (io.swagger.annotations.ApiResponses)3 IOException (java.io.IOException)3 List (java.util.List)3 Random (java.util.Random)3 Collectors (java.util.stream.Collectors)3