Skip to content

Commit 712c4bd

Browse files
[APM] Prevent imports of public in server code (#75979)
* renaming test file * removing eslint rule * restructuring observability types * refactoring fetchOptions type
1 parent 86870d2 commit 712c4bd

File tree

26 files changed

+159
-34
lines changed

26 files changed

+159
-34
lines changed

.eslintrc.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,7 @@ module.exports = {
296296
errorMessage: `Plugins may only import from src/core/server and src/core/public.`,
297297
},
298298
{
299-
target: [
300-
'(src|x-pack)/plugins/*/server/**/*',
301-
'!x-pack/plugins/apm/**/*', // https://github.com/elastic/kibana/issues/67210
302-
],
299+
target: ['(src|x-pack)/plugins/*/server/**/*'],
303300
from: ['(src|x-pack)/plugins/*/public/**/*'],
304301
errorMessage: `Server code can not import from public, use a common directory.`,
305302
},
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { HttpFetchOptions } from 'kibana/public';
8+
9+
export type FetchOptions = Omit<HttpFetchOptions, 'body'> & {
10+
pathname: string;
11+
isCachable?: boolean;
12+
method?: string;
13+
body?: any;
14+
};

x-pack/plugins/apm/public/hooks/useCallApi.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
*/
66

77
import { useMemo } from 'react';
8-
import { callApi, FetchOptions } from '../services/rest/callApi';
8+
import { callApi } from '../services/rest/callApi';
99
import { useApmPluginContext } from './useApmPluginContext';
10+
import { FetchOptions } from '../../common/fetch_options';
1011

1112
export function useCallApi() {
1213
const { http } = useApmPluginContext().core;

x-pack/plugins/apm/public/services/rest/callApi.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,11 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7+
import { HttpSetup } from 'kibana/public';
78
import { isString, startsWith } from 'lodash';
89
import LRU from 'lru-cache';
910
import hash from 'object-hash';
10-
import { HttpSetup, HttpFetchOptions } from 'kibana/public';
11-
12-
export type FetchOptions = Omit<HttpFetchOptions, 'body'> & {
13-
pathname: string;
14-
isCachable?: boolean;
15-
method?: string;
16-
body?: any;
17-
};
11+
import { FetchOptions } from '../../../common/fetch_options';
1812

1913
function fetchOptionsWithDebug(fetchOptions: FetchOptions) {
2014
const debugEnabled =

x-pack/plugins/apm/public/services/rest/createCallApmApi.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66
import { HttpSetup } from 'kibana/public';
7-
import { callApi, FetchOptions } from './callApi';
7+
import { FetchOptions } from '../../../common/fetch_options';
8+
import { callApi } from './callApi';
89
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
910
import { APMAPI } from '../../../server/routes/create_apm_api';
1011
// eslint-disable-next-line @kbn/eslint/no-restricted-paths

x-pack/plugins/apm/server/lib/environments/get_all_environments.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { getAllEnvironments } from './get_all_environments';
88
import {
99
SearchParamsMock,
1010
inspectSearchParams,
11-
} from '../../../public/utils/testHelpers';
11+
} from '../../utils/test_helpers';
1212

1313
describe('getAllEnvironments', () => {
1414
let mock: SearchParamsMock;

x-pack/plugins/apm/server/lib/errors/distribution/queries.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { getErrorDistribution } from './get_distribution';
88
import {
99
SearchParamsMock,
1010
inspectSearchParams,
11-
} from '../../../../public/utils/testHelpers';
11+
} from '../../../utils/test_helpers';
1212

1313
describe('error distribution queries', () => {
1414
let mock: SearchParamsMock;

x-pack/plugins/apm/server/lib/errors/queries.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { getErrorGroups } from './get_error_groups';
99
import {
1010
SearchParamsMock,
1111
inspectSearchParams,
12-
} from '../../../public/utils/testHelpers';
12+
} from '../../utils/test_helpers';
1313

1414
describe('error queries', () => {
1515
let mock: SearchParamsMock;

x-pack/plugins/apm/server/lib/metrics/queries.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { getThreadCountChart } from './by_agent/java/thread_count';
1212
import {
1313
SearchParamsMock,
1414
inspectSearchParams,
15-
} from '../../../public/utils/testHelpers';
15+
} from '../../utils/test_helpers';
1616
import { SERVICE_NODE_NAME_MISSING } from '../../../common/service_nodes';
1717

1818
describe('metrics queries', () => {

x-pack/plugins/apm/server/lib/observability_overview/get_transaction_coordinates.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* you may not use this file except in compliance with the Elastic License.
1010
*/
1111
import { rangeFilter } from '../../../common/utils/range_filter';
12-
import { Coordinates } from '../../../../observability/public';
12+
import { Coordinates } from '../../../../observability/typings/common';
1313
import { Setup, SetupTimeRange } from '../helpers/setup_request';
1414
import { ProcessorEvent } from '../../../common/processor_event';
1515

0 commit comments

Comments
 (0)