Skip to content

Commit

Permalink
Moving METRICS_WRITE_ERROR metric to Named Counter, updating deleteFi…
Browse files Browse the repository at this point in the history
…les() signature
  • Loading branch information
khushbr committed Jul 12, 2021
1 parent 23f67e4 commit fe9601e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public static void addMetricEntry(StringBuilder value, String metricKey, long me
private static void emitMetric(BlockingQueue<Event> q, Event entry) {
if (!q.offer(entry)) {
PerformanceAnalyzerApp.WRITER_METRICS_AGGREGATOR.updateStat(
WriterMetrics.METRICS_WRITE_ERROR, "", 1);
WriterMetrics.METRICS_WRITE_ERROR, entry.key, 1);
LOG.debug("Could not enter metric {}", entry);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ public enum WriterMetrics implements MeasurementSet {

STALE_METRICS("StaleMetrics", "count", Arrays.asList(Statistics.COUNT)),

METRICS_WRITE_ERROR("MetricsWriteError", "count", Arrays.asList(Statistics.COUNT)),
METRICS_WRITE_ERROR(
"MetricsWriteError",
"namedCount",
Collections.singletonList(Statistics.NAMED_COUNTERS)),

METRICS_REMOVE_ERROR("MetricsRemoveError", "count", Arrays.asList(Statistics.COUNT)),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;

import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.Buffer;
Expand All @@ -39,6 +40,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.Arrays;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -170,23 +172,27 @@ private void readInternal(Path pathToFile, int bufferSize, EventDispatcher proce
}
}

public void deleteFiles(long referenceTime, int purgeInterval) {
public void deleteAllFiles() {
LOG.debug("Cleaning up any leftover files.");
File root = new File(metricsLocation);
// Filter out '.tmp' files, we do not want to delete currBucket .tmp files
String[] filesToDelete = root.list((dir, name) -> !name.endsWith(TMP_FILE_EXT));
deleteFiles(Arrays.asList(filesToDelete));
}

public void deleteFiles(List<String> filesToDelete) {
LOG.debug("Starting to delete old writer files");
long startTime = System.currentTimeMillis();

File root = new File(metricsLocation);
String[] children = root.list();
if (children == null) {
if (filesToDelete == null) {
return;
}
int filesDeletedCount = 0;
for (String child : children) {
File fileToDelete = new File(root, child);
if (fileToDelete.lastModified()
< PerformanceAnalyzerMetrics.getTimeInterval(referenceTime - purgeInterval)) {
PerformanceAnalyzerMetrics.removeMetrics(fileToDelete);
filesDeletedCount += 1;
}
File root = new File(metricsLocation);
for (String fileToDelete : filesToDelete) {
File file = new File(root, fileToDelete);
PerformanceAnalyzerMetrics.removeMetrics(file);
filesDeletedCount += 1;
}
long duration = System.currentTimeMillis() - startTime;
PerformanceAnalyzerApp.WRITER_METRICS_AGGREGATOR.updateStat(
Expand Down

0 comments on commit fe9601e

Please sign in to comment.