diff options
author | Jon Bratseth <bratseth@gmail.com> | 2022-10-07 10:28:45 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-07 10:28:45 +0200 |
commit | 7438b33d2447f5348e25c18160a592924130ee25 (patch) | |
tree | f83b786d8d424bd611ee6f50998c27da1bd3b7bc /container-core | |
parent | 973c8f0aaf9d755aebd2c9a6c2226fc81dc1b183 (diff) | |
parent | 0f15123c14bc8fec27693d4122108c9e1be67df4 (diff) |
Merge pull request #24344 from vespa-engine/bratseth/return-ignored-fields
Return X-Vespa-Ignored-Fields if fields were ignored
Diffstat (limited to 'container-core')
9 files changed, 51 insertions, 73 deletions
diff --git a/container-core/src/main/java/com/yahoo/container/handler/LogReader.java b/container-core/src/main/java/com/yahoo/container/handler/LogReader.java index 2890cbfb5ab..fe841bac68e 100644 --- a/container-core/src/main/java/com/yahoo/container/handler/LogReader.java +++ b/container-core/src/main/java/com/yahoo/container/handler/LogReader.java @@ -43,13 +43,13 @@ import static java.nio.charset.StandardCharsets.UTF_8; * @author jonmv */ class LogReader { + static final Pattern logArchivePathPattern = Pattern.compile("(\\d{4})/(\\d{2})/(\\d{2})/(\\d{2})-\\d+(\\.gz|\\.zst)?"); static final Pattern vespaLogPathPattern = Pattern.compile("vespa\\.log(?:-(\\d{4})-(\\d{2})-(\\d{2})\\.(\\d{2})-(\\d{2})-(\\d{2})(?:\\.gz|\\.zst)?)?"); private final Path logDirectory; private final Pattern logFilePattern; - LogReader(String logDirectory, String logFilePattern) { this(Paths.get(Defaults.getDefaults().underVespaHome(logDirectory)), Pattern.compile(logFilePattern)); } diff --git a/container-core/src/main/java/com/yahoo/container/jdisc/state/StateHandler.java b/container-core/src/main/java/com/yahoo/container/jdisc/state/StateHandler.java index cfd2244bd70..7a64e14e65e 100644 --- a/container-core/src/main/java/com/yahoo/container/jdisc/state/StateHandler.java +++ b/container-core/src/main/java/com/yahoo/container/jdisc/state/StateHandler.java @@ -274,15 +274,11 @@ public class StateHandler extends AbstractRequestHandler { } private static List<Tuple> collapseMetrics(MetricSnapshot snapshot, String consumer) { - switch (consumer) { - case HEALTH_PATH: - return collapseHealthMetrics(snapshot); - case "all": // deprecated name - case METRICS_PATH: - return flattenAllMetrics(snapshot); - default: - throw new IllegalArgumentException("Unknown consumer '" + consumer + "'."); - } + return switch (consumer) { + case HEALTH_PATH -> collapseHealthMetrics(snapshot); // deprecated name + case "all", METRICS_PATH -> flattenAllMetrics(snapshot); + default -> throw new IllegalArgumentException("Unknown consumer '" + consumer + "'."); + }; } private static List<Tuple> collapseHealthMetrics(MetricSnapshot snapshot) { diff --git a/container-core/src/main/java/com/yahoo/container/logging/AccessLogEntry.java b/container-core/src/main/java/com/yahoo/container/logging/AccessLogEntry.java index c469c90f6ab..2639239d23f 100644 --- a/container-core/src/main/java/com/yahoo/container/logging/AccessLogEntry.java +++ b/container-core/src/main/java/com/yahoo/container/logging/AccessLogEntry.java @@ -65,16 +65,14 @@ public class AccessLogEntry { return null; } - final Map<String, List<String>> newMapWithImmutableValues = mapValues( + Map<String, List<String>> newMapWithImmutableValues = mapValues( keyValues.entrySet(), valueList -> Collections.unmodifiableList(new ArrayList<>(valueList))); return Collections.unmodifiableMap(newMapWithImmutableValues); } } - private static <K, V1, V2> Map<K, V2> mapValues( - final Set<Map.Entry<K, V1>> entrySet, - final Function<V1, V2> valueConverter) { + private static <K, V1, V2> Map<K, V2> mapValues(Set<Map.Entry<K, V1>> entrySet, Function<V1, V2> valueConverter) { return entrySet.stream() .collect(toMap( entry -> entry.getKey(), diff --git a/container-core/src/main/java/com/yahoo/jdisc/http/server/jetty/FormPostRequestHandler.java b/container-core/src/main/java/com/yahoo/jdisc/http/server/jetty/FormPostRequestHandler.java index 72057563e36..d2dbfaa3514 100644 --- a/container-core/src/main/java/com/yahoo/jdisc/http/server/jetty/FormPostRequestHandler.java +++ b/container-core/src/main/java/com/yahoo/jdisc/http/server/jetty/FormPostRequestHandler.java @@ -54,17 +54,14 @@ class FormPostRequestHandler extends AbstractRequestHandler implements ContentCh * @param delegateHandler the "real" request handler that this handler wraps * @param contentCharsetName name of the charset to use when interpreting the content data */ - public FormPostRequestHandler( - final RequestHandler delegateHandler, - final String contentCharsetName, - final boolean removeBody) { + public FormPostRequestHandler(RequestHandler delegateHandler, String contentCharsetName, boolean removeBody) { this.delegateHandler = Objects.requireNonNull(delegateHandler); this.contentCharsetName = Objects.requireNonNull(contentCharsetName); this.removeBody = removeBody; } @Override - public ContentChannel handleRequest(final Request request, final ResponseHandler responseHandler) { + public ContentChannel handleRequest(Request request, ResponseHandler responseHandler) { Preconditions.checkArgument(request instanceof HttpRequest, "Expected HttpRequest, got " + request); Objects.requireNonNull(responseHandler, "responseHandler"); @@ -77,24 +74,24 @@ class FormPostRequestHandler extends AbstractRequestHandler implements ContentCh } @Override - public void write(final ByteBuffer buf, final CompletionHandler completionHandler) { + public void write(ByteBuffer buf, CompletionHandler completionHandler) { assert buf.hasArray(); accumulatedRequestContent.write(buf.array(), buf.arrayOffset() + buf.position(), buf.remaining()); completionHandler.completed(); } @Override - public void close(final CompletionHandler completionHandler) { - try (final ResourceReference ref = requestReference) { - final byte[] requestContentBytes = accumulatedRequestContent.toByteArray(); - final String content = new String(requestContentBytes, contentCharset); + public void close(CompletionHandler completionHandler) { + try (ResourceReference ref = requestReference) { + byte[] requestContentBytes = accumulatedRequestContent.toByteArray(); + String content = new String(requestContentBytes, contentCharset); completionHandler.completed(); - final Map<String, List<String>> parameterMap = parseFormParameters(content); + Map<String, List<String>> parameterMap = parseFormParameters(content); mergeParameters(parameterMap, request.parameters()); - final ContentChannel contentChannel = delegateHandler.handleRequest(request, responseHandler); + ContentChannel contentChannel = delegateHandler.handleRequest(request, responseHandler); if (contentChannel != null) { if (!removeBody) { - final ByteBuffer byteBuffer = ByteBuffer.wrap(requestContentBytes); + ByteBuffer byteBuffer = ByteBuffer.wrap(requestContentBytes); contentChannel.write(byteBuffer, NOOP_COMPLETION_HANDLER); } contentChannel.close(NOOP_COMPLETION_HANDLER); @@ -109,14 +106,10 @@ class FormPostRequestHandler extends AbstractRequestHandler implements ContentCh * @return a valid Charset for the charset name (never returns null) * @throws RequestException if the charset name is invalid or unsupported */ - private static Charset getCharsetByName(final String charsetName) throws RequestException { + private static Charset getCharsetByName(String charsetName) throws RequestException { try { - final Charset charset = Charset.forName(charsetName); - if (charset == null) { - throw new RequestException(UNSUPPORTED_MEDIA_TYPE, "Unsupported charset " + charsetName); - } - return charset; - } catch (final IllegalCharsetNameException |UnsupportedCharsetException e) { + return Charset.forName(charsetName); + } catch (IllegalCharsetNameException | UnsupportedCharsetException e) { throw new RequestException(UNSUPPORTED_MEDIA_TYPE, "Unsupported charset " + charsetName, e); } } @@ -127,17 +120,17 @@ class FormPostRequestHandler extends AbstractRequestHandler implements ContentCh * @param formContent raw form content data (body) * @return map of decoded parameters */ - private static Map<String, List<String>> parseFormParameters(final String formContent) { + private static Map<String, List<String>> parseFormParameters(String formContent) { if (formContent.isEmpty()) { return Collections.emptyMap(); } - final Map<String, List<String>> parameterMap = new HashMap<>(); - final String[] params = formContent.split("&"); - for (final String param : params) { - final String[] parts = param.split("="); - final String paramName = urlDecode(parts[0]); - final String paramValue = parts.length > 1 ? urlDecode(parts[1]) : ""; + Map<String, List<String>> parameterMap = new HashMap<>(); + String[] params = formContent.split("&"); + for (String param : params) { + String[] parts = param.split("="); + String paramName = urlDecode(parts[0]); + String paramValue = parts.length > 1 ? urlDecode(parts[1]) : ""; List<String> currentValues = parameterMap.get(paramName); if (currentValues == null) { currentValues = new LinkedList<>(); @@ -159,7 +152,7 @@ class FormPostRequestHandler extends AbstractRequestHandler implements ContentCh // Regardless of the charset used to transfer the request body, // all percent-escaping of non-ascii characters should use UTF-8 code points. return URLDecoder.decode(encoded, StandardCharsets.UTF_8.name()); - } catch (final UnsupportedEncodingException e) { + } catch (UnsupportedEncodingException e) { // Unfortunately, there is no URLDecoder.decode() method that takes a Charset, so we have to deal // with this exception. throw new IllegalStateException("Whoa, JVM doesn't support UTF-8 today.", e); @@ -172,11 +165,9 @@ class FormPostRequestHandler extends AbstractRequestHandler implements ContentCh * @param source containing the parameters to copy into the destination * @param destination receiver of parameters, possibly already containing data */ - private static void mergeParameters( - final Map<String,List<String>> source, - final Map<String,List<String>> destination) { + private static void mergeParameters(Map<String,List<String>> source, Map<String,List<String>> destination) { for (Map.Entry<String, List<String>> entry : source.entrySet()) { - final List<String> destinationValues = destination.get(entry.getKey()); + List<String> destinationValues = destination.get(entry.getKey()); if (destinationValues != null) { destinationValues.addAll(entry.getValue()); } else { @@ -189,4 +180,5 @@ class FormPostRequestHandler extends AbstractRequestHandler implements ContentCh public RequestHandler getDelegate() { return delegateHandler; } + } diff --git a/container-core/src/main/java/com/yahoo/processing/handler/AbstractProcessingHandler.java b/container-core/src/main/java/com/yahoo/processing/handler/AbstractProcessingHandler.java index 2c15c994bb7..f4db1c5085a 100644 --- a/container-core/src/main/java/com/yahoo/processing/handler/AbstractProcessingHandler.java +++ b/container-core/src/main/java/com/yahoo/processing/handler/AbstractProcessingHandler.java @@ -187,7 +187,7 @@ public abstract class AbstractProcessingHandler<COMPONENT extends Processor> ext private void populate(String prefixName,Map<String,?> parameters,Properties properties) { CompoundName prefix = new CompoundName(prefixName); for (Map.Entry<String,?> entry : parameters.entrySet()) - properties.set(prefix.append(entry.getKey()),entry.getValue()); + properties.set(prefix.append(entry.getKey()), entry.getValue()); } private static class FreezeListener implements Runnable, ResponseReceiver { diff --git a/container-core/src/test/java/com/yahoo/metrics/simple/BucketTest.java b/container-core/src/test/java/com/yahoo/metrics/simple/BucketTest.java index 11cc8b86a09..75d1c37c5c1 100644 --- a/container-core/src/test/java/com/yahoo/metrics/simple/BucketTest.java +++ b/container-core/src/test/java/com/yahoo/metrics/simple/BucketTest.java @@ -23,9 +23,10 @@ import com.yahoo.metrics.simple.UntypedMetric.AssumedType; * Functional tests for the value buckets, as implemented in the class Bucket, * and by extension the value store itself, UntypedValue. * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ public class BucketTest { + private Bucket bucket; @BeforeEach @@ -55,23 +56,12 @@ public class BucketTest { for (Entry<Identifier, UntypedMetric> x : bucket.entrySet()) { String metricName = x.getKey().getName(); switch (metricName) { - case "nalle": - ++nalle; - break; - case "nalle_0": - ++nalle0; - break; - case "nalle_1": - ++nalle1; - break; - case "nalle_2": - ++nalle2; - break; - case "nalle_3": - ++nalle3; - break; - default: - throw new IllegalStateException(); + case "nalle" -> ++nalle; + case "nalle_0" -> ++nalle0; + case "nalle_1" -> ++nalle1; + case "nalle_2" -> ++nalle2; + case "nalle_3" -> ++nalle3; + default -> throw new IllegalStateException(); } } assertEquals(4, nalle); diff --git a/container-core/src/test/java/com/yahoo/metrics/simple/CounterTest.java b/container-core/src/test/java/com/yahoo/metrics/simple/CounterTest.java index 45a76078619..074c0c7b2e5 100644 --- a/container-core/src/test/java/com/yahoo/metrics/simple/CounterTest.java +++ b/container-core/src/test/java/com/yahoo/metrics/simple/CounterTest.java @@ -33,7 +33,7 @@ public class CounterTest { } @Test - final void testAdd() throws InterruptedException { + final void testAdd() { final String metricName = "unitTestCounter"; Counter c = receiver.declareCounter(metricName); c.add(); @@ -47,7 +47,7 @@ public class CounterTest { } @Test - final void testAddLong() throws InterruptedException { + final void testAddLong() { final String metricName = "unitTestCounter"; Counter c = receiver.declareCounter(metricName); final long twoToThePowerOfFourtyeight = 65536L * 65536L * 65536L; @@ -62,7 +62,7 @@ public class CounterTest { } @Test - final void testAddPoint() throws InterruptedException { + final void testAddPoint() { final String metricName = "unitTestCounter"; Point p = receiver.pointBuilder().set("x", 2L).set("y", 3.0d).set("z", "5").build(); Counter c = receiver.declareCounter(metricName, p); @@ -77,7 +77,7 @@ public class CounterTest { } @Test - final void testAddLongPoint() throws InterruptedException { + final void testAddLongPoint() { final String metricName = "unitTestCounter"; Point p = receiver.pointBuilder().set("x", 2L).set("y", 3.0d).set("z", "5").build(); Counter c = receiver.declareCounter(metricName, p); diff --git a/container-core/src/test/java/com/yahoo/metrics/simple/MetricsTest.java b/container-core/src/test/java/com/yahoo/metrics/simple/MetricsTest.java index f64998f0be4..dd949627f30 100644 --- a/container-core/src/test/java/com/yahoo/metrics/simple/MetricsTest.java +++ b/container-core/src/test/java/com/yahoo/metrics/simple/MetricsTest.java @@ -17,9 +17,10 @@ import com.yahoo.metrics.simple.jdisc.SimpleMetricConsumer; /** * Functional test for simple metric implementation. * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ public class MetricsTest extends UnitTestSetup { + SimpleMetricConsumer metricApi; @BeforeEach @@ -36,7 +37,7 @@ public class MetricsTest extends UnitTestSetup { @Test final void smokeTest() throws InterruptedException { final String metricName = "testMetric"; - metricApi.set(metricName, Double.valueOf(1.0d), null); + metricApi.set(metricName, 1.0d, null); updater.gotData.await(10, TimeUnit.SECONDS); Bucket s = getUpdatedSnapshot(); Collection<Entry<Point, UntypedMetric>> values = s.getValuesForMetric(metricName); diff --git a/container-core/src/test/java/com/yahoo/metrics/simple/jdisc/SnapshotConverterTest.java b/container-core/src/test/java/com/yahoo/metrics/simple/jdisc/SnapshotConverterTest.java index 7981e5904f3..1d5cf264964 100644 --- a/container-core/src/test/java/com/yahoo/metrics/simple/jdisc/SnapshotConverterTest.java +++ b/container-core/src/test/java/com/yahoo/metrics/simple/jdisc/SnapshotConverterTest.java @@ -20,6 +20,7 @@ import java.util.Map; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * @author bratseth @@ -50,7 +51,7 @@ public class SnapshotConverterTest { for (Map.Entry<MetricDimensions, MetricSet> entry : snapshot) { for (Map.Entry<String, String> dv : entry.getKey()) { - assertTrue(false); + fail(); } int cnt = 0; @@ -67,7 +68,7 @@ public class SnapshotConverterTest { assertEquals(42.25, ((GaugeMetric) mv.getValue()).getLast(), 0.001); assertEquals(1, ((GaugeMetric) mv.getValue()).getCount()); } else { - assertTrue(false); + fail(); } } assertEquals(3, cnt); |