You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2021/06/29 14:14:39 UTC

[GitHub] [ignite] ptupitsyn commented on a change in pull request #9182: IGNITE-14815 Metrics for thin clients

ptupitsyn commented on a change in pull request #9182:
URL: https://github.com/apache/ignite/pull/9182#discussion_r660654229



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/ClientListenerMetrics.java
##########
@@ -0,0 +1,157 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ignite.internal.processors.odbc;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.processors.metric.MetricRegistry;
+import org.apache.ignite.internal.processors.metric.impl.IntMetricImpl;
+import org.apache.ignite.internal.processors.metric.impl.MetricUtils;
+
+import static org.apache.ignite.internal.processors.metric.GridMetricManager.CLIENT_METRICS;
+import static org.apache.ignite.internal.processors.odbc.ClientListenerNioListener.JDBC_CLIENT;
+import static org.apache.ignite.internal.processors.odbc.ClientListenerNioListener.ODBC_CLIENT;
+import static org.apache.ignite.internal.processors.odbc.ClientListenerNioListener.THIN_CLIENT;
+
+/**
+ * Client listener metrics.
+ */
+public class ClientListenerMetrics {
+    /** Connections metric label. */
+    public static final String METRIC_CONNECTIONS = "connections";
+
+    /** Handshakes rejected by timeout metric label. */
+    public static final String METRIC_REJECTED_TIMEOUT =
+            MetricUtils.metricName(METRIC_CONNECTIONS, "rejectedByTimeout");
+
+    /** Handshakes rejected by authentication metric label. */
+    public static final String METRIC_REJECTED_AUTHENTICATION =
+            MetricUtils.metricName(METRIC_CONNECTIONS, "rejectedAuthentication");
+
+    /** Total number of rejected handshakes. */
+    public static final String METRIC_REJECTED_TOTAL =
+            MetricUtils.metricName(METRIC_CONNECTIONS, "rejectedTotal");
+
+    /** Rejected by timeout. */
+    private final IntMetricImpl rejectedTimeout;
+
+    /** Rejected by authentication. */
+    private final IntMetricImpl rejectedAuth;
+
+    /** Total number of rejected connections. */
+    private final IntMetricImpl rejectedTotal;
+
+    /** Connections accepted. */
+    private final Map<Byte, IntMetricImpl> accepted;

Review comment:
       Nitpick: Map can be replaced with an array, here and below.

##########
File path: modules/core/src/test/java/org/apache/ignite/internal/processors/odbc/ClientListenerMetricsTest.java
##########
@@ -0,0 +1,222 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.odbc;
+
+import org.apache.ignite.Ignition;
+import org.apache.ignite.client.ClientAuthenticationException;
+import org.apache.ignite.client.ClientException;
+import org.apache.ignite.client.Config;
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.client.SslMode;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.ClientConfiguration;
+import org.apache.ignite.configuration.ClientConnectorConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.IgniteInterruptedCheckedException;
+import org.apache.ignite.internal.processors.metric.MetricRegistry;
+import org.apache.ignite.internal.util.lang.GridAbsPredicate;
+import org.apache.ignite.spi.metric.IntMetric;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+import static org.apache.ignite.internal.processors.metric.GridMetricManager.CLIENT_METRICS;
+import static org.apache.ignite.ssl.SslContextFactory.DFLT_STORE_TYPE;
+
+/**
+ * Client listener metrics tests.
+ */
+public class ClientListenerMetricsTest extends GridCommonAbstractTest {
+    /**
+     * Check that valid connections and disconnections to the grid affect metrics.
+     */
+    @Test
+    public void testClientListenerMetricsAccept() throws Exception {
+        try (IgniteEx ignite = startGrid(0))
+        {
+            MetricRegistry mreg = ignite.context().metric().registry(CLIENT_METRICS);
+
+            checkConnectionsMetrics(mreg, 0, 0);
+
+            IgniteClient client0 = Ignition.startClient(getClientConfiguration());
+
+            checkConnectionsMetrics(mreg, 1, 1);
+
+            client0.close();
+
+            checkConnectionsMetrics(mreg, 1, 0);
+
+            IgniteClient client1 = Ignition.startClient(getClientConfiguration());
+
+            checkConnectionsMetrics(mreg, 2, 1);
+
+            IgniteClient client2 = Ignition.startClient(getClientConfiguration());
+
+            checkConnectionsMetrics(mreg, 3, 2);
+
+            client1.close();
+
+            checkConnectionsMetrics(mreg, 3, 1);
+
+            client2.close();
+
+            checkConnectionsMetrics(mreg, 3, 0);
+        }
+    }
+
+    /**
+     * Check that failed connection attempts to the grid affect metrics.
+     */
+    @Test
+    public void testClientListenerMetricsReject() throws Exception {
+        cleanPersistenceDir();
+
+        IgniteConfiguration nodeCfg = getConfiguration()
+            .setClientConnectorConfiguration(new ClientConnectorConfiguration()
+                .setHandshakeTimeout(2000))
+            .setAuthenticationEnabled(true)
+            .setDataStorageConfiguration(new DataStorageConfiguration()
+                .setDefaultDataRegionConfiguration(new DataRegionConfiguration()
+                    .setPersistenceEnabled(true)));
+
+        try (IgniteEx ignite = startGrid(nodeCfg))
+        {
+            ignite.cluster().state(ClusterState.ACTIVE);
+            MetricRegistry mreg = ignite.context().metric().registry(CLIENT_METRICS);
+
+            checkRejectMetrics(mreg, 0, 0, 0);
+
+            ClientConfiguration cfgSsl = getClientConfiguration()
+                .setSslMode(SslMode.REQUIRED)
+                .setSslClientCertificateKeyStorePath(GridTestUtils.keyStorePath("client"))
+                .setSslClientCertificateKeyStoreType(DFLT_STORE_TYPE)
+                .setSslClientCertificateKeyStorePassword("123456")
+                .setSslTrustCertificateKeyStorePath(GridTestUtils.keyStorePath("trustone"))
+                .setSslTrustCertificateKeyStoreType(DFLT_STORE_TYPE)
+                .setSslTrustCertificateKeyStorePassword("123456");
+
+            try {
+                Ignition.startClient(cfgSsl);
+
+                fail("Should be rejected.");
+            }
+            catch (ClientException ignored) {}
+
+            checkRejectMetrics(mreg, 1, 0, 1);
+
+            ClientConfiguration cfgAuth = getClientConfiguration()
+                .setUserName("SomeRandomInvalidName")
+                .setUserPassword("42");
+
+            try {
+                Ignition.startClient(cfgAuth);
+
+                fail("Should be rejected.");
+            }
+            catch (ClientAuthenticationException ignored) {}
+
+            checkRejectMetrics(mreg, 1, 1, 2);
+        }
+    }
+
+    /**
+     * Check that failed connection attempts to the grid affect metrics.
+     */
+    @Test
+    public void testClientListenerMetricsRejectGeneral() throws Exception {
+        IgniteConfiguration nodeCfg = getConfiguration()
+            .setClientConnectorConfiguration(new ClientConnectorConfiguration()
+            .setThinClientEnabled(false));
+
+        try (IgniteEx ignite = startGrid(nodeCfg))
+        {
+            MetricRegistry mreg = ignite.context().metric().registry(CLIENT_METRICS);
+
+            checkRejectMetrics(mreg, 0, 0, 0);
+
+            try {
+                Ignition.startClient(getClientConfiguration());
+            }
+            catch (RuntimeException err) {
+                assert err.getMessage().contains("Thin client connection is not allowed");

Review comment:
       Let's use `GridTestUtils.assertThrows`: it can check that exception occurs and the message contains expected text.

##########
File path: modules/core/src/test/java/org/apache/ignite/internal/processors/odbc/ClientListenerMetricsTest.java
##########
@@ -0,0 +1,222 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.odbc;
+
+import org.apache.ignite.Ignition;
+import org.apache.ignite.client.ClientAuthenticationException;
+import org.apache.ignite.client.ClientException;
+import org.apache.ignite.client.Config;
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.client.SslMode;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.ClientConfiguration;
+import org.apache.ignite.configuration.ClientConnectorConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.IgniteInterruptedCheckedException;
+import org.apache.ignite.internal.processors.metric.MetricRegistry;
+import org.apache.ignite.internal.util.lang.GridAbsPredicate;
+import org.apache.ignite.spi.metric.IntMetric;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+import static org.apache.ignite.internal.processors.metric.GridMetricManager.CLIENT_METRICS;
+import static org.apache.ignite.ssl.SslContextFactory.DFLT_STORE_TYPE;
+
+/**
+ * Client listener metrics tests.
+ */
+public class ClientListenerMetricsTest extends GridCommonAbstractTest {
+    /**
+     * Check that valid connections and disconnections to the grid affect metrics.
+     */
+    @Test
+    public void testClientListenerMetricsAccept() throws Exception {
+        try (IgniteEx ignite = startGrid(0))
+        {
+            MetricRegistry mreg = ignite.context().metric().registry(CLIENT_METRICS);
+
+            checkConnectionsMetrics(mreg, 0, 0);
+
+            IgniteClient client0 = Ignition.startClient(getClientConfiguration());
+
+            checkConnectionsMetrics(mreg, 1, 1);
+
+            client0.close();
+
+            checkConnectionsMetrics(mreg, 1, 0);
+
+            IgniteClient client1 = Ignition.startClient(getClientConfiguration());
+
+            checkConnectionsMetrics(mreg, 2, 1);
+
+            IgniteClient client2 = Ignition.startClient(getClientConfiguration());
+
+            checkConnectionsMetrics(mreg, 3, 2);
+
+            client1.close();
+
+            checkConnectionsMetrics(mreg, 3, 1);
+
+            client2.close();
+
+            checkConnectionsMetrics(mreg, 3, 0);
+        }
+    }
+
+    /**
+     * Check that failed connection attempts to the grid affect metrics.
+     */
+    @Test
+    public void testClientListenerMetricsReject() throws Exception {
+        cleanPersistenceDir();
+
+        IgniteConfiguration nodeCfg = getConfiguration()
+            .setClientConnectorConfiguration(new ClientConnectorConfiguration()
+                .setHandshakeTimeout(2000))
+            .setAuthenticationEnabled(true)
+            .setDataStorageConfiguration(new DataStorageConfiguration()
+                .setDefaultDataRegionConfiguration(new DataRegionConfiguration()
+                    .setPersistenceEnabled(true)));
+
+        try (IgniteEx ignite = startGrid(nodeCfg))
+        {
+            ignite.cluster().state(ClusterState.ACTIVE);
+            MetricRegistry mreg = ignite.context().metric().registry(CLIENT_METRICS);
+
+            checkRejectMetrics(mreg, 0, 0, 0);
+
+            ClientConfiguration cfgSsl = getClientConfiguration()
+                .setSslMode(SslMode.REQUIRED)
+                .setSslClientCertificateKeyStorePath(GridTestUtils.keyStorePath("client"))
+                .setSslClientCertificateKeyStoreType(DFLT_STORE_TYPE)
+                .setSslClientCertificateKeyStorePassword("123456")
+                .setSslTrustCertificateKeyStorePath(GridTestUtils.keyStorePath("trustone"))
+                .setSslTrustCertificateKeyStoreType(DFLT_STORE_TYPE)
+                .setSslTrustCertificateKeyStorePassword("123456");
+
+            try {
+                Ignition.startClient(cfgSsl);
+
+                fail("Should be rejected.");
+            }
+            catch (ClientException ignored) {}
+
+            checkRejectMetrics(mreg, 1, 0, 1);
+
+            ClientConfiguration cfgAuth = getClientConfiguration()
+                .setUserName("SomeRandomInvalidName")
+                .setUserPassword("42");
+
+            try {
+                Ignition.startClient(cfgAuth);
+
+                fail("Should be rejected.");
+            }
+            catch (ClientAuthenticationException ignored) {}
+
+            checkRejectMetrics(mreg, 1, 1, 2);
+        }
+    }
+
+    /**
+     * Check that failed connection attempts to the grid affect metrics.
+     */
+    @Test
+    public void testClientListenerMetricsRejectGeneral() throws Exception {
+        IgniteConfiguration nodeCfg = getConfiguration()
+            .setClientConnectorConfiguration(new ClientConnectorConfiguration()
+            .setThinClientEnabled(false));
+
+        try (IgniteEx ignite = startGrid(nodeCfg))
+        {
+            MetricRegistry mreg = ignite.context().metric().registry(CLIENT_METRICS);
+
+            checkRejectMetrics(mreg, 0, 0, 0);
+
+            try {
+                Ignition.startClient(getClientConfiguration());
+            }
+            catch (RuntimeException err) {
+                assert err.getMessage().contains("Thin client connection is not allowed");
+            }
+
+            checkRejectMetrics(mreg, 0, 0, 1);
+        }
+    }
+
+    /** */
+    private static ClientConfiguration getClientConfiguration() {
+        return new ClientConfiguration()
+                .setAddresses(Config.SERVER)
+                .setSendBufferSize(0)
+                .setReceiveBufferSize(0);
+    }
+
+    /**
+     * Wait for specific metric to change
+     * @param mreg Metric registry.
+     * @param metric Metric to check.
+     * @param value Metric value to wait for.
+     * @param timeout Timeout.
+     */
+    private void waitForMetricValue(MetricRegistry mreg, String metric, long value, long timeout) {
+        try {
+            GridTestUtils.waitForCondition(new GridAbsPredicate() {
+                @Override public boolean apply() {
+                    return mreg.<IntMetric>findMetric(metric).value() == value;
+                }
+            }, timeout);
+            assertEquals(mreg.<IntMetric>findMetric(metric).value(), value);
+        } catch (IgniteInterruptedCheckedException e) {
+            fail("Interrupted while waiting for metric change");

Review comment:
       Failing this way swallows original exception details. I don't think we need to catch anything at all - let it fail.

##########
File path: modules/core/src/test/java/org/apache/ignite/internal/processors/odbc/ClientListenerMetricsTest.java
##########
@@ -0,0 +1,222 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.odbc;
+
+import org.apache.ignite.Ignition;
+import org.apache.ignite.client.ClientAuthenticationException;
+import org.apache.ignite.client.ClientException;
+import org.apache.ignite.client.Config;
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.client.SslMode;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.ClientConfiguration;
+import org.apache.ignite.configuration.ClientConnectorConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.IgniteInterruptedCheckedException;
+import org.apache.ignite.internal.processors.metric.MetricRegistry;
+import org.apache.ignite.internal.util.lang.GridAbsPredicate;
+import org.apache.ignite.spi.metric.IntMetric;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+import static org.apache.ignite.internal.processors.metric.GridMetricManager.CLIENT_METRICS;
+import static org.apache.ignite.ssl.SslContextFactory.DFLT_STORE_TYPE;
+
+/**
+ * Client listener metrics tests.
+ */
+public class ClientListenerMetricsTest extends GridCommonAbstractTest {
+    /**
+     * Check that valid connections and disconnections to the grid affect metrics.
+     */
+    @Test
+    public void testClientListenerMetricsAccept() throws Exception {
+        try (IgniteEx ignite = startGrid(0))
+        {
+            MetricRegistry mreg = ignite.context().metric().registry(CLIENT_METRICS);
+
+            checkConnectionsMetrics(mreg, 0, 0);
+
+            IgniteClient client0 = Ignition.startClient(getClientConfiguration());
+
+            checkConnectionsMetrics(mreg, 1, 1);
+
+            client0.close();
+
+            checkConnectionsMetrics(mreg, 1, 0);
+
+            IgniteClient client1 = Ignition.startClient(getClientConfiguration());
+
+            checkConnectionsMetrics(mreg, 2, 1);
+
+            IgniteClient client2 = Ignition.startClient(getClientConfiguration());
+
+            checkConnectionsMetrics(mreg, 3, 2);
+
+            client1.close();
+
+            checkConnectionsMetrics(mreg, 3, 1);
+
+            client2.close();
+
+            checkConnectionsMetrics(mreg, 3, 0);
+        }
+    }
+
+    /**
+     * Check that failed connection attempts to the grid affect metrics.
+     */
+    @Test
+    public void testClientListenerMetricsReject() throws Exception {
+        cleanPersistenceDir();
+
+        IgniteConfiguration nodeCfg = getConfiguration()
+            .setClientConnectorConfiguration(new ClientConnectorConfiguration()
+                .setHandshakeTimeout(2000))
+            .setAuthenticationEnabled(true)
+            .setDataStorageConfiguration(new DataStorageConfiguration()
+                .setDefaultDataRegionConfiguration(new DataRegionConfiguration()
+                    .setPersistenceEnabled(true)));
+
+        try (IgniteEx ignite = startGrid(nodeCfg))
+        {
+            ignite.cluster().state(ClusterState.ACTIVE);
+            MetricRegistry mreg = ignite.context().metric().registry(CLIENT_METRICS);
+
+            checkRejectMetrics(mreg, 0, 0, 0);
+
+            ClientConfiguration cfgSsl = getClientConfiguration()
+                .setSslMode(SslMode.REQUIRED)
+                .setSslClientCertificateKeyStorePath(GridTestUtils.keyStorePath("client"))
+                .setSslClientCertificateKeyStoreType(DFLT_STORE_TYPE)
+                .setSslClientCertificateKeyStorePassword("123456")
+                .setSslTrustCertificateKeyStorePath(GridTestUtils.keyStorePath("trustone"))
+                .setSslTrustCertificateKeyStoreType(DFLT_STORE_TYPE)
+                .setSslTrustCertificateKeyStorePassword("123456");
+
+            try {
+                Ignition.startClient(cfgSsl);
+
+                fail("Should be rejected.");

Review comment:
       Can we use `assertThrows` instead of catching exceptions?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org