Search in sources :

Example 1 with ServiceMonitor

use of com.yahoo.vespa.service.monitor.ServiceMonitor in project vespa by vespa-engine.

the class MetricsReporterTest method test_registered_metric.

@Test
public void test_registered_metric() throws Exception {
    NodeFlavors nodeFlavors = FlavorConfigBuilder.createDummies("default");
    Curator curator = new MockCurator();
    NodeRepository nodeRepository = new NodeRepository(nodeFlavors, curator, Clock.systemUTC(), Zone.defaultZone(), new MockNameResolver().mockAnyLookup(), new DockerImage("docker-registry.domain.tld:8080/dist/vespa"), true);
    Node node = nodeRepository.createNode("openStackId", "hostname", Optional.empty(), nodeFlavors.getFlavorOrThrow("default"), NodeType.tenant);
    nodeRepository.addNodes(Collections.singletonList(node));
    Node hostNode = nodeRepository.createNode("openStackId2", "parent", Optional.empty(), nodeFlavors.getFlavorOrThrow("default"), NodeType.proxy);
    nodeRepository.addNodes(Collections.singletonList(hostNode));
    Map<String, Number> expectedMetrics = new HashMap<>();
    expectedMetrics.put("hostedVespa.provisionedHosts", 1L);
    expectedMetrics.put("hostedVespa.parkedHosts", 0L);
    expectedMetrics.put("hostedVespa.readyHosts", 0L);
    expectedMetrics.put("hostedVespa.reservedHosts", 0L);
    expectedMetrics.put("hostedVespa.activeHosts", 0L);
    expectedMetrics.put("hostedVespa.inactiveHosts", 0L);
    expectedMetrics.put("hostedVespa.dirtyHosts", 0L);
    expectedMetrics.put("hostedVespa.failedHosts", 0L);
    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("hardwareFailure", 0);
    expectedMetrics.put("hardwareDivergence", 0);
    expectedMetrics.put("allowedToBeDown", 0);
    expectedMetrics.put("numberOfServices", 0L);
    Orchestrator orchestrator = mock(Orchestrator.class);
    ServiceMonitor serviceMonitor = mock(ServiceMonitor.class);
    when(orchestrator.getNodeStatus(any())).thenReturn(HostStatus.NO_REMARKS);
    ServiceModel serviceModel = mock(ServiceModel.class);
    when(serviceMonitor.getServiceModelSnapshot()).thenReturn(serviceModel);
    when(serviceModel.getServiceInstancesByHostName()).thenReturn(Collections.emptyMap());
    TestMetric metric = new TestMetric();
    MetricsReporter metricsReporter = new MetricsReporter(nodeRepository, metric, orchestrator, serviceMonitor, Duration.ofMinutes(1), new JobControl(nodeRepository.database()));
    metricsReporter.maintain();
    assertEquals(expectedMetrics, metric.values);
}
Also used : MockNameResolver(com.yahoo.vespa.hosted.provision.testutils.MockNameResolver) HashMap(java.util.HashMap) Node(com.yahoo.vespa.hosted.provision.Node) JobControl(com.yahoo.vespa.hosted.provision.maintenance.JobControl) Curator(com.yahoo.vespa.curator.Curator) MockCurator(com.yahoo.vespa.curator.mock.MockCurator) Orchestrator(com.yahoo.vespa.orchestrator.Orchestrator) ServiceMonitor(com.yahoo.vespa.service.monitor.ServiceMonitor) NodeFlavors(com.yahoo.config.provision.NodeFlavors) ServiceModel(com.yahoo.vespa.service.monitor.ServiceModel) MetricsReporter(com.yahoo.vespa.hosted.provision.maintenance.MetricsReporter) NodeRepository(com.yahoo.vespa.hosted.provision.NodeRepository) DockerImage(com.yahoo.config.provision.DockerImage) MockCurator(com.yahoo.vespa.curator.mock.MockCurator) Test(org.junit.Test)

Example 2 with ServiceMonitor

use of com.yahoo.vespa.service.monitor.ServiceMonitor in project vespa by vespa-engine.

the class MetricsReporterTest method docker_metrics.

@Test
public void docker_metrics() throws Exception {
    NodeFlavors nodeFlavors = FlavorConfigBuilder.createDummies("host", "docker", "docker2");
    Curator curator = new MockCurator();
    NodeRepository nodeRepository = new NodeRepository(nodeFlavors, curator, Clock.systemUTC(), Zone.defaultZone(), new MockNameResolver().mockAnyLookup(), new DockerImage("docker-registry.domain.tld:8080/dist/vespa"), true);
    // Allow 4 containers
    Set<String> additionalIps = new HashSet<>();
    additionalIps.add("::2");
    additionalIps.add("::3");
    additionalIps.add("::4");
    additionalIps.add("::5");
    Node dockerHost = Node.create("openStackId1", Collections.singleton("::1"), additionalIps, "dockerHost", Optional.empty(), nodeFlavors.getFlavorOrThrow("host"), NodeType.host);
    nodeRepository.addNodes(Collections.singletonList(dockerHost));
    nodeRepository.setDirty("dockerHost", Agent.system, getClass().getSimpleName());
    nodeRepository.setReady("dockerHost", Agent.system, getClass().getSimpleName());
    Node container1 = Node.createDockerNode("openStackId1:1", Collections.singleton("::2"), Collections.emptySet(), "container1", Optional.of("dockerHost"), nodeFlavors.getFlavorOrThrow("docker"), NodeType.tenant);
    container1 = container1.with(allocation(Optional.of("app1")).get());
    nodeRepository.addDockerNodes(Collections.singletonList(container1));
    Node container2 = Node.createDockerNode("openStackId1:2", Collections.singleton("::3"), Collections.emptySet(), "container2", Optional.of("dockerHost"), nodeFlavors.getFlavorOrThrow("docker2"), NodeType.tenant);
    container2 = container2.with(allocation(Optional.of("app2")).get());
    nodeRepository.addDockerNodes(Collections.singletonList(container2));
    Orchestrator orchestrator = mock(Orchestrator.class);
    ServiceMonitor serviceMonitor = mock(ServiceMonitor.class);
    when(orchestrator.getNodeStatus(any())).thenReturn(HostStatus.NO_REMARKS);
    ServiceModel serviceModel = mock(ServiceModel.class);
    when(serviceMonitor.getServiceModelSnapshot()).thenReturn(serviceModel);
    when(serviceModel.getServiceInstancesByHostName()).thenReturn(Collections.emptyMap());
    TestMetric metric = new TestMetric();
    MetricsReporter metricsReporter = new MetricsReporter(nodeRepository, metric, orchestrator, serviceMonitor, Duration.ofMinutes(1), new JobControl(nodeRepository.database()));
    metricsReporter.maintain();
    assertEquals(0L, metric.values.get("hostedVespa.readyHosts"));
    /**
     * Only tenants counts *
     */
    assertEquals(2L, metric.values.get("hostedVespa.reservedHosts"));
    assertEquals(12.0, metric.values.get("hostedVespa.docker.totalCapacityDisk"));
    assertEquals(10.0, metric.values.get("hostedVespa.docker.totalCapacityMem"));
    assertEquals(7.0, metric.values.get("hostedVespa.docker.totalCapacityCpu"));
    assertEquals(6.0, metric.values.get("hostedVespa.docker.freeCapacityDisk"));
    assertEquals(3.0, metric.values.get("hostedVespa.docker.freeCapacityMem"));
    assertEquals(4.0, metric.values.get("hostedVespa.docker.freeCapacityCpu"));
    assertContext(metric, "hostedVespa.docker.freeCapacityFlavor", 1, 0);
    assertContext(metric, "hostedVespa.docker.idealHeadroomFlavor", 0, 0);
    assertContext(metric, "hostedVespa.docker.hostsAvailableFlavor", 1l, 0l);
}
Also used : MockNameResolver(com.yahoo.vespa.hosted.provision.testutils.MockNameResolver) Node(com.yahoo.vespa.hosted.provision.Node) JobControl(com.yahoo.vespa.hosted.provision.maintenance.JobControl) Curator(com.yahoo.vespa.curator.Curator) MockCurator(com.yahoo.vespa.curator.mock.MockCurator) Orchestrator(com.yahoo.vespa.orchestrator.Orchestrator) ServiceMonitor(com.yahoo.vespa.service.monitor.ServiceMonitor) NodeFlavors(com.yahoo.config.provision.NodeFlavors) ServiceModel(com.yahoo.vespa.service.monitor.ServiceModel) MetricsReporter(com.yahoo.vespa.hosted.provision.maintenance.MetricsReporter) NodeRepository(com.yahoo.vespa.hosted.provision.NodeRepository) DockerImage(com.yahoo.config.provision.DockerImage) MockCurator(com.yahoo.vespa.curator.mock.MockCurator) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

DockerImage (com.yahoo.config.provision.DockerImage)2 NodeFlavors (com.yahoo.config.provision.NodeFlavors)2 Curator (com.yahoo.vespa.curator.Curator)2 MockCurator (com.yahoo.vespa.curator.mock.MockCurator)2 Node (com.yahoo.vespa.hosted.provision.Node)2 NodeRepository (com.yahoo.vespa.hosted.provision.NodeRepository)2 JobControl (com.yahoo.vespa.hosted.provision.maintenance.JobControl)2 MetricsReporter (com.yahoo.vespa.hosted.provision.maintenance.MetricsReporter)2 MockNameResolver (com.yahoo.vespa.hosted.provision.testutils.MockNameResolver)2 Orchestrator (com.yahoo.vespa.orchestrator.Orchestrator)2 ServiceModel (com.yahoo.vespa.service.monitor.ServiceModel)2 ServiceMonitor (com.yahoo.vespa.service.monitor.ServiceMonitor)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1