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



##########
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:
       Implemented

##########
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:
       Done




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to