diff options
author | Jon Marius Venstad <jvenstad@yahoo-inc.com> | 2018-08-27 09:47:04 +0200 |
---|---|---|
committer | Jon Marius Venstad <jvenstad@yahoo-inc.com> | 2018-08-27 09:47:13 +0200 |
commit | 29e4016ae5dcf47dc248b59e159fda7d473d204a (patch) | |
tree | 7c8da96318e4a2296a9084c40b7b732cce253f3b | |
parent | 73ed7ad7c3cbd41d5ca44c4f2f7ae547fe4c5abe (diff) |
Replace log entry levels with types
11 files changed, 88 insertions, 46 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/LogEntry.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/LogEntry.java index 026e9250cef..39e61a99b80 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/LogEntry.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/LogEntry.java @@ -4,7 +4,6 @@ import com.yahoo.log.LogLevel; import java.util.Objects; import java.util.logging.Level; -import java.util.logging.LogRecord; import static java.util.Objects.requireNonNull; @@ -13,16 +12,16 @@ public class LogEntry { private final long id; private final long at; - private final Level level; + private final Type type; private final String message; - public LogEntry(long id, long at, Level level, String message) { + public LogEntry(long id, long at, Type type, String message) { if (id < 0) throw new IllegalArgumentException("Id must be non-negative, but was " + id + "."); this.id = id; this.at = at; - this.level = LogLevel.getVespaLogLevel(requireNonNull(level)); + this.type = requireNonNull(type); this.message = requireNonNull(message); } @@ -34,8 +33,8 @@ public class LogEntry { return at; } - public Level level() { - return level; + public Type type() { + return type; } public String message() { @@ -47,7 +46,7 @@ public class LogEntry { return "LogEntry{" + "id=" + id + ", at=" + at + - ", level=" + level + + ", type=" + type + ", message='" + message + '\'' + '}'; } @@ -59,13 +58,25 @@ public class LogEntry { LogEntry entry = (LogEntry) o; return id == entry.id && at == entry.at && - Objects.equals(level, entry.level) && + type == entry.type && Objects.equals(message, entry.message); } @Override public int hashCode() { - return Objects.hash(id, at, level, message); + return Objects.hash(id, at, type, message); + } + + public static Type typeOf(Level level) { + return level.intValue() < LogLevel.INFO.intValue() ? Type.debug + : level.intValue() < LogLevel.WARNING.intValue() ? Type.info + : level.intValue() < LogLevel.ERROR.intValue() ? Type.warning + : Type.error; + } + + /** The type of entry, used for rendering. */ + public enum Type { + debug, info, warning, error, html; } } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/InternalStepRunner.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/InternalStepRunner.java index 054eabc0f21..a3c3461db3b 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/InternalStepRunner.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/InternalStepRunner.java @@ -223,6 +223,7 @@ public class InternalStepRunner implements StepRunner { } private Optional<RunStatus> installReal(RunId id, boolean setTheStage, DualLogger logger) { + // TODO jvenstad: Check for expiry after installation, before timeout, startTests, endTests ... if (expired(id.application(), id.type())) { logger.log(INFO, "Deployment expired before installation was successful."); return Optional.of(installationFailed); diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/JobController.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/JobController.java index ed844b96eda..1321e232fee 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/JobController.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/JobController.java @@ -96,7 +96,7 @@ public class JobController { /** Stores the given log record for the given run and step. */ public void log(RunId id, Step step, Level level, String message) { locked(id, __ -> { - LogEntry entry = new LogEntry(0, controller.clock().millis(), level, message); + LogEntry entry = new LogEntry(0, controller.clock().millis(), LogEntry.typeOf(level), message); logs.append(id.application(), id.type(), step, Collections.singletonList(entry)); return __; }); diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/BufferedLogStore.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/BufferedLogStore.java index dce3f52bd35..7d5a6d2d36f 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/BufferedLogStore.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/BufferedLogStore.java @@ -52,7 +52,7 @@ public class BufferedLogStore { Map<Step, List<LogEntry>> log = logSerializer.fromJson(lastChunk, -1); List<LogEntry> stepEntries = log.computeIfAbsent(step, __ -> new ArrayList<>()); for (LogEntry entry : entries) - stepEntries.add(new LogEntry(++lastEntryId, entry.at(), entry.level(), entry.message())); + stepEntries.add(new LogEntry(++lastEntryId, entry.at(), entry.type(), entry.message())); buffer.writeLog(id, type, lastChunkId, logSerializer.toJson(log)); buffer.writeLastLogEntryId(id, type, lastEntryId); diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/LogSerializer.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/LogSerializer.java index 337204a31af..457ef761c0f 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/LogSerializer.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/LogSerializer.java @@ -1,6 +1,5 @@ package com.yahoo.vespa.hosted.controller.persistence; -import com.yahoo.log.LogLevel; import com.yahoo.slime.ArrayTraverser; import com.yahoo.slime.Cursor; import com.yahoo.slime.Inspector; @@ -8,6 +7,7 @@ import com.yahoo.slime.ObjectTraverser; import com.yahoo.slime.Slime; import com.yahoo.vespa.config.SlimeUtils; import com.yahoo.vespa.hosted.controller.api.integration.LogEntry; +import com.yahoo.vespa.hosted.controller.api.integration.LogEntry.Type; import com.yahoo.vespa.hosted.controller.deployment.Step; import java.io.IOException; @@ -28,6 +28,7 @@ class LogSerializer { private static final String idField = "id"; private static final String levelField = "level"; + private static final String typeField = "type"; private static final String timestampField = "at"; private static final String messageField = "message"; @@ -53,7 +54,8 @@ class LogSerializer { private void toSlime(LogEntry entry, Cursor entryObject) { entryObject.setLong(idField, entry.id()); entryObject.setLong(timestampField, entry.at()); - entryObject.setString(levelField, entry.level().getName()); + entryObject.setString(levelField, valueOf(entry.type())); // TODO jvenstad: Remove after one deployment. + entryObject.setString(typeField, valueOf(entry.type())); entryObject.setString(messageField, entry.message()); } @@ -85,8 +87,32 @@ class LogSerializer { private LogEntry fromSlime(Inspector entryObject) { return new LogEntry(entryObject.field(idField).asLong(), entryObject.field(timestampField).asLong(), - LogLevel.parse(entryObject.field(levelField).asString()), + entryObject.field(typeField).valid() // TODO jvenstad: Remove after one deployment. + ? typeOf(entryObject.field(typeField).asString()) + : typeOf(entryObject.field(levelField).asString()), entryObject.field(messageField).asString()); } + static String valueOf(Type type) { + switch (type) { + case debug: return "debug"; + case info: return "info"; + case warning: return "warning"; + case error: return "error"; + case html: return "html"; + default: throw new AssertionError("Unexpected log entry type '" + type + "'!"); + } + } + + static Type typeOf(String type) { + switch (type.toLowerCase()) { // TODO jvenstad: Remove lowercasing after this has been deployed. + case "debug": return Type.debug; + case "info": return Type.info; + case "warning": return Type.warning; + case "error": return Type.error; + case "html": return Type.html; + default: throw new IllegalArgumentException("Unknown log entry type '" + type + "'!"); + } + } + } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/JobControllerApiHandlerHelper.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/JobControllerApiHandlerHelper.java index 68ba8ab83f3..9435bc63015 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/JobControllerApiHandlerHelper.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/JobControllerApiHandlerHelper.java @@ -127,7 +127,7 @@ class JobControllerApiHandlerHelper { private static void toSlime(Cursor entryObject, LogEntry entry) { entryObject.setLong("at", entry.at()); - entryObject.setString("level", entry.level().getName()); + entryObject.setString("type", entry.type().name()); entryObject.setString("message", entry.message()); } diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/InternalStepRunnerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/InternalStepRunnerTest.java index ce0446e41b6..8c897ae6706 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/InternalStepRunnerTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/InternalStepRunnerTest.java @@ -45,6 +45,9 @@ import java.util.logging.Logger; import static com.yahoo.log.LogLevel.DEBUG; import static com.yahoo.log.LogLevel.ERROR; +import static com.yahoo.vespa.hosted.controller.api.integration.LogEntry.Type.debug; +import static com.yahoo.vespa.hosted.controller.api.integration.LogEntry.Type.error; +import static com.yahoo.vespa.hosted.controller.api.integration.LogEntry.Type.info; import static com.yahoo.vespa.hosted.controller.deployment.InternalStepRunner.testerOf; import static com.yahoo.vespa.hosted.controller.deployment.RunStatus.aborted; import static com.yahoo.vespa.hosted.controller.deployment.Step.Status.failed; @@ -339,29 +342,29 @@ public class InternalStepRunnerTest { @Test public void testsFailIfTestsFailRemotely() { RunId id = startSystemTestTests(); - cloud.add(new LogEntry(123, 321, ERROR, "Failure!")); + cloud.add(new LogEntry(123, 321, error, "Failure!")); cloud.set(TesterCloud.Status.FAILURE); long lastId = jobs.details(id).get().lastId().getAsLong(); runner.run(); assertTestLogEntries(id, Step.endTests, - new LogEntry(lastId + 1, 321, ERROR, "Failure!"), - new LogEntry(lastId + 2, tester.clock().millis(), DEBUG, "Tests failed.")); + new LogEntry(lastId + 1, 321, error, "Failure!"), + new LogEntry(lastId + 2, tester.clock().millis(), debug, "Tests failed.")); assertEquals(failed, jobs.run(id).get().steps().get(Step.endTests)); } @Test public void testsFailIfTestsErr() { RunId id = startSystemTestTests(); - cloud.add(new LogEntry(0, 123, ERROR, "Error!")); + cloud.add(new LogEntry(0, 123, error, "Error!")); cloud.set(TesterCloud.Status.ERROR); long lastId = jobs.details(id).get().lastId().getAsLong(); runner.run(); assertEquals(failed, jobs.run(id).get().steps().get(Step.endTests)); assertTestLogEntries(id, Step.endTests, - new LogEntry(lastId + 1, 123, ERROR, "Error!"), - new LogEntry(lastId + 2, tester.clock().millis(), INFO, "Tester failed running its tests!")); + new LogEntry(lastId + 1, 123, error, "Error!"), + new LogEntry(lastId + 2, tester.clock().millis(), info, "Tester failed running its tests!")); } @Test @@ -381,25 +384,25 @@ public class InternalStepRunnerTest { assertEquals(routing.endpoints(new DeploymentId(appId, JobType.systemTest.zone(tester.controller().system()))).get(0).getEndpoint(), endpoint.asString())); long lastId = jobs.details(id).get().lastId().getAsLong(); - cloud.add(new LogEntry(0, 123, INFO, "Ready!")); + cloud.add(new LogEntry(0, 123, info, "Ready!")); runner.run(); assertTestLogEntries(id, Step.endTests, - new LogEntry(lastId + 1, 123, INFO, "Ready!")); + new LogEntry(lastId + 1, 123, info, "Ready!")); - cloud.add(new LogEntry(1, 1234, INFO, "Steady!")); + cloud.add(new LogEntry(1, 1234, info, "Steady!")); runner.run(); assertTestLogEntries(id, Step.endTests, - new LogEntry(lastId + 1, 123, INFO, "Ready!"), - new LogEntry(lastId + 2, 1234, INFO, "Steady!")); + new LogEntry(lastId + 1, 123, info, "Ready!"), + new LogEntry(lastId + 2, 1234, info, "Steady!")); - cloud.add(new LogEntry(12, 12345, INFO, "Success!")); + cloud.add(new LogEntry(12, 12345, info, "Success!")); cloud.set(TesterCloud.Status.SUCCESS); runner.run(); assertTestLogEntries(id, Step.endTests, - new LogEntry(lastId + 1, 123, INFO, "Ready!"), - new LogEntry(lastId + 2, 1234, INFO, "Steady!"), - new LogEntry(lastId + 3, 12345, INFO, "Success!"), - new LogEntry(lastId + 4, tester.clock().millis(), DEBUG, "Tests completed successfully.")); + new LogEntry(lastId + 1, 123, info, "Ready!"), + new LogEntry(lastId + 2, 1234, info, "Steady!"), + new LogEntry(lastId + 3, 12345, info, "Success!"), + new LogEntry(lastId + 4, tester.clock().millis(), debug, "Tests completed successfully.")); assertEquals(succeeded, jobs.run(id).get().steps().get(Step.endTests)); } diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/BufferedLogStoreTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/BufferedLogStoreTest.java index 6147c50120e..0866b28045c 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/BufferedLogStoreTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/BufferedLogStoreTest.java @@ -13,7 +13,6 @@ import org.junit.Test; import java.util.Arrays; import java.util.Collections; import java.util.Optional; -import java.util.logging.Level; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; @@ -31,12 +30,12 @@ public class BufferedLogStoreTest { byte[] manyBytes = new byte[BufferedLogStore.chunkSize / 2 + 1]; // One fits, and two (over-)fills. Arrays.fill(manyBytes, (byte) 'O'); - LogEntry entry = new LogEntry(0, 123, Level.WARNING, new String(manyBytes)); + LogEntry entry = new LogEntry(0, 123, LogEntry.Type.warning, new String(manyBytes)); // Log entries are re-sequenced by the log store, by enumeration. - LogEntry entry0 = new LogEntry(0, entry.at(), entry.level(), entry.message()); - LogEntry entry1 = new LogEntry(1, entry.at(), entry.level(), entry.message()); - LogEntry entry2 = new LogEntry(2, entry.at(), entry.level(), entry.message()); + LogEntry entry0 = new LogEntry(0, entry.at(), entry.type(), entry.message()); + LogEntry entry1 = new LogEntry(1, entry.at(), entry.type(), entry.message()); + LogEntry entry2 = new LogEntry(2, entry.at(), entry.type(), entry.message()); assertEquals(Optional.empty(), logs.readFinished(id, -1)); assertEquals(RunLog.empty(), logs.readActive(id.application(), id.type(), -1)); diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/LogSerializerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/LogSerializerTest.java index 64aaec97b09..ac3308c242c 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/LogSerializerTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/persistence/LogSerializerTest.java @@ -1,6 +1,5 @@ package com.yahoo.vespa.hosted.controller.persistence; -import com.yahoo.log.LogLevel; import com.yahoo.vespa.hosted.controller.api.integration.LogEntry; import com.yahoo.vespa.hosted.controller.deployment.Step; import org.junit.Test; @@ -29,12 +28,15 @@ public class LogSerializerTest { @Test public void testSerialization() throws IOException { + for (LogEntry.Type type : LogEntry.Type.values()) + assertEquals(type, LogSerializer.typeOf(LogSerializer.valueOf(type))); + byte[] logJson = Files.readAllBytes(logsFile); - LogEntry first = new LogEntry(0, 0, LogLevel.INFO, "First"); - LogEntry second = new LogEntry(1, 0, LogLevel.INFO, "Second"); - LogEntry third = new LogEntry(2, 1000, LogLevel.DEBUG, "Third"); - LogEntry fourth = new LogEntry(3, 2000, LogLevel.WARNING, "Fourth"); + LogEntry first = new LogEntry(0, 0, LogEntry.Type.info, "First"); + LogEntry second = new LogEntry(1, 0, LogEntry.Type.info, "Second"); + LogEntry third = new LogEntry(2, 1000, LogEntry.Type.debug, "Third"); + LogEntry fourth = new LogEntry(3, 2000, LogEntry.Type.warning, "Fourth"); Map<Step, List<LogEntry>> expected = new HashMap<>(); expected.put(deployReal, new ArrayList<>()); diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/JobControllerApiHandlerHelperTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/JobControllerApiHandlerHelperTest.java index bfa4a694208..dd17f7f54bc 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/JobControllerApiHandlerHelperTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/JobControllerApiHandlerHelperTest.java @@ -102,9 +102,9 @@ public class JobControllerApiHandlerHelperTest { runId.type(), Collections.singleton(createRun(JobType.systemTest, 42, 44, lastStep, Optional.of(RunStatus.running)))); - logStore.append(appId, JobType.systemTest, Step.deployTester, Collections.singletonList(new LogEntry(0, 1, Level.INFO, "SUCCESS"))); - logStore.append(appId, JobType.systemTest, Step.installTester, Collections.singletonList(new LogEntry(0, 12, Level.FINE, "SUCCESS"))); - logStore.append(appId, JobType.systemTest, Step.deactivateTester, Collections.singletonList(new LogEntry(0, 123, Level.WARNING, "ERROR"))); + logStore.append(appId, JobType.systemTest, Step.deployTester, Collections.singletonList(new LogEntry(0, 1, LogEntry.Type.info, "SUCCESS"))); + logStore.append(appId, JobType.systemTest, Step.installTester, Collections.singletonList(new LogEntry(0, 12, LogEntry.Type.debug, "SUCCESS"))); + logStore.append(appId, JobType.systemTest, Step.deactivateTester, Collections.singletonList(new LogEntry(0, 123, LogEntry.Type.warning, "ERROR"))); logStore.flush(runId); HttpResponse response = JobControllerApiHandlerHelper.runDetailsResponse(jobController, runId,"0"); diff --git a/controller-server/src/test/resources/job/run-details-response.json b/controller-server/src/test/resources/job/run-details-response.json index 06f02565a75..95622313852 100644 --- a/controller-server/src/test/resources/job/run-details-response.json +++ b/controller-server/src/test/resources/job/run-details-response.json @@ -5,14 +5,14 @@ "installTester":[ { "at":12, - "level":"DEBUG", + "type":"debug", "message":"SUCCESS" } ], "deactivateTester":[ { "at":123, - "level":"WARNING", + "type":"warning", "message":"ERROR" } ] |