From 62174c81c824faa8a988094480bd0afde47070f3 Mon Sep 17 00:00:00 2001 From: Marcus Efraimsson Date: Mon, 19 Mar 2018 13:06:46 +0100 Subject: [PATCH] mssql: cleanup and minor changes --- public/app/plugins/datasource/mssql/module.ts | 14 ++++++++------ .../mssql/partials/annotations.editor.html | 18 +++++++++--------- .../datasource/mssql/partials/config.html | 4 +--- .../mssql/partials/query.editor.html | 12 ++++++------ .../app/plugins/datasource/mssql/query_ctrl.ts | 12 +++++++----- .../datasource/mssql/response_parser.ts | 4 ---- 6 files changed, 31 insertions(+), 33 deletions(-) diff --git a/public/app/plugins/datasource/mssql/module.ts b/public/app/plugins/datasource/mssql/module.ts index fca3ec6b7bd..a2e1e923bc6 100644 --- a/public/app/plugins/datasource/mssql/module.ts +++ b/public/app/plugins/datasource/mssql/module.ts @@ -5,14 +5,16 @@ class MssqlConfigCtrl { static templateUrl = 'partials/config.html'; } -const defaultQuery = `SELECT TOP 100 - $__utcTime(), +const defaultQuery = `SELECT + as time, as text, as tags - FROM - WHERE $__timeFilter(time_column) - ORDER BY ASC - `; + FROM +
+ WHERE + $__timeFilter(time_column) + ORDER BY + ASC`; class MssqlAnnotationsQueryCtrl { static templateUrl = 'partials/annotations.editor.html'; diff --git a/public/app/plugins/datasource/mssql/partials/annotations.editor.html b/public/app/plugins/datasource/mssql/partials/annotations.editor.html index 015ba2b4416..ecdffd92d1e 100644 --- a/public/app/plugins/datasource/mssql/partials/annotations.editor.html +++ b/public/app/plugins/datasource/mssql/partials/annotations.editor.html @@ -18,23 +18,23 @@
Annotation Query Format
-An annotation is an event that is overlayed 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. +An annotation is an event that is overlayed 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. -- column with alias: time for the annotation event time (in UTC), as a unix time stamp or any sql native date datatype. -- column with alias: text for the annotation text -- column with alias: tags for annotation tags. This is a comma separated string of tags e.g. 'tag1,tag2' +- column with alias: time for the annotation event time (in UTC). Use unix timestamp in seconds or any native date data type. +- column with alias: text for the annotation text. +- column with alias: tags for annotation tags. This is a comma separated string of tags e.g. 'tag1,tag2'. Macros: - $__time(column) -> column AS time -- $__utcTime(column) -> DATEADD(second, DATEDIFF(second,GETDATE(),GETUTCDATE()), column) AS time -- $__timeEpoch(column) -> DATEDIFF(second, {d '1970-01-01'}, DATEADD(second, DATEDIFF(second,GETDATE(),GETUTCDATE()), column) ) AS time -- $__timeFilter(column) -> column > DATEADD(s, 1492750877+DATEDIFF(second,GETUTCDATE(),GETDATE()), '1970-01-01') AND column < DATEADD(s, 1492750877+DATEDIFF(second,GETUTCDATE(),GETDATE()), '1970-01-01') +- $__utcTime(column) -> DATEADD(second, DATEDIFF(second, GETDATE(), GETUTCDATE()), column) AS time +- $__timeEpoch(column) -> DATEDIFF(second, {d '1970-01-01'}, DATEADD(second, DATEDIFF(second, GETDATE(), GETUTCDATE()), column) ) AS time +- $__timeFilter(column) -> column > DATEADD(s, 1492750877+DATEDIFF(second, GETUTCDATE(), GETDATE()), '1970-01-01') AND column < DATEADD(s, 1492750877+DATEDIFF(second, GETUTCDATE(), GETDATE()), '1970-01-01') - $__unixEpochFilter(column) -> column > 1492750877 AND column < 1492750877 Or build your own conditionals using these macros which just return the values: -- $__timeFrom() -> DATEADD(second, 1492750877+DATEDIFF(second,GETUTCDATE(),GETDATE()), '1970-01-01') -- $__timeTo() -> DATEADD(second, 1492750877+DATEDIFF(second,GETUTCDATE(),GETDATE()), '1970-01-01') +- $__timeFrom() -> DATEADD(second, 1492750877+DATEDIFF(second, GETUTCDATE(), GETDATE()), '1970-01-01') +- $__timeTo() -> DATEADD(second, 1492750877+DATEDIFF(second, GETUTCDATE(), GETDATE()), '1970-01-01') - $__unixEpochFrom() -> 1492750877 - $__unixEpochTo() -> 1492750877
diff --git a/public/app/plugins/datasource/mssql/partials/config.html b/public/app/plugins/datasource/mssql/partials/config.html index 2af84b3611a..9da64fa12c2 100644 --- a/public/app/plugins/datasource/mssql/partials/config.html +++ b/public/app/plugins/datasource/mssql/partials/config.html @@ -4,7 +4,7 @@
Host - +
@@ -32,8 +32,6 @@ Grafana does not validate that queries are safe so queries can contain any SQL statement. For example, statements like USE otherdb; and DROP TABLE user; would be executed. To protect against this we Highly recommmend you create a specific MSSQL user with restricted permissions. - - Checkout the MSSQL Data Source Docs for more information.

diff --git a/public/app/plugins/datasource/mssql/partials/query.editor.html b/public/app/plugins/datasource/mssql/partials/query.editor.html index e24b004822b..e8f44c8c9f8 100644 --- a/public/app/plugins/datasource/mssql/partials/query.editor.html +++ b/public/app/plugins/datasource/mssql/partials/query.editor.html @@ -38,7 +38,7 @@
Time series:
-- return column named time (in UTC), as a unix time stamp or any sql native date datatype. You can use the macros below.
+- return column named time (in UTC), as a unix time stamp or any sql native date data type. You can use the macros below.
 - optional: return column named metric to represent the series names.
 - any other columns returned will be the time point values.
 - if multiple value columns are present and a metric column is provided. the series name will be the combination of "MetricName - ValueColumnName".
@@ -48,15 +48,15 @@ Table:
 
 Macros:
 - $__time(column) -> column AS time
-- $__utcTime(column) -> DATEADD(second, DATEDIFF(second,GETDATE(),GETUTCDATE()), column) AS time
-- $__timeEpoch(column) -> DATEDIFF(second, {d '1970-01-01'}, DATEADD(second, DATEDIFF(second,GETDATE(),GETUTCDATE()), column) ) AS time
-- $__timeFilter(column) -> column > DATEADD(s, 1492750877+DATEDIFF(second,GETUTCDATE(),GETDATE()), '1970-01-01') AND column < DATEADD(s, 1492750877+DATEDIFF(second,GETUTCDATE(),GETDATE()), '1970-01-01')
+- $__utcTime(column) -> DATEADD(second, DATEDIFF(second, GETDATE(), GETUTCDATE()), column) AS time
+- $__timeEpoch(column) -> DATEDIFF(second, {d '1970-01-01'}, DATEADD(second, DATEDIFF(second, GETDATE(), GETUTCDATE()), column) ) AS time
+- $__timeFilter(column) -> column > DATEADD(s, 1492750877+DATEDIFF(second, GETUTCDATE(), GETDATE()), '1970-01-01') AND column < DATEADD(s, 1492750877+DATEDIFF(second, GETUTCDATE(), GETDATE()), '1970-01-01')
 - $__unixEpochFilter(column) -> column > 1492750877 AND column < 1492750877
 - $__timeGroup(column, '5m'[, fillvalue]) -> cast(cast(DATEDIFF(second, {d '1970-01-01'}, DATEADD(second, DATEDIFF(second, GETDATE(), GETUTCDATE()), column))/300 as int)*300 as int). Providing a fillValue of NULL or floating value will automatically fill empty series in timerange with that value.
 
 Or build your own conditionals using these macros which just return the values:
-- $__timeFrom() -> DATEADD(second, 1492750877+DATEDIFF(second,GETUTCDATE(),GETDATE()), '1970-01-01')
-- $__timeTo() -> DATEADD(second, 1492750877+DATEDIFF(second,GETUTCDATE(),GETDATE()), '1970-01-01')
+- $__timeFrom() -> DATEADD(second, 1492750877+DATEDIFF(second, GETUTCDATE(), GETDATE()), '1970-01-01')
+- $__timeTo() -> DATEADD(second, 1492750877+DATEDIFF(second, GETUTCDATE(), GETDATE()), '1970-01-01')
 - $__unixEpochFrom() -> 1492750877
 - $__unixEpochTo() -> 1492750877
 		
diff --git a/public/app/plugins/datasource/mssql/query_ctrl.ts b/public/app/plugins/datasource/mssql/query_ctrl.ts index c7f745a76fa..884eb634f54 100644 --- a/public/app/plugins/datasource/mssql/query_ctrl.ts +++ b/public/app/plugins/datasource/mssql/query_ctrl.ts @@ -13,13 +13,15 @@ export interface QueryMeta { } const defaultQuery = `SELECT - $__utcTime(), + $__timeEpoch(), as value, as metric -FROM
-WHERE $__timeFilter(time_column) -ORDER BY ASC -`; +FROM +
+WHERE + $__timeFilter(time_column) +ORDER BY + ASC`; export class MssqlQueryCtrl extends QueryCtrl { static templateUrl = 'partials/query.editor.html'; diff --git a/public/app/plugins/datasource/mssql/response_parser.ts b/public/app/plugins/datasource/mssql/response_parser.ts index 8f4e9c005ff..b7d96d820cb 100644 --- a/public/app/plugins/datasource/mssql/response_parser.ts +++ b/public/app/plugins/datasource/mssql/response_parser.ts @@ -112,10 +112,6 @@ 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 === 'title') { - return this.$q.reject({ - message: 'The title column for annotations is deprecated, now only a column named text is returned', - }); } else if (table.columns[i].text === 'text') { textColumnIndex = i; } else if (table.columns[i].text === 'tags') {