Skip to content

Commit 44d377b

Browse files
committed
feat(prometheus): refactoring and polish of the prometheus editor removing unused/uneeded code
1 parent a2bf3e0 commit 44d377b

File tree

5 files changed

+54
-157
lines changed

5 files changed

+54
-157
lines changed

public/app/plugins/datasource/prometheus/datasource.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ define([
55
'moment',
66
'app/core/utils/datemath',
77
'./directives',
8-
'./queryCtrl',
8+
'./query_ctrl',
99
],
1010
function (angular, _, kbn, dateMath) {
1111
'use strict';
@@ -22,7 +22,6 @@ function (angular, _, kbn, dateMath) {
2222

2323
var url = datasource.url;
2424
if (url[url.length-1] === '/') {
25-
// remove trailing slash
2625
url = url.substr(0, url.length - 1);
2726
}
2827
this.url = url;

public/app/plugins/datasource/prometheus/partials/query.editor.html

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,7 @@
4848
placeholder="query expression"
4949
data-min-length=0 data-items=100
5050
ng-model-onblur
51-
ng-change="refreshMetricData()"
52-
>
53-
<a bs-tooltip="target.datasourceErrors.query"
54-
style="color: rgb(229, 189, 28)"
55-
ng-show="target.datasourceErrors.query">
56-
<i class="fa fa-warning"></i>
57-
</a>
51+
ng-change="refreshMetricData()">
5852
</li>
5953
<li class="tight-form-item">
6054
Metric
@@ -66,13 +60,7 @@
6660
spellcheck='false'
6761
bs-typeahead="suggestMetrics"
6862
placeholder="metric name"
69-
data-min-length=0 data-items=100
70-
>
71-
<a bs-tooltip="target.errors.metric"
72-
style="color: rgb(229, 189, 28)"
73-
ng-show="target.errors.metric">
74-
<i class="fa fa-warning"></i>
75-
</a>
63+
data-min-length=0 data-items=100>
7664
</li>
7765

7866
</ul>
@@ -113,7 +101,7 @@
113101
bs-tooltip="'Leave blank for auto handling based on time range and panel width'"
114102
data-placement="right"
115103
spellcheck='false'
116-
placeholder="{{target.calculatedInterval}}"
104+
placeholder="{{interval}}"
117105
data-min-length=0 data-items=100
118106
ng-model-onblur
119107
ng-change="refreshMetricData()"
@@ -131,12 +119,6 @@
131119
</select>
132120
</li>
133121

134-
<li class="tight-form-item">
135-
<a href="{{target.prometheusLink}}" target="_blank" bs-tooltip="'Link to Graph in Prometheus'">
136-
<i class="fa fa-share-square-o"></i>
137-
</a>
138-
</li>
139-
140122
</ul>
141123

142124
<div class="clearfix"></div>

public/app/plugins/datasource/prometheus/queryCtrl.js

Lines changed: 0 additions & 133 deletions
This file was deleted.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
define([
2+
'angular',
3+
'lodash',
4+
],
5+
function (angular, _) {
6+
'use strict';
7+
8+
var module = angular.module('grafana.controllers');
9+
10+
module.controller('PrometheusQueryCtrl', function($scope) {
11+
12+
$scope.init = function() {
13+
var target = $scope.target;
14+
15+
target.expr = target.expr || '';
16+
target.intervalFactor = target.intervalFactor || 2;
17+
18+
$scope.metric = '';
19+
$scope.resolutions = _.map([1,2,3,4,5,10], function(f) {
20+
return {factor: f, label: '1/' + f};
21+
});
22+
23+
$scope.$on('typeahead-updated', function() {
24+
$scope.$apply($scope.inputMetric);
25+
$scope.refreshMetricData();
26+
});
27+
};
28+
29+
$scope.refreshMetricData = function() {
30+
if (!_.isEqual($scope.oldTarget, $scope.target)) {
31+
$scope.oldTarget = angular.copy($scope.target);
32+
$scope.get_data();
33+
}
34+
};
35+
36+
$scope.inputMetric = function() {
37+
$scope.target.expr += $scope.target.metric;
38+
$scope.metric = '';
39+
};
40+
41+
$scope.suggestMetrics = function(query, callback) {
42+
$scope.datasource
43+
.performSuggestQuery(query)
44+
.then(callback);
45+
};
46+
47+
$scope.init();
48+
});
49+
50+
});

tasks/options/requirejs.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ module.exports = function(config,grunt) {
6363
'app/plugins/datasource/grafana/datasource',
6464
'app/plugins/datasource/graphite/datasource',
6565
'app/plugins/datasource/influxdb/datasource',
66-
'app/plugins/datasource/prometheus/datasource',
6766
]
6867
},
6968
];

0 commit comments

Comments
 (0)