aboutsummaryrefslogtreecommitdiffstats
path: root/configserver
diff options
context:
space:
mode:
authorjonmv <venstad@gmail.com>2024-05-22 14:39:44 +0200
committerjonmv <venstad@gmail.com>2024-05-22 14:39:44 +0200
commitdff253253457e1cd570de3c55364e235cf8ce2de (patch)
tree619bb05969b7fe169c4ec419e78e0520d201abdd /configserver
parent09f7004464f3d2869e6b85b2479cd7b75cfe2f3e (diff)
Less strings, more proper classes
Diffstat (limited to 'configserver')
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationRepository.java13
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/http/LogRetriever.java5
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java6
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java5
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/MockLogRetriever.java4
5 files changed, 18 insertions, 15 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 ee827e02082..c2c42054109 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
@@ -4,6 +4,7 @@ package com.yahoo.vespa.config.server;
import ai.vespa.http.DomainName;
import ai.vespa.http.HttpURL;
import ai.vespa.http.HttpURL.Query;
+import ai.vespa.http.HttpURL.Scheme;
import com.yahoo.cloud.config.ConfigserverConfig;
import com.yahoo.component.Version;
import com.yahoo.component.annotation.Inject;
@@ -810,8 +811,8 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye
// ---------------- Logs ----------------------------------------------------------------
- public HttpResponse getLogs(ApplicationId applicationId, Optional<DomainName> hostname, String apiParams) {
- String logServerURI = getLogServerURI(applicationId, hostname) + apiParams;
+ public HttpResponse getLogs(ApplicationId applicationId, Optional<DomainName> hostname, Query apiParams) {
+ HttpURL logServerURI = getLogServerURI(applicationId, hostname).withQuery(apiParams);
return logRetriever.getLogs(logServerURI, activationTime(applicationId));
}
@@ -1184,14 +1185,14 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye
}
}
- private String getLogServerURI(ApplicationId applicationId, Optional<DomainName> hostname) {
+ private HttpURL getLogServerURI(ApplicationId applicationId, Optional<DomainName> hostname) {
// Allow to get logs from a given hostname if the application is under the hosted-vespa tenant.
// We make no validation that the hostname is actually allocated to the given application since
- // most applications under hosted-vespa are not known to the model and it's OK for a user to get
+ // most applications under hosted-vespa are not known to the model, and it's OK for a user to get
// logs for any host if they are authorized for the hosted-vespa tenant.
if (hostname.isPresent() && HOSTED_VESPA_TENANT.equals(applicationId.tenant())) {
int port = List.of(InfrastructureApplication.CONFIG_SERVER.id(), InfrastructureApplication.CONTROLLER.id()).contains(applicationId) ? 19071 : 8080;
- return "http://" + hostname.get().value() + ":" + port + "/logs";
+ return HttpURL.create(Scheme.http, hostname.get(), port).withPath(HttpURL.Path.empty().append("logs"));
}
Application application = getApplication(applicationId);
@@ -1210,7 +1211,7 @@ public class ApplicationRepository implements com.yahoo.config.provision.Deploye
.findFirst())
.orElseThrow(() -> new IllegalArgumentException("No container running on logserver host"));
int port = servicePort(logService);
- return "http://" + logServerHostInfo.getHostname() + ":" + port + "/logs";
+ return HttpURL.create(Scheme.http, DomainName.of(logServerHostInfo.getHostname()), port, HttpURL.Path.empty().append("logs"));
}
private int servicePort(ServiceInfo serviceInfo) {
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 af9645f55ce..acfa8e455c0 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
@@ -1,6 +1,7 @@
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.server.http;
+import ai.vespa.http.HttpURL;
import ai.vespa.util.http.hc5.VespaHttpClientBuilder;
import com.yahoo.container.jdisc.EmptyResponse;
import com.yahoo.container.jdisc.HttpResponse;
@@ -27,8 +28,8 @@ public class LogRetriever {
.buildClient();
@SuppressWarnings("deprecation")
- public HttpResponse getLogs(String logServerUri, Optional<Instant> deployTime) {
- HttpGet get = new HttpGet(logServerUri);
+ public HttpResponse getLogs(HttpURL logServerUri, Optional<Instant> deployTime) {
+ HttpGet get = new HttpGet(logServerUri.asURI());
try {
return new ProxyResponse(httpClient.execute(get));
} catch (IOException e) {
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java
index aebf6df5a07..4dcb2e44f36 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandler.java
@@ -215,9 +215,9 @@ public class ApplicationHandler extends HttpHandler {
}
private HttpResponse logs(ApplicationId applicationId, HttpRequest request) {
- Optional<DomainName> hostname = Optional.ofNullable(request.getProperty("hostname")).map(DomainName::of);
- String apiParams = Optional.ofNullable(request.getUri().getQuery()).map(q -> "?" + q).orElse("");
- return applicationRepository.getLogs(applicationId, hostname, apiParams);
+ HttpURL requestURL = HttpURL.from(request.getUri());
+ Optional<DomainName> hostname = Optional.ofNullable(requestURL.query().lastEntries().get("hostname")).map(DomainName::of);
+ return applicationRepository.getLogs(applicationId, hostname, requestURL.query().remove("hostname"));
}
private HttpResponse searchNodeMetrics(ApplicationId applicationId) {
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 d20a10c26d3..9a24dc293ce 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
@@ -2,6 +2,7 @@
package com.yahoo.vespa.config.server;
import ai.vespa.http.DomainName;
+import ai.vespa.http.HttpURL.Query;
import com.yahoo.cloud.config.ConfigserverConfig;
import com.yahoo.component.Version;
import com.yahoo.config.ConfigInstance;
@@ -267,7 +268,7 @@ public class ApplicationRepositoryTest {
@Test
public void getLogs() throws IOException {
deployApp(testAppLogServerWithContainer);
- HttpResponse response = applicationRepository.getLogs(applicationId(), Optional.empty(), "");
+ HttpResponse response = applicationRepository.getLogs(applicationId(), Optional.empty(), Query.empty());
assertEquals(200, response.getStatus());
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
response.render(buffer);
@@ -278,7 +279,7 @@ public class ApplicationRepositoryTest {
public void getLogsForHostname() {
ApplicationId applicationId = ApplicationId.from("hosted-vespa", "tenant-host", "default");
deployApp(testAppLogServerWithContainer, new PrepareParams.Builder().applicationId(applicationId).build());
- HttpResponse response = applicationRepository.getLogs(applicationId, Optional.of(DomainName.localhost), "");
+ HttpResponse response = applicationRepository.getLogs(applicationId, Optional.of(DomainName.localhost), Query.empty());
assertEquals(200, response.getStatus());
}
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 fbc0bf0ca41..4d085dddd82 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
@@ -1,6 +1,7 @@
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.server;
+import ai.vespa.http.HttpURL;
import com.yahoo.container.jdisc.HttpResponse;
import com.yahoo.vespa.config.server.http.LogRetriever;
@@ -16,13 +17,12 @@ import java.util.Optional;
public class MockLogRetriever extends LogRetriever {
@Override
- public HttpResponse getLogs(String logServerUri, Optional<Instant>deployTime ) {
+ public HttpResponse getLogs(HttpURL logServerUri, Optional<Instant> deployTime) {
return new HttpResponse(200) {
@Override
public void render(OutputStream outputStream) throws IOException {
outputStream.write("log line".getBytes(StandardCharsets.UTF_8));
}
-
};
}