Search in sources :

Example 1 with PartialNode

use of com.yahoo.vespa.hosted.controller.api.integration.chef.rest.PartialNode 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 2 with PartialNode

use of com.yahoo.vespa.hosted.controller.api.integration.chef.rest.PartialNode 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

PartialNode (com.yahoo.vespa.hosted.controller.api.integration.chef.rest.PartialNode)2 PartialNodeResult (com.yahoo.vespa.hosted.controller.api.integration.chef.rest.PartialNodeResult)2 HashMap (java.util.HashMap)2 Metric (com.yahoo.jdisc.Metric)1 Instant (java.time.Instant)1