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");
}
}
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);
}
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"));
}
});
}
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);
}
}
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
}
}
Aggregations