Merge pull request #12753 from svenklemm/sql-fillmode-last

Add fill mode to fill in previously seen value when point is missing to SQL datasources
This commit is contained in:
Marcus Efraimsson 2018-08-08 10:29:56 +02:00 committed by GitHub
commit 8952137ea2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 748 additions and 135 deletions

View File

@ -64,7 +64,7 @@
"editable": true,
"gnetId": null,
"graphTooltip": 0,
"iteration": 1532949769359,
"iteration": 1533713720618,
"links": [],
"panels": [
{
@ -338,8 +338,8 @@
"datasource": "gdev-mssql-ds-tests",
"fill": 2,
"gridPos": {
"h": 9,
"w": 8,
"h": 6,
"w": 6,
"x": 0,
"y": 7
},
@ -421,9 +421,9 @@
"datasource": "gdev-mssql-ds-tests",
"fill": 2,
"gridPos": {
"h": 9,
"w": 8,
"x": 8,
"h": 6,
"w": 6,
"x": 6,
"y": 7
},
"id": 9,
@ -504,9 +504,9 @@
"datasource": "gdev-mssql-ds-tests",
"fill": 2,
"gridPos": {
"h": 9,
"w": 8,
"x": 16,
"h": 6,
"w": 6,
"x": 12,
"y": 7
},
"id": 10,
@ -579,6 +579,89 @@
"alignLevel": null
}
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "gdev-mssql-ds-tests",
"fill": 2,
"gridPos": {
"h": 6,
"w": 6,
"x": 18,
"y": 7
},
"id": 36,
"legend": {
"avg": false,
"current": false,
"max": false,
"min": false,
"show": true,
"total": false,
"values": false
},
"lines": true,
"linewidth": 2,
"links": [],
"nullPointMode": "null as zero",
"percentage": false,
"pointradius": 3,
"points": true,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"stack": false,
"steppedLine": true,
"targets": [
{
"alias": "",
"format": "time_series",
"rawSql": "SELECT $__timeGroupAlias(time, '5m', previous), avg(value) as value FROM metric WHERE $__timeFilter(time) GROUP BY $__timeGroup(time, '5m') ORDER BY 1",
"refId": "A"
}
],
"thresholds": [],
"timeFrom": null,
"timeShift": null,
"title": "timeGroup macro 5m with fill(previous) and null as zero",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": "0",
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
},
{
"aliasColors": {},
"bars": true,
@ -587,10 +670,10 @@
"datasource": "gdev-mssql-ds-tests",
"fill": 2,
"gridPos": {
"h": 9,
"w": 8,
"h": 6,
"w": 6,
"x": 0,
"y": 16
"y": 13
},
"id": 16,
"legend": {
@ -670,10 +753,10 @@
"datasource": "gdev-mssql-ds-tests",
"fill": 2,
"gridPos": {
"h": 9,
"w": 8,
"x": 8,
"y": 16
"h": 6,
"w": 6,
"x": 6,
"y": 13
},
"id": 12,
"legend": {
@ -753,10 +836,10 @@
"datasource": "gdev-mssql-ds-tests",
"fill": 2,
"gridPos": {
"h": 9,
"w": 8,
"x": 16,
"y": 16
"h": 6,
"w": 6,
"x": 12,
"y": 13
},
"id": 13,
"legend": {
@ -828,6 +911,89 @@
"alignLevel": null
}
},
{
"aliasColors": {},
"bars": true,
"dashLength": 10,
"dashes": false,
"datasource": "gdev-mssql-ds-tests",
"fill": 2,
"gridPos": {
"h": 6,
"w": 6,
"x": 18,
"y": 13
},
"id": 37,
"legend": {
"avg": false,
"current": false,
"max": false,
"min": false,
"show": true,
"total": false,
"values": false
},
"lines": false,
"linewidth": 2,
"links": [],
"nullPointMode": "null",
"percentage": false,
"pointradius": 3,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"stack": false,
"steppedLine": true,
"targets": [
{
"alias": "",
"format": "time_series",
"rawSql": "SELECT $__timeGroupAlias(time, '$summarize', previous), sum(value) as value FROM metric WHERE $__timeFilter(time) GROUP BY $__timeGroup(time, '$summarize') ORDER BY 1",
"refId": "A"
}
],
"thresholds": [],
"timeFrom": null,
"timeShift": null,
"title": "Metrics - timeGroup macro $summarize with fill(previous)",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
},
{
"aliasColors": {},
"bars": false,
@ -839,7 +1005,7 @@
"h": 8,
"w": 12,
"x": 0,
"y": 25
"y": 19
},
"id": 27,
"legend": {
@ -926,7 +1092,7 @@
"h": 8,
"w": 12,
"x": 12,
"y": 25
"y": 19
},
"id": 5,
"legend": {
@ -1029,7 +1195,7 @@
"h": 8,
"w": 12,
"x": 0,
"y": 33
"y": 27
},
"id": 4,
"legend": {
@ -1116,7 +1282,7 @@
"h": 8,
"w": 12,
"x": 12,
"y": 33
"y": 27
},
"id": 28,
"legend": {
@ -1201,7 +1367,7 @@
"h": 8,
"w": 12,
"x": 0,
"y": 41
"y": 35
},
"id": 19,
"legend": {
@ -1288,7 +1454,7 @@
"h": 8,
"w": 12,
"x": 12,
"y": 41
"y": 35
},
"id": 18,
"legend": {
@ -1373,7 +1539,7 @@
"h": 8,
"w": 12,
"x": 0,
"y": 49
"y": 43
},
"id": 17,
"legend": {
@ -1460,7 +1626,7 @@
"h": 8,
"w": 12,
"x": 12,
"y": 49
"y": 43
},
"id": 20,
"legend": {
@ -1545,7 +1711,7 @@
"h": 8,
"w": 12,
"x": 0,
"y": 57
"y": 51
},
"id": 29,
"legend": {
@ -1632,7 +1798,7 @@
"h": 8,
"w": 12,
"x": 12,
"y": 57
"y": 51
},
"id": 30,
"legend": {
@ -1719,7 +1885,7 @@
"h": 8,
"w": 12,
"x": 0,
"y": 65
"y": 59
},
"id": 14,
"legend": {
@ -1807,7 +1973,7 @@
"h": 8,
"w": 12,
"x": 12,
"y": 65
"y": 59
},
"id": 15,
"legend": {
@ -1894,7 +2060,7 @@
"h": 8,
"w": 12,
"x": 0,
"y": 73
"y": 67
},
"id": 25,
"legend": {
@ -1982,7 +2148,7 @@
"h": 8,
"w": 12,
"x": 12,
"y": 73
"y": 67
},
"id": 22,
"legend": {
@ -2069,7 +2235,7 @@
"h": 8,
"w": 12,
"x": 0,
"y": 81
"y": 75
},
"id": 21,
"legend": {
@ -2157,7 +2323,7 @@
"h": 8,
"w": 12,
"x": 12,
"y": 81
"y": 75
},
"id": 26,
"legend": {
@ -2244,7 +2410,7 @@
"h": 8,
"w": 12,
"x": 0,
"y": 89
"y": 83
},
"id": 23,
"legend": {
@ -2332,7 +2498,7 @@
"h": 8,
"w": 12,
"x": 12,
"y": 89
"y": 83
},
"id": 24,
"legend": {
@ -2542,5 +2708,5 @@
"timezone": "",
"title": "Datasource tests - MSSQL (unit test)",
"uid": "GlAqcPgmz",
"version": 3
"version": 10
}

View File

@ -64,7 +64,7 @@
"editable": true,
"gnetId": null,
"graphTooltip": 0,
"iteration": 1532949531280,
"iteration": 1533714324007,
"links": [],
"panels": [
{
@ -338,8 +338,8 @@
"datasource": "gdev-mysql-ds-tests",
"fill": 2,
"gridPos": {
"h": 9,
"w": 8,
"h": 6,
"w": 6,
"x": 0,
"y": 7
},
@ -421,9 +421,9 @@
"datasource": "gdev-mysql-ds-tests",
"fill": 2,
"gridPos": {
"h": 9,
"w": 8,
"x": 8,
"h": 6,
"w": 6,
"x": 6,
"y": 7
},
"id": 9,
@ -504,9 +504,9 @@
"datasource": "gdev-mysql-ds-tests",
"fill": 2,
"gridPos": {
"h": 9,
"w": 8,
"x": 16,
"h": 6,
"w": 6,
"x": 12,
"y": 7
},
"id": 10,
@ -579,6 +579,89 @@
"alignLevel": null
}
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "gdev-mysql-ds-tests",
"fill": 2,
"gridPos": {
"h": 6,
"w": 6,
"x": 18,
"y": 7
},
"id": 36,
"legend": {
"avg": false,
"current": false,
"max": false,
"min": false,
"show": true,
"total": false,
"values": false
},
"lines": true,
"linewidth": 2,
"links": [],
"nullPointMode": "null",
"percentage": false,
"pointradius": 3,
"points": true,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"stack": false,
"steppedLine": true,
"targets": [
{
"alias": "",
"format": "time_series",
"rawSql": "SELECT $__timeGroupAlias(time, '5m', previous), avg(value) as value FROM metric WHERE $__timeFilter(time) GROUP BY 1 ORDER BY 1",
"refId": "A"
}
],
"thresholds": [],
"timeFrom": null,
"timeShift": null,
"title": "timeGroup macro 5m with fill(previous)",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": "0",
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
},
{
"aliasColors": {},
"bars": true,
@ -587,10 +670,10 @@
"datasource": "gdev-mysql-ds-tests",
"fill": 2,
"gridPos": {
"h": 9,
"w": 8,
"h": 6,
"w": 6,
"x": 0,
"y": 16
"y": 13
},
"id": 16,
"legend": {
@ -670,10 +753,10 @@
"datasource": "gdev-mysql-ds-tests",
"fill": 2,
"gridPos": {
"h": 9,
"w": 8,
"x": 8,
"y": 16
"h": 6,
"w": 6,
"x": 6,
"y": 13
},
"id": 12,
"legend": {
@ -753,10 +836,10 @@
"datasource": "gdev-mysql-ds-tests",
"fill": 2,
"gridPos": {
"h": 9,
"w": 8,
"x": 16,
"y": 16
"h": 6,
"w": 6,
"x": 12,
"y": 13
},
"id": 13,
"legend": {
@ -828,6 +911,89 @@
"alignLevel": null
}
},
{
"aliasColors": {},
"bars": true,
"dashLength": 10,
"dashes": false,
"datasource": "gdev-mysql-ds-tests",
"fill": 2,
"gridPos": {
"h": 6,
"w": 6,
"x": 18,
"y": 13
},
"id": 37,
"legend": {
"avg": false,
"current": false,
"max": false,
"min": false,
"show": true,
"total": false,
"values": false
},
"lines": false,
"linewidth": 2,
"links": [],
"nullPointMode": "null",
"percentage": false,
"pointradius": 3,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"stack": false,
"steppedLine": true,
"targets": [
{
"alias": "",
"format": "time_series",
"rawSql": "SELECT $__timeGroupAlias(time, '$summarize', previous), sum(value) as value FROM metric WHERE $__timeFilter(time) GROUP BY 1 ORDER BY 1",
"refId": "A"
}
],
"thresholds": [],
"timeFrom": null,
"timeShift": null,
"title": "Metrics - timeGroup macro $summarize with fill(previous)",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
},
{
"aliasColors": {},
"bars": false,
@ -839,7 +1005,7 @@
"h": 8,
"w": 12,
"x": 0,
"y": 25
"y": 19
},
"id": 27,
"legend": {
@ -926,7 +1092,7 @@
"h": 8,
"w": 12,
"x": 12,
"y": 25
"y": 19
},
"id": 5,
"legend": {
@ -1023,7 +1189,7 @@
"h": 8,
"w": 12,
"x": 0,
"y": 33
"y": 27
},
"id": 4,
"legend": {
@ -1110,7 +1276,7 @@
"h": 8,
"w": 12,
"x": 12,
"y": 33
"y": 27
},
"id": 28,
"legend": {
@ -1195,7 +1361,7 @@
"h": 8,
"w": 12,
"x": 0,
"y": 41
"y": 35
},
"id": 19,
"legend": {
@ -1282,7 +1448,7 @@
"h": 8,
"w": 12,
"x": 12,
"y": 41
"y": 35
},
"id": 18,
"legend": {
@ -1367,7 +1533,7 @@
"h": 8,
"w": 12,
"x": 0,
"y": 49
"y": 43
},
"id": 17,
"legend": {
@ -1454,7 +1620,7 @@
"h": 8,
"w": 12,
"x": 12,
"y": 49
"y": 43
},
"id": 20,
"legend": {
@ -1539,7 +1705,7 @@
"h": 8,
"w": 12,
"x": 0,
"y": 57
"y": 51
},
"id": 14,
"legend": {
@ -1627,7 +1793,7 @@
"h": 8,
"w": 12,
"x": 12,
"y": 57
"y": 51
},
"id": 15,
"legend": {
@ -1714,7 +1880,7 @@
"h": 8,
"w": 12,
"x": 0,
"y": 65
"y": 59
},
"id": 25,
"legend": {
@ -1802,7 +1968,7 @@
"h": 8,
"w": 12,
"x": 12,
"y": 65
"y": 59
},
"id": 22,
"legend": {
@ -1889,7 +2055,7 @@
"h": 8,
"w": 12,
"x": 0,
"y": 73
"y": 67
},
"id": 21,
"legend": {
@ -1977,7 +2143,7 @@
"h": 8,
"w": 12,
"x": 12,
"y": 73
"y": 67
},
"id": 26,
"legend": {
@ -2064,7 +2230,7 @@
"h": 8,
"w": 12,
"x": 0,
"y": 81
"y": 75
},
"id": 23,
"legend": {
@ -2152,7 +2318,7 @@
"h": 8,
"w": 12,
"x": 12,
"y": 81
"y": 75
},
"id": 24,
"legend": {
@ -2360,5 +2526,5 @@
"timezone": "",
"title": "Datasource tests - MySQL (unittest)",
"uid": "Hmf8FDkmz",
"version": 1
"version": 9
}

View File

@ -64,7 +64,7 @@
"editable": true,
"gnetId": null,
"graphTooltip": 0,
"iteration": 1532951521836,
"iteration": 1533714184500,
"links": [],
"panels": [
{
@ -338,8 +338,8 @@
"datasource": "gdev-postgres-ds-tests",
"fill": 2,
"gridPos": {
"h": 9,
"w": 8,
"h": 6,
"w": 6,
"x": 0,
"y": 7
},
@ -421,9 +421,9 @@
"datasource": "gdev-postgres-ds-tests",
"fill": 2,
"gridPos": {
"h": 9,
"w": 8,
"x": 8,
"h": 6,
"w": 6,
"x": 6,
"y": 7
},
"id": 9,
@ -504,9 +504,9 @@
"datasource": "gdev-postgres-ds-tests",
"fill": 2,
"gridPos": {
"h": 9,
"w": 8,
"x": 16,
"h": 6,
"w": 6,
"x": 12,
"y": 7
},
"id": 10,
@ -579,6 +579,89 @@
"alignLevel": null
}
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "gdev-postgres-ds-tests",
"fill": 2,
"gridPos": {
"h": 6,
"w": 6,
"x": 18,
"y": 7
},
"id": 36,
"legend": {
"avg": false,
"current": false,
"max": false,
"min": false,
"show": true,
"total": false,
"values": false
},
"lines": true,
"linewidth": 2,
"links": [],
"nullPointMode": "null",
"percentage": false,
"pointradius": 3,
"points": true,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"stack": false,
"steppedLine": true,
"targets": [
{
"alias": "",
"format": "time_series",
"rawSql": "SELECT $__timeGroupAlias(time, '5m', previous), avg(value) as value FROM metric WHERE $__timeFilter(time) GROUP BY 1 ORDER BY 1",
"refId": "A"
}
],
"thresholds": [],
"timeFrom": null,
"timeShift": null,
"title": "timeGroup macro 5m with fill(previous)",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": "0",
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
},
{
"aliasColors": {},
"bars": true,
@ -587,10 +670,10 @@
"datasource": "gdev-postgres-ds-tests",
"fill": 2,
"gridPos": {
"h": 9,
"w": 8,
"h": 6,
"w": 6,
"x": 0,
"y": 16
"y": 13
},
"id": 16,
"legend": {
@ -670,10 +753,10 @@
"datasource": "gdev-postgres-ds-tests",
"fill": 2,
"gridPos": {
"h": 9,
"w": 8,
"x": 8,
"y": 16
"h": 6,
"w": 6,
"x": 6,
"y": 13
},
"id": 12,
"legend": {
@ -753,10 +836,10 @@
"datasource": "gdev-postgres-ds-tests",
"fill": 2,
"gridPos": {
"h": 9,
"w": 8,
"x": 16,
"y": 16
"h": 6,
"w": 6,
"x": 12,
"y": 13
},
"id": 13,
"legend": {
@ -828,6 +911,89 @@
"alignLevel": null
}
},
{
"aliasColors": {},
"bars": true,
"dashLength": 10,
"dashes": false,
"datasource": "gdev-postgres-ds-tests",
"fill": 2,
"gridPos": {
"h": 6,
"w": 6,
"x": 18,
"y": 13
},
"id": 37,
"legend": {
"avg": false,
"current": false,
"max": false,
"min": false,
"show": true,
"total": false,
"values": false
},
"lines": false,
"linewidth": 2,
"links": [],
"nullPointMode": "null",
"percentage": false,
"pointradius": 3,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"stack": false,
"steppedLine": true,
"targets": [
{
"alias": "",
"format": "time_series",
"rawSql": "SELECT $__timeGroupAlias(time, '$summarize', previous), sum(value) as value FROM metric WHERE $__timeFilter(time) GROUP BY 1 ORDER BY 1",
"refId": "A"
}
],
"thresholds": [],
"timeFrom": null,
"timeShift": null,
"title": "Metrics - timeGroup macro $summarize with fill(previous)",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
},
{
"aliasColors": {},
"bars": false,
@ -839,7 +1005,7 @@
"h": 8,
"w": 12,
"x": 0,
"y": 25
"y": 19
},
"id": 27,
"legend": {
@ -926,7 +1092,7 @@
"h": 8,
"w": 12,
"x": 12,
"y": 25
"y": 19
},
"id": 5,
"legend": {
@ -1011,7 +1177,7 @@
"h": 8,
"w": 12,
"x": 0,
"y": 33
"y": 27
},
"id": 4,
"legend": {
@ -1098,7 +1264,7 @@
"h": 8,
"w": 12,
"x": 12,
"y": 33
"y": 27
},
"id": 28,
"legend": {
@ -1183,7 +1349,7 @@
"h": 8,
"w": 12,
"x": 0,
"y": 41
"y": 35
},
"id": 19,
"legend": {
@ -1270,7 +1436,7 @@
"h": 8,
"w": 12,
"x": 12,
"y": 41
"y": 35
},
"id": 18,
"legend": {
@ -1355,7 +1521,7 @@
"h": 8,
"w": 12,
"x": 0,
"y": 49
"y": 43
},
"id": 17,
"legend": {
@ -1442,7 +1608,7 @@
"h": 8,
"w": 12,
"x": 12,
"y": 49
"y": 43
},
"id": 20,
"legend": {
@ -1527,7 +1693,7 @@
"h": 8,
"w": 12,
"x": 0,
"y": 57
"y": 51
},
"id": 14,
"legend": {
@ -1615,7 +1781,7 @@
"h": 8,
"w": 12,
"x": 12,
"y": 57
"y": 51
},
"id": 15,
"legend": {
@ -1702,7 +1868,7 @@
"h": 8,
"w": 12,
"x": 0,
"y": 65
"y": 59
},
"id": 25,
"legend": {
@ -1790,7 +1956,7 @@
"h": 8,
"w": 12,
"x": 12,
"y": 65
"y": 59
},
"id": 22,
"legend": {
@ -1877,7 +2043,7 @@
"h": 8,
"w": 12,
"x": 0,
"y": 73
"y": 67
},
"id": 21,
"legend": {
@ -1965,7 +2131,7 @@
"h": 8,
"w": 12,
"x": 12,
"y": 73
"y": 67
},
"id": 26,
"legend": {
@ -2052,7 +2218,7 @@
"h": 8,
"w": 12,
"x": 0,
"y": 81
"y": 75
},
"id": 23,
"legend": {
@ -2140,7 +2306,7 @@
"h": 8,
"w": 12,
"x": 12,
"y": 81
"y": 75
},
"id": 24,
"legend": {
@ -2352,6 +2518,5 @@
"timezone": "",
"title": "Datasource tests - Postgres (unittest)",
"uid": "vHQdlVziz",
"version": 1
}
"version": 9
}

View File

@ -81,7 +81,9 @@ Macro example | Description
*$__timeFrom()* | Will be replaced by the start of the currently active time selection. For example, *'2017-04-21T05:01:17Z'*
*$__timeTo()* | Will be replaced by the end of the currently active time selection. For example, *'2017-04-21T05:06:17Z'*
*$__timeGroup(dateColumn,'5m'[, fillvalue])* | Will be replaced by an expression usable in GROUP BY clause. Providing a *fillValue* of *NULL* or *floating value* will automatically fill empty series in timerange with that value. <br/>For example, *CAST(ROUND(DATEDIFF(second, '1970-01-01', time_column)/300.0, 0) as bigint)\*300*.
*$__timeGroup(dateColumn,'5m', 0)* | Same as above but with a fill parameter so all null values will be converted to the fill value (all null values would be set to zero using this example).
*$__timeGroup(dateColumn,'5m', 0)* | Same as above but with a fill parameter so missing points in that series will be added by grafana and 0 will be used as value.
*$__timeGroup(dateColumn,'5m', NULL)* | Same as above but NULL will be used as value for missing points.
*$__timeGroup(dateColumn,'5m', previous)* | Same as above but the previous value in that series will be used as fill value if no value has been seen yet NULL will be used (only available in Grafana 5.3+).
*$__timeGroupAlias(dateColumn,'5m')* | Will be replaced identical to $__timeGroup but with an added column alias (only available in Grafana 5.3+).
*$__unixEpochFilter(dateColumn)* | Will be replaced by a time range filter using the specified column name with times represented as unix timestamp. For example, *dateColumn > 1494410783 AND dateColumn < 1494497183*
*$__unixEpochFrom()* | Will be replaced by the start of the currently active time selection as unix timestamp. For example, *1494410783*

View File

@ -64,7 +64,9 @@ Macro example | Description
*$__timeFrom()* | Will be replaced by the start of the currently active time selection. For example, *'2017-04-21T05:01:17Z'*
*$__timeTo()* | Will be replaced by the end of the currently active time selection. For example, *'2017-04-21T05:06:17Z'*
*$__timeGroup(dateColumn,'5m')* | Will be replaced by an expression usable in GROUP BY clause. For example, *cast(cast(UNIX_TIMESTAMP(dateColumn)/(300) as signed)*300 as signed),*
*$__timeGroup(dateColumn,'5m',0)* | Same as above but with a fill parameter so all null values will be converted to the fill value (all null values would be set to zero using this example).
*$__timeGroup(dateColumn,'5m', 0)* | Same as above but with a fill parameter so missing points in that series will be added by grafana and 0 will be used as value.
*$__timeGroup(dateColumn,'5m', NULL)* | Same as above but NULL will be used as value for missing points.
*$__timeGroup(dateColumn,'5m', previous)* | Same as above but the previous value in that series will be used as fill value if no value has been seen yet NULL will be used (only available in Grafana 5.3+).
*$__timeGroupAlias(dateColumn,'5m')* | Will be replaced identical to $__timeGroup but with an added column alias (only available in Grafana 5.3+).
*$__unixEpochFilter(dateColumn)* | Will be replaced by a time range filter using the specified column name with times represented as unix timestamp. For example, *dateColumn > 1494410783 AND dateColumn < 1494497183*
*$__unixEpochFrom()* | Will be replaced by the start of the currently active time selection as unix timestamp. For example, *1494410783*

View File

@ -61,7 +61,9 @@ Macro example | Description
*$__timeFrom()* | Will be replaced by the start of the currently active time selection. For example, *'2017-04-21T05:01:17Z'*
*$__timeTo()* | Will be replaced by the end of the currently active time selection. For example, *'2017-04-21T05:06:17Z'*
*$__timeGroup(dateColumn,'5m')* | Will be replaced by an expression usable in GROUP BY clause. For example, *(extract(epoch from dateColumn)/300)::bigint*300*
*$__timeGroup(dateColumn,'5m', 0)* | Same as above but with a fill parameter so all null values will be converted to the fill value (all null values would be set to zero using this example).
*$__timeGroup(dateColumn,'5m', 0)* | Same as above but with a fill parameter so missing points in that series will be added by grafana and 0 will be used as value.
*$__timeGroup(dateColumn,'5m', NULL)* | Same as above but NULL will be used as value for missing points.
*$__timeGroup(dateColumn,'5m', previous)* | Same as above but the previous value in that series will be used as fill value if no value has been seen yet NULL will be used (only available in Grafana 5.3+).
*$__timeGroupAlias(dateColumn,'5m')* | Will be replaced identical to $__timeGroup but with an added column alias (only available in Grafana 5.3+).
*$__unixEpochFilter(dateColumn)* | Will be replaced by a time range filter using the specified column name with times represented as unix timestamp. For example, *dateColumn >= 1494410783 AND dateColumn <= 1494497183*
*$__unixEpochFrom()* | Will be replaced by the start of the currently active time selection as unix timestamp. For example, *1494410783*

View File

@ -99,9 +99,13 @@ func (m *msSqlMacroEngine) evaluateMacro(name string, args []string) (string, er
if len(args) == 3 {
m.query.Model.Set("fill", true)
m.query.Model.Set("fillInterval", interval.Seconds())
if args[2] == "NULL" {
m.query.Model.Set("fillNull", true)
} else {
switch args[2] {
case "NULL":
m.query.Model.Set("fillMode", "null")
case "previous":
m.query.Model.Set("fillMode", "previous")
default:
m.query.Model.Set("fillMode", "value")
floatVal, err := strconv.ParseFloat(args[2], 64)
if err != nil {
return "", fmt.Errorf("error parsing fill value %v", args[2])

View File

@ -76,12 +76,25 @@ func TestMacroEngine(t *testing.T) {
_, err := engine.Interpolate(query, timeRange, "GROUP BY $__timeGroup(time_column,'5m', NULL)")
fill := query.Model.Get("fill").MustBool()
fillNull := query.Model.Get("fillNull").MustBool()
fillMode := query.Model.Get("fillMode").MustString()
fillInterval := query.Model.Get("fillInterval").MustInt()
So(err, ShouldBeNil)
So(fill, ShouldBeTrue)
So(fillNull, ShouldBeTrue)
So(fillMode, ShouldEqual, "null")
So(fillInterval, ShouldEqual, 5*time.Minute.Seconds())
})
Convey("interpolate __timeGroup function with fill (value = previous)", func() {
_, err := engine.Interpolate(query, timeRange, "GROUP BY $__timeGroup(time_column,'5m', previous)")
fill := query.Model.Get("fill").MustBool()
fillMode := query.Model.Get("fillMode").MustString()
fillInterval := query.Model.Get("fillInterval").MustInt()
So(err, ShouldBeNil)
So(fill, ShouldBeTrue)
So(fillMode, ShouldEqual, "previous")
So(fillInterval, ShouldEqual, 5*time.Minute.Seconds())
})

View File

@ -94,9 +94,13 @@ func (m *mySqlMacroEngine) evaluateMacro(name string, args []string) (string, er
if len(args) == 3 {
m.query.Model.Set("fill", true)
m.query.Model.Set("fillInterval", interval.Seconds())
if args[2] == "NULL" {
m.query.Model.Set("fillNull", true)
} else {
switch args[2] {
case "NULL":
m.query.Model.Set("fillMode", "null")
case "previous":
m.query.Model.Set("fillMode", "previous")
default:
m.query.Model.Set("fillMode", "value")
floatVal, err := strconv.ParseFloat(args[2], 64)
if err != nil {
return "", fmt.Errorf("error parsing fill value %v", args[2])

View File

@ -295,7 +295,7 @@ func TestMySQL(t *testing.T) {
})
Convey("When doing a metric query using timeGroup with float fill enabled", func() {
Convey("When doing a metric query using timeGroup with value fill enabled", func() {
query := &tsdb.TsdbQuery{
Queries: []*tsdb.Query{
{
@ -320,6 +320,35 @@ func TestMySQL(t *testing.T) {
points := queryResult.Series[0].Points
So(points[3][0].Float64, ShouldEqual, 1.5)
})
Convey("When doing a metric query using timeGroup with previous fill enabled", func() {
query := &tsdb.TsdbQuery{
Queries: []*tsdb.Query{
{
Model: simplejson.NewFromAny(map[string]interface{}{
"rawSql": "SELECT $__timeGroup(time, '5m', previous) as time_sec, avg(value) as value FROM metric GROUP BY 1 ORDER BY 1",
"format": "time_series",
}),
RefId: "A",
},
},
TimeRange: &tsdb.TimeRange{
From: fmt.Sprintf("%v", fromStart.Unix()*1000),
To: fmt.Sprintf("%v", fromStart.Add(34*time.Minute).Unix()*1000),
},
}
resp, err := endpoint.Query(nil, nil, query)
So(err, ShouldBeNil)
queryResult := resp.Results["A"]
So(queryResult.Error, ShouldBeNil)
points := queryResult.Series[0].Points
So(points[2][0].Float64, ShouldEqual, 15.0)
So(points[3][0].Float64, ShouldEqual, 15.0)
So(points[6][0].Float64, ShouldEqual, 20.0)
})
})
Convey("Given a table with metrics having multiple values and measurements", func() {

View File

@ -116,9 +116,13 @@ func (m *postgresMacroEngine) evaluateMacro(name string, args []string) (string,
if len(args) == 3 {
m.query.Model.Set("fill", true)
m.query.Model.Set("fillInterval", interval.Seconds())
if args[2] == "NULL" {
m.query.Model.Set("fillNull", true)
} else {
switch args[2] {
case "NULL":
m.query.Model.Set("fillMode", "null")
case "previous":
m.query.Model.Set("fillMode", "previous")
default:
m.query.Model.Set("fillMode", "value")
floatVal, err := strconv.ParseFloat(args[2], 64)
if err != nil {
return "", fmt.Errorf("error parsing fill value %v", args[2])

View File

@ -276,7 +276,7 @@ func TestPostgres(t *testing.T) {
})
Convey("When doing a metric query using timeGroup with float fill enabled", func() {
Convey("When doing a metric query using timeGroup with value fill enabled", func() {
query := &tsdb.TsdbQuery{
Queries: []*tsdb.Query{
{
@ -303,6 +303,34 @@ func TestPostgres(t *testing.T) {
})
})
Convey("When doing a metric query using timeGroup with previous fill enabled", func() {
query := &tsdb.TsdbQuery{
Queries: []*tsdb.Query{
{
Model: simplejson.NewFromAny(map[string]interface{}{
"rawSql": "SELECT $__timeGroup(time, '5m', previous), avg(value) as value FROM metric GROUP BY 1 ORDER BY 1",
"format": "time_series",
}),
RefId: "A",
},
},
TimeRange: &tsdb.TimeRange{
From: fmt.Sprintf("%v", fromStart.Unix()*1000),
To: fmt.Sprintf("%v", fromStart.Add(34*time.Minute).Unix()*1000),
},
}
resp, err := endpoint.Query(nil, nil, query)
So(err, ShouldBeNil)
queryResult := resp.Results["A"]
So(queryResult.Error, ShouldBeNil)
points := queryResult.Series[0].Points
So(points[2][0].Float64, ShouldEqual, 15.0)
So(points[3][0].Float64, ShouldEqual, 15.0)
So(points[6][0].Float64, ShouldEqual, 20.0)
})
Convey("Given a table with metrics having multiple values and measurements", func() {
type metric_values struct {
Time time.Time

View File

@ -274,9 +274,15 @@ func (e *sqlQueryEndpoint) transformToTimeSeries(query *Query, rows *core.Rows,
fillMissing := query.Model.Get("fill").MustBool(false)
var fillInterval float64
fillValue := null.Float{}
fillPrevious := false
if fillMissing {
fillInterval = query.Model.Get("fillInterval").MustFloat64() * 1000
if !query.Model.Get("fillNull").MustBool(false) {
switch query.Model.Get("fillMode").MustString() {
case "null":
case "previous":
fillPrevious = true
case "value":
fillValue.Float64 = query.Model.Get("fillValue").MustFloat64()
fillValue.Valid = true
}
@ -352,6 +358,14 @@ func (e *sqlQueryEndpoint) transformToTimeSeries(query *Query, rows *core.Rows,
intervalStart = series.Points[len(series.Points)-1][1].Float64 + fillInterval
}
if fillPrevious {
if len(series.Points) > 0 {
fillValue = series.Points[len(series.Points)-1][0]
} else {
fillValue.Valid = false
}
}
// align interval start
intervalStart = math.Floor(intervalStart/fillInterval) * fillInterval
@ -377,6 +391,14 @@ func (e *sqlQueryEndpoint) transformToTimeSeries(query *Query, rows *core.Rows,
intervalStart := series.Points[len(series.Points)-1][1].Float64
intervalEnd := float64(tsdbQuery.TimeRange.MustGetTo().UnixNano() / 1e6)
if fillPrevious {
if len(series.Points) > 0 {
fillValue = series.Points[len(series.Points)-1][0]
} else {
fillValue.Valid = false
}
}
// align interval start
intervalStart = math.Floor(intervalStart/fillInterval) * fillInterval
for i := intervalStart + fillInterval; i < intervalEnd; i += fillInterval {

View File

@ -53,7 +53,9 @@ Macros:
- $__timeEpoch(column) -&gt; DATEDIFF(second, '1970-01-01', column) AS time
- $__timeFilter(column) -&gt; column BETWEEN '2017-04-21T05:01:17Z' AND '2017-04-21T05:01:17Z'
- $__unixEpochFilter(column) -&gt; column &gt;= 1492750877 AND column &lt;= 1492750877
- $__timeGroup(column, '5m'[, fillvalue]) -&gt; CAST(ROUND(DATEDIFF(second, '1970-01-01', column)/300.0, 0) as bigint)*300. Providing a <i>fillValue</i> of <i>NULL</i> or floating value will automatically fill empty series in timerange with that value.
- $__timeGroup(column, '5m'[, fillvalue]) -&gt; CAST(ROUND(DATEDIFF(second, '1970-01-01', column)/300.0, 0) as bigint)*300.
by setting fillvalue grafana will fill in missing values according to the interval
fillvalue can be either a literal value, NULL or previous; previous will fill in the previous seen value or NULL if none has been seen yet
- $__timeGroupAlias(column, '5m'[, fillvalue]) -&gt; CAST(ROUND(DATEDIFF(second, '1970-01-01', column)/300.0, 0) as bigint)*300 AS [time]
Example of group by and order by with $__timeGroup:

View File

@ -53,7 +53,9 @@ Macros:
- $__timeEpoch(column) -&gt; UNIX_TIMESTAMP(column) as time_sec
- $__timeFilter(column) -&gt; column BETWEEN '2017-04-21T05:01:17Z' AND '2017-04-21T05:01:17Z'
- $__unixEpochFilter(column) -&gt; time_unix_epoch &gt; 1492750877 AND time_unix_epoch &lt; 1492750877
- $__timeGroup(column,'5m') -&gt; cast(cast(UNIX_TIMESTAMP(column)/(300) as signed)*300 as signed)
- $__timeGroup(column,'5m'[, fillvalue]) -&gt; cast(cast(UNIX_TIMESTAMP(column)/(300) as signed)*300 as signed)
by setting fillvalue grafana will fill in missing values according to the interval
fillvalue can be either a literal value, NULL or previous; previous will fill in the previous seen value or NULL if none has been seen yet
- $__timeGroupAlias(column,'5m') -&gt; cast(cast(UNIX_TIMESTAMP(column)/(300) as signed)*300 as signed) AS "time"
Example of group by and order by with $__timeGroup:

View File

@ -53,7 +53,9 @@ Macros:
- $__timeEpoch -&gt; extract(epoch from column) as "time"
- $__timeFilter(column) -&gt; column BETWEEN '2017-04-21T05:01:17Z' AND '2017-04-21T05:01:17Z'
- $__unixEpochFilter(column) -&gt; column &gt;= 1492750877 AND column &lt;= 1492750877
- $__timeGroup(column,'5m') -&gt; (extract(epoch from column)/300)::bigint*300
- $__timeGroup(column,'5m'[, fillvalue]) -&gt; (extract(epoch from column)/300)::bigint*300
by setting fillvalue grafana will fill in missing values according to the interval
fillvalue can be either a literal value, NULL or previous; previous will fill in the previous seen value or NULL if none has been seen yet
- $__timeGroupAlias(column,'5m') -&gt; (extract(epoch from column)/300)::bigint*300 AS "time"
Example of group by and order by with $__timeGroup: