diff options
Diffstat (limited to 'container-core/src/main/java/com/yahoo/container/jdisc/state')
3 files changed, 10 insertions, 13 deletions
diff --git a/container-core/src/main/java/com/yahoo/container/jdisc/state/HostLifeGatherer.java b/container-core/src/main/java/com/yahoo/container/jdisc/state/HostLifeGatherer.java index 876c3657b9d..dff03f920b1 100644 --- a/container-core/src/main/java/com/yahoo/container/jdisc/state/HostLifeGatherer.java +++ b/container-core/src/main/java/com/yahoo/container/jdisc/state/HostLifeGatherer.java @@ -1,13 +1,11 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.container.jdisc.state; +import ai.vespa.json.Jackson; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; import com.yahoo.component.Vtag; -import java.io.IOException; -import java.nio.file.Path; import java.time.Instant; /** @@ -15,9 +13,8 @@ import java.time.Instant; */ public class HostLifeGatherer { - private static final ObjectMapper jsonMapper = new ObjectMapper(); - public static JsonNode getHostLifePacket() { + var jsonMapper = Jackson.mapper(); ObjectNode jsonObject = jsonMapper.createObjectNode(); jsonObject.put("timestamp", Instant.now().getEpochSecond()); jsonObject.put("application", "host_life"); diff --git a/container-core/src/main/java/com/yahoo/container/jdisc/state/MetricsPacketsHandler.java b/container-core/src/main/java/com/yahoo/container/jdisc/state/MetricsPacketsHandler.java index b94fadec213..a682dcd3965 100644 --- a/container-core/src/main/java/com/yahoo/container/jdisc/state/MetricsPacketsHandler.java +++ b/container-core/src/main/java/com/yahoo/container/jdisc/state/MetricsPacketsHandler.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.container.jdisc.state; +import ai.vespa.json.Jackson; import ai.vespa.metrics.set.InfrastructureMetricSet; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; @@ -51,7 +52,7 @@ import static com.yahoo.container.jdisc.state.StateHandler.getSnapshotProviderOr */ public class MetricsPacketsHandler extends AbstractRequestHandler { - private static final ObjectMapper jsonMapper = new ObjectMapper(); + private static final ObjectMapper jsonMapper = Jackson.mapper(); static final String APPLICATION_KEY = "application"; static final String TIMESTAMP_KEY = "timestamp"; @@ -226,8 +227,7 @@ public class MetricsPacketsHandler extends AbstractRequestHandler { MetricValue value = metric.getValue(); if (value instanceof CountMetric) { metrics.put(name + ".count", ((CountMetric) value).getCount()); - } else if (value instanceof GaugeMetric) { - GaugeMetric gauge = (GaugeMetric) value; + } else if (value instanceof GaugeMetric gauge) { metrics.put(name + ".average", sanitizeDouble(gauge.getAverage())) .put(name + ".last", sanitizeDouble(gauge.getLast())) .put(name + ".max", sanitizeDouble(gauge.getMax())) @@ -252,8 +252,7 @@ public class MetricsPacketsHandler extends AbstractRequestHandler { MetricValue value = metric.getValue(); if (value instanceof CountMetric) { metrics.put(name + ".count", ((CountMetric) value).getCount()); - } else if (value instanceof GaugeMetric) { - GaugeMetric gauge = (GaugeMetric) value; + } else if (value instanceof GaugeMetric gauge) { metrics.put(name + ".average", sanitizeDouble(gauge.getAverage())); metrics.put(name + ".last", sanitizeDouble(gauge.getLast())); metrics.put(name + ".max", sanitizeDouble(gauge.getMax())); @@ -262,7 +261,7 @@ public class MetricsPacketsHandler extends AbstractRequestHandler { metrics.put(name + ".count", gauge.getCount()); if (gauge.getPercentiles().isPresent()) { for (Tuple2<String, Double> prefixAndValue : gauge.getPercentiles().get()) { - metrics.put(name + "." + prefixAndValue.first + "percentile", prefixAndValue.second.doubleValue()); + metrics.put(name + "." + prefixAndValue.first + "percentile", prefixAndValue.second); } } } else { 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 045b13e5d63..281acfdce0f 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 @@ -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.container.jdisc.state; +import ai.vespa.json.Jackson; import ai.vespa.metrics.ContainerMetrics; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; @@ -45,7 +46,7 @@ import static com.yahoo.container.jdisc.state.JsonUtil.sanitizeDouble; */ public class StateHandler extends AbstractRequestHandler implements CapabilityRequiringRequestHandler { - private static final ObjectMapper jsonMapper = new ObjectMapper(); + private static final ObjectMapper jsonMapper = Jackson.mapper(); public static final String STATE_API_ROOT = "/state/v1"; private static final String METRICS_PATH = "metrics"; @@ -73,7 +74,7 @@ public class StateHandler extends AbstractRequestHandler implements CapabilityRe static SnapshotProvider getSnapshotProviderOrThrow(ComponentRegistry<SnapshotProvider> preprocessors) { List<SnapshotProvider> allPreprocessors = preprocessors.allComponents(); - if (allPreprocessors.size() > 0) { + if (!allPreprocessors.isEmpty()) { return allPreprocessors.get(0); } else { throw new IllegalArgumentException("At least one snapshot provider is required."); |