mirror of
https://github.com/google/nomulus.git
synced 2025-05-28 16:30:12 +02:00
Log EppExceptions in EppController at INFO (vs FlowRunner at WARNING)
The logging for exceptions in FlowRunner - always at WARNING - has long been sub-optimal. For EppExceptions it's too aggressive/spammy to log at WARNING because it's generally not actionable - EppException gets properly thrown for all kinds of ordinary reasons (trying to create a resource when one already exists with that foreign key) and/or for client misbehavior that we can't control (sending bad parameter values, etc.). For non-EppException RuntimeExceptions, it's redundant with existing logging in EppController. This CL resolves this by removing that logging in FlowRunner entirely in favor of the EppController logging, where we're now logging EppExceptions at INFO in parallel with the existing logging of RuntimeExceptions at SEVERE. This has the benefit that we're now logging EppExceptions that come from FlowPicker (by way of EppExceptionInProviderException), which previously were unlogged. Note however that this does mean that in places where we run FlowRunner without EppController - exclusively test code as it stands today - we'd no longer be logging EppExceptions. If that seems like a loss, we could either reinstate logging there (at INFO) and just deal with redundant messages for most EppExceptions, or we could add it manually to places where we call FlowRunner.run() in tests and avoid the redundancy that way. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=154733365
This commit is contained in:
parent
11e7374c0f
commit
f640d765e8
6 changed files with 196 additions and 76 deletions
|
@ -16,6 +16,7 @@ package google.registry.flows;
|
|||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.TestDataHelper.loadFileWithSubstitutions;
|
||||
import static google.registry.testing.TestLogHandlerUtils.findFirstLogMessageByPrefix;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
|
@ -24,11 +25,9 @@ import static org.mockito.Mockito.verify;
|
|||
import com.google.appengine.api.users.User;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.testing.TestLogHandler;
|
||||
import google.registry.model.eppcommon.Trid;
|
||||
import google.registry.model.eppoutput.EppOutput.ResponseOrGreeting;
|
||||
|
@ -40,7 +39,6 @@ import google.registry.testing.FakeHttpSession;
|
|||
import google.registry.testing.Providers;
|
||||
import google.registry.testing.ShardableTestCase;
|
||||
import java.util.List;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
|
@ -129,7 +127,7 @@ public class FlowRunnerTest extends ShardableTestCase {
|
|||
@Test
|
||||
public void testRun_legacyLoggingStatement_basic() throws Exception {
|
||||
flowRunner.run(eppMetricBuilder);
|
||||
assertThat(Splitter.on("\n\t").split(findLogMessageByPrefix(handler, "EPP Command\n\t")))
|
||||
assertThat(Splitter.on("\n\t").split(findFirstLogMessageByPrefix(handler, "EPP Command\n\t")))
|
||||
.containsExactly(
|
||||
"server-456",
|
||||
"TheRegistrar",
|
||||
|
@ -148,7 +146,7 @@ public class FlowRunnerTest extends ShardableTestCase {
|
|||
flowRunner.sessionMetadata = new HttpSessionMetadata(new FakeHttpSession());
|
||||
flowRunner.sessionMetadata.setClientId("TheRegistrar");
|
||||
flowRunner.run(eppMetricBuilder);
|
||||
assertThat(Splitter.on("\n\t").split(findLogMessageByPrefix(handler, "EPP Command\n\t")))
|
||||
assertThat(Splitter.on("\n\t").split(findFirstLogMessageByPrefix(handler, "EPP Command\n\t")))
|
||||
.contains(
|
||||
"HttpSessionMetadata"
|
||||
+ "{clientId=TheRegistrar, failedLoginAttempts=0, serviceExtensionUris=}");
|
||||
|
@ -159,7 +157,7 @@ public class FlowRunnerTest extends ShardableTestCase {
|
|||
flowRunner.credentials =
|
||||
GaeUserCredentials.forTestingUser(new User("user@example.com", "authDomain"), false);
|
||||
flowRunner.run(eppMetricBuilder);
|
||||
assertThat(Splitter.on("\n\t").split(findLogMessageByPrefix(handler, "EPP Command\n\t")))
|
||||
assertThat(Splitter.on("\n\t").split(findFirstLogMessageByPrefix(handler, "EPP Command\n\t")))
|
||||
.contains("GaeUserCredentials{gaeUser=user@example.com, isAdmin=false}");
|
||||
}
|
||||
|
||||
|
@ -167,7 +165,7 @@ public class FlowRunnerTest extends ShardableTestCase {
|
|||
public void testRun_legacyLoggingStatement_tlsCredentials() throws Exception {
|
||||
flowRunner.credentials = new TlsCredentials("abc123def", Optional.of("127.0.0.1"), "sni");
|
||||
flowRunner.run(eppMetricBuilder);
|
||||
assertThat(Splitter.on("\n\t").split(findLogMessageByPrefix(handler, "EPP Command\n\t")))
|
||||
assertThat(Splitter.on("\n\t").split(findFirstLogMessageByPrefix(handler, "EPP Command\n\t")))
|
||||
.contains(
|
||||
"TlsCredentials{clientCertificateHash=abc123def, clientAddress=/127.0.0.1, sni=sni}");
|
||||
}
|
||||
|
@ -176,7 +174,7 @@ public class FlowRunnerTest extends ShardableTestCase {
|
|||
public void testRun_legacyLoggingStatement_dryRun() throws Exception {
|
||||
flowRunner.isDryRun = true;
|
||||
flowRunner.run(eppMetricBuilder);
|
||||
assertThat(Splitter.on("\n\t").split(findLogMessageByPrefix(handler, "EPP Command\n\t")))
|
||||
assertThat(Splitter.on("\n\t").split(findFirstLogMessageByPrefix(handler, "EPP Command\n\t")))
|
||||
.contains("DRY_RUN");
|
||||
}
|
||||
|
||||
|
@ -186,27 +184,10 @@ public class FlowRunnerTest extends ShardableTestCase {
|
|||
getClass(), "domain_create_prettyprinted.xml", ImmutableMap.<String, String>of());
|
||||
flowRunner.inputXmlBytes = domainCreateXml.getBytes(UTF_8);
|
||||
flowRunner.run(eppMetricBuilder);
|
||||
String logMessage = findLogMessageByPrefix(handler, "EPP Command\n\t");
|
||||
String logMessage = findFirstLogMessageByPrefix(handler, "EPP Command\n\t");
|
||||
List<String> lines = Splitter.on("\n\t").splitToList(logMessage);
|
||||
assertThat(lines.size()).named("number of lines in log message").isAtLeast(9);
|
||||
String xml = Joiner.on('\n').join(lines.subList(3, lines.size() - 3));
|
||||
assertThat(xml).isEqualTo(domainCreateXml);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the first log message stored in the handler that has the provided prefix, and return
|
||||
* that message with the prefix stripped off.
|
||||
*/
|
||||
private static String findLogMessageByPrefix(TestLogHandler handler, final String prefix) {
|
||||
return Iterables.find(
|
||||
handler.getStoredLogRecords(),
|
||||
new Predicate<LogRecord>() {
|
||||
@Override
|
||||
public boolean apply(LogRecord logRecord) {
|
||||
return logRecord.getMessage().startsWith(prefix);
|
||||
}
|
||||
})
|
||||
.getMessage()
|
||||
.replaceFirst("^" + prefix, "");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue