Skip to content

Commit 2f18444

Browse files
committed
Graphite: alt node suggestions will now not include wildcard or template variables if the node is empty, Closes grafana#1230
1 parent 8a4ff5b commit 2f18444

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/app/controllers/graphiteTarget.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ function (angular, _, config, gfunc, Parser) {
162162
return new MetricSegment({ value: segment.text, expandable: segment.expandable });
163163
});
164164

165+
if ($scope.altSegments.length === 0) {
166+
return;
167+
}
168+
169+
// add template variables
165170
_.each(templateSrv.variables, function(variable) {
166171
$scope.altSegments.unshift(new MetricSegment({
167172
type: 'template',
@@ -170,6 +175,7 @@ function (angular, _, config, gfunc, Parser) {
170175
}));
171176
});
172177

178+
// add wildcard option
173179
$scope.altSegments.unshift(new MetricSegment('*'));
174180
})
175181
.then(null, function(err) {

src/test/specs/graphiteTargetCtrl-specs.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,22 @@ define([
136136
});
137137
});
138138

139+
describe('when getting altSegments and metricFindQuery retuns empty array', function() {
140+
beforeEach(function() {
141+
ctx.scope.target.target = 'test.count';
142+
ctx.scope.datasource.metricFindQuery.returns(ctx.$q.when([]));
143+
ctx.scope.init();
144+
ctx.scope.getAltSegments(1);
145+
ctx.scope.$digest();
146+
ctx.scope.$parent = { get_data: sinon.spy() };
147+
});
148+
149+
it('should have no segments', function() {
150+
expect(ctx.scope.altSegments.length).to.be(0);
151+
});
152+
153+
});
154+
139155
describe('targetChanged', function() {
140156
beforeEach(function() {
141157
ctx.scope.datasource.metricFindQuery.returns(ctx.$q.when([{expandable: false}]));

0 commit comments

Comments
 (0)