com.netflix.kayenta.datadog.service.DatadogTimeSeries Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2018 Armory, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.netflix.kayenta.datadog.service;
import com.fasterxml.jackson.annotation.JsonIgnore;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Data
public class DatadogTimeSeries {
private List series;
@Data
public static class DatadogSeriesEntry {
private String scope;
private Long start;
private Long interval;
private Long end;
private List> pointlist;
// Datadog returns an array of timestamp/value pairs; the pairs are
// ordered, but may not be sequential (ie. may be a sparse result)
// Since Kayenta's MetricSet is storing a simple array, we need to
// convert this sparse list to a full array, and make sure we slot the
// values into the correct array indices.
@JsonIgnore private List adjustedPointList;
@JsonIgnore
private List getAdjustedPointList() {
if ((this.adjustedPointList != null) && (this.adjustedPointList.size() != 0)) {
// Already computed, just return.
return this.adjustedPointList;
}
// Start at time and index zero.
this.adjustedPointList = new ArrayList();
int idx = 0;
for (Long time = start; time <= end; time += this.interval * 1000) {
List point = pointlist.get(idx);
// If the point at this index matches the timestamp at this position,
// add the value to the array and advance the index.
if (point.get(0).longValue() == time) {
if (point.get(1) == null) {
this.adjustedPointList.add(Double.NaN);
} else {
this.adjustedPointList.add(point.get(1).doubleValue());
}
idx++;
} else {
// Otherwise, put in a NaN to represent the "gap" in the Datadog
// data.
this.adjustedPointList.add(Double.NaN);
}
}
return this.adjustedPointList;
}
@JsonIgnore
public Stream getDataPoints() {
return this.getAdjustedPointList().stream();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy