Graphite: Fix nested variable interpolation for repeated rows (#106976)

* Fix for repeated row variables

* Add unit tests

---------

Co-authored-by: Ivan Ortega <ivanortegaalba@gmail.com>
This commit is contained in:
Andreas Christou
2025-06-19 15:40:05 +02:00
committed by GitHub
parent b9fa641ff6
commit f7667f44db
2 changed files with 47 additions and 1 deletions

View File

@ -462,6 +462,52 @@ describe('graphiteDatasource', () => {
expect(results[2]).toBe('target=' + encodeURIComponent('asPercent(aMetricName,sumSeries(aMetricName))')); expect(results[2]).toBe('target=' + encodeURIComponent('asPercent(aMetricName,sumSeries(aMetricName))'));
}); });
it('should use scoped variables when nesting query references', () => {
ctx.templateSrv.init([{ type: 'query', name: 'metric', current: { value: ['globalValue'] } }]);
const originalTargetMap = {
A: '$metric',
B: 'sumSeries(#A)',
};
const scopedVars = {
metric: { text: 'scopedValue', value: 'scopedValue' },
};
const results = ctx.ds.buildGraphiteParams(
{
targets: [{ target: '$metric' }, { target: 'sumSeries(#A)' }],
},
originalTargetMap,
scopedVars
);
expect(results[1]).toBe('target=' + encodeURIComponent('sumSeries(scopedValue)'));
});
it('should apply scoped variables to nested references with hidden targets', () => {
ctx.templateSrv.init([{ type: 'query', name: 'server', current: { value: ['global'] } }]);
const originalTargetMap = {
A: '$server.cpu',
B: 'avg(#A)',
};
const scopedVars = {
server: { text: 'web01', value: 'web01' },
};
const results = ctx.ds.buildGraphiteParams(
{
targets: [{ target: '$server.cpu', hide: true }, { target: 'avg(#A)' }],
},
originalTargetMap,
scopedVars
);
expect(results[0]).toBe('target=' + encodeURIComponent('avg(web01.cpu)'));
});
it('should fix wrong minute interval parameters', () => { it('should fix wrong minute interval parameters', () => {
const originalTargetMap = { const originalTargetMap = {
A: "summarize(prod.25m.count, '25m', 'sum')", A: "summarize(prod.25m.count, '25m', 'sum')",

View File

@ -1029,7 +1029,7 @@ export class GraphiteDatasource
} }
targetValue = targets[target.refId]; targetValue = targets[target.refId];
targetValue = this.templateSrv.replace(targetValue.replace(regex, nestedSeriesRegexReplacer)); targetValue = this.templateSrv.replace(targetValue.replace(regex, nestedSeriesRegexReplacer), scopedVars);
targets[target.refId] = targetValue; targets[target.refId] = targetValue;
if (!target.hide) { if (!target.hide) {