summaryrefslogtreecommitdiffstats
path: root/controller-api/src
diff options
context:
space:
mode:
Diffstat (limited to 'controller-api/src')
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/LogEntry.java47
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/ConfigServer.java7
2 files changed, 48 insertions, 6 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 3da6b34542c..384b1342ea4 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
@@ -3,20 +3,34 @@ package com.yahoo.vespa.hosted.controller.api.integration;
import com.yahoo.log.LogLevel;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.UncheckedIOException;
+import java.time.Instant;
+import java.time.temporal.ChronoUnit;
+import java.util.List;
import java.util.Objects;
import java.util.logging.Level;
+import java.util.stream.Collectors;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Objects.requireNonNull;
-/** Immutable, simple log entries. */
+/**
+ * Immutable, simple log entries.
+ *
+ * @author jonmv
+ */
public class LogEntry {
private final long id;
- private final long at;
+ private final Instant at;
private final Type type;
private final String message;
- public LogEntry(long id, long at, Type type, String message) {
+ public LogEntry(long id, Instant at, Type type, String message) {
if (id < 0)
throw new IllegalArgumentException("Id must be non-negative, but was " + id + ".");
@@ -30,7 +44,7 @@ public class LogEntry {
return id;
}
- public long at() {
+ public Instant at() {
return at;
}
@@ -42,11 +56,31 @@ public class LogEntry {
return message;
}
+ public static List<LogEntry> parseVespaLog(InputStream log, Instant from) {
+ try (BufferedReader reader = new BufferedReader(new InputStreamReader(log, UTF_8))) {
+ return reader.lines()
+ .map(line -> line.split("\t"))
+ .filter(parts -> parts.length == 7)
+ .map(parts -> new LogEntry(0,
+ Instant.EPOCH.plus((long) (Double.parseDouble(parts[0]) * 1_000_000), ChronoUnit.MICROS),
+ typeOf(LogLevel.parse(parts[5])),
+ parts[1] + '\t' + parts[3] + '\t' + parts[4] + '\n' +
+ parts[6].replaceAll("\\\\n", "\n")
+ .replaceAll("\\\\t", "\t")))
+ .filter(entry -> entry.at().isAfter(from))
+ .collect(Collectors.toUnmodifiableList());
+ }
+ catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
+ }
+
+
@Override
public String toString() {
return "LogEntry{" +
"id=" + id +
- ", at=" + at +
+ ", at=" + at.toEpochMilli() +
", type=" + type +
", message='" + message + '\'' +
'}';
@@ -58,7 +92,7 @@ public class LogEntry {
if (!(o instanceof LogEntry)) return false;
LogEntry entry = (LogEntry) o;
return id == entry.id &&
- at == entry.at &&
+ at.toEpochMilli() == entry.at.toEpochMilli() &&
type == entry.type &&
Objects.equals(message, entry.message);
}
@@ -75,6 +109,7 @@ public class LogEntry {
: Type.error;
}
+
/** The type of entry, used for rendering. */
public enum Type {
debug, info, warning, error, html;
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/ConfigServer.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/ConfigServer.java
index 88ce8c41561..bc40d2e080c 100644
--- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/ConfigServer.java
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/ConfigServer.java
@@ -42,6 +42,13 @@ public interface ConfigServer {
Map<?,?> getServiceApiResponse(String tenantName, String applicationName, String instanceName, String environment, String region, String serviceName, String restPath);
+ /**
+ * Gets the Vespa logs of the given deployment.
+ *
+ * If the "from" and/or "to" query parameters are present, they are read as millis since EPOCH, and used
+ * to limit the time window for which log entries are gathered. <em>This is not exact, and will return too much.</em>
+ * If the "hostname" query parameter is present, it limits the entries to be from that host.
+ */
InputStream getLogs(DeploymentId deployment, Map<String, String> queryParameters);
List<ClusterMetrics> getMetrics(DeploymentId deployment);