Skip to content

Commit

Permalink
Graphite: Fix drag and drop queries (#39130)
Browse files Browse the repository at this point in the history
* Do not use "select metric" segment when rendering target

* Use better names for tests
  • Loading branch information
ifrost committed Sep 13, 2021
1 parent 2cc0788 commit 26bb08e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion public/app/plugins/datasource/graphite/graphite_query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export default class GraphiteQuery {
};

if (!this.target.textEditor) {
const metricPath = this.getSegmentPathUpTo(this.segments.length).replace(/\.select metric$/, '');
const metricPath = this.getSegmentPathUpTo(this.segments.length).replace(/\.?select metric$/, '');
this.target.target = reduce(this.functions, wrapFunction, metricPath);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,25 @@ describe('Graphite query model', () => {
expect(ctx.queryModel.functions[1].params[0]).toBe('$limit');
});
});

describe('when query is generated from segments', () => {
beforeEach(() => {
ctx.target = { refId: 'A', target: '' };
ctx.queryModel = new GraphiteQuery(ctx.datasource, ctx.target, ctx.templateSrv);
});

it('and no segments are selected then the query is empty', () => {
ctx.queryModel.segments = [{ value: 'select metric' }];
ctx.queryModel.updateModelTarget(ctx.targets);

expect(ctx.queryModel.target.target).toBe('');
});

it('and some segments are selected then segments without selected value are omitted', () => {
ctx.queryModel.segments = [{ value: 'foo' }, { value: 'bar' }, { value: 'select metric' }];
ctx.queryModel.updateModelTarget(ctx.targets);

expect(ctx.queryModel.target.target).toBe('foo.bar');
});
});
});

0 comments on commit 26bb08e

Please sign in to comment.