Search in sources :

Example 1 with PartialNodeResult

use of com.yahoo.vespa.hosted.controller.api.integration.chef.rest.PartialNodeResult in project vespa by vespa-engine.

the class MetricsReporterTest method createReporter.

private MetricsReporter createReporter(Clock clock, Controller controller, MetricsMock metricsMock, SystemName system) {
    Chef client = Mockito.mock(Chef.class);
    PartialNodeResult result;
    try {
        result = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).readValue(testData.resolve("chef_output.json").toFile(), PartialNodeResult.class);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    when(client.partialSearchNodes(anyString(), anyListOf(AttributeMapping.class))).thenReturn(result);
    return new MetricsReporter(controller, metricsMock, client, clock, new JobControl(new MockCuratorDb()), system);
}
Also used : PartialNodeResult(com.yahoo.vespa.hosted.controller.api.integration.chef.rest.PartialNodeResult) MockCuratorDb(com.yahoo.vespa.hosted.controller.persistence.MockCuratorDb) Chef(com.yahoo.vespa.hosted.controller.api.integration.chef.Chef) AttributeMapping(com.yahoo.vespa.hosted.controller.api.integration.chef.AttributeMapping) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with PartialNodeResult

use of com.yahoo.vespa.hosted.controller.api.integration.chef.rest.PartialNodeResult in project vespa by vespa-engine.

the class MetricsReporter method reportChefMetrics.

private void reportChefMetrics() {
    String query = "chef_environment:hosted*";
    if (system == SystemName.cd) {
        query += " AND hosted_system:" + system;
    }
    PartialNodeResult nodeResult = chefClient.partialSearchNodes(query, Arrays.asList(AttributeMapping.simpleMapping("fqdn"), AttributeMapping.simpleMapping("ohai_time"), AttributeMapping.deepMapping("tenant", Arrays.asList("hosted", "owner", "tenant")), AttributeMapping.deepMapping("application", Arrays.asList("hosted", "owner", "application")), AttributeMapping.deepMapping("instance", Arrays.asList("hosted", "owner", "instance")), AttributeMapping.deepMapping("environment", Arrays.asList("hosted", "environment")), AttributeMapping.deepMapping("region", Arrays.asList("hosted", "region")), AttributeMapping.deepMapping("system", Arrays.asList("hosted", "system"))));
    // The above search will return a correct list if the system is CD. However for main, it will
    // return all nodes, since system==nil for main
    keepNodesWithSystem(nodeResult, system);
    Instant instant = clock.instant();
    for (PartialNode node : nodeResult.rows) {
        String hostname = node.getFqdn();
        long secondsSinceConverge = Duration.between(Instant.ofEpochSecond(node.getOhaiTime().longValue()), instant).getSeconds();
        Map<String, String> dimensions = new HashMap<>();
        dimensions.put("host", hostname);
        dimensions.put("system", node.getValue("system").orElse("main"));
        Optional<String> environment = node.getValue("environment");
        Optional<String> region = node.getValue("region");
        if (environment.isPresent() && region.isPresent()) {
            dimensions.put("zone", String.format("%s.%s", environment.get(), region.get()));
        }
        node.getValue("tenant").ifPresent(tenant -> dimensions.put("tenantName", tenant));
        Optional<String> application = node.getValue("application");
        if (application.isPresent()) {
            dimensions.put("app", String.format("%s.%s", application.get(), node.getValue("instance").orElse("default")));
        }
        Metric.Context context = metric.createContext(dimensions);
        metric.set(convergeMetric, secondsSinceConverge, context);
    }
}
Also used : PartialNodeResult(com.yahoo.vespa.hosted.controller.api.integration.chef.rest.PartialNodeResult) HashMap(java.util.HashMap) Instant(java.time.Instant) Metric(com.yahoo.jdisc.Metric) PartialNode(com.yahoo.vespa.hosted.controller.api.integration.chef.rest.PartialNode)

Example 3 with PartialNodeResult

use of com.yahoo.vespa.hosted.controller.api.integration.chef.rest.PartialNodeResult in project vespa by vespa-engine.

the class ChefMock method partialSearchNodes.

@Override
public PartialNodeResult partialSearchNodes(String query, List<AttributeMapping> returnAttributes) {
    PartialNodeResult partialNodeResult = new PartialNodeResult();
    partialNodeResult.rows = result.rows.stream().map(chefNode -> {
        Map<String, String> data = new HashMap<>();
        data.put("fqdn", chefNode.name);
        return new PartialNode(data);
    }).collect(Collectors.toList());
    return partialNodeResult;
}
Also used : PartialNodeResult(com.yahoo.vespa.hosted.controller.api.integration.chef.rest.PartialNodeResult) HashMap(java.util.HashMap) PartialNode(com.yahoo.vespa.hosted.controller.api.integration.chef.rest.PartialNode)

Aggregations

PartialNodeResult (com.yahoo.vespa.hosted.controller.api.integration.chef.rest.PartialNodeResult)3 PartialNode (com.yahoo.vespa.hosted.controller.api.integration.chef.rest.PartialNode)2 HashMap (java.util.HashMap)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Metric (com.yahoo.jdisc.Metric)1 AttributeMapping (com.yahoo.vespa.hosted.controller.api.integration.chef.AttributeMapping)1 Chef (com.yahoo.vespa.hosted.controller.api.integration.chef.Chef)1 MockCuratorDb (com.yahoo.vespa.hosted.controller.persistence.MockCuratorDb)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 Instant (java.time.Instant)1