@Override public String buildQuery(String metricsAccountName, CanaryConfig canaryConfig, CanaryMetricConfig canaryMetricConfig, CanaryScope canaryScope) throws IOException { GraphiteCanaryMetricSetQueryConfig queryConfig = (GraphiteCanaryMetricSetQueryConfig) canaryMetricConfig.getQuery(); String query = queryConfig.getMetricName(); if (!Strings.isNullOrEmpty(canaryScope.getScope())) { query = query.replace(SCOPE_VARIABLE, canaryScope.getScope()); } if (!Strings.isNullOrEmpty(canaryScope.getLocation())) { query = query.replace(LOCATION_VARIABLE, canaryScope.getLocation()); } log.debug("Query sent to graphite: {}.", query); return query; }
private CanaryMetricConfigWithResults queryMetric(CanaryMetricConfig metric, GraphiteCanaryScope scope) { Long step = 10L; Long start = scope.getStart().getEpochSecond() / step * step; Long end = scope.getEnd().getEpochSecond() / step * step; Long count = (end - start) / step; GraphiteCanaryMetricSetQueryConfig graphiteMetricSetQuery = (GraphiteCanaryMetricSetQueryConfig) metric.getQuery(); List<List<Double>> dataPoints = new LinkedList<>(); LongStream.range(0, count).forEach(i -> { Long time = (start + i * step); dataPoints.add(Lists.newArrayList((double) i, time.doubleValue())); }); GraphiteResults graphiteResults = GraphiteResults.builder() .target(graphiteMetricSetQuery.getMetricName() + "." + scope.getScope()) .datapoints(dataPoints).build(); return CanaryMetricConfigWithResults.builder() .canaryMetricConfig(metric) .graphiteResults(Collections.singletonList(graphiteResults)) .build(); }
@Override public String buildQuery(String metricsAccountName, CanaryConfig canaryConfig, CanaryMetricConfig canaryMetricConfig, CanaryScope canaryScope) throws IOException { GraphiteCanaryMetricSetQueryConfig queryConfig = (GraphiteCanaryMetricSetQueryConfig) canaryMetricConfig.getQuery(); String query = queryConfig.getMetricName(); if (!Strings.isNullOrEmpty(canaryScope.getScope())) { query = query.replace(SCOPE_VARIABLE, canaryScope.getScope()); } if (!Strings.isNullOrEmpty(canaryScope.getLocation())) { query = query.replace(LOCATION_VARIABLE, canaryScope.getLocation()); } log.debug("Query sent to graphite: {}.", query); return query; }