Skip to content

Commit

Permalink
move more
Browse files Browse the repository at this point in the history
  • Loading branch information
smith committed Feb 10, 2021
1 parent aacc18e commit 108c64e
Show file tree
Hide file tree
Showing 14 changed files with 143 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import { useHistory } from 'react-router-dom';
import { LocalUIFilterName } from '../../../../../common/ui_filter';
import { pickKeys } from '../../../../../common/utils/pick_keys';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { LocalUIFiltersAPIResponse } from '../../../../../server/lib/ui_filters/local_ui_filters';
import { LocalUIFiltersAPIResponse } from '../../../../../server/lib/rum_client/ui_filters/local_ui_filters';
import {
localUIFilters,
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
} from '../../../../../server/lib/ui_filters/local_ui_filters/config';
} from '../../../../../server/lib/rum_client/ui_filters/local_ui_filters/config';
import {
fromQuery,
toQuery,
Expand Down Expand Up @@ -72,7 +72,7 @@ export function useLocalUIFilters({
(callApmApi) => {
if (shouldFetch && urlParams.start && urlParams.end) {
return callApmApi({
endpoint: `GET /api/apm/ui_filters/local_filters/rumOverview`,
endpoint: 'GET /api/apm/rum/local_filters',
params: {
query: {
uiFilters: JSON.stringify(uiFilters),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Location } from 'history';
import { LatencyAggregationType } from '../../../common/latency_aggregation_types';
import { pickKeys } from '../../../common/utils/pick_keys';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { localUIFilterNames } from '../../../server/lib/ui_filters/local_ui_filters/config';
import { localUIFilterNames } from '../../../server/lib/rum_client/ui_filters/local_ui_filters/config';
import { toQuery } from '../../components/shared/Links/url_helpers';
import {
getDateRange,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { ENVIRONMENT_ALL } from '../../../common/environment_filter_values';
import { LocalUIFilterName } from '../../../common/ui_filter';
import { pickKeys } from '../../../common/utils/pick_keys';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { localUIFilterNames } from '../../../server/lib/ui_filters/local_ui_filters/config';
import { localUIFilterNames } from '../../../server/lib/rum_client/ui_filters/local_ui_filters/config';
import { UIFilters } from '../../../typings/ui_filters';
import { useDeepObjectIdentity } from '../../hooks/useDeepObjectIdentity';
import { getDateRange } from './helpers';
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
inspectSearchParams,
} from '../../utils/test_helpers';

describe('ui filter queries', () => {
describe('getEnvironments', () => {
let mock: SearchParamsMock;

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { getEnvironmentUiFilterES } from './get_environment_ui_filter_es';
import {
localUIFilters,
localUIFilterNames,
} from '../../ui_filters/local_ui_filters/config';
} from '../../rum_client/ui_filters/local_ui_filters/config';
import { esKuery } from '../../../../../../../src/plugins/data/server';

export function getEsFilter(uiFilters: UIFilters) {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
* 2.0.
*/

import { filtersByName, LocalUIFilterName } from '../../../../common/ui_filter';
import {
filtersByName,
LocalUIFilterName,
} from '../../../../../common/ui_filter';

export interface LocalUIFilter {
name: LocalUIFilterName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
*/

import { omit } from 'lodash';
import { mergeProjection } from '../../../projections/util/merge_projection';
import { Projection } from '../../../projections/typings';
import { UIFilters } from '../../../../typings/ui_filters';
import { getEsFilter } from '../../helpers/convert_ui_filters/get_es_filter';
import { mergeProjection } from '../../../../projections/util/merge_projection';
import { Projection } from '../../../../projections/typings';
import { UIFilters } from '../../../../../typings/ui_filters';
import { getEsFilter } from '../../../helpers/convert_ui_filters/get_es_filter';
import { localUIFilters } from './config';
import { LocalUIFilterName } from '../../../../common/ui_filter';
import { LocalUIFilterName } from '../../../../../common/ui_filter';

export const getLocalFilterQuery = ({
uiFilters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
* 2.0.
*/

import { getLocalUIFilters } from './';
import { getLocalUIFilters } from '.';
import {
SearchParamsMock,
inspectSearchParams,
} from '../../../utils/test_helpers';
import { getServicesProjection } from '../../../projections/services';
} from '../../../../utils/test_helpers';
import { getServicesProjection } from '../../../../projections/services';

describe('local ui filter queries', () => {
describe('getLocalUIFilters', () => {
let mock: SearchParamsMock;

beforeEach(() => {
jest.mock('../../helpers/convert_ui_filters/get_es_filter', () => {
jest.mock('../../../helpers/convert_ui_filters/get_es_filter', () => {
return [];
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
*/

import { cloneDeep, orderBy } from 'lodash';
import { UIFilters } from '../../../../typings/ui_filters';
import { Projection } from '../../../projections/typings';
import { PromiseReturnType } from '../../../../../observability/typings/common';
import { UIFilters } from '../../../../../typings/ui_filters';
import { Projection } from '../../../../projections/typings';
import { PromiseReturnType } from '../../../../../../observability/typings/common';
import { getLocalFilterQuery } from './get_local_filter_query';
import { Setup } from '../../helpers/setup_request';
import { Setup } from '../../../helpers/setup_request';
import { localUIFilters } from './config';
import { LocalUIFilterName } from '../../../../common/ui_filter';
import { LocalUIFilterName } from '../../../../../common/ui_filter';

export type LocalUIFiltersAPIResponse = PromiseReturnType<
typeof getLocalUIFilters
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/apm/server/routes/create_apm_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ import {
transactionLatencyChatsRoute,
transactionThroughputChatsRoute,
} from './transactions';
import { rumOverviewLocalFiltersRoute } from './ui_filters';
import { serviceMapRoute, serviceMapServiceNodeRoute } from './service_map';
import {
createCustomLinkRoute,
Expand All @@ -89,6 +88,7 @@ import {
rumClientMetricsRoute,
rumJSErrors,
rumLongTaskMetrics,
rumOverviewLocalFiltersRoute,
rumPageLoadDistBreakdownRoute,
rumPageLoadDistributionRoute,
rumPageViewsTrendRoute,
Expand Down
120 changes: 113 additions & 7 deletions x-pack/plugins/apm/server/routes/rum_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,33 @@
*/

import * as t from 'io-ts';
import { createRoute } from './create_route';
import { setupRequest } from '../lib/helpers/setup_request';
import { omit } from 'lodash';
import { jsonRt } from '../../common/runtime_types/json_rt';
import { LocalUIFilterName } from '../../common/ui_filter';
import { getEsFilter } from '../lib/helpers/convert_ui_filters/get_es_filter';
import {
Setup,
setupRequest,
SetupTimeRange,
} from '../lib/helpers/setup_request';
import { getClientMetrics } from '../lib/rum_client/get_client_metrics';
import { rangeRt, uiFiltersRt } from './default_api_types';
import { getPageViewTrends } from '../lib/rum_client/get_page_view_trends';
import { getJSErrors } from '../lib/rum_client/get_js_errors';
import { getLongTaskMetrics } from '../lib/rum_client/get_long_task_metrics';
import { getPageLoadDistribution } from '../lib/rum_client/get_page_load_distribution';
import { getPageViewTrends } from '../lib/rum_client/get_page_view_trends';
import { getPageLoadDistBreakdown } from '../lib/rum_client/get_pl_dist_breakdown';
import { getRumServices } from '../lib/rum_client/get_rum_services';
import { getUrlSearch } from '../lib/rum_client/get_url_search';
import { getVisitorBreakdown } from '../lib/rum_client/get_visitor_breakdown';
import { getWebCoreVitals } from '../lib/rum_client/get_web_core_vitals';
import { getJSErrors } from '../lib/rum_client/get_js_errors';
import { getLongTaskMetrics } from '../lib/rum_client/get_long_task_metrics';
import { getUrlSearch } from '../lib/rum_client/get_url_search';
import { hasRumData } from '../lib/rum_client/has_rum_data';
import { getLocalUIFilters } from '../lib/rum_client/ui_filters/local_ui_filters';
import { localUIFilterNames } from '../lib/rum_client/ui_filters/local_ui_filters/config';
import { getRumPageLoadTransactionsProjection } from '../projections/rum_page_load_transactions';
import { Projection } from '../projections/typings';
import { createRoute } from './create_route';
import { rangeRt, uiFiltersRt } from './default_api_types';
import { APMRequestHandlerContext } from './typings';

export const percentileRangeRt = t.partial({
minPercentile: t.string,
Expand Down Expand Up @@ -253,3 +266,96 @@ export const rumHasDataRoute = createRoute({
return await hasRumData({ setup });
},
});

// Everything below here was originally in ui_filters.ts but now is here, since
// UX is the only part of APM using UI filters now.

const filterNamesRt = t.type({
filterNames: jsonRt.pipe(
t.array(
t.keyof(
Object.fromEntries(
localUIFilterNames.map((filterName) => [filterName, null])
) as Record<LocalUIFilterName, null>
)
)
),
});

const localUiBaseQueryRt = t.intersection([
filterNamesRt,
uiFiltersRt,
rangeRt,
]);

function createLocalFiltersRoute<
TEndpoint extends string,
TProjection extends Projection,
TQueryRT extends t.HasProps
>({
endpoint,
getProjection,
queryRt,
}: {
endpoint: TEndpoint;
getProjection: GetProjection<
TProjection,
t.IntersectionC<[TQueryRT, BaseQueryType]>
>;
queryRt: TQueryRT;
}) {
return createRoute({
endpoint,
params: t.type({
query: t.intersection([localUiBaseQueryRt, queryRt]),
}),
options: { tags: ['access:apm'] },
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);
const { uiFilters } = setup;
const { query } = context.params;

const { filterNames } = query;
const projection = await getProjection({
query,
context,
setup: {
...setup,
esFilter: getEsFilter(omit(uiFilters, filterNames)),
},
});

return getLocalUIFilters({
projection,
setup,
uiFilters,
localFilterNames: filterNames,
});
},
});
}

export const rumOverviewLocalFiltersRoute = createLocalFiltersRoute({
endpoint: 'GET /api/apm/rum/local_filters',
getProjection: async ({ setup }) => {
return getRumPageLoadTransactionsProjection({
setup,
});
},
queryRt: t.type({}),
});

type BaseQueryType = typeof localUiBaseQueryRt;

type GetProjection<
TProjection extends Projection,
TQueryRT extends t.HasProps
> = ({
query,
setup,
context,
}: {
query: t.TypeOf<TQueryRT>;
setup: Setup & SetupTimeRange;
context: APMRequestHandlerContext;
}) => Promise<TProjection> | TProjection;
Loading

0 comments on commit 108c64e

Please sign in to comment.