Commit a7ac3f14 by Zoltán Bedi Committed by GitHub

Prometheus: Fix min step variable interpolation (#27505)

* Add missing dependency to lockfile

* Prometheus: Fix min step variable interpolation
parent 9928f925
......@@ -1640,12 +1640,12 @@ describe('PrometheusDatasource', () => {
it('should be 4 times the scrape interval if min step set to 1m and interval is 15s', () => {
// For a 5m graph, $__interval is 15s
ds.createQuery({ ...target, interval: '1m' }, { interval: '15s' } as any, 0, 300);
expect((templateSrv.replace as any).mock.calls[1][1]['__rate_interval'].value).toBe('240s');
expect((templateSrv.replace as any).mock.calls[2][1]['__rate_interval'].value).toBe('240s');
});
it('should be interval + scrape interval if min step set to 1m and interval is 5m', () => {
// For a 7d graph, $__interval is 5m
ds.createQuery({ ...target, interval: '1m' }, { interval: '5m' } as any, 0, 10080);
expect((templateSrv.replace as any).mock.calls[1][1]['__rate_interval'].value).toBe('360s');
expect((templateSrv.replace as any).mock.calls[2][1]['__rate_interval'].value).toBe('360s');
});
it('should be interval + scrape interval if resolution is set to 1/2 and interval is 10m', () => {
// For a 7d graph, $__interval is 10m
......@@ -1657,6 +1657,12 @@ describe('PrometheusDatasource', () => {
ds.createQuery({ ...target, intervalFactor: 2 }, { interval: '15s' } as any, 0, 300);
expect((templateSrv.replace as any).mock.calls[1][1]['__rate_interval'].value).toBe('60s');
});
it('should interpolate min step if set', () => {
templateSrv.replace = jest.fn(() => '15s');
ds.createQuery({ ...target, interval: '$int' }, { interval: '15s' } as any, 0, 300);
expect((templateSrv.replace as any).mock.calls).toHaveLength(3);
templateSrv.replace = jest.fn((a: string) => a);
});
});
});
......
......@@ -351,7 +351,11 @@ export class PrometheusDatasource extends DataSourceApi<PromQuery, PromOptions>
templateSrv.replace(target.interval || options.interval, options.scopedVars)
);
// Scrape interval as specified for the query ("Min step") or otherwise taken from the datasource.
const scrapeInterval = rangeUtil.intervalToSeconds(target.interval || this.interval);
// Min step field can have template variables in it, make sure to replace it.
const scrapeInterval = target.interval
? rangeUtil.intervalToSeconds(templateSrv.replace(target.interval, options.scopedVars))
: rangeUtil.intervalToSeconds(this.interval);
const intervalFactor = target.intervalFactor || 1;
// Adjust the interval to take into account any specified minimum and interval factor plus Prometheus limits
const adjustedInterval = this.adjustInterval(interval, minInterval, range, intervalFactor);
......
......@@ -19633,6 +19633,11 @@ pako@~1.0.5:
resolved "https://registry.yarnpkg.com/pako/-/pako-1.0.10.tgz#4328badb5086a426aa90f541977d4955da5c9732"
integrity sha512-0DTvPVU3ed8+HNXOu5Bs+o//Mbdj9VNQMUOe9oKCwh8l0GNwpTDMKCWbRjgtD291AWnkAgkqA/LOnQS8AmS1tw==
papaparse@4.6.3:
version "4.6.3"
resolved "https://registry.yarnpkg.com/papaparse/-/papaparse-4.6.3.tgz#742e5eaaa97fa6c7e1358d2934d8f18f44aee781"
integrity sha512-LRq7BrHC2kHPBYSD50aKuw/B/dGcg29omyJbKWY3KsYUZU69RKwaBHu13jGmCYBtOc4odsLCrFyk6imfyNubJQ==
papaparse@5.3.0:
version "5.3.0"
resolved "https://registry.yarnpkg.com/papaparse/-/papaparse-5.3.0.tgz#ab1702feb96e79ab4309652f36db9536563ad05a"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment