@Override public void eventOccurred(ResponseReceivedEvent eventArg) { RequestResult currentResult = operationContext.getLastResult(); int statusCode = currentResult.getStatusCode(); // Check if it's a client-side error: a 4xx status // We exclude 404 because it happens frequently during the normal // course of operation (each call to exists() would generate that // if it's not found). if (statusCode >= HTTP_BAD_REQUEST && statusCode < HTTP_INTERNAL_ERROR && statusCode != HTTP_NOT_FOUND) { instrumentation.clientErrorEncountered(); } else if (statusCode >= HTTP_INTERNAL_ERROR) { // It's a server error: a 5xx status. Could be an Azure Storage // bug or (more likely) throttling. instrumentation.serverErrorEncountered(); } } }
/** * Update the metrics source gauge for what the current transfer rate * is. * @param updateWrite If true, update the write (upload) counter. * Otherwise update the read (download) counter. * @param bytesPerSecond The number of bytes per second we're seeing. */ private void updateBytesTransferRate(boolean updateWrite, long bytesPerSecond) { if (updateWrite) { instrumentation.currentUploadBytesPerSecond(bytesPerSecond); } else { instrumentation.currentDownloadBytesPerSecond(bytesPerSecond); } }
/** * Delete the specified file or directory and increment metrics. * If the file or directory does not exist, the operation returns false. * @param path the path to a file or directory. * @param isDir true if the path is a directory; otherwise false. * @return true if delete is successful; otherwise false. * @throws IOException if an IO error occurs while attempting to delete the * path. * */ @VisibleForTesting boolean deleteFile(String path, boolean isDir) throws IOException { if (!store.delete(path)) { return false; } if (isDir) { instrumentation.directoryDeleted(); } else { instrumentation.fileDeleted(); } return true; }
instrumentation.webResponse(); if (!(eventArg.getConnectionObject() instanceof HttpURLConnection)) { currentResult.getStopDate(), length); instrumentation.rawBytesUploaded(length); instrumentation.blockUploaded(requestLatency); currentResult.getStopDate(), length); instrumentation.rawBytesDownloaded(length); instrumentation.blockDownloaded(requestLatency);
instrumentation = new AzureFileSystemInstrumentation(conf); if(!conf.getBoolean(SKIP_AZURE_METRICS_PROPERTY_NAME, false)) {
instrumentation.directoryCreated();
instrumentation.fileCreated();
instrumentation.fileDeleted(); } else { return false;
instrumentation.webResponse(); if (!(eventArg.getConnectionObject() instanceof HttpURLConnection)) { currentResult.getStopDate(), length); instrumentation.rawBytesUploaded(length); instrumentation.blockUploaded(requestLatency); currentResult.getStopDate(), length); instrumentation.rawBytesDownloaded(length); instrumentation.blockDownloaded(requestLatency);
instrumentation = new AzureFileSystemInstrumentation(conf); if(!conf.getBoolean(SKIP_AZURE_METRICS_PROPERTY_NAME, false)) {
instrumentation.directoryCreated();
instrumentation.fileCreated();
instrumentation.fileDeleted(); } else { return false;
@Test public void testMultiThreaded() throws Exception { final AzureFileSystemInstrumentation instrumentation = new AzureFileSystemInstrumentation(new Configuration()); final BandwidthGaugeUpdater updater = new BandwidthGaugeUpdater(instrumentation, 1000, true); Thread[] threads = new Thread[10]; for (int i = 0; i < threads.length; i++) { threads[i] = new Thread(new Runnable() { @Override public void run() { updater.blockDownloaded(new Date(), new Date(), 10); updater.blockDownloaded(new Date(0), new Date(0), 10); } }); } for (Thread t : threads) { t.start(); } for (Thread t : threads) { t.join(); } updater.triggerUpdate(false); assertEquals(10 * threads.length, AzureMetricsTestUtil.getCurrentBytesRead(instrumentation)); updater.close(); } }
/** * Update the metrics source gauge for what the current transfer rate * is. * @param updateWrite If true, update the write (upload) counter. * Otherwise update the read (download) counter. * @param bytesPerSecond The number of bytes per second we're seeing. */ private void updateBytesTransferRate(boolean updateWrite, long bytesPerSecond) { if (updateWrite) { instrumentation.currentUploadBytesPerSecond(bytesPerSecond); } else { instrumentation.currentDownloadBytesPerSecond(bytesPerSecond); } }
@Override public void eventOccurred(ResponseReceivedEvent eventArg) { RequestResult currentResult = operationContext.getLastResult(); int statusCode = currentResult.getStatusCode(); // Check if it's a client-side error: a 4xx status // We exclude 404 because it happens frequently during the normal // course of operation (each call to exists() would generate that // if it's not found). if (statusCode >= HTTP_BAD_REQUEST && statusCode < HTTP_INTERNAL_ERROR && statusCode != HTTP_NOT_FOUND) { instrumentation.clientErrorEncountered(); } else if (statusCode >= HTTP_INTERNAL_ERROR) { // It's a server error: a 5xx status. Could be an Azure Storage // bug or (more likely) throttling. instrumentation.serverErrorEncountered(); } } }
instrumentation.fileDeleted(); } else { if (!p.isDir()) { store.delete(key + suffix); instrumentation.fileDeleted(); } else { instrumentation.directoryDeleted();
@Test public void testMultiThreaded() throws Exception { final AzureFileSystemInstrumentation instrumentation = new AzureFileSystemInstrumentation(new Configuration()); final BandwidthGaugeUpdater updater = new BandwidthGaugeUpdater(instrumentation, 1000, true); Thread[] threads = new Thread[10]; for (int i = 0; i < threads.length; i++) { threads[i] = new Thread(new Runnable() { @Override public void run() { updater.blockDownloaded(new Date(), new Date(), 10); updater.blockDownloaded(new Date(0), new Date(0), 10); } }); } for (Thread t : threads) { t.start(); } for (Thread t : threads) { t.join(); } updater.triggerUpdate(false); assertEquals(10 * threads.length, AzureMetricsTestUtil.getCurrentBytesRead(instrumentation)); updater.close(); } }
@Test public void testSingleThreaded() throws Exception { AzureFileSystemInstrumentation instrumentation = new AzureFileSystemInstrumentation(new Configuration()); BandwidthGaugeUpdater updater = new BandwidthGaugeUpdater(instrumentation, 1000, true); updater.triggerUpdate(true); assertEquals(0, AzureMetricsTestUtil.getCurrentBytesWritten(instrumentation)); updater.blockUploaded(new Date(), new Date(), 150); updater.triggerUpdate(true); assertEquals(150, AzureMetricsTestUtil.getCurrentBytesWritten(instrumentation)); updater.blockUploaded(new Date(new Date().getTime() - 10000), new Date(), 200); updater.triggerUpdate(true); long currentBytes = AzureMetricsTestUtil.getCurrentBytesWritten(instrumentation); assertTrue( "We expect around (200/10 = 20) bytes written as the gauge value." + "Got " + currentBytes, currentBytes > 18 && currentBytes < 22); updater.close(); }
@Test public void testSingleThreaded() throws Exception { AzureFileSystemInstrumentation instrumentation = new AzureFileSystemInstrumentation(new Configuration()); BandwidthGaugeUpdater updater = new BandwidthGaugeUpdater(instrumentation, 1000, true); updater.triggerUpdate(true); assertEquals(0, AzureMetricsTestUtil.getCurrentBytesWritten(instrumentation)); updater.blockUploaded(new Date(), new Date(), 150); updater.triggerUpdate(true); assertEquals(150, AzureMetricsTestUtil.getCurrentBytesWritten(instrumentation)); updater.blockUploaded(new Date(new Date().getTime() - 10000), new Date(), 200); updater.triggerUpdate(true); long currentBytes = AzureMetricsTestUtil.getCurrentBytesWritten(instrumentation); assertTrue( "We expect around (200/10 = 20) bytes written as the gauge value." + "Got " + currentBytes, currentBytes > 18 && currentBytes < 22); updater.close(); }