mirror of
https://github.com/elastic/kibana.git
synced 2025-04-25 10:23:14 -04:00
* [APM] Filter out 6.x data Add test Fix snapshots Fix lint issues * Fix tests
This commit is contained in:
parent
0bad70f699
commit
299050be15
4 changed files with 74 additions and 15 deletions
|
@ -11,7 +11,9 @@ import {
|
|||
SearchParams
|
||||
} from 'elasticsearch';
|
||||
import { Legacy } from 'kibana';
|
||||
import { merge } from 'lodash';
|
||||
import moment from 'moment';
|
||||
import { OBSERVER_VERSION_MAJOR } from 'x-pack/plugins/apm/common/elasticsearch_fieldnames';
|
||||
|
||||
function decodeEsQuery(esQuery?: string) {
|
||||
return esQuery ? JSON.parse(decodeURIComponent(esQuery)) : null;
|
||||
|
@ -37,6 +39,20 @@ interface APMRequestQuery {
|
|||
esFilterQuery: string;
|
||||
}
|
||||
|
||||
function addFilterForLegacyData(params: SearchParams) {
|
||||
// ensure a filter exists
|
||||
const nextParams = merge({}, params, {
|
||||
body: { query: { bool: { filter: [] } } }
|
||||
});
|
||||
|
||||
// add to filter
|
||||
nextParams.body.query.bool.filter.push({
|
||||
range: { [OBSERVER_VERSION_MAJOR]: { gte: 7 } }
|
||||
});
|
||||
|
||||
return nextParams;
|
||||
}
|
||||
|
||||
export function setupRequest(req: Legacy.Request): Setup {
|
||||
const query = (req.query as unknown) as APMRequestQuery;
|
||||
const cluster = req.server.plugins.elasticsearch.getCluster('data');
|
||||
|
@ -45,23 +61,24 @@ export function setupRequest(req: Legacy.Request): Setup {
|
|||
const client: ESClient = async (type, params) => {
|
||||
const includeFrozen = await uiSettings.get('search:includeFrozen');
|
||||
|
||||
const nextParams = {
|
||||
...addFilterForLegacyData(params), // filter out pre-7.0 data
|
||||
ignore_throttled: !includeFrozen, // whether to query frozen indices or not
|
||||
rest_total_hits_as_int: true // ensure that ES returns accurate hits.total with pre-6.6 format
|
||||
};
|
||||
|
||||
if (query._debug) {
|
||||
console.log(`DEBUG ES QUERY:`);
|
||||
console.log({ includeFrozen });
|
||||
console.log('includeFrozen: ', includeFrozen);
|
||||
console.log(
|
||||
`${req.method.toUpperCase()} ${req.url.pathname} ${JSON.stringify(
|
||||
query
|
||||
)}`
|
||||
);
|
||||
console.log(`GET ${params.index}/_search`);
|
||||
console.log(JSON.stringify(params.body, null, 4));
|
||||
console.log(`GET ${nextParams.index}/_search`);
|
||||
console.log(JSON.stringify(nextParams.body, null, 4));
|
||||
}
|
||||
|
||||
const nextParams = {
|
||||
...params,
|
||||
ignore_throttled: !includeFrozen,
|
||||
rest_total_hits_as_int: true // ensure that ES returns accurate hits.total with pre-6.6 format
|
||||
};
|
||||
return cluster.callWithRequest(req, type, nextParams);
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue