diff options
author | andreer <andreer@verizonmedia.com> | 2019-03-29 11:31:21 +0100 |
---|---|---|
committer | andreer <andreer@verizonmedia.com> | 2019-03-29 11:48:03 +0100 |
commit | 5609e38927a64e5e1163919ea852c007be1bcaeb (patch) | |
tree | 4aaa7f72e8dcba4f2e05fca4e2b98352c42879b5 /controller-server | |
parent | f7e0b3c5c58c6db87fc59f0dc6995b57e4fc2dae (diff) |
add basic metrics to metering
Diffstat (limited to 'controller-server')
3 files changed, 25 insertions, 9 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ControllerMaintenance.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ControllerMaintenance.java index da0eedbdd36..506231f086b 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ControllerMaintenance.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ControllerMaintenance.java @@ -86,7 +86,7 @@ public class ControllerMaintenance extends AbstractComponent { contactInformationMaintainer = new ContactInformationMaintainer(controller, Duration.ofHours(12), jobControl, contactRetriever); costReportMaintainer = new CostReportMaintainer(controller, Duration.ofHours(2), reportConsumer, jobControl, nodeRepositoryClient, Clock.systemUTC(), selfHostedCostConfig); routingPolicyMaintainer = new RoutingPolicyMaintainer(controller, Duration.ofMinutes(5), jobControl, nameService, curator); - resourceMeterMaintainer = new ResourceMeterMaintainer(controller, Duration.ofMinutes(5), jobControl, nodeRepositoryClient, Clock.systemUTC(), resourceSnapshotConsumer); + resourceMeterMaintainer = new ResourceMeterMaintainer(controller, Duration.ofMinutes(5), jobControl, nodeRepositoryClient, Clock.systemUTC(), metric, resourceSnapshotConsumer); } public Upgrader upgrader() { return upgrader; } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ResourceMeterMaintainer.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ResourceMeterMaintainer.java index d9bd3e8131b..5ed7a14836e 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ResourceMeterMaintainer.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ResourceMeterMaintainer.java @@ -2,6 +2,7 @@ package com.yahoo.vespa.hosted.controller.maintenance; import com.yahoo.config.provision.SystemName; +import com.yahoo.jdisc.Metric; import com.yahoo.vespa.hosted.controller.Controller; import com.yahoo.config.provision.ApplicationId; import com.yahoo.vespa.hosted.controller.api.integration.noderepository.NodeOwner; @@ -14,11 +15,7 @@ import com.yahoo.vespa.hosted.controller.api.integration.resource.ResourceAlloca import java.time.Clock; import java.time.Duration; import java.time.Instant; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.stream.Collectors; import static com.yahoo.yolean.Exceptions.uncheck; @@ -26,23 +23,31 @@ import static com.yahoo.yolean.Exceptions.uncheck; /** * Creates a ResourceSnapshot per application, which is then passed on to a ResourceSnapshotConsumer * TODO: Write JSON blob of node repo somewhere + * * @author olaa */ public class ResourceMeterMaintainer extends Maintainer { private final Clock clock; + private final Metric metric; private final NodeRepositoryClientInterface nodeRepository; private final ResourceSnapshotConsumer resourceSnapshotConsumer; + private static final String metering_last_reported = "metering_last_reported"; + private static final String metering_total_reported = "metering_total_reported"; + + @SuppressWarnings("WeakerAccess") public ResourceMeterMaintainer(Controller controller, Duration interval, JobControl jobControl, NodeRepositoryClientInterface nodeRepository, Clock clock, + Metric metric, ResourceSnapshotConsumer resourceSnapshotConsumer) { super(controller, interval, jobControl, ResourceMeterMaintainer.class.getSimpleName(), Set.of(SystemName.cd)); this.clock = clock; this.nodeRepository = nodeRepository; + this.metric = metric; this.resourceSnapshotConsumer = resourceSnapshotConsumer; } @@ -61,6 +66,13 @@ public class ResourceMeterMaintainer extends Maintainer { resourceSnapshotConsumer.consume(resourceSnapshots); + + metric.set(metering_last_reported, clock.millis() / 1000, metric.createContext(Collections.emptyMap())); + metric.set(metering_total_reported, resourceSnapshots.values().stream() + .map(ResourceSnapshot::getResourceAllocation) + .mapToDouble(r -> r.getCpuCores() + r.getMemoryGb() + r.getDiskGb()) // total metered resource usage, for alerting on drastic changes + .sum() + , metric.createContext(Collections.emptyMap())); } private List<NodeRepositoryNode> getNodes() { diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/ResourceMeterMaintainerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/ResourceMeterMaintainerTest.java index 14c75e791a5..df2a4b5ca7f 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/ResourceMeterMaintainerTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/ResourceMeterMaintainerTest.java @@ -6,6 +6,7 @@ import com.yahoo.config.provision.ApplicationId; import com.yahoo.vespa.hosted.controller.api.integration.resource.ResourceSnapshot; import com.yahoo.vespa.hosted.controller.api.integration.stubs.MockResourceSnapshotConsumer; import com.yahoo.vespa.hosted.controller.integration.NodeRepositoryClientMock; +import com.yahoo.vespa.hosted.controller.integration.MetricsMock; import org.junit.Test; import java.time.Duration; @@ -19,13 +20,14 @@ import static org.junit.Assert.*; public class ResourceMeterMaintainerTest { private final double DELTA = Double.MIN_VALUE; - NodeRepositoryClientMock nodeRepository = new NodeRepositoryClientMock(); - MockResourceSnapshotConsumer snapshotConsumer = new MockResourceSnapshotConsumer(); + private NodeRepositoryClientMock nodeRepository = new NodeRepositoryClientMock(); + private MockResourceSnapshotConsumer snapshotConsumer = new MockResourceSnapshotConsumer(); + private MetricsMock metrics = new MetricsMock(); @Test public void testMaintainer() { ControllerTester tester = new ControllerTester(); - ResourceMeterMaintainer resourceMeterMaintainer = new ResourceMeterMaintainer(tester.controller(), Duration.ofMinutes(5), new JobControl(tester.curator()), nodeRepository, tester.clock(), snapshotConsumer); + ResourceMeterMaintainer resourceMeterMaintainer = new ResourceMeterMaintainer(tester.controller(), Duration.ofMinutes(5), new JobControl(tester.curator()), nodeRepository, tester.clock(), metrics, snapshotConsumer); resourceMeterMaintainer.maintain(); Map<ApplicationId, ResourceSnapshot> consumedResources = snapshotConsumer.consumedResources(); @@ -42,5 +44,7 @@ public class ResourceMeterMaintainerTest { assertEquals(96, app2.getResourceAllocation().getMemoryGb(), DELTA); assertEquals(2000, app2.getResourceAllocation().getDiskGb(), DELTA); + assertEquals(tester.clock().millis()/1000, metrics.getMetric("metering_last_reported")); + assertEquals(4448.0d, (Double) metrics.getMetric("metering_total_reported"), DELTA); } }
\ No newline at end of file |