Commit e27ab89a by Jerry Ylilammi Committed by Marcus Efraimsson

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
parent f65da93d
...@@ -4,11 +4,37 @@ ...@@ -4,11 +4,37 @@
{ {
"builtIn": 1, "builtIn": 1,
"datasource": "-- Grafana --", "datasource": "-- Grafana --",
"enable": true, "enable": false,
"hide": true, "hide": true,
"iconColor": "rgba(0, 211, 255, 1)", "iconColor": "rgba(0, 211, 255, 1)",
"limit": 100,
"name": "Annotations & Alerts", "name": "Annotations & Alerts",
"showIn": 0,
"type": "dashboard" "type": "dashboard"
},
{
"datasource": "gdev-mssql",
"enable": false,
"hide": false,
"iconColor": "rgba(0, 211, 255, 1)",
"limit": 100,
"name": "Single",
"rawQuery": "SELECT TOP 1\n createdAt as time,\n 'single' as text,\n hostname as tags\nFROM\n grafana_metric\nWHERE\n $__timeFilter(createdAt)\nORDER BY time\n",
"showIn": 0,
"tags": [],
"type": "tags"
},
{
"datasource": "gdev-mssql",
"enable": false,
"hide": false,
"iconColor": "rgba(0, 211, 255, 1)",
"limit": 100,
"name": "Region",
"rawQuery": "SELECT TOP 1\n DATEADD(MINUTE, 1, createdAt) as time,\n DATEADD(MINUTE, 6, createdAt) as timeend,\n 'region' as text,\n hostname as tags\nFROM\n grafana_metric\nWHERE\n $__timeFilter(createdAt)\nORDER BY time",
"showIn": 0,
"tags": [],
"type": "tags"
} }
] ]
}, },
...@@ -16,7 +42,7 @@ ...@@ -16,7 +42,7 @@
"editable": true, "editable": true,
"gnetId": null, "gnetId": null,
"graphTooltip": 0, "graphTooltip": 0,
"iteration": 1532618661457, "iteration": 1576251075020,
"links": [], "links": [],
"panels": [ "panels": [
{ {
...@@ -28,12 +54,14 @@ ...@@ -28,12 +54,14 @@
"dashes": false, "dashes": false,
"datasource": "gdev-mssql", "datasource": "gdev-mssql",
"fill": 2, "fill": 2,
"fillGradient": 0,
"gridPos": { "gridPos": {
"h": 9, "h": 9,
"w": 12, "w": 12,
"x": 0, "x": 0,
"y": 0 "y": 0
}, },
"hiddenSeries": false,
"id": 2, "id": 2,
"legend": { "legend": {
"avg": false, "avg": false,
...@@ -48,6 +76,9 @@ ...@@ -48,6 +76,9 @@
"linewidth": 2, "linewidth": 2,
"links": [], "links": [],
"nullPointMode": "null", "nullPointMode": "null",
"options": {
"dataLinks": []
},
"percentage": false, "percentage": false,
"pointradius": 5, "pointradius": 5,
"points": false, "points": false,
...@@ -79,6 +110,7 @@ ...@@ -79,6 +110,7 @@
], ],
"thresholds": [], "thresholds": [],
"timeFrom": null, "timeFrom": null,
"timeRegions": [],
"timeShift": null, "timeShift": null,
"title": "Average logins / $summarize", "title": "Average logins / $summarize",
"tooltip": { "tooltip": {
...@@ -125,12 +157,14 @@ ...@@ -125,12 +157,14 @@
"dashes": false, "dashes": false,
"datasource": "gdev-mssql", "datasource": "gdev-mssql",
"fill": 2, "fill": 2,
"fillGradient": 0,
"gridPos": { "gridPos": {
"h": 18, "h": 18,
"w": 12, "w": 12,
"x": 12, "x": 12,
"y": 0 "y": 0
}, },
"hiddenSeries": false,
"id": 8, "id": 8,
"legend": { "legend": {
"avg": false, "avg": false,
...@@ -145,6 +179,9 @@ ...@@ -145,6 +179,9 @@
"linewidth": 2, "linewidth": 2,
"links": [], "links": [],
"nullPointMode": "null", "nullPointMode": "null",
"options": {
"dataLinks": []
},
"percentage": false, "percentage": false,
"pointradius": 5, "pointradius": 5,
"points": false, "points": false,
...@@ -169,6 +206,7 @@ ...@@ -169,6 +206,7 @@
], ],
"thresholds": [], "thresholds": [],
"timeFrom": null, "timeFrom": null,
"timeRegions": [],
"timeShift": null, "timeShift": null,
"title": "Average payments started/ended / $summarize", "title": "Average payments started/ended / $summarize",
"tooltip": { "tooltip": {
...@@ -214,12 +252,14 @@ ...@@ -214,12 +252,14 @@
"dashes": false, "dashes": false,
"datasource": "gdev-mssql", "datasource": "gdev-mssql",
"fill": 2, "fill": 2,
"fillGradient": 0,
"gridPos": { "gridPos": {
"h": 9, "h": 9,
"w": 12, "w": 12,
"x": 0, "x": 0,
"y": 9 "y": 9
}, },
"hiddenSeries": false,
"id": 6, "id": 6,
"legend": { "legend": {
"avg": false, "avg": false,
...@@ -234,6 +274,9 @@ ...@@ -234,6 +274,9 @@
"linewidth": 2, "linewidth": 2,
"links": [], "links": [],
"nullPointMode": "null", "nullPointMode": "null",
"options": {
"dataLinks": []
},
"percentage": false, "percentage": false,
"pointradius": 5, "pointradius": 5,
"points": false, "points": false,
...@@ -252,6 +295,7 @@ ...@@ -252,6 +295,7 @@
], ],
"thresholds": [], "thresholds": [],
"timeFrom": null, "timeFrom": null,
"timeRegions": [],
"timeShift": null, "timeShift": null,
"title": "Max CPU / $summarize", "title": "Max CPU / $summarize",
"tooltip": { "tooltip": {
...@@ -302,6 +346,7 @@ ...@@ -302,6 +346,7 @@
}, },
"id": 4, "id": 4,
"links": [], "links": [],
"options": {},
"pageSize": null, "pageSize": null,
"scroll": true, "scroll": true,
"showHeader": true, "showHeader": true,
...@@ -340,15 +385,19 @@ ...@@ -340,15 +385,19 @@
"type": "table" "type": "table"
} }
], ],
"schemaVersion": 16, "schemaVersion": 21,
"style": "dark", "style": "dark",
"tags": ["gdev", "mssql", "datasource-test"], "tags": ["gdev", "mssql", "datasource-test"],
"templating": { "templating": {
"list": [ "list": [
{ {
"allValue": null, "allValue": null,
"current": {}, "current": {
"text": "Africa",
"value": "Africa"
},
"datasource": "gdev-mssql", "datasource": "gdev-mssql",
"definition": "",
"hide": 0, "hide": 0,
"includeAll": false, "includeAll": false,
"label": "Datacenter", "label": "Datacenter",
...@@ -368,8 +417,13 @@ ...@@ -368,8 +417,13 @@
}, },
{ {
"allValue": null, "allValue": null,
"current": {}, "current": {
"selected": false,
"text": "All",
"value": "$__all"
},
"datasource": "gdev-mssql", "datasource": "gdev-mssql",
"definition": "",
"hide": 0, "hide": 0,
"includeAll": true, "includeAll": true,
"label": "Hostname", "label": "Hostname",
...@@ -392,6 +446,7 @@ ...@@ -392,6 +446,7 @@
"auto_count": 30, "auto_count": 30,
"auto_min": "10s", "auto_min": "10s",
"current": { "current": {
"selected": false,
"text": "1m", "text": "1m",
"value": "1m" "value": "1m"
}, },
...@@ -488,5 +543,5 @@ ...@@ -488,5 +543,5 @@
"timezone": "", "timezone": "",
"title": "Datasource tests - MSSQL", "title": "Datasource tests - MSSQL",
"uid": "86Js1xRmk", "uid": "86Js1xRmk",
"version": 1 "version": 2
} }
...@@ -4,11 +4,35 @@ ...@@ -4,11 +4,35 @@
{ {
"builtIn": 1, "builtIn": 1,
"datasource": "-- Grafana --", "datasource": "-- Grafana --",
"enable": true, "enable": false,
"hide": true, "hide": true,
"iconColor": "rgba(0, 211, 255, 1)", "iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts", "name": "Annotations & Alerts",
"type": "dashboard" "type": "dashboard"
},
{
"datasource": "gdev-mysql",
"enable": false,
"hide": false,
"iconColor": "rgba(0, 211, 255, 1)",
"limit": 100,
"name": "Single",
"rawQuery": "SELECT\n createdAt as time,\n 'single' as text,\n hostname as tags\nFROM\n grafana_metric\nWHERE\n $__timeFilter(createdAt)\nORDER BY time\nLIMIT 1\n",
"showIn": 0,
"tags": [],
"type": "tags"
},
{
"datasource": "gdev-mysql",
"enable": false,
"hide": false,
"iconColor": "rgba(0, 211, 255, 1)",
"limit": 100,
"name": "Region",
"rawQuery": "SELECT\n ADDTIME(createdAt, '00:01:00') as time,\n ADDTIME(createdAt, '00:06:00') as timeend,\n 'region' as text,\n hostname as tags\nFROM\n grafana_metric\nWHERE\n $__timeFilter(createdAt)\nORDER BY time\nLIMIT 1\n",
"showIn": 0,
"tags": [],
"type": "tags"
} }
] ]
}, },
...@@ -16,7 +40,7 @@ ...@@ -16,7 +40,7 @@
"editable": true, "editable": true,
"gnetId": null, "gnetId": null,
"graphTooltip": 0, "graphTooltip": 0,
"iteration": 1532620738041, "iteration": 1576250298312,
"links": [], "links": [],
"panels": [ "panels": [
{ {
...@@ -28,12 +52,14 @@ ...@@ -28,12 +52,14 @@
"dashes": false, "dashes": false,
"datasource": "gdev-mysql", "datasource": "gdev-mysql",
"fill": 2, "fill": 2,
"fillGradient": 0,
"gridPos": { "gridPos": {
"h": 9, "h": 9,
"w": 12, "w": 12,
"x": 0, "x": 0,
"y": 0 "y": 0
}, },
"hiddenSeries": false,
"id": 2, "id": 2,
"legend": { "legend": {
"avg": false, "avg": false,
...@@ -48,6 +74,9 @@ ...@@ -48,6 +74,9 @@
"linewidth": 2, "linewidth": 2,
"links": [], "links": [],
"nullPointMode": "null", "nullPointMode": "null",
"options": {
"dataLinks": []
},
"percentage": false, "percentage": false,
"pointradius": 5, "pointradius": 5,
"points": false, "points": false,
...@@ -81,6 +110,7 @@ ...@@ -81,6 +110,7 @@
], ],
"thresholds": [], "thresholds": [],
"timeFrom": null, "timeFrom": null,
"timeRegions": [],
"timeShift": null, "timeShift": null,
"title": "Average logins / $summarize", "title": "Average logins / $summarize",
"tooltip": { "tooltip": {
...@@ -126,12 +156,14 @@ ...@@ -126,12 +156,14 @@
"dashes": false, "dashes": false,
"datasource": "gdev-mysql", "datasource": "gdev-mysql",
"fill": 2, "fill": 2,
"fillGradient": 0,
"gridPos": { "gridPos": {
"h": 18, "h": 18,
"w": 12, "w": 12,
"x": 12, "x": 12,
"y": 0 "y": 0
}, },
"hiddenSeries": false,
"id": 4, "id": 4,
"legend": { "legend": {
"avg": false, "avg": false,
...@@ -146,6 +178,9 @@ ...@@ -146,6 +178,9 @@
"linewidth": 2, "linewidth": 2,
"links": [], "links": [],
"nullPointMode": "null", "nullPointMode": "null",
"options": {
"dataLinks": []
},
"percentage": false, "percentage": false,
"pointradius": 5, "pointradius": 5,
"points": false, "points": false,
...@@ -171,6 +206,7 @@ ...@@ -171,6 +206,7 @@
], ],
"thresholds": [], "thresholds": [],
"timeFrom": null, "timeFrom": null,
"timeRegions": [],
"timeShift": null, "timeShift": null,
"title": "Average payments started/ended / $summarize", "title": "Average payments started/ended / $summarize",
"tooltip": { "tooltip": {
...@@ -216,12 +252,14 @@ ...@@ -216,12 +252,14 @@
"dashes": false, "dashes": false,
"datasource": "gdev-mysql", "datasource": "gdev-mysql",
"fill": 2, "fill": 2,
"fillGradient": 0,
"gridPos": { "gridPos": {
"h": 9, "h": 9,
"w": 12, "w": 12,
"x": 0, "x": 0,
"y": 9 "y": 9
}, },
"hiddenSeries": false,
"id": 3, "id": 3,
"legend": { "legend": {
"avg": false, "avg": false,
...@@ -236,6 +274,9 @@ ...@@ -236,6 +274,9 @@
"linewidth": 2, "linewidth": 2,
"links": [], "links": [],
"nullPointMode": "null", "nullPointMode": "null",
"options": {
"dataLinks": []
},
"percentage": false, "percentage": false,
"pointradius": 5, "pointradius": 5,
"points": false, "points": false,
...@@ -255,6 +296,7 @@ ...@@ -255,6 +296,7 @@
], ],
"thresholds": [], "thresholds": [],
"timeFrom": null, "timeFrom": null,
"timeRegions": [],
"timeShift": null, "timeShift": null,
"title": "Max CPU / $summarize", "title": "Max CPU / $summarize",
"tooltip": { "tooltip": {
...@@ -305,6 +347,7 @@ ...@@ -305,6 +347,7 @@
}, },
"id": 6, "id": 6,
"links": [], "links": [],
"options": {},
"pageSize": null, "pageSize": null,
"scroll": true, "scroll": true,
"showHeader": true, "showHeader": true,
...@@ -346,7 +389,8 @@ ...@@ -346,7 +389,8 @@
"type": "table" "type": "table"
} }
], ],
"schemaVersion": 16, "refresh": false,
"schemaVersion": 21,
"style": "dark", "style": "dark",
"tags": ["gdev", "mysql", "datasource-tags"], "tags": ["gdev", "mysql", "datasource-tags"],
"templating": { "templating": {
...@@ -358,6 +402,7 @@ ...@@ -358,6 +402,7 @@
"value": "America" "value": "America"
}, },
"datasource": "gdev-mysql", "datasource": "gdev-mysql",
"definition": "",
"hide": 0, "hide": 0,
"includeAll": false, "includeAll": false,
"label": "Datacenter", "label": "Datacenter",
...@@ -378,10 +423,12 @@ ...@@ -378,10 +423,12 @@
{ {
"allValue": null, "allValue": null,
"current": { "current": {
"selected": false,
"text": "All", "text": "All",
"value": "$__all" "value": "$__all"
}, },
"datasource": "gdev-mysql", "datasource": "gdev-mysql",
"definition": "",
"hide": 0, "hide": 0,
"includeAll": true, "includeAll": true,
"label": "Hostname", "label": "Hostname",
...@@ -404,6 +451,7 @@ ...@@ -404,6 +451,7 @@
"auto_count": 5, "auto_count": 5,
"auto_min": "10s", "auto_min": "10s",
"current": { "current": {
"selected": false,
"text": "1m", "text": "1m",
"value": "1m" "value": "1m"
}, },
...@@ -500,5 +548,5 @@ ...@@ -500,5 +548,5 @@
"timezone": "", "timezone": "",
"title": "Datasource tests - MySQL", "title": "Datasource tests - MySQL",
"uid": "DGsCac3kz", "uid": "DGsCac3kz",
"version": 8 "version": 2
} }
...@@ -4,11 +4,35 @@ ...@@ -4,11 +4,35 @@
{ {
"builtIn": 1, "builtIn": 1,
"datasource": "-- Grafana --", "datasource": "-- Grafana --",
"enable": true, "enable": false,
"hide": true, "hide": true,
"iconColor": "rgba(0, 211, 255, 1)", "iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts", "name": "Annotations & Alerts",
"type": "dashboard" "type": "dashboard"
},
{
"datasource": "gdev-postgres",
"enable": false,
"hide": false,
"iconColor": "rgba(0, 211, 255, 1)",
"limit": 100,
"name": "Single",
"rawQuery": "SELECT\n \"createdAt\" as time,\n 'single' as text,\n hostname as tags\nFROM\n grafana_metric\nWHERE\n $__timeFilter(\"createdAt\")\nORDER BY time\nLIMIT 1\n",
"showIn": 0,
"tags": [],
"type": "tags"
},
{
"datasource": "gdev-postgres",
"enable": false,
"hide": false,
"iconColor": "rgba(0, 211, 255, 1)",
"limit": 100,
"name": "Region",
"rawQuery": "SELECT\n \"createdAt\" + (interval '1 minute') as time,\n \"createdAt\" + (6 * interval '1 minute') as timeend,\n 'region' as text,\n hostname as tags\nFROM\n grafana_metric\nWHERE\n $__timeFilter(\"createdAt\")\nORDER BY time\nLIMIT 1\n",
"showIn": 0,
"tags": [],
"type": "tags"
} }
] ]
}, },
...@@ -16,7 +40,7 @@ ...@@ -16,7 +40,7 @@
"editable": true, "editable": true,
"gnetId": null, "gnetId": null,
"graphTooltip": 0, "graphTooltip": 0,
"iteration": 1532620601931, "iteration": 1576249087264,
"links": [], "links": [],
"panels": [ "panels": [
{ {
...@@ -28,12 +52,14 @@ ...@@ -28,12 +52,14 @@
"dashes": false, "dashes": false,
"datasource": "gdev-postgres", "datasource": "gdev-postgres",
"fill": 2, "fill": 2,
"fillGradient": 0,
"gridPos": { "gridPos": {
"h": 9, "h": 9,
"w": 12, "w": 12,
"x": 0, "x": 0,
"y": 0 "y": 0
}, },
"hiddenSeries": false,
"id": 2, "id": 2,
"legend": { "legend": {
"avg": false, "avg": false,
...@@ -48,6 +74,9 @@ ...@@ -48,6 +74,9 @@
"linewidth": 2, "linewidth": 2,
"links": [], "links": [],
"nullPointMode": "null", "nullPointMode": "null",
"options": {
"dataLinks": []
},
"percentage": false, "percentage": false,
"pointradius": 5, "pointradius": 5,
"points": false, "points": false,
...@@ -67,20 +96,59 @@ ...@@ -67,20 +96,59 @@
{ {
"alias": "", "alias": "",
"format": "time_series", "format": "time_series",
"group": [],
"hide": false, "hide": false,
"metricColumn": "none",
"rawQuery": true,
"rawSql": "SELECT\n $__timeGroup(\"createdAt\",'$summarize'),\n avg(value) as \"value\",\n hostname as \"metric\"\nFROM \n grafana_metric\nWHERE\n $__timeFilter(\"createdAt\") AND\n measurement = 'logins.count' AND\n hostname IN($host)\nGROUP BY time, metric\nORDER BY time", "rawSql": "SELECT\n $__timeGroup(\"createdAt\",'$summarize'),\n avg(value) as \"value\",\n hostname as \"metric\"\nFROM \n grafana_metric\nWHERE\n $__timeFilter(\"createdAt\") AND\n measurement = 'logins.count' AND\n hostname IN($host)\nGROUP BY time, metric\nORDER BY time",
"refId": "A", "refId": "A",
"target": "" "select": [
[
{
"params": ["value"],
"type": "column"
}
]
],
"target": "",
"timeColumn": "time",
"where": [
{
"name": "$__timeFilter",
"params": [],
"type": "macro"
}
]
}, },
{ {
"alias": "", "alias": "",
"format": "time_series", "format": "time_series",
"group": [],
"metricColumn": "none",
"rawQuery": true,
"rawSql": "SELECT\n $__timeGroup(\"createdAt\",'$summarize'),\n min(value) as \"value\",\n 'total avg' as \"metric\"\nFROM \n grafana_metric\nWHERE\n $__timeFilter(\"createdAt\") AND\n measurement = 'logins.count'\nGROUP BY time\nORDER BY time", "rawSql": "SELECT\n $__timeGroup(\"createdAt\",'$summarize'),\n min(value) as \"value\",\n 'total avg' as \"metric\"\nFROM \n grafana_metric\nWHERE\n $__timeFilter(\"createdAt\") AND\n measurement = 'logins.count'\nGROUP BY time\nORDER BY time",
"refId": "B" "refId": "B",
"select": [
[
{
"params": ["value"],
"type": "column"
}
]
],
"timeColumn": "time",
"where": [
{
"name": "$__timeFilter",
"params": [],
"type": "macro"
}
]
} }
], ],
"thresholds": [], "thresholds": [],
"timeFrom": null, "timeFrom": null,
"timeRegions": [],
"timeShift": null, "timeShift": null,
"title": "Average logins / $summarize", "title": "Average logins / $summarize",
"tooltip": { "tooltip": {
...@@ -126,12 +194,14 @@ ...@@ -126,12 +194,14 @@
"dashes": false, "dashes": false,
"datasource": "gdev-postgres", "datasource": "gdev-postgres",
"fill": 2, "fill": 2,
"fillGradient": 0,
"gridPos": { "gridPos": {
"h": 18, "h": 18,
"w": 12, "w": 12,
"x": 12, "x": 12,
"y": 0 "y": 0
}, },
"hiddenSeries": false,
"id": 4, "id": 4,
"legend": { "legend": {
"avg": false, "avg": false,
...@@ -146,6 +216,9 @@ ...@@ -146,6 +216,9 @@
"linewidth": 2, "linewidth": 2,
"links": [], "links": [],
"nullPointMode": "null", "nullPointMode": "null",
"options": {
"dataLinks": []
},
"percentage": false, "percentage": false,
"pointradius": 5, "pointradius": 5,
"points": false, "points": false,
...@@ -171,6 +244,7 @@ ...@@ -171,6 +244,7 @@
], ],
"thresholds": [], "thresholds": [],
"timeFrom": null, "timeFrom": null,
"timeRegions": [],
"timeShift": null, "timeShift": null,
"title": "Average payments started/ended / $summarize", "title": "Average payments started/ended / $summarize",
"tooltip": { "tooltip": {
...@@ -216,12 +290,14 @@ ...@@ -216,12 +290,14 @@
"dashes": false, "dashes": false,
"datasource": "gdev-postgres", "datasource": "gdev-postgres",
"fill": 2, "fill": 2,
"fillGradient": 0,
"gridPos": { "gridPos": {
"h": 9, "h": 9,
"w": 12, "w": 12,
"x": 0, "x": 0,
"y": 9 "y": 9
}, },
"hiddenSeries": false,
"id": 3, "id": 3,
"legend": { "legend": {
"avg": false, "avg": false,
...@@ -236,6 +312,9 @@ ...@@ -236,6 +312,9 @@
"linewidth": 2, "linewidth": 2,
"links": [], "links": [],
"nullPointMode": "null", "nullPointMode": "null",
"options": {
"dataLinks": []
},
"percentage": false, "percentage": false,
"pointradius": 5, "pointradius": 5,
"points": false, "points": false,
...@@ -255,6 +334,7 @@ ...@@ -255,6 +334,7 @@
], ],
"thresholds": [], "thresholds": [],
"timeFrom": null, "timeFrom": null,
"timeRegions": [],
"timeShift": null, "timeShift": null,
"title": "Max CPU / $summarize", "title": "Max CPU / $summarize",
"tooltip": { "tooltip": {
...@@ -305,6 +385,7 @@ ...@@ -305,6 +385,7 @@
}, },
"id": 6, "id": 6,
"links": [], "links": [],
"options": {},
"pageSize": null, "pageSize": null,
"scroll": true, "scroll": true,
"showHeader": true, "showHeader": true,
...@@ -345,7 +426,7 @@ ...@@ -345,7 +426,7 @@
"type": "table" "type": "table"
} }
], ],
"schemaVersion": 16, "schemaVersion": 21,
"style": "dark", "style": "dark",
"tags": ["gdev", "postgres", "datasource-test"], "tags": ["gdev", "postgres", "datasource-test"],
"templating": { "templating": {
...@@ -357,6 +438,7 @@ ...@@ -357,6 +438,7 @@
"value": "America" "value": "America"
}, },
"datasource": "gdev-postgres", "datasource": "gdev-postgres",
"definition": "",
"hide": 0, "hide": 0,
"includeAll": false, "includeAll": false,
"label": "Datacenter", "label": "Datacenter",
...@@ -377,10 +459,12 @@ ...@@ -377,10 +459,12 @@
{ {
"allValue": null, "allValue": null,
"current": { "current": {
"selected": false,
"text": "All", "text": "All",
"value": "$__all" "value": "$__all"
}, },
"datasource": "gdev-postgres", "datasource": "gdev-postgres",
"definition": "",
"hide": 0, "hide": 0,
"includeAll": true, "includeAll": true,
"label": "Hostname", "label": "Hostname",
...@@ -403,6 +487,7 @@ ...@@ -403,6 +487,7 @@
"auto_count": 5, "auto_count": 5,
"auto_min": "10s", "auto_min": "10s",
"current": { "current": {
"selected": false,
"text": "1m", "text": "1m",
"value": "1m" "value": "1m"
}, },
...@@ -499,5 +584,5 @@ ...@@ -499,5 +584,5 @@
"timezone": "", "timezone": "",
"title": "Datasource tests - Postgres", "title": "Datasource tests - Postgres",
"uid": "JYola5qzz", "uid": "JYola5qzz",
"version": 4 "version": 5
} }
...@@ -178,7 +178,7 @@ The resulting table panel: ...@@ -178,7 +178,7 @@ The resulting table panel:
## Time series queries ## Time series queries
If you set `Format as` to `Time series`, for use in Graph panel for example, then the query must have a column named `time` that returns either a sql datetime or any numeric datatype representing Unix epoch in seconds. You may return a column named `metric` that is used as metric name for the value column. Any column except `time` and `metric` is treated as a value column. If you omit the `metric` column, the name of the value column will be the metric name. You may select multiple value columns, each will have its name as metric. If you set `Format as` to `Time series`, for use in Graph panel for example, then the query must have a column named `time` that returns either a SQL datetime or any numeric datatype representing Unix epoch in seconds. You may return a column named `metric` that is used as metric name for the value column. Any column except `time` and `metric` is treated as a value column. If you omit the `metric` column, the name of the value column will be the metric name. You may select multiple value columns, each will have its name as metric.
If you return multiple value columns and a column named `metric` then this column is used as prefix for the series name (only available in Grafana 5.3+). If you return multiple value columns and a column named `metric` then this column is used as prefix for the series name (only available in Grafana 5.3+).
Resultsets of time series queries need to be sorted by time. Resultsets of time series queries need to be sorted by time.
...@@ -380,7 +380,8 @@ Read more about variable formatting options in the [Variables]({{< relref "../.. ...@@ -380,7 +380,8 @@ Read more about variable formatting options in the [Variables]({{< relref "../..
Name | Description Name | Description
------------ | ------------- ------------ | -------------
time | The name of the date/time field. Could be a column with a native sql date/time data type or epoch value. time | The name of the date/time field. Could be a column with a native SQL date/time data type or epoch value.
timeend | Optional name of the end date/time field. Could be a column with a native SQL date/time data type or epoch value.
text | Event description field. text | Event description field.
tags | Optional field name to use for event tags as a comma separated string. tags | Optional field name to use for event tags as a comma separated string.
...@@ -410,7 +411,7 @@ WHERE ...@@ -410,7 +411,7 @@ WHERE
ORDER BY 1 ORDER BY 1
``` ```
**Example query using time column of native sql date/time data type:** **Example query using time column of native SQL date/time data type:**
```sql ```sql
SELECT SELECT
......
...@@ -182,7 +182,7 @@ The resulting table panel: ...@@ -182,7 +182,7 @@ The resulting table panel:
## Time series queries ## Time series queries
If you set `Format as` to `Time series`, for use in Graph panel for example, then the query must return a column named `time` that returns either a sql datetime or any numeric datatype representing Unix epoch. If you set `Format as` to `Time series`, for use in Graph panel for example, then the query must return a column named `time` that returns either a SQL datetime or any numeric datatype representing Unix epoch.
Any column except `time` and `metric` is treated as a value column. Any column except `time` and `metric` is treated as a value column.
You may return a column named `metric` that is used as metric name for the value column. You may return a column named `metric` that is used as metric name for the value column.
If you return multiple value columns and a column named `metric` then this column is used as prefix for the series name (only available in Grafana 5.3+). If you return multiple value columns and a column named `metric` then this column is used as prefix for the series name (only available in Grafana 5.3+).
...@@ -350,7 +350,7 @@ WHERE ...@@ -350,7 +350,7 @@ WHERE
$__unixEpochFilter(epoch_time) $__unixEpochFilter(epoch_time)
``` ```
**Example query using time column of native sql date/time data type:** **Example query using time column of native SQL date/time data type:**
```sql ```sql
SELECT SELECT
...@@ -365,7 +365,8 @@ WHERE ...@@ -365,7 +365,8 @@ WHERE
Name | Description Name | Description
------------ | ------------- ------------ | -------------
time | The name of the date/time field. Could be a column with a native sql date/time data type or epoch value. time | The name of the date/time field. Could be a column with a native SQL date/time data type or epoch value.
timeend | Optional name of the end date/time field. Could be a column with a native SQL date/time data type or epoch value.
text | Event description field. text | Event description field.
tags | Optional field name to use for event tags as a comma separated string. tags | Optional field name to use for event tags as a comma separated string.
......
...@@ -354,7 +354,7 @@ WHERE ...@@ -354,7 +354,7 @@ WHERE
$__unixEpochFilter(epoch_time) $__unixEpochFilter(epoch_time)
``` ```
**Example query using time column of native sql date/time data type:** **Example query using time column of native SQL date/time data type:**
```sql ```sql
SELECT SELECT
...@@ -369,7 +369,8 @@ WHERE ...@@ -369,7 +369,8 @@ WHERE
Name | Description Name | Description
------------ | ------------- ------------ | -------------
time | The name of the date/time field. Could be a column with a native sql date/time data type or epoch value. time | The name of the date/time field. Could be a column with a native SQL date/time data type or epoch value.
timeend | Optional name of the time end field, needs to be date/time data type. If set, then annotations are marked as regions between time and time-end.
text | Event description field. text | Event description field.
tags | Optional field name to use for event tags as a comma separated string. tags | Optional field name to use for event tags as a comma separated string.
......
...@@ -56,6 +56,8 @@ var NewXormEngine = func(driverName string, connectionString string) (*xorm.Engi ...@@ -56,6 +56,8 @@ var NewXormEngine = func(driverName string, connectionString string) (*xorm.Engi
return xorm.NewEngine(driverName, connectionString) return xorm.NewEngine(driverName, connectionString)
} }
const timeEndColumnName = "timeend"
type sqlQueryEndpoint struct { type sqlQueryEndpoint struct {
macroEngine SqlMacroEngine macroEngine SqlMacroEngine
queryResultTransformer SqlQueryResultTransformer queryResultTransformer SqlQueryResultTransformer
...@@ -218,6 +220,7 @@ func (e *sqlQueryEndpoint) transformToTable(query *tsdb.Query, rows *core.Rows, ...@@ -218,6 +220,7 @@ func (e *sqlQueryEndpoint) transformToTable(query *tsdb.Query, rows *core.Rows,
rowCount := 0 rowCount := 0
timeIndex := -1 timeIndex := -1
timeEndIndex := -1
table := &tsdb.Table{ table := &tsdb.Table{
Columns: make([]tsdb.TableColumn, columnCount), Columns: make([]tsdb.TableColumn, columnCount),
...@@ -232,6 +235,11 @@ func (e *sqlQueryEndpoint) transformToTable(query *tsdb.Query, rows *core.Rows, ...@@ -232,6 +235,11 @@ func (e *sqlQueryEndpoint) transformToTable(query *tsdb.Query, rows *core.Rows,
timeIndex = i timeIndex = i
break break
} }
if timeIndex >= 0 && name == timeEndColumnName {
timeEndIndex = i
break
}
} }
} }
...@@ -250,10 +258,11 @@ func (e *sqlQueryEndpoint) transformToTable(query *tsdb.Query, rows *core.Rows, ...@@ -250,10 +258,11 @@ func (e *sqlQueryEndpoint) transformToTable(query *tsdb.Query, rows *core.Rows,
return err return err
} }
// converts column named time to unix timestamp in milliseconds // converts column named time and timeend to unix timestamp in milliseconds
// to make native mssql datetime types and epoch dates work in // to make native mssql datetime types and epoch dates work in
// annotation and table queries. // annotation and table queries.
ConvertSqlTimeColumnToEpochMs(values, timeIndex) ConvertSqlTimeColumnToEpochMs(values, timeIndex)
ConvertSqlTimeColumnToEpochMs(values, timeEndIndex)
table.Rows = append(table.Rows, values) table.Rows = append(table.Rows, values)
} }
......
...@@ -18,9 +18,10 @@ ...@@ -18,9 +18,10 @@
<div class="gf-form" ng-show="ctrl.showHelp"> <div class="gf-form" ng-show="ctrl.showHelp">
<pre class="gf-form-pre alert alert-info"><h6>Annotation Query Format</h6> <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 <b>time</b> 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 <b>time</b> 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>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 end time. Use epoch time or any native date data type.
- column with alias: <b>text</b> for the annotation text. - 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'. - column with alias: <b>tags</b> for annotation tags. This is a comma separated string of tags e.g. 'tag1,tag2'.
......
...@@ -104,12 +104,15 @@ export default class ResponseParser { ...@@ -104,12 +104,15 @@ export default class ResponseParser {
const table = data.data.results[options.annotation.name].tables[0]; const table = data.data.results[options.annotation.name].tables[0];
let timeColumnIndex = -1; let timeColumnIndex = -1;
let timeEndColumnIndex = -1;
let textColumnIndex = -1; let textColumnIndex = -1;
let tagsColumnIndex = -1; let tagsColumnIndex = -1;
for (let i = 0; i < table.columns.length; i++) { for (let i = 0; i < table.columns.length; i++) {
if (table.columns[i].text === 'time') { if (table.columns[i].text === 'time') {
timeColumnIndex = i; timeColumnIndex = i;
} else if (table.columns[i].text === 'timeend') {
timeEndColumnIndex = i;
} else if (table.columns[i].text === 'text') { } else if (table.columns[i].text === 'text') {
textColumnIndex = i; textColumnIndex = i;
} else if (table.columns[i].text === 'tags') { } else if (table.columns[i].text === 'tags') {
...@@ -124,9 +127,12 @@ export default class ResponseParser { ...@@ -124,9 +127,12 @@ export default class ResponseParser {
const list = []; const list = [];
for (let i = 0; i < table.rows.length; i++) { for (let i = 0; i < table.rows.length; i++) {
const row = table.rows[i]; const row = table.rows[i];
const timeEnd =
timeEndColumnIndex !== -1 && row[timeEndColumnIndex] ? Math.floor(row[timeEndColumnIndex]) : undefined;
list.push({ list.push({
annotation: options.annotation, annotation: options.annotation,
time: Math.floor(row[timeColumnIndex]), time: Math.floor(row[timeColumnIndex]),
timeEnd,
text: row[textColumnIndex], text: row[textColumnIndex],
tags: row[tagsColumnIndex] ? row[tagsColumnIndex].trim().split(/\s*,\s*/) : [], tags: row[tagsColumnIndex] ? row[tagsColumnIndex].trim().split(/\s*,\s*/) : [],
}); });
......
...@@ -18,9 +18,10 @@ ...@@ -18,9 +18,10 @@
<div class="gf-form" ng-show="ctrl.showHelp"> <div class="gf-form" ng-show="ctrl.showHelp">
<pre class="gf-form-pre alert alert-info"><h6>Annotation Query Format</h6> <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 <i>time</i> or <i>time_sec</i> 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 <i>time</i> or <i>time_sec</i> column is mandatory. Annotation rendering is expensive so it is important to limit the number of rows returned.
- column with alias: <b>time</b> or <i>time_sec</i> for the annotation event time. Use epoch time or any native date data type. - column with alias: <b>time</b> or <i>time_sec</i> for the annotation event time. Use epoch time or any native date data type.
- column with alias: <b>timeend</b> for the annotation event end time. Use epoch time or any native date data type.
- column with alias: <b>text</b> for the annotation text - 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' - column with alias: <b>tags</b> for annotation tags. This is a comma separated string of tags e.g. 'tag1,tag2'
......
...@@ -107,12 +107,15 @@ export default class ResponseParser { ...@@ -107,12 +107,15 @@ export default class ResponseParser {
const table = data.data.results[options.annotation.name].tables[0]; const table = data.data.results[options.annotation.name].tables[0];
let timeColumnIndex = -1; let timeColumnIndex = -1;
let timeEndColumnIndex = -1;
let textColumnIndex = -1; let textColumnIndex = -1;
let tagsColumnIndex = -1; let tagsColumnIndex = -1;
for (let i = 0; i < table.columns.length; i++) { for (let i = 0; i < table.columns.length; i++) {
if (table.columns[i].text === 'time_sec' || table.columns[i].text === 'time') { if (table.columns[i].text === 'time_sec' || table.columns[i].text === 'time') {
timeColumnIndex = i; timeColumnIndex = i;
} else if (table.columns[i].text === 'timeend') {
timeEndColumnIndex = i;
} else if (table.columns[i].text === 'title') { } else if (table.columns[i].text === 'title') {
return Promise.reject({ return Promise.reject({
message: 'The title column for annotations is deprecated, now only a column named text is returned', message: 'The title column for annotations is deprecated, now only a column named text is returned',
...@@ -133,9 +136,12 @@ export default class ResponseParser { ...@@ -133,9 +136,12 @@ export default class ResponseParser {
const list = []; const list = [];
for (let i = 0; i < table.rows.length; i++) { for (let i = 0; i < table.rows.length; i++) {
const row = table.rows[i]; const row = table.rows[i];
const timeEnd =
timeEndColumnIndex !== -1 && row[timeEndColumnIndex] ? Math.floor(row[timeEndColumnIndex]) : undefined;
list.push({ list.push({
annotation: options.annotation, annotation: options.annotation,
time: Math.floor(row[timeColumnIndex]), time: Math.floor(row[timeColumnIndex]),
timeEnd,
text: row[textColumnIndex] ? row[textColumnIndex].toString() : '', text: row[textColumnIndex] ? row[textColumnIndex].toString() : '',
tags: row[tagsColumnIndex] ? row[tagsColumnIndex].trim().split(/\s*,\s*/) : [], tags: row[tagsColumnIndex] ? row[tagsColumnIndex].trim().split(/\s*,\s*/) : [],
}); });
......
...@@ -18,9 +18,10 @@ ...@@ -18,9 +18,10 @@
<div class="gf-form" ng-show="ctrl.showHelp"> <div class="gf-form" ng-show="ctrl.showHelp">
<pre class="gf-form-pre alert alert-info"><h6>Annotation Query Format</h6> <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>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>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' - column with alias: <b>tags</b> for annotation tags. This is a comma separated string of tags e.g. 'tag1,tag2'
......
...@@ -107,6 +107,7 @@ export default class ResponseParser { ...@@ -107,6 +107,7 @@ export default class ResponseParser {
const table = data.data.results[options.annotation.name].tables[0]; const table = data.data.results[options.annotation.name].tables[0];
let timeColumnIndex = -1; let timeColumnIndex = -1;
let timeEndColumnIndex = -1;
const titleColumnIndex = -1; const titleColumnIndex = -1;
let textColumnIndex = -1; let textColumnIndex = -1;
let tagsColumnIndex = -1; let tagsColumnIndex = -1;
...@@ -114,6 +115,8 @@ export default class ResponseParser { ...@@ -114,6 +115,8 @@ export default class ResponseParser {
for (let i = 0; i < table.columns.length; i++) { for (let i = 0; i < table.columns.length; i++) {
if (table.columns[i].text === 'time') { if (table.columns[i].text === 'time') {
timeColumnIndex = i; timeColumnIndex = i;
} else if (table.columns[i].text === 'timeend') {
timeEndColumnIndex = i;
} else if (table.columns[i].text === 'text') { } else if (table.columns[i].text === 'text') {
textColumnIndex = i; textColumnIndex = i;
} else if (table.columns[i].text === 'tags') { } else if (table.columns[i].text === 'tags') {
...@@ -130,9 +133,12 @@ export default class ResponseParser { ...@@ -130,9 +133,12 @@ export default class ResponseParser {
const list = []; const list = [];
for (let i = 0; i < table.rows.length; i++) { for (let i = 0; i < table.rows.length; i++) {
const row = table.rows[i]; const row = table.rows[i];
const timeEnd =
timeEndColumnIndex !== -1 && row[timeEndColumnIndex] ? Math.floor(row[timeEndColumnIndex]) : undefined;
list.push({ list.push({
annotation: options.annotation, annotation: options.annotation,
time: Math.floor(row[timeColumnIndex]), time: Math.floor(row[timeColumnIndex]),
timeEnd,
title: row[titleColumnIndex], title: row[titleColumnIndex],
text: row[textColumnIndex], text: row[textColumnIndex],
tags: row[tagsColumnIndex] ? row[tagsColumnIndex].trim().split(/\s*,\s*/) : [], tags: row[tagsColumnIndex] ? row[tagsColumnIndex].trim().split(/\s*,\s*/) : [],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment