Search in sources :

Example 6 with LongMetric

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());
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) Arrays(java.util.Arrays) GridCacheUtils.cacheId(org.apache.ignite.internal.processors.cache.GridCacheUtils.cacheId) CdcMain(org.apache.ignite.internal.cdc.CdcMain) GridTestUtils.waitForCondition(org.apache.ignite.testframework.GridTestUtils.waitForCondition) DELETE(org.apache.ignite.cdc.AbstractCdcTest.ChangeEventType.DELETE) CdcConsumerState(org.apache.ignite.internal.cdc.CdcConsumerState) Function(java.util.function.Function) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) ObjectMetric(org.apache.ignite.spi.metric.ObjectMetric) COMMITTED_SEG_IDX(org.apache.ignite.internal.cdc.CdcMain.COMMITTED_SEG_IDX) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) LAST_SEG_CONSUMPTION_TIME(org.apache.ignite.internal.cdc.CdcMain.LAST_SEG_CONSUMPTION_TIME) GridTestUtils.runAsync(org.apache.ignite.testframework.GridTestUtils.runAsync) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) MetricExporterSpi(org.apache.ignite.spi.metric.MetricExporterSpi) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) COMMITTED_SEG_OFFSET(org.apache.ignite.internal.cdc.CdcMain.COMMITTED_SEG_OFFSET) MARSHALLER_DIR(org.apache.ignite.internal.cdc.CdcMain.MARSHALLER_DIR) CdcMain.cdcInstanceName(org.apache.ignite.internal.cdc.CdcMain.cdcInstanceName) Path(java.nio.file.Path) F(org.apache.ignite.internal.util.typedef.F) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Iterator(java.util.Iterator) IgniteException(org.apache.ignite.IgniteException) BINARY_META_DIR(org.apache.ignite.internal.cdc.CdcMain.BINARY_META_DIR) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IOException(java.io.IOException) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) CI3(org.apache.ignite.internal.util.typedef.CI3) LAST_EVT_TIME(org.apache.ignite.internal.cdc.WalRecordsConsumer.LAST_EVT_TIME) File(java.io.File) IgniteCache(org.apache.ignite.IgniteCache) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) CUR_SEG_IDX(org.apache.ignite.internal.cdc.CdcMain.CUR_SEG_IDX) UPDATE(org.apache.ignite.cdc.AbstractCdcTest.ChangeEventType.UPDATE) EVTS_CNT(org.apache.ignite.internal.cdc.WalRecordsConsumer.EVTS_CNT) GridTestUtils.getFieldValue(org.apache.ignite.testframework.GridTestUtils.getFieldValue) DynamicMBean(javax.management.DynamicMBean) LongMetric(org.apache.ignite.spi.metric.LongMetric) CDC_DIR(org.apache.ignite.internal.cdc.CdcMain.CDC_DIR) DynamicMBean(javax.management.DynamicMBean) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteException(org.apache.ignite.IgniteException) ObjectMetric(org.apache.ignite.spi.metric.ObjectMetric) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) LongMetric(org.apache.ignite.spi.metric.LongMetric) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteException(org.apache.ignite.IgniteException) IOException(java.io.IOException)

Example 7 with LongMetric

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();
}
Also used : MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) LongMetric(org.apache.ignite.spi.metric.LongMetric) CountDownLatch(java.util.concurrent.CountDownLatch) TransactionMetricsMxBean(org.apache.ignite.mxbean.TransactionMetricsMxBean) Transaction(org.apache.ignite.transactions.Transaction) IntMetric(org.apache.ignite.spi.metric.IntMetric) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 8 with LongMetric

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());
}
Also used : LongMetric(org.apache.ignite.spi.metric.LongMetric) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 9 with LongMetric

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());
    }
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage) IgniteEx(org.apache.ignite.internal.IgniteEx) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) LongMetric(org.apache.ignite.spi.metric.LongMetric) HistogramMetricImpl(org.apache.ignite.internal.processors.metric.impl.HistogramMetricImpl) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Lock(java.util.concurrent.locks.Lock)

Example 10 with LongMetric

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());
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) List(java.util.List) LongMetric(org.apache.ignite.spi.metric.LongMetric) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

LongMetric (org.apache.ignite.spi.metric.LongMetric)34 MetricRegistry (org.apache.ignite.internal.processors.metric.MetricRegistry)27 Test (org.junit.Test)24 IgniteEx (org.apache.ignite.internal.IgniteEx)15 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)15 Ignite (org.apache.ignite.Ignite)7 List (java.util.List)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 ArrayList (java.util.ArrayList)5 IntMetric (org.apache.ignite.spi.metric.IntMetric)5 UUID (java.util.UUID)4 Metric (org.apache.ignite.spi.metric.Metric)4 File (java.io.File)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Function (java.util.function.Function)3 BinaryObjectBuilder (org.apache.ignite.binary.BinaryObjectBuilder)3 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)3 ClusterNode (org.apache.ignite.cluster.ClusterNode)3 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)3