MetricsHBaseServer mrpc = new MetricsHBaseServer("HMaster", new MetricsHBaseServerWrapperStub()); MetricsHBaseServerSource serverSource = mrpc.getMetricsSource(); mrpc.authenticationFailure(); mrpc.authenticationSuccess(); mrpc.authorizationSuccess(); mrpc.authorizationFailure(); mrpc.dequeuedCall(100); mrpc.processedCall(101); mrpc.totalCall(102); HELPER.assertCounter("queueCallTime_NumOps", 1, serverSource); HELPER.assertCounter("processCallTime_NumOps", 1, serverSource); HELPER.assertCounter("totalCallTime_NumOps", 1, serverSource); mrpc.sentBytes(103); mrpc.sentBytes(103); mrpc.sentBytes(103); mrpc.receivedBytes(104); mrpc.receivedBytes(104); mrpc.receivedRequest(105); mrpc.sentResponse(106); HELPER.assertCounter("requestSize_NumOps", 1, serverSource); HELPER.assertCounter("responseSize_NumOps", 1, serverSource);
@Before public void setupBasicMocks() throws IOException, ServiceException { rs = Mockito.mock(HRegionServer.class); rpcServices = Mockito.mock(RSRpcServices.class); rpcServer = Mockito.mock(RpcServerInterface.class); Mockito.doReturn(HBaseConfiguration.create()) .when(rs).getConfiguration(); Mockito.doReturn(rpcServices).when(rs).getRSRpcServices(); Mockito.doReturn(rpcServer).when(rs).getRpcServer(); Mockito.doReturn(fakeResponse).when(rpcServices).getServerInfo( (RpcController)Mockito.any(), (GetServerInfoRequest)Mockito.any()); // Fake ZKW ZKWatcher zkw = Mockito.mock(ZKWatcher.class); Mockito.doReturn("fakequorum").when(zkw).getQuorum(); Mockito.doReturn(zkw).when(rs).getZooKeeper(); // Fake BlockCache LOG.warn("The " + HConstants.HFILE_BLOCK_CACHE_SIZE_KEY + " is set to 0"); Mockito.doReturn(Optional.empty()).when(rs).getBlockCache(); // Fake MasterAddressTracker MasterAddressTracker mat = Mockito.mock(MasterAddressTracker.class); Mockito.doReturn(fakeMasterAddress).when(mat).getMasterAddress(); Mockito.doReturn(mat).when(rs).getMasterAddressTracker(); MetricsRegionServer rms = Mockito.mock(MetricsRegionServer.class); Mockito.doReturn(new MetricsRegionServerWrapperStub()).when(rms).getRegionServerWrapper(); Mockito.doReturn(rms).when(rs).getRegionServerMetrics(); MetricsHBaseServer ms = Mockito.mock(MetricsHBaseServer.class); Mockito.doReturn(new MetricsHBaseServerWrapperStub()).when(ms).getHBaseServerWrapper(); Mockito.doReturn(ms).when(rpcServer).getMetrics(); }
private boolean authorizeConnection() throws IOException { try { // If auth method is DIGEST, the token was obtained by the // real user for the effective user, therefore not required to // authorize real user. doAs is allowed only for simple or kerberos // authentication if (ugi != null && ugi.getRealUser() != null && (authMethod != AuthMethod.DIGEST)) { ProxyUsers.authorize(ugi, this.getHostAddress(), this.rpcServer.conf); } this.rpcServer.authorize(ugi, connectionHeader, getHostInetAddress()); this.rpcServer.metrics.authorizationSuccess(); } catch (AuthorizationException ae) { if (RpcServer.LOG.isDebugEnabled()) { RpcServer.LOG.debug("Connection authorization failed: " + ae.getMessage(), ae); } this.rpcServer.metrics.authorizationFailure(); doRespond(getErrorResponse(ae.getMessage(), new AccessDeniedException(ae))); return false; } return true; }
metrics.dequeuedCall(qTime); metrics.processedCall(processingTime); metrics.totalCall(totalTime); metrics.receivedRequest(requestSize); metrics.sentResponse(responseSize); metrics.exception(e);
@Test public void testFactory() { MetricsHBaseServer masterMetrics = new MetricsHBaseServer("HMaster", new MetricsHBaseServerWrapperStub()); MetricsHBaseServerSource masterSource = masterMetrics.getMetricsSource(); MetricsHBaseServer rsMetrics = new MetricsHBaseServer("HRegionServer", new MetricsHBaseServerWrapperStub()); MetricsHBaseServerSource rsSource = rsMetrics.getMetricsSource(); assertEquals("master", masterSource.getMetricsContext()); assertEquals("regionserver", rsSource.getMetricsContext()); assertEquals("Master,sub=IPC", masterSource.getMetricsJmxContext()); assertEquals("RegionServer,sub=IPC", rsSource.getMetricsJmxContext()); assertEquals("Master", masterSource.getMetricsName()); assertEquals("RegionServer", rsSource.getMetricsName()); }
private void failRegionAction(MultiResponse.Builder responseBuilder, RegionActionResult.Builder regionActionResultBuilder, RegionAction regionAction, CellScanner cellScanner, Throwable error) { rpcServer.getMetrics().exception(error); regionActionResultBuilder.setException(ResponseConverter.buildException(error)); responseBuilder.addRegionActionResult(regionActionResultBuilder.build()); // All Mutations in this RegionAction not executed as we can not see the Region online here // in this RS. Will be retried from Client. Skipping all the Cells in CellScanner // corresponding to these Mutations. if (cellScanner != null) { skipCellsForMutations(regionAction.getActionList(), cellScanner); } }
this.rpcServer.metrics.authenticationFailure(); String clientIP = this.toString(); ". Negotiated QoP is " + qop); this.rpcServer.metrics.authenticationSuccess(); RpcServer.AUDITLOG.info(RpcServer.AUTH_SUCCESSFUL_FOR + ugi); saslContextEstablished = true;
protected int channelDataRead(ReadableByteChannel channel, ByteBuff buf) throws IOException { int count = buf.read(channel); if (count > 0) { this.rpcServer.metrics.receivedBytes(count); } return count; }
this.maxRequestSize = conf.getInt(MAX_REQUEST_SIZE, DEFAULT_MAX_REQUEST_SIZE); this.metrics = new MetricsHBaseServer(name, new MetricsHBaseServerWrapperImpl(this)); this.tcpNoDelay = conf.getBoolean("hbase.ipc.server.tcpnodelay", true); this.tcpKeepAlive = conf.getBoolean("hbase.ipc.server.tcpkeepalive", true);
metrics.dequeuedCall(qTime); metrics.processedCall(processingTime); metrics.totalCall(totalTime); metrics.receivedRequest(requestSize); metrics.sentResponse(responseSize); metrics.exception(e);
@Test public void testServerContextNameWithHostName() { String[] masterServerNames = { "master/node-xyz/10.19.250.253:16020", "master/node-regionserver-xyz/10.19.250.253:16020", "HMaster/node-xyz/10.19.250.253:16020", "HMaster/node-regionserver-xyz/10.19.250.253:16020" }; String[] regionServerNames = { "regionserver/node-xyz/10.19.250.253:16020", "regionserver/node-master1-xyz/10.19.250.253:16020", "HRegionserver/node-xyz/10.19.250.253:16020", "HRegionserver/node-master1-xyz/10.19.250.253:16020" }; MetricsHBaseServerSource masterSource = null; for (String serverName : masterServerNames) { masterSource = new MetricsHBaseServer(serverName, new MetricsHBaseServerWrapperStub()) .getMetricsSource(); assertEquals("master", masterSource.getMetricsContext()); assertEquals("Master,sub=IPC", masterSource.getMetricsJmxContext()); assertEquals("Master", masterSource.getMetricsName()); } MetricsHBaseServerSource rsSource = null; for (String serverName : regionServerNames) { rsSource = new MetricsHBaseServer(serverName, new MetricsHBaseServerWrapperStub()) .getMetricsSource(); assertEquals("regionserver", rsSource.getMetricsContext()); assertEquals("RegionServer,sub=IPC", rsSource.getMetricsJmxContext()); assertEquals("RegionServer", rsSource.getMetricsName()); } } }
connection.rpcServer.reservoir, connection.rpcServer.cellBlockBuilder, null); connection.rpcServer.metrics.exception(SimpleRpcServer.REQUEST_TOO_BIG_EXCEPTION);
private boolean authorizeConnection() throws IOException { try { // If auth method is DIGEST, the token was obtained by the // real user for the effective user, therefore not required to // authorize real user. doAs is allowed only for simple or kerberos // authentication if (ugi != null && ugi.getRealUser() != null && (authMethod != AuthMethod.DIGEST)) { ProxyUsers.authorize(ugi, this.getHostAddress(), conf); } authorize(ugi, connectionHeader, getHostInetAddress()); metrics.authorizationSuccess(); } catch (AuthorizationException ae) { if (LOG.isDebugEnabled()) { LOG.debug("Connection authorization failed: " + ae.getMessage(), ae); } metrics.authorizationFailure(); setupResponse(authFailedResponse, authFailedCall, new AccessDeniedException(ae), ae.getMessage()); responder.doRespond(authFailedCall); return false; } return true; }
metrics.authenticationFailure(); String clientIP = this.toString(); + saslServer.getNegotiatedProperty(Sasl.QOP)); metrics.authenticationSuccess(); AUDITLOG.info(AUTH_SUCCESSFUL_FOR + ugi); saslContextEstablished = true;
/** * This is a wrapper around {@link java.nio.channels.ReadableByteChannel#read(java.nio.ByteBuffer)}. * If the amount of data is large, it writes to channel in smaller chunks. * This is to avoid jdk from creating many direct buffers as the size of * ByteBuffer increases. There should not be any performance degredation. * * @param channel writable byte channel to write on * @param buffer buffer to write * @return number of bytes written * @throws java.io.IOException e * @see java.nio.channels.ReadableByteChannel#read(java.nio.ByteBuffer) */ protected int channelRead(ReadableByteChannel channel, ByteBuffer buffer) throws IOException { int count = (buffer.remaining() <= NIO_BUFFER_LIMIT) ? channel.read(buffer) : channelIO(channel, null, buffer); if (count > 0) { metrics.receivedBytes(count); } return count; }
this.port = listener.getAddress().getPort(); this.metrics = new MetricsHBaseServer(name, new MetricsHBaseServerWrapperImpl(this)); this.tcpNoDelay = conf.getBoolean("hbase.ipc.server.tcpnodelay", true); this.tcpKeepAlive = conf.getBoolean("hbase.ipc.server.tcpkeepalive", true);
MetricsHBaseServer mrpc = new MetricsHBaseServer("HMaster", new MetricsHBaseServerWrapperStub()); MetricsHBaseServerSource serverSource = mrpc.getMetricsSource(); mrpc.authenticationFailure(); mrpc.authenticationSuccess(); mrpc.authorizationSuccess(); mrpc.authorizationFailure(); mrpc.dequeuedCall(100); mrpc.processedCall(101); mrpc.totalCall(102); HELPER.assertCounter("queueCallTime_NumOps", 1, serverSource); HELPER.assertCounter("processCallTime_NumOps", 1, serverSource); HELPER.assertCounter("totalCallTime_NumOps", 1, serverSource); mrpc.sentBytes(103); mrpc.sentBytes(103); mrpc.sentBytes(103); mrpc.receivedBytes(104); mrpc.receivedBytes(104); mrpc.receivedRequest(105); mrpc.sentResponse(106); HELPER.assertCounter("requestSize_NumOps", 1, serverSource); HELPER.assertCounter("responseSize_NumOps", 1, serverSource);
/** * This test makes sure that the numbers from a MetricsHBaseServerWrapper are correctly exported * to hadoop metrics 2 system. */ @Test public void testWrapperSource() { MetricsHBaseServer mrpc = new MetricsHBaseServer("HMaster", new MetricsHBaseServerWrapperStub()); MetricsHBaseServerSource serverSource = mrpc.getMetricsSource(); HELPER.assertGauge("queueSize", 101, serverSource); HELPER.assertGauge("numCallsInGeneralQueue", 102, serverSource); HELPER.assertGauge("numCallsInReplicationQueue", 103, serverSource); HELPER.assertGauge("numCallsInPriorityQueue", 104, serverSource); HELPER.assertGauge("numOpenConnections", 105, serverSource); HELPER.assertGauge("numActiveHandler", 106, serverSource); HELPER.assertGauge("numActiveGeneralHandler", 201, serverSource); HELPER.assertGauge("numActivePriorityHandler", 202, serverSource); HELPER.assertGauge("numActiveReplicationHandler", 203, serverSource); HELPER.assertGauge("numActiveWriteHandler", 50, serverSource); HELPER.assertGauge("numActiveReadHandler", 50, serverSource); HELPER.assertGauge("numActiveScanHandler", 6, serverSource); HELPER.assertGauge("numCallsInWriteQueue", 50, serverSource); HELPER.assertGauge("numCallsInReadQueue", 50, serverSource); HELPER.assertGauge("numCallsInScanQueue", 2, serverSource); }
null, null, null, this, 0, this.addr, System.currentTimeMillis(), 0, this.rpcServer.reservoir, this.rpcServer.cellBlockBuilder, null, responder); this.rpcServer.metrics.exception(SimpleRpcServer.REQUEST_TOO_BIG_EXCEPTION);
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { ByteBuf input = (ByteBuf) msg; // 4 bytes length field metrics.receivedBytes(input.readableBytes() + 4); connection.process(input); }