Skip to content

Commit afa5393

Browse files
committed
fill null in Prometheus
1 parent a87b5f7 commit afa5393

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

public/app/plugins/datasource/prometheus/datasource.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ function (angular, _, moment, dateMath) {
9191
delete self.lastErrors.query;
9292

9393
_.each(response.data.data.result, function(metricData) {
94-
result.push(transformMetricData(metricData, options.targets[index]));
94+
result.push(transformMetricData(metricData, options.targets[index], start, end));
9595
});
9696
});
9797

@@ -207,28 +207,33 @@ function (angular, _, moment, dateMath) {
207207
return Math.ceil(sec * intervalFactor);
208208
};
209209

210-
function transformMetricData(md, options) {
210+
function transformMetricData(md, options, start, end) {
211211
var dps = [],
212212
metricLabel = null;
213213

214214
metricLabel = createMetricLabel(md.metric, options);
215215

216216
var stepMs = parseInt(options.step) * 1000;
217-
var lastTimestamp = null;
217+
var baseTimestamp = start * 1000;
218218
_.each(md.values, function(value) {
219219
var dp_value = parseFloat(value[1]);
220220
if (_.isNaN(dp_value)) {
221221
dp_value = null;
222222
}
223223

224224
var timestamp = value[0] * 1000;
225-
if (lastTimestamp && (timestamp - lastTimestamp) > stepMs) {
226-
dps.push([null, lastTimestamp + stepMs]);
225+
for (var t = baseTimestamp; t < timestamp; t += stepMs) {
226+
dps.push([null, t]);
227227
}
228-
lastTimestamp = timestamp;
228+
baseTimestamp = timestamp + stepMs;
229229
dps.push([dp_value, timestamp]);
230230
});
231231

232+
var endTimestamp = end * 1000;
233+
for (var t = baseTimestamp; t < endTimestamp; t += stepMs) {
234+
dps.push([null, t]);
235+
}
236+
232237
return { target: metricLabel, datapoints: dps };
233238
}
234239

0 commit comments

Comments
 (0)