NodeMetricsDb { public NodeMetricsDb(NodeRepository nodeRepository) { this.nodeRepository = nodeRepository; } NodeMetricsDb(NodeRepository nodeRepository); void add(Collection<NodeMetrics.MetricValue> metricValues); void add(AutoscalingEvent event); void gc(Clock clock); List<NodeMeasurements> getMeasurements(Instant startTime, Metric metric, List<String> hostnames); List<AutoscalingEvent> getEvents(ApplicationId application);  }
@Test public void testNodeMetricsDb() { ProvisioningTester tester = new ProvisioningTester.Builder().build(); tester.makeReadyHosts(10, new NodeResources(10, 100, 1000, 10)) .activateTenantHosts(); ApplicationId app1 = ProvisioningTester.makeApplicationId("app1"); var hosts = tester.activate(app1, ClusterSpec.request(ClusterSpec.Type.container, ClusterSpec.Id.from("test")).vespaVersion("7.0").build(), Capacity.from(new ClusterResources(2, 1, new NodeResources(1, 4, 10, 1)))); String node0 = hosts.iterator().next().hostname(); ManualClock clock = tester.clock(); NodeMetricsDb db = new NodeMetricsDb(tester.nodeRepository()); List<NodeMetrics.MetricValue> values = new ArrayList<>(); for (int i = 0; i < 40; i++) { values.add(new NodeMetrics.MetricValue(node0, "cpu.util", clock.instant().getEpochSecond(), 0.9f)); clock.advance(Duration.ofMinutes(10)); } db.add(values); clock.advance(Duration.ofMinutes(1)); assertEquals(35, measurementCount(db.getMeasurements(clock.instant().minus(Duration.ofHours(6)), Metric.cpu, List.of(node0)))); assertEquals( 0, measurementCount(db.getMeasurements(clock.instant().minus(Duration.ofHours(6)), Metric.memory, List.of(node0)))); db.gc(clock); assertEquals( 5, measurementCount(db.getMeasurements(clock.instant().minus(Duration.ofHours(6)), Metric.cpu, List.of(node0)))); assertEquals( 0, measurementCount(db.getMeasurements(clock.instant().minus(Duration.ofHours(6)), Metric.memory, List.of(node0)))); }