From f065af320d13eba7862be85575f96a0236d8dda2 Mon Sep 17 00:00:00 2001 From: Marcus Efraimsson Date: Thu, 8 Nov 2018 00:46:13 +0100 Subject: [PATCH 1/8] fix switching from es raw document metric breaks query editor --- .../plugins/datasource/elasticsearch/metric_agg.ts | 6 ++++++ .../datasource/elasticsearch/query_builder.ts | 4 ++-- .../plugins/datasource/elasticsearch/query_ctrl.ts | 13 +++++++++++++ .../plugins/datasource/elasticsearch/query_def.ts | 8 ++++++++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/public/app/plugins/datasource/elasticsearch/metric_agg.ts b/public/app/plugins/datasource/elasticsearch/metric_agg.ts index 1dd0d892360..56f874d90b9 100644 --- a/public/app/plugins/datasource/elasticsearch/metric_agg.ts +++ b/public/app/plugins/datasource/elasticsearch/metric_agg.ts @@ -160,6 +160,12 @@ export class ElasticMetricAggCtrl { $scope.agg.settings = {}; $scope.agg.meta = {}; $scope.showOptions = false; + + // reset back to metric/group by query + if ($scope.target.bucketAggs.length === 0 && $scope.agg.type !== 'raw_document') { + $scope.target.bucketAggs = [queryDef.defaultBucketAgg()]; + } + $scope.updatePipelineAggOptions(); $scope.onChange(); }; diff --git a/public/app/plugins/datasource/elasticsearch/query_builder.ts b/public/app/plugins/datasource/elasticsearch/query_builder.ts index 21af0ba9b80..efdeee68370 100644 --- a/public/app/plugins/datasource/elasticsearch/query_builder.ts +++ b/public/app/plugins/datasource/elasticsearch/query_builder.ts @@ -181,8 +181,8 @@ export class ElasticQueryBuilder { build(target, adhocFilters?, queryString?) { // make sure query has defaults; - target.metrics = target.metrics || [{ type: 'count', id: '1' }]; - target.bucketAggs = target.bucketAggs || [{ type: 'date_histogram', id: '2', settings: { interval: 'auto' } }]; + target.metrics = target.metrics || [queryDef.defaultMetricAgg()]; + target.bucketAggs = target.bucketAggs || [queryDef.defaultBucketAgg()]; target.timeField = this.timeField; let i, nestedAggs, metric; diff --git a/public/app/plugins/datasource/elasticsearch/query_ctrl.ts b/public/app/plugins/datasource/elasticsearch/query_ctrl.ts index 422d35dd277..81dbd5b8f8a 100644 --- a/public/app/plugins/datasource/elasticsearch/query_ctrl.ts +++ b/public/app/plugins/datasource/elasticsearch/query_ctrl.ts @@ -17,6 +17,19 @@ export class ElasticQueryCtrl extends QueryCtrl { super($scope, $injector); this.esVersion = this.datasource.esVersion; + + this.target = this.target || {}; + this.target.metrics = this.target.metrics || [queryDef.defaultMetricAgg()]; + this.target.bucketAggs = this.target.bucketAggs || [queryDef.defaultBucketAgg()]; + + if (this.target.bucketAggs.length === 0) { + const metric = this.target.metrics[0]; + if (!metric || metric.type !== 'raw_document') { + this.target.bucketAggs = [queryDef.defaultBucketAgg()]; + } + this.refresh(); + } + this.queryUpdated(); } diff --git a/public/app/plugins/datasource/elasticsearch/query_def.ts b/public/app/plugins/datasource/elasticsearch/query_def.ts index dd65a8b373e..3ea5945f54d 100644 --- a/public/app/plugins/datasource/elasticsearch/query_def.ts +++ b/public/app/plugins/datasource/elasticsearch/query_def.ts @@ -228,3 +228,11 @@ export function describeOrderBy(orderBy, target) { return 'metric not found'; } } + +export function defaultMetricAgg() { + return { type: 'count', id: '1' }; +} + +export function defaultBucketAgg() { + return { type: 'date_histogram', id: '2', settings: { interval: 'auto' } }; +} From 9b48338d95af8052ddb7187ba406dd7afc0c4bd2 Mon Sep 17 00:00:00 2001 From: David Kaltschmidt Date: Mon, 12 Nov 2018 18:06:12 +0000 Subject: [PATCH 2/8] Explore: Dont set datasource in state if navigated away Datasource selection triggers a connection test, on success the DS is set in the Explore state. If the test takes long and user selects a different DS, and just after that the first test succeeds, then the first DS overwrites the state. * when test returns check if datasource is still the requested one --- public/app/features/explore/Explore.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/public/app/features/explore/Explore.tsx b/public/app/features/explore/Explore.tsx index 753f158fd9f..238c5c917b9 100644 --- a/public/app/features/explore/Explore.tsx +++ b/public/app/features/explore/Explore.tsx @@ -94,6 +94,10 @@ export class Explore extends React.PureComponent { * Not kept in component state to prevent edit-render roundtrips. */ queryExpressions: string[]; + /** + * Local ID cache to compare requested vs selected datasource + */ + requestedDatasourceId: string; constructor(props) { super(props); @@ -167,6 +171,9 @@ export class Explore extends React.PureComponent { const datasourceId = datasource.meta.id; let datasourceError = null; + // Keep ID to track selection + this.requestedDatasourceId = datasourceId; + try { const testResult = await datasource.testDatasource(); datasourceError = testResult.status === 'success' ? null : testResult.message; @@ -174,6 +181,11 @@ export class Explore extends React.PureComponent { datasourceError = (error && error.statusText) || 'Network error'; } + if (datasourceId !== this.requestedDatasourceId) { + // User already changed datasource again, discard results + return; + } + const historyKey = `grafana.explore.history.${datasourceId}`; const history = store.getObject(historyKey, []); From 7627de80f2d675fb5465628dce101160615d63d0 Mon Sep 17 00:00:00 2001 From: David Kaltschmidt Date: Tue, 13 Nov 2018 11:00:32 +0000 Subject: [PATCH 3/8] Explore: Fix table pagination styles - get rid of drop shadow - get rid of top border - add min height for better no-data placement - add margins --- public/sass/pages/_explore.scss | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/public/sass/pages/_explore.scss b/public/sass/pages/_explore.scss index 4b07b04e330..58b4ca17840 100644 --- a/public/sass/pages/_explore.scss +++ b/public/sass/pages/_explore.scss @@ -320,8 +320,11 @@ .ReactTable { border: none; +} + +.ReactTable .rt-table { // Allow some space for the no-data text - min-height: 120px; + min-height: 90px; } .ReactTable .rt-thead.-header { @@ -350,6 +353,11 @@ .ReactTable .rt-tbody .rt-td:last-child { border-right: none; } +.ReactTable .-pagination { + border-top: none; + box-shadow: none; + margin-top: $panel-margin; +} .ReactTable .-pagination .-btn { color: $blue; background: $list-item-bg; @@ -371,6 +379,10 @@ .ReactTable .rt-tr .rt-td:last-child { text-align: right; } +.ReactTable .rt-noData { + top: 60px; + z-index: inherit; +} // React-component cascade fix: show "loading" even though item can expand From aa340b90996adb46403887b73cf0cdbbeac8fc6d Mon Sep 17 00:00:00 2001 From: bergquist Date: Wed, 14 Nov 2018 11:30:19 +0100 Subject: [PATCH 4/8] changelog: adds note about closing #14043 --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index afde0874f87..f9b8e84200c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,10 @@ * Postgres/MySQL/MSSQL datasources now per default uses `max open connections` = `unlimited` (earlier 10), `max idle connections` = `2` (earlier 10) and `connection max lifetime` = `4` hours (earlier unlimited) +# 5.3.5 (unreleased) + +* **Security**: Upgrade macaron session package to fix security issue. [#14043](https://github.com/grafana/grafana/pull/14043) + # 5.3.4 (2018-11-13) * **Alerting**: Delete alerts when parent folder was deleted [#13322](https://github.com/grafana/grafana/issues/13322) From 20214b3d6aa6e7c0458229bf1e89be8a84cf5ea5 Mon Sep 17 00:00:00 2001 From: stop-cran Date: Wed, 14 Nov 2018 18:12:05 +0200 Subject: [PATCH 5/8] [elasticsearch] Do not set a placeholder to index name, if it's already specified. --- .../plugins/datasource/elasticsearch/config_ctrl.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/public/app/plugins/datasource/elasticsearch/config_ctrl.ts b/public/app/plugins/datasource/elasticsearch/config_ctrl.ts index 154ff9bcb91..fad3a6895ae 100644 --- a/public/app/plugins/datasource/elasticsearch/config_ctrl.ts +++ b/public/app/plugins/datasource/elasticsearch/config_ctrl.ts @@ -28,9 +28,13 @@ export class ElasticConfigCtrl { ]; indexPatternTypeChanged() { - const def = _.find(this.indexPatternTypes, { - value: this.current.jsonData.interval, - }); - this.current.database = def.example || 'es-index-name'; + if (!this.current.database || + this.current.database.length === 0 || + this.current.database.startsWith('[logstash-]')) { + const def = _.find(this.indexPatternTypes, { + value: this.current.jsonData.interval, + }); + this.current.database = def.example || 'es-index-name'; + } } } From 2ae3b972996377c3c30c5a48f802999297d6dde4 Mon Sep 17 00:00:00 2001 From: Marcus Efraimsson Date: Wed, 14 Nov 2018 18:12:46 +0100 Subject: [PATCH 6/8] changelog: add notes about closing #6367 [skip ci] --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f9b8e84200c..ae088da9740 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ * **Cloudwatch**: Show all available CloudWatch regions [#12308](https://github.com/grafana/grafana/issues/12308), thx [@mtanda](https://github.com/mtanda) * **Cloudwatch**: AWS/Connect metrics and dimensions [#13970](https://github.com/grafana/grafana/pull/13970), thx [@zcoffy](https://github.com/zcoffy) * **Postgres**: Add delta window function to postgres query builder [#13925](https://github.com/grafana/grafana/issues/13925), thx [svenklemm](https://github.com/svenklemm) +* **Elasticsearch**: Fix switching to/from es raw document metric query [#6367](https://github.com/grafana/grafana/issues/6367) * **Units**: New clock time format, to format ms or second values as for example `01h:59m`, [#13635](https://github.com/grafana/grafana/issues/13635), thx [@franciscocpg](https://github.com/franciscocpg) * **Datasource Proxy**: Keep trailing slash for datasource proxy requests [#13326](https://github.com/grafana/grafana/pull/13326), thx [@ryantxu](https://github.com/ryantxu) * **DingDing**: Can't receive DingDing alert when alert is triggered [#13723](https://github.com/grafana/grafana/issues/13723), thx [@Yukinoshita-Yukino](https://github.com/Yukinoshita-Yukino) From 75bc9b315de54cde9dc9c5a3141d9cf299ec1d25 Mon Sep 17 00:00:00 2001 From: Marcus Efraimsson Date: Wed, 14 Nov 2018 18:15:02 +0100 Subject: [PATCH 7/8] changelog: add notes about closing #11977 [skip ci] --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae088da9740..7390c4f1799 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ * **Cloudwatch**: AWS/Connect metrics and dimensions [#13970](https://github.com/grafana/grafana/pull/13970), thx [@zcoffy](https://github.com/zcoffy) * **Postgres**: Add delta window function to postgres query builder [#13925](https://github.com/grafana/grafana/issues/13925), thx [svenklemm](https://github.com/svenklemm) * **Elasticsearch**: Fix switching to/from es raw document metric query [#6367](https://github.com/grafana/grafana/issues/6367) +* **Elasticsearch**: Fix deprecation warning about terms aggregation order key in Elasticsearch 6.x [#11977](https://github.com/grafana/grafana/issues/11977) * **Units**: New clock time format, to format ms or second values as for example `01h:59m`, [#13635](https://github.com/grafana/grafana/issues/13635), thx [@franciscocpg](https://github.com/franciscocpg) * **Datasource Proxy**: Keep trailing slash for datasource proxy requests [#13326](https://github.com/grafana/grafana/pull/13326), thx [@ryantxu](https://github.com/ryantxu) * **DingDing**: Can't receive DingDing alert when alert is triggered [#13723](https://github.com/grafana/grafana/issues/13723), thx [@Yukinoshita-Yukino](https://github.com/Yukinoshita-Yukino) From 0cba6da2b05518fa3966b53c7ca1684caaddfaf7 Mon Sep 17 00:00:00 2001 From: Marcus Efraimsson Date: Wed, 14 Nov 2018 18:16:41 +0100 Subject: [PATCH 8/8] update changelog [skip ci] --- CHANGELOG.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7390c4f1799..a3c0ce494f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,13 +16,13 @@ * **Postgres**: Add delta window function to postgres query builder [#13925](https://github.com/grafana/grafana/issues/13925), thx [svenklemm](https://github.com/svenklemm) * **Elasticsearch**: Fix switching to/from es raw document metric query [#6367](https://github.com/grafana/grafana/issues/6367) * **Elasticsearch**: Fix deprecation warning about terms aggregation order key in Elasticsearch 6.x [#11977](https://github.com/grafana/grafana/issues/11977) -* **Units**: New clock time format, to format ms or second values as for example `01h:59m`, [#13635](https://github.com/grafana/grafana/issues/13635), thx [@franciscocpg](https://github.com/franciscocpg) -* **Datasource Proxy**: Keep trailing slash for datasource proxy requests [#13326](https://github.com/grafana/grafana/pull/13326), thx [@ryantxu](https://github.com/ryantxu) -* **DingDing**: Can't receive DingDing alert when alert is triggered [#13723](https://github.com/grafana/grafana/issues/13723), thx [@Yukinoshita-Yukino](https://github.com/Yukinoshita-Yukino) -* **Internal metrics**: Renamed `grafana_info` to `grafana_build_info` and added branch, goversion and revision [#13876](https://github.com/grafana/grafana/pull/13876) -* **Alerting**: Increaste default duration for queries [#13945](https://github.com/grafana/grafana/pull/13945) * **Table**: Fix CSS alpha background-color applied twice in table cell with link [#13606](https://github.com/grafana/grafana/issues/13606), thx [@grisme](https://github.com/grisme) +* **Units**: New clock time format, to format ms or second values as for example `01h:59m`, [#13635](https://github.com/grafana/grafana/issues/13635), thx [@franciscocpg](https://github.com/franciscocpg) +* **Alerting**: Increaste default duration for queries [#13945](https://github.com/grafana/grafana/pull/13945) * **Alerting**: More options for the Slack Alert notifier [#13993](https://github.com/grafana/grafana/issues/13993), thx [@andreykaipov](https://github.com/andreykaipov) +* **Alerting**: Can't receive DingDing alert when alert is triggered [#13723](https://github.com/grafana/grafana/issues/13723), thx [@Yukinoshita-Yukino](https://github.com/Yukinoshita-Yukino) +* **Internal metrics**: Renamed `grafana_info` to `grafana_build_info` and added branch, goversion and revision [#13876](https://github.com/grafana/grafana/pull/13876) +* **Datasource Proxy**: Keep trailing slash for datasource proxy requests [#13326](https://github.com/grafana/grafana/pull/13326), thx [@ryantxu](https://github.com/ryantxu) ### Breaking changes