use of org.apache.ignite.spi.metric.LongMetric in project ignite by apache.
the class AbstractCdcTest method checkMetrics.
/**
*/
protected void checkMetrics(CdcMain cdc, int expCnt) throws Exception {
if (metricExporters() != null) {
IgniteConfiguration cfg = getFieldValue(cdc, "igniteCfg");
DynamicMBean jmxCdcReg = metricRegistry(cdcInstanceName(cfg.getIgniteInstanceName()), null, "cdc");
Function<String, ?> jmxVal = m -> {
try {
return jmxCdcReg.getAttribute(m);
} catch (Exception e) {
throw new IgniteException(e);
}
};
checkMetrics(expCnt, (Function<String, Long>) jmxVal, (Function<String, String>) jmxVal);
}
MetricRegistry mreg = getFieldValue(cdc, "mreg");
assertNotNull(mreg);
checkMetrics(expCnt, m -> mreg.<LongMetric>findMetric(m).value(), m -> mreg.<ObjectMetric<String>>findMetric(m).value());
}
use of org.apache.ignite.spi.metric.LongMetric in project ignite by apache.
the class TransactionMetricsTest method testTxMetric.
/**
*/
@Test
public void testTxMetric() throws Exception {
// given:
int keysNumber = 10;
IgniteEx ignite = startGrid(0);
startGrid(1);
IgniteEx client = startClientGrid(getConfiguration(getTestIgniteInstanceName(2)));
awaitPartitionMapExchange();
TransactionMetricsMxBean txMXBean = getMxBean(getTestIgniteInstanceName(0), "TransactionMetrics", TransactionMetricsMxBeanImpl.class, TransactionMetricsMxBean.class);
MetricRegistry mreg = grid(0).context().metric().registry(TX_METRICS);
final IgniteCache<Integer, String> cache = ignite.cache(DEFAULT_CACHE_NAME);
// when: one transaction commit
ignite.transactions().txStart().commit();
// then:
assertEquals(1, txMXBean.getTransactionsCommittedNumber());
assertEquals(1, mreg.<IntMetric>findMetric("txCommits").value());
// when: transaction is opening
final Transaction tx1 = ignite.transactions().txStart(PESSIMISTIC, REPEATABLE_READ);
int localKeysNum = 0;
for (int i = 0; i < keysNumber; i++) {
cache.put(i, "");
if (affinity(cache).isPrimary(ignite.localNode(), i))
localKeysNum++;
}
// then:
assertEquals(localKeysNum, mreg.<LongMetric>findMetric("LockedKeysNumber").value());
assertEquals(1, mreg.<LongMetric>findMetric("TransactionsHoldingLockNumber").value());
assertEquals(1, mreg.<LongMetric>findMetric("OwnerTransactionsNumber").value());
// when: transaction rollback
tx1.rollback();
// then:
assertEquals(1, txMXBean.getTransactionsRolledBackNumber());
assertEquals(1, mreg.<IntMetric>findMetric("txRollbacks").value());
assertEquals(0, mreg.<LongMetric>findMetric("LockedKeysNumber").value());
assertEquals(0, mreg.<LongMetric>findMetric("TransactionsHoldingLockNumber").value());
assertEquals(0, mreg.<LongMetric>findMetric("OwnerTransactionsNumber").value());
// when: keysNumber transactions from owner node + keysNumber transactions from client.
CountDownLatch commitAllower = new CountDownLatch(1);
CountDownLatch transactionStarter = new CountDownLatch(keysNumber + keysNumber);
int txNumFromOwner = 0;
for (int i = 0; i < keysNumber; i++) {
new Thread(new TxThread(commitAllower, transactionStarter, ignite, i, i)).start();
if (affinity(cache).isPrimary(ignite.localNode(), i))
txNumFromOwner++;
}
int txNumFromClient = 0;
for (int i = keysNumber; i < keysNumber * 2; i++) {
new Thread(new TxThread(commitAllower, transactionStarter, client, i, i)).start();
if (affinity(cache).isPrimary(ignite.localNode(), i))
txNumFromClient++;
}
transactionStarter.await();
// then:
assertEquals(txNumFromOwner + txNumFromClient, mreg.<LongMetric>findMetric("LockedKeysNumber").value());
assertEquals(keysNumber + txNumFromClient, mreg.<LongMetric>findMetric("TransactionsHoldingLockNumber").value());
assertEquals(keysNumber, mreg.<LongMetric>findMetric("OwnerTransactionsNumber").value());
commitAllower.countDown();
}
use of org.apache.ignite.spi.metric.LongMetric in project ignite by apache.
the class QueryParserMetricsHolderSelfTest method testParserCacheHits.
/**
* Ensure that query cache hits statistic is properly collected
*/
@Test
public void testParserCacheHits() {
LongMetric hits = (LongMetric) ignite.context().metric().registry(QUERY_PARSER_METRIC_GROUP_NAME).findMetric("hits");
Assert.assertNotNull("Unable to find metric with name " + QUERY_PARSER_METRIC_GROUP_NAME + ".hits", hits);
hits.reset();
cache.query(new SqlFieldsQuery("CREATE TABLE tbl_hits (id LONG PRIMARY KEY, val LONG)"));
Assert.assertEquals(0, hits.value());
for (int i = 0; i < 10; i++) cache.query(new SqlFieldsQuery("INSERT INTO tbl_hits (id, val) values (?, ?)").setArgs(i, i));
Assert.assertEquals(9, hits.value());
cache.query(new SqlFieldsQuery("SELECT * FROM tbl_hits"));
Assert.assertEquals(9, hits.value());
cache.query(new SqlFieldsQuery("SELECT * FROM tbl_hits"));
Assert.assertEquals(10, hits.value());
}
use of org.apache.ignite.spi.metric.LongMetric in project ignite by apache.
the class ClusterMetricsSelfTest method checkPmeMetricsOnNodeJoin.
/**
* @param client Client flag.
* @throws Exception If failed.
*/
private void checkPmeMetricsOnNodeJoin(boolean client) throws Exception {
IgniteEx ignite = startGrid(0);
MetricRegistry reg = ignite.context().metric().registry(PME_METRICS);
LongMetric currentPMEDuration = reg.findMetric(PME_DURATION);
LongMetric currentBlockingPMEDuration = reg.findMetric(PME_OPS_BLOCKED_DURATION);
HistogramMetricImpl durationHistogram = reg.findMetric(PME_DURATION_HISTOGRAM);
HistogramMetricImpl blockindDurationHistogram = reg.findMetric(PME_OPS_BLOCKED_DURATION_HISTOGRAM);
IgniteCache<Object, Object> cache = ignite.getOrCreateCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME).setAtomicityMode(TRANSACTIONAL));
cache.put(1, 1);
awaitPartitionMapExchange();
int timeout = 5000;
assertTrue(GridTestUtils.waitForCondition(() -> currentPMEDuration.value() == 0, timeout));
assertEquals(0, currentBlockingPMEDuration.value());
// There was two blocking exchange: server node start and cache start.
assertEquals(2, Arrays.stream(durationHistogram.value()).sum());
assertEquals(2, Arrays.stream(blockindDurationHistogram.value()).sum());
Lock lock = cache.lock(1);
lock.lock();
TestRecordingCommunicationSpi spi = TestRecordingCommunicationSpi.spi(ignite);
spi.blockMessages((node, message) -> message instanceof GridDhtPartitionsFullMessage);
GridTestUtils.runAsync(() -> client ? startClientGrid("client") : startGrid(1));
assertTrue(waitForCondition(() -> ignite.context().cache().context().exchange().lastTopologyFuture().initialVersion().topologyVersion() == 2, timeout));
if (client)
assertEquals(0, currentBlockingPMEDuration.value());
else
assertTrue(currentBlockingPMEDuration.value() > 0);
lock.unlock();
spi.waitForBlocked();
spi.stopBlock();
awaitPartitionMapExchange();
assertTrue(GridTestUtils.waitForCondition(() -> currentPMEDuration.value() == 0, timeout));
assertEquals(0, currentBlockingPMEDuration.value());
if (client) {
// There was non-blocking exchange: client node start.
assertEquals(3, Arrays.stream(durationHistogram.value()).sum());
assertEquals(2, Arrays.stream(blockindDurationHistogram.value()).sum());
} else {
// There was two blocking exchange: server node start and rebalance completing.
assertEquals(4, Arrays.stream(durationHistogram.value()).sum());
assertEquals(4, Arrays.stream(blockindDurationHistogram.value()).sum());
}
}
use of org.apache.ignite.spi.metric.LongMetric in project ignite by apache.
the class IgniteClusterSnapshotSelfTest method testClusterSnapshotMetrics.
/**
* @throws Exception If fails.
*/
@Test
public void testClusterSnapshotMetrics() throws Exception {
String newSnapshotName = SNAPSHOT_NAME + "_new";
CountDownLatch deltaApply = new CountDownLatch(1);
CountDownLatch deltaBlock = new CountDownLatch(1);
IgniteEx ignite = startGridsWithCache(2, dfltCacheCfg, CACHE_KEYS_RANGE);
MetricRegistry mreg0 = ignite.context().metric().registry(SNAPSHOT_METRICS);
LongMetric startTime = mreg0.findMetric("LastSnapshotStartTime");
LongMetric endTime = mreg0.findMetric("LastSnapshotEndTime");
ObjectGauge<String> snpName = mreg0.findMetric("LastSnapshotName");
ObjectGauge<String> errMsg = mreg0.findMetric("LastSnapshotErrorMessage");
ObjectGauge<List<String>> snpList = mreg0.findMetric("LocalSnapshotNames");
// Snapshot process will be blocked when delta partition files processing starts.
snp(ignite).localSnapshotSenderFactory(blockingLocalSnapshotSender(ignite, deltaApply, deltaBlock));
assertEquals("Snapshot start time must be undefined prior to snapshot operation started.", 0, startTime.value());
assertEquals("Snapshot end time must be undefined to snapshot operation started.", 0, endTime.value());
assertTrue("Snapshot name must not exist prior to snapshot operation started.", snpName.value().isEmpty());
assertTrue("Snapshot error message must null prior to snapshot operation started.", errMsg.value().isEmpty());
assertTrue("Snapshots on local node must not exist", snpList.value().isEmpty());
long cutoffStartTime = U.currentTimeMillis();
IgniteFuture<Void> fut0 = ignite.snapshot().createSnapshot(SNAPSHOT_NAME);
U.await(deltaApply);
assertTrue("Snapshot start time must be set prior to snapshot operation started " + "[startTime=" + startTime.value() + ", cutoffTime=" + cutoffStartTime + ']', startTime.value() >= cutoffStartTime);
assertEquals("Snapshot end time must be zero prior to snapshot operation started.", 0, endTime.value());
assertEquals("Snapshot name must be set prior to snapshot operation started.", SNAPSHOT_NAME, snpName.value());
assertTrue("Snapshot error message must null prior to snapshot operation started.", errMsg.value().isEmpty());
IgniteFuture<Void> fut1 = grid(1).snapshot().createSnapshot(newSnapshotName);
assertThrowsWithCause((Callable<Object>) fut1::get, IgniteException.class);
MetricRegistry mreg1 = grid(1).context().metric().registry(SNAPSHOT_METRICS);
LongMetric startTime1 = mreg1.findMetric("LastSnapshotStartTime");
LongMetric endTime1 = mreg1.findMetric("LastSnapshotEndTime");
ObjectGauge<String> snpName1 = mreg1.findMetric("LastSnapshotName");
ObjectGauge<String> errMsg1 = mreg1.findMetric("LastSnapshotErrorMessage");
assertTrue("Snapshot start time must be greater than zero for finished snapshot.", startTime1.value() > 0);
assertEquals("Snapshot end time must zero for failed on start snapshots.", 0, endTime1.value());
assertEquals("Snapshot name must be set when snapshot operation already finished.", newSnapshotName, snpName1.value());
assertNotNull("Concurrent snapshot operation must failed.", errMsg1.value());
deltaBlock.countDown();
fut0.get();
assertTrue("Snapshot start time must be greater than zero for finished snapshot.", startTime.value() > 0);
assertTrue("Snapshot end time must be greater than zero for finished snapshot.", endTime.value() > 0);
assertEquals("Snapshot name must be set when snapshot operation already finished.", SNAPSHOT_NAME, snpName.value());
assertTrue("Concurrent snapshot operation must finished successfully.", errMsg.value().isEmpty());
assertEquals("Only the first snapshot must be created and stored on disk.", Collections.singletonList(SNAPSHOT_NAME), snpList.value());
}
Aggregations