mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
* [APM] Fix anomalies not showing up on transaction charts * Added API tests to check transaction groups charts for anomaly data * Improve test names and assertions from PR feedback * Updated the transaction groups chart API to make `environment` a required param while making `uiFilters` optional * updates the basic API tests for transaction_groups/charts with the required `environment` param * makes uiFIltersES default to [] on core setup and removes SetupUIFilters type * fixes vertical shade * - replaces uiFiltersES with esFilter & uiFilters and cleans up related code around these - deduplicates the required environment in the transaction_groups/charts API * updates basic apm_api_integration tests * pr feedback * updates api test snapshots with correct anomaly data * removed environment query param from useTransactionCharts and ensures it's included in uiFilters returned from useUrlParams Co-authored-by: Oliver Gupte <olivergupte@gmail.com> # Conflicts: # x-pack/plugins/apm/public/utils/testHelpers.tsx # x-pack/plugins/apm/server/lib/rum_client/get_long_task_metrics.ts Co-authored-by: Søren Louv-Jansen <sorenlouv@gmail.com>
134 lines
3.9 KiB
TypeScript
134 lines
3.9 KiB
TypeScript
/*
|
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
* or more contributor license agreements. Licensed under the Elastic License;
|
|
* you may not use this file except in compliance with the Elastic License.
|
|
*/
|
|
|
|
import moment from 'moment';
|
|
import { Logger } from 'kibana/server';
|
|
import { isActivePlatinumLicense } from '../../../common/service_map';
|
|
import { UI_SETTINGS } from '../../../../../../src/plugins/data/common';
|
|
import { KibanaRequest } from '../../../../../../src/core/server';
|
|
import { APMConfig } from '../..';
|
|
import {
|
|
getApmIndices,
|
|
ApmIndicesConfig,
|
|
} from '../settings/apm_indices/get_apm_indices';
|
|
import { ESFilter } from '../../../typings/elasticsearch';
|
|
import { getEsFilter } from './convert_ui_filters/get_es_filter';
|
|
import { APMRequestHandlerContext } from '../../routes/typings';
|
|
import { ProcessorEvent } from '../../../common/processor_event';
|
|
import {
|
|
APMEventClient,
|
|
createApmEventClient,
|
|
} from './create_es_client/create_apm_event_client';
|
|
import {
|
|
APMInternalClient,
|
|
createInternalESClient,
|
|
} from './create_es_client/create_internal_es_client';
|
|
import { UIFilters } from '../../../typings/ui_filters';
|
|
|
|
// Explicitly type Setup to prevent TS initialization errors
|
|
// https://github.com/microsoft/TypeScript/issues/34933
|
|
|
|
export interface Setup {
|
|
apmEventClient: APMEventClient;
|
|
internalClient: APMInternalClient;
|
|
ml?: ReturnType<typeof getMlSetup>;
|
|
config: APMConfig;
|
|
indices: ApmIndicesConfig;
|
|
uiFilters: UIFilters;
|
|
esFilter: ESFilter[];
|
|
}
|
|
|
|
export interface SetupTimeRange {
|
|
start: number;
|
|
end: number;
|
|
}
|
|
|
|
interface SetupRequestParams {
|
|
query?: {
|
|
_debug?: boolean;
|
|
start?: string;
|
|
end?: string;
|
|
uiFilters?: string;
|
|
processorEvent?: ProcessorEvent;
|
|
};
|
|
}
|
|
|
|
type InferSetup<TParams extends SetupRequestParams> = Setup &
|
|
(TParams extends { query: { start: string } } ? { start: number } : {}) &
|
|
(TParams extends { query: { end: string } } ? { end: number } : {});
|
|
|
|
export async function setupRequest<TParams extends SetupRequestParams>(
|
|
context: APMRequestHandlerContext<TParams>,
|
|
request: KibanaRequest
|
|
): Promise<InferSetup<TParams>> {
|
|
const { config, logger } = context;
|
|
const { query } = context.params;
|
|
|
|
const [indices, includeFrozen] = await Promise.all([
|
|
getApmIndices({
|
|
savedObjectsClient: context.core.savedObjects.client,
|
|
config,
|
|
}),
|
|
context.core.uiSettings.client.get(UI_SETTINGS.SEARCH_INCLUDE_FROZEN),
|
|
]);
|
|
|
|
const uiFilters = decodeUiFilters(logger, query.uiFilters);
|
|
|
|
const coreSetupRequest = {
|
|
indices,
|
|
apmEventClient: createApmEventClient({
|
|
context,
|
|
request,
|
|
indices,
|
|
options: { includeFrozen },
|
|
}),
|
|
internalClient: createInternalESClient({
|
|
context,
|
|
request,
|
|
}),
|
|
ml:
|
|
context.plugins.ml && isActivePlatinumLicense(context.licensing.license)
|
|
? getMlSetup(
|
|
context.plugins.ml,
|
|
context.core.savedObjects.client,
|
|
request
|
|
)
|
|
: undefined,
|
|
config,
|
|
uiFilters,
|
|
esFilter: getEsFilter(uiFilters),
|
|
};
|
|
|
|
return {
|
|
...('start' in query ? { start: moment.utc(query.start).valueOf() } : {}),
|
|
...('end' in query ? { end: moment.utc(query.end).valueOf() } : {}),
|
|
...coreSetupRequest,
|
|
} as InferSetup<TParams>;
|
|
}
|
|
|
|
function getMlSetup(
|
|
ml: Required<APMRequestHandlerContext['plugins']>['ml'],
|
|
savedObjectsClient: APMRequestHandlerContext['core']['savedObjects']['client'],
|
|
request: KibanaRequest
|
|
) {
|
|
return {
|
|
mlSystem: ml.mlSystemProvider(request),
|
|
anomalyDetectors: ml.anomalyDetectorsProvider(request),
|
|
modules: ml.modulesProvider(request, savedObjectsClient),
|
|
};
|
|
}
|
|
|
|
function decodeUiFilters(logger: Logger, uiFiltersEncoded?: string): UIFilters {
|
|
if (!uiFiltersEncoded) {
|
|
return {};
|
|
}
|
|
try {
|
|
return JSON.parse(uiFiltersEncoded);
|
|
} catch (error) {
|
|
logger.error(error);
|
|
return {};
|
|
}
|
|
}
|