aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/vespa/model/container/http/ssl/HostedSslConnectorFactory.java
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@vespa.ai>2024-06-06 11:08:45 +0200
committerBjørn Christian Seime <bjorncs@vespa.ai>2024-06-06 11:40:41 +0200
commitcf00a65940560c8fbfe32a015f4ef50942e997d8 (patch)
tree277661ff338df1834daaa955b0f225eb5f3d7417 /config-model/src/main/java/com/yahoo/vespa/model/container/http/ssl/HostedSslConnectorFactory.java
parentd6818209d90b407dc1a9bde5cae4269c071eea2d (diff)
Move parsing of configuration string to config model
Diffstat (limited to 'config-model/src/main/java/com/yahoo/vespa/model/container/http/ssl/HostedSslConnectorFactory.java')
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/container/http/ssl/HostedSslConnectorFactory.java38
1 files changed, 28 insertions, 10 deletions
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/http/ssl/HostedSslConnectorFactory.java b/config-model/src/main/java/com/yahoo/vespa/model/container/http/ssl/HostedSslConnectorFactory.java
index f8b739c638b..9c9e20062f8 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/container/http/ssl/HostedSslConnectorFactory.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/container/http/ssl/HostedSslConnectorFactory.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.model.container.http.ssl;
+import ai.vespa.utils.BytesQuantity;
import com.yahoo.config.model.api.EndpointCertificateSecrets;
import com.yahoo.jdisc.http.ConnectorConfig;
import com.yahoo.security.tls.TlsContext;
@@ -21,6 +22,8 @@ import java.util.TreeSet;
*/
public class HostedSslConnectorFactory extends ConnectorFactory {
+ private record EntityLoggingEntry(String prefix, double sampleRate, BytesQuantity maxEntitySize) {}
+
private final SslClientAuth clientAuth;
private final List<String> tlsCiphersOverride;
private final boolean proxyProtocolEnabled;
@@ -28,7 +31,7 @@ public class HostedSslConnectorFactory extends ConnectorFactory {
private final List<String> remoteAddressHeaders;
private final List<String> remotePortHeaders;
private final Set<String> knownServerNames;
- private final Set<String> requestPrefixForLoggingContent;
+ private final List<EntityLoggingEntry> entityLoggingEntries;
public static Builder builder(String name, int listenPort) { return new Builder(name, listenPort); }
@@ -41,12 +44,22 @@ public class HostedSslConnectorFactory extends ConnectorFactory {
this.remoteAddressHeaders = List.copyOf(builder.remoteAddressHeaders);
this.remotePortHeaders = List.copyOf(builder.remotePortHeaders);
this.knownServerNames = Collections.unmodifiableSet(new TreeSet<>(builder.knownServerNames));
- builder.requestPrefixForLoggingContent.forEach(prefix -> {
- var regex = "^.*:[01](\\.\\d+)?:\\d+[a-zA-Z]+$";
- if (!prefix.matches(regex))
- throw new IllegalArgumentException("Invalid prefix '%s, must match regex '%s'".formatted(prefix, regex));
- });
- this.requestPrefixForLoggingContent = Collections.unmodifiableSet(new TreeSet<>(builder.requestPrefixForLoggingContent));
+ this.entityLoggingEntries = builder.requestPrefixForLoggingContent.stream()
+ .map(prefix -> {
+ var parts = prefix.split(":");
+ if (parts.length != 3) {
+ throw new IllegalArgumentException("Expected string of format 'prefix:sample-rate:max-entity-size', got '%s'".formatted(prefix));
+ }
+ var pathPrefix = parts[0];
+ if (pathPrefix.isBlank())
+ throw new IllegalArgumentException("Path prefix must not be blank");
+ var sampleRate = Double.parseDouble(parts[1]);
+ if (sampleRate < 0 || sampleRate > 1)
+ throw new IllegalArgumentException("Sample rate must be in range [0, 1], got '%s'".formatted(sampleRate));
+ var maxEntitySize = BytesQuantity.fromString(parts[2]);
+ return new EntityLoggingEntry(pathPrefix, sampleRate, maxEntitySize);
+ })
+ .toList();
}
private static SslProvider createSslProvider(Builder builder) {
@@ -79,9 +92,14 @@ public class HostedSslConnectorFactory extends ConnectorFactory {
.idleTimeout(Duration.ofSeconds(30).toSeconds())
.maxConnectionLife(endpointConnectionTtl != null ? endpointConnectionTtl.toSeconds() : 0)
.accessLog(new ConnectorConfig.AccessLog.Builder()
- .remoteAddressHeaders(remoteAddressHeaders)
- .remotePortHeaders(remotePortHeaders)
- .contentPathPrefixes(requestPrefixForLoggingContent))
+ .remoteAddressHeaders(remoteAddressHeaders)
+ .remotePortHeaders(remotePortHeaders)
+ .content(entityLoggingEntries.stream()
+ .map(e -> new ConnectorConfig.AccessLog.Content.Builder()
+ .pathPrefix(e.prefix)
+ .sampleRate(e.sampleRate)
+ .maxSize(e.maxEntitySize.toBytes()))
+ .toList()))
.serverName.known(knownServerNames);
}