Ver Fonte

Add delta window function to postgres query builder

Unlike the increase function delta doesn't check for resets
and can go negative. This is similar to the prometheus delta
function.
Sven Klemm há 7 anos atrás
pai
commit
f608340c35

+ 5 - 0
public/app/plugins/datasource/postgres/postgres_query.ts

@@ -184,6 +184,11 @@ export default class PostgresQuery {
       switch (windows.type) {
       switch (windows.type) {
         case 'window':
         case 'window':
           switch (windows.params[0]) {
           switch (windows.params[0]) {
+            case 'delta':
+              curr = query;
+              prev = 'lag(' + curr + ') OVER (' + over + ')';
+              query = curr + ' - ' + prev;
+              break;
             case 'increase':
             case 'increase':
               curr = query;
               curr = query;
               prev = 'lag(' + curr + ') OVER (' + over + ')';
               prev = 'lag(' + curr + ') OVER (' + over + ')';

+ 1 - 0
public/app/plugins/datasource/postgres/query_ctrl.ts

@@ -158,6 +158,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
       text: 'Window Functions',
       text: 'Window Functions',
       value: 'window',
       value: 'window',
       submenu: [
       submenu: [
+        { text: 'Delta', value: 'delta' },
         { text: 'Increase', value: 'increase' },
         { text: 'Increase', value: 'increase' },
         { text: 'Rate', value: 'rate' },
         { text: 'Rate', value: 'rate' },
         { text: 'Sum', value: 'sum' },
         { text: 'Sum', value: 'sum' },

+ 1 - 1
public/app/plugins/datasource/postgres/sql_part.ts

@@ -107,7 +107,7 @@ register({
     {
     {
       name: 'function',
       name: 'function',
       type: 'string',
       type: 'string',
-      options: ['increase', 'rate', 'sum'],
+      options: ['delta', 'increase', 'rate', 'sum'],
     },
     },
   ],
   ],
   defaultParams: ['increase'],
   defaultParams: ['increase'],