SslHandshakeFailedListener implements SslHandshakeListener { @Override public void handshakeFailed(Event event, Throwable throwable) { log.log(Level.FINE, throwable, () -> "Ssl handshake failed: " + throwable.getMessage()); String metricName = SslHandshakeFailure.fromSslHandshakeException((SSLHandshakeException) throwable) .map(SslHandshakeFailure::metricName) .orElse(Metrics.SSL_HANDSHAKE_FAILURE_UNKNOWN); metric.add(metricName, 1L, metric.createContext(createDimensions(event))); } SslHandshakeFailedListener(Metric metric, String connectorName, int listenPort); @Override void handshakeFailed(Event event, Throwable throwable);  }
@Test public void includes_client_ip_dimension_present_when_peer_available() { listener.handshakeFailed(handshakeEvent(true), new SSLHandshakeException("Empty server certificate chain")); verify(metrics).createContext(eq(Map.of("clientIp", "127.0.0.1", "serverName", "connector", "serverPort", 1234))); }
@Test public void does_not_include_client_ip_dimension_present_when_peer_unavailable() { listener.handshakeFailed(handshakeEvent(false), new SSLHandshakeException("Empty server certificate chain")); verify(metrics).createContext(eq(Map.of("serverName", "connector", "serverPort", 1234))); }