diff options
author | Valerij Fredriksen <valerijf@verizonmedia.com> | 2019-04-17 09:01:00 +0200 |
---|---|---|
committer | Valerij Fredriksen <valerijf@verizonmedia.com> | 2019-04-17 09:01:00 +0200 |
commit | a203b1b780f8fc7cd6794c16a81c0ddae8f2041e (patch) | |
tree | 534970478ffe9b23d2a1d434395bdd48fe2be007 /node-admin | |
parent | 5ab193575090efa10cc5aa07744ad457e1af973f (diff) |
Upgrade docker-java to 3.1.2
Diffstat (limited to 'node-admin')
2 files changed, 18 insertions, 31 deletions
diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImpl.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImpl.java index 57e504a6ffd..96db16bf1c1 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImpl.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImpl.java @@ -33,7 +33,6 @@ import com.yahoo.vespa.hosted.node.admin.util.SecretAgentCheckConfig; import java.util.ArrayList; import java.util.List; -import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.concurrent.atomic.AtomicBoolean; @@ -534,13 +533,13 @@ public class NodeAgentImpl implements NodeAgent { ContainerStats stats = containerStats.get(); final String APP = MetricReceiverWrapper.APPLICATION_NODE; - final int totalNumCpuCores = ((List<Number>) ((Map) stats.getCpuStats().get("cpu_usage")).get("percpu_usage")).size(); - final long cpuContainerKernelTime = ((Number) ((Map) stats.getCpuStats().get("cpu_usage")).get("usage_in_kernelmode")).longValue(); - final long cpuContainerTotalTime = ((Number) ((Map) stats.getCpuStats().get("cpu_usage")).get("total_usage")).longValue(); - final long cpuSystemTotalTime = ((Number) stats.getCpuStats().get("system_cpu_usage")).longValue(); - final long memoryTotalBytes = ((Number) stats.getMemoryStats().get("limit")).longValue(); - final long memoryTotalBytesUsage = ((Number) stats.getMemoryStats().get("usage")).longValue(); - final long memoryTotalBytesCache = ((Number) ((Map) stats.getMemoryStats().get("stats")).get("cache")).longValue(); + final int totalNumCpuCores = stats.getCpuStats().getOnlineCpus(); + final long cpuContainerKernelTime = stats.getCpuStats().getUsageInKernelMode(); + final long cpuContainerTotalTime = stats.getCpuStats().getTotalUsage(); + final long cpuSystemTotalTime = stats.getCpuStats().getSystemCpuUsage(); + final long memoryTotalBytes = stats.getMemoryStats().getLimit(); + final long memoryTotalBytesUsage = stats.getMemoryStats().getUsage(); + final long memoryTotalBytesCache = stats.getMemoryStats().getCache(); final long diskTotalBytes = (long) (node.getMinDiskAvailableGb() * BYTES_IN_GB); final Optional<Long> diskTotalBytesUsed = storageMaintainer.getDiskUsageFor(context); @@ -573,14 +572,13 @@ public class NodeAgentImpl implements NodeAgent { stats.getNetworks().forEach((interfaceName, interfaceStats) -> { Dimensions netDims = dimensionsBuilder.add("interface", interfaceName).build(); - Map<String, Number> infStats = (Map<String, Number>) interfaceStats; DimensionMetrics networkMetrics = new DimensionMetrics.Builder(APP, netDims) - .withMetric("net.in.bytes", infStats.get("rx_bytes").longValue()) - .withMetric("net.in.errors", infStats.get("rx_errors").longValue()) - .withMetric("net.in.dropped", infStats.get("rx_dropped").longValue()) - .withMetric("net.out.bytes", infStats.get("tx_bytes").longValue()) - .withMetric("net.out.errors", infStats.get("tx_errors").longValue()) - .withMetric("net.out.dropped", infStats.get("tx_dropped").longValue()) + .withMetric("net.in.bytes", interfaceStats.getRxBytes()) + .withMetric("net.in.errors", interfaceStats.getRxErrors()) + .withMetric("net.in.dropped", interfaceStats.getRxDropped()) + .withMetric("net.out.bytes", interfaceStats.getTxBytes()) + .withMetric("net.out.errors", interfaceStats.getTxErrors()) + .withMetric("net.out.dropped", interfaceStats.getTxDropped()) .build(); metrics.add(networkMetrics); }); diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImplTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImplTest.java index dcbbaf792a8..620c59969d6 100644 --- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImplTest.java +++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImplTest.java @@ -1,10 +1,10 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.hosted.node.admin.nodeagent; -import com.fasterxml.jackson.databind.ObjectMapper; import com.yahoo.component.Version; import com.yahoo.config.provision.DockerImage; import com.yahoo.config.provision.NodeType; +import com.yahoo.io.IOUtils; import com.yahoo.metrics.simple.MetricReceiver; import com.yahoo.vespa.flags.Flags; import com.yahoo.vespa.flags.InMemoryFlagSource; @@ -30,7 +30,7 @@ import com.yahoo.vespa.hosted.node.admin.nodeadmin.ConvergenceException; import org.junit.Test; import org.mockito.InOrder; -import java.net.URL; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -82,8 +82,6 @@ public class NodeAgentImplTest { private final MetricReceiverWrapper metricReceiver = new MetricReceiverWrapper(MetricReceiver.nullImplementation); private final AclMaintainer aclMaintainer = mock(AclMaintainer.class); private final HealthChecker healthChecker = mock(HealthChecker.class); - private final ContainerStats emptyContainerStats = new ContainerStats(Collections.emptyMap(), - Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap()); private final CredentialsMaintainer credentialsMaintainer = mock(CredentialsMaintainer.class); private final InMemoryFlagSource flagSource = new InMemoryFlagSource(); @@ -645,18 +643,10 @@ public class NodeAgentImplTest { @Test @SuppressWarnings("unchecked") public void testGetRelevantMetrics() throws Exception { - final ObjectMapper objectMapper = new ObjectMapper(); ClassLoader classLoader = getClass().getClassLoader(); - URL statsFile = classLoader.getResource("docker.stats.json"); - Map<String, Map<String, Object>> dockerStats = objectMapper.readValue(statsFile, Map.class); - - Map<String, Object> networks = dockerStats.get("networks"); - Map<String, Object> precpu_stats = dockerStats.get("precpu_stats"); - Map<String, Object> cpu_stats = dockerStats.get("cpu_stats"); - Map<String, Object> memory_stats = dockerStats.get("memory_stats"); - Map<String, Object> blkio_stats = dockerStats.get("blkio_stats"); - ContainerStats stats1 = new ContainerStats(networks, precpu_stats, memory_stats, blkio_stats); - ContainerStats stats2 = new ContainerStats(networks, cpu_stats, memory_stats, blkio_stats); + String json = IOUtils.readAll(classLoader.getResourceAsStream("docker.stats.json"), StandardCharsets.UTF_8); + ContainerStats stats2 = ContainerStats.fromJson(json); + ContainerStats stats1 = ContainerStats.fromJson(json.replace("\"cpu_stats\"", "\"cpu_stats2\"").replace("\"precpu_stats\"", "\"cpu_stats\"")); NodeOwner owner = new NodeOwner("tester", "testapp", "testinstance"); NodeMembership membership = new NodeMembership("clustType", "clustId", "grp", 3, false); @@ -759,7 +749,6 @@ public class NodeAgentImplTest { private NodeAgentImpl makeNodeAgent(DockerImage dockerImage, boolean isRunning) { mockGetContainer(dockerImage, isRunning); - when(dockerOperations.getContainerStats(any())).thenReturn(Optional.of(emptyContainerStats)); doNothing().when(storageMaintainer).writeMetricsConfig(any()); return new NodeAgentImpl(contextSupplier, nodeRepository, orchestrator, dockerOperations, |