Postgres/MySQL/MSSQL: Adds support for region annotations (#20752)

Adds support for region annotations in Postgres, MySQL and 
MSSQL data sources by adding a column named timeend to 
annotation query.

Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>

Closes #20918
Ref #10589
This commit is contained in:
Jerry Ylilammi
2019-12-13 18:25:36 +02:00
committed by Marcus Efraimsson
parent f65da93d72
commit e27ab89aed
13 changed files with 249 additions and 28 deletions

View File

@ -18,9 +18,10 @@
<div class="gf-form" ng-show="ctrl.showHelp">
<pre class="gf-form-pre alert alert-info"><h6>Annotation Query Format</h6>
An annotation is an event that is overlaid on top of graphs. The query can have up to three columns per row, the time column is mandatory. Annotation rendering is expensive so it is important to limit the number of rows returned.
An annotation is an event that is overlaid on top of graphs. The query can have up to four columns per row, the time column is mandatory. Annotation rendering is expensive so it is important to limit the number of rows returned.
- column with alias: <b>time</b> for the annotation event time. Use epoch time or any native date data type.
- column with alias: <b>timeend</b> for the annotation event time-end. Use epoch time or any native date data type.
- column with alias: <b>text</b> for the annotation text
- column with alias: <b>tags</b> for annotation tags. This is a comma separated string of tags e.g. 'tag1,tag2'

View File

@ -107,6 +107,7 @@ export default class ResponseParser {
const table = data.data.results[options.annotation.name].tables[0];
let timeColumnIndex = -1;
let timeEndColumnIndex = -1;
const titleColumnIndex = -1;
let textColumnIndex = -1;
let tagsColumnIndex = -1;
@ -114,6 +115,8 @@ export default class ResponseParser {
for (let i = 0; i < table.columns.length; i++) {
if (table.columns[i].text === 'time') {
timeColumnIndex = i;
} else if (table.columns[i].text === 'timeend') {
timeEndColumnIndex = i;
} else if (table.columns[i].text === 'text') {
textColumnIndex = i;
} else if (table.columns[i].text === 'tags') {
@ -130,9 +133,12 @@ export default class ResponseParser {
const list = [];
for (let i = 0; i < table.rows.length; i++) {
const row = table.rows[i];
const timeEnd =
timeEndColumnIndex !== -1 && row[timeEndColumnIndex] ? Math.floor(row[timeEndColumnIndex]) : undefined;
list.push({
annotation: options.annotation,
time: Math.floor(row[timeColumnIndex]),
timeEnd,
title: row[titleColumnIndex],
text: row[textColumnIndex],
tags: row[tagsColumnIndex] ? row[tagsColumnIndex].trim().split(/\s*,\s*/) : [],