From 980b9b5ca05baa2eb414aeaa755652057f95ce3a Mon Sep 17 00:00:00 2001 From: Victor Azevedo Date: Thu, 25 May 2017 11:43:29 -0400 Subject: [PATCH 1/4] use fielddata_fields in elasticsearch 2.x queries Resolves issue #8467 --- .../app/plugins/datasource/elasticsearch/query_builder.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/public/app/plugins/datasource/elasticsearch/query_builder.js b/public/app/plugins/datasource/elasticsearch/query_builder.js index dd296c00a34..571eea14399 100644 --- a/public/app/plugins/datasource/elasticsearch/query_builder.js +++ b/public/app/plugins/datasource/elasticsearch/query_builder.js @@ -118,8 +118,12 @@ function (queryDef) { query.fields = ["*", "_source"]; } - query.script_fields = {}, - query.docvalue_fields = [this.timeField]; + query.script_fields = {}; + if (this.esVersion < 5) { + query.fielddata_fields = [this.timeField]; + } else { + query.docvalue_fields = [this.timeField]; + } return query; }; From 0d865a83bc7b21b36fdae6fdf305a9dea894883a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Mon, 29 May 2017 10:48:38 +0200 Subject: [PATCH 2/4] fix: fixed test data fake metric query, fixes #8474 --- pkg/api/api.go | 1 + pkg/api/metrics.go | 27 +++++++++++++++++++ .../plugins/datasource/grafana/datasource.ts | 26 +++++++++++++++--- .../grafana/partials/query.editor.html | 6 ++++- 4 files changed, 56 insertions(+), 4 deletions(-) diff --git a/pkg/api/api.go b/pkg/api/api.go index 6dcc900c16f..eb17c65ac73 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -253,6 +253,7 @@ func (hs *HttpServer) registerRoutes() { r.Post("/tsdb/query", bind(dtos.MetricRequest{}), wrap(QueryMetrics)) r.Get("/tsdb/testdata/scenarios", wrap(GetTestDataScenarios)) r.Get("/tsdb/testdata/gensql", reqGrafanaAdmin, wrap(GenerateSqlTestData)) + r.Get("/tsdb/testdata/random-walk", wrap(GetTestDataRandomWalk)) // metrics r.Get("/metrics", wrap(GetInternalMetrics)) diff --git a/pkg/api/metrics.go b/pkg/api/metrics.go index abd6527431a..e35e35cdab6 100644 --- a/pkg/api/metrics.go +++ b/pkg/api/metrics.go @@ -7,6 +7,7 @@ import ( "github.com/grafana/grafana/pkg/api/dtos" "github.com/grafana/grafana/pkg/bus" + "github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/metrics" "github.com/grafana/grafana/pkg/middleware" "github.com/grafana/grafana/pkg/models" @@ -144,3 +145,29 @@ func GenerateSqlTestData(c *middleware.Context) Response { return Json(200, &util.DynMap{"message": "OK"}) } + +// GET /api/tsdb/testdata/random-walk +func GetTestDataRandomWalk(c *middleware.Context) Response { + from := c.Query("from") + to := c.Query("to") + intervalMs := c.QueryInt64("intervalMs") + + timeRange := tsdb.NewTimeRange(from, to) + request := &tsdb.Request{TimeRange: timeRange} + + request.Queries = append(request.Queries, &tsdb.Query{ + RefId: "A", + IntervalMs: intervalMs, + Model: simplejson.NewFromAny(&util.DynMap{ + "scenario": "random_walk", + }), + DataSource: &models.DataSource{Type: "grafana-testdata-datasource"}, + }) + + resp, err := tsdb.HandleRequest(context.Background(), request) + if err != nil { + return ApiError(500, "Metric request error", err) + } + + return Json(200, &resp) +} diff --git a/public/app/plugins/datasource/grafana/datasource.ts b/public/app/plugins/datasource/grafana/datasource.ts index 8fb987e75e5..2960af6b062 100644 --- a/public/app/plugins/datasource/grafana/datasource.ts +++ b/public/app/plugins/datasource/grafana/datasource.ts @@ -8,11 +8,31 @@ class GrafanaDatasource { constructor(private backendSrv, private $q) {} query(options) { - return this.$q.when({data: []}); + return this.backendSrv.get('/api/tsdb/testdata/random-walk', { + from: options.range.from.valueOf(), + to: options.range.to.valueOf(), + intervalMs: options.intervalMs, + maxDataPoints: options.maxDataPoints, + }).then(res => { + var data = []; + + if (res.results) { + _.forEach(res.results, queryRes => { + for (let series of queryRes.series) { + data.push({ + target: series.name, + datapoints: series.points + }); + } + }); + } + + return {data: data}; + }); } - metricFindQuery() { - return this.$q.when([]); + metricFindQuery(options) { + return this.$q.when({data: []}); } annotationQuery(options) { diff --git a/public/app/plugins/datasource/grafana/partials/query.editor.html b/public/app/plugins/datasource/grafana/partials/query.editor.html index 880402573d5..91ec2bc8faa 100644 --- a/public/app/plugins/datasource/grafana/partials/query.editor.html +++ b/public/app/plugins/datasource/grafana/partials/query.editor.html @@ -1,7 +1,11 @@
- + +
+ +
+
From c95162e0679eb3729f815eeb145c2e6e0be6e38f Mon Sep 17 00:00:00 2001 From: Dan Cech Date: Mon, 29 May 2017 02:31:36 -0400 Subject: [PATCH 3/4] tweak column lengths for utf8mb4 support on older mysql (#8483) --- pkg/services/sqlstore/migrations/alert_mig.go | 4 ++-- pkg/services/sqlstore/migrations/dashboard_mig.go | 4 ++-- pkg/services/sqlstore/migrations/temp_user.go | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/services/sqlstore/migrations/alert_mig.go b/pkg/services/sqlstore/migrations/alert_mig.go index 7b6558656f1..2a364d5f464 100644 --- a/pkg/services/sqlstore/migrations/alert_mig.go +++ b/pkg/services/sqlstore/migrations/alert_mig.go @@ -16,7 +16,7 @@ func addAlertMigrations(mg *Migrator) { {Name: "org_id", Type: DB_BigInt, Nullable: false}, {Name: "name", Type: DB_NVarchar, Length: 255, Nullable: false}, {Name: "message", Type: DB_Text, Nullable: false}, - {Name: "state", Type: DB_NVarchar, Length: 255, Nullable: false}, + {Name: "state", Type: DB_NVarchar, Length: 190, Nullable: false}, {Name: "settings", Type: DB_Text, Nullable: false}, {Name: "frequency", Type: DB_BigInt, Nullable: false}, {Name: "handler", Type: DB_BigInt, Nullable: false}, @@ -70,7 +70,7 @@ func addAlertMigrations(mg *Migrator) { mg.AddMigration("Update alert table charset", NewTableCharsetMigration("alert", []*Column{ {Name: "name", Type: DB_NVarchar, Length: 255, Nullable: false}, {Name: "message", Type: DB_Text, Nullable: false}, - {Name: "state", Type: DB_NVarchar, Length: 255, Nullable: false}, + {Name: "state", Type: DB_NVarchar, Length: 190, Nullable: false}, {Name: "settings", Type: DB_Text, Nullable: false}, {Name: "severity", Type: DB_Text, Nullable: false}, {Name: "execution_error", Type: DB_Text, Nullable: false}, diff --git a/pkg/services/sqlstore/migrations/dashboard_mig.go b/pkg/services/sqlstore/migrations/dashboard_mig.go index 0ef2f3be54f..0519194ae31 100644 --- a/pkg/services/sqlstore/migrations/dashboard_mig.go +++ b/pkg/services/sqlstore/migrations/dashboard_mig.go @@ -56,7 +56,7 @@ func addDashboardMigration(mg *Migrator) { Columns: []*Column{ {Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true}, {Name: "version", Type: DB_Int, Nullable: false}, - {Name: "slug", Type: DB_NVarchar, Length: 190, Nullable: false}, + {Name: "slug", Type: DB_NVarchar, Length: 189, Nullable: false}, {Name: "title", Type: DB_NVarchar, Length: 255, Nullable: false}, {Name: "data", Type: DB_Text, Nullable: false}, {Name: "org_id", Type: DB_BigInt, Nullable: false}, @@ -127,7 +127,7 @@ func addDashboardMigration(mg *Migrator) { })) mg.AddMigration("Update dashboard table charset", NewTableCharsetMigration("dashboard", []*Column{ - {Name: "slug", Type: DB_NVarchar, Length: 190, Nullable: false}, + {Name: "slug", Type: DB_NVarchar, Length: 189, Nullable: false}, {Name: "title", Type: DB_NVarchar, Length: 255, Nullable: false}, {Name: "plugin_id", Type: DB_NVarchar, Nullable: true, Length: 255}, {Name: "data", Type: DB_MediumText, Nullable: false}, diff --git a/pkg/services/sqlstore/migrations/temp_user.go b/pkg/services/sqlstore/migrations/temp_user.go index 5592ab7e4ad..3913b18b3d8 100644 --- a/pkg/services/sqlstore/migrations/temp_user.go +++ b/pkg/services/sqlstore/migrations/temp_user.go @@ -9,10 +9,10 @@ func addTempUserMigrations(mg *Migrator) { {Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true}, {Name: "org_id", Type: DB_BigInt, Nullable: false}, {Name: "version", Type: DB_Int, Nullable: false}, - {Name: "email", Type: DB_NVarchar, Length: 255}, + {Name: "email", Type: DB_NVarchar, Length: 190}, {Name: "name", Type: DB_NVarchar, Length: 255, Nullable: true}, {Name: "role", Type: DB_NVarchar, Length: 20, Nullable: true}, - {Name: "code", Type: DB_NVarchar, Length: 255}, + {Name: "code", Type: DB_NVarchar, Length: 190}, {Name: "status", Type: DB_Varchar, Length: 20}, {Name: "invited_by_user_id", Type: DB_BigInt, Nullable: true}, {Name: "email_sent", Type: DB_Bool}, @@ -37,10 +37,10 @@ func addTempUserMigrations(mg *Migrator) { addTableIndicesMigrations(mg, "v1-7", tempUserV1) mg.AddMigration("Update temp_user table charset", NewTableCharsetMigration("temp_user", []*Column{ - {Name: "email", Type: DB_NVarchar, Length: 255}, + {Name: "email", Type: DB_NVarchar, Length: 190}, {Name: "name", Type: DB_NVarchar, Length: 255, Nullable: true}, {Name: "role", Type: DB_NVarchar, Length: 20, Nullable: true}, - {Name: "code", Type: DB_NVarchar, Length: 255}, + {Name: "code", Type: DB_NVarchar, Length: 190}, {Name: "status", Type: DB_Varchar, Length: 20}, {Name: "remote_addr", Type: DB_Varchar, Length: 255, Nullable: true}, })) From d318c9093fc2fcf610f38bf22550fb0f66849626 Mon Sep 17 00:00:00 2001 From: Daniel Lee Date: Mon, 29 May 2017 11:04:49 +0200 Subject: [PATCH 4/4] graph: Handle data with zeroes for log scale fixes #8446. Data with all values equal to zero, creates a max with the value of Infinite. The for loop for creating ticks then gets stuck in an infinite loop. This fix resets min and max and creates some fake ticks for the y-axis if the min and max are not finite numbers. --- public/app/plugins/panel/graph/graph.ts | 17 ++++++++++---- .../plugins/panel/graph/specs/graph_specs.ts | 23 +++++++++++++++++++ 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/public/app/plugins/panel/graph/graph.ts b/public/app/plugins/panel/graph/graph.ts index e0cec3febbf..726f8be5628 100755 --- a/public/app/plugins/panel/graph/graph.ts +++ b/public/app/plugins/panel/graph/graph.ts @@ -555,12 +555,19 @@ coreModule.directive('grafanaGraph', function($rootScope, timeSrv, popoverSrv) { return; } - axis.ticks = []; - var nextTick; - for (nextTick = min; nextTick <= max; nextTick *= axis.logBase) { - axis.ticks.push(nextTick); + if (Number.isFinite(min) && Number.isFinite(max)) { + axis.ticks = []; + var nextTick; + for (nextTick = min; nextTick <= max; nextTick *= axis.logBase) { + axis.ticks.push(nextTick); + } + axis.tickDecimals = decimalPlaces(min); + } else { + axis.ticks = [1, 2]; + delete axis.min; + delete axis.max; } - axis.tickDecimals = decimalPlaces(min); + } function decimalPlaces(num) { diff --git a/public/app/plugins/panel/graph/specs/graph_specs.ts b/public/app/plugins/panel/graph/specs/graph_specs.ts index 161aca11e42..9595c3dd544 100644 --- a/public/app/plugins/panel/graph/specs/graph_specs.ts +++ b/public/app/plugins/panel/graph/specs/graph_specs.ts @@ -153,6 +153,29 @@ describe('grafanaGraph', function() { }); }); + graphScenario('when logBase is log 10 and data points contain only zeroes', function(ctx) { + ctx.setup(function(ctrl, data) { + ctrl.panel.yaxes[0].logBase = 10; + data[0] = new TimeSeries({ + datapoints: [[0,1],[0,2],[0,3],[0,4]], + alias: 'seriesAutoscale', + }); + data[0].yaxis = 1; + }); + + it('should not set min and max and should create some fake ticks', function() { + var axisAutoscale = ctx.plotOptions.yaxes[0]; + expect(axisAutoscale.transform(100)).to.be(2); + expect(axisAutoscale.inverseTransform(-3)).to.be(0.001); + expect(axisAutoscale.min).to.be(undefined); + expect(axisAutoscale.max).to.be(undefined); + expect(axisAutoscale.ticks.length).to.be(2); + expect(axisAutoscale.ticks[0]).to.be(1); + expect(axisAutoscale.ticks[1]).to.be(2); + expect(axisAutoscale.tickDecimals).to.be(undefined); + }); + }); + graphScenario('dashed lines options', function(ctx) { ctx.setup(function(ctrl) { ctrl.panel.lines = true;