mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
add annotation option to treat series value as timestamp
This commit is contained in:
parent
e4496080ff
commit
2926725bab
@ -487,15 +487,21 @@ export class PrometheusDatasource {
|
|||||||
.value();
|
.value();
|
||||||
|
|
||||||
for (const value of series.values) {
|
for (const value of series.values) {
|
||||||
if (value[1] === '1') {
|
const valueIsTrue = value[1] === '1'; // e.g. ALERTS
|
||||||
|
if (valueIsTrue || annotation.useValueForTime) {
|
||||||
const event = {
|
const event = {
|
||||||
annotation: annotation,
|
annotation: annotation,
|
||||||
time: Math.floor(parseFloat(value[0])) * 1000,
|
|
||||||
title: self.resultTransformer.renderTemplate(titleFormat, series.metric),
|
title: self.resultTransformer.renderTemplate(titleFormat, series.metric),
|
||||||
tags: tags,
|
tags: tags,
|
||||||
text: self.resultTransformer.renderTemplate(textFormat, series.metric),
|
text: self.resultTransformer.renderTemplate(textFormat, series.metric),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (annotation.useValueForTime) {
|
||||||
|
event['time'] = Math.floor(parseFloat(value[1]));
|
||||||
|
} else {
|
||||||
|
event['time'] = Math.floor(parseFloat(value[0])) * 1000;
|
||||||
|
}
|
||||||
|
|
||||||
eventList.push(event);
|
eventList.push(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="gf-form-group">
|
<div class="gf-form-group">
|
||||||
<h5 class="section-heading">Field formats</h6>
|
<h5 class="section-heading">Field formats</h5>
|
||||||
<div class="gf-form-inline">
|
<div class="gf-form-inline">
|
||||||
<div class="gf-form">
|
<div class="gf-form">
|
||||||
<span class="gf-form-label width-5">Title</span>
|
<span class="gf-form-label width-5">Title</span>
|
||||||
@ -27,4 +27,13 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<h5 class="section-heading">Other options</h5>
|
||||||
|
<div class="gf-form-inline">
|
||||||
|
<div class="gf-form">
|
||||||
|
<gf-form-switch class="gf-form" label="Series value as timestamp" label-class="width-14" checked="ctrl.annotation.useValueForTime"
|
||||||
|
tooltip="The unit of timestamp is milliseconds. If the unit of the series value is seconds, multiply its range vector by 1000.">
|
||||||
|
</gf-form-switch>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -630,6 +630,45 @@ describe('PrometheusDatasource', () => {
|
|||||||
expect(results[0].text).toBe('testinstance');
|
expect(results[0].text).toBe('testinstance');
|
||||||
expect(results[0].time).toBe(123 * 1000);
|
expect(results[0].time).toBe(123 * 1000);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should return annotation list with seriesValueAsTiemstamp', () => {
|
||||||
|
const options = {
|
||||||
|
annotation: {
|
||||||
|
expr: 'timestamp_seconds',
|
||||||
|
tagKeys: 'job',
|
||||||
|
titleFormat: '{{job}}',
|
||||||
|
textFormat: '{{instance}}',
|
||||||
|
useValueForTime: true,
|
||||||
|
},
|
||||||
|
range: {
|
||||||
|
from: new Date('2014-04-10T05:20:10Z'),
|
||||||
|
to: new Date('2014-05-20T03:10:22Z'),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
ctx.backendSrvMock.datasourceRequest.mockReturnValue(
|
||||||
|
Promise.resolve({
|
||||||
|
status: 'success',
|
||||||
|
data: {
|
||||||
|
resultType: 'matrix',
|
||||||
|
result: [
|
||||||
|
{
|
||||||
|
metric: {
|
||||||
|
__name__: 'timestamp_milliseconds',
|
||||||
|
instance: 'testinstance',
|
||||||
|
job: 'testjob',
|
||||||
|
},
|
||||||
|
values: [[1443454528, '1500000000000']],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
);
|
||||||
|
ctx.ds = new PrometheusDatasource(instanceSettings, q, ctx.backendSrvMock, ctx.templateSrvMock, ctx.timeSrvMock);
|
||||||
|
ctx.ds.annotationQuery(options).then(function (results) {
|
||||||
|
expect(results[0].time).toEqual(1500000000000);
|
||||||
|
ctx.backendSrvMock.datasourceRequest.mockReset();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('When resultFormat is table and instant = true', () => {
|
describe('When resultFormat is table and instant = true', () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user