@Test public void test_registered_metric() { NodeFlavors nodeFlavors = FlavorConfigBuilder.createDummies("default"); Curator curator = new MockCurator(); NodeRepository nodeRepository = new NodeRepository(nodeFlavors, new EmptyProvisionServiceProvider().getHostResourcesCalculator(), curator, Clock.systemUTC(), Zone.defaultZone(), new MockNameResolver().mockAnyLookup(), DockerImage.fromString("docker-registry.domain.tld:8080/dist/vespa"), new InMemoryFlagSource(), true, false, 0, 1000); Node node = nodeRepository.createNode("openStackId", "hostname", Optional.empty(), nodeFlavors.getFlavorOrThrow("default"), NodeType.tenant); nodeRepository.addNodes(List.of(node), Agent.system); Node hostNode = nodeRepository.createNode("openStackId2", "parent", Optional.empty(), nodeFlavors.getFlavorOrThrow("default"), NodeType.proxy); nodeRepository.addNodes(List.of(hostNode), Agent.system); Map<String, Number> expectedMetrics = new TreeMap<>(); expectedMetrics.put("hostedVespa.provisionedHosts", 1); expectedMetrics.put("hostedVespa.parkedHosts", 0); expectedMetrics.put("hostedVespa.readyHosts", 0); expectedMetrics.put("hostedVespa.reservedHosts", 0); expectedMetrics.put("hostedVespa.activeHosts", 0); expectedMetrics.put("hostedVespa.inactiveHosts", 0); expectedMetrics.put("hostedVespa.dirtyHosts", 0); expectedMetrics.put("hostedVespa.failedHosts", 0); expectedMetrics.put("hostedVespa.deprovisionedHosts", 0); expectedMetrics.put("hostedVespa.pendingRedeployments", 42); expectedMetrics.put("hostedVespa.docker.totalCapacityDisk", 0.0); expectedMetrics.put("hostedVespa.docker.totalCapacityMem", 0.0); expectedMetrics.put("hostedVespa.docker.totalCapacityCpu", 0.0); expectedMetrics.put("hostedVespa.docker.freeCapacityDisk", 0.0); expectedMetrics.put("hostedVespa.docker.freeCapacityMem", 0.0); expectedMetrics.put("hostedVespa.docker.freeCapacityCpu", 0.0); expectedMetrics.put("wantedRebootGeneration", 0L); expectedMetrics.put("currentRebootGeneration", 0L); expectedMetrics.put("wantToReboot", 0); expectedMetrics.put("wantToRetire", 0); expectedMetrics.put("wantToDeprovision", 0); expectedMetrics.put("failReport", 0); expectedMetrics.put("allowedToBeDown", 1); expectedMetrics.put("suspended", 1); expectedMetrics.put("suspendedSeconds", 123L); expectedMetrics.put("numberOfServices", 0L); expectedMetrics.put("cache.nodeObject.hitRate", 0.6D); expectedMetrics.put("cache.nodeObject.evictionCount", 0L); expectedMetrics.put("cache.nodeObject.size", 2L); nodeRepository.list(); expectedMetrics.put("cache.curator.hitRate", 0.5D); expectedMetrics.put("cache.curator.evictionCount", 0L); expectedMetrics.put("cache.curator.size", 11L); ManualClock clock = new ManualClock(Instant.ofEpochSecond(124)); Orchestrator orchestrator = mock(Orchestrator.class); when(orchestrator.getHostInfo(eq(reference), any())).thenReturn( HostInfo.createSuspended(HostStatus.ALLOWED_TO_BE_DOWN, Instant.ofEpochSecond(1))); TestMetric metric = new TestMetric(); MetricsReporter metricsReporter = new MetricsReporter( nodeRepository, metric, orchestrator, serviceMonitor, () -> 42, Duration.ofMinutes(1), clock); metricsReporter.maintain(); verifyAndRemoveIntegerMetricSum(metric, "lockAttempt.acquire", 3); verifyAndRemoveIntegerMetricSum(metric, "lockAttempt.acquireFailed", 0); verifyAndRemoveIntegerMetricSum(metric, "lockAttempt.acquireTimedOut", 0); verifyAndRemoveIntegerMetricSum(metric, "lockAttempt.locked", 3); verifyAndRemoveIntegerMetricSum(metric, "lockAttempt.release", 3); verifyAndRemoveIntegerMetricSum(metric, "lockAttempt.releaseFailed", 0); metric.remove("lockAttempt.acquireLatency"); metric.remove("lockAttempt.acquireMaxActiveLatency"); metric.remove("lockAttempt.acquireHz"); metric.remove("lockAttempt.acquireLoad"); metric.remove("lockAttempt.lockedLatency"); metric.remove("lockAttempt.lockedMaxActiveLatency"); metric.remove("lockAttempt.lockedHz"); metric.remove("lockAttempt.lockedLoad"); assertEquals(expectedMetrics, new TreeMap<>(metric.values)); }
@Override public boolean maintain() { NodeList nodes = nodeRepository().list(); ServiceModel serviceModel = serviceMonitor.getServiceModelSnapshot(); updateLockMetrics(); nodes.forEach(node -> updateNodeMetrics(node, serviceModel)); updateStateMetrics(nodes); updateMaintenanceMetrics(); updateDockerMetrics(nodes); updateTenantUsageMetrics(nodes); updateCacheMetrics(); return true; }
MetricsReporter extends NodeRepositoryMaintainer { @Override public boolean maintain() { NodeList nodes = nodeRepository().list(); ServiceModel serviceModel = serviceMonitor.getServiceModelSnapshot(); updateLockMetrics(); nodes.forEach(node -> updateNodeMetrics(node, serviceModel)); updateStateMetrics(nodes); updateMaintenanceMetrics(); updateDockerMetrics(nodes); updateTenantUsageMetrics(nodes); updateCacheMetrics(); return true; } }
MetricsReporter extends NodeRepositoryMaintainer { @Override public boolean maintain() { NodeList nodes = nodeRepository().list(); ServiceModel serviceModel = serviceMonitor.getServiceModelSnapshot(); updateLockMetrics(); nodes.forEach(node -> updateNodeMetrics(node, serviceModel)); updateStateMetrics(nodes); updateMaintenanceMetrics(); updateDockerMetrics(nodes); updateTenantUsageMetrics(nodes); updateCacheMetrics(); return true; } MetricsReporter(NodeRepository nodeRepository,
                    Metric metric,
                    Orchestrator orchestrator,
                    ServiceMonitor serviceMonitor,
                    Supplier<Integer> pendingRedeploymentsSupplier,
                    Duration interval,
                    Clock clock); }
MetricsReporter extends NodeRepositoryMaintainer { @Override public boolean maintain() { NodeList nodes = nodeRepository().list(); ServiceModel serviceModel = serviceMonitor.getServiceModelSnapshot(); updateLockMetrics(); nodes.forEach(node -> updateNodeMetrics(node, serviceModel)); updateStateMetrics(nodes); updateMaintenanceMetrics(); updateDockerMetrics(nodes); updateTenantUsageMetrics(nodes); updateCacheMetrics(); return true; } MetricsReporter(NodeRepository nodeRepository,
                    Metric metric,
                    Orchestrator orchestrator,
                    ServiceMonitor serviceMonitor,
                    Supplier<Integer> pendingRedeploymentsSupplier,
                    Duration interval,
                    Clock clock); @Override boolean maintain(); }
MetricsReporter extends NodeRepositoryMaintainer { @Override public boolean maintain() { NodeList nodes = nodeRepository().list(); ServiceModel serviceModel = serviceMonitor.getServiceModelSnapshot(); updateLockMetrics(); nodes.forEach(node -> updateNodeMetrics(node, serviceModel)); updateStateMetrics(nodes); updateMaintenanceMetrics(); updateDockerMetrics(nodes); updateTenantUsageMetrics(nodes); updateCacheMetrics(); return true; } MetricsReporter(NodeRepository nodeRepository,
                    Metric metric,
                    Orchestrator orchestrator,
                    ServiceMonitor serviceMonitor,
                    Supplier<Integer> pendingRedeploymentsSupplier,
                    Duration interval,
                    Clock clock); @Override boolean maintain();  }