summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOla Aunrønning <olaa@verizonmedia.com>2022-06-18 15:17:09 +0200
committerGitHub <noreply@github.com>2022-06-18 15:17:09 +0200
commit5d2c9fa077648828aaa2299109c47e9c10b48c13 (patch)
treea121ede3d215d38faacb514a8732154bfa7d23d2
parent4e649cd2f7a0aee813518d2644282dd7a43d1992 (diff)
parent63d6fa74bf7988633680b46474699ace38bc250a (diff)
Merge pull request #23157 from vespa-engine/hmusum/return-empty-log-if-no-log-found
Return empty log if getting log fails and we just deployed
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java2
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/ServerCache.java2
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/http/LogRetriever.java17
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java9
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/MockLogRetriever.java25
5 files changed, 33 insertions, 22 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java b/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java
index fd4f1824885..5bed5ec8d26 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java
@@ -750,7 +750,7 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye
public HttpResponse getLogs(ApplicationId applicationId, Optional<DomainName> hostname, String apiParams) {
String logServerURI = getLogServerURI(applicationId, hostname) + apiParams;
- return logRetriever.getLogs(logServerURI);
+ return logRetriever.getLogs(logServerURI, lastDeployTime(applicationId));
}
// ---------------- Methods to do call against tester containers in hosted ------------------------------
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/ServerCache.java b/configserver/src/main/java/com/yahoo/vespa/config/server/ServerCache.java
index 6d6b93dad46..0ec1382b496 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/ServerCache.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/ServerCache.java
@@ -24,7 +24,7 @@ public class ServerCache {
private final ConfigDefinitionRepo builtinConfigDefinitions;
private final ConfigDefinitionRepo userConfigDefinitions;
- // NOTE: The reason we do a double mapping here is to de-dupe configs that have the same md5.
+ // NOTE: The reason we do a double mapping here is to de-dupe configs that have the same checksum.
private final Map<ConfigCacheKey, PayloadChecksum> checksums = new ConcurrentHashMap<>();
private final Map<PayloadChecksum, ConfigResponse> checksumToConfig = new ConcurrentHashMap<>();
private final Object [] stripedLocks = new Object[113];
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/LogRetriever.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/LogRetriever.java
index 14586e2289e..7d8aacba0d5 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/LogRetriever.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/LogRetriever.java
@@ -6,8 +6,12 @@ import com.yahoo.container.jdisc.HttpResponse;
import com.yahoo.yolean.Exceptions;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
-
import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
+import java.time.Duration;
+import java.time.Instant;
+import java.util.Optional;
/**
* @author olaaun
@@ -16,11 +20,20 @@ public class LogRetriever {
private final CloseableHttpClient httpClient = VespaHttpClientBuilder.create().build();
- public HttpResponse getLogs(String logServerUri) {
+ public HttpResponse getLogs(String logServerUri, Optional<Instant> deployTime) {
HttpGet get = new HttpGet(logServerUri);
try {
return new ProxyResponse(httpClient.execute(get));
} catch (IOException e) {
+ // It takes some time before nodes are up after first-time deployment, return empty log for up to 1 minute
+ // if getting logs fail
+ if (deployTime.isPresent() && Instant.now().isBefore(deployTime.get().plus(Duration.ofMinutes(1))))
+ return new HttpResponse(200) {
+ @Override
+ public void render(OutputStream outputStream) throws IOException {
+ outputStream.write("".getBytes(StandardCharsets.UTF_8));
+ }
+ };
return HttpErrorResponse.internalServerError("Failed to get logs: " + Exceptions.toMessageString(e));
}
}
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java
index d9ca31d561d..ee2a979be7a 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java
@@ -7,7 +7,6 @@ import com.yahoo.component.Version;
import com.yahoo.config.ConfigInstance;
import com.yahoo.config.SimpletypesConfig;
import com.yahoo.config.application.api.ApplicationMetaData;
-import com.yahoo.config.model.NullConfigModelRegistry;
import com.yahoo.config.model.application.provider.BaseDeployLogger;
import com.yahoo.config.model.application.provider.FilesApplicationPackage;
import com.yahoo.config.provision.AllocatedHosts;
@@ -57,7 +56,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
-
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;
@@ -75,6 +74,7 @@ import java.util.Map;
import java.util.Optional;
import java.util.stream.IntStream;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
@@ -245,10 +245,13 @@ public class ApplicationRepositoryTest {
}
@Test
- public void getLogs() {
+ public void getLogs() throws IOException {
deployApp(testAppLogServerWithContainer);
HttpResponse response = applicationRepository.getLogs(applicationId(), Optional.empty(), "");
assertEquals(200, response.getStatus());
+ ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+ response.render(buffer);
+ assertEquals("log line", buffer.toString(UTF_8));
}
@Test
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/MockLogRetriever.java b/configserver/src/test/java/com/yahoo/vespa/config/server/MockLogRetriever.java
index 6a95c059fcc..4a521e3b8a2 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/MockLogRetriever.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/MockLogRetriever.java
@@ -7,6 +7,8 @@ import com.yahoo.vespa.config.server.http.LogRetriever;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
+import java.time.Instant;
+import java.util.Optional;
/**
* @author olaa
@@ -14,21 +16,14 @@ import java.nio.charset.StandardCharsets;
public class MockLogRetriever extends LogRetriever {
@Override
- public HttpResponse getLogs(String logServerUri) {
- return new MockHttpResponse();
- }
-
- private static class MockHttpResponse extends HttpResponse {
-
- private MockHttpResponse() {
- super(200);
- }
-
- @Override
- public void render(OutputStream outputStream) throws IOException {
- outputStream.write("log line".getBytes(StandardCharsets.UTF_8));
- }
-
+ public HttpResponse getLogs(String logServerUri, Optional<Instant>deployTime ) {
+ return new HttpResponse(200) {
+ @Override
+ public void render(OutputStream outputStream) throws IOException {
+ outputStream.write("log line".getBytes(StandardCharsets.UTF_8));
+ }
+
+ };
}
} \ No newline at end of file