1
0
mirror of https://github.com/google/nomulus synced 2026-07-07 16:46:56 +00:00

Compare commits

...

3 Commits

Author SHA1 Message Date
Pavlo Tkach ab4bac05d1 Replace RegistryTestServerMain start address with ipv6 loopback (#2448) 2024-05-21 19:00:25 +00:00
Pavlo Tkach 8e22ce7c70 Add phone and fax number to console whois endpoint (#2447) 2024-05-20 20:32:23 +00:00
Lai Jiang d96a5547ce Store stack trace in a separate filed during logging (#2444)
For reasons unclear to me, if the stack trace is appended directly to
the message, the log entry will be lumped together with following logs
on GKE.

Also updated the GKE service account for Nomulus in the manifest so we
can use workload identity just for Nomulus, not other pods on the same
cluster.
2024-05-20 16:17:56 +00:00
7 changed files with 47 additions and 27 deletions
@@ -51,10 +51,12 @@ export const columns = [
columnDef: 'billingAccountMap',
header: 'Billing Accounts',
cell: (record: Registrar) =>
// @ts-ignore - completely legit line, but TS keeps complaining
`${Object.entries(record.billingAccountMap).reduce((acc, [key, val]) => {
return `${acc}${key}=${val}<br/>`;
}, '')}`,
`${Object.entries(record.billingAccountMap || {}).reduce(
(acc, [key, val]) => {
return `${acc}${key}=${val}<br/>`;
},
''
)}`,
},
{
columnDef: 'registryLockAllowed',
@@ -81,6 +81,8 @@ public class WhoisRegistrarFieldsAction extends ConsoleApiAction {
newRegistrar.setWhoisServer(providedRegistrar.getWhoisServer());
newRegistrar.setUrl(providedRegistrar.getUrl());
newRegistrar.setLocalizedAddress(providedRegistrar.getLocalizedAddress());
newRegistrar.setPhoneNumber(providedRegistrar.getPhoneNumber());
newRegistrar.setFaxNumber(providedRegistrar.getFaxNumber());
tm().put(newRegistrar.build());
consoleApiParams.response().setStatus(HttpStatusCodes.STATUS_CODE_OK);
}
@@ -53,7 +53,7 @@ public final class RegistryTestServerMain {
names = "--address",
description = "Listening address.",
validateWith = HostAndPortParameter.class)
private HostAndPort address = HostAndPort.fromString("[::]:8080");
private HostAndPort address = HostAndPort.fromString("[::1]:8080");
@Parameter(names = "--fixtures", description = "Fixtures to load into the DB.")
private List<Fixture> fixtures = ImmutableList.of(Fixture.BASIC);
@@ -105,6 +105,10 @@ public class WhoisRegistrarFieldsActionTest {
ImmutableMap.of(
"whoisServer",
"whois.nic.google",
"phoneNumber",
"+1.4155552671",
"faxNumber",
"+1.4155552672",
"url",
"\"https://newurl.example\"",
"localizedAddress",
@@ -118,10 +122,13 @@ public class WhoisRegistrarFieldsActionTest {
assertThat(newRegistrar.getWhoisServer()).isEqualTo("whois.nic.google");
assertThat(newRegistrar.getUrl()).isEqualTo("https://newurl.example");
assertThat(newRegistrar.getLocalizedAddress().toJsonMap()).isEqualTo(addressMap);
assertThat(newRegistrar.getPhoneNumber()).isEqualTo("+1.4155552671");
assertThat(newRegistrar.getFaxNumber()).isEqualTo("+1.4155552672");
// the non-changed fields should be the same
assertAboutImmutableObjects()
.that(newRegistrar)
.isEqualExceptFields(oldRegistrar, "whoisServer", "url", "localizedAddress");
.isEqualExceptFields(
oldRegistrar, "whoisServer", "url", "localizedAddress", "phoneNumber", "faxNumber");
}
@Test
+1
View File
@@ -13,6 +13,7 @@ spec:
labels:
app: nomulus
spec:
serviceAccountName: nomulus
containers:
- name: nomulus
image: gcr.io/GCP_PROJECT/nomulus
@@ -57,6 +57,16 @@ public class GcpJsonFormatter extends Formatter {
/** JSON field that contains the content, this will show up as the main entry in a log. */
private static final String MESSAGE = "message";
/**
* JSON field that contains the stack trace, if any.
*
* <p>Note that this field is not part of the structured logging that stackdriver understands.
* Normally we'd just append the stack trace to the message itself. However, for unclear reasons,
* if we do that on GKE, the log entry containing a stack trace will be lumped together with
* several following log entries and makes it hard to read.
*/
private static final String STACKTRACE = "stacktrace";
private static final String FILE = "file";
private static final String FUNCTION = "function";
@@ -99,16 +109,17 @@ public class GcpJsonFormatter extends Formatter {
String severity = severityFor(record.getLevel());
// The rest is mostly lifted from java.util.logging.SimpleFormatter.
String stacktrace = "";
String throwable = "";
if (record.getThrown() != null) {
StringWriter sw = new StringWriter();
try (PrintWriter pw = new PrintWriter(sw)) {
pw.println();
record.getThrown().printStackTrace(pw);
}
stacktrace = sw.toString();
PrintWriter pw = new PrintWriter(sw);
pw.println();
record.getThrown().printStackTrace(pw);
pw.close();
throwable = sw.toString();
}
String message = '\n' + record.getMessage() + stacktrace;
String message = '\n' + formatMessage(record);
String function = "";
if (record.getSourceClassName() != null) {
@@ -144,6 +155,9 @@ public class GcpJsonFormatter extends Formatter {
json.put(SEVERITY, severity);
json.put(SOURCE_LOCATION, sourceLocation);
json.put(MESSAGE, message);
if (!throwable.isEmpty()) {
json.put(STACKTRACE, throwable);
}
if (traceId.get() != null) {
json.put(TRACE, traceId.get());
}
@@ -109,14 +109,11 @@ class GcpJsonFormatterTest {
handler.close();
String output = ostream.toString(StandardCharsets.US_ASCII);
String prefix =
makeJson(
"ERROR",
108,
"testSuccess_withCause",
"Something went terribly wrong\\njava.lang.RuntimeException: boom!");
// Remove the last three characters (", }, \n) from the template as the actual output contains
makeJson("ERROR", 108, "testSuccess_withCause", "Something went terribly wrong");
// Remove the last two characters (}, \n) from the template as the actual output contains
// the full stack trace.
prefix = prefix.substring(0, prefix.length() - 3);
prefix = prefix.substring(0, prefix.length() - 2);
prefix += ",\"stacktrace\":\"\\njava.lang.RuntimeException: boom!\\n";
assertThat(output).startsWith(prefix);
}
@@ -126,14 +123,11 @@ class GcpJsonFormatterTest {
handler.close();
String output = ostream.toString(StandardCharsets.US_ASCII);
String prefix =
makeJson(
"ERROR",
125,
"testSuccess_withStackTrace",
"Something is worth checking\\ncom.google.common.flogger.LogSiteStackTrace: FULL");
// Remove the last three characters (", }, \n) from the template as the actual output contains
makeJson("ERROR", 122, "testSuccess_withStackTrace", "Something is worth checking");
// Remove the last three characters (}, \n) from the template as the actual output contains
// the full stack trace.
prefix = prefix.substring(0, prefix.length() - 3);
prefix = prefix.substring(0, prefix.length() - 2);
prefix += ",\"stacktrace\":\"\\ncom.google.common.flogger.LogSiteStackTrace: FULL\\n";
assertThat(output).startsWith(prefix);
}