From 220b65afd244e21eade8da55d5f3d1b2b1c1b68f Mon Sep 17 00:00:00 2001 From: Grzegorz Pietrusza Date: Sat, 4 Feb 2017 14:10:40 +0000 Subject: [PATCH 1/9] implement panels loading on scroll --- .../app/features/panel/metrics_panel_ctrl.ts | 15 ++++++++++ public/app/features/panel/panel_directive.ts | 28 +++++++++++++++---- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/public/app/features/panel/metrics_panel_ctrl.ts b/public/app/features/panel/metrics_panel_ctrl.ts index d37a3f5db41..de6e331e8a1 100644 --- a/public/app/features/panel/metrics_panel_ctrl.ts +++ b/public/app/features/panel/metrics_panel_ctrl.ts @@ -12,6 +12,8 @@ import * as dateMath from 'app/core/utils/datemath'; import {Subject} from 'vendor/npm/rxjs/Subject'; class MetricsPanelCtrl extends PanelCtrl { + scope: any; + needsRefresh: boolean; loading: boolean; datasource: any; datasourceName: any; @@ -40,6 +42,8 @@ class MetricsPanelCtrl extends PanelCtrl { this.datasourceSrv = $injector.get('datasourceSrv'); this.timeSrv = $injector.get('timeSrv'); this.templateSrv = $injector.get('templateSrv'); + this.scope = $scope; + this.needsRefresh = false; if (!this.panel.targets) { this.panel.targets = [{}]; @@ -50,6 +54,10 @@ class MetricsPanelCtrl extends PanelCtrl { this.events.on('panel-teardown', this.onPanelTearDown.bind(this)); } + private isRenderGraph () { + return window.location.href.indexOf("/dashboard-solo/") === 0; + } + private onPanelTearDown() { if (this.dataSubscription) { this.dataSubscription.unsubscribe(); @@ -66,6 +74,13 @@ class MetricsPanelCtrl extends PanelCtrl { // ignore fetching data if another panel is in fullscreen if (this.otherPanelInFullscreenMode()) { return; } + if (!this.scope.$$childHead || (!this.scope.$$childHead.isVisible() && !this.isRenderGraph())) { + this.scope.$$childHead.needsRefresh = true; + return; + } + + this.scope.$$childHead.needsRefresh = false; + // if we have snapshot data use that if (this.panel.snapshotData) { this.updateTimeRange(); diff --git a/public/app/features/panel/panel_directive.ts b/public/app/features/panel/panel_directive.ts index 24977bd386c..8c51c8795d5 100644 --- a/public/app/features/panel/panel_directive.ts +++ b/public/app/features/panel/panel_directive.ts @@ -1,9 +1,8 @@ /// -import angular from 'angular'; -import $ from 'jquery'; -import _ from 'lodash'; -import Drop from 'tether-drop'; +import angular from "angular"; +import $ from "jquery"; +import Drop from "tether-drop"; var module = angular.module('grafana.directives'); @@ -57,7 +56,7 @@ var panelTemplate = ` `; -module.directive('grafanaPanel', function($rootScope) { +module.directive('grafanaPanel', function($rootScope, $document, $timeout) { return { restrict: 'E', template: panelTemplate, @@ -183,6 +182,25 @@ module.directive('grafanaPanel', function($rootScope) { infoDrop.destroy(); } }); + + var getDataPromise = null; + scope.needsRefresh = false; + + scope.isVisible = function () { + var position = panelContainer[0].getBoundingClientRect(); + return (0 < position.top) && (position.top < window.innerHeight); + }; + + $document.bind('scroll', function () { + if (getDataPromise) { + $timeout.cancel(getDataPromise); + } + if (scope.needsRefresh) { + getDataPromise = $timeout(function () { + scope.ctrl.refresh(); + }, 250); + } + }); } }; }); From a3019a9789caa8c3433e8659cfe963be899638d4 Mon Sep 17 00:00:00 2001 From: Grzegorz Pietrusza Date: Sat, 4 Feb 2017 14:30:24 +0000 Subject: [PATCH 2/9] cleanup --- public/app/features/panel/panel_directive.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/public/app/features/panel/panel_directive.ts b/public/app/features/panel/panel_directive.ts index 8c51c8795d5..637facb50c1 100644 --- a/public/app/features/panel/panel_directive.ts +++ b/public/app/features/panel/panel_directive.ts @@ -1,8 +1,9 @@ /// -import angular from "angular"; -import $ from "jquery"; -import Drop from "tether-drop"; +import angular from 'angular'; +import $ from 'jquery'; +import _ from 'lodash'; +import Drop from 'tether-drop'; var module = angular.module('grafana.directives'); From c09cd4ba296fa899dbed18229d53155d3c002707 Mon Sep 17 00:00:00 2001 From: jifwin Date: Wed, 1 Mar 2017 15:02:59 +0000 Subject: [PATCH 3/9] make load on scroll configurable and use debouce --- public/app/features/dashboard/model.ts | 2 ++ .../app/features/dashboard/partials/settings.html | 6 ++++++ public/app/features/panel/metrics_panel_ctrl.ts | 11 ++++++----- public/app/features/panel/panel_directive.ts | 14 ++++---------- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/public/app/features/dashboard/model.ts b/public/app/features/dashboard/model.ts index e31a6c1afd0..959b5ff2116 100644 --- a/public/app/features/dashboard/model.ts +++ b/public/app/features/dashboard/model.ts @@ -36,6 +36,7 @@ export class DashboardModel { meta: any; events: any; editMode: boolean; + loadOnScroll: boolean; constructor(data, meta?) { if (!data) { @@ -64,6 +65,7 @@ export class DashboardModel { this.version = data.version || 0; this.links = data.links || []; this.gnetId = data.gnetId || null; + this.loadOnScroll = data.loadOnScroll || false; this.rows = []; if (data.rows) { diff --git a/public/app/features/dashboard/partials/settings.html b/public/app/features/dashboard/partials/settings.html index b8d8303a51b..7475fceb2d8 100644 --- a/public/app/features/dashboard/partials/settings.html +++ b/public/app/features/dashboard/partials/settings.html @@ -61,6 +61,12 @@ checked="dashboard.hideControls" label-class="width-11"> + + diff --git a/public/app/features/panel/metrics_panel_ctrl.ts b/public/app/features/panel/metrics_panel_ctrl.ts index de6e331e8a1..d9670291481 100644 --- a/public/app/features/panel/metrics_panel_ctrl.ts +++ b/public/app/features/panel/metrics_panel_ctrl.ts @@ -74,13 +74,14 @@ class MetricsPanelCtrl extends PanelCtrl { // ignore fetching data if another panel is in fullscreen if (this.otherPanelInFullscreenMode()) { return; } - if (!this.scope.$$childHead || (!this.scope.$$childHead.isVisible() && !this.isRenderGraph())) { - this.scope.$$childHead.needsRefresh = true; - return; + if (this.scope.ctrl.dashboard.loadOnScroll) { + if (!this.scope.$$childHead || (!this.scope.$$childHead.isVisible() && !this.isRenderGraph())) { + this.scope.$$childHead.needsRefresh = true; + return; + } + this.scope.$$childHead.needsRefresh = false; } - this.scope.$$childHead.needsRefresh = false; - // if we have snapshot data use that if (this.panel.snapshotData) { this.updateTimeRange(); diff --git a/public/app/features/panel/panel_directive.ts b/public/app/features/panel/panel_directive.ts index 637facb50c1..3aa195e706c 100644 --- a/public/app/features/panel/panel_directive.ts +++ b/public/app/features/panel/panel_directive.ts @@ -184,7 +184,6 @@ module.directive('grafanaPanel', function($rootScope, $document, $timeout) { } }); - var getDataPromise = null; scope.needsRefresh = false; scope.isVisible = function () { @@ -192,16 +191,11 @@ module.directive('grafanaPanel', function($rootScope, $document, $timeout) { return (0 < position.top) && (position.top < window.innerHeight); }; - $document.bind('scroll', function () { - if (getDataPromise) { - $timeout.cancel(getDataPromise); + $document.bind('scroll', _.debounce(function () { + if (scope.ctrl.dashboard.loadOnScroll && scope.needsRefresh) { + scope.ctrl.refresh(); } - if (scope.needsRefresh) { - getDataPromise = $timeout(function () { - scope.ctrl.refresh(); - }, 250); - } - }); + }, 250)); } }; }); From 9efb6e76e9f12dee278578cd12e349490373decc Mon Sep 17 00:00:00 2001 From: Daniel Lee Date: Tue, 7 Mar 2017 16:03:54 +0100 Subject: [PATCH 4/9] users: adds search and pagination (#7753) ref #7469. Follow up change that adds proper paging with 50 results per page as well as a search box to search by name, login or email. --- pkg/api/user.go | 4 +- pkg/services/sqlstore/user.go | 13 ++++- pkg/services/sqlstore/user_test.go | 50 ++++++++++++++++++- .../features/admin/admin_list_users_ctrl.ts | 6 ++- public/app/features/admin/partials/users.html | 6 +++ 5 files changed, 73 insertions(+), 6 deletions(-) diff --git a/pkg/api/user.go b/pkg/api/user.go index 8dd6daab4bc..39e7fce1462 100644 --- a/pkg/api/user.go +++ b/pkg/api/user.go @@ -239,7 +239,9 @@ func searchUser(c *middleware.Context) (*m.SearchUsersQuery, error) { page = 1 } - query := &m.SearchUsersQuery{Query: "", Page: page, Limit: perPage} + searchQuery := c.Query("query") + + query := &m.SearchUsersQuery{Query: searchQuery, Page: page, Limit: perPage} if err := bus.Dispatch(query); err != nil { return nil, err } diff --git a/pkg/services/sqlstore/user.go b/pkg/services/sqlstore/user.go index 2e3c5c673d6..9a44d6f194e 100644 --- a/pkg/services/sqlstore/user.go +++ b/pkg/services/sqlstore/user.go @@ -363,8 +363,12 @@ func SearchUsers(query *m.SearchUsersQuery) error { query.Result = m.SearchUserQueryResult{ Users: make([]*m.UserSearchHitDTO, 0), } + queryWithWildcards := "%" + query.Query + "%" + sess := x.Table("user") - sess.Where("email LIKE ?", query.Query+"%") + if query.Query != "" { + sess.Where("email LIKE ? OR name LIKE ? OR login like ?", queryWithWildcards, queryWithWildcards, queryWithWildcards) + } offset := query.Limit * (query.Page - 1) sess.Limit(query.Limit, offset) sess.Cols("id", "email", "name", "login", "is_admin") @@ -373,7 +377,12 @@ func SearchUsers(query *m.SearchUsersQuery) error { } user := m.User{} - count, err := x.Count(&user) + + countSess := x.Table("user") + if query.Query != "" { + countSess.Where("email LIKE ? OR name LIKE ? OR login like ?", queryWithWildcards, queryWithWildcards, queryWithWildcards) + } + count, err := countSess.Count(&user) query.Result.TotalCount = count return err } diff --git a/pkg/services/sqlstore/user_test.go b/pkg/services/sqlstore/user_test.go index 53a50f9631c..decb4682552 100644 --- a/pkg/services/sqlstore/user_test.go +++ b/pkg/services/sqlstore/user_test.go @@ -19,7 +19,7 @@ func TestUserDataAccess(t *testing.T) { err = CreateUser(&models.CreateUserCommand{ Email: fmt.Sprint("user", i, "@test.com"), Name: fmt.Sprint("user", i), - Login: fmt.Sprint("user", i), + Login: fmt.Sprint("loginuser", i), }) So(err, ShouldBeNil) } @@ -41,5 +41,53 @@ func TestUserDataAccess(t *testing.T) { So(len(query.Result.Users), ShouldEqual, 2) So(query.Result.TotalCount, ShouldEqual, 5) }) + + Convey("Can return list of users matching query on user name", func() { + query := models.SearchUsersQuery{Query: "use", Page: 1, Limit: 3} + err = SearchUsers(&query) + + So(err, ShouldBeNil) + So(len(query.Result.Users), ShouldEqual, 3) + So(query.Result.TotalCount, ShouldEqual, 5) + + query = models.SearchUsersQuery{Query: "ser1", Page: 1, Limit: 3} + err = SearchUsers(&query) + + So(err, ShouldBeNil) + So(len(query.Result.Users), ShouldEqual, 1) + So(query.Result.TotalCount, ShouldEqual, 1) + + query = models.SearchUsersQuery{Query: "USER1", Page: 1, Limit: 3} + err = SearchUsers(&query) + + So(err, ShouldBeNil) + So(len(query.Result.Users), ShouldEqual, 1) + So(query.Result.TotalCount, ShouldEqual, 1) + + query = models.SearchUsersQuery{Query: "idontexist", Page: 1, Limit: 3} + err = SearchUsers(&query) + + So(err, ShouldBeNil) + So(len(query.Result.Users), ShouldEqual, 0) + So(query.Result.TotalCount, ShouldEqual, 0) + }) + + Convey("Can return list of users matching query on email", func() { + query := models.SearchUsersQuery{Query: "ser1@test.com", Page: 1, Limit: 3} + err = SearchUsers(&query) + + So(err, ShouldBeNil) + So(len(query.Result.Users), ShouldEqual, 1) + So(query.Result.TotalCount, ShouldEqual, 1) + }) + + Convey("Can return list of users matching query on login name", func() { + query := models.SearchUsersQuery{Query: "loginuser1", Page: 1, Limit: 3} + err = SearchUsers(&query) + + So(err, ShouldBeNil) + So(len(query.Result.Users), ShouldEqual, 1) + So(query.Result.TotalCount, ShouldEqual, 1) + }) }) } diff --git a/public/app/features/admin/admin_list_users_ctrl.ts b/public/app/features/admin/admin_list_users_ctrl.ts index 1347457bc06..e2ed12cba60 100644 --- a/public/app/features/admin/admin_list_users_ctrl.ts +++ b/public/app/features/admin/admin_list_users_ctrl.ts @@ -3,18 +3,20 @@ export default class AdminListUsersCtrl { users: any; pages = []; - perPage = 1000; + perPage = 50; page = 1; totalPages: number; showPaging = false; + query: any; /** @ngInject */ constructor(private $scope, private backendSrv) { + this.query = ''; this.getUsers(); } getUsers() { - this.backendSrv.get(`/api/users/search?perpage=${this.perPage}&page=${this.page}`).then((result) => { + this.backendSrv.get(`/api/users/search?perpage=${this.perPage}&page=${this.page}&query=${this.query}`).then((result) => { this.users = result.users; this.page = result.page; this.perPage = result.perPage; diff --git a/public/app/features/admin/partials/users.html b/public/app/features/admin/partials/users.html index 57714380c67..18ffdb4eaeb 100644 --- a/public/app/features/admin/partials/users.html +++ b/public/app/features/admin/partials/users.html @@ -14,6 +14,12 @@ Add new user +
+ + + +
From dc6d55a59f3383735a59d23414601bf7d10e7851 Mon Sep 17 00:00:00 2001 From: Daniel Lee Date: Wed, 8 Mar 2017 11:16:14 +0100 Subject: [PATCH 5/9] docs: changelog for 4.2.0 Adds notes for: - ref #7694 - ref #7681 - ref #7736 - ref #7743 - ref #7696 - ref #3536 - ref #6365 - ref #7591 - ref #7276 - ref #7723 - ref #7739 - ref #7680 --- CHANGELOG.md | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b078bb892ce..f3a7af35573 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,15 +1,28 @@ # 4.3.0 (unreleased) ## Minor Enchancements -* **Threema**: Add emoji to Threema alert notifications [#7676](https://github.com/grafana/grafana/pull/7676) thx [@dbrgn](https://github.com/dbrgn) -* **Panels**: Support dm3 unit [#7695](https://github.com/grafana/grafana/issues/7695) thx [@mitjaziv](https://github.com/mitjaziv) +* **Admin**: Global User List: add search and pagination [#7469](https://github.com/grafana/grafana/issues/7469) # 4.2.0-beta2 (unreleased) ## Minor Enhancements * **Templates**: Prevent use of the prefix `__` for templates in web UI [#7678](https://github.com/grafana/grafana/issues/7678) +* **Threema**: Add emoji to Threema alert notifications [#7676](https://github.com/grafana/grafana/pull/7676) thx [@dbrgn](https://github.com/dbrgn) +* **Panels**: Support dm3 unit [#7695](https://github.com/grafana/grafana/issues/7695) thx [@mitjaziv](https://github.com/mitjaziv) +* **Docs**: Added some details about Sessions in Postgres [#7694](https://github.com/grafana/grafana/pull/7694) thx [@rickard-von-essen](https://github.com/rickard-von-essen) +* **Influxdb**: Allow commas in template variables [#7681](https://github.com/grafana/grafana/issues/7681) thx [@thuck](https://github.com/thuck) +* **Cloudwatch**: stop using deprecated session.New() [#7736](https://github.com/grafana/grafana/issues/7736) thx [@mtanda](https://github.com/mtanda) +* **OpenTSDB**: Pass dropcounter rate option if no max counter and no reset value or reset value as 0 is specified [#7743](https://github.com/grafana/grafana/pull/7743) thx [@r4um](https://github.com/r4um) +* **Templating**: support full resolution for $interval variable [#7696](https://github.com/grafana/grafana/pull/7696) thx [@mtanda](https://github.com/mtanda) +* **Elasticsearch**: Unique Count on string fields in ElasticSearch [#3536](https://github.com/grafana/grafana/issues/3536), thx [@pyro2927](https://github.com/pyro2927) +* **Templating**: Data source template variable that refers to other variable in regex filter [#6365](https://github.com/grafana/grafana/issues/6365) thx [@rlodge](https://github.com/rlodge) ## Bugfixes * **Webhook**: Use proxy settings from environment variables [#7710](https://github.com/grafana/grafana/issues/7710) +* **Panels**: Deleting a dashboard with unsaved changes raises an error message [#7591](https://github.com/grafana/grafana/issues/7591) thx [@thuck](https://github.com/thuck) +* **Influxdb**: Query builder detects regex to easily for measurement [#7276](https://github.com/grafana/grafana/issues/7276) thx [@thuck](https://github.com/thuck) +* **Docs**: router_logging not documented [#7723](https://github.com/grafana/grafana/issues/7723) +* **Alerting**: Spelling mistake [#7739](https://github.com/grafana/grafana/pull/7739) thx [@woutersmit](https://github.com/woutersmit) +* **Alerting**: Graph legend scrolls to top when an alias is toggled/clicked [#7680](https://github.com/grafana/grafana/issues/7680) thx [@p4ddy1](https://github.com/p4ddy1) # 4.2.0-beta1 (2017-02-27) From 5037dae9597ad65a20d0689564464e115f5b3e29 Mon Sep 17 00:00:00 2001 From: Daniel Lee Date: Wed, 8 Mar 2017 17:09:08 +0100 Subject: [PATCH 6/9] docs: move #7469 to v4.2.0 --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f3a7af35573..ec6f6390cc4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,6 @@ # 4.3.0 (unreleased) ## Minor Enchancements -* **Admin**: Global User List: add search and pagination [#7469](https://github.com/grafana/grafana/issues/7469) # 4.2.0-beta2 (unreleased) ## Minor Enhancements @@ -14,7 +13,8 @@ * **OpenTSDB**: Pass dropcounter rate option if no max counter and no reset value or reset value as 0 is specified [#7743](https://github.com/grafana/grafana/pull/7743) thx [@r4um](https://github.com/r4um) * **Templating**: support full resolution for $interval variable [#7696](https://github.com/grafana/grafana/pull/7696) thx [@mtanda](https://github.com/mtanda) * **Elasticsearch**: Unique Count on string fields in ElasticSearch [#3536](https://github.com/grafana/grafana/issues/3536), thx [@pyro2927](https://github.com/pyro2927) -* **Templating**: Data source template variable that refers to other variable in regex filter [#6365](https://github.com/grafana/grafana/issues/6365) thx [@rlodge](https://github.com/rlodge) +* **Templating**: Data source template variable that refers to other variable in regex filter [#6365](https://github.com/grafana/grafana/issues/6365) thx [@rlodge](https://github.com/rlodge) +* **Admin**: Global User List: add search and pagination [#7469](https://github.com/grafana/grafana/issues/7469) ## Bugfixes * **Webhook**: Use proxy settings from environment variables [#7710](https://github.com/grafana/grafana/issues/7710) From 4f06202e9a15a66eda9721c929f23d8f799eabb2 Mon Sep 17 00:00:00 2001 From: Daniel Lee Date: Wed, 8 Mar 2017 17:10:51 +0100 Subject: [PATCH 7/9] build: bumped version to 4.3.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index dc3970bfe69..d38de899bf5 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "company": "Coding Instinct AB" }, "name": "grafana", - "version": "4.2.0-pre1", + "version": "4.3.0-pre1", "repository": { "type": "git", "url": "http://github.com/grafana/grafana.git" From bd348a47c74a190b1873228e386e4ed251c8f720 Mon Sep 17 00:00:00 2001 From: Daniel Lee Date: Wed, 8 Mar 2017 17:52:33 +0100 Subject: [PATCH 8/9] panel: update to #7452 panel loading on scroll Moves the logic up a level to the panel_ctrl. This cleans up the code and makes the lazy loading available for all panels. Removes the config option and making this default behavior. We can add back the config option if we get feedback that it is needed during the beta phase of the v4.3.0 release. Unbind the scroll handler on panel destroy to avoid memory leaks. Fix for png rendering, it did not match all forms of dashboard-solo. e.g. /render/dashboard-solo/db... Fix for when taking a snapshot. All the panels get refreshed then even the panels that are not visible. Closes #5216. --- public/app/features/dashboard/model.ts | 2 -- .../features/dashboard/partials/settings.html | 6 ---- .../app/features/panel/metrics_panel_ctrl.ts | 14 --------- public/app/features/panel/panel_ctrl.ts | 13 +++++++++ public/app/features/panel/panel_directive.ts | 29 ++++++++++--------- 5 files changed, 28 insertions(+), 36 deletions(-) diff --git a/public/app/features/dashboard/model.ts b/public/app/features/dashboard/model.ts index 959b5ff2116..e31a6c1afd0 100644 --- a/public/app/features/dashboard/model.ts +++ b/public/app/features/dashboard/model.ts @@ -36,7 +36,6 @@ export class DashboardModel { meta: any; events: any; editMode: boolean; - loadOnScroll: boolean; constructor(data, meta?) { if (!data) { @@ -65,7 +64,6 @@ export class DashboardModel { this.version = data.version || 0; this.links = data.links || []; this.gnetId = data.gnetId || null; - this.loadOnScroll = data.loadOnScroll || false; this.rows = []; if (data.rows) { diff --git a/public/app/features/dashboard/partials/settings.html b/public/app/features/dashboard/partials/settings.html index 7475fceb2d8..b8d8303a51b 100644 --- a/public/app/features/dashboard/partials/settings.html +++ b/public/app/features/dashboard/partials/settings.html @@ -61,12 +61,6 @@ checked="dashboard.hideControls" label-class="width-11"> - - diff --git a/public/app/features/panel/metrics_panel_ctrl.ts b/public/app/features/panel/metrics_panel_ctrl.ts index d9670291481..7ed360aab1a 100644 --- a/public/app/features/panel/metrics_panel_ctrl.ts +++ b/public/app/features/panel/metrics_panel_ctrl.ts @@ -13,7 +13,6 @@ import {Subject} from 'vendor/npm/rxjs/Subject'; class MetricsPanelCtrl extends PanelCtrl { scope: any; - needsRefresh: boolean; loading: boolean; datasource: any; datasourceName: any; @@ -43,7 +42,6 @@ class MetricsPanelCtrl extends PanelCtrl { this.timeSrv = $injector.get('timeSrv'); this.templateSrv = $injector.get('templateSrv'); this.scope = $scope; - this.needsRefresh = false; if (!this.panel.targets) { this.panel.targets = [{}]; @@ -54,10 +52,6 @@ class MetricsPanelCtrl extends PanelCtrl { this.events.on('panel-teardown', this.onPanelTearDown.bind(this)); } - private isRenderGraph () { - return window.location.href.indexOf("/dashboard-solo/") === 0; - } - private onPanelTearDown() { if (this.dataSubscription) { this.dataSubscription.unsubscribe(); @@ -74,14 +68,6 @@ class MetricsPanelCtrl extends PanelCtrl { // ignore fetching data if another panel is in fullscreen if (this.otherPanelInFullscreenMode()) { return; } - if (this.scope.ctrl.dashboard.loadOnScroll) { - if (!this.scope.$$childHead || (!this.scope.$$childHead.isVisible() && !this.isRenderGraph())) { - this.scope.$$childHead.needsRefresh = true; - return; - } - this.scope.$$childHead.needsRefresh = false; - } - // if we have snapshot data use that if (this.panel.snapshotData) { this.updateTimeRange(); diff --git a/public/app/features/panel/panel_ctrl.ts b/public/app/features/panel/panel_ctrl.ts index 83c79f4123b..0c80d7a88e3 100644 --- a/public/app/features/panel/panel_ctrl.ts +++ b/public/app/features/panel/panel_ctrl.ts @@ -35,6 +35,8 @@ export class PanelCtrl { containerHeight: any; events: Emitter; timing: any; + skippedLastRefresh: boolean; + isPanelVisible: any; constructor($scope, $injector) { this.$injector = $injector; @@ -74,7 +76,18 @@ export class PanelCtrl { profiler.renderingCompleted(this.panel.id, this.timing); } + private isRenderingPng () { + return window.location.href.indexOf("/dashboard-solo/db") >= 0; + } + refresh() { + if (!this.isPanelVisible() && !this.isRenderingPng() && !this.dashboard.snapshot) { + this.skippedLastRefresh = true; + return; + } + + this.skippedLastRefresh = false; + this.events.emit('refresh', null); } diff --git a/public/app/features/panel/panel_directive.ts b/public/app/features/panel/panel_directive.ts index 3aa195e706c..6f3987d872f 100644 --- a/public/app/features/panel/panel_directive.ts +++ b/public/app/features/panel/panel_directive.ts @@ -57,7 +57,7 @@ var panelTemplate = ` `; -module.directive('grafanaPanel', function($rootScope, $document, $timeout) { +module.directive('grafanaPanel', function($rootScope, $document) { return { restrict: 'E', template: panelTemplate, @@ -175,27 +175,28 @@ module.directive('grafanaPanel', function($rootScope, $document, $timeout) { elem.on('mouseenter', mouseEnter); elem.on('mouseleave', mouseLeave); + ctrl.isPanelVisible = function () { + var position = panelContainer[0].getBoundingClientRect(); + return (0 < position.top) && (position.top < window.innerHeight); + }; + + const refreshOnScroll = _.debounce(function () { + if (ctrl.skippedLastRefresh) { + ctrl.refresh(); + } + }, 250); + + $document.on('scroll', refreshOnScroll); + scope.$on('$destroy', function() { elem.off(); cornerInfoElem.off(); + $document.off('scroll', refreshOnScroll); if (infoDrop) { infoDrop.destroy(); } }); - - scope.needsRefresh = false; - - scope.isVisible = function () { - var position = panelContainer[0].getBoundingClientRect(); - return (0 < position.top) && (position.top < window.innerHeight); - }; - - $document.bind('scroll', _.debounce(function () { - if (scope.ctrl.dashboard.loadOnScroll && scope.needsRefresh) { - scope.ctrl.refresh(); - } - }, 250)); } }; }); From be123a07c5758abb92cc4f4bd274fe0b97c178bc Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Thu, 9 Mar 2017 14:53:50 +0900 Subject: [PATCH 9/9] (prometheus) adjust annotation step (#7768) * (prometheus) adjust annotation step * (prometheus) add step option --- .../datasource/prometheus/datasource.ts | 31 ++++++++++++------- .../partials/annotations.editor.html | 7 +++-- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/public/app/plugins/datasource/prometheus/datasource.ts b/public/app/plugins/datasource/prometheus/datasource.ts index 972fa2c7c55..f883b40e5ee 100644 --- a/public/app/plugins/datasource/prometheus/datasource.ts +++ b/public/app/plugins/datasource/prometheus/datasource.ts @@ -4,6 +4,7 @@ import angular from 'angular'; import _ from 'lodash'; import moment from 'moment'; +import kbn from 'app/core/utils/kbn'; import * as dateMath from 'app/core/utils/datemath'; import PrometheusMetricFindQuery from './metric_find_query'; @@ -88,12 +89,7 @@ export function PrometheusDatasource(instanceSettings, $q, backendSrv, templateS var intervalFactor = target.intervalFactor || 1; target.step = query.step = this.calculateInterval(interval, intervalFactor); var range = Math.ceil(end - start); - // Prometheus drop query if range/step > 11000 - // calibrate step if it is too big - if (query.step !== 0 && range / query.step > 11000) { - target.step = query.step = Math.ceil(range / 11000); - } - + target.step = query.step = this.adjustStep(query.step, range); queries.push(query); }); @@ -126,6 +122,15 @@ export function PrometheusDatasource(instanceSettings, $q, backendSrv, templateS }); }; + this.adjustStep = function(step, range) { + // Prometheus drop query if range/step > 11000 + // calibrate step if it is too big + if (step !== 0 && range / step > 11000) { + return Math.ceil(range / 11000); + } + return step; + }; + this.performTimeSeriesQuery = function(query, start, end) { if (start > end) { throw { message: 'Invalid time range' }; @@ -175,15 +180,19 @@ export function PrometheusDatasource(instanceSettings, $q, backendSrv, templateS return $q.reject(err); } - var query = { - expr: interpolated, - step: '60s' - }; + var step = '60s'; + if (annotation.step) { + step = templateSrv.replace(annotation.step); + } var start = this.getPrometheusTime(options.range.from, false); var end = this.getPrometheusTime(options.range.to, true); - var self = this; + var query = { + expr: interpolated, + step: this.adjustStep(kbn.interval_to_seconds(step), Math.ceil(end - start)) + 's' + }; + var self = this; return this.performTimeSeriesQuery(query, start, end).then(function(results) { var eventList = []; tagKeys = tagKeys.split(','); diff --git a/public/app/plugins/datasource/prometheus/partials/annotations.editor.html b/public/app/plugins/datasource/prometheus/partials/annotations.editor.html index 818aa42e886..09ee52bda45 100644 --- a/public/app/plugins/datasource/prometheus/partials/annotations.editor.html +++ b/public/app/plugins/datasource/prometheus/partials/annotations.editor.html @@ -1,9 +1,12 @@ - -
Search expression
+ Search expression
+
+ step + +