Search in sources :

Example 36 with MetricRegistry

use of org.apache.ignite.internal.processors.metric.MetricRegistry 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 37 with MetricRegistry

use of org.apache.ignite.internal.processors.metric.MetricRegistry 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)

Example 38 with MetricRegistry

use of org.apache.ignite.internal.processors.metric.MetricRegistry in project ignite by apache.

the class UserQueriesTestBase method longMetricValue.

/**
 * Finds LongMetric from sql user queries registry by specified metric name and returns it's value.
 *
 * @param gridIdx index of a grid which metric value to find.
 * @param metricName short name of the metric from the "sql memory" metric registry.
 */
protected long longMetricValue(int gridIdx, String metricName) {
    MetricRegistry sqlMemReg = grid(gridIdx).context().metric().registry(SQL_USER_QUERIES_REG_NAME);
    Metric metric = sqlMemReg.findMetric(metricName);
    Assert.assertNotNull("Didn't find metric " + metricName, metric);
    Assert.assertTrue("Expected long metric, but got " + metric.getClass(), metric instanceof LongMetric);
    return ((LongMetric) metric).value();
}
Also used : MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) Metric(org.apache.ignite.spi.metric.Metric) LongMetric(org.apache.ignite.spi.metric.LongMetric) LongMetric(org.apache.ignite.spi.metric.LongMetric)

Example 39 with MetricRegistry

use of org.apache.ignite.internal.processors.metric.MetricRegistry in project ignite by apache.

the class GridJobMetricsSelfTest method testGridJobWaitingRejectedMetrics.

/**
 * Test correct calculation of rejected and waiting metrics of the {@link GridJobProcessor}.
 */
@Test
public void testGridJobWaitingRejectedMetrics() throws Exception {
    latch = new CountDownLatch(1);
    GridTestCollision collisioinSpi = new GridTestCollision();
    IgniteConfiguration cfg = getConfiguration().setCollisionSpi(collisioinSpi);
    try (IgniteEx g = startGrid(cfg)) {
        MetricRegistry mreg = g.context().metric().registry(JOBS_METRICS);
        LongMetric started = mreg.findMetric(STARTED);
        LongMetric active = mreg.findMetric(ACTIVE);
        LongMetric waiting = mreg.findMetric(WAITING);
        LongMetric canceled = mreg.findMetric(CANCELED);
        LongMetric rejected = mreg.findMetric(REJECTED);
        LongMetric finished = mreg.findMetric(FINISHED);
        LongMetric totalExecutionTime = mreg.findMetric(EXECUTION_TIME);
        LongMetric totalWaitingTime = mreg.findMetric(WAITING_TIME);
        assertNotNull(started);
        assertNotNull(active);
        assertNotNull(waiting);
        assertNotNull(canceled);
        assertNotNull(rejected);
        assertNotNull(finished);
        assertNotNull(totalExecutionTime);
        assertNotNull(totalWaitingTime);
        assertEquals(0, started.value());
        assertEquals(0, active.value());
        assertEquals(0, waiting.value());
        assertEquals(0, canceled.value());
        assertEquals(0, rejected.value());
        assertEquals(0, finished.value());
        assertEquals(0, totalExecutionTime.value());
        assertEquals(0, totalWaitingTime.value());
        SimplestTask task1 = new SimplestTask();
        SimplestTask task2 = new SimplestTask();
        SimplestTask task3 = new SimplestTask();
        task1.block = true;
        task2.block = true;
        task3.block = true;
        // Task will become "waiting", because of CollisionSpi implementation.
        ComputeTaskFuture<?> fut1 = g.compute().executeAsync(task1, 1);
        ComputeTaskFuture<?> fut2 = g.compute().executeAsync(task2, 1);
        ComputeTaskFuture<?> fut3 = g.compute().executeAsync(task3, 1);
        assertEquals(0, started.value());
        assertEquals(0, active.value());
        assertEquals(3, waiting.value());
        assertEquals(0, canceled.value());
        assertEquals(0, rejected.value());
        assertEquals(0, finished.value());
        // Activating 2 of 3 jobs. Rejecting 1 of them.
        Iterator<CollisionJobContext> iter = collisioinSpi.jobs.values().iterator();
        iter.next().cancel();
        assertEquals(1, rejected.value());
        // Sleeping to make sure totalWaitingTime will become more the zero.
        Thread.sleep(100);
        iter.next().activate();
        iter.next().activate();
        boolean res = waitForCondition(() -> active.value() > 0, TIMEOUT);
        assertTrue(res);
        assertTrue("Waiting time should be greater then zero.", totalWaitingTime.value() > 0);
        // Sleeping to make sure totalExecutionTime will become more the zero.
        Thread.sleep(100);
        latch.countDown();
        res = waitForCondition(() -> fut1.isDone() && fut2.isDone() && fut3.isDone(), TIMEOUT);
        assertTrue(res);
        res = waitForCondition(() -> finished.value() == 3, TIMEOUT);
        assertTrue(res);
        assertTrue("Execution time should be greater then zero.", totalExecutionTime.value() > 0);
    }
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteEx(org.apache.ignite.internal.IgniteEx) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) LongMetric(org.apache.ignite.spi.metric.LongMetric) CollisionJobContext(org.apache.ignite.spi.collision.CollisionJobContext) CountDownLatch(java.util.concurrent.CountDownLatch) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 40 with MetricRegistry

use of org.apache.ignite.internal.processors.metric.MetricRegistry in project ignite by apache.

the class CacheGroupMetricsWithIndexTest method testIndexRebuildCountPartitionsLeft.

/**
 * Test number of partitions need to finished indexes rebuilding.
 */
@Test
public void testIndexRebuildCountPartitionsLeft() throws Exception {
    pds = true;
    Ignite ignite = startGrid(0);
    ignite.cluster().active(true);
    IgniteCache<Object, Object> cache1 = ignite.cache(CACHE_NAME);
    for (int i = 0; i < 100_000; i++) {
        Long id = (long) i;
        BinaryObjectBuilder o = ignite.binary().builder(OBJECT_NAME).setField(KEY_NAME, id).setField(COLUMN1_NAME, i / 2).setField(COLUMN2_NAME, "str" + Integer.toHexString(i));
        cache1.put(id, o.build());
    }
    ignite.cluster().active(false);
    File dir = U.resolveWorkDirectory(U.defaultWorkDirectory(), DFLT_STORE_DIR, false);
    IOFileFilter filter = FileFilterUtils.nameFileFilter("index.bin");
    Collection<File> idxBinFiles = FileUtils.listFiles(dir, filter, TrueFileFilter.TRUE);
    for (File indexBin : idxBinFiles) U.delete(indexBin);
    ignite.cluster().active(true);
    MetricRegistry metrics = cacheGroupMetrics(0, GROUP_NAME).get2();
    LongMetric idxBuildCntPartitionsLeft = metrics.findMetric("IndexBuildCountPartitionsLeft");
    assertTrue("Timeout wait start rebuild index", waitForCondition(() -> idxBuildCntPartitionsLeft.value() > 0, 30_000));
    assertTrue("Timeout wait finished rebuild index", GridTestUtils.waitForCondition(() -> idxBuildCntPartitionsLeft.value() == 0, 30_000));
}
Also used : MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) IOFileFilter(org.apache.commons.io.filefilter.IOFileFilter) Ignite(org.apache.ignite.Ignite) LongMetric(org.apache.ignite.spi.metric.LongMetric) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder) File(java.io.File) Test(org.junit.Test)

Aggregations

MetricRegistry (org.apache.ignite.internal.processors.metric.MetricRegistry)86 Test (org.junit.Test)52 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)29 IgniteEx (org.apache.ignite.internal.IgniteEx)26 LongMetric (org.apache.ignite.spi.metric.LongMetric)26 List (java.util.List)11 CountDownLatch (java.util.concurrent.CountDownLatch)11 UUID (java.util.UUID)10 Map (java.util.Map)8 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)8 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)8 ArrayList (java.util.ArrayList)7 IgniteException (org.apache.ignite.IgniteException)7 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)7 IntMetric (org.apache.ignite.spi.metric.IntMetric)7 IgniteCache (org.apache.ignite.IgniteCache)6 ClusterNode (org.apache.ignite.cluster.ClusterNode)6 Arrays (java.util.Arrays)5 HashSet (java.util.HashSet)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5