From 23c97d080ff6892379038e3742d712aa41c5b771 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Niemann?= Date: Wed, 13 Jun 2018 09:43:33 +0200 Subject: [PATCH 1/4] added id tag to Panels for html bookmarking on longer Dashboards --- public/app/features/dashboard/dashgrid/DashboardGrid.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/app/features/dashboard/dashgrid/DashboardGrid.tsx b/public/app/features/dashboard/dashgrid/DashboardGrid.tsx index 290e587eace..457ad4ef56c 100644 --- a/public/app/features/dashboard/dashgrid/DashboardGrid.tsx +++ b/public/app/features/dashboard/dashgrid/DashboardGrid.tsx @@ -177,7 +177,7 @@ export class DashboardGrid extends React.Component { for (let panel of this.dashboard.panels) { const panelClasses = classNames({ panel: true, 'panel--fullscreen': panel.fullscreen }); panelElements.push( -
+
); From 757e2b0b7ee264079853a92fe70a706a16230984 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Niemann?= Date: Mon, 18 Jun 2018 10:59:44 +0200 Subject: [PATCH 2/4] added comment to reason the id tag --- public/app/features/dashboard/dashgrid/DashboardGrid.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/public/app/features/dashboard/dashgrid/DashboardGrid.tsx b/public/app/features/dashboard/dashgrid/DashboardGrid.tsx index 457ad4ef56c..9a451798ff7 100644 --- a/public/app/features/dashboard/dashgrid/DashboardGrid.tsx +++ b/public/app/features/dashboard/dashgrid/DashboardGrid.tsx @@ -177,6 +177,7 @@ export class DashboardGrid extends React.Component { for (let panel of this.dashboard.panels) { const panelClasses = classNames({ panel: true, 'panel--fullscreen': panel.fullscreen }); panelElements.push( + /** panel-id is set for html bookmarks */
From 6b863e3b0f424229de23149d6f31492a89976160 Mon Sep 17 00:00:00 2001 From: Sven Klemm Date: Fri, 7 Sep 2018 10:21:10 +0200 Subject: [PATCH 3/4] Fix quoting to handle non-string values --- public/app/plugins/datasource/postgres/postgres_query.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/public/app/plugins/datasource/postgres/postgres_query.ts b/public/app/plugins/datasource/postgres/postgres_query.ts index fd0987f2761..04464978140 100644 --- a/public/app/plugins/datasource/postgres/postgres_query.ts +++ b/public/app/plugins/datasource/postgres/postgres_query.ts @@ -44,15 +44,15 @@ export default class PostgresQuery { } quoteIdentifier(value) { - return '"' + value.replace(/"/g, '""') + '"'; + return '"' + String(value).replace(/"/g, '""') + '"'; } quoteLiteral(value) { - return "'" + value.replace(/'/g, "''") + "'"; + return "'" + String(value).replace(/'/g, "''") + "'"; } escapeLiteral(value) { - return value.replace(/'/g, "''"); + return String(value).replace(/'/g, "''"); } hasTimeGroup() { From 116fb50530412401ff048ac0fc483975e3c85ac4 Mon Sep 17 00:00:00 2001 From: Sven Klemm Date: Sat, 8 Sep 2018 08:24:53 +0200 Subject: [PATCH 4/4] Fix query builder queries for interval start This changes the rate and increase queries to not calculate a value when there is no previous value. This also adds an order by metric column to prevent inconsistent series ordering in the legend. --- .../plugins/datasource/postgres/postgres_query.ts | 9 +++++++-- .../postgres/specs/postgres_query.test.ts | 13 +++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/public/app/plugins/datasource/postgres/postgres_query.ts b/public/app/plugins/datasource/postgres/postgres_query.ts index fd0987f2761..36b7f6edfc1 100644 --- a/public/app/plugins/datasource/postgres/postgres_query.ts +++ b/public/app/plugins/datasource/postgres/postgres_query.ts @@ -187,7 +187,8 @@ export default class PostgresQuery { case 'increase': curr = query; prev = 'lag(' + curr + ') OVER (' + over + ')'; - query = '(CASE WHEN ' + curr + ' >= ' + prev + ' THEN ' + curr + ' - ' + prev + ' ELSE ' + curr + ' END)'; + query = '(CASE WHEN ' + curr + ' >= ' + prev + ' THEN ' + curr + ' - ' + prev; + query += ' WHEN ' + prev + ' IS NULL THEN NULL ELSE ' + curr + ' END)'; break; case 'rate': let timeColumn = this.target.timeColumn; @@ -197,7 +198,8 @@ export default class PostgresQuery { curr = query; prev = 'lag(' + curr + ') OVER (' + over + ')'; - query = '(CASE WHEN ' + curr + ' >= ' + prev + ' THEN ' + curr + ' - ' + prev + ' ELSE ' + curr + ' END)'; + query = '(CASE WHEN ' + curr + ' >= ' + prev + ' THEN ' + curr + ' - ' + prev; + query += ' WHEN ' + prev + ' IS NULL THEN NULL ELSE ' + curr + ' END)'; query += '/extract(epoch from ' + timeColumn + ' - lag(' + timeColumn + ') OVER (' + over + '))'; break; default: @@ -279,6 +281,9 @@ export default class PostgresQuery { query += this.buildGroupClause(); query += '\nORDER BY 1'; + if (this.hasMetricColumn()) { + query += ',2'; + } return query; } diff --git a/public/app/plugins/datasource/postgres/specs/postgres_query.test.ts b/public/app/plugins/datasource/postgres/specs/postgres_query.test.ts index 0d6f61a8748..42b143c01c8 100644 --- a/public/app/plugins/datasource/postgres/specs/postgres_query.test.ts +++ b/public/app/plugins/datasource/postgres/specs/postgres_query.test.ts @@ -72,7 +72,9 @@ describe('PostgresQuery', () => { { type: 'window', params: ['increase'] }, ]; expect(query.buildValueColumn(column)).toBe( - '(CASE WHEN v >= lag(v) OVER (ORDER BY time) THEN v - lag(v) OVER (ORDER BY time) ELSE v END) AS "a"' + '(CASE WHEN v >= lag(v) OVER (ORDER BY time) ' + + 'THEN v - lag(v) OVER (ORDER BY time) ' + + 'WHEN lag(v) OVER (ORDER BY time) IS NULL THEN NULL ELSE v END) AS "a"' ); }); @@ -96,7 +98,9 @@ describe('PostgresQuery', () => { { type: 'window', params: ['increase'] }, ]; expect(query.buildValueColumn(column)).toBe( - '(CASE WHEN v >= lag(v) OVER (PARTITION BY host ORDER BY time) THEN v - lag(v) OVER (PARTITION BY host ORDER BY time) ELSE v END) AS "a"' + '(CASE WHEN v >= lag(v) OVER (PARTITION BY host ORDER BY time) ' + + 'THEN v - lag(v) OVER (PARTITION BY host ORDER BY time) ' + + 'WHEN lag(v) OVER (PARTITION BY host ORDER BY time) IS NULL THEN NULL ELSE v END) AS "a"' ); column = [ { type: 'column', params: ['v'] }, @@ -106,7 +110,8 @@ describe('PostgresQuery', () => { ]; expect(query.buildValueColumn(column)).toBe( '(CASE WHEN max(v) >= lag(max(v)) OVER (PARTITION BY host ORDER BY time) ' + - 'THEN max(v) - lag(max(v)) OVER (PARTITION BY host ORDER BY time) ELSE max(v) END) AS "a"' + 'THEN max(v) - lag(max(v)) OVER (PARTITION BY host ORDER BY time) ' + + 'WHEN lag(max(v)) OVER (PARTITION BY host ORDER BY time) IS NULL THEN NULL ELSE max(v) END) AS "a"' ); }); @@ -149,7 +154,7 @@ describe('PostgresQuery', () => { expect(query.buildQuery()).toBe(result); query.target.metricColumn = 'm'; - result = 'SELECT\n t AS "time",\n m AS metric,\n value\nFROM table\nORDER BY 1'; + result = 'SELECT\n t AS "time",\n m AS metric,\n value\nFROM table\nORDER BY 1,2'; expect(query.buildQuery()).toBe(result); }); });