Skip to content

Commit

Permalink
OAK-10789 - Log paths used for inclusing/exclusion for Mongo regex fi…
Browse files Browse the repository at this point in the history
…lters in job summary (apache#1478)
  • Loading branch information
nfsantos authored May 23, 2024
1 parent 76c0d7e commit bd5a327
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -40,13 +41,14 @@ public class ConsoleIndexingReporter implements IndexingReporter {
private final Map<String, String> metrics = new TreeMap<>();
private final List<String> envVariablesToLog;
private List<String> indexes = List.of();
private final List<String> informationStrings = new ArrayList<>();

public ConsoleIndexingReporter() {
this(List.of());
}

/**
* @param envVariablesToLog These environment variables and their values will be included in the final report.
* @param envVariablesToLog These environment variables and their values will be included in the final report.
*/
public ConsoleIndexingReporter(@NotNull List<String> envVariablesToLog) {
this.envVariablesToLog = List.copyOf(envVariablesToLog);
Expand All @@ -68,6 +70,11 @@ public void addMetric(String name, long value) {
metrics.put(name, String.valueOf(value));
}

@Override
public void addInformation(String value) {
informationStrings.add(value);
}

public void addMetricByteSize(String name, long value) {
String v = String.valueOf(value);
if (value >= FileUtils.ONE_KB) {
Expand All @@ -82,6 +89,7 @@ public String generateReport() {
"OAK Version: " + OakVersion.getVersion() + "\n" +
"Configuration:\n" + mapToString(config) + "\n" +
"Environment Variables:\n" + genEnvVariables() + "\n" +
"Information:\n" + listToString(informationStrings) + "\n" +
"Timings:\n" + mapToString(timings) + "\n" +
"Metrics:\n" + mapToString(metrics);
}
Expand All @@ -95,7 +103,15 @@ private String genEnvVariables() {

private String mapToString(Map<String, String> map) {
return map.entrySet().stream()
.sorted(Map.Entry.comparingByKey())
.map(entry -> " " + entry.getKey() + ": " + entry.getValue())
.collect(Collectors.joining("\n"));
}

private String listToString(List<String> map) {
return map.stream()
.sorted()
.map(entry -> " " + entry)
.collect(Collectors.joining("\n"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public void addTiming(String stage, String time) {
public void addMetric(String name, long value) {
}

@Override
public void addInformation(String value) {
}

@Override
public void addMetricByteSize(String name, long value) {
}
Expand All @@ -59,6 +63,8 @@ public String generateReport() {

void addMetric(String name, long value);

void addInformation(String value);

/**
* Similar to {@link #addMetric(String, long)} but size should be logged in a human-friendly format, that is,
* something like
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

public class ConsoleIndexingReporterTest {

private static char DELIM = new DecimalFormatSymbols().getDecimalSeparator();
private static final char DELIM = new DecimalFormatSymbols().getDecimalSeparator();

@Test
public void emptyReport() {
Expand All @@ -38,6 +38,8 @@ public void emptyReport() {
"\n" +
"Environment Variables:\n" +
"\n" +
"Information:\n" +
"\n" +
"Timings:\n" +
"\n" +
"Metrics:\n";
Expand All @@ -59,6 +61,9 @@ public void fullReport() {
"Environment Variables:\n" +
" ENV_VAR1: <value>\n" +
" ENV_VAR2: <value>\n" +
"Information:\n" +
" A message\n" +
" Foo Bar\n" +
"Timings:\n" +
" stage1: 10:23\n" +
"Metrics:\n" +
Expand All @@ -80,6 +85,8 @@ public void fullReport() {

consoleIndexingReporter.addConfig("config1", "value1");
consoleIndexingReporter.addConfig("config2", 12);
consoleIndexingReporter.addInformation("Foo Bar");
consoleIndexingReporter.addInformation("A message");

consoleIndexingReporter.addTiming("stage1", "10:23");

Expand All @@ -97,7 +104,7 @@ private String replaceDate(String report) {
}

private String replaceVariable(String report, String varName) {
return report.replaceAll(" " + varName + ": .*", " " + varName + ": <value>");
return report.replaceAll(" {2}" + varName + ": .*", " " + varName + ": <value>");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public String toString() {
'}';
}

public String prettyPrint() {
return "{included=" + included + ", excluded=" + excluded + "}";
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down Expand Up @@ -136,7 +140,7 @@ public MongoFilterPaths buildMongoFilter(List<PathFilter> pathFilters, List<Stri
}

if (customExcludedPaths.stream().anyMatch(PathUtils::denotesRoot)) {
LOG.warn("Ignoring custom excluded paths setting, root cannot be excluded: {}", customExcludedPaths);
LOG.warn("Ignoring custom excluded paths setting, root cannot be excluded: {}", customExcludedPaths);
} else if (!isRootPath(finalIncludedPathsRoots)) {
LOG.info("Ignoring custom excluded paths because included paths did not resolve to root. Mongo filters: {}", finalIncludedPathsRoots);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ private Future<?> submitDownloadTask(ExecutorService executor, DownloadTask down
private MongoFilterPaths getPathsForRegexFiltering() {
if (!regexPathFiltering) {
LOG.info("Regex path filtering disabled.");
reporter.addInformation("Mongo regex filter paths: " + MongoFilterPaths.DOWNLOAD_ALL.prettyPrint());
return MongoFilterPaths.DOWNLOAD_ALL;
} else {
LOG.info("Computing included/excluded paths for Mongo regex path filtering. PathFilters: {}",
Expand All @@ -493,6 +494,7 @@ private MongoFilterPaths getPathsForRegexFiltering() {
);
MongoFilterPaths mongoFilterPaths = this.regexPathFilterFactory.buildMongoFilter(pathFilters, customExcludedPaths);
LOG.info("Paths used for regex filtering on Mongo: {}", mongoFilterPaths);
reporter.addInformation("Mongo regex filter paths: " + mongoFilterPaths.prettyPrint());
return mongoFilterPaths;
}
}
Expand Down

0 comments on commit bd5a327

Please sign in to comment.