Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move ui_filters API endpoints #90900

Merged
merged 8 commits into from
Feb 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default {
core: {
http: {
get: (endpoint: string) => {
if (endpoint === '/api/apm/ui_filters/environments') {
if (endpoint === '/api/apm/environments') {
return Promise.resolve(['production']);
} else {
return Promise.resolve({
Expand Down
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 { TimeRangeComparisonType } from '../../components/shared/time_comparison/get_time_range_comparison';
import {
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
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function useEnvironmentsFetcher({
(callApmApi) => {
if (start && end) {
return callApmApi({
endpoint: 'GET /api/apm/ui_filters/environments',
endpoint: 'GET /api/apm/environments',
params: {
query: {
start,
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 @@ -15,6 +15,10 @@ import { ENVIRONMENT_NOT_DEFINED } from '../../../common/environment_filter_valu
import { getProcessorEventForAggregatedTransactions } from '../helpers/aggregated_transactions';
import { withApmSpan } from '../../utils/with_apm_span';

/**
* This is used for getting *all* environments, and does not filter by range.
* It's used in places where we get the list of all possible environments.
*/
export async function getAllEnvironments({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to rename it to dangerousGetEnvironmentsSinceBeginningOfTime to highlight this

serviceName,
setup,
Expand Down
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 @@ -17,6 +17,10 @@ import { withApmSpan } from '../../utils/with_apm_span';
import { getProcessorEventForAggregatedTransactions } from '../helpers/aggregated_transactions';
import { Setup, SetupTimeRange } from '../helpers/setup_request';

/**
* This is used for getting the list of environments for the environments selector,
* filtered by range.
*/
export async function getEnvironments({
setup,
serviceName,
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,14 +6,14 @@
*/

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 { withApmSpan } from '../../../utils/with_apm_span';
import { LocalUIFilterName } from '../../../../../common/ui_filter';
import { withApmSpan } from '../../../../utils/with_apm_span';

export type LocalUIFiltersAPIResponse = PromiseReturnType<
typeof getLocalUIFilters
Expand Down
12 changes: 5 additions & 7 deletions x-pack/plugins/apm/server/routes/create_apm_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
apmIndexPatternTitleRoute,
} from './index_pattern';
import { createApi } from './create_api';
import { environmentsRoute } from './environments';
import {
errorDistributionRoute,
errorGroupsRoute,
Expand Down Expand Up @@ -66,10 +67,6 @@ import {
transactionThroughputChatsRoute,
transactionGroupsComparisonStatisticsRoute,
} from './transactions';
import {
rumOverviewLocalFiltersRoute,
uiFiltersEnvironmentsRoute,
} from './ui_filters';
import { serviceMapRoute, serviceMapServiceNodeRoute } from './service_map';
import {
createCustomLinkRoute,
Expand All @@ -92,6 +89,7 @@ import {
rumClientMetricsRoute,
rumJSErrors,
rumLongTaskMetrics,
rumOverviewLocalFiltersRoute,
rumPageLoadDistBreakdownRoute,
rumPageLoadDistributionRoute,
rumPageViewsTrendRoute,
Expand All @@ -113,6 +111,9 @@ const createApmApi = () => {
.add(dynamicIndexPatternRoute)
.add(apmIndexPatternTitleRoute)

// Environments
.add(environmentsRoute)

// Errors
.add(errorDistributionRoute)
.add(errorGroupsRoute)
Expand Down Expand Up @@ -170,9 +171,6 @@ const createApmApi = () => {
.add(transactionThroughputChatsRoute)
.add(transactionGroupsComparisonStatisticsRoute)

// UI filters
.add(uiFiltersEnvironmentsRoute)

// Service map
.add(serviceMapRoute)
.add(serviceMapServiceNodeRoute)
Expand Down
39 changes: 39 additions & 0 deletions x-pack/plugins/apm/server/routes/environments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import * as t from 'io-ts';
import { getSearchAggregatedTransactions } from '../lib/helpers/aggregated_transactions';
import { setupRequest } from '../lib/helpers/setup_request';
import { getEnvironments } from '../lib/environments/get_environments';
import { createRoute } from './create_route';
import { rangeRt } from './default_api_types';

export const environmentsRoute = createRoute({
endpoint: 'GET /api/apm/environments',
params: t.type({
query: t.intersection([
t.partial({
serviceName: t.string,
}),
rangeRt,
]),
}),
options: { tags: ['access:apm'] },
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);
const { serviceName } = context.params.query;
const searchAggregatedTransactions = await getSearchAggregatedTransactions(
setup
);

return getEnvironments({
setup,
serviceName,
searchAggregatedTransactions,
});
},
});
Loading