From 9c53d17838068132868e22521f975c4f44e5f80b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Louv-Jansen?= Date: Thu, 19 Nov 2020 19:48:54 +0100 Subject: [PATCH 1/2] [APM] Prefer `APIReturnType` over `PromiseReturnType` --- .../app/ErrorGroupDetails/DetailView/index.tsx | 6 +++--- .../app/ErrorGroupDetails/Distribution/index.tsx | 7 +++++-- .../app/ErrorGroupOverview/List/index.tsx | 5 ++--- .../List/ConfirmDeleteModal.tsx | 9 +++++---- .../Settings/AgentConfigurations/List/index.tsx | 5 ++--- .../components/app/TraceOverview/TraceList.tsx | 11 ++++++----- .../app/TransactionDetails/Distribution/index.tsx | 15 +++++++++++---- .../WaterfallWithSummmary/index.tsx | 9 +++++++-- .../TransactionOverview/TransactionList/index.tsx | 7 +++++-- .../app/service_inventory/ServiceList/index.tsx | 9 +++++---- .../public/hooks/useTransactionDistribution.ts | 9 ++++++--- .../lib/errors/distribution/get_distribution.ts | 5 ----- .../apm/server/lib/errors/get_error_group.ts | 3 --- .../apm/server/lib/errors/get_error_groups.ts | 5 ----- .../services/get_services/get_services_items.ts | 2 -- .../apm/server/lib/services/get_services/index.ts | 3 --- .../agent_configuration/list_configurations.ts | 4 ---- .../apm/server/lib/transaction_groups/fetcher.ts | 2 +- .../distribution/get_buckets/index.ts | 7 +------ .../server/lib/transactions/distribution/index.ts | 4 ---- 20 files changed, 59 insertions(+), 68 deletions(-) diff --git a/x-pack/plugins/apm/public/components/app/ErrorGroupDetails/DetailView/index.tsx b/x-pack/plugins/apm/public/components/app/ErrorGroupDetails/DetailView/index.tsx index 5202ca13ed102..5ee59784790c7 100644 --- a/x-pack/plugins/apm/public/components/app/ErrorGroupDetails/DetailView/index.tsx +++ b/x-pack/plugins/apm/public/components/app/ErrorGroupDetails/DetailView/index.tsx @@ -20,8 +20,6 @@ import { first } from 'lodash'; import React from 'react'; import { useHistory } from 'react-router-dom'; import styled from 'styled-components'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { ErrorGroupAPIResponse } from '../../../../../server/lib/errors/get_error_group'; import { APMError } from '../../../../../typings/es_schemas/ui/apm_error'; import { IUrlParams } from '../../../../context/UrlParamsContext/types'; import { px, unit, units } from '../../../../style/variables'; @@ -56,7 +54,9 @@ const TransactionLinkName = styled.div` `; interface Props { - errorGroup: ErrorGroupAPIResponse; + errorGroup: APIReturnType< + 'GET /api/apm/services/{serviceName}/errors/{groupId}' + >; urlParams: IUrlParams; location: Location; } diff --git a/x-pack/plugins/apm/public/components/app/ErrorGroupDetails/Distribution/index.tsx b/x-pack/plugins/apm/public/components/app/ErrorGroupDetails/Distribution/index.tsx index a17bf7e93e466..fd656b8be6ec7 100644 --- a/x-pack/plugins/apm/public/components/app/ErrorGroupDetails/Distribution/index.tsx +++ b/x-pack/plugins/apm/public/components/app/ErrorGroupDetails/Distribution/index.tsx @@ -18,11 +18,14 @@ import { import { EuiTitle } from '@elastic/eui'; import d3 from 'd3'; import React from 'react'; +import { APIReturnType } from '../../../../services/rest/createCallApmApi'; import { asRelativeDateTimeRange } from '../../../../../common/utils/formatters'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import type { ErrorDistributionAPIResponse } from '../../../../../server/lib/errors/distribution/get_distribution'; import { useTheme } from '../../../../hooks/useTheme'; +type ErrorDistributionAPIResponse = APIReturnType< + 'GET /api/apm/services/{serviceName}/errors/distribution' +>; + interface FormattedBucket { x0: number; x: number; diff --git a/x-pack/plugins/apm/public/components/app/ErrorGroupOverview/List/index.tsx b/x-pack/plugins/apm/public/components/app/ErrorGroupOverview/List/index.tsx index e1f6239112555..48c2961a0b65b 100644 --- a/x-pack/plugins/apm/public/components/app/ErrorGroupOverview/List/index.tsx +++ b/x-pack/plugins/apm/public/components/app/ErrorGroupOverview/List/index.tsx @@ -11,8 +11,6 @@ import React, { useMemo } from 'react'; import styled from 'styled-components'; import { EuiIconTip } from '@elastic/eui'; import { NOT_AVAILABLE_LABEL } from '../../../../../common/i18n'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { ErrorGroupListAPIResponse } from '../../../../../server/lib/errors/get_error_groups'; import { fontFamilyCode, fontSizes, @@ -26,6 +24,7 @@ import { ErrorDetailLink } from '../../../shared/Links/apm/ErrorDetailLink'; import { TimestampTooltip } from '../../../shared/TimestampTooltip'; import { ErrorOverviewLink } from '../../../shared/Links/apm/ErrorOverviewLink'; import { APMQueryParams } from '../../../shared/Links/url_helpers'; +import { APIReturnType } from '../../../services/rest/createCallApmApi'; const GroupIdLink = styled(ErrorDetailLink)` font-family: ${fontFamilyCode}; @@ -50,7 +49,7 @@ const Culprit = styled.div` `; interface Props { - items: ErrorGroupListAPIResponse; + items: APIReturnType<'GET /api/apm/services/{serviceName}/errors'>; serviceName: string; } diff --git a/x-pack/plugins/apm/public/components/app/Settings/AgentConfigurations/List/ConfirmDeleteModal.tsx b/x-pack/plugins/apm/public/components/app/Settings/AgentConfigurations/List/ConfirmDeleteModal.tsx index 3483ad0822801..adae50db85ada 100644 --- a/x-pack/plugins/apm/public/components/app/Settings/AgentConfigurations/List/ConfirmDeleteModal.tsx +++ b/x-pack/plugins/apm/public/components/app/Settings/AgentConfigurations/List/ConfirmDeleteModal.tsx @@ -8,13 +8,14 @@ import React, { useState } from 'react'; import { EuiConfirmModal, EuiOverlayMask } from '@elastic/eui'; import { NotificationsStart } from 'kibana/public'; import { i18n } from '@kbn/i18n'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { AgentConfigurationListAPIResponse } from '../../../../../../server/lib/settings/agent_configuration/list_configurations'; import { getOptionLabel } from '../../../../../../common/agent_configuration/all_option'; -import { callApmApi } from '../../../../../services/rest/createCallApmApi'; +import { + APIReturnType, + callApmApi, +} from '../../../../../services/rest/createCallApmApi'; import { useApmPluginContext } from '../../../../../hooks/useApmPluginContext'; -type Config = AgentConfigurationListAPIResponse[0]; +type Config = APIReturnType<'GET /api/apm/settings/agent-configuration'>[0]; interface Props { config: Config; diff --git a/x-pack/plugins/apm/public/components/app/Settings/AgentConfigurations/List/index.tsx b/x-pack/plugins/apm/public/components/app/Settings/AgentConfigurations/List/index.tsx index a67df86b21b1e..81079d78a148a 100644 --- a/x-pack/plugins/apm/public/components/app/Settings/AgentConfigurations/List/index.tsx +++ b/x-pack/plugins/apm/public/components/app/Settings/AgentConfigurations/List/index.tsx @@ -16,9 +16,8 @@ import { i18n } from '@kbn/i18n'; import { isEmpty } from 'lodash'; import React, { useState } from 'react'; import { useLocation } from 'react-router-dom'; +import { APIReturnType } from '../../../../../services/rest/createCallApmApi'; import { getOptionLabel } from '../../../../../../common/agent_configuration/all_option'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { AgentConfigurationListAPIResponse } from '../../../../../../server/lib/settings/agent_configuration/list_configurations'; import { useApmPluginContext } from '../../../../../hooks/useApmPluginContext'; import { FETCH_STATUS } from '../../../../../hooks/useFetcher'; import { useTheme } from '../../../../../hooks/useTheme'; @@ -32,7 +31,7 @@ import { ITableColumn, ManagedTable } from '../../../../shared/ManagedTable'; import { TimestampTooltip } from '../../../../shared/TimestampTooltip'; import { ConfirmDeleteModal } from './ConfirmDeleteModal'; -type Config = AgentConfigurationListAPIResponse[0]; +type Config = APIReturnType<'GET /api/apm/settings/agent-configuration'>[0]; interface Props { status: FETCH_STATUS; diff --git a/x-pack/plugins/apm/public/components/app/TraceOverview/TraceList.tsx b/x-pack/plugins/apm/public/components/app/TraceOverview/TraceList.tsx index 1c21824656754..4704230d7c68c 100644 --- a/x-pack/plugins/apm/public/components/app/TraceOverview/TraceList.tsx +++ b/x-pack/plugins/apm/public/components/app/TraceOverview/TraceList.tsx @@ -8,8 +8,6 @@ import { EuiIcon, EuiToolTip } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import React from 'react'; import styled from 'styled-components'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { TransactionGroup } from '../../../../server/lib/transaction_groups/fetcher'; import { asMillisecondDuration } from '../../../../common/utils/formatters'; import { fontSizes, truncate } from '../../../style/variables'; import { EmptyMessage } from '../../shared/EmptyMessage'; @@ -17,6 +15,9 @@ import { ImpactBar } from '../../shared/ImpactBar'; import { ITableColumn, ManagedTable } from '../../shared/ManagedTable'; import { LoadingStatePrompt } from '../../shared/LoadingStatePrompt'; import { TransactionDetailLink } from '../../shared/Links/apm/TransactionDetailLink'; +import { APIReturnType } from '../../../services/rest/createCallApmApi'; + +type TraceGroup = APIReturnType<'GET /api/apm/traces'>['items'][0]; const StyledTransactionLink = styled(TransactionDetailLink)` font-size: ${fontSizes.large}; @@ -24,11 +25,11 @@ const StyledTransactionLink = styled(TransactionDetailLink)` `; interface Props { - items: TransactionGroup[]; + items: TraceGroup[]; isLoading: boolean; } -const traceListColumns: Array> = [ +const traceListColumns: Array> = [ { field: 'name', name: i18n.translate('xpack.apm.tracesTable.nameColumnLabel', { @@ -38,7 +39,7 @@ const traceListColumns: Array> = [ sortable: true, render: ( _: string, - { serviceName, transactionName, transactionType }: TransactionGroup + { serviceName, transactionName, transactionType }: TraceGroup ) => ( ; + +type DistributionApiResponse = APIReturnType< + 'GET /api/apm/services/{serviceName}/transaction_groups/distribution' +>; + +type DistributionBucket = DistributionApiResponse['buckets'][0]; + interface IChartPoint { x0: number; x: number; diff --git a/x-pack/plugins/apm/public/components/app/TransactionDetails/WaterfallWithSummmary/index.tsx b/x-pack/plugins/apm/public/components/app/TransactionDetails/WaterfallWithSummmary/index.tsx index 3bb23fd6396ca..86221a6e92853 100644 --- a/x-pack/plugins/apm/public/components/app/TransactionDetails/WaterfallWithSummmary/index.tsx +++ b/x-pack/plugins/apm/public/components/app/TransactionDetails/WaterfallWithSummmary/index.tsx @@ -17,8 +17,7 @@ import { i18n } from '@kbn/i18n'; import { Location } from 'history'; import React, { useEffect, useState } from 'react'; import { useHistory } from 'react-router-dom'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { DistributionBucket } from '../../../../../server/lib/transactions/distribution/get_buckets'; +import { APIReturnType } from '../../../../services/rest/createCallApmApi'; import { IUrlParams } from '../../../../context/UrlParamsContext/types'; import { fromQuery, toQuery } from '../../../shared/Links/url_helpers'; import { LoadingStatePrompt } from '../../../shared/LoadingStatePrompt'; @@ -28,6 +27,12 @@ import { MaybeViewTraceLink } from './MaybeViewTraceLink'; import { TransactionTabs } from './TransactionTabs'; import { IWaterfall } from './WaterfallContainer/Waterfall/waterfall_helpers/waterfall_helpers'; +type DistributionApiResponse = APIReturnType< + 'GET /api/apm/services/{serviceName}/transaction_groups/distribution' +>; + +type DistributionBucket = DistributionApiResponse['buckets'][0]; + interface Props { urlParams: IUrlParams; location: Location; diff --git a/x-pack/plugins/apm/public/components/app/TransactionOverview/TransactionList/index.tsx b/x-pack/plugins/apm/public/components/app/TransactionOverview/TransactionList/index.tsx index 7f1dd100d721c..b084d05ee16e8 100644 --- a/x-pack/plugins/apm/public/components/app/TransactionOverview/TransactionList/index.tsx +++ b/x-pack/plugins/apm/public/components/app/TransactionOverview/TransactionList/index.tsx @@ -8,8 +8,7 @@ import { EuiToolTip, EuiIconTip } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import React, { useMemo } from 'react'; import styled from 'styled-components'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { TransactionGroup } from '../../../../../server/lib/transaction_groups/fetcher'; +import { APIReturnType } from '../../../../services/rest/createCallApmApi'; import { asDecimal, asMillisecondDuration, @@ -21,6 +20,10 @@ import { LoadingStatePrompt } from '../../../shared/LoadingStatePrompt'; import { EmptyMessage } from '../../../shared/EmptyMessage'; import { TransactionDetailLink } from '../../../shared/Links/apm/TransactionDetailLink'; +type TransactionGroup = APIReturnType< + 'GET /api/apm/services/{serviceName}/transaction_groups' +>['items'][0]; + // Truncate both the link and the child span (the tooltip anchor.) The link so // it doesn't overflow, and the anchor so we get the ellipsis. const TransactionNameLink = styled(TransactionDetailLink)` diff --git a/x-pack/plugins/apm/public/components/app/service_inventory/ServiceList/index.tsx b/x-pack/plugins/apm/public/components/app/service_inventory/ServiceList/index.tsx index 3d1572689c5bf..9b7fd5e499ace 100644 --- a/x-pack/plugins/apm/public/components/app/service_inventory/ServiceList/index.tsx +++ b/x-pack/plugins/apm/public/components/app/service_inventory/ServiceList/index.tsx @@ -10,14 +10,13 @@ import React from 'react'; import styled from 'styled-components'; import { ValuesType } from 'utility-types'; import { orderBy } from 'lodash'; +import { APIReturnType } from '../../../../services/rest/createCallApmApi'; import { ServiceHealthStatus } from '../../../../../common/service_health_status'; import { asPercent, asDecimal, asMillisecondDuration, } from '../../../../../common/utils/formatters'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { ServiceListAPIResponse } from '../../../../../server/lib/services/get_services'; import { NOT_AVAILABLE_LABEL } from '../../../../../common/i18n'; import { fontSizes, px, truncate, unit } from '../../../../style/variables'; import { ManagedTable, ITableColumn } from '../../../shared/ManagedTable'; @@ -27,12 +26,14 @@ import { AgentIcon } from '../../../shared/AgentIcon'; import { HealthBadge } from './HealthBadge'; import { ServiceListMetric } from './ServiceListMetric'; +type Items = APIReturnType<'GET /api/apm/services'>['items']; + interface Props { - items: ServiceListAPIResponse['items']; + items: Items; noItemsMessage?: React.ReactNode; } -type ServiceListItem = ValuesType; +type ServiceListItem = ValuesType; function formatNumber(value: number) { if (value === 0) { diff --git a/x-pack/plugins/apm/public/hooks/useTransactionDistribution.ts b/x-pack/plugins/apm/public/hooks/useTransactionDistribution.ts index 36b5a7c00d4be..9980569ee54dd 100644 --- a/x-pack/plugins/apm/public/hooks/useTransactionDistribution.ts +++ b/x-pack/plugins/apm/public/hooks/useTransactionDistribution.ts @@ -9,13 +9,16 @@ import { useHistory, useParams } from 'react-router-dom'; import { IUrlParams } from '../context/UrlParamsContext/types'; import { useFetcher } from './useFetcher'; import { useUiFilters } from '../context/UrlParamsContext'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import type { TransactionDistributionAPIResponse } from '../../server/lib/transactions/distribution'; import { toQuery, fromQuery } from '../components/shared/Links/url_helpers'; import { maybe } from '../../common/utils/maybe'; +import { APIReturnType } from '../services/rest/createCallApmApi'; + +type APIResponse = APIReturnType< + 'GET /api/apm/services/{serviceName}/transaction_groups/distribution' +>; const INITIAL_DATA = { - buckets: [] as TransactionDistributionAPIResponse['buckets'], + buckets: [] as APIResponse['buckets'], noHits: true, bucketSize: 0, }; diff --git a/x-pack/plugins/apm/server/lib/errors/distribution/get_distribution.ts b/x-pack/plugins/apm/server/lib/errors/distribution/get_distribution.ts index 7866c99353451..8c63d097fe56e 100644 --- a/x-pack/plugins/apm/server/lib/errors/distribution/get_distribution.ts +++ b/x-pack/plugins/apm/server/lib/errors/distribution/get_distribution.ts @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import { PromiseReturnType } from '../../../../../observability/typings/common'; import { Setup, SetupTimeRange } from '../../helpers/setup_request'; import { BUCKET_TARGET_COUNT } from '../../transactions/constants'; import { getBuckets } from './get_buckets'; @@ -13,10 +12,6 @@ function getBucketSize({ start, end }: SetupTimeRange) { return Math.floor((end - start) / BUCKET_TARGET_COUNT); } -export type ErrorDistributionAPIResponse = PromiseReturnType< - typeof getErrorDistribution ->; - export async function getErrorDistribution({ serviceName, groupId, diff --git a/x-pack/plugins/apm/server/lib/errors/get_error_group.ts b/x-pack/plugins/apm/server/lib/errors/get_error_group.ts index 37be72beedeb1..965cc28952b7a 100644 --- a/x-pack/plugins/apm/server/lib/errors/get_error_group.ts +++ b/x-pack/plugins/apm/server/lib/errors/get_error_group.ts @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import { PromiseReturnType } from '../../../../observability/typings/common'; import { ERROR_GROUP_ID, SERVICE_NAME, @@ -15,8 +14,6 @@ import { rangeFilter } from '../../../common/utils/range_filter'; import { Setup, SetupTimeRange } from '../helpers/setup_request'; import { getTransaction } from '../transactions/get_transaction'; -export type ErrorGroupAPIResponse = PromiseReturnType; - // TODO: rename from "getErrorGroup" to "getErrorGroupSample" (since a single error is returned, not an errorGroup) export async function getErrorGroup({ serviceName, diff --git a/x-pack/plugins/apm/server/lib/errors/get_error_groups.ts b/x-pack/plugins/apm/server/lib/errors/get_error_groups.ts index 97c03924538c8..3a3cf02297701 100644 --- a/x-pack/plugins/apm/server/lib/errors/get_error_groups.ts +++ b/x-pack/plugins/apm/server/lib/errors/get_error_groups.ts @@ -5,7 +5,6 @@ */ import { SortOptions } from '../../../../../typings/elasticsearch/aggregations'; -import { PromiseReturnType } from '../../../../observability/typings/common'; import { ERROR_CULPRIT, ERROR_EXC_HANDLED, @@ -19,10 +18,6 @@ import { mergeProjection } from '../../projections/util/merge_projection'; import { getErrorName } from '../helpers/get_error_name'; import { Setup, SetupTimeRange } from '../helpers/setup_request'; -export type ErrorGroupListAPIResponse = PromiseReturnType< - typeof getErrorGroups ->; - export async function getErrorGroups({ serviceName, sortField, diff --git a/x-pack/plugins/apm/server/lib/services/get_services/get_services_items.ts b/x-pack/plugins/apm/server/lib/services/get_services/get_services_items.ts index 89915e798b7cd..11f3e44fce87c 100644 --- a/x-pack/plugins/apm/server/lib/services/get_services/get_services_items.ts +++ b/x-pack/plugins/apm/server/lib/services/get_services/get_services_items.ts @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ import { Logger } from '@kbn/logging'; -import { PromiseReturnType } from '../../../../../observability/typings/common'; import { joinByKey } from '../../../../common/utils/join_by_key'; import { getServicesProjection } from '../../../projections/services'; import { Setup, SetupTimeRange } from '../../helpers/setup_request'; @@ -17,7 +16,6 @@ import { getTransactionRates, } from './get_services_items_stats'; -export type ServiceListAPIResponse = PromiseReturnType; export type ServicesItemsSetup = Setup & SetupTimeRange; export type ServicesItemsProjection = ReturnType; diff --git a/x-pack/plugins/apm/server/lib/services/get_services/index.ts b/x-pack/plugins/apm/server/lib/services/get_services/index.ts index 9d450804e421d..6a77392550bfe 100644 --- a/x-pack/plugins/apm/server/lib/services/get_services/index.ts +++ b/x-pack/plugins/apm/server/lib/services/get_services/index.ts @@ -6,14 +6,11 @@ import { Logger } from '@kbn/logging'; import { isEmpty } from 'lodash'; -import { PromiseReturnType } from '../../../../../observability/typings/common'; import { Setup, SetupTimeRange } from '../../helpers/setup_request'; import { getLegacyDataStatus } from './get_legacy_data_status'; import { getServicesItems } from './get_services_items'; import { hasHistoricalAgentData } from './has_historical_agent_data'; -export type ServiceListAPIResponse = PromiseReturnType; - export async function getServices({ setup, searchAggregatedTransactions, diff --git a/x-pack/plugins/apm/server/lib/settings/agent_configuration/list_configurations.ts b/x-pack/plugins/apm/server/lib/settings/agent_configuration/list_configurations.ts index d76f9600b3d93..d68863e250684 100644 --- a/x-pack/plugins/apm/server/lib/settings/agent_configuration/list_configurations.ts +++ b/x-pack/plugins/apm/server/lib/settings/agent_configuration/list_configurations.ts @@ -4,14 +4,10 @@ * you may not use this file except in compliance with the Elastic License. */ -import { PromiseReturnType } from '../../../../../observability/typings/common'; import { Setup } from '../../helpers/setup_request'; import { AgentConfiguration } from '../../../../common/agent_configuration/configuration_types'; import { convertConfigSettingsToString } from './convert_settings_to_string'; -export type AgentConfigurationListAPIResponse = PromiseReturnType< - typeof listConfigurations ->; export async function listConfigurations({ setup }: { setup: Setup }) { const { internalClient, indices } = setup; diff --git a/x-pack/plugins/apm/server/lib/transaction_groups/fetcher.ts b/x-pack/plugins/apm/server/lib/transaction_groups/fetcher.ts index 89fff260a7d23..e57ea3aecb09a 100644 --- a/x-pack/plugins/apm/server/lib/transaction_groups/fetcher.ts +++ b/x-pack/plugins/apm/server/lib/transaction_groups/fetcher.ts @@ -204,7 +204,7 @@ export async function transactionGroupsFetcher( }; } -export interface TransactionGroup { +interface TransactionGroup { key: string | Record<'service.name' | 'transaction.name', string>; serviceName: string; transactionName: string; diff --git a/x-pack/plugins/apm/server/lib/transactions/distribution/get_buckets/index.ts b/x-pack/plugins/apm/server/lib/transactions/distribution/get_buckets/index.ts index 010acd09239a3..98df68e50220d 100644 --- a/x-pack/plugins/apm/server/lib/transactions/distribution/get_buckets/index.ts +++ b/x-pack/plugins/apm/server/lib/transactions/distribution/get_buckets/index.ts @@ -3,8 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import { ValuesType } from 'utility-types'; -import { PromiseReturnType } from '../../../../../../observability/typings/common'; + import { SERVICE_NAME, TRACE_ID, @@ -196,7 +195,3 @@ export async function getBuckets({ buckets, }; } - -export type DistributionBucket = ValuesType< - PromiseReturnType['buckets'] ->; diff --git a/x-pack/plugins/apm/server/lib/transactions/distribution/index.ts b/x-pack/plugins/apm/server/lib/transactions/distribution/index.ts index deafc37ee42e2..af6e05a2ca336 100644 --- a/x-pack/plugins/apm/server/lib/transactions/distribution/index.ts +++ b/x-pack/plugins/apm/server/lib/transactions/distribution/index.ts @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import { PromiseReturnType } from '../../../../../observability/typings/common'; import { Setup, SetupTimeRange } from '../../helpers/setup_request'; import { getBuckets } from './get_buckets'; import { getDistributionMax } from './get_distribution_max'; @@ -18,9 +17,6 @@ function getBucketSize(max: number) { ); } -export type TransactionDistributionAPIResponse = PromiseReturnType< - typeof getTransactionDistribution ->; export async function getTransactionDistribution({ serviceName, transactionName, From 59553d53eb3b8805f08d7da203562c6dac21640e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Louv-Jansen?= Date: Thu, 19 Nov 2020 23:16:01 +0100 Subject: [PATCH 2/2] Fix ts issues --- .../components/app/ErrorGroupDetails/DetailView/index.tsx | 1 + .../components/app/ErrorGroupOverview/List/index.tsx | 8 ++++++-- .../TransactionList/TransactionList.stories.tsx | 7 +++++-- .../app/service_inventory/ServiceList/index.tsx | 4 ++-- .../service_inventory/ServiceList/service_list.test.tsx | 5 +++-- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/x-pack/plugins/apm/public/components/app/ErrorGroupDetails/DetailView/index.tsx b/x-pack/plugins/apm/public/components/app/ErrorGroupDetails/DetailView/index.tsx index 5ee59784790c7..777ee014d3e58 100644 --- a/x-pack/plugins/apm/public/components/app/ErrorGroupDetails/DetailView/index.tsx +++ b/x-pack/plugins/apm/public/components/app/ErrorGroupDetails/DetailView/index.tsx @@ -20,6 +20,7 @@ import { first } from 'lodash'; import React from 'react'; import { useHistory } from 'react-router-dom'; import styled from 'styled-components'; +import { APIReturnType } from '../../../../services/rest/createCallApmApi'; import { APMError } from '../../../../../typings/es_schemas/ui/apm_error'; import { IUrlParams } from '../../../../context/UrlParamsContext/types'; import { px, unit, units } from '../../../../style/variables'; diff --git a/x-pack/plugins/apm/public/components/app/ErrorGroupOverview/List/index.tsx b/x-pack/plugins/apm/public/components/app/ErrorGroupOverview/List/index.tsx index 48c2961a0b65b..bfa426985d1c6 100644 --- a/x-pack/plugins/apm/public/components/app/ErrorGroupOverview/List/index.tsx +++ b/x-pack/plugins/apm/public/components/app/ErrorGroupOverview/List/index.tsx @@ -10,6 +10,7 @@ import { i18n } from '@kbn/i18n'; import React, { useMemo } from 'react'; import styled from 'styled-components'; import { EuiIconTip } from '@elastic/eui'; +import { APIReturnType } from '../../../../services/rest/createCallApmApi'; import { NOT_AVAILABLE_LABEL } from '../../../../../common/i18n'; import { fontFamilyCode, @@ -24,7 +25,6 @@ import { ErrorDetailLink } from '../../../shared/Links/apm/ErrorDetailLink'; import { TimestampTooltip } from '../../../shared/TimestampTooltip'; import { ErrorOverviewLink } from '../../../shared/Links/apm/ErrorOverviewLink'; import { APMQueryParams } from '../../../shared/Links/url_helpers'; -import { APIReturnType } from '../../../services/rest/createCallApmApi'; const GroupIdLink = styled(ErrorDetailLink)` font-family: ${fontFamilyCode}; @@ -48,8 +48,12 @@ const Culprit = styled.div` font-family: ${fontFamilyCode}; `; +type ErrorGroupListAPIResponse = APIReturnType< + 'GET /api/apm/services/{serviceName}/errors' +>; + interface Props { - items: APIReturnType<'GET /api/apm/services/{serviceName}/errors'>; + items: ErrorGroupListAPIResponse; serviceName: string; } diff --git a/x-pack/plugins/apm/public/components/app/TransactionOverview/TransactionList/TransactionList.stories.tsx b/x-pack/plugins/apm/public/components/app/TransactionOverview/TransactionList/TransactionList.stories.tsx index 049c5934813a2..65dfdd19fa0c5 100644 --- a/x-pack/plugins/apm/public/components/app/TransactionOverview/TransactionList/TransactionList.stories.tsx +++ b/x-pack/plugins/apm/public/components/app/TransactionOverview/TransactionList/TransactionList.stories.tsx @@ -6,11 +6,14 @@ import React, { ComponentType } from 'react'; import { MemoryRouter } from 'react-router-dom'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { TransactionGroup } from '../../../../../server/lib/transaction_groups/fetcher'; +import { APIReturnType } from '../../../../services/rest/createCallApmApi'; import { MockApmPluginContextWrapper } from '../../../../context/ApmPluginContext/MockApmPluginContext'; import { TransactionList } from './'; +type TransactionGroup = APIReturnType< + 'GET /api/apm/services/{serviceName}/transaction_groups' +>['items'][0]; + export default { title: 'app/TransactionOverview/TransactionList', component: TransactionList, diff --git a/x-pack/plugins/apm/public/components/app/service_inventory/ServiceList/index.tsx b/x-pack/plugins/apm/public/components/app/service_inventory/ServiceList/index.tsx index 9b7fd5e499ace..df7a533c0289d 100644 --- a/x-pack/plugins/apm/public/components/app/service_inventory/ServiceList/index.tsx +++ b/x-pack/plugins/apm/public/components/app/service_inventory/ServiceList/index.tsx @@ -26,13 +26,13 @@ import { AgentIcon } from '../../../shared/AgentIcon'; import { HealthBadge } from './HealthBadge'; import { ServiceListMetric } from './ServiceListMetric'; -type Items = APIReturnType<'GET /api/apm/services'>['items']; +type ServiceListAPIResponse = APIReturnType<'GET /api/apm/services'>; +type Items = ServiceListAPIResponse['items']; interface Props { items: Items; noItemsMessage?: React.ReactNode; } - type ServiceListItem = ValuesType; function formatNumber(value: number) { diff --git a/x-pack/plugins/apm/public/components/app/service_inventory/ServiceList/service_list.test.tsx b/x-pack/plugins/apm/public/components/app/service_inventory/ServiceList/service_list.test.tsx index 73777c2221a5b..39cb73d2a0dd9 100644 --- a/x-pack/plugins/apm/public/components/app/service_inventory/ServiceList/service_list.test.tsx +++ b/x-pack/plugins/apm/public/components/app/service_inventory/ServiceList/service_list.test.tsx @@ -7,13 +7,14 @@ import React, { ReactNode } from 'react'; import { MemoryRouter } from 'react-router-dom'; import { ServiceHealthStatus } from '../../../../../common/service_health_status'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { ServiceListAPIResponse } from '../../../../../server/lib/services/get_services'; import { MockApmPluginContextWrapper } from '../../../../context/ApmPluginContext/MockApmPluginContext'; import { mockMoment, renderWithTheme } from '../../../../utils/testHelpers'; +import { APIReturnType } from '../../../../services/rest/createCallApmApi'; import { ServiceList, SERVICE_COLUMNS } from './'; import props from './__fixtures__/props.json'; +type ServiceListAPIResponse = APIReturnType<'GET /api/apm/services'>; + function Wrapper({ children }: { children?: ReactNode }) { return (