[APM] [User Experience] remove uiFilters from setupRequest (#109908)
* remove uiFilters from setupRequest * adjust get_buckets test * update getAnomalySeries Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
bb9ea8413f
commit
6e8d86b3e7
|
@ -44,7 +44,6 @@ describe('get buckets', () => {
|
|||
get: () => 'myIndex',
|
||||
}
|
||||
) as APMConfig,
|
||||
uiFilters: {},
|
||||
indices: {
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
'apm_oss.sourcemapIndices': 'apm-*',
|
||||
|
|
|
@ -5,12 +5,10 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { Logger } from 'kibana/server';
|
||||
import { isActivePlatinumLicense } from '../../../common/license_check';
|
||||
import { APMConfig } from '../..';
|
||||
import { KibanaRequest } from '../../../../../../src/core/server';
|
||||
import { UI_SETTINGS } from '../../../../../../src/plugins/data/common';
|
||||
import { UxUIFilters } from '../../../typings/ui_filters';
|
||||
import { APMRouteHandlerResources } from '../../routes/typings';
|
||||
import {
|
||||
ApmIndicesConfig,
|
||||
|
@ -35,7 +33,6 @@ export interface Setup {
|
|||
ml?: ReturnType<typeof getMlSetup>;
|
||||
config: APMConfig;
|
||||
indices: ApmIndicesConfig;
|
||||
uiFilters: UxUIFilters;
|
||||
}
|
||||
|
||||
export interface SetupTimeRange {
|
||||
|
@ -43,7 +40,7 @@ export interface SetupTimeRange {
|
|||
end: number;
|
||||
}
|
||||
|
||||
interface SetupRequestParams {
|
||||
export interface SetupRequestParams {
|
||||
query: {
|
||||
_inspect?: boolean;
|
||||
|
||||
|
@ -56,7 +53,6 @@ interface SetupRequestParams {
|
|||
* Timestamp in ms since epoch
|
||||
*/
|
||||
end?: number;
|
||||
uiFilters?: string;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -74,7 +70,6 @@ export async function setupRequest<TParams extends SetupRequestParams>({
|
|||
plugins,
|
||||
request,
|
||||
config,
|
||||
logger,
|
||||
}: APMRouteHandlerResources & {
|
||||
params: TParams;
|
||||
}): Promise<InferSetup<TParams>> {
|
||||
|
@ -91,8 +86,6 @@ export async function setupRequest<TParams extends SetupRequestParams>({
|
|||
),
|
||||
]);
|
||||
|
||||
const uiFilters = decodeUiFilters(logger, query.uiFilters);
|
||||
|
||||
const coreSetupRequest = {
|
||||
indices,
|
||||
apmEventClient: createApmEventClient({
|
||||
|
@ -116,7 +109,6 @@ export async function setupRequest<TParams extends SetupRequestParams>({
|
|||
)
|
||||
: undefined,
|
||||
config,
|
||||
uiFilters,
|
||||
};
|
||||
|
||||
return {
|
||||
|
@ -138,18 +130,3 @@ function getMlSetup(
|
|||
modules: ml.modulesProvider(request, savedObjectsClient),
|
||||
};
|
||||
}
|
||||
|
||||
function decodeUiFilters(
|
||||
logger: Logger,
|
||||
uiFiltersEncoded?: string
|
||||
): UxUIFilters {
|
||||
if (!uiFiltersEncoded) {
|
||||
return {};
|
||||
}
|
||||
try {
|
||||
return JSON.parse(uiFiltersEncoded);
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
|
||||
import { getRumPageLoadTransactionsProjection } from '../../projections/rum_page_load_transactions';
|
||||
import { mergeProjection } from '../../projections/util/merge_projection';
|
||||
import { Setup, SetupTimeRange } from '../helpers/setup_request';
|
||||
import { SetupTimeRange } from '../helpers/setup_request';
|
||||
import { SetupUX } from '../../routes/rum_client';
|
||||
import {
|
||||
TRANSACTION_TIME_TO_FIRST_BYTE,
|
||||
TRANSACTION_DURATION,
|
||||
|
@ -18,7 +19,7 @@ export async function getClientMetrics({
|
|||
urlQuery,
|
||||
percentile = 50,
|
||||
}: {
|
||||
setup: Setup & SetupTimeRange;
|
||||
setup: SetupUX & SetupTimeRange;
|
||||
urlQuery?: string;
|
||||
percentile?: number;
|
||||
}) {
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
*/
|
||||
|
||||
import { mergeProjection } from '../../projections/util/merge_projection';
|
||||
import { Setup, SetupTimeRange } from '../helpers/setup_request';
|
||||
import { SetupTimeRange } from '../helpers/setup_request';
|
||||
import { SetupUX } from '../../routes/rum_client';
|
||||
import { getRumErrorsProjection } from '../../projections/rum_page_load_transactions';
|
||||
import {
|
||||
ERROR_EXC_MESSAGE,
|
||||
|
@ -23,7 +24,7 @@ export async function getJSErrors({
|
|||
pageIndex,
|
||||
urlQuery,
|
||||
}: {
|
||||
setup: Setup & SetupTimeRange;
|
||||
setup: SetupUX & SetupTimeRange;
|
||||
pageSize: number;
|
||||
pageIndex: number;
|
||||
urlQuery?: string;
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
|
||||
import { getRumPageLoadTransactionsProjection } from '../../projections/rum_page_load_transactions';
|
||||
import { mergeProjection } from '../../projections/util/merge_projection';
|
||||
import { Setup, SetupTimeRange } from '../helpers/setup_request';
|
||||
import { SetupTimeRange } from '../helpers/setup_request';
|
||||
import { SetupUX } from '../../routes/rum_client';
|
||||
|
||||
const LONG_TASK_SUM_FIELD = 'transaction.experience.longtask.sum';
|
||||
const LONG_TASK_COUNT_FIELD = 'transaction.experience.longtask.count';
|
||||
|
@ -18,7 +19,7 @@ export async function getLongTaskMetrics({
|
|||
urlQuery,
|
||||
percentile = 50,
|
||||
}: {
|
||||
setup: Setup & SetupTimeRange;
|
||||
setup: SetupUX & SetupTimeRange;
|
||||
urlQuery?: string;
|
||||
percentile?: number;
|
||||
}) {
|
||||
|
|
|
@ -8,7 +8,8 @@
|
|||
import { TRANSACTION_DURATION } from '../../../common/elasticsearch_fieldnames';
|
||||
import { getRumPageLoadTransactionsProjection } from '../../projections/rum_page_load_transactions';
|
||||
import { mergeProjection } from '../../projections/util/merge_projection';
|
||||
import { Setup, SetupTimeRange } from '../helpers/setup_request';
|
||||
import { SetupTimeRange } from '../helpers/setup_request';
|
||||
import { SetupUX } from '../../routes/rum_client';
|
||||
|
||||
export const MICRO_TO_SEC = 1000000;
|
||||
|
||||
|
@ -64,7 +65,7 @@ export async function getPageLoadDistribution({
|
|||
maxPercentile,
|
||||
urlQuery,
|
||||
}: {
|
||||
setup: Setup & SetupTimeRange;
|
||||
setup: SetupUX & SetupTimeRange;
|
||||
minPercentile?: string;
|
||||
maxPercentile?: string;
|
||||
urlQuery?: string;
|
||||
|
@ -176,7 +177,7 @@ const getPercentilesDistribution = async ({
|
|||
minDuration,
|
||||
maxDuration,
|
||||
}: {
|
||||
setup: Setup & SetupTimeRange;
|
||||
setup: SetupUX & SetupTimeRange;
|
||||
minDuration: number;
|
||||
maxDuration: number;
|
||||
}) => {
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
|
||||
import { getRumPageLoadTransactionsProjection } from '../../projections/rum_page_load_transactions';
|
||||
import { mergeProjection } from '../../projections/util/merge_projection';
|
||||
import { Setup, SetupTimeRange } from '../helpers/setup_request';
|
||||
import { SetupTimeRange } from '../helpers/setup_request';
|
||||
import { SetupUX } from '../../routes/rum_client';
|
||||
import { BreakdownItem } from '../../../typings/ui_filters';
|
||||
|
||||
export async function getPageViewTrends({
|
||||
|
@ -15,7 +16,7 @@ export async function getPageViewTrends({
|
|||
breakdowns,
|
||||
urlQuery,
|
||||
}: {
|
||||
setup: Setup & SetupTimeRange;
|
||||
setup: SetupUX & SetupTimeRange;
|
||||
breakdowns?: string;
|
||||
urlQuery?: string;
|
||||
}) {
|
||||
|
|
|
@ -8,7 +8,8 @@
|
|||
import { getRumPageLoadTransactionsProjection } from '../../projections/rum_page_load_transactions';
|
||||
import { ProcessorEvent } from '../../../common/processor_event';
|
||||
import { mergeProjection } from '../../projections/util/merge_projection';
|
||||
import { Setup, SetupTimeRange } from '../helpers/setup_request';
|
||||
import { SetupTimeRange } from '../helpers/setup_request';
|
||||
import { SetupUX } from '../../routes/rum_client';
|
||||
import {
|
||||
CLIENT_GEO_COUNTRY_ISO_CODE,
|
||||
USER_AGENT_DEVICE,
|
||||
|
@ -44,7 +45,7 @@ export const getPageLoadDistBreakdown = async ({
|
|||
breakdown,
|
||||
urlQuery,
|
||||
}: {
|
||||
setup: Setup & SetupTimeRange;
|
||||
setup: SetupUX & SetupTimeRange;
|
||||
minPercentile: number;
|
||||
maxPercentile: number;
|
||||
breakdown: string;
|
||||
|
|
|
@ -4,16 +4,16 @@
|
|||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { SERVICE_NAME } from '../../../common/elasticsearch_fieldnames';
|
||||
import { Setup, SetupTimeRange } from '../helpers/setup_request';
|
||||
import { SetupTimeRange } from '../helpers/setup_request';
|
||||
import { SetupUX } from '../../routes/rum_client';
|
||||
import { getRumPageLoadTransactionsProjection } from '../../projections/rum_page_load_transactions';
|
||||
import { mergeProjection } from '../../projections/util/merge_projection';
|
||||
|
||||
export async function getRumServices({
|
||||
setup,
|
||||
}: {
|
||||
setup: Setup & SetupTimeRange;
|
||||
setup: SetupUX & SetupTimeRange;
|
||||
}) {
|
||||
const projection = getRumPageLoadTransactionsProjection({
|
||||
setup,
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
*/
|
||||
|
||||
import { mergeProjection } from '../../projections/util/merge_projection';
|
||||
import { Setup, SetupTimeRange } from '../helpers/setup_request';
|
||||
import { SetupTimeRange } from '../helpers/setup_request';
|
||||
import { SetupUX } from '../../routes/rum_client';
|
||||
import { getRumPageLoadTransactionsProjection } from '../../projections/rum_page_load_transactions';
|
||||
import {
|
||||
TRANSACTION_DURATION,
|
||||
|
@ -18,7 +19,7 @@ export async function getUrlSearch({
|
|||
urlQuery,
|
||||
percentile,
|
||||
}: {
|
||||
setup: Setup & SetupTimeRange;
|
||||
setup: SetupUX & SetupTimeRange;
|
||||
urlQuery?: string;
|
||||
percentile: number;
|
||||
}) {
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
|
||||
import { getRumPageLoadTransactionsProjection } from '../../projections/rum_page_load_transactions';
|
||||
import { mergeProjection } from '../../projections/util/merge_projection';
|
||||
import { Setup, SetupTimeRange } from '../helpers/setup_request';
|
||||
import { SetupTimeRange } from '../helpers/setup_request';
|
||||
import { SetupUX } from '../../routes/rum_client';
|
||||
import {
|
||||
USER_AGENT_NAME,
|
||||
USER_AGENT_OS,
|
||||
|
@ -17,7 +18,7 @@ export async function getVisitorBreakdown({
|
|||
setup,
|
||||
urlQuery,
|
||||
}: {
|
||||
setup: Setup & SetupTimeRange;
|
||||
setup: SetupUX & SetupTimeRange;
|
||||
urlQuery?: string;
|
||||
}) {
|
||||
const projection = getRumPageLoadTransactionsProjection({
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
|
||||
import { getRumPageLoadTransactionsProjection } from '../../projections/rum_page_load_transactions';
|
||||
import { mergeProjection } from '../../projections/util/merge_projection';
|
||||
import { Setup, SetupTimeRange } from '../helpers/setup_request';
|
||||
import { SetupTimeRange } from '../helpers/setup_request';
|
||||
import { SetupUX } from '../../routes/rum_client';
|
||||
import {
|
||||
CLS_FIELD,
|
||||
FCP_FIELD,
|
||||
|
@ -21,7 +22,7 @@ export async function getWebCoreVitals({
|
|||
urlQuery,
|
||||
percentile = 50,
|
||||
}: {
|
||||
setup: Setup & SetupTimeRange;
|
||||
setup: SetupUX & SetupTimeRange;
|
||||
urlQuery?: string;
|
||||
percentile?: number;
|
||||
}) {
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { Setup, SetupTimeRange } from '../helpers/setup_request';
|
||||
import { SetupTimeRange } from '../helpers/setup_request';
|
||||
import { SetupUX } from '../../routes/rum_client';
|
||||
import {
|
||||
SERVICE_NAME,
|
||||
TRANSACTION_TYPE,
|
||||
|
@ -17,7 +18,7 @@ import { TRANSACTION_PAGE_LOAD } from '../../../common/transaction_types';
|
|||
export async function hasRumData({
|
||||
setup,
|
||||
}: {
|
||||
setup: Setup & Partial<SetupTimeRange>;
|
||||
setup: SetupUX & Partial<SetupTimeRange>;
|
||||
}) {
|
||||
try {
|
||||
const { start, end } = setup;
|
||||
|
|
|
@ -22,6 +22,7 @@ export async function getAnomalySeries({
|
|||
serviceName,
|
||||
transactionType,
|
||||
transactionName,
|
||||
kuery,
|
||||
setup,
|
||||
logger,
|
||||
}: {
|
||||
|
@ -29,6 +30,7 @@ export async function getAnomalySeries({
|
|||
serviceName: string;
|
||||
transactionType: string;
|
||||
transactionName?: string;
|
||||
kuery: string;
|
||||
setup: Setup & SetupTimeRange;
|
||||
logger: Logger;
|
||||
}) {
|
||||
|
@ -50,13 +52,8 @@ export async function getAnomalySeries({
|
|||
return undefined;
|
||||
}
|
||||
|
||||
// Don't fetch anomalies if uiFilters are applied. This filters out anything
|
||||
// with empty values so `kuery: ''` returns false but `kuery: 'x:y'` returns true.
|
||||
const hasUiFiltersApplied =
|
||||
Object.entries(setup.uiFilters).filter(([_key, value]) => !!value).length >
|
||||
0;
|
||||
|
||||
if (hasUiFiltersApplied) {
|
||||
// Don't fetch anomalies if kuery is present
|
||||
if (kuery) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { Setup, SetupTimeRange } from '../../server/lib/helpers/setup_request';
|
||||
import { SetupTimeRange } from '../../server/lib/helpers/setup_request';
|
||||
import { SetupUX } from '../routes/rum_client';
|
||||
import {
|
||||
AGENT_NAME,
|
||||
TRANSACTION_TYPE,
|
||||
|
@ -21,7 +22,7 @@ export function getRumPageLoadTransactionsProjection({
|
|||
urlQuery,
|
||||
checkFetchStartFieldExists = true,
|
||||
}: {
|
||||
setup: Setup & SetupTimeRange;
|
||||
setup: SetupUX & SetupTimeRange;
|
||||
urlQuery?: string;
|
||||
checkFetchStartFieldExists?: boolean;
|
||||
}) {
|
||||
|
@ -72,7 +73,7 @@ export function getRumErrorsProjection({
|
|||
setup,
|
||||
urlQuery,
|
||||
}: {
|
||||
setup: Setup & SetupTimeRange;
|
||||
setup: SetupUX & SetupTimeRange;
|
||||
urlQuery?: string;
|
||||
}) {
|
||||
const { start, end, uiFilters } = setup;
|
||||
|
|
|
@ -4,10 +4,14 @@
|
|||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import * as t from 'io-ts';
|
||||
import { Logger } from 'kibana/server';
|
||||
import { isoToEpochRt } from '@kbn/io-ts-utils';
|
||||
import { setupRequest } from '../lib/helpers/setup_request';
|
||||
import {
|
||||
setupRequest,
|
||||
Setup,
|
||||
SetupRequestParams,
|
||||
} from '../lib/helpers/setup_request';
|
||||
import { getClientMetrics } from '../lib/rum_client/get_client_metrics';
|
||||
import { getJSErrors } from '../lib/rum_client/get_js_errors';
|
||||
import { getLongTaskMetrics } from '../lib/rum_client/get_long_task_metrics';
|
||||
|
@ -22,6 +26,18 @@ import { hasRumData } from '../lib/rum_client/has_rum_data';
|
|||
import { createApmServerRoute } from './create_apm_server_route';
|
||||
import { createApmServerRouteRepository } from './create_apm_server_route_repository';
|
||||
import { rangeRt } from './default_api_types';
|
||||
import { UxUIFilters } from '../../typings/ui_filters';
|
||||
import { APMRouteHandlerResources } from '../routes/typings';
|
||||
|
||||
export type SetupUX = Setup & {
|
||||
uiFilters: UxUIFilters;
|
||||
};
|
||||
|
||||
type SetupUXRequestParams = Omit<SetupRequestParams, 'query'> & {
|
||||
query: SetupRequestParams['query'] & {
|
||||
uiFilters?: string;
|
||||
};
|
||||
};
|
||||
|
||||
export const percentileRangeRt = t.partial({
|
||||
minPercentile: t.string,
|
||||
|
@ -43,7 +59,7 @@ const rumClientMetricsRoute = createApmServerRoute({
|
|||
}),
|
||||
options: { tags: ['access:apm'] },
|
||||
handler: async (resources) => {
|
||||
const setup = await setupRequest(resources);
|
||||
const setup = await setupUXRequest(resources);
|
||||
|
||||
const {
|
||||
query: { urlQuery, percentile },
|
||||
|
@ -64,7 +80,7 @@ const rumPageLoadDistributionRoute = createApmServerRoute({
|
|||
}),
|
||||
options: { tags: ['access:apm'] },
|
||||
handler: async (resources) => {
|
||||
const setup = await setupRequest(resources);
|
||||
const setup = await setupUXRequest(resources);
|
||||
|
||||
const {
|
||||
query: { minPercentile, maxPercentile, urlQuery },
|
||||
|
@ -92,7 +108,7 @@ const rumPageLoadDistBreakdownRoute = createApmServerRoute({
|
|||
}),
|
||||
options: { tags: ['access:apm'] },
|
||||
handler: async (resources) => {
|
||||
const setup = await setupRequest(resources);
|
||||
const setup = await setupUXRequest(resources);
|
||||
|
||||
const {
|
||||
query: { minPercentile, maxPercentile, breakdown, urlQuery },
|
||||
|
@ -117,7 +133,7 @@ const rumPageViewsTrendRoute = createApmServerRoute({
|
|||
}),
|
||||
options: { tags: ['access:apm'] },
|
||||
handler: async (resources) => {
|
||||
const setup = await setupRequest(resources);
|
||||
const setup = await setupUXRequest(resources);
|
||||
|
||||
const {
|
||||
query: { breakdowns, urlQuery },
|
||||
|
@ -138,7 +154,7 @@ const rumServicesRoute = createApmServerRoute({
|
|||
}),
|
||||
options: { tags: ['access:apm'] },
|
||||
handler: async (resources) => {
|
||||
const setup = await setupRequest(resources);
|
||||
const setup = await setupUXRequest(resources);
|
||||
|
||||
const rumServices = await getRumServices({ setup });
|
||||
return { rumServices };
|
||||
|
@ -152,7 +168,7 @@ const rumVisitorsBreakdownRoute = createApmServerRoute({
|
|||
}),
|
||||
options: { tags: ['access:apm'] },
|
||||
handler: async (resources) => {
|
||||
const setup = await setupRequest(resources);
|
||||
const setup = await setupUXRequest(resources);
|
||||
|
||||
const {
|
||||
query: { urlQuery },
|
||||
|
@ -172,7 +188,7 @@ const rumWebCoreVitals = createApmServerRoute({
|
|||
}),
|
||||
options: { tags: ['access:apm'] },
|
||||
handler: async (resources) => {
|
||||
const setup = await setupRequest(resources);
|
||||
const setup = await setupUXRequest(resources);
|
||||
|
||||
const {
|
||||
query: { urlQuery, percentile },
|
||||
|
@ -193,7 +209,7 @@ const rumLongTaskMetrics = createApmServerRoute({
|
|||
}),
|
||||
options: { tags: ['access:apm'] },
|
||||
handler: async (resources) => {
|
||||
const setup = await setupRequest(resources);
|
||||
const setup = await setupUXRequest(resources);
|
||||
|
||||
const {
|
||||
query: { urlQuery, percentile },
|
||||
|
@ -214,7 +230,7 @@ const rumUrlSearch = createApmServerRoute({
|
|||
}),
|
||||
options: { tags: ['access:apm'] },
|
||||
handler: async (resources) => {
|
||||
const setup = await setupRequest(resources);
|
||||
const setup = await setupUXRequest(resources);
|
||||
|
||||
const {
|
||||
query: { urlQuery, percentile },
|
||||
|
@ -236,7 +252,7 @@ const rumJSErrors = createApmServerRoute({
|
|||
}),
|
||||
options: { tags: ['access:apm'] },
|
||||
handler: async (resources) => {
|
||||
const setup = await setupRequest(resources);
|
||||
const setup = await setupUXRequest(resources);
|
||||
|
||||
const {
|
||||
query: { pageSize, pageIndex, urlQuery },
|
||||
|
@ -262,11 +278,39 @@ const rumHasDataRoute = createApmServerRoute({
|
|||
}),
|
||||
options: { tags: ['access:apm'] },
|
||||
handler: async (resources) => {
|
||||
const setup = await setupRequest(resources);
|
||||
const setup = await setupUXRequest(resources);
|
||||
return await hasRumData({ setup });
|
||||
},
|
||||
});
|
||||
|
||||
function decodeUiFilters(
|
||||
logger: Logger,
|
||||
uiFiltersEncoded?: string
|
||||
): UxUIFilters {
|
||||
if (!uiFiltersEncoded) {
|
||||
return {};
|
||||
}
|
||||
try {
|
||||
return JSON.parse(uiFiltersEncoded);
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
async function setupUXRequest<TParams extends SetupUXRequestParams>(
|
||||
resources: APMRouteHandlerResources & { params: TParams }
|
||||
) {
|
||||
const setup = await setupRequest(resources);
|
||||
return {
|
||||
...setup,
|
||||
uiFilters: decodeUiFilters(
|
||||
resources.logger,
|
||||
resources.params.query.uiFilters
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
export const rumRouteRepository = createApmServerRouteRepository()
|
||||
.add(rumClientMetricsRoute)
|
||||
.add(rumPageLoadDistributionRoute)
|
||||
|
|
Loading…
Reference in a new issue