Skip to content

Commit f44eaae

Browse files
committed
Merge pull request grafana#2867 from juliusv/fix-prometheus-link
Fix "Link to Prometheus" button for proxied Prometheus sources.
2 parents 228aac2 + 3cc6911 commit f44eaae

File tree

5 files changed

+14
-12
lines changed

5 files changed

+14
-12
lines changed

pkg/api/frontendsettings.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ func getFrontendSettingsMap(c *middleware.Context) (map[string]interface{}, erro
8181
dsMap["index"] = ds.Database
8282
}
8383

84+
if ds.Type == m.DS_PROMETHEUS {
85+
// add unproxied server URL for link to Prometheus web UI
86+
dsMap["directUrl"] = ds.Url
87+
}
88+
8489
datasources[ds.Name] = dsMap
8590
}
8691

pkg/models/datasource.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const (
1212
DS_ES = "elasticsearch"
1313
DS_OPENTSDB = "opentsdb"
1414
DS_CLOUDWATCH = "cloudwatch"
15+
DS_PROMETHEUS = "prometheus"
1516
DS_ACCESS_DIRECT = "direct"
1617
DS_ACCESS_PROXY = "proxy"
1718
)

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,8 @@ function (angular, _, moment, dateMath) {
2121
this.name = datasource.name;
2222
this.supportMetrics = true;
2323

24-
var url = datasource.url;
25-
if (url[url.length-1] === '/') {
26-
// remove trailing slash
27-
url = url.substr(0, url.length - 1);
28-
}
29-
this.url = url;
24+
this.url = datasource.url.replace(/\/$/g, '');
25+
this.directUrl = datasource.directUrl.replace(/\/$/g, '');
3026
this.basicAuth = datasource.basicAuth;
3127
this.lastErrors = {};
3228
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ function (angular, _, kbn, dateMath) {
111111
};
112112

113113
var hash = encodeURIComponent(JSON.stringify([expr]));
114-
return $scope.datasource.url + '/graph#' + hash;
114+
return $scope.datasource.directUrl + '/graph#' + hash;
115115
};
116116

117117
$scope.calculateInterval = function() {

public/app/plugins/datasource/prometheus/specs/datasource_specs.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ describe('PrometheusDatasource', function() {
1010
beforeEach(angularMocks.module('grafana.services'));
1111
beforeEach(ctx.createService('PrometheusDatasource'));
1212
beforeEach(function() {
13-
ctx.ds = new ctx.service({ url: '', user: 'test', password: 'mupp' });
13+
ctx.ds = new ctx.service({ url: 'proxied', directUrl: 'direct', user: 'test', password: 'mupp' });
1414
});
1515
describe('When querying prometheus with one target using query editor target spec', function() {
1616
var results;
17-
var urlExpected = '/api/v1/query_range?query=' +
17+
var urlExpected = 'proxied/api/v1/query_range?query=' +
1818
encodeURIComponent('test{job="testjob"}') +
1919
'&start=1443438675&end=1443460275&step=60s';
2020
var query = {
@@ -53,7 +53,7 @@ describe('PrometheusDatasource', function() {
5353
status: "success",
5454
data: ["value1", "value2", "value3"]
5555
};
56-
ctx.$httpBackend.expect('GET', '/api/v1/label/resource/values').respond(response);
56+
ctx.$httpBackend.expect('GET', 'proxied/api/v1/label/resource/values').respond(response);
5757
ctx.ds.metricFindQuery('label_values(resource)').then(function(data) { results = data; });
5858
ctx.$httpBackend.flush();
5959
ctx.$rootScope.$apply();
@@ -71,7 +71,7 @@ describe('PrometheusDatasource', function() {
7171
]
7272
}
7373
};
74-
ctx.$httpBackend.expect('GET', /\/api\/v1\/query\?query=count\(metric\)%20by%20\(resource\)&time=.*/).respond(response);
74+
ctx.$httpBackend.expect('GET', /proxied\/api\/v1\/query\?query=count\(metric\)%20by%20\(resource\)&time=.*/).respond(response);
7575
ctx.ds.metricFindQuery('label_values(metric, resource)').then(function(data) { results = data; });
7676
ctx.$httpBackend.flush();
7777
ctx.$rootScope.$apply();
@@ -82,7 +82,7 @@ describe('PrometheusDatasource', function() {
8282
status: "success",
8383
data: ["metric1","metric2","metric3","nomatch"]
8484
};
85-
ctx.$httpBackend.expect('GET', '/api/v1/label/__name__/values').respond(response);
85+
ctx.$httpBackend.expect('GET', 'proxied/api/v1/label/__name__/values').respond(response);
8686
ctx.ds.metricFindQuery('metrics(metric.*)').then(function(data) { results = data; });
8787
ctx.$httpBackend.flush();
8888
ctx.$rootScope.$apply();

0 commit comments

Comments
 (0)