From 3ff362e446fe4455532cc4362c65d99d87f36481 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Fri, 24 Nov 2017 09:11:10 +0100 Subject: [PATCH 01/31] Update LICENSE.md --- LICENSE.md | 208 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 198 insertions(+), 10 deletions(-) diff --git a/LICENSE.md b/LICENSE.md index 4c6a79691f0..d6456956733 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,14 +1,202 @@ -Copyright 2014-2017 Torkel Ödegaard, Raintank Inc. -Licensed under the Apache License, Version 2.0 (the "License"); you -may not use this file except in compliance with the License. You may -obtain a copy of the License at + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ - http://www.apache.org/licenses/LICENSE-2.0 + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -implied. See the License for the specific language governing -permissions and limitations under the License. + 1. Definitions. + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. From 8ce05a7c24f93ec197a1e9430f7baa78df26538e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Fri, 24 Nov 2017 09:14:14 +0100 Subject: [PATCH 02/31] Update NOTICE.md --- NOTICE.md | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/NOTICE.md b/NOTICE.md index 171332f00d4..ca148971b62 100644 --- a/NOTICE.md +++ b/NOTICE.md @@ -1,16 +1,6 @@ -This software is based on Kibana: -======================================== +Copyright 2014-2017 Grafana Labs + +This software is based on Kibana: Copyright 2012-2013 Elasticsearch BV -Licensed under the Apache License, Version 2.0 (the "License"); you -may not use this file except in compliance with the License. You may -obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -implied. See the License for the specific language governing -permissions and limitations under the License. From b752cfee1f2b43d2ba5621728e39dd0338719b12 Mon Sep 17 00:00:00 2001 From: Patrick O'Carroll Date: Fri, 24 Nov 2017 12:59:36 +0100 Subject: [PATCH 03/31] migrated four files to ts, addd some code to config to make it work (#9980) --- public/app/core/config.ts | 4 ++ .../{invited_ctrl.js => invited_ctrl.ts} | 19 +++---- .../{login_ctrl.js => login_ctrl.ts} | 25 ++++----- .../{shareModalCtrl.js => shareModalCtrl.ts} | 25 ++++----- public/app/features/panel/solo_panel_ctrl.js | 51 ------------------- public/app/features/panel/solo_panel_ctrl.ts | 49 ++++++++++++++++++ 6 files changed, 81 insertions(+), 92 deletions(-) rename public/app/core/controllers/{invited_ctrl.js => invited_ctrl.ts} (75%) rename public/app/core/controllers/{login_ctrl.js => login_ctrl.ts} (85%) rename public/app/features/dashboard/{shareModalCtrl.js => shareModalCtrl.ts} (87%) delete mode 100644 public/app/features/panel/solo_panel_ctrl.js create mode 100644 public/app/features/panel/solo_panel_ctrl.ts diff --git a/public/app/core/config.ts b/public/app/core/config.ts index 63f01bea458..e54d62d7c0e 100644 --- a/public/app/core/config.ts +++ b/public/app/core/config.ts @@ -17,6 +17,10 @@ class Settings { alertingEnabled: boolean; authProxyEnabled: boolean; ldapEnabled: boolean; + oauth: any; + disableUserSignUp: boolean; + loginHint: any; + loginError: any; constructor(options) { var defaults = { diff --git a/public/app/core/controllers/invited_ctrl.js b/public/app/core/controllers/invited_ctrl.ts similarity index 75% rename from public/app/core/controllers/invited_ctrl.js rename to public/app/core/controllers/invited_ctrl.ts index dfcc198f3aa..ed4bd1793b8 100644 --- a/public/app/core/controllers/invited_ctrl.js +++ b/public/app/core/controllers/invited_ctrl.ts @@ -1,14 +1,10 @@ -define([ - 'angular', - '../core_module', - 'app/core/config', -], -function (angular, coreModule, config) { - 'use strict'; +import coreModule from '../core_module'; +import config from 'app/core/config'; - config = config.default; +export class InvitedCtrl { - coreModule.default.controller('InvitedCtrl', function($scope, $routeParams, contextSrv, backendSrv) { + /** @ngInject */ + constructor($scope, $routeParams, contextSrv, backendSrv) { contextSrv.sidemenu = false; $scope.formModel = {}; @@ -35,6 +31,7 @@ function (angular, coreModule, config) { }; $scope.init(); + } +} - }); -}); +coreModule.controller('InvitedCtrl', InvitedCtrl); diff --git a/public/app/core/controllers/login_ctrl.js b/public/app/core/controllers/login_ctrl.ts similarity index 85% rename from public/app/core/controllers/login_ctrl.js rename to public/app/core/controllers/login_ctrl.ts index 5f02811a143..11bebbce8e6 100644 --- a/public/app/core/controllers/login_ctrl.js +++ b/public/app/core/controllers/login_ctrl.ts @@ -1,15 +1,11 @@ -define([ - 'angular', - 'lodash', - '../core_module', - 'app/core/config', -], -function (angular, _, coreModule, config) { - 'use strict'; +import _ from 'lodash'; +import coreModule from '../core_module'; +import config from 'app/core/config'; - config = config.default; +export class LoginCtrl { - coreModule.default.controller('LoginCtrl', function($scope, backendSrv, contextSrv, $location) { + /** @ngInject */ + constructor($scope, backendSrv, contextSrv, $location) { $scope.formModel = { user: '', email: '', @@ -74,8 +70,7 @@ function (angular, _, coreModule, config) { if (params.redirect && params.redirect[0] === '/') { window.location.href = config.appSubUrl + params.redirect; - } - else if (result.redirectUrl) { + } else if (result.redirectUrl) { window.location.href = result.redirectUrl; } else { window.location.href = config.appSubUrl + '/'; @@ -84,5 +79,7 @@ function (angular, _, coreModule, config) { }; $scope.init(); - }); -}); + } +} + +coreModule.controller('LoginCtrl', LoginCtrl); diff --git a/public/app/features/dashboard/shareModalCtrl.js b/public/app/features/dashboard/shareModalCtrl.ts similarity index 87% rename from public/app/features/dashboard/shareModalCtrl.js rename to public/app/features/dashboard/shareModalCtrl.ts index e750b631771..1ddec697eb2 100644 --- a/public/app/features/dashboard/shareModalCtrl.js +++ b/public/app/features/dashboard/shareModalCtrl.ts @@ -1,18 +1,11 @@ -define(['angular', - 'lodash', - 'jquery', - 'moment', - 'app/core/config', -], -function (angular, _, $, moment, config) { - 'use strict'; +import angular from 'angular'; +import moment from 'moment'; +import config from 'app/core/config'; - config = config.default; - - var module = angular.module('grafana.controllers'); - - module.controller('ShareModalCtrl', function($scope, $rootScope, $location, $timeout, timeSrv, templateSrv, linkSrv) { +export class ShareModalCtrl { + /** @ngInject */ + constructor($scope, $rootScope, $location, $timeout, timeSrv, templateSrv, linkSrv) { $scope.options = { forCurrent: true, includeTemplateVars: true, theme: 'current' }; $scope.editor = { index: $scope.tabIndex || 0}; @@ -93,7 +86,7 @@ function (angular, _, $, moment, config) { $scope.getShareUrl = function() { return $scope.shareUrl; }; + } +} - }); - -}); +angular.module('grafana.controllers').controller('ShareModalCtrl', ShareModalCtrl); diff --git a/public/app/features/panel/solo_panel_ctrl.js b/public/app/features/panel/solo_panel_ctrl.js deleted file mode 100644 index a25c5f90c27..00000000000 --- a/public/app/features/panel/solo_panel_ctrl.js +++ /dev/null @@ -1,51 +0,0 @@ -define([ - 'angular', - 'jquery', -], -function (angular, $) { - "use strict"; - - var module = angular.module('grafana.routes'); - - module.controller('SoloPanelCtrl', function($scope, $routeParams, $location, dashboardLoaderSrv, contextSrv) { - - var panelId; - - $scope.init = function() { - contextSrv.sidemenu = false; - - var params = $location.search(); - panelId = parseInt(params.panelId); - - $scope.onAppEvent("dashboard-initialized", $scope.initPanelScope); - - dashboardLoaderSrv.loadDashboard($routeParams.type, $routeParams.slug).then(function(result) { - result.meta.soloMode = true; - $scope.initDashboard(result, $scope); - }); - }; - - $scope.initPanelScope = function() { - var panelInfo = $scope.dashboard.getPanelInfoById(panelId); - - // fake row ctrl scope - $scope.ctrl = { - row: panelInfo.row, - dashboard: $scope.dashboard, - }; - - $scope.ctrl.row.height = $(window).height(); - $scope.panel = panelInfo.panel; - $scope.$index = 0; - - if (!$scope.panel) { - $scope.appEvent('alert-error', ['Panel not found', '']); - return; - } - - $scope.panel.span = 12; - }; - - $scope.init(); - }); -}); diff --git a/public/app/features/panel/solo_panel_ctrl.ts b/public/app/features/panel/solo_panel_ctrl.ts new file mode 100644 index 00000000000..2157d840e3e --- /dev/null +++ b/public/app/features/panel/solo_panel_ctrl.ts @@ -0,0 +1,49 @@ +import angular from 'angular'; +import $ from 'jquery'; + +export class SoloPanelCtrl { + + /** @ngInject */ + constructor($scope, $routeParams, $location, dashboardLoaderSrv, contextSrv) { + var panelId; + + $scope.init = function() { + contextSrv.sidemenu = false; + + var params = $location.search(); + panelId = parseInt(params.panelId); + + $scope.onAppEvent("dashboard-initialized", $scope.initPanelScope); + + dashboardLoaderSrv.loadDashboard($routeParams.type, $routeParams.slug).then(function(result) { + result.meta.soloMode = true; + $scope.initDashboard(result, $scope); + }); + }; + + $scope.initPanelScope = function() { + var panelInfo = $scope.dashboard.getPanelInfoById(panelId); + + // fake row ctrl scope + $scope.ctrl = { + row: panelInfo.row, + dashboard: $scope.dashboard, + }; + + $scope.ctrl.row.height = $(window).height(); + $scope.panel = panelInfo.panel; + $scope.$index = 0; + + if (!$scope.panel) { + $scope.appEvent('alert-error', ['Panel not found', '']); + return; + } + + $scope.panel.span = 12; + }; + + $scope.init(); + } +} + +angular.module('grafana.routes').controller('SoloPanelCtrl', SoloPanelCtrl); From 015932fd026566c3fe5561dd2995a4a8d30c2717 Mon Sep 17 00:00:00 2001 From: Patrick O'Carroll Date: Fri, 24 Nov 2017 13:38:54 +0100 Subject: [PATCH 04/31] migrated four files from js to ts --- public/app/core/controllers/all.js | 9 --------- public/app/core/controllers/all.ts | 7 +++++++ .../{error_ctrl.js => error_ctrl.ts} | 19 ++++++++----------- ...son_editor_ctrl.js => json_editor_ctrl.ts} | 18 ++++++++---------- ...assword_ctrl.js => reset_password_ctrl.ts} | 18 ++++++++---------- 5 files changed, 31 insertions(+), 40 deletions(-) delete mode 100644 public/app/core/controllers/all.js create mode 100644 public/app/core/controllers/all.ts rename public/app/core/controllers/{error_ctrl.js => error_ctrl.ts} (54%) rename public/app/core/controllers/{json_editor_ctrl.js => json_editor_ctrl.ts} (58%) rename public/app/core/controllers/{reset_password_ctrl.js => reset_password_ctrl.ts} (80%) diff --git a/public/app/core/controllers/all.js b/public/app/core/controllers/all.js deleted file mode 100644 index 54631586c2f..00000000000 --- a/public/app/core/controllers/all.js +++ /dev/null @@ -1,9 +0,0 @@ -define([ - './inspect_ctrl', - './json_editor_ctrl', - './login_ctrl', - './invited_ctrl', - './signup_ctrl', - './reset_password_ctrl', - './error_ctrl', -], function () {}); diff --git a/public/app/core/controllers/all.ts b/public/app/core/controllers/all.ts new file mode 100644 index 00000000000..0dbcdf4cb28 --- /dev/null +++ b/public/app/core/controllers/all.ts @@ -0,0 +1,7 @@ +import './inspect_ctrl'; +import './json_editor_ctrl'; +import './login_ctrl'; +import './invited_ctrl'; +import './signup_ctrl'; +import './reset_password_ctrl'; +import './error_ctrl'; diff --git a/public/app/core/controllers/error_ctrl.js b/public/app/core/controllers/error_ctrl.ts similarity index 54% rename from public/app/core/controllers/error_ctrl.js rename to public/app/core/controllers/error_ctrl.ts index fd4081186be..fe894a69806 100644 --- a/public/app/core/controllers/error_ctrl.js +++ b/public/app/core/controllers/error_ctrl.ts @@ -1,13 +1,10 @@ -define([ - 'angular', - 'app/core/config', - '../core_module', -], -function (angular, config, coreModule) { - 'use strict'; +import config from 'app/core/config'; +import coreModule from '../core_module'; - coreModule.default.controller('ErrorCtrl', function($scope, contextSrv, navModelSrv) { +export class ErrorCtrl { + /** @ngInject */ + constructor($scope, contextSrv, navModelSrv) { $scope.navModel = navModelSrv.getNotFoundNav(); $scope.appSubUrl = config.appSubUrl; @@ -17,7 +14,7 @@ function (angular, config, coreModule) { $scope.$on('$destroy', function() { contextSrv.sidemenu = showSideMenu; }); + } +} - }); - -}); +coreModule.controller('ErrorCtrl', ErrorCtrl); diff --git a/public/app/core/controllers/json_editor_ctrl.js b/public/app/core/controllers/json_editor_ctrl.ts similarity index 58% rename from public/app/core/controllers/json_editor_ctrl.js rename to public/app/core/controllers/json_editor_ctrl.ts index 7d7d56fa96b..ba6d9abfd74 100644 --- a/public/app/core/controllers/json_editor_ctrl.js +++ b/public/app/core/controllers/json_editor_ctrl.ts @@ -1,12 +1,10 @@ -define([ - 'angular', - '../core_module', -], -function (angular, coreModule) { - 'use strict'; +import angular from 'angular'; +import coreModule from '../core_module'; - coreModule.default.controller('JsonEditorCtrl', function($scope) { +export class JsonEditorCtrl { + /** @ngInject */ + constructor($scope) { $scope.json = angular.toJson($scope.object, true); $scope.canUpdate = $scope.updateHandler !== void 0 && $scope.contextSrv.isEditor; @@ -14,7 +12,7 @@ function (angular, coreModule) { var newObject = angular.fromJson($scope.json); $scope.updateHandler(newObject, $scope.object); }; + } +} - }); - -}); +coreModule.controller('JsonEditorCtrl', JsonEditorCtrl); diff --git a/public/app/core/controllers/reset_password_ctrl.js b/public/app/core/controllers/reset_password_ctrl.ts similarity index 80% rename from public/app/core/controllers/reset_password_ctrl.js rename to public/app/core/controllers/reset_password_ctrl.ts index 4cf014d2482..524cfb7af64 100644 --- a/public/app/core/controllers/reset_password_ctrl.js +++ b/public/app/core/controllers/reset_password_ctrl.ts @@ -1,11 +1,9 @@ -define([ - 'angular', - '../core_module', -], -function (angular, coreModule) { - 'use strict'; +import coreModule from '../core_module'; - coreModule.default.controller('ResetPasswordCtrl', function($scope, contextSrv, backendSrv, $location) { +export class ResetPasswordCtrl { + + /** @ngInject */ + constructor($scope, contextSrv, backendSrv, $location) { contextSrv.sidemenu = false; $scope.formModel = {}; $scope.mode = 'send'; @@ -37,7 +35,7 @@ function (angular, coreModule) { $location.path('login'); }); }; + } +} - }); - -}); +coreModule.controller('ResetPasswordCtrl', ResetPasswordCtrl); From afd0fc3652c168d5789396a2cf10dfecf085ddba Mon Sep 17 00:00:00 2001 From: Patrick O'Carroll Date: Tue, 28 Nov 2017 13:27:43 +0100 Subject: [PATCH 05/31] export view json now templatized, fixes #10001 --- public/app/features/dashboard/export/export_modal.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/app/features/dashboard/export/export_modal.ts b/public/app/features/dashboard/export/export_modal.ts index 826086ebdf0..1b8aa4ae5d8 100644 --- a/public/app/features/dashboard/export/export_modal.ts +++ b/public/app/features/dashboard/export/export_modal.ts @@ -26,7 +26,7 @@ export class DashExportCtrl { } saveJson() { - var clone = this.dashboardSrv.getCurrent().getSaveModelClone(); + var clone = this.dash; this.$scope.$root.appEvent('show-json-editor', { object: clone, From c0e087640bd8227b28b74f357e0d314ff4c79308 Mon Sep 17 00:00:00 2001 From: bergquist Date: Tue, 28 Nov 2017 15:05:53 +0100 Subject: [PATCH 06/31] test: close file before deleting --- pkg/log/file_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/log/file_test.go b/pkg/log/file_test.go index 458a39d754b..3e98e0786cc 100644 --- a/pkg/log/file_test.go +++ b/pkg/log/file_test.go @@ -38,6 +38,7 @@ func TestLogFile(t *testing.T) { So(fileLogWrite.maxlines_curlines, ShouldEqual, 3) }) + fileLogWrite.Close() err = os.Remove(fileLogWrite.Filename) So(err, ShouldBeNil) }) From 3f95180c983602e27aa8d7bd3ff6d15d2827c460 Mon Sep 17 00:00:00 2001 From: jomenxiao Date: Tue, 28 Nov 2017 22:20:22 +0800 Subject: [PATCH 07/31] fix render http[get] params error --- pkg/api/render.go | 6 +++++- pkg/util/url.go | 11 ++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/pkg/api/render.go b/pkg/api/render.go index 5284c7831bb..fdf53e6730d 100644 --- a/pkg/api/render.go +++ b/pkg/api/render.go @@ -10,7 +10,11 @@ import ( ) func RenderToPng(c *middleware.Context) { - queryReader := util.NewUrlQueryReader(c.Req.URL) + queryReader, err := util.NewUrlQueryReader(c.Req.URL) + if err != nil { + c.Handle(400, "Rander parameters error", err) + return + } queryParams := fmt.Sprintf("?%s", c.Req.URL.RawQuery) renderOpts := &renderer.RenderOpts{ diff --git a/pkg/util/url.go b/pkg/util/url.go index ba452596a2b..c82dcef67c5 100644 --- a/pkg/util/url.go +++ b/pkg/util/url.go @@ -9,10 +9,15 @@ type UrlQueryReader struct { values url.Values } -func NewUrlQueryReader(url *url.URL) *UrlQueryReader { - return &UrlQueryReader{ - values: url.Query(), +func NewUrlQueryReader(urlInfo *url.URL) (*UrlQueryReader, error) { + u, err := url.ParseQuery(urlInfo.String()) + if err != nil { + return nil, err } + + return &UrlQueryReader{ + values: u, + }, nil } func (r *UrlQueryReader) Get(name string, def string) string { From 98bb8bf7612a133a47ee171d3a256a29473a4f5f Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Sat, 25 Nov 2017 02:35:29 +0900 Subject: [PATCH 08/31] prometheus nested query support --- .../plugins/datasource/prometheus/datasource.ts | 8 ++++++++ .../prometheus/specs/datasource_specs.ts | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/public/app/plugins/datasource/prometheus/datasource.ts b/public/app/plugins/datasource/prometheus/datasource.ts index c4939b5b2fa..7e21852f476 100644 --- a/public/app/plugins/datasource/prometheus/datasource.ts +++ b/public/app/plugins/datasource/prometheus/datasource.ts @@ -155,6 +155,7 @@ export class PrometheusDatasource { // Only replace vars in expression after having (possibly) updated interval vars query.expr = this.templateSrv.replace(target.expr, scopedVars, this.interpolateQueryExpr); + query.expr = this.replaceNestedQuery(query.expr, options); query.requestId = options.panelId + target.refId; return query; } @@ -269,6 +270,13 @@ export class PrometheusDatasource { }); } + replaceNestedQuery(query, options) { + return query.replace(/\#([A-Z])/g, (match, g1) => { + let replaceTarget = options.targets.find((t) => { return t.refId === g1; }); + return replaceTarget ? replaceTarget.expr : match; + }); + } + transformMetricData(md, options, start, end, step) { var dps = [], metricLabel = null; diff --git a/public/app/plugins/datasource/prometheus/specs/datasource_specs.ts b/public/app/plugins/datasource/prometheus/specs/datasource_specs.ts index 9d528c735de..67d861da1c6 100644 --- a/public/app/plugins/datasource/prometheus/specs/datasource_specs.ts +++ b/public/app/plugins/datasource/prometheus/specs/datasource_specs.ts @@ -590,4 +590,19 @@ describe('PrometheusDatasource', function() { expect(query.scopedVars.__interval_ms.value).to.be(5 * 1000); }); }); + describe('The nested query', function() { + it('should generate correct query', function() { + let query = 'sum(rate(#A[1m]))'; + let options = { + targets: [ + { + refId: 'A', + expr: 'http_requests_total' + } + ] + }; + let result = ctx.ds.replaceNestedQuery(query, options); + expect(result).to.be('sum(rate(http_requests_total[1m]))'); + }); + }); }); From e6bf266c4be87a54d65940dadecbf5c075e57fb5 Mon Sep 17 00:00:00 2001 From: Daniel Lee Date: Wed, 29 Nov 2017 11:15:27 +0100 Subject: [PATCH 09/31] formatting in build file --- build.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.go b/build.go index a1d1d3012ab..1c61c72d5dc 100644 --- a/build.go +++ b/build.go @@ -95,9 +95,9 @@ func main() { case "package": grunt(gruntBuildArg("release")...) - if runtime.GOOS != "windows" { - createLinuxPackages() - } + if runtime.GOOS != "windows" { + createLinuxPackages() + } case "pkg-rpm": grunt(gruntBuildArg("release")...) From 554c7ba96f28c48a3d868a0a663f605aefb4a43c Mon Sep 17 00:00:00 2001 From: Daniel Lee Date: Wed, 29 Nov 2017 11:16:45 +0100 Subject: [PATCH 10/31] notifier: Fixes path for uploaded image for Slack notifier Fixes #10012 --- pkg/services/alerting/notifiers/slack.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/services/alerting/notifiers/slack.go b/pkg/services/alerting/notifiers/slack.go index ed1451da419..e051a71740a 100644 --- a/pkg/services/alerting/notifiers/slack.go +++ b/pkg/services/alerting/notifiers/slack.go @@ -6,6 +6,7 @@ import ( "io" "mime/multipart" "os" + "path/filepath" "time" "github.com/grafana/grafana/pkg/bus" @@ -176,7 +177,7 @@ func (this *SlackNotifier) Notify(evalContext *alerting.EvalContext) error { func SlackFileUpload(evalContext *alerting.EvalContext, log log.Logger, url string, recipient string, token string) error { if evalContext.ImageOnDiskPath == "" { - evalContext.ImageOnDiskPath = "public/img/mixed_styles.png" + evalContext.ImageOnDiskPath = filepath.Join(setting.HomePath, "public/img/mixed_styles.png") } log.Info("Uploading to slack via file.upload API") headers, uploadBody, err := GenerateSlackBody(evalContext.ImageOnDiskPath, token, recipient) From c8ac6add166796f0f62075f3fdf70a97ef330a74 Mon Sep 17 00:00:00 2001 From: Marcus Efraimsson Date: Wed, 29 Nov 2017 14:40:23 +0100 Subject: [PATCH 11/31] test: speedup mysql and postgres integration tests by 10-20x Use docker tmpfs mounts for mysql and postgres data volumes --- docker/blocks/mysql_tests/docker-compose.yaml | 1 + docker/blocks/postgres_tests/docker-compose.yaml | 1 + 2 files changed, 2 insertions(+) diff --git a/docker/blocks/mysql_tests/docker-compose.yaml b/docker/blocks/mysql_tests/docker-compose.yaml index 646cc7ee369..c6c3097d463 100644 --- a/docker/blocks/mysql_tests/docker-compose.yaml +++ b/docker/blocks/mysql_tests/docker-compose.yaml @@ -7,3 +7,4 @@ MYSQL_PASSWORD: password ports: - "3306:3306" + tmpfs: /var/lib/mysql:rw diff --git a/docker/blocks/postgres_tests/docker-compose.yaml b/docker/blocks/postgres_tests/docker-compose.yaml index 3d9a82c034c..44b66e8e558 100644 --- a/docker/blocks/postgres_tests/docker-compose.yaml +++ b/docker/blocks/postgres_tests/docker-compose.yaml @@ -5,3 +5,4 @@ POSTGRES_PASSWORD: grafanatest ports: - "5432:5432" + tmpfs: /var/lib/postgresql/data:rw \ No newline at end of file From 1e10fcad83ead00b20e2c24f87277fbc49003410 Mon Sep 17 00:00:00 2001 From: Marcus Efraimsson Date: Wed, 29 Nov 2017 15:17:31 +0100 Subject: [PATCH 12/31] test: fix failing postgres test Should use case insensitive matching when searching for users --- pkg/services/sqlstore/user.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/services/sqlstore/user.go b/pkg/services/sqlstore/user.go index 3781d83dd96..4c199d306f0 100644 --- a/pkg/services/sqlstore/user.go +++ b/pkg/services/sqlstore/user.go @@ -400,7 +400,7 @@ func SearchUsers(query *m.SearchUsersQuery) error { } if query.Query != "" { - whereConditions = append(whereConditions, "(email LIKE ? OR name LIKE ? OR login like ?)") + whereConditions = append(whereConditions, "(email "+dialect.LikeStr()+" ? OR name "+dialect.LikeStr()+" ? OR login "+dialect.LikeStr()+" ?)") whereParams = append(whereParams, queryWithWildcards, queryWithWildcards, queryWithWildcards) } From af5ced0e18f4f9948d68742725c821adf02b4b58 Mon Sep 17 00:00:00 2001 From: Carl Bergquist Date: Thu, 30 Nov 2017 15:06:02 +0100 Subject: [PATCH 13/31] Revert "prometheus nested query support" --- .../plugins/datasource/prometheus/datasource.ts | 8 -------- .../prometheus/specs/datasource_specs.ts | 15 --------------- 2 files changed, 23 deletions(-) diff --git a/public/app/plugins/datasource/prometheus/datasource.ts b/public/app/plugins/datasource/prometheus/datasource.ts index 6f41833e22a..ec295760d49 100644 --- a/public/app/plugins/datasource/prometheus/datasource.ts +++ b/public/app/plugins/datasource/prometheus/datasource.ts @@ -157,7 +157,6 @@ export class PrometheusDatasource { // Only replace vars in expression after having (possibly) updated interval vars query.expr = this.templateSrv.replace(target.expr, scopedVars, this.interpolateQueryExpr); - query.expr = this.replaceNestedQuery(query.expr, options); query.requestId = options.panelId + target.refId; return query; } @@ -272,13 +271,6 @@ export class PrometheusDatasource { }); } - replaceNestedQuery(query, options) { - return query.replace(/\#([A-Z])/g, (match, g1) => { - let replaceTarget = options.targets.find((t) => { return t.refId === g1; }); - return replaceTarget ? replaceTarget.expr : match; - }); - } - transformMetricData(md, options, start, end, step) { var dps = [], metricLabel = null; diff --git a/public/app/plugins/datasource/prometheus/specs/datasource_specs.ts b/public/app/plugins/datasource/prometheus/specs/datasource_specs.ts index a507aa41545..a7d18f3f158 100644 --- a/public/app/plugins/datasource/prometheus/specs/datasource_specs.ts +++ b/public/app/plugins/datasource/prometheus/specs/datasource_specs.ts @@ -590,19 +590,4 @@ describe('PrometheusDatasource', function() { expect(query.scopedVars.__interval_ms.value).to.be(5 * 1000); }); }); - describe('The nested query', function() { - it('should generate correct query', function() { - let query = 'sum(rate(#A[1m]))'; - let options = { - targets: [ - { - refId: 'A', - expr: 'http_requests_total' - } - ] - }; - let result = ctx.ds.replaceNestedQuery(query, options); - expect(result).to.be('sum(rate(http_requests_total[1m]))'); - }); - }); }); From 68d4211c50e76686d6a63e92fc647f4d320fec34 Mon Sep 17 00:00:00 2001 From: Andrei Kalasok Date: Thu, 30 Nov 2017 15:10:44 +0100 Subject: [PATCH 14/31] grafana-10039: fix query time range ends in the past --- pkg/tsdb/graphite/graphite.go | 4 ++-- pkg/tsdb/graphite/graphite_test.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/tsdb/graphite/graphite.go b/pkg/tsdb/graphite/graphite.go index 7cadf055ff6..73b173813af 100644 --- a/pkg/tsdb/graphite/graphite.go +++ b/pkg/tsdb/graphite/graphite.go @@ -17,7 +17,7 @@ import ( "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/tsdb" - opentracing "github.com/opentracing/opentracing-go" + "github.com/opentracing/opentracing-go" ) type GraphiteExecutor struct { @@ -158,7 +158,7 @@ func formatTimeRange(input string) string { if input == "now" { return input } - return strings.Replace(strings.Replace(input, "m", "min", -1), "M", "mon", -1) + return strings.Replace(strings.Replace(strings.Replace(input, "now", "", -1), "m", "min", -1), "M", "mon", -1) } func fixIntervalFormat(target string) string { diff --git a/pkg/tsdb/graphite/graphite_test.go b/pkg/tsdb/graphite/graphite_test.go index c1a2736293b..1704a9b5f55 100644 --- a/pkg/tsdb/graphite/graphite_test.go +++ b/pkg/tsdb/graphite/graphite_test.go @@ -18,14 +18,14 @@ func TestGraphiteFunctions(t *testing.T) { Convey("formatting time range for now-1m", func() { timeRange := formatTimeRange("now-1m") - So(timeRange, ShouldEqual, "now-1min") + So(timeRange, ShouldEqual, "-1min") }) Convey("formatting time range for now-1M", func() { timeRange := formatTimeRange("now-1M") - So(timeRange, ShouldEqual, "now-1mon") + So(timeRange, ShouldEqual, "-1mon") }) From d28ca541292c5fa9230c153999ec729eac98a611 Mon Sep 17 00:00:00 2001 From: Johannes Grassler Date: Tue, 28 Nov 2017 18:16:38 +0100 Subject: [PATCH 15/31] Use systemd notification where applicable With this change in place, the grafana service will signal readiness to serve by writing "READY=1" to the path specified through the NOTIFY_SOCKET environment variable. If this environment variable is not present or empty, no notification will happen. This notification is the standard systemd mechanism for indicating a service is ready to serve. For Grafana this may be a couple of seconds from startup due to database migrations. This change also adjusts the Grafana systemd service definition to make use of this feature. --- packaging/rpm/systemd/grafana-server.service | 2 +- pkg/cmd/grafana-server/server.go | 2 ++ pkg/util/sdnotify.go | 34 ++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 pkg/util/sdnotify.go diff --git a/packaging/rpm/systemd/grafana-server.service b/packaging/rpm/systemd/grafana-server.service index 3e018e8b176..b23e5196e17 100644 --- a/packaging/rpm/systemd/grafana-server.service +++ b/packaging/rpm/systemd/grafana-server.service @@ -9,7 +9,7 @@ After=postgresql.service mariadb.service mysql.service EnvironmentFile=/etc/sysconfig/grafana-server User=grafana Group=grafana -Type=simple +Type=notify Restart=on-failure WorkingDirectory=/usr/share/grafana RuntimeDirectory=grafana diff --git a/pkg/cmd/grafana-server/server.go b/pkg/cmd/grafana-server/server.go index 1d3ac092734..476eb2f433f 100644 --- a/pkg/cmd/grafana-server/server.go +++ b/pkg/cmd/grafana-server/server.go @@ -29,6 +29,7 @@ import ( "github.com/grafana/grafana/pkg/social" "github.com/grafana/grafana/pkg/tracing" + "github.com/grafana/grafana/pkg/util" ) func NewGrafanaServer() models.GrafanaServer { @@ -96,6 +97,7 @@ func (g *GrafanaServerImpl) Start() { return } + util.SdNotify("READY=1") g.startHttpServer() } diff --git a/pkg/util/sdnotify.go b/pkg/util/sdnotify.go new file mode 100644 index 00000000000..b5cd4a4a45d --- /dev/null +++ b/pkg/util/sdnotify.go @@ -0,0 +1,34 @@ +package util + +import ( + "errors" + "net" + "os" +) + +var NoNotifySocket = errors.New("NOTIFY_SOCKET environment variable empty or unset.") + +func SdNotify(state string) error { + notifySocket := os.Getenv("NOTIFY_SOCKET") + + if notifySocket == "" { + return NoNotifySocket + } + + socketAddr := &net.UnixAddr{ + Name: notifySocket, + Net: "unixgram", + } + + conn, err := net.DialUnix(socketAddr.Net, nil, socketAddr) + + if err != nil { + return err + } + + _, err = conn.Write([]byte(state)) + + conn.Close() + + return err +} From 94446fb85c2c69860c792bc0657600b7df082824 Mon Sep 17 00:00:00 2001 From: bergquist Date: Fri, 1 Dec 2017 13:54:31 +0100 Subject: [PATCH 16/31] changelog: adds note about closing #10024 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a75ad758c8..1b4adfcdda2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,7 @@ * **Cloudwatch**: Fixes broken query inspector for cloudwatch [#9661](https://github.com/grafana/grafana/issues/9661), thx [@mtanda](https://github.com/mtanda) * **Dashboard**: Make it possible to start dashboards from search and dashboard list panel [#1871](https://github.com/grafana/grafana/issues/1871) * **Annotations**: Posting annotations now return the id of the annotation [#9798](https://github.com/grafana/grafana/issues/9798) - +* **Systemd**: Use systemd notification ready flag [#10024](https://github.com/grafana/grafana/issues/10024), thx [@jgrassler](https://github.com/jgrassler) ## Tech * **RabbitMq**: Remove support for publishing events to RabbitMQ [#9645](https://github.com/grafana/grafana/issues/9645) From 7a497fd617b3648bc0ca5b4cd779e93c0d24a02a Mon Sep 17 00:00:00 2001 From: bergquist Date: Fri, 1 Dec 2017 14:02:05 +0100 Subject: [PATCH 17/31] move systemd ready notification to server.go --- pkg/cmd/grafana-server/server.go | 30 ++++++++++++++++++++++++++-- pkg/util/sdnotify.go | 34 -------------------------------- 2 files changed, 28 insertions(+), 36 deletions(-) delete mode 100644 pkg/util/sdnotify.go diff --git a/pkg/cmd/grafana-server/server.go b/pkg/cmd/grafana-server/server.go index 476eb2f433f..4d95e77ad29 100644 --- a/pkg/cmd/grafana-server/server.go +++ b/pkg/cmd/grafana-server/server.go @@ -3,7 +3,9 @@ package main import ( "context" "flag" + "fmt" "io/ioutil" + "net" "os" "path/filepath" "strconv" @@ -29,7 +31,6 @@ import ( "github.com/grafana/grafana/pkg/social" "github.com/grafana/grafana/pkg/tracing" - "github.com/grafana/grafana/pkg/util" ) func NewGrafanaServer() models.GrafanaServer { @@ -97,7 +98,7 @@ func (g *GrafanaServerImpl) Start() { return } - util.SdNotify("READY=1") + SendSystemdReady("READY=1") g.startHttpServer() } @@ -171,3 +172,28 @@ func (g *GrafanaServerImpl) writePIDFile() { g.log.Info("Writing PID file", "path", *pidFile, "pid", pid) } + +func SendSystemdReady(state string) error { + notifySocket := os.Getenv("NOTIFY_SOCKET") + + if notifySocket == "" { + return fmt.Errorf("NOTIFY_SOCKET environment variable empty or unset.") + } + + socketAddr := &net.UnixAddr{ + Name: notifySocket, + Net: "unixgram", + } + + conn, err := net.DialUnix(socketAddr.Net, nil, socketAddr) + + if err != nil { + return err + } + + _, err = conn.Write([]byte(state)) + + conn.Close() + + return err +} diff --git a/pkg/util/sdnotify.go b/pkg/util/sdnotify.go deleted file mode 100644 index b5cd4a4a45d..00000000000 --- a/pkg/util/sdnotify.go +++ /dev/null @@ -1,34 +0,0 @@ -package util - -import ( - "errors" - "net" - "os" -) - -var NoNotifySocket = errors.New("NOTIFY_SOCKET environment variable empty or unset.") - -func SdNotify(state string) error { - notifySocket := os.Getenv("NOTIFY_SOCKET") - - if notifySocket == "" { - return NoNotifySocket - } - - socketAddr := &net.UnixAddr{ - Name: notifySocket, - Net: "unixgram", - } - - conn, err := net.DialUnix(socketAddr.Net, nil, socketAddr) - - if err != nil { - return err - } - - _, err = conn.Write([]byte(state)) - - conn.Close() - - return err -} From 17bf87fb626ecb7b8a338e486403861e43deae17 Mon Sep 17 00:00:00 2001 From: bergquist Date: Fri, 1 Dec 2017 14:05:47 +0100 Subject: [PATCH 18/31] typo :boom: --- pkg/cmd/grafana-server/server.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/cmd/grafana-server/server.go b/pkg/cmd/grafana-server/server.go index 4d95e77ad29..f5c6b0d1cee 100644 --- a/pkg/cmd/grafana-server/server.go +++ b/pkg/cmd/grafana-server/server.go @@ -98,7 +98,7 @@ func (g *GrafanaServerImpl) Start() { return } - SendSystemdReady("READY=1") + SendSystemdNotification("READY=1") g.startHttpServer() } @@ -173,7 +173,7 @@ func (g *GrafanaServerImpl) writePIDFile() { g.log.Info("Writing PID file", "path", *pidFile, "pid", pid) } -func SendSystemdReady(state string) error { +func SendSystemdNotification(state string) error { notifySocket := os.Getenv("NOTIFY_SOCKET") if notifySocket == "" { From 5e9f0771c599ea1005f2d9faf7edc0eccf1a67a1 Mon Sep 17 00:00:00 2001 From: bergquist Date: Fri, 1 Dec 2017 15:49:54 +0100 Subject: [PATCH 19/31] ignore /conf/**/custom.yaml files --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 719f4347779..da222a55b5b 100644 --- a/.gitignore +++ b/.gitignore @@ -39,6 +39,8 @@ conf/custom.ini fig.yml docker-compose.yml docker-compose.yaml +/conf/dashboards/custom.yaml +/conf/datasources/custom.yaml profile.cov /grafana .notouch From 92821828055820bcbb6fdcaeba4a2b58eceab85f Mon Sep 17 00:00:00 2001 From: bergquist Date: Fri, 1 Dec 2017 16:16:49 +0100 Subject: [PATCH 20/31] influxdb: pass tags to alerting from influxdb client closes #10046 --- pkg/tsdb/influxdb/response_parser.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/tsdb/influxdb/response_parser.go b/pkg/tsdb/influxdb/response_parser.go index b7db6182241..8de8dcbb464 100644 --- a/pkg/tsdb/influxdb/response_parser.go +++ b/pkg/tsdb/influxdb/response_parser.go @@ -50,6 +50,7 @@ func (rp *ResponseParser) transformRows(rows []Row, queryResult *tsdb.QueryResul result = append(result, &tsdb.TimeSeries{ Name: rp.formatSerieName(row, column, query), Points: points, + Tags: row.Tags, }) } } From d6d64c53cd0e3bf1fdea4f98b4c2ce7fb8533ccf Mon Sep 17 00:00:00 2001 From: bergquist Date: Fri, 1 Dec 2017 16:23:55 +0100 Subject: [PATCH 21/31] typo :boom: --- pkg/api/render.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/api/render.go b/pkg/api/render.go index fdf53e6730d..cab9c81505d 100644 --- a/pkg/api/render.go +++ b/pkg/api/render.go @@ -12,7 +12,7 @@ import ( func RenderToPng(c *middleware.Context) { queryReader, err := util.NewUrlQueryReader(c.Req.URL) if err != nil { - c.Handle(400, "Rander parameters error", err) + c.Handle(400, "Render parameters error", err) return } queryParams := fmt.Sprintf("?%s", c.Req.URL.RawQuery) From 3e94d804303a3f8dfb750372fcde4edc9f828948 Mon Sep 17 00:00:00 2001 From: paulfantom Date: Fri, 1 Dec 2017 21:26:14 +0100 Subject: [PATCH 22/31] add Cloud Alchemy Ansible role --- docs/sources/administration/provisioning.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/sources/administration/provisioning.md b/docs/sources/administration/provisioning.md index 70d9d7a81f3..119044da6cf 100644 --- a/docs/sources/administration/provisioning.md +++ b/docs/sources/administration/provisioning.md @@ -65,6 +65,7 @@ Currently we do not provide any scripts/manifests for configuring Grafana. Rathe Tool | Project -----|------------ Puppet | [https://forge.puppet.com/puppet/grafana](https://forge.puppet.com/puppet/grafana) +Ansible | [https://github.com/cloudalchemy/ansible-grafana](https://github.com/cloudalchemy/ansible-grafana) Ansible | [https://github.com/picotrading/ansible-grafana](https://github.com/picotrading/ansible-grafana) Chef | [https://github.com/JonathanTron/chef-grafana](https://github.com/JonathanTron/chef-grafana) Saltstack | [https://github.com/salt-formulas/salt-formula-grafana](https://github.com/salt-formulas/salt-formula-grafana) From e8a6af7b22ae7ade575f40b6b48aae9916f26370 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Sun, 3 Dec 2017 01:21:21 +0900 Subject: [PATCH 23/31] fix templating undefined error (#10004) --- .../datasource/prometheus/metric_find_query.ts | 4 ++-- .../specs/metric_find_query_specs.ts | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/public/app/plugins/datasource/prometheus/metric_find_query.ts b/public/app/plugins/datasource/prometheus/metric_find_query.ts index 7a82a428939..46d9bf9fccd 100644 --- a/public/app/plugins/datasource/prometheus/metric_find_query.ts +++ b/public/app/plugins/datasource/prometheus/metric_find_query.ts @@ -67,8 +67,8 @@ export default class PrometheusMetricFindQuery { return this.datasource._request("GET", url).then(function(result) { var _labels = _.map(result.data.data, function(metric) { - return metric[label]; - }); + return metric[label] || ''; + }).filter(function(label) { return label !== ''; }); return _.uniq(_labels).map(function(metric) { return { diff --git a/public/app/plugins/datasource/prometheus/specs/metric_find_query_specs.ts b/public/app/plugins/datasource/prometheus/specs/metric_find_query_specs.ts index bb051d7328d..adc1cc248f8 100644 --- a/public/app/plugins/datasource/prometheus/specs/metric_find_query_specs.ts +++ b/public/app/plugins/datasource/prometheus/specs/metric_find_query_specs.ts @@ -76,6 +76,24 @@ describe('PrometheusMetricFindQuery', function() { ctx.$rootScope.$apply(); expect(results.length).to.be(3); }); + it('label_values(metric, resource) result should not contain empty string', function() { + response = { + status: "success", + data: [ + {__name__: "metric", resource: "value1"}, + {__name__: "metric", resource: "value2"}, + {__name__: "metric", resource: ""} + ] + }; + ctx.$httpBackend.expect('GET', /proxied\/api\/v1\/series\?match\[\]=metric&start=.*&end=.*/).respond(response); + var pm = new PrometheusMetricFindQuery(ctx.ds, 'label_values(metric, resource)', ctx.timeSrv); + pm.process().then(function(data) { results = data; }); + ctx.$httpBackend.flush(); + ctx.$rootScope.$apply(); + expect(results.length).to.be(2); + expect(results[0].text).to.be("value1"); + expect(results[1].text).to.be("value2"); + }); it('metrics(metric.*) should generate metric name query', function() { response = { status: "success", From 35232a77e648b3307b037d518dc2146b9c12dc4c Mon Sep 17 00:00:00 2001 From: bergquist Date: Tue, 5 Dec 2017 08:11:02 +0100 Subject: [PATCH 24/31] removes unused properties the dsType property caused some confusion about what datasource is beeing used. I just removed it since it not beeing used. closes #10072 --- pkg/services/alerting/extractor_test.go | 2 -- pkg/tsdb/influxdb/model_parser_test.go | 2 -- public/app/plugins/datasource/elasticsearch/query_builder.ts | 1 - public/app/plugins/datasource/influxdb/influx_query.ts | 1 - 4 files changed, 6 deletions(-) diff --git a/pkg/services/alerting/extractor_test.go b/pkg/services/alerting/extractor_test.go index b7f83404452..68054fab5ef 100644 --- a/pkg/services/alerting/extractor_test.go +++ b/pkg/services/alerting/extractor_test.go @@ -366,7 +366,6 @@ func TestAlertRuleExtraction(t *testing.T) { "steppedLine": false, "targets": [ { - "dsType": "influxdb", "groupBy": [ { "params": [ @@ -411,7 +410,6 @@ func TestAlertRuleExtraction(t *testing.T) { "tags": [] }, { - "dsType": "influxdb", "groupBy": [ { "params": [ diff --git a/pkg/tsdb/influxdb/model_parser_test.go b/pkg/tsdb/influxdb/model_parser_test.go index f8759afd3ba..7be9cae9702 100644 --- a/pkg/tsdb/influxdb/model_parser_test.go +++ b/pkg/tsdb/influxdb/model_parser_test.go @@ -20,7 +20,6 @@ func TestInfluxdbQueryParser(t *testing.T) { Convey("can parse influxdb json model", func() { json := ` { - "dsType": "influxdb", "groupBy": [ { "params": [ @@ -123,7 +122,6 @@ func TestInfluxdbQueryParser(t *testing.T) { Convey("can part raw query json model", func() { json := ` { - "dsType": "influxdb", "groupBy": [ { "params": [ diff --git a/public/app/plugins/datasource/elasticsearch/query_builder.ts b/public/app/plugins/datasource/elasticsearch/query_builder.ts index 754c541b2a8..a872d182930 100644 --- a/public/app/plugins/datasource/elasticsearch/query_builder.ts +++ b/public/app/plugins/datasource/elasticsearch/query_builder.ts @@ -172,7 +172,6 @@ export class ElasticQueryBuilder { build(target, adhocFilters?, queryString?) { // make sure query has defaults; target.metrics = target.metrics || [{ type: 'count', id: '1' }]; - target.dsType = 'elasticsearch'; target.bucketAggs = target.bucketAggs || [{type: 'date_histogram', id: '2', settings: {interval: 'auto'}}]; target.timeField = this.timeField; diff --git a/public/app/plugins/datasource/influxdb/influx_query.ts b/public/app/plugins/datasource/influxdb/influx_query.ts index 1b8dcf4cf3d..56635d775fb 100644 --- a/public/app/plugins/datasource/influxdb/influx_query.ts +++ b/public/app/plugins/datasource/influxdb/influx_query.ts @@ -19,7 +19,6 @@ export default class InfluxQuery { this.scopedVars = scopedVars; target.policy = target.policy || 'default'; - target.dsType = 'influxdb'; target.resultFormat = target.resultFormat || 'time_series'; target.orderByTime = target.orderByTime || 'ASC'; target.tags = target.tags || []; From bbc8aa05250d0be88b298e35c89453bf1ea8a575 Mon Sep 17 00:00:00 2001 From: bergquist Date: Tue, 5 Dec 2017 18:44:31 +0100 Subject: [PATCH 25/31] docs: link from cfg page to provisioning --- docs/sources/administration/provisioning.md | 2 +- docs/sources/installation/configuration.md | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/sources/administration/provisioning.md b/docs/sources/administration/provisioning.md index 119044da6cf..0745794496f 100644 --- a/docs/sources/administration/provisioning.md +++ b/docs/sources/administration/provisioning.md @@ -72,7 +72,7 @@ Saltstack | [https://github.com/salt-formulas/salt-formula-grafana](https://gith ## Datasources -> This feature is available from v4.7 +> This feature is available from v5.0 It's possible to manage datasources in Grafana by adding one or more yaml config files in the [`conf/datasources`](/installation/configuration/#datasources) directory. Each config file can contain a list of `datasources` that will be added or updated during start up. If the datasource already exists, Grafana will update it to match the configuration file. The config file can also contain a list of datasources that should be deleted. That list is called `delete_datasources`. Grafana will delete datasources listed in `delete_datasources` before inserting/updating those in the `datasource` list. diff --git a/docs/sources/installation/configuration.md b/docs/sources/installation/configuration.md index 483774f94f5..d454455a26b 100644 --- a/docs/sources/installation/configuration.md +++ b/docs/sources/installation/configuration.md @@ -93,7 +93,10 @@ Directory where grafana will automatically scan and look for plugins ### datasources -Config files containing datasources that will be configured at startup +> This feature is available in 5.0+ + +Config files containing datasources that will be configured at startup. +You can read more about the config files at the [provisioning page](/administration/provisioning/#datasources). ## [server] From 3aa1cb012a8b8f9e3cb1d28e9a52ef491654d916 Mon Sep 17 00:00:00 2001 From: Patrick O'Carroll Date: Wed, 6 Dec 2017 12:13:17 +0100 Subject: [PATCH 26/31] added tooltip, fixes #10092 (#10097) * added tooltip, fixes #10092 * fixed code formatting --- .../prometheus/partials/query.editor.html | 109 +++++++++--------- 1 file changed, 53 insertions(+), 56 deletions(-) diff --git a/public/app/plugins/datasource/prometheus/partials/query.editor.html b/public/app/plugins/datasource/prometheus/partials/query.editor.html index 98fd01eee15..8d6e89c3406 100644 --- a/public/app/plugins/datasource/prometheus/partials/query.editor.html +++ b/public/app/plugins/datasource/prometheus/partials/query.editor.html @@ -1,63 +1,60 @@ -
-
- - -
-
+
+
+ + +
+
-
-
- - - -
+
+
+ + + + + Controls the name of the time series, using name or pattern. For example {{hostname}} will be replaced with label value for + the label hostname. + +
-
- - - - Leave blank for auto handling based on time range and panel width - -
+
+ + + + Leave blank for auto handling based on time range and panel width + +
-
- -
- -
-
- -
- -
- -
- - - -
- -
-
-
-
+
+ +
+ +
+
+
+ +
+ +
+ + + +
+
+
+
+
From 48d9d0d356eb4dafa0673ae4866d6456b3960e53 Mon Sep 17 00:00:00 2001 From: bergquist Date: Wed, 6 Dec 2017 13:51:19 +0100 Subject: [PATCH 27/31] prom: enable min interval per panel This commit makes it possible to set min interval per panel. Overrides the value configured on the datasource. ref #9705 --- public/app/plugins/datasource/prometheus/plugin.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/public/app/plugins/datasource/prometheus/plugin.json b/public/app/plugins/datasource/prometheus/plugin.json index cb1a024a1d9..aa48a077b50 100644 --- a/public/app/plugins/datasource/prometheus/plugin.json +++ b/public/app/plugins/datasource/prometheus/plugin.json @@ -13,6 +13,10 @@ "alerting": true, "annotations": true, + "queryOptions": { + "minInterval": true + }, + "info": { "author": { "name": "Grafana Project", From 373389c920bf3eacd13fad7ff617aa8b75613c34 Mon Sep 17 00:00:00 2001 From: Sven Klemm <31455525+svenklemm@users.noreply.github.com> Date: Wed, 6 Dec 2017 18:04:33 +0100 Subject: [PATCH 28/31] treat any text column in timeseries query as metric name unless column (#9985) named metric is present --- pkg/tsdb/postgres/postgres.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/pkg/tsdb/postgres/postgres.go b/pkg/tsdb/postgres/postgres.go index dcb60977edc..56d3fcc9460 100644 --- a/pkg/tsdb/postgres/postgres.go +++ b/pkg/tsdb/postgres/postgres.go @@ -142,8 +142,13 @@ func (e PostgresQueryEndpoint) getTypedRowData(rows *core.Rows) (tsdb.RowValues, func (e PostgresQueryEndpoint) transformToTimeSeries(query *tsdb.Query, rows *core.Rows, result *tsdb.QueryResult) error { pointsBySeries := make(map[string]*tsdb.TimeSeries) seriesByQueryOrder := list.New() - columnNames, err := rows.Columns() + columnNames, err := rows.Columns() + if err != nil { + return err + } + + columnTypes, err := rows.ColumnTypes() if err != nil { return err } @@ -153,13 +158,21 @@ func (e PostgresQueryEndpoint) transformToTimeSeries(query *tsdb.Query, rows *co timeIndex := -1 metricIndex := -1 - // check columns of resultset + // check columns of resultset: a column named time is mandatory + // the first text column is treated as metric name unless a column named metric is present for i, col := range columnNames { switch col { case "time": timeIndex = i case "metric": metricIndex = i + default: + if metricIndex == -1 { + switch columnTypes[i].DatabaseTypeName() { + case "UNKNOWN", "TEXT", "VARCHAR", "CHAR": + metricIndex = i + } + } } } From c80eadcdf4a4e7ae6d10f188b9591844d8b9d47b Mon Sep 17 00:00:00 2001 From: Sven Klemm <31455525+svenklemm@users.noreply.github.com> Date: Wed, 6 Dec 2017 18:12:24 +0100 Subject: [PATCH 29/31] handle native postgres datetime types in annotation queries (#9986) --- pkg/tsdb/postgres/postgres.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pkg/tsdb/postgres/postgres.go b/pkg/tsdb/postgres/postgres.go index 56d3fcc9460..a8c96d8119c 100644 --- a/pkg/tsdb/postgres/postgres.go +++ b/pkg/tsdb/postgres/postgres.go @@ -78,6 +78,15 @@ func (e PostgresQueryEndpoint) transformToTable(query *tsdb.Query, rows *core.Ro rowLimit := 1000000 rowCount := 0 + timeIndex := -1 + + // check if there is a column named time + for i, col := range columnNames { + switch col { + case "time": + timeIndex = i + } + } for ; rows.Next(); rowCount++ { if rowCount > rowLimit { @@ -89,6 +98,15 @@ func (e PostgresQueryEndpoint) transformToTable(query *tsdb.Query, rows *core.Ro return err } + // convert column named time to unix timestamp to make + // native datetime postgres types work in annotation queries + if timeIndex != -1 { + switch value := values[timeIndex].(type) { + case time.Time: + values[timeIndex] = float64(value.UnixNano() / 1e9) + } + } + table.Rows = append(table.Rows, values) } From b44c5994100b7a285879c6a2586cd77113cc7207 Mon Sep 17 00:00:00 2001 From: Sven Klemm <31455525+svenklemm@users.noreply.github.com> Date: Thu, 7 Dec 2017 10:05:04 +0100 Subject: [PATCH 30/31] postgres: pass timerange for template variable queries (#10069) * pass timerange for template queries when refresh is set to timerange change * document on time range change refresh mode for template queries --- docs/sources/features/datasources/postgres.md | 6 ++++++ .../app/plugins/datasource/postgres/datasource.ts | 15 ++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/docs/sources/features/datasources/postgres.md b/docs/sources/features/datasources/postgres.md index 2b111d51f0e..e9d65b8f327 100644 --- a/docs/sources/features/datasources/postgres.md +++ b/docs/sources/features/datasources/postgres.md @@ -139,6 +139,12 @@ A query can return multiple columns and Grafana will automatically create a list SELECT host.hostname, other_host.hostname2 FROM host JOIN other_host ON host.city = other_host.city ``` +To use time range dependent macros like `$__timeFilter(column)` in your query the refresh mode of the template variable needs to be set to *On Time Range Change*. + +```sql +SELECT event_name FROM event_log WHERE $__timeFilter(time_column) +``` + Another option is a query that can create a key/value variable. The query should return two columns that are named `__text` and `__value`. The `__text` column value should be unique (if it is not unique then the first value is used). The options in the dropdown will have a text and value that allows you to have a friendly name as text and an id as the value. An example query with `hostname` as the text and `id` as the value: ```sql diff --git a/public/app/plugins/datasource/postgres/datasource.ts b/public/app/plugins/datasource/postgres/datasource.ts index af3d83f50d8..82354dd4bc6 100644 --- a/public/app/plugins/datasource/postgres/datasource.ts +++ b/public/app/plugins/datasource/postgres/datasource.ts @@ -99,12 +99,21 @@ export class PostgresDatasource { format: 'table', }; + var data = { + queries: [interpolatedQuery], + }; + + if (optionalOptions && optionalOptions.range && optionalOptions.range.from) { + data['from'] = optionalOptions.range.from.valueOf().toString(); + } + if (optionalOptions && optionalOptions.range && optionalOptions.range.to) { + data['to'] = optionalOptions.range.to.valueOf().toString(); + } + return this.backendSrv.datasourceRequest({ url: '/api/tsdb/query', method: 'POST', - data: { - queries: [interpolatedQuery], - } + data: data }) .then(data => this.responseParser.parseMetricFindQueryResult(refId, data)); } From a62ebb3e590cee02297997977b751a5929f8a496 Mon Sep 17 00:00:00 2001 From: Sven Klemm <31455525+svenklemm@users.noreply.github.com> Date: Thu, 7 Dec 2017 11:18:36 +0100 Subject: [PATCH 31/31] mysql: pass timerange for template variable queries (#10071) * mysql: pass timerange for template variable queries * mysql: document time range macro usage in template variables * mysql: docs for on time range change refresh mode for template queries * Revert "mysql: docs for on time range change refresh mode for template queries" This reverts commit 5325972aa4f66257aa20f7ae6d4de8fa8fe628b6. --- docs/sources/features/datasources/mysql.md | 6 ++++++ public/app/plugins/datasource/mysql/datasource.ts | 15 ++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/docs/sources/features/datasources/mysql.md b/docs/sources/features/datasources/mysql.md index 69c6f667062..d9f048e0371 100644 --- a/docs/sources/features/datasources/mysql.md +++ b/docs/sources/features/datasources/mysql.md @@ -127,6 +127,12 @@ A query can returns multiple columns and Grafana will automatically create a lis SELECT my_host.hostname, my_other_host.hostname2 FROM my_host JOIN my_other_host ON my_host.city = my_other_host.city ``` +To use time range dependent macros like `$__timeFilter(column)` in your query the refresh mode of the template variable needs to be set to *On Time Range Change*. + +```sql +SELECT event_name FROM event_log WHERE $__timeFilter(time_column) +``` + Another option is a query that can create a key/value variable. The query should return two columns that are named `__text` and `__value`. The `__text` column value should be unique (if it is not unique then the first value is used). The options in the dropdown will have a text and value that allows you to have a friendly name as text and an id as the value. An example query with `hostname` as the text and `id` as the value: ```sql diff --git a/public/app/plugins/datasource/mysql/datasource.ts b/public/app/plugins/datasource/mysql/datasource.ts index ac5ccfeb5ca..5a8d3b236c0 100644 --- a/public/app/plugins/datasource/mysql/datasource.ts +++ b/public/app/plugins/datasource/mysql/datasource.ts @@ -103,12 +103,21 @@ export class MysqlDatasource { format: 'table', }; + var data = { + queries: [interpolatedQuery], + }; + + if (optionalOptions && optionalOptions.range && optionalOptions.range.from) { + data['from'] = optionalOptions.range.from.valueOf().toString(); + } + if (optionalOptions && optionalOptions.range && optionalOptions.range.to) { + data['to'] = optionalOptions.range.to.valueOf().toString(); + } + return this.backendSrv.datasourceRequest({ url: '/api/tsdb/query', method: 'POST', - data: { - queries: [interpolatedQuery], - } + data: data }) .then(data => this.responseParser.parseMetricFindQueryResult(refId, data)); }