public virtual void TearDown() { MetricsSource source = DefaultMetricsSystem.Instance().GetSource("UgiMetrics"); if (source != null) { // Run only once since the UGI metrics is cleaned up during teardown MetricsRecordBuilder rb = MetricsAsserts.GetMetrics(source); MetricsAsserts.AssertQuantileGauges("GetGroups1s", rb); } cluster.Shutdown(); }
/// <exception cref="System.Exception"/> private static void VerifyGroupMetrics(long groups) { MetricsRecordBuilder rb = MetricsAsserts.GetMetrics("UgiMetrics"); if (groups > 0) { MetricsAsserts.AssertCounterGt("GetGroupsNumOps", groups - 1, rb); double avg = MetricsAsserts.GetDoubleGauge("GetGroupsAvgTime", rb); Assert.True(avg >= 0.0); // Sleep for an interval+slop to let the percentiles rollover Thread.Sleep((PercentilesInterval + 1) * 1000); // Check that the percentiles were updated MetricsAsserts.AssertQuantileGauges("GetGroups1s", rb); } }
public virtual void TestSyncAndBlockReportMetric() { MetricsRecordBuilder rb = MetricsAsserts.GetMetrics(NnMetrics); // We have one sync when the cluster starts up, just opening the journal MetricsAsserts.AssertCounter("SyncsNumOps", 1L, rb); // Each datanode reports in when the cluster comes up MetricsAsserts.AssertCounter("BlockReportNumOps", (long)DatanodeCount * cluster.GetStoragesPerDatanode (), rb); // Sleep for an interval+slop to let the percentiles rollover Sharpen.Thread.Sleep((PercentilesInterval + 1) * 1000); // Check that the percentiles were updated MetricsAsserts.AssertQuantileGauges("Syncs1s", rb); MetricsAsserts.AssertQuantileGauges("BlockReport1s", rb); }
public virtual void TestReceivePacketMetrics() { Configuration conf = new HdfsConfiguration(); int interval = 1; conf.Set(DFSConfigKeys.DfsMetricsPercentilesIntervalsKey, string.Empty + interval ); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).Build(); try { cluster.WaitActive(); DistributedFileSystem fs = cluster.GetFileSystem(); Path testFile = new Path("/testFlushNanosMetric.txt"); FSDataOutputStream fout = fs.Create(testFile); fout.Write(new byte[1]); fout.Hsync(); fout.Close(); IList <DataNode> datanodes = cluster.GetDataNodes(); DataNode datanode = datanodes[0]; MetricsRecordBuilder dnMetrics = MetricsAsserts.GetMetrics(datanode.GetMetrics(). Name()); // Expect two flushes, 1 for the flush that occurs after writing, // 1 that occurs on closing the data and metadata files. MetricsAsserts.AssertCounter("FlushNanosNumOps", 2L, dnMetrics); // Expect two syncs, one from the hsync, one on close. MetricsAsserts.AssertCounter("FsyncNanosNumOps", 2L, dnMetrics); // Wait for at least 1 rollover Sharpen.Thread.Sleep((interval + 1) * 1000); // Check the receivePacket percentiles that should be non-zero string sec = interval + "s"; MetricsAsserts.AssertQuantileGauges("FlushNanos" + sec, dnMetrics); MetricsAsserts.AssertQuantileGauges("FsyncNanos" + sec, dnMetrics); } finally { if (cluster != null) { cluster.Shutdown(); } } }
public virtual void TestSendDataPacketMetrics() { Configuration conf = new HdfsConfiguration(); int interval = 1; conf.Set(DFSConfigKeys.DfsMetricsPercentilesIntervalsKey, string.Empty + interval ); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).Build(); try { FileSystem fs = cluster.GetFileSystem(); // Create and read a 1 byte file Path tmpfile = new Path("/tmp.txt"); DFSTestUtil.CreateFile(fs, tmpfile, (long)1, (short)1, 1L); DFSTestUtil.ReadFile(fs, tmpfile); IList <DataNode> datanodes = cluster.GetDataNodes(); NUnit.Framework.Assert.AreEqual(datanodes.Count, 1); DataNode datanode = datanodes[0]; MetricsRecordBuilder rb = MetricsAsserts.GetMetrics(datanode.GetMetrics().Name()); // Expect 2 packets, 1 for the 1 byte read, 1 for the empty packet // signaling the end of the block MetricsAsserts.AssertCounter("SendDataPacketTransferNanosNumOps", (long)2, rb); MetricsAsserts.AssertCounter("SendDataPacketBlockedOnNetworkNanosNumOps", (long)2 , rb); // Wait for at least 1 rollover Sharpen.Thread.Sleep((interval + 1) * 1000); // Check that the sendPacket percentiles rolled to non-zero values string sec = interval + "s"; MetricsAsserts.AssertQuantileGauges("SendDataPacketBlockedOnNetworkNanos" + sec, rb); MetricsAsserts.AssertQuantileGauges("SendDataPacketTransferNanos" + sec, rb); } finally { if (cluster != null) { cluster.Shutdown(); } } }
public virtual void TestRpcMetrics() { Configuration configuration = new Configuration(); int interval = 1; configuration.SetBoolean(CommonConfigurationKeys.RpcMetricsQuantileEnable, true); configuration.Set(CommonConfigurationKeys.RpcMetricsPercentilesIntervalsKey, string.Empty + interval); Server server = new RPC.Builder(configuration).SetProtocol(typeof(TestRPC.TestProtocol )).SetInstance(new TestRPC.TestImpl()).SetBindAddress(Address).SetPort(0).SetNumHandlers (5).SetVerbose(true).Build(); server.Start(); TestRPC.TestProtocol proxy = RPC.GetProxy <TestRPC.TestProtocol>(TestRPC.TestProtocol .versionID, server.GetListenerAddress(), configuration); try { for (int i = 0; i < 1000; i++) { proxy.Ping(); proxy.Echo(string.Empty + i); } MetricsRecordBuilder rpcMetrics = MetricsAsserts.GetMetrics(server.GetRpcMetrics( ).Name()); Assert.True("Expected non-zero rpc queue time", MetricsAsserts.GetLongCounter ("RpcQueueTimeNumOps", rpcMetrics) > 0); Assert.True("Expected non-zero rpc processing time", MetricsAsserts.GetLongCounter ("RpcProcessingTimeNumOps", rpcMetrics) > 0); MetricsAsserts.AssertQuantileGauges("RpcQueueTime" + interval + "s", rpcMetrics); MetricsAsserts.AssertQuantileGauges("RpcProcessingTime" + interval + "s", rpcMetrics ); } finally { if (proxy != null) { RPC.StopProxy(proxy); } server.Stop(); } }
public virtual void TestRoundTripAckMetric() { int datanodeCount = 2; int interval = 1; Configuration conf = new HdfsConfiguration(); conf.Set(DFSConfigKeys.DfsMetricsPercentilesIntervalsKey, string.Empty + interval ); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(datanodeCount ).Build(); try { cluster.WaitActive(); FileSystem fs = cluster.GetFileSystem(); // Open a file and get the head of the pipeline Path testFile = new Path("/testRoundTripAckMetric.txt"); FSDataOutputStream fsout = fs.Create(testFile, (short)datanodeCount); DFSOutputStream dout = (DFSOutputStream)fsout.GetWrappedStream(); // Slow down the writes to catch the write pipeline dout.SetChunksPerPacket(5); dout.SetArtificialSlowdown(3000); fsout.Write(new byte[10000]); DatanodeInfo[] pipeline = null; int count = 0; while (pipeline == null && count < 5) { pipeline = dout.GetPipeline(); System.Console.Out.WriteLine("Waiting for pipeline to be created."); Sharpen.Thread.Sleep(1000); count++; } // Get the head node that should be receiving downstream acks DatanodeInfo headInfo = pipeline[0]; DataNode headNode = null; foreach (DataNode datanode in cluster.GetDataNodes()) { if (datanode.GetDatanodeId().Equals(headInfo)) { headNode = datanode; break; } } NUnit.Framework.Assert.IsNotNull("Could not find the head of the datanode write pipeline" , headNode); // Close the file and wait for the metrics to rollover Sharpen.Thread.Sleep((interval + 1) * 1000); // Check the ack was received MetricsRecordBuilder dnMetrics = MetricsAsserts.GetMetrics(headNode.GetMetrics(). Name()); NUnit.Framework.Assert.IsTrue("Expected non-zero number of acks", MetricsAsserts.GetLongCounter ("PacketAckRoundTripTimeNanosNumOps", dnMetrics) > 0); MetricsAsserts.AssertQuantileGauges("PacketAckRoundTripTimeNanos" + interval + "s" , dnMetrics); } finally { if (cluster != null) { cluster.Shutdown(); } } }