Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ public enum WriterMetrics implements MeasurementSet {

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

/** This metric indicates that the writer file creation was skipped. */
WRITER_FILE_CREATION_SKIPPED(
"WriterFileCreationSkipped", "count", Arrays.asList(Statistics.COUNT)),

METRICS_WRITE_ERROR(
"MetricsWriteError",
"namedCount",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,11 @@ public void writeTmpFile(List<Event> dataEntries, long epoch) {
* data.
*
* <p>If any of the above steps fail, then the tmp file is not deleted from the filesystem. This
* is fine as the {@link org.opensearch.performanceanalyzer.reader_writer_shared.EventLogFileHandler#deleteFiles},
* will eventually clean it. The copies are atomic and therefore the reader never reads incompletely written file.
* is fine as the {@link
* org.opensearch.performanceanalyzer.reader_writer_shared.EventLogFileHandler#deleteFiles},
* will eventually clean it. The copies are atomic and therefore the reader never reads
* incompletely written file.
*
* @param dataEntries The metrics to be written to file.
* @param epoch The epoch all the metrics belong to.
*/
Expand Down Expand Up @@ -116,11 +119,19 @@ public void renameFromTmp(long epoch) {
public void renameFromTmpWithPrivilege(long epoch) {
Path path = Paths.get(metricsLocation, String.valueOf(epoch));
Path tmpPath = Paths.get(path.toString() + TMP_FILE_EXT);
// This is done only when no exception is thrown.
try {
Files.move(tmpPath, path, REPLACE_EXISTING, ATOMIC_MOVE);
} catch (IOException e) {
LOG.error("Error moving file {} to {}.", tmpPath.toString(), path.toString(), e);
File tempFile = new File(tmpPath.toString());
// Only if the tmp file is present, we want to create the writer file.
// If not, we will publish a metric.
if (tempFile.exists()) {
// This is done only when no exception is thrown.
try {
Files.move(tmpPath, path, REPLACE_EXISTING, ATOMIC_MOVE);
} catch (IOException e) {
LOG.error("Error moving file {} to {}.", tmpPath.toString(), path.toString(), e);
}
} else {
PerformanceAnalyzerApp.WRITER_METRICS_AGGREGATOR.updateStat(
WriterMetrics.WRITER_FILE_CREATION_SKIPPED, "", 1);
}
}

Expand All @@ -134,7 +145,7 @@ public void read(long timestamp, EventDispatcher processor) {
File tempFile = new File(pathToFile.toString());
if (!tempFile.exists()) {
long mCurrT = System.currentTimeMillis();
LOG.info("Didnt find {} at {}", filename, mCurrT);
LOG.debug("Didnt find {} at {}", filename, mCurrT);
return;
}
readInternal(pathToFile, BUFFER_SIZE, processor);
Expand Down