Skip to content

Commit 15ced70

Browse files
authored
Adding zk server metrics to track connections on unified client port. (#79)
* Adding ZK server metrics to idetify SSL vs non-SSL connections request to unified port Co-authored-by: Rahul Rane <[email protected]>
1 parent 9c904fa commit 15ced70

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

zookeeper-server/src/main/java/org/apache/zookeeper/server/NettyServerCnxnFactory.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ private void handleNonSsl(ChannelHandlerContext context) {
169169
@Override
170170
protected SslHandler newSslHandler(ChannelHandlerContext context, SslContext sslContext) {
171171
NettyServerCnxn cnxn = Objects.requireNonNull(context.channel().attr(CONNECTION_ATTRIBUTE).get());
172+
ServerMetrics.getMetrics().UNIFIED_PORT_SSL_REQUESTS.add(1);
172173
LOG.debug("creating ssl handler for session {}", cnxn.getSessionId());
173174
SslHandler handler = super.newSslHandler(context, sslContext);
174175
Future<Channel> handshakeFuture = handler.handshakeFuture();
@@ -179,6 +180,7 @@ protected SslHandler newSslHandler(ChannelHandlerContext context, SslContext ssl
179180
@Override
180181
protected ChannelHandler newNonSslHandler(ChannelHandlerContext context) {
181182
NettyServerCnxn cnxn = Objects.requireNonNull(context.channel().attr(CONNECTION_ATTRIBUTE).get());
183+
ServerMetrics.getMetrics().UNIFIED_PORT_NONSSL_REQUESTS.add(1);
182184
LOG.debug("creating plaintext handler for session {}", cnxn.getSessionId());
183185
// Mark handshake finished if it's a insecure cnxn
184186
updateHandshakeCountIfStarted(cnxn);
@@ -442,6 +444,7 @@ public void operationComplete(Future<Channel> future) {
442444
return;
443445
}
444446

447+
ServerMetrics.getMetrics().X509_AUTH_REQUESTS.add(1);
445448
KeeperException.Code code = KeeperException.Code.AUTHFAILED;
446449
if (authProvider != null) {
447450
code = authProvider.handleAuthentication(cnxn, null);

zookeeper-server/src/main/java/org/apache/zookeeper/server/ServerMetrics.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,11 @@ private ServerMetrics(MetricsProvider metricsProvider) {
229229
REQUEST_THROTTLE_WAIT_COUNT = metricsContext.getCounter("request_throttle_wait_count");
230230
LARGE_REQUESTS_REJECTED = metricsContext.getCounter("large_requests_rejected");
231231

232+
UNIFIED_PORT_NONSSL_REQUESTS = metricsContext.getCounter("unified_port_nonssl_requests");
233+
UNIFIED_PORT_SSL_REQUESTS = metricsContext.getCounter("unified_port_ssl_requests");
234+
X509_AUTH_REQUESTS = metricsContext.getCounter("x509_auth_requests");
235+
X509_ZNODEGROUPACL_AUTH_PROVDER_REQUESTS = metricsContext.getCounter("x509_ZNodeGroupACL_auth_requests");
236+
232237
NETTY_QUEUED_BUFFER = metricsContext.getSummary("netty_queued_buffer_capacity", DetailLevel.BASIC);
233238

234239
DIGEST_MISMATCHES_COUNT = metricsContext.getCounter("digest_mismatches_count");
@@ -444,6 +449,14 @@ private ServerMetrics(MetricsProvider metricsProvider) {
444449
public final Counter REQUEST_THROTTLE_WAIT_COUNT;
445450
public final Counter LARGE_REQUESTS_REJECTED;
446451

452+
/*
453+
* Client Auth requests for x509 based AuthenticationProviders through portUnification.
454+
*/
455+
public final Counter UNIFIED_PORT_NONSSL_REQUESTS;
456+
public final Counter UNIFIED_PORT_SSL_REQUESTS;
457+
public final Counter X509_AUTH_REQUESTS;
458+
public final Counter X509_ZNODEGROUPACL_AUTH_PROVDER_REQUESTS;
459+
447460
public final Summary NETTY_QUEUED_BUFFER;
448461

449462
// Total number of digest mismatches that are observed when applying

zookeeper-server/src/main/java/org/apache/zookeeper/server/auth/znode/groupacl/X509ZNodeGroupAclProvider.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
package org.apache.zookeeper.server.auth.znode.groupacl;
2020

21+
import org.apache.zookeeper.server.ServerMetrics;
2122
import java.util.Collections;
2223
import java.util.HashSet;
2324
import java.util.Set;
@@ -90,6 +91,7 @@ public X509ZNodeGroupAclProvider(X509TrustManager trustManager, X509KeyManager k
9091

9192
@Override
9293
public KeeperException.Code handleAuthentication(ServerObjs serverObjs, byte[] authData) {
94+
ServerMetrics.getMetrics().X509_ZNODEGROUPACL_AUTH_PROVDER_REQUESTS.add(1);
9395
// 1. Authenticate connection
9496
ServerCnxn cnxn = serverObjs.getCnxn();
9597
try {

0 commit comments

Comments
 (0)