Added suport for timefilter/min/max in Vega urls (#124077)

This commit is contained in:
Tobias Stadler 2022-01-31 17:04:10 +01:00 committed by GitHub
parent 39de549049
commit 2a552e8de6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 1 deletions

View file

@ -351,6 +351,8 @@ a configuration option for changing the tooltip position and padding:
*Vega* can load data from any URL. To enable, set `vis_type_vega.enableExternalUrls: true` in `kibana.yml`,
then restart {kib}.
You can make the current time range part of the external as a millisecond timestamp by using the placeholders `%timefilter_min%` and `%timefilter_max%`, e.g. `http://example.com?min=%timefilter_min%`.
[float]
[[vega-inspector]]
====== Vega Inspector

View file

@ -8,6 +8,7 @@
import { cloneDeep } from 'lodash';
import 'jest-canvas-mock';
import { euiThemeVars } from '@kbn/ui-theme';
import { TimeCache } from './time_cache';
import { VegaParser } from './vega_parser';
import { bypassExternalUrlCheck } from '../vega_view/vega_base_view';
@ -226,7 +227,12 @@ describe('VegaParser._resolveEsQueries', () => {
},
};
};
const vp = new VegaParser(spec, searchApiStub, 0, 0, mockGetServiceSettings);
const tc = new (class extends TimeCache {
getTimeBounds() {
return { min: 123456, max: 654321 };
}
})();
const vp = new VegaParser(spec, searchApiStub, tc, 0, mockGetServiceSettings);
await vp._resolveDataUrls();
expect(vp.spec).toEqual(expected);
@ -265,6 +271,20 @@ describe('VegaParser._resolveEsQueries', () => {
{ data: { url: bypassExternalUrlCheck('url1') } }
)
);
test(
'timefilter_min',
check(
{ data: { url: 'http://example.com?min=%timefilter_min%' } },
{ data: { url: 'http://example.com?min=123456' } }
)
);
test(
'timefilter_max',
check(
{ data: { url: 'http://example.com?min=%timefilter_max%' } },
{ data: { url: 'http://example.com?min=654321' } }
)
);
});
describe('VegaParser.parseSchema', () => {

View file

@ -676,6 +676,11 @@ The URL is an identifier only. Kibana and your browser will never access this UR
);
}
onFind(obj as Data);
} else if (key === 'data' && typeof obj.url === 'string') {
const bounds = this.timeCache.getTimeBounds();
obj.url = obj.url
.replaceAll('%timefilter_min%', bounds.min.toString())
.replaceAll('%timefilter_max%', bounds.max.toString());
} else {
for (const k of Object.keys(obj)) {
this._findObjectDataUrls(obj[k], onFind, k);