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 Elasticsearch type definitions out of APM #83081

Merged
merged 3 commits into from
Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Move Elasticsearch type definitions out of APM
...and into x-pack.

Also remove `PromiseReturnType` from APM and use the copy in observability everywhere.

All of the additional changes to APM imports are just automatic sorting.

This makes doing #77720 a little easier and removes some implicit circular dependencies for #80508.
  • Loading branch information
smith committed Nov 10, 2020
commit feffa04e18e50fc642f7d4d52b56c729c6ec0a52
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { ESFilter } from '../../../../../../typings/elasticsearch';
import {
ERROR_GROUP_ID,
PROCESSOR_EVENT,
Expand All @@ -12,7 +13,6 @@ import {
TRANSACTION_TYPE,
} from '../../../../common/elasticsearch_fieldnames';
import { UIProcessorEvent } from '../../../../common/processor_event';
import { ESFilter } from '../../../../typings/elasticsearch';
import { IUrlParams } from '../../../context/UrlParamsContext/types';

export function getBoolFilter({
Expand Down
20 changes: 10 additions & 10 deletions x-pack/plugins/apm/public/utils/testHelpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@

/* global jest */

import React from 'react';
import { ReactWrapper, mount, MountRendererProps } from 'enzyme';
import { render, waitFor } from '@testing-library/react';
import { mount, MountRendererProps, ReactWrapper } from 'enzyme';
import enzymeToJson from 'enzyme-to-json';
import { Location } from 'history';
import moment from 'moment';
import { Moment } from 'moment-timezone';
import { render, waitFor } from '@testing-library/react';
import React from 'react';
import { MemoryRouter } from 'react-router-dom';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { APMConfig } from '../../server';
import { PromiseReturnType } from '../../typings/common';
import { EuiThemeProvider } from '../../../observability/public';
import {
ESFilter,
ESSearchResponse,
ESSearchRequest,
} from '../../typings/elasticsearch';
ESSearchResponse,
} from '../../../../typings/elasticsearch';
import { EuiThemeProvider } from '../../../observability/public';
import { PromiseReturnType } from '../../../observability/typings/common';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { APMConfig } from '../../server';
import { UIFilters } from '../../typings/ui_filters';
import { MockApmPluginContextWrapper } from '../context/ApmPluginContext/MockApmPluginContext';
import { UrlParamsProvider } from '../context/UrlParamsContext';
import { UIFilters } from '../../typings/ui_filters';

const originalConsoleWarn = console.warn; // eslint-disable-line no-console
/**
Expand Down
5 changes: 4 additions & 1 deletion x-pack/plugins/apm/scripts/shared/get_es_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

import { Client } from '@elastic/elasticsearch';
import { ApiKeyAuth, BasicAuth } from '@elastic/elasticsearch/lib/pool';
import { ESSearchResponse, ESSearchRequest } from '../../typings/elasticsearch';
import {
ESSearchResponse,
ESSearchRequest,
} from '../../../../typings/elasticsearch';

export type ESClient = ReturnType<typeof getEsClient>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { isEmpty } from 'lodash';
import { Observable } from 'rxjs';
import { take } from 'rxjs/operators';
import { APMConfig } from '../..';
import { ESSearchResponse } from '../../../../../typings/elasticsearch';
import { AlertingPlugin } from '../../../../alerts/server';
import { AlertType, ALERT_TYPES_CONFIG } from '../../../common/alert_types';
import {
Expand All @@ -17,7 +18,6 @@ import {
SERVICE_NAME,
} from '../../../common/elasticsearch_fieldnames';
import { ProcessorEvent } from '../../../common/processor_event';
import { ESSearchResponse } from '../../../typings/elasticsearch';
import { getEnvironmentUiFilterES } from '../helpers/convert_ui_filters/get_environment_ui_filter_es';
import { getApmIndices } from '../settings/apm_indices/get_apm_indices';
import { apmActionVariables } from './action_variables';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
import { schema } from '@kbn/config-schema';
import { Observable } from 'rxjs';
import { take } from 'rxjs/operators';
import { getDurationFormatter } from '../../../common/utils/formatters';
import { ProcessorEvent } from '../../../common/processor_event';
Copy link
Member

@sorenlouv sorenlouv Nov 10, 2020

Choose a reason for hiding this comment

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

Didn't we previously have an eslint rule that'd strictly order the imports alphabetically? Then we'd avoid this kind of diff.

I use that for backport: https://github.com/sqren/backport/blob/9c41c5bcd559f1b1b7a782a940143d28d1027c79/.eslintrc.js#L25

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know, but once they are ordered properly this kind of diff doesn't need to happen again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The ordering I'm doing here is with VSCode's options-shift-o, which invokes TypeScript's organize imports feature.

We have some ordering rules in ESLint, but it doesn't fully check for TypeScript's suggested ordering. There's an open issue (typescript-eslint/typescript-eslint#113) to get it implemented in the ESLint TypeScript plugin that's not yet completed.

Copy link
Member

Choose a reason for hiding this comment

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

FWIW, it's a little harder to review this PR because of the import changes. I would prefer to have something that is enforced & automatic, or to not do this at all. I do agree that there is value in sorting the imports.

Copy link
Member

@sorenlouv sorenlouv Nov 11, 2020

Choose a reason for hiding this comment

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

Agree, there is value in sorting imports and it should be enforced and automatic. For backport unsorted imports make the eslint check fail:

image

image

I would be surprised if we can't have the same behaviour in Kibana.

import { APMConfig } from '../..';
import { ESSearchResponse } from '../../../../../typings/elasticsearch';
import { AlertingPlugin } from '../../../../alerts/server';
import { AlertType, ALERT_TYPES_CONFIG } from '../../../common/alert_types';
import { ESSearchResponse } from '../../../typings/elasticsearch';
import {
PROCESSOR_EVENT,
SERVICE_ENVIRONMENT,
SERVICE_NAME,
TRANSACTION_TYPE,
TRANSACTION_DURATION,
SERVICE_ENVIRONMENT,
TRANSACTION_TYPE,
} from '../../../common/elasticsearch_fieldnames';
import { AlertingPlugin } from '../../../../alerts/server';
import { getApmIndices } from '../settings/apm_indices/get_apm_indices';
import { APMConfig } from '../..';
import { ProcessorEvent } from '../../../common/processor_event';
import { getDurationFormatter } from '../../../common/utils/formatters';
import { getEnvironmentUiFilterES } from '../helpers/convert_ui_filters/get_environment_ui_filter_es';
import { getApmIndices } from '../settings/apm_indices/get_apm_indices';
import { apmActionVariables } from './action_variables';

interface RegisterAlertParams {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@
*/

import { schema } from '@kbn/config-schema';
import { isEmpty } from 'lodash';
import { Observable } from 'rxjs';
import { take } from 'rxjs/operators';
import { isEmpty } from 'lodash';
import { asDecimalOrInteger } from '../../../common/utils/formatters';
import { ProcessorEvent } from '../../../common/processor_event';
import { EventOutcome } from '../../../common/event_outcome';
import { APMConfig } from '../..';
import { ESSearchResponse } from '../../../../../typings/elasticsearch';
import { AlertingPlugin } from '../../../../alerts/server';
import { AlertType, ALERT_TYPES_CONFIG } from '../../../common/alert_types';
import { ESSearchResponse } from '../../../typings/elasticsearch';
import {
EVENT_OUTCOME,
PROCESSOR_EVENT,
SERVICE_ENVIRONMENT,
SERVICE_NAME,
TRANSACTION_TYPE,
EVENT_OUTCOME,
SERVICE_ENVIRONMENT,
} from '../../../common/elasticsearch_fieldnames';
import { AlertingPlugin } from '../../../../alerts/server';
import { getApmIndices } from '../settings/apm_indices/get_apm_indices';
import { APMConfig } from '../..';
import { EventOutcome } from '../../../common/event_outcome';
import { ProcessorEvent } from '../../../common/processor_event';
import { asDecimalOrInteger } from '../../../common/utils/formatters';
import { getEnvironmentUiFilterES } from '../helpers/convert_ui_filters/get_environment_ui_filter_es';
import { getApmIndices } from '../settings/apm_indices/get_apm_indices';
import { apmActionVariables } from './action_variables';

interface RegisterAlertParams {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
import { ValuesType } from 'utility-types';
import { flatten, merge, sortBy, sum, pickBy } from 'lodash';
import { AggregationOptionsByType } from '../../../../typings/elasticsearch/aggregations';
import { AggregationOptionsByType } from '../../../../../../typings/elasticsearch/aggregations';
import { ProcessorEvent } from '../../../../common/processor_event';
import { TelemetryTask } from '.';
import { AGENT_NAMES, RUM_AGENT_NAMES } from '../../../../common/agent_name';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { ProcessorEvent } from '../../../../common/processor_event';
import { ESFilter } from '../../../../typings/elasticsearch';
import { ESFilter } from '../../../../../../typings/elasticsearch';
import {
ERROR_GROUP_ID,
SERVICE_NAME,
} from '../../../../common/elasticsearch_fieldnames';
import { ProcessorEvent } from '../../../../common/processor_event';
import { rangeFilter } from '../../../../common/utils/range_filter';
import { Setup, SetupTimeRange } from '../../helpers/setup_request';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { PromiseReturnType } from '../../../../typings/common';
import { PromiseReturnType } from '../../../../../observability/typings/common';
import { Setup, SetupTimeRange } from '../../helpers/setup_request';
import { getBuckets } from './get_buckets';
import { BUCKET_TARGET_COUNT } from '../../transactions/constants';
import { getBuckets } from './get_buckets';

function getBucketSize({ start, end }: SetupTimeRange) {
return Math.floor((end - start) / BUCKET_TARGET_COUNT);
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/apm/server/lib/errors/get_error_group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { ProcessorEvent } from '../../../common/processor_event';
import { PromiseReturnType } from '../../../../observability/typings/common';
import {
ERROR_GROUP_ID,
SERVICE_NAME,
TRANSACTION_SAMPLED,
} from '../../../common/elasticsearch_fieldnames';
import { PromiseReturnType } from '../../../typings/common';
import { ProcessorEvent } from '../../../common/processor_event';
import { rangeFilter } from '../../../common/utils/range_filter';
import { Setup, SetupTimeRange } from '../helpers/setup_request';
import { getTransaction } from '../transactions/get_transaction';
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/apm/server/lib/errors/get_error_groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { SortOptions } from '../../../../../typings/elasticsearch/aggregations';
import { PromiseReturnType } from '../../../../observability/typings/common';
import {
ERROR_CULPRIT,
ERROR_EXC_HANDLED,
Expand All @@ -12,11 +14,9 @@ import {
ERROR_GROUP_ID,
ERROR_LOG_MESSAGE,
} from '../../../common/elasticsearch_fieldnames';
import { PromiseReturnType } from '../../../typings/common';
import { Setup, SetupTimeRange } from '../helpers/setup_request';
import { getErrorGroupsProjection } from '../../projections/errors';
import { mergeProjection } from '../../projections/util/merge_projection';
import { SortOptions } from '../../../typings/elasticsearch/aggregations';
import { Setup, SetupTimeRange } from '../helpers/setup_request';

export type ErrorGroupListAPIResponse = PromiseReturnType<
typeof getErrorGroups
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { ESFilter } from '../../../../typings/elasticsearch';
import { ESFilter } from '../../../../../../typings/elasticsearch';
import {
ENVIRONMENT_NOT_DEFINED,
ENVIRONMENT_ALL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { ESFilter } from '../../../../typings/elasticsearch';
import { ESFilter } from '../../../../../../typings/elasticsearch';
import { UIFilters } from '../../../../typings/ui_filters';
import { getEnvironmentUiFilterES } from './get_environment_ui_filter_es';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { CoreSetup } from 'src/core/server';
import { PromiseReturnType } from '../../../typings/common';
import { PromiseReturnType } from '../../../../observability/typings/common';

export type InternalSavedObjectsClient = PromiseReturnType<
typeof getInternalSavedObjectsClient
Expand Down
18 changes: 9 additions & 9 deletions x-pack/plugins/apm/server/lib/helpers/setup_request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@
* 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 moment from 'moment';
import { APMConfig } from '../..';
import { KibanaRequest } from '../../../../../../src/core/server';
import { UI_SETTINGS } from '../../../../../../src/plugins/data/common';
import { ESFilter } from '../../../../../typings/elasticsearch';
import { ProcessorEvent } from '../../../common/processor_event';
import { isActivePlatinumLicense } from '../../../common/service_map';
import { UIFilters } from '../../../typings/ui_filters';
import { APMRequestHandlerContext } from '../../routes/typings';
import {
getApmIndices,
ApmIndicesConfig,
getApmIndices,
} 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,
Expand All @@ -26,7 +27,6 @@ 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { Unionize, Overwrite } from 'utility-types';
import { Setup, SetupTimeRange } from '../helpers/setup_request';
import { getMetricsDateHistogramParams } from '../helpers/metrics';
import { ChartBase } from './types';
import { transformDataToMetricsChart } from './transform_metrics_chart';
import { Overwrite, Unionize } from 'utility-types';
import { AggregationOptionsByType } from '../../../../../typings/elasticsearch';
import { getMetricsProjection } from '../../projections/metrics';
import { mergeProjection } from '../../projections/util/merge_projection';
import { AggregationOptionsByType } from '../../../typings/elasticsearch/aggregations';
import { APMEventESSearchRequest } from '../helpers/create_es_client/create_apm_event_client';
import { getMetricsDateHistogramParams } from '../helpers/metrics';
import { Setup, SetupTimeRange } from '../helpers/setup_request';
import { transformDataToMetricsChart } from './transform_metrics_chart';
import { ChartBase } from './types';

type MetricsAggregationMap = Unionize<{
min: AggregationOptionsByType['min'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
* you may not use this file except in compliance with the Elastic License.
*/
import theme from '@elastic/eui/dist/eui_theme_light.json';
import { ChartBase } from './types';
import { ESSearchResponse } from '../../../typings/elasticsearch';
import { ESSearchResponse } from '../../../../../typings/elasticsearch';
import { getVizColorForIndex } from '../../../common/viz_colors';
import { GenericMetricsRequest } from './fetch_and_transform_metrics';
import { ChartBase } from './types';

export type GenericMetricsChart = ReturnType<
typeof transformDataToMetricsChart
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
* you may not use this file except in compliance with the Elastic License.
*/
import Boom from '@hapi/boom';
import { MlPluginSetup } from '../../../../ml/server';
import { PromiseReturnType } from '../../../../observability/typings/common';
import {
getSeverity,
ML_ERRORS,
ServiceAnomalyStats,
} from '../../../common/anomaly_detection';
import { ENVIRONMENT_ALL } from '../../../common/environment_filter_values';
import { getServiceHealthStatus } from '../../../common/service_health_status';
import { Setup, SetupTimeRange } from '../helpers/setup_request';
import { PromiseReturnType } from '../../../typings/common';
import {
TRANSACTION_PAGE_LOAD,
TRANSACTION_REQUEST,
} from '../../../common/transaction_types';
import {
ServiceAnomalyStats,
getSeverity,
ML_ERRORS,
} from '../../../common/anomaly_detection';
import { getMlJobsWithAPMGroup } from '../anomaly_detection/get_ml_jobs_with_apm_group';
import { ENVIRONMENT_ALL } from '../../../common/environment_filter_values';
import { MlPluginSetup } from '../../../../ml/server';
import { Setup, SetupTimeRange } from '../helpers/setup_request';

export const DEFAULT_ANOMALIES = { mlJobIds: [], serviceAnomalies: {} };

Expand Down
14 changes: 7 additions & 7 deletions x-pack/plugins/apm/server/lib/service_map/get_service_map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { chunk } from 'lodash';
import { Logger } from 'kibana/server';
import { chunk } from 'lodash';
import { PromiseReturnType } from '../../../../observability/typings/common';
import {
AGENT_NAME,
SERVICE_ENVIRONMENT,
SERVICE_NAME,
} from '../../../common/elasticsearch_fieldnames';
import { getServicesProjection } from '../../projections/services';
import { mergeProjection } from '../../projections/util/merge_projection';
import { PromiseReturnType } from '../../../typings/common';
import { Setup, SetupTimeRange } from '../helpers/setup_request';
import { getEnvironmentUiFilterES } from '../helpers/convert_ui_filters/get_environment_ui_filter_es';
import { transformServiceMapResponses } from './transform_service_map_responses';
import { getServiceMapFromTraceIds } from './get_service_map_from_trace_ids';
import { getTraceSampleIds } from './get_trace_sample_ids';
import { Setup, SetupTimeRange } from '../helpers/setup_request';
import {
DEFAULT_ANOMALIES,
getServiceAnomalies,
ServiceAnomaliesResponse,
DEFAULT_ANOMALIES,
} from './get_service_anomalies';
import { getServiceMapFromTraceIds } from './get_service_map_from_trace_ids';
import { getTraceSampleIds } from './get_trace_sample_ids';
import { transformServiceMapResponses } from './transform_service_map_responses';

export interface IEnvOptions {
setup: Setup & SetupTimeRange;
Expand Down
Loading