Add optional logging for mismatches

This commit is contained in:
Chris Eager 2021-05-18 14:21:29 -05:00 committed by Chris Eager
parent aa65d34c36
commit bacf524ae6
2 changed files with 21 additions and 7 deletions

View File

@ -20,6 +20,9 @@ public class DynamicAccountsDynamoDbMigrationConfiguration {
@JsonProperty @JsonProperty
boolean readEnabled; boolean readEnabled;
@JsonProperty
boolean logMismatches;
public boolean isBackgroundMigrationEnabled() { public boolean isBackgroundMigrationEnabled() {
return backgroundMigrationEnabled; return backgroundMigrationEnabled;
} }
@ -52,4 +55,8 @@ public class DynamicAccountsDynamoDbMigrationConfiguration {
public boolean isReadEnabled() { public boolean isReadEnabled() {
return readEnabled; return readEnabled;
} }
public boolean isLogMismatches() {
return logMismatches;
}
} }

View File

@ -498,7 +498,7 @@ public class AccountsManager {
try { try {
final T dynamoResult = callable.call(); final T dynamoResult = callable.call();
compare(databaseResult, dynamoResult, mismatchClassifier, action); compare(databaseResult, dynamoResult, mismatchClassifier, action, maybeUuid);
} catch (final Exception e) { } catch (final Exception e) {
logger.error("Error running " + action + " in Dynamo", e); logger.error("Error running " + action + " in Dynamo", e);
@ -507,16 +507,23 @@ public class AccountsManager {
} }
} }
private <T> void compare(final T databaseResult, final T dynamoResult, final BiFunction<T, T, Optional<String>> mismatchClassifier, final String action) { @SuppressWarnings("OptionalUsedAsFieldOrParameterType")
private <T> void compare(final T databaseResult, final T dynamoResult, final BiFunction<T, T, Optional<String>> mismatchClassifier, final String action, final Optional<UUID> maybeUUid) {
DYNAMO_MIGRATION_COMPARISON_COUNTER.increment(); DYNAMO_MIGRATION_COMPARISON_COUNTER.increment();
mismatchClassifier.apply(databaseResult, dynamoResult) mismatchClassifier.apply(databaseResult, dynamoResult)
.ifPresent(mismatchType -> .ifPresent(mismatchType -> {
final String mismatchDescription = action + ":" + mismatchType;
Metrics.counter(DYNAMO_MIGRATION_MISMATCH_COUNTER_NAME, Metrics.counter(DYNAMO_MIGRATION_MISMATCH_COUNTER_NAME,
"mismatchType", action + ":" + mismatchType) "mismatchType", mismatchDescription)
.increment() .increment();
);
if (maybeUUid.isPresent()
&& dynamicConfigurationManager.getConfiguration().getAccountsDynamoDbMigrationConfiguration().isLogMismatches()) {
logger.info("Mismatched {} for {}", mismatchDescription, maybeUUid.get());
}
});
} }
private static abstract class AccountComparisonMixin extends Account { private static abstract class AccountComparisonMixin extends Account {