[APM] Don't fetch dynamic index pattern in setupRequest (#70308)
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
parent
c081caa634
commit
429805d1b8
9 changed files with 65 additions and 70 deletions
|
@ -56,7 +56,6 @@ describe('timeseriesFetcher', () => {
|
||||||
apmAgentConfigurationIndex: '.apm-agent-configuration',
|
apmAgentConfigurationIndex: '.apm-agent-configuration',
|
||||||
apmCustomLinkIndex: '.apm-custom-link',
|
apmCustomLinkIndex: '.apm-custom-link',
|
||||||
},
|
},
|
||||||
dynamicIndexPattern: null as any,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -11,15 +11,9 @@ import {
|
||||||
localUIFilters,
|
localUIFilters,
|
||||||
localUIFilterNames,
|
localUIFilterNames,
|
||||||
} from '../../ui_filters/local_ui_filters/config';
|
} from '../../ui_filters/local_ui_filters/config';
|
||||||
import {
|
import { esKuery } from '../../../../../../../src/plugins/data/server';
|
||||||
esKuery,
|
|
||||||
IIndexPattern,
|
|
||||||
} from '../../../../../../../src/plugins/data/server';
|
|
||||||
|
|
||||||
export function getUiFiltersES(
|
export function getUiFiltersES(uiFilters: UIFilters) {
|
||||||
indexPattern: IIndexPattern | undefined,
|
|
||||||
uiFilters: UIFilters
|
|
||||||
) {
|
|
||||||
const { kuery, environment, ...localFilterValues } = uiFilters;
|
const { kuery, environment, ...localFilterValues } = uiFilters;
|
||||||
const mappedFilters = localUIFilterNames
|
const mappedFilters = localUIFilterNames
|
||||||
.filter((name) => name in localFilterValues)
|
.filter((name) => name in localFilterValues)
|
||||||
|
@ -35,7 +29,7 @@ export function getUiFiltersES(
|
||||||
|
|
||||||
// remove undefined items from list
|
// remove undefined items from list
|
||||||
const esFilters = [
|
const esFilters = [
|
||||||
getKueryUiFilterES(indexPattern, uiFilters.kuery),
|
getKueryUiFilterES(uiFilters.kuery),
|
||||||
getEnvironmentUiFilterES(uiFilters.environment),
|
getEnvironmentUiFilterES(uiFilters.environment),
|
||||||
]
|
]
|
||||||
.filter((filter) => !!filter)
|
.filter((filter) => !!filter)
|
||||||
|
@ -44,14 +38,11 @@ export function getUiFiltersES(
|
||||||
return esFilters;
|
return esFilters;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getKueryUiFilterES(
|
function getKueryUiFilterES(kuery?: string) {
|
||||||
indexPattern: IIndexPattern | undefined,
|
if (!kuery) {
|
||||||
kuery?: string
|
|
||||||
) {
|
|
||||||
if (!kuery || !indexPattern) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ast = esKuery.fromKueryExpression(kuery);
|
const ast = esKuery.fromKueryExpression(kuery);
|
||||||
return esKuery.toElasticsearchQuery(ast, indexPattern) as ESFilter;
|
return esKuery.toElasticsearchQuery(ast) as ESFilter;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,11 +19,10 @@ import {
|
||||||
ESSearchRequest,
|
ESSearchRequest,
|
||||||
ESSearchResponse,
|
ESSearchResponse,
|
||||||
} from '../../../typings/elasticsearch';
|
} from '../../../typings/elasticsearch';
|
||||||
import { UI_SETTINGS } from '../../../../../../src/plugins/data/server';
|
|
||||||
import { OBSERVER_VERSION_MAJOR } from '../../../common/elasticsearch_fieldnames';
|
import { OBSERVER_VERSION_MAJOR } from '../../../common/elasticsearch_fieldnames';
|
||||||
import { pickKeys } from '../../../common/utils/pick_keys';
|
import { pickKeys } from '../../../common/utils/pick_keys';
|
||||||
import { APMRequestHandlerContext } from '../../routes/typings';
|
import { APMRequestHandlerContext } from '../../routes/typings';
|
||||||
import { getApmIndices } from '../settings/apm_indices/get_apm_indices';
|
import { ApmIndicesConfig } from '../settings/apm_indices/get_apm_indices';
|
||||||
|
|
||||||
// `type` was deprecated in 7.0
|
// `type` was deprecated in 7.0
|
||||||
export type APMIndexDocumentParams<T> = Omit<IndexDocumentParams<T>, 'type'>;
|
export type APMIndexDocumentParams<T> = Omit<IndexDocumentParams<T>, 'type'>;
|
||||||
|
@ -85,20 +84,19 @@ function addFilterForLegacyData(
|
||||||
}
|
}
|
||||||
|
|
||||||
// add additional params for search (aka: read) requests
|
// add additional params for search (aka: read) requests
|
||||||
async function getParamsForSearchRequest(
|
function getParamsForSearchRequest({
|
||||||
context: APMRequestHandlerContext,
|
context,
|
||||||
params: ESSearchRequest,
|
params,
|
||||||
apmOptions?: APMOptions
|
indices,
|
||||||
) {
|
includeFrozen,
|
||||||
const { uiSettings } = context.core;
|
includeLegacyData,
|
||||||
const [indices, includeFrozen] = await Promise.all([
|
}: {
|
||||||
getApmIndices({
|
context: APMRequestHandlerContext;
|
||||||
savedObjectsClient: context.core.savedObjects.client,
|
params: ESSearchRequest;
|
||||||
config: context.config,
|
indices: ApmIndicesConfig;
|
||||||
}),
|
includeFrozen: boolean;
|
||||||
uiSettings.client.get(UI_SETTINGS.SEARCH_INCLUDE_FROZEN),
|
includeLegacyData?: boolean;
|
||||||
]);
|
}) {
|
||||||
|
|
||||||
// Get indices for legacy data filter (only those which apply)
|
// Get indices for legacy data filter (only those which apply)
|
||||||
const apmIndices = Object.values(
|
const apmIndices = Object.values(
|
||||||
pickKeys(
|
pickKeys(
|
||||||
|
@ -112,7 +110,7 @@ async function getParamsForSearchRequest(
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
...addFilterForLegacyData(apmIndices, params, apmOptions), // filter out pre-7.0 data
|
...addFilterForLegacyData(apmIndices, params, { includeLegacyData }), // filter out pre-7.0 data
|
||||||
ignore_throttled: !includeFrozen, // whether to query frozen indices or not
|
ignore_throttled: !includeFrozen, // whether to query frozen indices or not
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -123,6 +121,8 @@ interface APMOptions {
|
||||||
|
|
||||||
interface ClientCreateOptions {
|
interface ClientCreateOptions {
|
||||||
clientAsInternalUser?: boolean;
|
clientAsInternalUser?: boolean;
|
||||||
|
indices: ApmIndicesConfig;
|
||||||
|
includeFrozen: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ESClient = ReturnType<typeof getESClient>;
|
export type ESClient = ReturnType<typeof getESClient>;
|
||||||
|
@ -134,7 +134,7 @@ function formatObj(obj: Record<string, any>) {
|
||||||
export function getESClient(
|
export function getESClient(
|
||||||
context: APMRequestHandlerContext,
|
context: APMRequestHandlerContext,
|
||||||
request: KibanaRequest,
|
request: KibanaRequest,
|
||||||
{ clientAsInternalUser = false }: ClientCreateOptions = {}
|
{ clientAsInternalUser = false, indices, includeFrozen }: ClientCreateOptions
|
||||||
) {
|
) {
|
||||||
const {
|
const {
|
||||||
callAsCurrentUser,
|
callAsCurrentUser,
|
||||||
|
@ -194,11 +194,13 @@ export function getESClient(
|
||||||
params: TSearchRequest,
|
params: TSearchRequest,
|
||||||
apmOptions?: APMOptions
|
apmOptions?: APMOptions
|
||||||
): Promise<ESSearchResponse<TDocument, TSearchRequest>> => {
|
): Promise<ESSearchResponse<TDocument, TSearchRequest>> => {
|
||||||
const nextParams = await getParamsForSearchRequest(
|
const nextParams = await getParamsForSearchRequest({
|
||||||
context,
|
context,
|
||||||
params,
|
params,
|
||||||
apmOptions
|
indices,
|
||||||
);
|
includeFrozen,
|
||||||
|
...apmOptions,
|
||||||
|
});
|
||||||
|
|
||||||
return callEs('search', nextParams);
|
return callEs('search', nextParams);
|
||||||
},
|
},
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
import { UI_SETTINGS } from '../../../../../../src/plugins/data/common';
|
||||||
import { KibanaRequest } from '../../../../../../src/core/server';
|
import { KibanaRequest } from '../../../../../../src/core/server';
|
||||||
import { IIndexPattern } from '../../../../../../src/plugins/data/common';
|
|
||||||
import { APMConfig } from '../..';
|
import { APMConfig } from '../..';
|
||||||
import {
|
import {
|
||||||
getApmIndices,
|
getApmIndices,
|
||||||
|
@ -18,17 +18,13 @@ import { getUiFiltersES } from './convert_ui_filters/get_ui_filters_es';
|
||||||
import { APMRequestHandlerContext } from '../../routes/typings';
|
import { APMRequestHandlerContext } from '../../routes/typings';
|
||||||
import { getESClient } from './es_client';
|
import { getESClient } from './es_client';
|
||||||
import { ProcessorEvent } from '../../../common/processor_event';
|
import { ProcessorEvent } from '../../../common/processor_event';
|
||||||
import { getDynamicIndexPattern } from '../index_pattern/get_dynamic_index_pattern';
|
|
||||||
|
|
||||||
function decodeUiFilters(
|
function decodeUiFilters(uiFiltersEncoded?: string) {
|
||||||
indexPattern: IIndexPattern | undefined,
|
if (!uiFiltersEncoded) {
|
||||||
uiFiltersEncoded?: string
|
|
||||||
) {
|
|
||||||
if (!uiFiltersEncoded || !indexPattern) {
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
const uiFilters = JSON.parse(uiFiltersEncoded);
|
const uiFilters = JSON.parse(uiFiltersEncoded);
|
||||||
return getUiFiltersES(indexPattern, uiFilters);
|
return getUiFiltersES(uiFilters);
|
||||||
}
|
}
|
||||||
// Explicitly type Setup to prevent TS initialization errors
|
// Explicitly type Setup to prevent TS initialization errors
|
||||||
// https://github.com/microsoft/TypeScript/issues/34933
|
// https://github.com/microsoft/TypeScript/issues/34933
|
||||||
|
@ -39,7 +35,6 @@ export interface Setup {
|
||||||
ml?: ReturnType<typeof getMlSetup>;
|
ml?: ReturnType<typeof getMlSetup>;
|
||||||
config: APMConfig;
|
config: APMConfig;
|
||||||
indices: ApmIndicesConfig;
|
indices: ApmIndicesConfig;
|
||||||
dynamicIndexPattern?: IIndexPattern;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SetupTimeRange {
|
export interface SetupTimeRange {
|
||||||
|
@ -75,28 +70,33 @@ export async function setupRequest<TParams extends SetupRequestParams>(
|
||||||
const { config } = context;
|
const { config } = context;
|
||||||
const { query } = context.params;
|
const { query } = context.params;
|
||||||
|
|
||||||
const indices = await getApmIndices({
|
const [indices, includeFrozen] = await Promise.all([
|
||||||
savedObjectsClient: context.core.savedObjects.client,
|
getApmIndices({
|
||||||
config,
|
savedObjectsClient: context.core.savedObjects.client,
|
||||||
});
|
config,
|
||||||
|
}),
|
||||||
|
context.core.uiSettings.client.get(UI_SETTINGS.SEARCH_INCLUDE_FROZEN),
|
||||||
|
]);
|
||||||
|
|
||||||
const dynamicIndexPattern = await getDynamicIndexPattern({
|
const createClientOptions = {
|
||||||
context,
|
|
||||||
indices,
|
indices,
|
||||||
processorEvent: query.processorEvent,
|
includeFrozen,
|
||||||
});
|
};
|
||||||
|
|
||||||
const uiFiltersES = decodeUiFilters(dynamicIndexPattern, query.uiFilters);
|
const uiFiltersES = decodeUiFilters(query.uiFilters);
|
||||||
|
|
||||||
const coreSetupRequest = {
|
const coreSetupRequest = {
|
||||||
indices,
|
indices,
|
||||||
client: getESClient(context, request, { clientAsInternalUser: false }),
|
client: getESClient(context, request, {
|
||||||
|
clientAsInternalUser: false,
|
||||||
|
...createClientOptions,
|
||||||
|
}),
|
||||||
internalClient: getESClient(context, request, {
|
internalClient: getESClient(context, request, {
|
||||||
clientAsInternalUser: true,
|
clientAsInternalUser: true,
|
||||||
|
...createClientOptions,
|
||||||
}),
|
}),
|
||||||
ml: getMlSetup(context, request),
|
ml: getMlSetup(context, request),
|
||||||
config,
|
config,
|
||||||
dynamicIndexPattern,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -44,7 +44,6 @@ describe('timeseriesFetcher', () => {
|
||||||
apmAgentConfigurationIndex: 'myIndex',
|
apmAgentConfigurationIndex: 'myIndex',
|
||||||
apmCustomLinkIndex: 'myIndex',
|
apmCustomLinkIndex: 'myIndex',
|
||||||
},
|
},
|
||||||
dynamicIndexPattern: null as any,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { omit } from 'lodash';
|
import { omit } from 'lodash';
|
||||||
import { IIndexPattern } from 'src/plugins/data/server';
|
|
||||||
import { mergeProjection } from '../../../../common/projections/util/merge_projection';
|
import { mergeProjection } from '../../../../common/projections/util/merge_projection';
|
||||||
import { Projection } from '../../../../common/projections/typings';
|
import { Projection } from '../../../../common/projections/typings';
|
||||||
import { UIFilters } from '../../../../typings/ui_filters';
|
import { UIFilters } from '../../../../typings/ui_filters';
|
||||||
|
@ -13,18 +12,16 @@ import { getUiFiltersES } from '../../helpers/convert_ui_filters/get_ui_filters_
|
||||||
import { localUIFilters, LocalUIFilterName } from './config';
|
import { localUIFilters, LocalUIFilterName } from './config';
|
||||||
|
|
||||||
export const getLocalFilterQuery = ({
|
export const getLocalFilterQuery = ({
|
||||||
indexPattern,
|
|
||||||
uiFilters,
|
uiFilters,
|
||||||
projection,
|
projection,
|
||||||
localUIFilterName,
|
localUIFilterName,
|
||||||
}: {
|
}: {
|
||||||
indexPattern: IIndexPattern | undefined;
|
|
||||||
uiFilters: UIFilters;
|
uiFilters: UIFilters;
|
||||||
projection: Projection;
|
projection: Projection;
|
||||||
localUIFilterName: LocalUIFilterName;
|
localUIFilterName: LocalUIFilterName;
|
||||||
}) => {
|
}) => {
|
||||||
const field = localUIFilters[localUIFilterName];
|
const field = localUIFilters[localUIFilterName];
|
||||||
const filter = getUiFiltersES(indexPattern, omit(uiFilters, field.name));
|
const filter = getUiFiltersES(omit(uiFilters, field.name));
|
||||||
|
|
||||||
const bucketCountAggregation = projection.body.aggs
|
const bucketCountAggregation = projection.body.aggs
|
||||||
? {
|
? {
|
||||||
|
|
|
@ -26,7 +26,7 @@ export async function getLocalUIFilters({
|
||||||
uiFilters: UIFilters;
|
uiFilters: UIFilters;
|
||||||
localFilterNames: LocalUIFilterName[];
|
localFilterNames: LocalUIFilterName[];
|
||||||
}) {
|
}) {
|
||||||
const { client, dynamicIndexPattern } = setup;
|
const { client } = setup;
|
||||||
|
|
||||||
const projectionWithoutAggs = cloneDeep(projection);
|
const projectionWithoutAggs = cloneDeep(projection);
|
||||||
|
|
||||||
|
@ -35,7 +35,6 @@ export async function getLocalUIFilters({
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
localFilterNames.map(async (name) => {
|
localFilterNames.map(async (name) => {
|
||||||
const query = getLocalFilterQuery({
|
const query = getLocalFilterQuery({
|
||||||
indexPattern: dynamicIndexPattern,
|
|
||||||
uiFilters,
|
uiFilters,
|
||||||
projection,
|
projection,
|
||||||
localUIFilterName: name,
|
localUIFilterName: name,
|
||||||
|
|
|
@ -9,6 +9,8 @@ import { createRoute } from './create_route';
|
||||||
import { setupRequest } from '../lib/helpers/setup_request';
|
import { setupRequest } from '../lib/helpers/setup_request';
|
||||||
import { getInternalSavedObjectsClient } from '../lib/helpers/get_internal_saved_objects_client';
|
import { getInternalSavedObjectsClient } from '../lib/helpers/get_internal_saved_objects_client';
|
||||||
import { getApmIndexPatternTitle } from '../lib/index_pattern/get_apm_index_pattern_title';
|
import { getApmIndexPatternTitle } from '../lib/index_pattern/get_apm_index_pattern_title';
|
||||||
|
import { getDynamicIndexPattern } from '../lib/index_pattern/get_dynamic_index_pattern';
|
||||||
|
import { getApmIndices } from '../lib/settings/apm_indices/get_apm_indices';
|
||||||
|
|
||||||
export const staticIndexPatternRoute = createRoute((core) => ({
|
export const staticIndexPatternRoute = createRoute((core) => ({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
@ -34,8 +36,17 @@ export const dynamicIndexPatternRoute = createRoute(() => ({
|
||||||
]),
|
]),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
handler: async ({ context, request }) => {
|
handler: async ({ context }) => {
|
||||||
const { dynamicIndexPattern } = await setupRequest(context, request);
|
const indices = await getApmIndices({
|
||||||
|
config: context.config,
|
||||||
|
savedObjectsClient: context.core.savedObjects.client,
|
||||||
|
});
|
||||||
|
|
||||||
|
const dynamicIndexPattern = await getDynamicIndexPattern({
|
||||||
|
context,
|
||||||
|
indices,
|
||||||
|
});
|
||||||
|
|
||||||
return { dynamicIndexPattern };
|
return { dynamicIndexPattern };
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -97,10 +97,7 @@ function createLocalFiltersRoute<
|
||||||
query,
|
query,
|
||||||
setup: {
|
setup: {
|
||||||
...setup,
|
...setup,
|
||||||
uiFiltersES: getUiFiltersES(
|
uiFiltersES: getUiFiltersES(omit(parsedUiFilters, filterNames)),
|
||||||
setup.dynamicIndexPattern,
|
|
||||||
omit(parsedUiFilters, filterNames)
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue