use of org.openkilda.testing.service.otsdb.model.Aggregator in project open-kilda by telstra.
the class OtsdbQueryServiceImpl method query.
@Override
public StatsResult query(Date start, Date end, Aggregator aggregator, String metric, Map<String, Object> tags) {
UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromUriString("/api/query");
uriBuilder.queryParam("start", start.getTime());
uriBuilder.queryParam("end", end.getTime());
List<String> tagParts = tags.entrySet().stream().map(entry -> entry.getKey() + "=" + entry.getValue()).collect(toList());
String tagsString = "{" + String.join(",", tagParts) + "}";
uriBuilder.queryParam("m", String.format("%s:%s{tags}", aggregator.toString(), metric));
try {
StatsResult[] result = restTemplate.exchange(uriBuilder.build().toString(), HttpMethod.GET, new HttpEntity<>(new HttpHeaders()), StatsResult[].class, tagsString).getBody();
return result != null && result.length > 0 ? result[0] : new EmptyStatsResult();
} catch (HttpClientErrorException e) {
if (e.getStatusCode() == HttpStatus.BAD_REQUEST && e.getResponseBodyAsString().contains("net.opentsdb.tsd.BadRequestException: No such name for ")) {
return new EmptyStatsResult();
}
throw e;
}
}
Aggregations