From d81a23becf9b306ff7dbf473a3089e8468868135 Mon Sep 17 00:00:00 2001 From: Sven Klemm Date: Sun, 12 Aug 2018 10:51:58 +0200 Subject: [PATCH 1/7] Refactor setting fillmode This adds SetupFillmode to the tsdb package to be used by the sql datasources. --- pkg/tsdb/mssql/macros.go | 19 +++---------------- pkg/tsdb/mysql/macros.go | 18 +++--------------- pkg/tsdb/postgres/macros.go | 18 +++--------------- pkg/tsdb/sql_engine.go | 21 +++++++++++++++++++++ 4 files changed, 30 insertions(+), 46 deletions(-) diff --git a/pkg/tsdb/mssql/macros.go b/pkg/tsdb/mssql/macros.go index 42e47ce6d3c..920e3781e0c 100644 --- a/pkg/tsdb/mssql/macros.go +++ b/pkg/tsdb/mssql/macros.go @@ -6,8 +6,6 @@ import ( "strings" "time" - "strconv" - "github.com/grafana/grafana/pkg/tsdb" ) @@ -97,20 +95,9 @@ func (m *msSqlMacroEngine) evaluateMacro(name string, args []string) (string, er return "", fmt.Errorf("error parsing interval %v", args[1]) } if len(args) == 3 { - m.query.Model.Set("fill", true) - m.query.Model.Set("fillInterval", interval.Seconds()) - 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]) - } - m.query.Model.Set("fillValue", floatVal) + err := tsdb.SetupFillmode(m.query, interval, args[2]) + if err != nil { + return "", err } } return fmt.Sprintf("FLOOR(DATEDIFF(second, '1970-01-01', %s)/%.0f)*%.0f", args[0], interval.Seconds(), interval.Seconds()), nil diff --git a/pkg/tsdb/mysql/macros.go b/pkg/tsdb/mysql/macros.go index 905d424f29a..48fa193edd5 100644 --- a/pkg/tsdb/mysql/macros.go +++ b/pkg/tsdb/mysql/macros.go @@ -3,7 +3,6 @@ package mysql import ( "fmt" "regexp" - "strconv" "strings" "time" @@ -92,20 +91,9 @@ func (m *mySqlMacroEngine) evaluateMacro(name string, args []string) (string, er return "", fmt.Errorf("error parsing interval %v", args[1]) } if len(args) == 3 { - m.query.Model.Set("fill", true) - m.query.Model.Set("fillInterval", interval.Seconds()) - 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]) - } - m.query.Model.Set("fillValue", floatVal) + err := tsdb.SetupFillmode(m.query, interval, args[2]) + if err != nil { + return "", err } } return fmt.Sprintf("UNIX_TIMESTAMP(%s) DIV %.0f * %.0f", args[0], interval.Seconds(), interval.Seconds()), nil diff --git a/pkg/tsdb/postgres/macros.go b/pkg/tsdb/postgres/macros.go index aebdc55d1d7..a4b4aaa9d1e 100644 --- a/pkg/tsdb/postgres/macros.go +++ b/pkg/tsdb/postgres/macros.go @@ -3,7 +3,6 @@ package postgres import ( "fmt" "regexp" - "strconv" "strings" "time" @@ -114,20 +113,9 @@ func (m *postgresMacroEngine) evaluateMacro(name string, args []string) (string, return "", fmt.Errorf("error parsing interval %v", args[1]) } if len(args) == 3 { - m.query.Model.Set("fill", true) - m.query.Model.Set("fillInterval", interval.Seconds()) - 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]) - } - m.query.Model.Set("fillValue", floatVal) + err := tsdb.SetupFillmode(m.query, interval, args[2]) + if err != nil { + return "", err } } return fmt.Sprintf("floor(extract(epoch from %s)/%v)*%v", args[0], interval.Seconds(), interval.Seconds()), nil diff --git a/pkg/tsdb/sql_engine.go b/pkg/tsdb/sql_engine.go index cbf6d6b4d60..454853c7cc8 100644 --- a/pkg/tsdb/sql_engine.go +++ b/pkg/tsdb/sql_engine.go @@ -6,6 +6,7 @@ import ( "database/sql" "fmt" "math" + "strconv" "strings" "sync" "time" @@ -568,3 +569,23 @@ func ConvertSqlValueColumnToFloat(columnName string, columnValue interface{}) (n return value, nil } + +func SetupFillmode(query *Query, interval time.Duration, fillmode string) error { + query.Model.Set("fill", true) + query.Model.Set("fillInterval", interval.Seconds()) + switch fillmode { + case "NULL": + query.Model.Set("fillMode", "null") + case "previous": + query.Model.Set("fillMode", "previous") + default: + query.Model.Set("fillMode", "value") + floatVal, err := strconv.ParseFloat(fillmode, 64) + if err != nil { + return fmt.Errorf("error parsing fill value %v", fillmode) + } + query.Model.Set("fillValue", floatVal) + } + + return nil +} From 48364f0111cfdaacfd4a05eaf4da98ba94a00251 Mon Sep 17 00:00:00 2001 From: Julien Pivotto Date: Mon, 13 Aug 2018 07:53:41 +0200 Subject: [PATCH 2/7] Add support for $__range_s (#12883) Fixes #12882 Signed-off-by: Julien Pivotto --- docs/sources/features/datasources/prometheus.md | 8 ++++---- docs/sources/reference/templating.md | 2 +- public/app/plugins/datasource/prometheus/datasource.ts | 2 ++ .../datasource/prometheus/specs/datasource.jest.ts | 2 ++ 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/docs/sources/features/datasources/prometheus.md b/docs/sources/features/datasources/prometheus.md index 3a04ef92e31..611a3b4d9e2 100644 --- a/docs/sources/features/datasources/prometheus.md +++ b/docs/sources/features/datasources/prometheus.md @@ -78,9 +78,9 @@ For details of *metric names*, *label names* and *label values* are please refer #### Using interval and range variables -> Support for `$__range` and `$__range_ms` only available from Grafana v5.3 +> Support for `$__range`, `$__range_s` and `$__range_ms` only available from Grafana v5.3 -It's possible to use some global built-in variables in query variables; `$__interval`, `$__interval_ms`, `$__range` and `$__range_ms`, see [Global built-in variables](/reference/templating/#global-built-in-variables) for more information. These can be convenient to use in conjunction with the `query_result` function when you need to filter variable queries since +It's possible to use some global built-in variables in query variables; `$__interval`, `$__interval_ms`, `$__range`, `$__range_s` and `$__range_ms`, see [Global built-in variables](/reference/templating/#global-built-in-variables) for more information. These can be convenient to use in conjunction with the `query_result` function when you need to filter variable queries since `label_values` function doesn't support queries. Make sure to set the variable's `refresh` trigger to be `On Time Range Change` to get the correct instances when changing the time range on the dashboard. @@ -94,10 +94,10 @@ Query: query_result(topk(5, sum(rate(http_requests_total[$__range])) by (instanc Regex: /"([^"]+)"/ ``` -Populate a variable with the instances having a certain state over the time range shown in the dashboard: +Populate a variable with the instances having a certain state over the time range shown in the dashboard, using the more precise `$__range_s`: ``` -Query: query_result(max_over_time([$__range]) != ) +Query: query_result(max_over_time([${__range_s}s]) != ) Regex: ``` diff --git a/docs/sources/reference/templating.md b/docs/sources/reference/templating.md index ce1a1299d26..d04d56dc788 100644 --- a/docs/sources/reference/templating.md +++ b/docs/sources/reference/templating.md @@ -277,7 +277,7 @@ This variable is only available in the Singlestat panel and can be used in the p > Only available in Grafana v5.3+ -Currently only supported for Prometheus data sources. This variable represents the range for the current dashboard. It is calculated by `to - from`. It has a millisecond representation called `$__range_ms`. +Currently only supported for Prometheus data sources. This variable represents the range for the current dashboard. It is calculated by `to - from`. It has a millisecond and a second representation called `$__range_ms` and `$__range_s`. ## Repeating Panels diff --git a/public/app/plugins/datasource/prometheus/datasource.ts b/public/app/plugins/datasource/prometheus/datasource.ts index ef440ab515d..318b0f8f1fc 100644 --- a/public/app/plugins/datasource/prometheus/datasource.ts +++ b/public/app/plugins/datasource/prometheus/datasource.ts @@ -489,9 +489,11 @@ export class PrometheusDatasource { getRangeScopedVars() { let range = this.timeSrv.timeRange(); let msRange = range.to.diff(range.from); + let sRange = Math.round(msRange / 1000); let regularRange = kbn.secondsToHms(msRange / 1000); return { __range_ms: { text: msRange, value: msRange }, + __range_s: { text: sRange, value: sRange }, __range: { text: regularRange, value: regularRange }, }; } diff --git a/public/app/plugins/datasource/prometheus/specs/datasource.jest.ts b/public/app/plugins/datasource/prometheus/specs/datasource.jest.ts index a108909e6e1..4ba2e3260a7 100644 --- a/public/app/plugins/datasource/prometheus/specs/datasource.jest.ts +++ b/public/app/plugins/datasource/prometheus/specs/datasource.jest.ts @@ -321,8 +321,10 @@ describe('PrometheusDatasource', () => { it('should have the correct range and range_ms', () => { let range = ctx.templateSrvMock.replace.mock.calls[0][1].__range; let rangeMs = ctx.templateSrvMock.replace.mock.calls[0][1].__range_ms; + let rangeS = ctx.templateSrvMock.replace.mock.calls[0][1].__range_s; expect(range).toEqual({ text: '21s', value: '21s' }); expect(rangeMs).toEqual({ text: 21031, value: 21031 }); + expect(rangeS).toEqual({ text: 21, value: 21 }); }); it('should pass the default interval value', () => { From 974359534fac6e91165b05705846ab225e4867d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Mon, 13 Aug 2018 07:54:49 +0200 Subject: [PATCH 3/7] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 198b28ca392..ef0d5b98696 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ * **Table**: Make table sorting stable when null values exist [#12362](https://github.com/grafana/grafana/pull/12362), thx [@bz2](https://github.com/bz2) * **Prometheus**: Fix graph panel bar width issue in aligned prometheus queries [#12379](https://github.com/grafana/grafana/issues/12379) * **Prometheus**: Heatmap - fix unhandled error when some points are missing [#12484](https://github.com/grafana/grafana/issues/12484) -* **Prometheus**: Add $interval, $interval_ms, $range, and $range_ms support for dashboard and template queries [#12597](https://github.com/grafana/grafana/issues/12597) +* **Prometheus**: Add $__interval, $__interval_ms, $__range, $__range_s & $__range_ms support for dashboard and template queries [#12597](https://github.com/grafana/grafana/issues/12597) * **Variables**: Skip unneeded extra query request when de-selecting variable values used for repeated panels [#8186](https://github.com/grafana/grafana/issues/8186), thx [@mtanda](https://github.com/mtanda) * **Postgres/MySQL/MSSQL**: Add previous fill mode to $__timeGroup macro which will fill in previously seen value when point is missing [#12756](https://github.com/grafana/grafana/issues/12756), thx [@svenklemm](https://github.com/svenklemm) * **Postgres/MySQL/MSSQL**: Use floor rounding in $__timeGroup macro function [#12460](https://github.com/grafana/grafana/issues/12460), thx [@svenklemm](https://github.com/svenklemm) From 48713b76f335bc307e6648985c26717287249bed Mon Sep 17 00:00:00 2001 From: Leonard Gram Date: Thu, 9 Aug 2018 16:29:16 +0200 Subject: [PATCH 4/7] docker: makes it possible to set a specific plugin url. Originally from the grafana/grafana-docker repo, authored by @ClementGautier. --- packaging/docker/run.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packaging/docker/run.sh b/packaging/docker/run.sh index 2d2318a9210..bc001bdf90a 100755 --- a/packaging/docker/run.sh +++ b/packaging/docker/run.sh @@ -67,7 +67,13 @@ if [ ! -z "${GF_INSTALL_PLUGINS}" ]; then IFS=',' for plugin in ${GF_INSTALL_PLUGINS}; do IFS=$OLDIFS - grafana-cli --pluginsDir "${GF_PATHS_PLUGINS}" plugins install ${plugin} + if [[ $plugin =~ .*\;.* ]]; then + pluginUrl=$(echo "$plugin" | cut -d';' -f 1) + pluginWithoutUrl=$(echo "$plugin" | cut -d';' -f 2) + grafana-cli --pluginUrl "${pluginUrl}" --pluginsDir "${GF_PATHS_PLUGINS}" plugins install ${pluginWithoutUrl} + else + grafana-cli --pluginsDir "${GF_PATHS_PLUGINS}" plugins install ${plugin} + fi done fi From aeba01237d3763c3a2560304bb19365d43167901 Mon Sep 17 00:00:00 2001 From: Leonard Gram Date: Mon, 13 Aug 2018 09:20:17 +0200 Subject: [PATCH 5/7] Changelog update --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef0d5b98696..6d1816b56b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ * **UI**: Fix iOS home screen "app" icon and Windows 10 app experience [#12752](https://github.com/grafana/grafana/issues/12752), thx [@andig](https://github.com/andig) * **Datasource**: Fix UI issue with secret fields after updating datasource [#11270](https://github.com/grafana/grafana/issues/11270) * **Plugins**: Convert URL-like text to links in plugins readme [#12843](https://github.com/grafana/grafana/pull/12843), thx [pgiraud](https://github.com/pgiraud) +* **Docker**: Make it possible to set a specific plugin url [#12861](https://github.com/grafana/grafana/pull/12861), thx [ClementGautier](https://github.com/ClementGautier) ### Breaking changes From d7a0f5ee074caaed6eb8884c537d4681230518cf Mon Sep 17 00:00:00 2001 From: Leonard Gram Date: Mon, 13 Aug 2018 11:14:24 +0200 Subject: [PATCH 6/7] Removes link to deprecated docker image build --- packaging/docker/README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packaging/docker/README.md b/packaging/docker/README.md index d80cd87aebc..cfb3c7248ef 100644 --- a/packaging/docker/README.md +++ b/packaging/docker/README.md @@ -1,7 +1,5 @@ # Grafana Docker image -[![CircleCI](https://circleci.com/gh/grafana/grafana-docker.svg?style=svg)](https://circleci.com/gh/grafana/grafana-docker) - ## Running your Grafana container Start your container binding the external port `3000`. @@ -42,4 +40,4 @@ Further documentation can be found at http://docs.grafana.org/installation/docke * Plugins dir (`/var/lib/grafana/plugins`) is no longer a separate volume ### v3.1.1 -* Make it possible to install specific plugin version https://github.com/grafana/grafana-docker/issues/59#issuecomment-260584026 \ No newline at end of file +* Make it possible to install specific plugin version https://github.com/grafana/grafana-docker/issues/59#issuecomment-260584026 From edb34a36a0cb84c0b6ec02bde71b68fddea0d6ca Mon Sep 17 00:00:00 2001 From: Marcus Efraimsson Date: Mon, 13 Aug 2018 11:16:49 +0200 Subject: [PATCH 7/7] changelog: add notes about closing #12882 [skip ci] --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d1816b56b2..7d5ed3378de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ * **Table**: Make table sorting stable when null values exist [#12362](https://github.com/grafana/grafana/pull/12362), thx [@bz2](https://github.com/bz2) * **Prometheus**: Fix graph panel bar width issue in aligned prometheus queries [#12379](https://github.com/grafana/grafana/issues/12379) * **Prometheus**: Heatmap - fix unhandled error when some points are missing [#12484](https://github.com/grafana/grafana/issues/12484) -* **Prometheus**: Add $__interval, $__interval_ms, $__range, $__range_s & $__range_ms support for dashboard and template queries [#12597](https://github.com/grafana/grafana/issues/12597) +* **Prometheus**: Add $__interval, $__interval_ms, $__range, $__range_s & $__range_ms support for dashboard and template queries [#12597](https://github.com/grafana/grafana/issues/12597) [#12882](https://github.com/grafana/grafana/issues/12882), thx [@roidelapluie](https://github.com/roidelapluie) * **Variables**: Skip unneeded extra query request when de-selecting variable values used for repeated panels [#8186](https://github.com/grafana/grafana/issues/8186), thx [@mtanda](https://github.com/mtanda) * **Postgres/MySQL/MSSQL**: Add previous fill mode to $__timeGroup macro which will fill in previously seen value when point is missing [#12756](https://github.com/grafana/grafana/issues/12756), thx [@svenklemm](https://github.com/svenklemm) * **Postgres/MySQL/MSSQL**: Use floor rounding in $__timeGroup macro function [#12460](https://github.com/grafana/grafana/issues/12460), thx [@svenklemm](https://github.com/svenklemm)