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);
}
}
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;
}
Aggregations