Search in sources :

Example 41 with MetricRegistry

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

the class IoStatisticsBasicIndexSelfTest method testMetricRegistryRemovedOnIndexDrop.

/**
 * Checks that {@link MetricRegistry} with the sorted index IO statistics removed on index drop.
 */
@Test
public void testMetricRegistryRemovedOnIndexDrop() throws Exception {
    indexes = Collections.emptyList();
    startGrid();
    grid().cluster().active(true);
    execute(grid(), "CREATE TABLE t(id int, name varchar, primary key (id))");
    execute(grid(), "CREATE INDEX MY_IDX ON t(name)");
    MetricRegistry mreg = grid().context().metric().registry(metricName(SORTED_INDEX.metricGroupName(), "SQL_PUBLIC_T", "MY_IDX"));
    assertTrue(mreg.iterator().hasNext());
    assertNotNull(mreg.findMetric("name"));
    execute(grid(), "DROP INDEX MY_IDX");
    mreg = grid().context().metric().registry(metricName(SORTED_INDEX.metricGroupName(), "SQL_PUBLIC_T", "MY_IDX"));
    assertFalse(mreg.iterator().hasNext());
}
Also used : MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) ReadOnlyMetricRegistry(org.apache.ignite.spi.metric.ReadOnlyMetricRegistry) Test(org.junit.Test)

Example 42 with MetricRegistry

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

the class GridTcpCommunicationSpiConfigSelfTest method testSendToNonInitializedTcpCommSpi.

/**
 * Verifies that TcpCommunicationSpi starts messaging protocol only when fully initialized.
 *
 * @see <a href="https://issues.apache.org/jira/browse/IGNITE-12982">IGNITE-12982</a>
 *
 * @throws Exception If failed.
 */
@Test
@WithSystemProperty(key = "IGNITE_SKIP_CONFIGURATION_CONSISTENCY_CHECK", value = "true")
public void testSendToNonInitializedTcpCommSpi() throws Exception {
    ListeningTestLogger listeningLogger = new ListeningTestLogger(log);
    LogListener npeLsnr = LogListener.matches("NullPointerException").andMatches("InboundConnectionHandler.onMessageSent").build();
    listeningLogger.registerListener(npeLsnr);
    GridTestNode sendingNode = new GridTestNode();
    sendingNode.order(0);
    GridSpiTestContext sendingCtx = initSpiContext();
    TcpCommunicationSpi sendingSpi = initializeSpi(sendingCtx, sendingNode, listeningLogger, false);
    spisToStop.add(sendingSpi);
    sendingSpi.onContextInitialized(sendingCtx);
    GridTestNode receiverNode = new GridTestNode();
    receiverNode.order(1);
    GridSpiTestContext receiverCtx = initSpiContext();
    /*
         * This is a dirty hack to intervene into TcpCommunicationSpi#onContextInitialized0 method
         * and add a delay before injecting metrics listener into its clients (like InboundConnectionHandler).
         * The purpose of the delay is to make race between sending a message and initializing TcpCommSpi visible.
         *
         * This solution heavily depends on current code structure of onContextInitialized0 method.
         * If any modifications are made to it, this logic could break and the test starts failing.
         *
         * In that case try to rewrite the test or delete it as this race is really hard to test.
         */
    receiverCtx.metricsRegistryProducer((name) -> {
        try {
            Thread.sleep(100);
        } catch (Exception ignored) {
        // No-op.
        }
        return new MetricRegistry(name, null, null, new NullLogger());
    });
    TcpCommunicationSpi receiverSpi = initializeSpi(receiverCtx, receiverNode, listeningLogger, true);
    spisToStop.add(receiverSpi);
    receiverCtx.remoteNodes().add(sendingNode);
    sendingCtx.remoteNodes().add(receiverNode);
    IgniteInternalFuture sendFut = GridTestUtils.runAsync(() -> {
        Message msg = new GridTestMessage(sendingNode.id(), 0, 0);
        sendingSpi.sendMessage(receiverNode, msg);
    });
    IgniteInternalFuture initFut = GridTestUtils.runAsync(() -> {
        try {
            receiverSpi.onContextInitialized(receiverCtx);
        } catch (Exception ignored) {
        // No-op.
        }
    });
    assertFalse("Check test logs, NPE was found", GridTestUtils.waitForCondition(npeLsnr::check, 3_000));
    initFut.get();
    sendFut.get();
}
Also used : GridSpiTestContext(org.apache.ignite.testframework.GridSpiTestContext) GridTestMessage(org.apache.ignite.spi.communication.GridTestMessage) NullLogger(org.apache.ignite.logger.NullLogger) LogListener(org.apache.ignite.testframework.LogListener) GridTestMessage(org.apache.ignite.spi.communication.GridTestMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridTestNode(org.apache.ignite.testframework.GridTestNode) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridSpiTest(org.apache.ignite.testframework.junits.spi.GridSpiTest) GridAbstractTest(org.apache.ignite.testframework.junits.GridAbstractTest) Test(org.junit.Test) GridSpiAbstractConfigTest(org.apache.ignite.testframework.junits.spi.GridSpiAbstractConfigTest) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty)

Example 43 with MetricRegistry

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

the class TcpCommunicationStatisticsTest method testStatistics.

/**
 * @throws Exception If failed.
 */
@SuppressWarnings("ConstantConditions")
@Test
public void testStatistics() throws Exception {
    startGrids(2);
    try {
        Object node0consistentId = grid(0).localNode().consistentId();
        Object node1consistentId = grid(1).localNode().consistentId();
        String node0regName = MetricUtils.metricName(COMMUNICATION_METRICS_GROUP_NAME, node0consistentId.toString());
        String node1regName = MetricUtils.metricName(COMMUNICATION_METRICS_GROUP_NAME, node1consistentId.toString());
        // Send custom message from node0 to node1.
        grid(0).context().io().sendToGridTopic(grid(1).cluster().localNode(), GridTopic.TOPIC_IO_TEST, new GridTestMessage(), GridIoPolicy.PUBLIC_POOL);
        latch.await(10, TimeUnit.SECONDS);
        ClusterGroup clusterGrpNode1 = grid(0).cluster().forNodeId(grid(1).localNode().id());
        // Send job from node0 to node1.
        grid(0).compute(clusterGrpNode1).call(new IgniteCallable<Boolean>() {

            @Override
            public Boolean call() throws Exception {
                return Boolean.TRUE;
            }
        });
        synchronized (mux) {
            TcpCommunicationSpiMBean mbean0 = mbean(0);
            TcpCommunicationSpiMBean mbean1 = mbean(1);
            Map<UUID, Long> msgsSentByNode0 = mbean0.getSentMessagesByNode();
            Map<UUID, Long> msgsSentByNode1 = mbean1.getSentMessagesByNode();
            Map<UUID, Long> msgsReceivedByNode0 = mbean0.getReceivedMessagesByNode();
            Map<UUID, Long> msgsReceivedByNode1 = mbean1.getReceivedMessagesByNode();
            UUID nodeId0 = grid(0).localNode().id();
            UUID nodeId1 = grid(1).localNode().id();
            assertEquals(msgsReceivedByNode0.get(nodeId1).longValue(), mbean0.getReceivedMessagesCount());
            assertEquals(msgsReceivedByNode1.get(nodeId0).longValue(), mbean1.getReceivedMessagesCount());
            assertEquals(msgsSentByNode0.get(nodeId1).longValue(), mbean0.getSentMessagesCount());
            assertEquals(msgsSentByNode1.get(nodeId0).longValue(), mbean1.getSentMessagesCount());
            assertEquals(mbean0.getSentMessagesCount(), mbean1.getReceivedMessagesCount());
            assertEquals(mbean1.getSentMessagesCount(), mbean0.getReceivedMessagesCount());
            Map<String, Long> msgsSentByType0 = mbean0.getSentMessagesByType();
            Map<String, Long> msgsSentByType1 = mbean1.getSentMessagesByType();
            Map<String, Long> msgsReceivedByType0 = mbean0.getReceivedMessagesByType();
            Map<String, Long> msgsReceivedByType1 = mbean1.getReceivedMessagesByType();
            // Node0 sent exactly the same types and count of messages as node1 received.
            assertEquals(msgsSentByType0, msgsReceivedByType1);
            // Node1 sent exactly the same types and count of messages as node0 received.
            assertEquals(msgsSentByType1, msgsReceivedByType0);
            assertEquals(1, msgsSentByType0.get(GridTestMessage.class.getName()).longValue());
            assertEquals(1, msgsReceivedByType1.get(GridTestMessage.class.getName()).longValue());
            MetricRegistry mreg0 = grid(0).context().metric().registry(node1regName);
            MetricRegistry mreg1 = grid(1).context().metric().registry(node0regName);
            LongAdderMetric sentMetric = mreg0.findMetric(SENT_MESSAGES_BY_NODE_CONSISTENT_ID_METRIC_NAME);
            assertNotNull(sentMetric);
            assertEquals(mbean0.getSentMessagesCount(), sentMetric.value());
            LongAdderMetric rcvMetric = mreg1.findMetric(RECEIVED_MESSAGES_BY_NODE_CONSISTENT_ID_METRIC_NAME);
            assertNotNull(rcvMetric);
            assertEquals(mbean1.getReceivedMessagesCount(), rcvMetric.value());
            stopGrid(1);
            mreg0 = grid(0).context().metric().registry(node1regName);
            sentMetric = mreg0.findMetric(SENT_MESSAGES_BY_NODE_CONSISTENT_ID_METRIC_NAME);
            // Automatically generated by MetricRegistryCreationListener.
            assertNotNull(sentMetric);
            assertEquals(0, sentMetric.value());
        }
    } finally {
        stopAllGrids();
    }
}
Also used : GridTestMessage(org.apache.ignite.spi.communication.GridTestMessage) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) IgniteException(org.apache.ignite.IgniteException) LongAdderMetric(org.apache.ignite.internal.processors.metric.impl.LongAdderMetric) UUID(java.util.UUID) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 44 with MetricRegistry

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

the class TcpDiscoverySpiMBeanTest method testMBean.

/**
 * Tests TcpDiscoverySpiMBean#getCurrentTopologyVersion() and TcpDiscoverySpiMBean#dumpRingStructure().
 *
 * @throws Exception if fails.
 */
@Test
public void testMBean() throws Exception {
    int cnt = 3;
    int cliIdx = cnt - 1;
    startGrids(cnt - 1);
    startClientGrid(cliIdx);
    ClusterNode crd = U.oldest(grid(0).context().discovery().aliveServerNodes(), null);
    assertNotNull(crd);
    try {
        for (int i = 0; i < cnt; i++) {
            IgniteEx grid = grid(i);
            MetricRegistry discoReg = grid.context().metric().registry(DISCO_METRICS);
            TcpDiscoverySpiMBean bean = getMxBean(grid.context().igniteInstanceName(), "SPIs", TcpDiscoverySpi.class, TcpDiscoverySpiMBean.class);
            assertNotNull(bean);
            assertEquals(grid.cluster().topologyVersion(), bean.getCurrentTopologyVersion());
            assertEquals(grid.cluster().topologyVersion(), discoReg.<LongMetric>findMetric("CurrentTopologyVersion").value());
            if (i != cliIdx) {
                assertEquals(crd.id(), bean.getCoordinator());
                assertEquals(crd.id(), discoReg.<ObjectMetric<UUID>>findMetric("Coordinator").value());
            } else {
                assertNull(bean.getCoordinator());
                assertNull(discoReg.findMetric("Coordinator"));
            }
            if (grid.localNode().id().equals(bean.getCoordinator())) {
                assertTrue(bean.getCoordinatorSinceTimestamp() > 0);
                assertTrue(discoReg.<LongMetric>findMetric("CoordinatorSince").value() > 0);
            } else {
                assertEquals(0, bean.getCoordinatorSinceTimestamp());
                if (i == cliIdx)
                    assertNull(discoReg.findMetric("CoordinatorSince"));
                else
                    assertEquals(0L, discoReg.<LongMetric>findMetric("CoordinatorSince").value());
            }
            // `getNodesJoined` returns count of joined nodes since local node startup.
            assertEquals((cnt - 1) - i, bean.getNodesJoined());
            assertEquals((cnt - 1) - i, discoReg.<IntMetric>findMetric("JoinedNodes").value());
            assertEquals(0L, bean.getNodesFailed());
            assertEquals(0, discoReg.<IntMetric>findMetric("FailedNodes").value());
            assertEquals(0L, bean.getNodesLeft());
            assertEquals(0, discoReg.<IntMetric>findMetric("LeftNodes").value());
            assertTrue(bean.getTotalReceivedMessages() > 0);
            assertTrue(discoReg.<IntMetric>findMetric("TotalReceivedMessages").value() > 0);
            assertTrue(bean.getTotalProcessedMessages() > 0);
            assertTrue(discoReg.<IntMetric>findMetric("TotalProcessedMessages").value() > 0);
            if (i != cliIdx) {
                assertTrue(bean.getPendingMessagesRegistered() > 0);
                assertTrue(discoReg.<IntMetric>findMetric("PendingMessagesRegistered").value() > 0);
            } else {
                assertEquals(0, bean.getPendingMessagesRegistered());
                assertEquals(0, discoReg.<IntMetric>findMetric("PendingMessagesRegistered").value());
            }
            assertEquals(0, bean.getPendingMessagesDiscarded());
            bean.dumpRingStructure();
            assertTrue(strLog.toString().contains("TcpDiscoveryNodesRing"));
            assertFalse(bean.getProcessedMessages().isEmpty());
            assertFalse(bean.getReceivedMessages().isEmpty());
            assertTrue(bean.getMaxMessageProcessingTime() >= 0);
            assertEquals(i == cliIdx, bean.isClientMode());
        }
        stopGrid(0);
        crd = U.oldest(grid(1).context().discovery().aliveServerNodes(), null);
        for (int i = 1; i < cnt; i++) {
            IgniteEx grid = grid(i);
            MetricRegistry discoReg = grid.context().metric().registry(DISCO_METRICS);
            TcpDiscoverySpiMBean bean = getMxBean(grid.context().igniteInstanceName(), "SPIs", TcpDiscoverySpi.class, TcpDiscoverySpiMBean.class);
            assertNotNull(bean);
            assertEquals(grid.cluster().topologyVersion(), bean.getCurrentTopologyVersion());
            assertEquals(grid.cluster().topologyVersion(), discoReg.<LongMetric>findMetric("CurrentTopologyVersion").value());
            if (i != cliIdx) {
                assertEquals(crd.id(), bean.getCoordinator());
                assertEquals(crd.id(), discoReg.<ObjectMetric<UUID>>findMetric("Coordinator").value());
            }
            if (grid.localNode().id().equals(crd.id())) {
                assertTrue(bean.getCoordinatorSinceTimestamp() > 0);
                assertTrue(discoReg.<LongMetric>findMetric("CoordinatorSince").value() > 0);
            }
            assertTrue(waitForCondition(() -> bean.getNodesLeft() == 1 && discoReg.<IntMetric>findMetric("LeftNodes").value() == 1, getTestTimeout()));
        }
    } finally {
        stopAllGrids();
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) ObjectMetric(org.apache.ignite.spi.metric.ObjectMetric) IgniteEx(org.apache.ignite.internal.IgniteEx) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) LongMetric(org.apache.ignite.spi.metric.LongMetric) IntMetric(org.apache.ignite.spi.metric.IntMetric) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 45 with MetricRegistry

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

the class NodeSslConnectionMetricTest method testJdbc.

/**
 * Tests SSL metrics produced by JDBC connection.
 */
@Test
public void testJdbc() throws Exception {
    MetricRegistry reg = mreg(startClusterNode(0), CLIENT_CONNECTOR_METRICS);
    assertEquals(0, reg.<LongMetric>findMetric(SENT_BYTES_METRIC_NAME).value());
    assertEquals(0, reg.<LongMetric>findMetric(RECEIVED_BYTES_METRIC_NAME).value());
    try (Connection ignored = getConnection(jdbcConfiguration("thinClient", "trusttwo", CIPHER_SUITE, "TLSv1.2"))) {
        checkSslCommunicationMetrics(reg, 1, 1, 0);
    }
    assertTrue(reg.<LongMetric>findMetric(SENT_BYTES_METRIC_NAME).value() > 0);
    assertTrue(reg.<LongMetric>findMetric(RECEIVED_BYTES_METRIC_NAME).value() > 0);
    checkSslCommunicationMetrics(reg, 1, 0, 0);
    // Tests untrusted certificate.
    assertThrowsWithCause(() -> getConnection(jdbcConfiguration("client", "trusttwo", CIPHER_SUITE, "TLSv1.2")), SQLException.class);
    checkSslCommunicationMetrics(reg, 2, 0, 1);
    // Tests unsupported cipher suite.
    assertThrowsWithCause(() -> getConnection(jdbcConfiguration("thinClient", "trusttwo", UNSUPPORTED_CIPHER_SUITE, "TLSv1.2")), SQLException.class);
    checkSslCommunicationMetrics(reg, 3, 0, 2);
    assertThrowsWithCause(() -> getConnection(jdbcConfiguration("thinClient", "trusttwo", null, "TLSv1.1")), SQLException.class);
    checkSslCommunicationMetrics(reg, 4, 0, 3);
}
Also used : MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) Connection(java.sql.Connection) DriverManager.getConnection(java.sql.DriverManager.getConnection) LongMetric(org.apache.ignite.spi.metric.LongMetric) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) 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