From 1a67a8db80c1a38294d833454866bebbc64ff34e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ander=20Argui=C3=B1ano?= Date: Wed, 2 Jan 2019 23:00:21 +0100 Subject: [PATCH 1/8] Nanosecond timestamp support postgresql --- pkg/tsdb/postgres/macros.go | 5 +++++ pkg/tsdb/postgres/macros_test.go | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/pkg/tsdb/postgres/macros.go b/pkg/tsdb/postgres/macros.go index 26a3d1e53ee..7f50f8269ca 100644 --- a/pkg/tsdb/postgres/macros.go +++ b/pkg/tsdb/postgres/macros.go @@ -122,6 +122,11 @@ func (m *postgresMacroEngine) evaluateMacro(name string, args []string) (string, return "", fmt.Errorf("missing time column argument for macro %v", name) } return fmt.Sprintf("%s >= %d AND %s <= %d", args[0], m.timeRange.GetFromAsSecondsEpoch(), args[0], m.timeRange.GetToAsSecondsEpoch()), nil + case "__unixEpochFilterNano": + if len(args) == 0 { + return "", fmt.Errorf("missing time column argument for macro %v", name) + } + return fmt.Sprintf("%s >= %d AND %s <= %d", args[0], m.timeRange.GetFromAsTimeUTC().UnixNano(), args[0], m.timeRange.GetToAsTimeUTC().UnixNano()), nil case "__unixEpochGroup": if len(args) < 2 { return "", fmt.Errorf("macro %v needs time column and interval and optional fill value", name) diff --git a/pkg/tsdb/postgres/macros_test.go b/pkg/tsdb/postgres/macros_test.go index 6a71caedeb9..0ec49bedb21 100644 --- a/pkg/tsdb/postgres/macros_test.go +++ b/pkg/tsdb/postgres/macros_test.go @@ -115,6 +115,12 @@ func TestMacroEngine(t *testing.T) { So(sql, ShouldEqual, fmt.Sprintf("select time >= %d AND time <= %d", from.Unix(), to.Unix())) }) + Convey("interpolate __unixEpochFilterNano function", func() { + sql, err := engine.Interpolate(query, timeRange, "select $__unixEpochFilterNano(time)") + So(err, ShouldBeNil) + + So(sql, ShouldEqual, fmt.Sprintf("select time >= %d AND time <= %d", from.UnixNano(), to.UnixNano())) + }) Convey("interpolate __unixEpochGroup function", func() { @@ -147,6 +153,12 @@ func TestMacroEngine(t *testing.T) { So(sql, ShouldEqual, fmt.Sprintf("select time >= %d AND time <= %d", from.Unix(), to.Unix())) }) + Convey("interpolate __unixEpochFilterNano function", func() { + sql, err := engine.Interpolate(query, timeRange, "select $__unixEpochFilterNano(time)") + So(err, ShouldBeNil) + + So(sql, ShouldEqual, fmt.Sprintf("select time >= %d AND time <= %d", from.UnixNano(), to.UnixNano())) + }) }) Convey("Given a time range between 1960-02-01 07:00 and 1980-02-03 08:00", func() { @@ -167,6 +179,12 @@ func TestMacroEngine(t *testing.T) { So(sql, ShouldEqual, fmt.Sprintf("select time >= %d AND time <= %d", from.Unix(), to.Unix())) }) + Convey("interpolate __unixEpochFilterNano function", func() { + sql, err := engine.Interpolate(query, timeRange, "select $__unixEpochFilterNano(time)") + So(err, ShouldBeNil) + + So(sql, ShouldEqual, fmt.Sprintf("select time >= %d AND time <= %d", from.UnixNano(), to.UnixNano())) + }) }) }) } From 4d8d2a9690e3694dac65fd944b36d806b99cf32a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ander=20Argui=C3=B1ano?= Date: Thu, 3 Jan 2019 20:40:17 +0100 Subject: [PATCH 2/8] Renamed unixEpochFilterNano to unixEpochNanoFilter --- pkg/tsdb/postgres/macros.go | 2 +- pkg/tsdb/postgres/macros_test.go | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/tsdb/postgres/macros.go b/pkg/tsdb/postgres/macros.go index 7f50f8269ca..3af43dfcf3e 100644 --- a/pkg/tsdb/postgres/macros.go +++ b/pkg/tsdb/postgres/macros.go @@ -122,7 +122,7 @@ func (m *postgresMacroEngine) evaluateMacro(name string, args []string) (string, return "", fmt.Errorf("missing time column argument for macro %v", name) } return fmt.Sprintf("%s >= %d AND %s <= %d", args[0], m.timeRange.GetFromAsSecondsEpoch(), args[0], m.timeRange.GetToAsSecondsEpoch()), nil - case "__unixEpochFilterNano": + case "__unixEpochNanoFilter": if len(args) == 0 { return "", fmt.Errorf("missing time column argument for macro %v", name) } diff --git a/pkg/tsdb/postgres/macros_test.go b/pkg/tsdb/postgres/macros_test.go index 0ec49bedb21..6334a3b5239 100644 --- a/pkg/tsdb/postgres/macros_test.go +++ b/pkg/tsdb/postgres/macros_test.go @@ -115,8 +115,8 @@ func TestMacroEngine(t *testing.T) { So(sql, ShouldEqual, fmt.Sprintf("select time >= %d AND time <= %d", from.Unix(), to.Unix())) }) - Convey("interpolate __unixEpochFilterNano function", func() { - sql, err := engine.Interpolate(query, timeRange, "select $__unixEpochFilterNano(time)") + Convey("interpolate __unixEpochNanoFilter function", func() { + sql, err := engine.Interpolate(query, timeRange, "select $__unixEpochNanoFilter(time)") So(err, ShouldBeNil) So(sql, ShouldEqual, fmt.Sprintf("select time >= %d AND time <= %d", from.UnixNano(), to.UnixNano())) @@ -153,8 +153,8 @@ func TestMacroEngine(t *testing.T) { So(sql, ShouldEqual, fmt.Sprintf("select time >= %d AND time <= %d", from.Unix(), to.Unix())) }) - Convey("interpolate __unixEpochFilterNano function", func() { - sql, err := engine.Interpolate(query, timeRange, "select $__unixEpochFilterNano(time)") + Convey("interpolate __unixEpochNanoFilter function", func() { + sql, err := engine.Interpolate(query, timeRange, "select $__unixEpochNanoFilter(time)") So(err, ShouldBeNil) So(sql, ShouldEqual, fmt.Sprintf("select time >= %d AND time <= %d", from.UnixNano(), to.UnixNano())) @@ -179,8 +179,8 @@ func TestMacroEngine(t *testing.T) { So(sql, ShouldEqual, fmt.Sprintf("select time >= %d AND time <= %d", from.Unix(), to.Unix())) }) - Convey("interpolate __unixEpochFilterNano function", func() { - sql, err := engine.Interpolate(query, timeRange, "select $__unixEpochFilterNano(time)") + Convey("interpolate __unixEpochNanoFilter function", func() { + sql, err := engine.Interpolate(query, timeRange, "select $__unixEpochNanoFilter(time)") So(err, ShouldBeNil) So(sql, ShouldEqual, fmt.Sprintf("select time >= %d AND time <= %d", from.UnixNano(), to.UnixNano())) From 9105625f246b55eab047732a7fdec2f3434c546e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ander=20Argui=C3=B1ano?= Date: Thu, 3 Jan 2019 21:31:47 +0100 Subject: [PATCH 3/8] Added unixEpochNanoTo and unixEpochNanoFrom macros to postgresql --- pkg/tsdb/postgres/macros.go | 4 ++++ pkg/tsdb/postgres/macros_test.go | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/pkg/tsdb/postgres/macros.go b/pkg/tsdb/postgres/macros.go index 3af43dfcf3e..048a2f34452 100644 --- a/pkg/tsdb/postgres/macros.go +++ b/pkg/tsdb/postgres/macros.go @@ -127,6 +127,10 @@ func (m *postgresMacroEngine) evaluateMacro(name string, args []string) (string, return "", fmt.Errorf("missing time column argument for macro %v", name) } return fmt.Sprintf("%s >= %d AND %s <= %d", args[0], m.timeRange.GetFromAsTimeUTC().UnixNano(), args[0], m.timeRange.GetToAsTimeUTC().UnixNano()), nil + case "__unixEpochNanoFrom": + return fmt.Sprintf("'%d'", m.timeRange.GetFromAsTimeUTC().UnixNano()), nil + case "__unixEpochNanoTo": + return fmt.Sprintf("'%d'", m.timeRange.GetToAsTimeUTC().UnixNano()), nil case "__unixEpochGroup": if len(args) < 2 { return "", fmt.Errorf("macro %v needs time column and interval and optional fill value", name) diff --git a/pkg/tsdb/postgres/macros_test.go b/pkg/tsdb/postgres/macros_test.go index 6334a3b5239..aa9eb5659e0 100644 --- a/pkg/tsdb/postgres/macros_test.go +++ b/pkg/tsdb/postgres/macros_test.go @@ -121,6 +121,19 @@ func TestMacroEngine(t *testing.T) { So(sql, ShouldEqual, fmt.Sprintf("select time >= %d AND time <= %d", from.UnixNano(), to.UnixNano())) }) + Convey("interpolate __unixEpochNanoFrom function", func() { + sql, err := engine.Interpolate(query, timeRange, "select $__unixEpochNanoFrom()") + So(err, ShouldBeNil) + + So(sql, ShouldEqual, fmt.Sprintf("select '%d'", from.UnixNano())) + }) + + Convey("interpolate __unixEpochNanoTo function", func() { + sql, err := engine.Interpolate(query, timeRange, "select $__unixEpochNanoTo()") + So(err, ShouldBeNil) + + So(sql, ShouldEqual, fmt.Sprintf("select '%d'", to.UnixNano())) + }) Convey("interpolate __unixEpochGroup function", func() { From b4eac406d5dee31d77bdf9ea1bc88c77fb23853e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ander=20Argui=C3=B1ano?= Date: Thu, 3 Jan 2019 21:43:08 +0100 Subject: [PATCH 4/8] Added previous macros to mssql --- pkg/tsdb/mssql/macros.go | 9 +++++++++ pkg/tsdb/mssql/macros_test.go | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/pkg/tsdb/mssql/macros.go b/pkg/tsdb/mssql/macros.go index dac18f3ac03..a99e6e41557 100644 --- a/pkg/tsdb/mssql/macros.go +++ b/pkg/tsdb/mssql/macros.go @@ -96,6 +96,15 @@ func (m *msSqlMacroEngine) evaluateMacro(name string, args []string) (string, er return "", fmt.Errorf("missing time column argument for macro %v", name) } return fmt.Sprintf("%s >= %d AND %s <= %d", args[0], m.timeRange.GetFromAsSecondsEpoch(), args[0], m.timeRange.GetToAsSecondsEpoch()), nil + case "__unixEpochNanoFilter": + if len(args) == 0 { + return "", fmt.Errorf("missing time column argument for macro %v", name) + } + return fmt.Sprintf("%s >= %d AND %s <= %d", args[0], m.timeRange.GetFromAsTimeUTC().UnixNano(), args[0], m.timeRange.GetToAsTimeUTC().UnixNano()), nil + case "__unixEpochNanoFrom": + return fmt.Sprintf("'%d'", m.timeRange.GetFromAsTimeUTC().UnixNano()), nil + case "__unixEpochNanoTo": + return fmt.Sprintf("'%d'", m.timeRange.GetToAsTimeUTC().UnixNano()), nil case "__unixEpochGroup": if len(args) < 2 { return "", fmt.Errorf("macro %v needs time column and interval and optional fill value", name) diff --git a/pkg/tsdb/mssql/macros_test.go b/pkg/tsdb/mssql/macros_test.go index 43cbe9fefda..311bffe3bcb 100644 --- a/pkg/tsdb/mssql/macros_test.go +++ b/pkg/tsdb/mssql/macros_test.go @@ -132,6 +132,26 @@ func TestMacroEngine(t *testing.T) { So(sql, ShouldEqual, fmt.Sprintf("select time_column >= %d AND time_column <= %d", from.Unix(), to.Unix())) }) + Convey("interpolate __unixEpochNanoFilter function", func() { + sql, err := engine.Interpolate(query, timeRange, "select $__unixEpochNanoFilter(time_column)") + So(err, ShouldBeNil) + + So(sql, ShouldEqual, fmt.Sprintf("select time_column >= %d AND time_column <= %d", from.UnixNano(), to.UnixNano())) + }) + Convey("interpolate __unixEpochNanoFrom function", func() { + sql, err := engine.Interpolate(query, timeRange, "select $__unixEpochNanoFrom()") + So(err, ShouldBeNil) + + So(sql, ShouldEqual, fmt.Sprintf("select '%d'", from.UnixNano())) + }) + + Convey("interpolate __unixEpochNanoTo function", func() { + sql, err := engine.Interpolate(query, timeRange, "select $__unixEpochNanoTo()") + So(err, ShouldBeNil) + + So(sql, ShouldEqual, fmt.Sprintf("select '%d'", to.UnixNano())) + }) + Convey("interpolate __unixEpochGroup function", func() { sql, err := engine.Interpolate(query, timeRange, "SELECT $__unixEpochGroup(time_column,'5m')") @@ -163,6 +183,13 @@ func TestMacroEngine(t *testing.T) { So(sql, ShouldEqual, fmt.Sprintf("select time_column >= %d AND time_column <= %d", from.Unix(), to.Unix())) }) + + Convey("interpolate __unixEpochNanoFilter function", func() { + sql, err := engine.Interpolate(query, timeRange, "select $__unixEpochNanoFilter(time_column)") + So(err, ShouldBeNil) + + So(sql, ShouldEqual, fmt.Sprintf("select time_column >= %d AND time_column <= %d", from.UnixNano(), to.UnixNano())) + }) }) Convey("Given a time range between 1960-02-01 07:00 and 1980-02-03 08:00", func() { @@ -183,6 +210,13 @@ func TestMacroEngine(t *testing.T) { So(sql, ShouldEqual, fmt.Sprintf("select time_column >= %d AND time_column <= %d", from.Unix(), to.Unix())) }) + + Convey("interpolate __unixEpochNanoFilter function", func() { + sql, err := engine.Interpolate(query, timeRange, "select $__unixEpochNanoFilter(time_column)") + So(err, ShouldBeNil) + + So(sql, ShouldEqual, fmt.Sprintf("select time_column >= %d AND time_column <= %d", from.UnixNano(), to.UnixNano())) + }) }) }) } From 3801a751318523a5c5f33a254ffb0b04229c2543 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ander=20Argui=C3=B1ano?= Date: Thu, 3 Jan 2019 22:25:10 +0100 Subject: [PATCH 5/8] FIxed syntaxis mistake unixEpochNanoFrom and unixEpochNanoTo --- pkg/tsdb/mssql/macros.go | 4 ++-- pkg/tsdb/mssql/macros_test.go | 4 ++-- pkg/tsdb/postgres/macros.go | 4 ++-- pkg/tsdb/postgres/macros_test.go | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/tsdb/mssql/macros.go b/pkg/tsdb/mssql/macros.go index a99e6e41557..ec3f103a4ef 100644 --- a/pkg/tsdb/mssql/macros.go +++ b/pkg/tsdb/mssql/macros.go @@ -102,9 +102,9 @@ func (m *msSqlMacroEngine) evaluateMacro(name string, args []string) (string, er } return fmt.Sprintf("%s >= %d AND %s <= %d", args[0], m.timeRange.GetFromAsTimeUTC().UnixNano(), args[0], m.timeRange.GetToAsTimeUTC().UnixNano()), nil case "__unixEpochNanoFrom": - return fmt.Sprintf("'%d'", m.timeRange.GetFromAsTimeUTC().UnixNano()), nil + return fmt.Sprintf("%d", m.timeRange.GetFromAsTimeUTC().UnixNano()), nil case "__unixEpochNanoTo": - return fmt.Sprintf("'%d'", m.timeRange.GetToAsTimeUTC().UnixNano()), nil + return fmt.Sprintf("%d", m.timeRange.GetToAsTimeUTC().UnixNano()), nil case "__unixEpochGroup": if len(args) < 2 { return "", fmt.Errorf("macro %v needs time column and interval and optional fill value", name) diff --git a/pkg/tsdb/mssql/macros_test.go b/pkg/tsdb/mssql/macros_test.go index 311bffe3bcb..829a8b1ff1a 100644 --- a/pkg/tsdb/mssql/macros_test.go +++ b/pkg/tsdb/mssql/macros_test.go @@ -142,14 +142,14 @@ func TestMacroEngine(t *testing.T) { sql, err := engine.Interpolate(query, timeRange, "select $__unixEpochNanoFrom()") So(err, ShouldBeNil) - So(sql, ShouldEqual, fmt.Sprintf("select '%d'", from.UnixNano())) + So(sql, ShouldEqual, fmt.Sprintf("select %d", from.UnixNano())) }) Convey("interpolate __unixEpochNanoTo function", func() { sql, err := engine.Interpolate(query, timeRange, "select $__unixEpochNanoTo()") So(err, ShouldBeNil) - So(sql, ShouldEqual, fmt.Sprintf("select '%d'", to.UnixNano())) + So(sql, ShouldEqual, fmt.Sprintf("select %d", to.UnixNano())) }) Convey("interpolate __unixEpochGroup function", func() { diff --git a/pkg/tsdb/postgres/macros.go b/pkg/tsdb/postgres/macros.go index c51a11877d5..fbba582c262 100644 --- a/pkg/tsdb/postgres/macros.go +++ b/pkg/tsdb/postgres/macros.go @@ -128,9 +128,9 @@ func (m *postgresMacroEngine) evaluateMacro(name string, args []string) (string, } return fmt.Sprintf("%s >= %d AND %s <= %d", args[0], m.timeRange.GetFromAsTimeUTC().UnixNano(), args[0], m.timeRange.GetToAsTimeUTC().UnixNano()), nil case "__unixEpochNanoFrom": - return fmt.Sprintf("'%d'", m.timeRange.GetFromAsTimeUTC().UnixNano()), nil + return fmt.Sprintf("%d", m.timeRange.GetFromAsTimeUTC().UnixNano()), nil case "__unixEpochNanoTo": - return fmt.Sprintf("'%d'", m.timeRange.GetToAsTimeUTC().UnixNano()), nil + return fmt.Sprintf("%d", m.timeRange.GetToAsTimeUTC().UnixNano()), nil case "__unixEpochGroup": if len(args) < 2 { return "", fmt.Errorf("macro %v needs time column and interval and optional fill value", name) diff --git a/pkg/tsdb/postgres/macros_test.go b/pkg/tsdb/postgres/macros_test.go index ceb418fbfed..eb14656c546 100644 --- a/pkg/tsdb/postgres/macros_test.go +++ b/pkg/tsdb/postgres/macros_test.go @@ -125,14 +125,14 @@ func TestMacroEngine(t *testing.T) { sql, err := engine.Interpolate(query, timeRange, "select $__unixEpochNanoFrom()") So(err, ShouldBeNil) - So(sql, ShouldEqual, fmt.Sprintf("select '%d'", from.UnixNano())) + So(sql, ShouldEqual, fmt.Sprintf("select %d", from.UnixNano())) }) Convey("interpolate __unixEpochNanoTo function", func() { sql, err := engine.Interpolate(query, timeRange, "select $__unixEpochNanoTo()") So(err, ShouldBeNil) - So(sql, ShouldEqual, fmt.Sprintf("select '%d'", to.UnixNano())) + So(sql, ShouldEqual, fmt.Sprintf("select %d", to.UnixNano())) }) Convey("interpolate __unixEpochGroup function", func() { From 089d85af639a473177733f11c904fdab5c7be511 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ander=20Argui=C3=B1ano?= Date: Thu, 3 Jan 2019 22:29:57 +0100 Subject: [PATCH 6/8] Added macros to mysql --- pkg/tsdb/mysql/macros.go | 9 +++++++++ pkg/tsdb/mysql/macros_test.go | 21 +++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/pkg/tsdb/mysql/macros.go b/pkg/tsdb/mysql/macros.go index c0ed64aa65c..bbd928b0563 100644 --- a/pkg/tsdb/mysql/macros.go +++ b/pkg/tsdb/mysql/macros.go @@ -91,6 +91,15 @@ func (m *mySqlMacroEngine) evaluateMacro(name string, args []string) (string, er return "", fmt.Errorf("missing time column argument for macro %v", name) } return fmt.Sprintf("%s >= %d AND %s <= %d", args[0], m.timeRange.GetFromAsSecondsEpoch(), args[0], m.timeRange.GetToAsSecondsEpoch()), nil + case "__unixEpochNanoFilter": + if len(args) == 0 { + return "", fmt.Errorf("missing time column argument for macro %v", name) + } + return fmt.Sprintf("%s >= %d AND %s <= %d", args[0], m.timeRange.GetFromAsTimeUTC().UnixNano(), args[0], m.timeRange.GetToAsTimeUTC().UnixNano()), nil + case "__unixEpochNanoFrom": + return fmt.Sprintf("%d", m.timeRange.GetFromAsTimeUTC().UnixNano()), nil + case "__unixEpochNanoTo": + return fmt.Sprintf("%d", m.timeRange.GetToAsTimeUTC().UnixNano()), nil case "__unixEpochGroup": if len(args) < 2 { return "", fmt.Errorf("macro %v needs time column and interval and optional fill value", name) diff --git a/pkg/tsdb/mysql/macros_test.go b/pkg/tsdb/mysql/macros_test.go index 49633347a4c..7d129e845b1 100644 --- a/pkg/tsdb/mysql/macros_test.go +++ b/pkg/tsdb/mysql/macros_test.go @@ -84,6 +84,27 @@ func TestMacroEngine(t *testing.T) { So(sql, ShouldEqual, fmt.Sprintf("select time >= %d AND time <= %d", from.Unix(), to.Unix())) }) + Convey("interpolate __unixEpochNanoFilter function", func() { + sql, err := engine.Interpolate(query, timeRange, "select $__unixEpochNanoFilter(time)") + So(err, ShouldBeNil) + + So(sql, ShouldEqual, fmt.Sprintf("select time >= %d AND time <= %d", from.UnixNano(), to.UnixNano())) + }) + + Convey("interpolate __unixEpochNanoFrom function", func() { + sql, err := engine.Interpolate(query, timeRange, "select $__unixEpochNanoFrom()") + So(err, ShouldBeNil) + + So(sql, ShouldEqual, fmt.Sprintf("select %d", from.UnixNano())) + }) + + Convey("interpolate __unixEpochNanoTo function", func() { + sql, err := engine.Interpolate(query, timeRange, "select $__unixEpochNanoTo()") + So(err, ShouldBeNil) + + So(sql, ShouldEqual, fmt.Sprintf("select %d", to.UnixNano())) + }) + Convey("interpolate __unixEpochGroup function", func() { sql, err := engine.Interpolate(query, timeRange, "SELECT $__unixEpochGroup(time_column,'5m')") From 49133b00128e6a96ade5236c96f598a761ef267a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ander=20Argui=C3=B1ano?= Date: Fri, 4 Jan 2019 14:36:07 +0100 Subject: [PATCH 7/8] Updated documentation for new macros --- docs/sources/features/datasources/mssql.md | 3 +++ docs/sources/features/datasources/mysql.md | 3 +++ docs/sources/features/datasources/postgres.md | 3 +++ 3 files changed, 9 insertions(+) diff --git a/docs/sources/features/datasources/mssql.md b/docs/sources/features/datasources/mssql.md index cd191f14273..5bab14c05fa 100644 --- a/docs/sources/features/datasources/mssql.md +++ b/docs/sources/features/datasources/mssql.md @@ -110,6 +110,9 @@ Macro example | Description *$__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* *$__unixEpochTo()* | Will be replaced by the end of the currently active time selection as unix timestamp. For example, *1494497183* +*$__unixEpochNanoFilter(dateColumn)* | Will be replaced by a time range filter using the specified column name with times represented as nanosecond timestamp. For example, *dateColumn > 1494410783152415214 AND dateColumn < 1494497183142514872* +*$__unixEpochNanoFrom()* | Will be replaced by the start of the currently active time selection as nanosecond timestamp. For example, *1494410783152415214* +*$__unixEpochNanoTo()* | Will be replaced by the end of the currently active time selection as nanosecond timestamp. For example, *1494497183142514872* *$__unixEpochGroup(dateColumn,'5m', [fillmode])* | Same as $__timeGroup but for times stored as unix timestamp (only available in Grafana 5.3+). *$__unixEpochGroupAlias(dateColumn,'5m', [fillmode])* | Same as above but also adds a column alias (only available in Grafana 5.3+). diff --git a/docs/sources/features/datasources/mysql.md b/docs/sources/features/datasources/mysql.md index 371c92cde70..bafe79bd09a 100644 --- a/docs/sources/features/datasources/mysql.md +++ b/docs/sources/features/datasources/mysql.md @@ -144,6 +144,9 @@ Macro example | Description *$__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* *$__unixEpochTo()* | Will be replaced by the end of the currently active time selection as unix timestamp. For example, *1494497183* +*$__unixEpochNanoFilter(dateColumn)* | Will be replaced by a time range filter using the specified column name with times represented as nanosecond timestamp. For example, *dateColumn > 1494410783152415214 AND dateColumn < 1494497183142514872* +*$__unixEpochNanoFrom()* | Will be replaced by the start of the currently active time selection as nanosecond timestamp. For example, *1494410783152415214* +*$__unixEpochNanoTo()* | Will be replaced by the end of the currently active time selection as nanosecond timestamp. For example, *1494497183142514872* *$__unixEpochGroup(dateColumn,'5m', [fillmode])* | Same as $__timeGroup but for times stored as unix timestamp (only available in Grafana 5.3+). *$__unixEpochGroupAlias(dateColumn,'5m', [fillmode])* | Same as above but also adds a column alias (only available in Grafana 5.3+). diff --git a/docs/sources/features/datasources/postgres.md b/docs/sources/features/datasources/postgres.md index 52f8804f27f..df6bf555077 100644 --- a/docs/sources/features/datasources/postgres.md +++ b/docs/sources/features/datasources/postgres.md @@ -154,6 +154,9 @@ Macro example | Description *$__unixEpochFilter(dateColumn)* | Will be replaced by a time range filter using the specified column name with times represented as unix timestamps. 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* *$__unixEpochTo()* | Will be replaced by the end of the currently active time selection as unix timestamp. For example, *1494497183* +*$__unixEpochNanoFilter(dateColumn)* | Will be replaced by a time range filter using the specified column name with times represented as nanosecond timestamps. For example, *dateColumn >= 1494410783152415214 AND dateColumn <= 1494497183142514872* +*$__unixEpochNanoFrom()* | Will be replaced by the start of the currently active time selection as nanosecond timestamp. For example, *1494410783152415214* +*$__unixEpochNanoTo()* | Will be replaced by the end of the currently active time selection as unix timestamp. For example, *1494497183142514872* *$__unixEpochGroup(dateColumn,'5m', [fillmode])* | Same as $__timeGroup, but for times stored as unix timestamp (only available in Grafana 5.3+). *$__unixEpochGroupAlias(dateColumn,'5m', [fillmode])* | Same as above, but also adds a column alias (only available in Grafana 5.3+). From 3a53f75ebbcebaa4dacbdc865e6414ed064ba2e6 Mon Sep 17 00:00:00 2001 From: Marcus Efraimsson Date: Mon, 28 Jan 2019 19:52:35 +0100 Subject: [PATCH 8/8] update inline documentation --- .../datasource/mssql/partials/annotations.editor.html | 3 +++ .../plugins/datasource/mssql/partials/query.editor.html | 3 +++ .../datasource/mysql/partials/annotations.editor.html | 3 +++ .../plugins/datasource/mysql/partials/query.editor.html | 3 +++ .../datasource/postgres/partials/annotations.editor.html | 3 +++ .../datasource/postgres/partials/query.editor.html | 9 ++++++--- 6 files changed, 21 insertions(+), 3 deletions(-) diff --git a/public/app/plugins/datasource/mssql/partials/annotations.editor.html b/public/app/plugins/datasource/mssql/partials/annotations.editor.html index 0ad8b0c01f0..f1c549cefa4 100644 --- a/public/app/plugins/datasource/mssql/partials/annotations.editor.html +++ b/public/app/plugins/datasource/mssql/partials/annotations.editor.html @@ -30,12 +30,15 @@ Macros: - $__timeEpoch(column) -> DATEDIFF(second, '1970-01-01', column) AS time - $__timeFilter(column) -> column BETWEEN '2017-04-21T05:01:17Z' AND '2017-04-21T05:01:17Z' - $__unixEpochFilter(column) -> column >= 1492750877 AND column <= 1492750877 +- $__unixEpochNanoFilter(column) -> column >= 1494410783152415214 AND column <= 1494497183142514872 Or build your own conditionals using these macros which just return the values: - $__timeFrom() -> '2017-04-21T05:01:17Z' - $__timeTo() -> '2017-04-21T05:01:17Z' - $__unixEpochFrom() -> 1492750877 - $__unixEpochTo() -> 1492750877 +- $__unixEpochNanoFrom() -> 1494410783152415214 +- $__unixEpochNanoTo() -> 1494497183142514872 diff --git a/public/app/plugins/datasource/mssql/partials/query.editor.html b/public/app/plugins/datasource/mssql/partials/query.editor.html index ba3bb6a4b82..f48af291216 100644 --- a/public/app/plugins/datasource/mssql/partials/query.editor.html +++ b/public/app/plugins/datasource/mssql/partials/query.editor.html @@ -55,6 +55,7 @@ Macros: - $__timeEpoch(column) -> DATEDIFF(second, '1970-01-01', column) AS time - $__timeFilter(column) -> column BETWEEN '2017-04-21T05:01:17Z' AND '2017-04-21T05:01:17Z' - $__unixEpochFilter(column) -> column >= 1492750877 AND column <= 1492750877 +- $__unixEpochNanoFilter(column) -> column >= 1494410783152415214 AND column <= 1494497183142514872 - $__timeGroup(column, '5m'[, fillvalue]) -> 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 @@ -75,6 +76,8 @@ Or build your own conditionals using these macros which just return the values: - $__timeTo() -> '2017-04-21T05:01:17Z' - $__unixEpochFrom() -> 1492750877 - $__unixEpochTo() -> 1492750877 +- $__unixEpochNanoFrom() -> 1494410783152415214 +- $__unixEpochNanoTo() -> 1494497183142514872 diff --git a/public/app/plugins/datasource/mysql/partials/annotations.editor.html b/public/app/plugins/datasource/mysql/partials/annotations.editor.html index 79f3c782898..25d2f969cee 100644 --- a/public/app/plugins/datasource/mysql/partials/annotations.editor.html +++ b/public/app/plugins/datasource/mysql/partials/annotations.editor.html @@ -30,12 +30,15 @@ Macros: - $__timeEpoch(column) -> UNIX_TIMESTAMP(column) as time (or as time_sec) - $__timeFilter(column) -> column BETWEEN FROM_UNIXTIME(1492750877) AND FROM_UNIXTIME(1492750877) - $__unixEpochFilter(column) -> time_unix_epoch > 1492750877 AND time_unix_epoch < 1492750877 +- $__unixEpochNanoFilter(column) -> column >= 1494410783152415214 AND column <= 1494497183142514872 Or build your own conditionals using these macros which just return the values: - $__timeFrom() -> FROM_UNIXTIME(1492750877) - $__timeTo() -> FROM_UNIXTIME(1492750877) - $__unixEpochFrom() -> 1492750877 - $__unixEpochTo() -> 1492750877 +- $__unixEpochNanoFrom() -> 1494410783152415214 +- $__unixEpochNanoTo() -> 1494497183142514872 diff --git a/public/app/plugins/datasource/mysql/partials/query.editor.html b/public/app/plugins/datasource/mysql/partials/query.editor.html index 90680ed104f..0cb47061a9e 100644 --- a/public/app/plugins/datasource/mysql/partials/query.editor.html +++ b/public/app/plugins/datasource/mysql/partials/query.editor.html @@ -153,6 +153,7 @@ Macros: - $__timeEpoch(column) -> UNIX_TIMESTAMP(column) as time_sec - $__timeFilter(column) -> column BETWEEN FROM_UNIXTIME(1492750877) AND FROM_UNIXTIME(1492750877) - $__unixEpochFilter(column) -> time_unix_epoch > 1492750877 AND time_unix_epoch < 1492750877 +- $__unixEpochNanoFilter(column) -> column >= 1494410783152415214 AND column <= 1494497183142514872 - $__timeGroup(column,'5m'[, fillvalue]) -> 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 @@ -173,6 +174,8 @@ Or build your own conditionals using these macros which just return the values: - $__timeTo() -> FROM_UNIXTIME(1492750877) - $__unixEpochFrom() -> 1492750877 - $__unixEpochTo() -> 1492750877 +- $__unixEpochNanoFrom() -> 1494410783152415214 +- $__unixEpochNanoTo() -> 1494497183142514872 diff --git a/public/app/plugins/datasource/postgres/partials/annotations.editor.html b/public/app/plugins/datasource/postgres/partials/annotations.editor.html index b83f5a14832..0b7180c0eaf 100644 --- a/public/app/plugins/datasource/postgres/partials/annotations.editor.html +++ b/public/app/plugins/datasource/postgres/partials/annotations.editor.html @@ -30,12 +30,15 @@ Macros: - $__timeEpoch -> extract(epoch from column) as "time" - $__timeFilter(column) -> column BETWEEN '2017-04-21T05:01:17Z' AND '2017-04-21T05:01:17Z' - $__unixEpochFilter(column) -> column >= 1492750877 AND column <= 1492750877 +- $__unixEpochNanoFilter(column) -> column >= 1494410783152415214 AND column <= 1494497183142514872 Or build your own conditionals using these macros which just return the values: - $__timeFrom() -> '2017-04-21T05:01:17Z' - $__timeTo() -> '2017-04-21T05:01:17Z' - $__unixEpochFrom() -> 1492750877 - $__unixEpochTo() -> 1492750877 +- $__unixEpochNanoFrom() -> 1494410783152415214 +- $__unixEpochNanoTo() -> 1494497183142514872 diff --git a/public/app/plugins/datasource/postgres/partials/query.editor.html b/public/app/plugins/datasource/postgres/partials/query.editor.html index 6c3bf02cb51..b5e2b5d87ed 100644 --- a/public/app/plugins/datasource/postgres/partials/query.editor.html +++ b/public/app/plugins/datasource/postgres/partials/query.editor.html @@ -138,9 +138,9 @@
Time series:
 - return column named time (UTC in seconds or timestamp)
 - return column(s) with numeric datatype as values
-Optional: 
-  - return column named metric to represent the series name. 
-  - If multiple value columns are returned the metric column is used as prefix. 
+Optional:
+  - return column named metric to represent the series name.
+  - If multiple value columns are returned the metric column is used as prefix.
   - If no column named metric is found the column name of the value column is used as series name
 
 Resultsets of time series queries need to be sorted by time.
@@ -153,6 +153,7 @@ Macros:
 - $__timeEpoch -> extract(epoch from column) as "time"
 - $__timeFilter(column) -> column BETWEEN '2017-04-21T05:01:17Z' AND '2017-04-21T05:01:17Z'
 - $__unixEpochFilter(column) ->  column >= 1492750877 AND column <= 1492750877
+- $__unixEpochNanoFilter(column) ->  column >= 1494410783152415214 AND column <= 1494497183142514872
 - $__timeGroup(column,'5m'[, fillvalue]) -> (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
@@ -173,6 +174,8 @@ Or build your own conditionals using these macros which just return the values:
 - $__timeTo() ->  '2017-04-21T05:01:17Z'
 - $__unixEpochFrom() ->  1492750877
 - $__unixEpochTo() ->  1492750877
+- $__unixEpochNanoFrom() ->  1494410783152415214
+- $__unixEpochNanoTo() ->  1494497183142514872