From f8b05e0f42f6274a0539b46f8d4531d6ada46784 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Fri, 2 Oct 2015 03:19:25 +0900 Subject: [PATCH 01/57] add prometheus annotation query --- .../datasource/prometheus/datasource.ts | 67 +++++++++++++++++-- .../plugins/datasource/prometheus/module.ts | 7 +- .../partials/annotations.editor.html | 28 ++++++++ .../plugins/datasource/prometheus/plugin.json | 3 +- .../prometheus/specs/datasource_specs.ts | 35 ++++++++++ 5 files changed, 132 insertions(+), 8 deletions(-) create mode 100644 public/app/plugins/datasource/prometheus/partials/annotations.editor.html diff --git a/public/app/plugins/datasource/prometheus/datasource.ts b/public/app/plugins/datasource/prometheus/datasource.ts index 0a81e04831b..4aff842d38b 100644 --- a/public/app/plugins/datasource/prometheus/datasource.ts +++ b/public/app/plugins/datasource/prometheus/datasource.ts @@ -188,6 +188,58 @@ export function PrometheusDatasource(instanceSettings, $q, backendSrv, templateS } }; + this.annotationQuery = function(options) { + var annotation = options.annotation; + var expr = annotation.expr || ''; + var tagKeys = annotation.tagKeys || ''; + var titleFormat = annotation.titleFormat || ''; + var textFormat = annotation.textFormat || ''; + + if (!expr) { return $q.when([]); } + + var interpolated; + try { + interpolated = templateSrv.replace(expr); + } + catch (err) { + return $q.reject(err); + } + + var query = { + expr: interpolated, + step: '60s' + }; + var start = getPrometheusTime(options.range.from, false); + var end = getPrometheusTime(options.range.to, true); + return this.performTimeSeriesQuery(query, start, end).then(function(results) { + var eventList = []; + tagKeys = tagKeys.split(','); + + _.each(results.data.data.result, function(series) { + var tags = _.chain(series.metric) + .filter(function(v, k) { + return _.contains(tagKeys, k); + }).value(); + + _.each(series.values, function(value) { + if (value[1] === '1') { + var event = { + annotation: annotation, + time: Math.floor(value[0]) * 1000, + title: renderTemplate(titleFormat, series.metric), + tags: tags, + text: renderTemplate(textFormat, series.metric) + }; + + eventList.push(event); + } + }); + }); + + return eventList; + }); + }; + this.testDatasource = function() { return this.metricFindQuery('metrics(.*)').then(function() { return { status: 'success', message: 'Data source is working', title: 'Success' }; @@ -240,22 +292,25 @@ export function PrometheusDatasource(instanceSettings, $q, backendSrv, templateS return getOriginalMetricName(labelData); } - var originalSettings = _.templateSettings; + return renderTemplate(options.legendFormat, labelData) || '{}'; + } + + function renderTemplate(format, data) { _.templateSettings = { interpolate: /\{\{(.+?)\}\}/g }; - var template = _.template(templateSrv.replace(options.legendFormat)); - var metricName; + var template = _.template(templateSrv.replace(format)); + var result; try { - metricName = template(labelData); + result = template(data); } catch (e) { - metricName = '{}'; + result = null; } _.templateSettings = originalSettings; - return metricName; + return result; } function getOriginalMetricName(labelData) { diff --git a/public/app/plugins/datasource/prometheus/module.ts b/public/app/plugins/datasource/prometheus/module.ts index 9af37384b4f..0ddba422bcc 100644 --- a/public/app/plugins/datasource/prometheus/module.ts +++ b/public/app/plugins/datasource/prometheus/module.ts @@ -5,8 +5,13 @@ class PrometheusConfigCtrl { static templateUrl = 'public/app/plugins/datasource/prometheus/partials/config.html'; } +class PrometheusAnnotationsQueryCtrl { + static templateUrl = 'public/app/plugins/datasource/prometheus/partials/annotations.editor.html'; +} + export { PrometheusDatasource as Datasource, PrometheusQueryCtrl as QueryCtrl, - PrometheusConfigCtrl as ConfigCtrl + PrometheusConfigCtrl as ConfigCtrl, + PrometheusAnnotationsQueryCtrl as AnnotationsQueryCtrl, }; diff --git a/public/app/plugins/datasource/prometheus/partials/annotations.editor.html b/public/app/plugins/datasource/prometheus/partials/annotations.editor.html new file mode 100644 index 00000000000..d8110b03c52 --- /dev/null +++ b/public/app/plugins/datasource/prometheus/partials/annotations.editor.html @@ -0,0 +1,28 @@ +
+
+
Search expression
+
+ +
+
+
+ +
+
+
Field formats
+
+ + +
+ +
+ + +
+ +
+ + +
+
+
diff --git a/public/app/plugins/datasource/prometheus/plugin.json b/public/app/plugins/datasource/prometheus/plugin.json index 4cd55605816..66dd9145e6a 100644 --- a/public/app/plugins/datasource/prometheus/plugin.json +++ b/public/app/plugins/datasource/prometheus/plugin.json @@ -3,5 +3,6 @@ "name": "Prometheus", "id": "prometheus", - "metrics": true + "metrics": true, + "annotations": true } diff --git a/public/app/plugins/datasource/prometheus/specs/datasource_specs.ts b/public/app/plugins/datasource/prometheus/specs/datasource_specs.ts index fc3d2f489de..043546a9398 100644 --- a/public/app/plugins/datasource/prometheus/specs/datasource_specs.ts +++ b/public/app/plugins/datasource/prometheus/specs/datasource_specs.ts @@ -157,4 +157,39 @@ describe('PrometheusDatasource', function() { expect(results.length).to.be(3); }); }); + describe('When performing annotationQuery', function() { + var results; + var urlExpected = 'proxied/api/v1/query_range?query=' + + encodeURIComponent('ALERTS{alertstate="firing"}') + + '&start=1443438675&end=1443460275&step=60s'; + var annotation = { + expr: 'ALERTS{alertstate="firing"}', + tagKeys: 'job', + titleFormat: '{{alertname}}', + textFormat: '{{instance}}' + }; + var response = { + status: "success", + data: { + resultType: "matrix", + result: [{ + metric: {"__name__": "ALERTS", alertname: "InstanceDown", alertstate: "firing", instance: "testinstance", job: "testjob"}, + values: [[1443454528, "1"]] + }] + } + }; + beforeEach(function() { + ctx.$httpBackend.expect('GET', urlExpected).respond(response); + ctx.ds.annotationQuery(annotation, {from: moment(1443438674760), to: moment(1443460274760)}).then(function(data) { results = data; }); + ctx.$httpBackend.flush(); + }); + it('should return annotation list', function() { + ctx.$rootScope.$apply(); + expect(results.length).to.be(1); + expect(results[0].tags).to.contain('testjob'); + expect(results[0].title).to.be('InstanceDown'); + expect(results[0].text).to.be('testinstance'); + expect(results[0].time).to.be(1443454528 * 1000); + }); + }); }); From ee84d4371b4d78c67b2eb197e8a856561b6ab18d Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Fri, 13 Nov 2015 02:33:21 +0900 Subject: [PATCH 02/57] fix prometheus annotation, reflect API change --- .../prometheus/specs/datasource_specs.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/public/app/plugins/datasource/prometheus/specs/datasource_specs.ts b/public/app/plugins/datasource/prometheus/specs/datasource_specs.ts index 043546a9398..4a1b4121dba 100644 --- a/public/app/plugins/datasource/prometheus/specs/datasource_specs.ts +++ b/public/app/plugins/datasource/prometheus/specs/datasource_specs.ts @@ -162,11 +162,17 @@ describe('PrometheusDatasource', function() { var urlExpected = 'proxied/api/v1/query_range?query=' + encodeURIComponent('ALERTS{alertstate="firing"}') + '&start=1443438675&end=1443460275&step=60s'; - var annotation = { - expr: 'ALERTS{alertstate="firing"}', - tagKeys: 'job', - titleFormat: '{{alertname}}', - textFormat: '{{instance}}' + var options = { + annotation: { + expr: 'ALERTS{alertstate="firing"}', + tagKeys: 'job', + titleFormat: '{{alertname}}', + textFormat: '{{instance}}' + }, + range: { + from: moment(1443438674760), + to: moment(1443460274760) + } }; var response = { status: "success", @@ -180,7 +186,7 @@ describe('PrometheusDatasource', function() { }; beforeEach(function() { ctx.$httpBackend.expect('GET', urlExpected).respond(response); - ctx.ds.annotationQuery(annotation, {from: moment(1443438674760), to: moment(1443460274760)}).then(function(data) { results = data; }); + ctx.ds.annotationQuery(options).then(function(data) { results = data; }); ctx.$httpBackend.flush(); }); it('should return annotation list', function() { From 7a1326ff142b880c617c0199323202187965eeb6 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Fri, 15 Jan 2016 11:00:09 +0900 Subject: [PATCH 03/57] follow new plugin format --- .../prometheus/partials/annotations.editor.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/public/app/plugins/datasource/prometheus/partials/annotations.editor.html b/public/app/plugins/datasource/prometheus/partials/annotations.editor.html index d8110b03c52..2612c611849 100644 --- a/public/app/plugins/datasource/prometheus/partials/annotations.editor.html +++ b/public/app/plugins/datasource/prometheus/partials/annotations.editor.html @@ -2,7 +2,7 @@
Search expression
- +
@@ -12,17 +12,17 @@
Field formats
- +
- +
- +
From 7d97f381cf33407f364944c0f175299a8a190bb5 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Thu, 4 Feb 2016 14:09:59 +0900 Subject: [PATCH 04/57] fix tslint error --- public/app/plugins/datasource/prometheus/datasource.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/public/app/plugins/datasource/prometheus/datasource.ts b/public/app/plugins/datasource/prometheus/datasource.ts index 4aff842d38b..804115e849b 100644 --- a/public/app/plugins/datasource/prometheus/datasource.ts +++ b/public/app/plugins/datasource/prometheus/datasource.ts @@ -200,8 +200,7 @@ export function PrometheusDatasource(instanceSettings, $q, backendSrv, templateS var interpolated; try { interpolated = templateSrv.replace(expr); - } - catch (err) { + } catch (err) { return $q.reject(err); } From 634699c8e2c0520729234a274858a1d0d8fe21b9 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Thu, 4 Feb 2016 14:10:27 +0900 Subject: [PATCH 05/57] fix prometheus datasource plugin --- public/app/plugins/datasource/prometheus/datasource.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/public/app/plugins/datasource/prometheus/datasource.ts b/public/app/plugins/datasource/prometheus/datasource.ts index 804115e849b..4cfd174978c 100644 --- a/public/app/plugins/datasource/prometheus/datasource.ts +++ b/public/app/plugins/datasource/prometheus/datasource.ts @@ -295,6 +295,7 @@ export function PrometheusDatasource(instanceSettings, $q, backendSrv, templateS } function renderTemplate(format, data) { + var originalSettings = _.templateSettings; _.templateSettings = { interpolate: /\{\{(.+?)\}\}/g }; From 20283a46f9bd8fbc4614f3f47a2dd9175f24dad6 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Thu, 4 Feb 2016 14:14:19 +0900 Subject: [PATCH 06/57] fix annotation editor error --- .../prometheus/partials/annotations.editor.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/public/app/plugins/datasource/prometheus/partials/annotations.editor.html b/public/app/plugins/datasource/prometheus/partials/annotations.editor.html index 2612c611849..ffeb7d6deea 100644 --- a/public/app/plugins/datasource/prometheus/partials/annotations.editor.html +++ b/public/app/plugins/datasource/prometheus/partials/annotations.editor.html @@ -2,7 +2,7 @@
Search expression
- +
@@ -12,17 +12,17 @@
Field formats
- +
- +
- +
From 15fb56e607d7faa9173920c568be6338118a36ff Mon Sep 17 00:00:00 2001 From: Kevin Pike Date: Thu, 4 Feb 2016 13:46:02 -0800 Subject: [PATCH 07/57] Add github api_url to github auth docs --- docs/sources/installation/configuration.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/sources/installation/configuration.md b/docs/sources/installation/configuration.md index 247cfbb0d19..b652abcabb6 100644 --- a/docs/sources/installation/configuration.md +++ b/docs/sources/installation/configuration.md @@ -268,6 +268,7 @@ example: scopes = user:email auth_url = https://github.com/login/oauth/authorize token_url = https://github.com/login/oauth/access_token + api_url = https://api.github.com allow_sign_up = false team_ids = From aa8bd044c5410cc857ca553ef6e4c46156217592 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Fri, 5 Feb 2016 11:05:47 +0100 Subject: [PATCH 08/57] fix(): various fixes to snapshots --- .../features/dashboard/dashnav/dashnav.html | 4 +- public/app/features/panel/panel_directive.ts | 51 ++++++++++++++++++- public/app/plugins/panel/singlestat/module.ts | 10 ++-- public/less/navbar.less | 23 +++------ 4 files changed, 64 insertions(+), 24 deletions(-) diff --git a/public/app/features/dashboard/dashnav/dashnav.html b/public/app/features/dashboard/dashnav/dashnav.html index 89f9f301729..3edafc1f96f 100644 --- a/public/app/features/dashboard/dashnav/dashnav.html +++ b/public/app/features/dashboard/dashnav/dashnav.html @@ -8,8 +8,8 @@ -
- +
+ {{dashboard.title}} diff --git a/public/app/features/panel/panel_directive.ts b/public/app/features/panel/panel_directive.ts index 757f9f8e43d..2497732928b 100644 --- a/public/app/features/panel/panel_directive.ts +++ b/public/app/features/panel/panel_directive.ts @@ -5,10 +5,59 @@ import $ from 'jquery'; var module = angular.module('grafana.directives'); +var panelTemplate = ` +
+
+ + + + + + + + + + +
+
+ +
+ +
+ +
+ +
+
+
+
+ + {{ctrl.name}} +
+ +
+
+
+
+ + +
+ +
+
+ +
+
+
+
+`; + module.directive('grafanaPanel', function() { return { restrict: 'E', - templateUrl: 'public/app/features/panel/partials/panel.html', + template: panelTemplate, transclude: true, scope: { ctrl: "=" }, link: function(scope, elem) { diff --git a/public/app/plugins/panel/singlestat/module.ts b/public/app/plugins/panel/singlestat/module.ts index 24d6af46c26..b161cd1d8ed 100644 --- a/public/app/plugins/panel/singlestat/module.ts +++ b/public/app/plugins/panel/singlestat/module.ts @@ -59,7 +59,7 @@ class SingleStatCtrl extends MetricsPanelCtrl { super.initEditMode(); this.icon = "fa fa-dashboard"; this.fontSizes = ['20%', '30%','50%','70%','80%','100%', '110%', '120%', '150%', '170%', '200%']; - this.addEditorTab('Options', 'app/plugins/panel/singlestat/editor.html', 2); + this.addEditorTab('Options', 'public/app/plugins/panel/singlestat/editor.html', 2); this.unitFormats = kbn.getUnitFormats(); } @@ -172,11 +172,11 @@ class SingleStatCtrl extends MetricsPanelCtrl { data.flotpairs = []; if (this.series.length > 1) { - this.inspector.error = new Error(); - this.inspector.error.message = 'Multiple Series Error'; - this.inspector.error.data = 'Metric query returns ' + this.series.length + + var error: any = new Error(); + error.message = 'Multiple Series Error'; + error.data = 'Metric query returns ' + this.series.length + ' series. Single Stat Panel expects a single series.\n\nResponse:\n'+JSON.stringify(this.series); - throw this.inspector.error; + throw error; } if (this.series && this.series.length > 0) { diff --git a/public/less/navbar.less b/public/less/navbar.less index 19c6b7d9a75..8dd78e95b14 100644 --- a/public/less/navbar.less +++ b/public/less/navbar.less @@ -83,6 +83,13 @@ position: relative; top: 2px; } + + .icon-gf { + position: relative; + top: 5px; + font-size: 27px; + line-height: 8px; + } } .dashboard-title { @@ -114,20 +121,4 @@ color: @linkColor; } -.top-nav-snapshot-title { - .gf-icon { - position: relative; - top: 3px; - font-size: 27px; - } - a { - display: inline-block; - padding: 0px 15px 5px 10px; - } - display: block; - float: left; - font-size: 1.4em; - margin: 9px 18px 5px 14px; - color: @linkColor; -} From 0fab210ad2a6688bc58c23b3cc5c97266f2929ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Fri, 5 Feb 2016 12:13:59 +0100 Subject: [PATCH 09/57] feat(apps): changed edit apps view to use plugin-component for apps config view --- .../app/core/directives/plugin_component.ts | 11 +++++++++ public/app/features/apps/all.ts | 1 - public/app/features/apps/config_view.ts | 23 ------------------- public/app/features/apps/partials/edit.html | 2 +- .../app/features/panel/metrics_panel_ctrl.ts | 4 ++-- 5 files changed, 14 insertions(+), 27 deletions(-) delete mode 100644 public/app/features/apps/config_view.ts diff --git a/public/app/core/directives/plugin_component.ts b/public/app/core/directives/plugin_component.ts index 94e50bf5c86..21900ce94ed 100644 --- a/public/app/core/directives/plugin_component.ts +++ b/public/app/core/directives/plugin_component.ts @@ -141,6 +141,17 @@ function pluginDirectiveLoader($compile, datasourceSrv, $rootScope, $q, $http, $ }; }); } + // AppConfigCtrl + case 'app-config-ctrl': { + return System.import(scope.ctrl.appModel.module).then(function(appModule) { + return { + name: 'app-config-' + scope.ctrl.appModel.appId, + bindings: {appModel: "=", appEditCtrl: "="}, + attrs: {"app-model": "ctrl.appModel", "app-edit-ctrl": "ctrl"}, + Component: appModule.ConfigCtrl, + }; + }); + } // Panel case 'panel': { return loadPanelComponentInfo(scope, attrs); diff --git a/public/app/features/apps/all.ts b/public/app/features/apps/all.ts index 6f15e8b1bf6..fcdd27dff4d 100644 --- a/public/app/features/apps/all.ts +++ b/public/app/features/apps/all.ts @@ -1,3 +1,2 @@ import './edit_ctrl'; import './list_ctrl'; -import './config_view'; diff --git a/public/app/features/apps/config_view.ts b/public/app/features/apps/config_view.ts deleted file mode 100644 index 31e85967cb2..00000000000 --- a/public/app/features/apps/config_view.ts +++ /dev/null @@ -1,23 +0,0 @@ -/// - -import angular from 'angular'; - -/** @ngInject */ -function appConfigView(dynamicDirectiveSrv) { - return dynamicDirectiveSrv.create({ - scope: { - appModel: "=" - }, - directive: scope => { - return System.import(scope.appModel.module).then(function(appModule) { - return { - name: 'app-config-' + scope.appModel.appId, - fn: appModule.configView, - }; - }); - }, - }); -} - - -angular.module('grafana.directives').directive('appConfigView', appConfigView); diff --git a/public/app/features/apps/partials/edit.html b/public/app/features/apps/partials/edit.html index 20df40bd247..efc5f93c738 100644 --- a/public/app/features/apps/partials/edit.html +++ b/public/app/features/apps/partials/edit.html @@ -97,7 +97,7 @@

Configuration:

- +
diff --git a/public/app/features/panel/metrics_panel_ctrl.ts b/public/app/features/panel/metrics_panel_ctrl.ts index 1e6f34775f5..2c25aa6eca5 100644 --- a/public/app/features/panel/metrics_panel_ctrl.ts +++ b/public/app/features/panel/metrics_panel_ctrl.ts @@ -6,8 +6,8 @@ import _ from 'lodash'; import kbn from 'app/core/utils/kbn'; import {PanelCtrl} from './panel_ctrl'; -import * as rangeUtil from '../../core/utils/rangeutil'; -import * as dateMath from '../../core/utils/datemath'; +import * as rangeUtil from 'app/core/utils/rangeutil'; +import * as dateMath from 'app/core/utils/datemath'; class MetricsPanelCtrl extends PanelCtrl { error: boolean; From 853cd1633642ab51e777c17e894cd51774dd6dbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Fri, 5 Feb 2016 13:48:10 +0100 Subject: [PATCH 10/57] fix(search); fixes to dashboard search (using keyboard), and fix for singlestat in snapshot view --- public/app/core/components/grafana_app.ts | 8 ++- public/app/core/components/search/search.html | 7 +-- public/app/core/components/search/search.ts | 30 ++++++++--- public/app/features/dashboard/all.js | 1 - .../dashboard/directives/dashSearchView.js | 54 ------------------- public/app/partials/dashboard.html | 2 +- public/app/plugins/panel/singlestat/module.ts | 22 +++----- public/less/grafana.less | 5 ++ public/views/index.html | 2 +- 9 files changed, 47 insertions(+), 84 deletions(-) delete mode 100644 public/app/features/dashboard/directives/dashSearchView.js diff --git a/public/app/core/components/grafana_app.ts b/public/app/core/components/grafana_app.ts index 9b627e930a0..1dd1661aff0 100644 --- a/public/app/core/components/grafana_app.ts +++ b/public/app/core/components/grafana_app.ts @@ -187,13 +187,17 @@ export function grafanaAppDirective(playlistSrv) { // hide search if (elem.find('.search-container').length > 0) { if (target.parents('.search-container').length === 0) { - scope.appEvent('hide-dash-search'); + scope.$apply(function() { + scope.appEvent('hide-dash-search'); + }); } } // hide sidemenu if (!ignoreSideMenuHide && !scope.contextSrv.pinned && elem.find('.sidemenu').length > 0) { if (target.parents('.sidemenu').length === 0) { - scope.$apply(() => scope.contextSrv.toggleSideMenu()); + scope.$apply(function() { + scope.contextSrv.toggleSideMenu(); + }); } } diff --git a/public/app/core/components/search/search.html b/public/app/core/components/search/search.html index 7a78f1a4a3e..35c4431d80c 100644 --- a/public/app/core/components/search/search.html +++ b/public/app/core/components/search/search.html @@ -1,3 +1,4 @@ +
diff --git a/public/app/core/components/search/search.ts b/public/app/core/components/search/search.ts index 3f8cb495e71..e296acf56e1 100644 --- a/public/app/core/components/search/search.ts +++ b/public/app/core/components/search/search.ts @@ -7,6 +7,7 @@ import $ from 'jquery'; import coreModule from '../../core_module'; export class SearchCtrl { + isOpen: boolean; query: any; giveSearchFocus: number; selectedIndex: number; @@ -15,16 +16,34 @@ export class SearchCtrl { tagsMode: boolean; showImport: boolean; dismiss: any; + ignoreClose: any; /** @ngInject */ - constructor(private $scope, private $location, private $timeout, private backendSrv, private contextSrv) { + constructor(private $scope, private $location, private $timeout, private backendSrv, private contextSrv, private $rootScope) { + $rootScope.onAppEvent('show-dash-search', this.openSearch.bind(this), $scope); + $rootScope.onAppEvent('hide-dash-search', this.closeSearch.bind(this), $scope); + } + + closeSearch() { + this.isOpen = this.ignoreClose; + } + + openSearch() { + if (this.isOpen) { + this.isOpen = false; + return; + } + + this.isOpen = true; this.giveSearchFocus = 0; this.selectedIndex = -1; this.results = []; this.query = { query: '', tag: [], starred: false }; this.currentSearchId = 0; + this.ignoreClose = true; - $timeout(() => { + this.$timeout(() => { + this.ignoreClose = false; this.giveSearchFocus = this.giveSearchFocus + 1; this.query.query = ''; this.search(); @@ -33,7 +52,7 @@ export class SearchCtrl { keyDown(evt) { if (evt.keyCode === 27) { - this.dismiss(); + this.closeSearch(); } if (evt.keyCode === 40) { this.moveSelection(1); @@ -141,10 +160,7 @@ export function searchDirective() { controller: SearchCtrl, bindToController: true, controllerAs: 'ctrl', - scope: { - dismiss: '&' - }, }; } -coreModule.directive('search', searchDirective); +coreModule.directive('dashboardSearch', searchDirective); diff --git a/public/app/features/dashboard/all.js b/public/app/features/dashboard/all.js index 9d7cd06019b..073ca2ae1d9 100644 --- a/public/app/features/dashboard/all.js +++ b/public/app/features/dashboard/all.js @@ -12,7 +12,6 @@ define([ './viewStateSrv', './timeSrv', './unsavedChangesSrv', - './directives/dashSearchView', './timepicker/timepicker', './graphiteImportCtrl', './dynamicDashboardSrv', diff --git a/public/app/features/dashboard/directives/dashSearchView.js b/public/app/features/dashboard/directives/dashSearchView.js deleted file mode 100644 index cee97fee758..00000000000 --- a/public/app/features/dashboard/directives/dashSearchView.js +++ /dev/null @@ -1,54 +0,0 @@ -define([ - 'angular', - 'jquery' -], -function (angular, $) { - 'use strict'; - - angular - .module('grafana.directives') - .directive('dashSearchView', function($compile) { - return { - restrict: 'A', - link: function(scope, elem) { - var editorScope; - var ignoreHide; - - function showSearch() { - if (editorScope) { - editorScope.dismiss(); - return; - } - - ignoreHide = true; - editorScope = scope.$new(); - editorScope.dismiss = function() { - editorScope.$destroy(); - elem.empty(); - elem.unbind(); - editorScope = null; - }; - - var view = $(''); - - elem.append(view); - $compile(elem.contents())(editorScope); - - setTimeout(function() { - ignoreHide = false; - }, 300); - } - - function hideSearch() { - if (editorScope && !ignoreHide) { - editorScope.dismiss(); - } - } - - scope.onAppEvent('show-dash-search', showSearch); - scope.onAppEvent('hide-dash-search', hideSearch); - } - }; - }); - -}); diff --git a/public/app/partials/dashboard.html b/public/app/partials/dashboard.html index d63c0d01e29..edba0d85bb9 100644 --- a/public/app/partials/dashboard.html +++ b/public/app/partials/dashboard.html @@ -4,7 +4,7 @@
-
+
diff --git a/public/app/plugins/panel/singlestat/module.ts b/public/app/plugins/panel/singlestat/module.ts index b161cd1d8ed..5786c6be6d2 100644 --- a/public/app/plugins/panel/singlestat/module.ts +++ b/public/app/plugins/panel/singlestat/module.ts @@ -79,7 +79,8 @@ class SingleStatCtrl extends MetricsPanelCtrl { } loadSnapshot(snapshotData) { - this.dataHandler(snapshotData); + // give element time to get attached and get dimensions + this.$timeout(() => this.dataHandler(snapshotData), 50); } dataHandler(results) { @@ -239,22 +240,13 @@ class SingleStatCtrl extends MetricsPanelCtrl { var $timeout = this.$timeout; var panel = ctrl.panel; var templateSrv = this.templateSrv; - var data, linkInfo, $panelContainer; - var firstRender = true; + var data, linkInfo; + var $panelContainer = elem.parents('.panel-container'); + // change elem to singlestat panel + elem = elem.find('.singlestat-panel'); + hookupDrilldownLinkTooltip(); scope.$on('render', function() { - if (firstRender) { - var inner = elem.find('.singlestat-panel'); - if (inner.length) { - elem = inner; - $panelContainer = elem.parents('.panel-container'); - firstRender = false; - hookupDrilldownLinkTooltip(); - } else { - return; - } - } - render(); ctrl.renderingCompleted(); }); diff --git a/public/less/grafana.less b/public/less/grafana.less index 88745f6a57b..d33db98376b 100644 --- a/public/less/grafana.less +++ b/public/less/grafana.less @@ -70,6 +70,11 @@ top: 20%; } +.grafana-app { + display: block; + min-height: 100%; +} + .histogram-chart { position:relative; } diff --git a/public/views/index.html b/public/views/index.html index 1d612e53385..40be796b306 100644 --- a/public/views/index.html +++ b/public/views/index.html @@ -26,7 +26,7 @@ - +
+
+

Default query settings

+
+
    +
  • + Group by time interval +
  • +
  • + +
  • +
  • + +
  • +
+
+
From 020277c04594bf751f5da876b82ac91927327c42 Mon Sep 17 00:00:00 2001 From: bergquist Date: Fri, 5 Feb 2016 15:10:55 +0100 Subject: [PATCH 13/57] style(panel): fix intendention issue --- .../app/features/panel/metrics_panel_ctrl.ts | 82 +++++++++---------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/public/app/features/panel/metrics_panel_ctrl.ts b/public/app/features/panel/metrics_panel_ctrl.ts index 2c25aa6eca5..537bdbbcbdb 100644 --- a/public/app/features/panel/metrics_panel_ctrl.ts +++ b/public/app/features/panel/metrics_panel_ctrl.ts @@ -111,49 +111,49 @@ class MetricsPanelCtrl extends PanelCtrl { var panelInterval = this.panel.interval; var datasourceInterval = (this.datasource || {}).interval; - this.interval = kbn.calculateInterval(this.range, this.resolution, panelInterval || datasourceInterval); - }; + this.interval = kbn.calculateInterval(this.range, this.resolution, panelInterval || datasourceInterval); + }; - applyPanelTimeOverrides() { + applyPanelTimeOverrides() { + this.timeInfo = ''; + + // check panel time overrrides + if (this.panel.timeFrom) { + var timeFromInfo = rangeUtil.describeTextRange(this.panel.timeFrom); + if (timeFromInfo.invalid) { + this.timeInfo = 'invalid time override'; + return; + } + + if (_.isString(this.rangeRaw.from)) { + var timeFromDate = dateMath.parse(timeFromInfo.from); + this.timeInfo = timeFromInfo.display; + this.rangeRaw.from = timeFromInfo.from; + this.rangeRaw.to = timeFromInfo.to; + this.range.from = timeFromDate; + this.range.to = dateMath.parse(timeFromInfo.to); + } + } + + if (this.panel.timeShift) { + var timeShiftInfo = rangeUtil.describeTextRange(this.panel.timeShift); + if (timeShiftInfo.invalid) { + this.timeInfo = 'invalid timeshift'; + return; + } + + var timeShift = '-' + this.panel.timeShift; + this.timeInfo += ' timeshift ' + timeShift; + this.range.from = dateMath.parseDateMath(timeShift, this.range.from, false); + this.range.to = dateMath.parseDateMath(timeShift, this.range.to, true); + + this.rangeRaw = this.range; + } + + if (this.panel.hideTimeOverride) { this.timeInfo = ''; - - // check panel time overrrides - if (this.panel.timeFrom) { - var timeFromInfo = rangeUtil.describeTextRange(this.panel.timeFrom); - if (timeFromInfo.invalid) { - this.timeInfo = 'invalid time override'; - return; - } - - if (_.isString(this.rangeRaw.from)) { - var timeFromDate = dateMath.parse(timeFromInfo.from); - this.timeInfo = timeFromInfo.display; - this.rangeRaw.from = timeFromInfo.from; - this.rangeRaw.to = timeFromInfo.to; - this.range.from = timeFromDate; - this.range.to = dateMath.parse(timeFromInfo.to); - } - } - - if (this.panel.timeShift) { - var timeShiftInfo = rangeUtil.describeTextRange(this.panel.timeShift); - if (timeShiftInfo.invalid) { - this.timeInfo = 'invalid timeshift'; - return; - } - - var timeShift = '-' + this.panel.timeShift; - this.timeInfo += ' timeshift ' + timeShift; - this.range.from = dateMath.parseDateMath(timeShift, this.range.from, false); - this.range.to = dateMath.parseDateMath(timeShift, this.range.to, true); - - this.rangeRaw = this.range; - } - - if (this.panel.hideTimeOverride) { - this.timeInfo = ''; - } - }; + } + }; issueQueries(datasource) { this.updateTimeRange(); From 801129530e37b541de01ca72f434c3ec4d5122ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Fri, 5 Feb 2016 18:08:21 +0100 Subject: [PATCH 14/57] feat(plugins): base clases are now in app/plugins/sdk --- public/app/features/panel/panel.ts | 13 ------------- .../app/plugins/datasource/cloudwatch/query_ctrl.ts | 2 +- .../plugins/datasource/elasticsearch/query_ctrl.ts | 2 +- public/app/plugins/datasource/grafana/module.ts | 2 +- .../app/plugins/datasource/graphite/query_ctrl.ts | 2 +- .../app/plugins/datasource/influxdb/query_ctrl.ts | 2 +- .../app/plugins/datasource/opentsdb/query_ctrl.ts | 2 +- .../app/plugins/datasource/prometheus/query_ctrl.ts | 2 +- public/app/plugins/panel/dashlist/module.ts | 2 +- public/app/plugins/panel/graph/module.ts | 6 +++--- public/app/plugins/panel/singlestat/module.ts | 4 ++-- public/app/plugins/panel/table/module.ts | 2 +- public/app/plugins/panel/text/module.ts | 2 +- public/app/plugins/panel/unknown/module.ts | 2 +- public/app/plugins/sdk.ts | 9 +++++++++ 15 files changed, 25 insertions(+), 29 deletions(-) delete mode 100644 public/app/features/panel/panel.ts create mode 100644 public/app/plugins/sdk.ts diff --git a/public/app/features/panel/panel.ts b/public/app/features/panel/panel.ts deleted file mode 100644 index c2415aaa1da..00000000000 --- a/public/app/features/panel/panel.ts +++ /dev/null @@ -1,13 +0,0 @@ -/// - -import config from 'app/core/config'; - -import {PanelCtrl} from './panel_ctrl'; -import {MetricsPanelCtrl} from './metrics_panel_ctrl'; -import {QueryCtrl} from './query_ctrl'; - -export { - PanelCtrl, - MetricsPanelCtrl, - QueryCtrl, -} diff --git a/public/app/plugins/datasource/cloudwatch/query_ctrl.ts b/public/app/plugins/datasource/cloudwatch/query_ctrl.ts index daacd7fe198..ab0ac0bdcff 100644 --- a/public/app/plugins/datasource/cloudwatch/query_ctrl.ts +++ b/public/app/plugins/datasource/cloudwatch/query_ctrl.ts @@ -2,7 +2,7 @@ import './query_parameter_ctrl'; import _ from 'lodash'; -import {QueryCtrl} from 'app/features/panel/panel'; +import {QueryCtrl} from 'app/plugins/sdk'; export class CloudWatchQueryCtrl extends QueryCtrl { static templateUrl = 'public/app/plugins/datasource/cloudwatch/partials/query.editor.html'; diff --git a/public/app/plugins/datasource/elasticsearch/query_ctrl.ts b/public/app/plugins/datasource/elasticsearch/query_ctrl.ts index fb04f39b8ac..cab1fcf5676 100644 --- a/public/app/plugins/datasource/elasticsearch/query_ctrl.ts +++ b/public/app/plugins/datasource/elasticsearch/query_ctrl.ts @@ -5,7 +5,7 @@ import './metric_agg'; import angular from 'angular'; import _ from 'lodash'; -import {QueryCtrl} from 'app/features/panel/panel'; +import {QueryCtrl} from 'app/plugins/sdk'; export class ElasticQueryCtrl extends QueryCtrl { static templateUrl = 'public/app/plugins/datasource/elasticsearch/partials/query.editor.html'; diff --git a/public/app/plugins/datasource/grafana/module.ts b/public/app/plugins/datasource/grafana/module.ts index 19233c4f975..66d398273e0 100644 --- a/public/app/plugins/datasource/grafana/module.ts +++ b/public/app/plugins/datasource/grafana/module.ts @@ -2,7 +2,7 @@ import angular from 'angular'; import {GrafanaDatasource} from './datasource'; -import {QueryCtrl} from 'app/features/panel/panel'; +import {QueryCtrl} from 'app/plugins/sdk'; class GrafanaQueryCtrl extends QueryCtrl { static templateUrl = 'public/app/plugins/datasource/grafana/partials/query.editor.html'; diff --git a/public/app/plugins/datasource/graphite/query_ctrl.ts b/public/app/plugins/datasource/graphite/query_ctrl.ts index 23c6c2aa6d6..659253102c5 100644 --- a/public/app/plugins/datasource/graphite/query_ctrl.ts +++ b/public/app/plugins/datasource/graphite/query_ctrl.ts @@ -8,7 +8,7 @@ import _ from 'lodash'; import moment from 'moment'; import gfunc from './gfunc'; import {Parser} from './parser'; -import {QueryCtrl} from 'app/features/panel/panel'; +import {QueryCtrl} from 'app/plugins/sdk'; export class GraphiteQueryCtrl extends QueryCtrl { static templateUrl = 'public/app/plugins/datasource/graphite/partials/query.editor.html'; diff --git a/public/app/plugins/datasource/influxdb/query_ctrl.ts b/public/app/plugins/datasource/influxdb/query_ctrl.ts index 0622fc17bd1..cecfac28ea8 100644 --- a/public/app/plugins/datasource/influxdb/query_ctrl.ts +++ b/public/app/plugins/datasource/influxdb/query_ctrl.ts @@ -8,7 +8,7 @@ import _ from 'lodash'; import InfluxQueryBuilder from './query_builder'; import InfluxQuery from './influx_query'; import queryPart from './query_part'; -import {QueryCtrl} from 'app/features/panel/panel'; +import {QueryCtrl} from 'app/plugins/sdk'; export class InfluxQueryCtrl extends QueryCtrl { static templateUrl = 'public/app/plugins/datasource/influxdb/partials/query.editor.html'; diff --git a/public/app/plugins/datasource/opentsdb/query_ctrl.ts b/public/app/plugins/datasource/opentsdb/query_ctrl.ts index 69590b714ca..43086588679 100644 --- a/public/app/plugins/datasource/opentsdb/query_ctrl.ts +++ b/public/app/plugins/datasource/opentsdb/query_ctrl.ts @@ -2,7 +2,7 @@ import _ from 'lodash'; import kbn from 'app/core/utils/kbn'; -import {QueryCtrl} from 'app/features/panel/panel'; +import {QueryCtrl} from 'app/plugins/sdk'; export class OpenTsQueryCtrl extends QueryCtrl { static templateUrl = 'public/app/plugins/datasource/opentsdb/partials/query.editor.html'; diff --git a/public/app/plugins/datasource/prometheus/query_ctrl.ts b/public/app/plugins/datasource/prometheus/query_ctrl.ts index c215b184275..4ae380f1f65 100644 --- a/public/app/plugins/datasource/prometheus/query_ctrl.ts +++ b/public/app/plugins/datasource/prometheus/query_ctrl.ts @@ -5,7 +5,7 @@ import _ from 'lodash'; import moment from 'moment'; import * as dateMath from 'app/core/utils/datemath'; -import {QueryCtrl} from 'app/features/panel/panel'; +import {QueryCtrl} from 'app/plugins/sdk'; class PrometheusQueryCtrl extends QueryCtrl { static templateUrl = 'public/app/plugins/datasource/prometheus/partials/query.editor.html'; diff --git a/public/app/plugins/panel/dashlist/module.ts b/public/app/plugins/panel/dashlist/module.ts index 829c98f39f5..78f2c0e3f6a 100644 --- a/public/app/plugins/panel/dashlist/module.ts +++ b/public/app/plugins/panel/dashlist/module.ts @@ -2,7 +2,7 @@ import _ from 'lodash'; import config from 'app/core/config'; -import {PanelCtrl} from '../../../features/panel/panel'; +import {PanelCtrl} from 'app/plugins/sdk'; // Set and populate defaults var panelDefaults = { diff --git a/public/app/plugins/panel/graph/module.ts b/public/app/plugins/panel/graph/module.ts index 7b7db37a0d5..1b1d9f567ca 100644 --- a/public/app/plugins/panel/graph/module.ts +++ b/public/app/plugins/panel/graph/module.ts @@ -7,9 +7,9 @@ import './seriesOverridesCtrl'; import moment from 'moment'; import kbn from 'app/core/utils/kbn'; import _ from 'lodash'; -import TimeSeries from '../../../core/time_series2'; -import * as fileExport from '../../../core/utils/file_export'; -import {MetricsPanelCtrl} from '../../../features/panel/panel'; +import TimeSeries from 'app/core/time_series2'; +import * as fileExport from 'app/core/utils/file_export'; +import {MetricsPanelCtrl} from 'app/plugins/sdk'; var panelDefaults = { // datasource name, null = default datasource diff --git a/public/app/plugins/panel/singlestat/module.ts b/public/app/plugins/panel/singlestat/module.ts index 5786c6be6d2..7eee8524d8c 100644 --- a/public/app/plugins/panel/singlestat/module.ts +++ b/public/app/plugins/panel/singlestat/module.ts @@ -6,8 +6,8 @@ import $ from 'jquery'; import 'jquery.flot'; import kbn from 'app/core/utils/kbn'; -import TimeSeries from '../../../core/time_series2'; -import {MetricsPanelCtrl} from '../../../features/panel/panel'; +import TimeSeries from 'app/core/time_series2'; +import {MetricsPanelCtrl} from 'app/plugins/sdk'; // Set and populate defaults var panelDefaults = { diff --git a/public/app/plugins/panel/table/module.ts b/public/app/plugins/panel/table/module.ts index a84d2678295..43355d5966c 100644 --- a/public/app/plugins/panel/table/module.ts +++ b/public/app/plugins/panel/table/module.ts @@ -5,7 +5,7 @@ import _ from 'lodash'; import $ from 'jquery'; import moment from 'moment'; import * as FileExport from 'app/core/utils/file_export'; -import {MetricsPanelCtrl} from '../../../features/panel/panel'; +import {MetricsPanelCtrl} from 'app/plugins/sdk'; import {transformDataToTable} from './transformers'; import {tablePanelEditor} from './editor'; import {TableRenderer} from './renderer'; diff --git a/public/app/plugins/panel/text/module.ts b/public/app/plugins/panel/text/module.ts index 5e781571eff..3509db12cfa 100644 --- a/public/app/plugins/panel/text/module.ts +++ b/public/app/plugins/panel/text/module.ts @@ -1,7 +1,7 @@ /// import _ from 'lodash'; -import {PanelCtrl} from 'app/features/panel/panel'; +import {PanelCtrl} from 'app/plugins/sdk'; // Set and populate defaults var panelDefaults = { diff --git a/public/app/plugins/panel/unknown/module.ts b/public/app/plugins/panel/unknown/module.ts index d625485cb63..0a0871d6b69 100644 --- a/public/app/plugins/panel/unknown/module.ts +++ b/public/app/plugins/panel/unknown/module.ts @@ -1,6 +1,6 @@ /// -import {PanelCtrl} from '../../../features/panel/panel'; +import {PanelCtrl} from 'app/plugins/sdk'; export class UnknownPanelCtrl extends PanelCtrl { static templateUrl = 'public/app/plugins/panel/unknown/module.html'; diff --git a/public/app/plugins/sdk.ts b/public/app/plugins/sdk.ts new file mode 100644 index 00000000000..a3616903908 --- /dev/null +++ b/public/app/plugins/sdk.ts @@ -0,0 +1,9 @@ +import {PanelCtrl} from 'app/features/panel/panel_ctrl'; +import {MetricsPanelCtrl} from 'app/features/panel/metrics_panel_ctrl'; +import {QueryCtrl} from 'app/features/panel/query_ctrl'; + +export { + PanelCtrl, + MetricsPanelCtrl, + QueryCtrl, +} From 89ef019b7cb2f5853d4fcf2cae8bd0ef788cfc4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Sat, 6 Feb 2016 10:32:07 +0100 Subject: [PATCH 15/57] fix(): back to dashboard link fix --- public/app/features/dashboard/dashnav/dashnav.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/app/features/dashboard/dashnav/dashnav.html b/public/app/features/dashboard/dashnav/dashnav.html index 3edafc1f96f..765c68c7ee4 100644 --- a/public/app/features/dashboard/dashnav/dashnav.html +++ b/public/app/features/dashboard/dashnav/dashnav.html @@ -70,7 +70,7 @@