From 1ad8f307e55176bdcb3a62f9c576aecc687bf4fd Mon Sep 17 00:00:00 2001 From: Dario Gieselaar Date: Sat, 16 Nov 2019 14:19:36 +0100 Subject: [PATCH] [APM Replace usage of idx with optional chaining Closes #50758 --- .../DetailView/ErrorTabs.tsx | 3 +- .../DetailView/ExceptionStacktrace.tsx | 3 +- .../__snapshots__/index.test.tsx.snap | 1 + .../DetailView/index.test.tsx | 3 ++ .../ErrorGroupDetails/DetailView/index.tsx | 16 +++++----- .../app/ErrorGroupDetails/index.tsx | 12 +++---- .../ServiceIntegrations/index.tsx | 7 ++-- .../AddEditFlyout/index.tsx | 12 ++++--- .../Waterfall/SpanFlyout/HttpContext.tsx | 3 +- .../Waterfall/SpanFlyout/index.tsx | 15 +++++---- .../TransactionFlyout/DroppedSpansWarning.tsx | 3 +- .../waterfall_helpers/waterfall_helpers.ts | 3 +- .../components/shared/ManagedTable/index.tsx | 3 +- .../components/shared/Stacktrace/Context.tsx | 9 +++--- .../shared/Stacktrace/FrameHeading.tsx | 3 +- .../shared/Summary/TransactionSummary.tsx | 13 ++++---- .../TransactionActionMenu.tsx | 11 +++---- .../shared/charts/TransactionCharts/index.tsx | 7 ++-- .../plugins/apm/public/hooks/useFetcher.tsx | 6 ++-- .../lib/errors/distribution/get_buckets.ts | 13 ++++---- .../apm/server/lib/errors/get_error_group.ts | 7 ++-- .../apm/server/lib/errors/get_error_groups.ts | 32 +++++++++---------- .../get_trace_errors_per_transaction.ts | 3 +- .../get_kuery_ui_filter_es.ts | 5 ++- .../java/gc/fetchAndTransformGcMetrics.ts | 10 +++--- .../lib/metrics/transform_metrics_chart.ts | 22 ++++++------- .../lib/services/get_service_agent_name.ts | 5 +-- .../lib/services/get_service_node_metadata.ts | 8 ++--- .../services/get_service_transaction_types.ts | 5 ++- .../get_services/get_services_items.ts | 15 +++++---- .../get_agent_name_by_service.ts | 5 +-- .../get_environments/get_all_environments.ts | 7 ++-- .../get_existing_environments_for_service.ts | 8 +++-- .../agent_configuration/get_service_names.ts | 7 ++-- .../lib/transaction_groups/transform.ts | 3 +- .../lib/transactions/breakdown/index.ts | 5 +-- .../get_anomaly_data/get_ml_bucket_size.ts | 5 +-- .../charts/get_anomaly_data/transform.test.ts | 9 +++--- .../charts/get_anomaly_data/transform.ts | 8 ++--- .../charts/get_timeseries_data/transform.ts | 17 +++++----- .../distribution/get_buckets/transform.ts | 15 ++++----- .../lib/transactions/get_transaction/index.ts | 3 +- .../server/lib/ui_filters/get_environments.ts | 3 +- 43 files changed, 168 insertions(+), 185 deletions(-) diff --git a/x-pack/legacy/plugins/apm/public/components/app/ErrorGroupDetails/DetailView/ErrorTabs.tsx b/x-pack/legacy/plugins/apm/public/components/app/ErrorGroupDetails/DetailView/ErrorTabs.tsx index 33b20b0f0f226..ab61ce444232d 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/ErrorGroupDetails/DetailView/ErrorTabs.tsx +++ b/x-pack/legacy/plugins/apm/public/components/app/ErrorGroupDetails/DetailView/ErrorTabs.tsx @@ -6,7 +6,6 @@ import { i18n } from '@kbn/i18n'; import { isEmpty } from 'lodash'; -import { idx } from '@kbn/elastic-idx'; import { APMError } from '../../../../../typings/es_schemas/ui/APMError'; export interface ErrorTab { @@ -39,7 +38,7 @@ export const metadataTab: ErrorTab = { }; export function getTabs(error: APMError) { - const hasLogStacktrace = !isEmpty(idx(error, _ => _.error.log.stacktrace)); + const hasLogStacktrace = !isEmpty(error.error.log?.stacktrace); return [ ...(hasLogStacktrace ? [logStacktraceTab] : []), exceptionStacktraceTab, diff --git a/x-pack/legacy/plugins/apm/public/components/app/ErrorGroupDetails/DetailView/ExceptionStacktrace.tsx b/x-pack/legacy/plugins/apm/public/components/app/ErrorGroupDetails/DetailView/ExceptionStacktrace.tsx index 13c904a119449..0b91bddf862bc 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/ErrorGroupDetails/DetailView/ExceptionStacktrace.tsx +++ b/x-pack/legacy/plugins/apm/public/components/app/ErrorGroupDetails/DetailView/ExceptionStacktrace.tsx @@ -6,7 +6,6 @@ import React from 'react'; import { EuiTitle } from '@elastic/eui'; -import { idx } from '@kbn/elastic-idx/target'; import { Exception } from '../../../../../typings/es_schemas/raw/ErrorRaw'; import { Stacktrace } from '../../../shared/Stacktrace'; import { CauseStacktrace } from '../../../shared/Stacktrace/CauseStacktrace'; @@ -20,7 +19,7 @@ export function ExceptionStacktrace({ codeLanguage, exceptions }: ExceptionStacktraceProps) { - const title = idx(exceptions, _ => _[0].message); + const title = exceptions[0]?.message; return ( <> diff --git a/x-pack/legacy/plugins/apm/public/components/app/ErrorGroupDetails/DetailView/__snapshots__/index.test.tsx.snap b/x-pack/legacy/plugins/apm/public/components/app/ErrorGroupDetails/DetailView/__snapshots__/index.test.tsx.snap index 39874c11b09bf..b2c503806c385 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/ErrorGroupDetails/DetailView/__snapshots__/index.test.tsx.snap +++ b/x-pack/legacy/plugins/apm/public/components/app/ErrorGroupDetails/DetailView/__snapshots__/index.test.tsx.snap @@ -52,6 +52,7 @@ exports[`DetailView should render TabContent 1`] = ` error={ Object { "context": Object {}, + "error": Object {}, "timestamp": Object { "us": 0, }, diff --git a/x-pack/legacy/plugins/apm/public/components/app/ErrorGroupDetails/DetailView/index.test.tsx b/x-pack/legacy/plugins/apm/public/components/app/ErrorGroupDetails/DetailView/index.test.tsx index c6b84ddc0722e..af4c129d61b60 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/ErrorGroupDetails/DetailView/index.test.tsx +++ b/x-pack/legacy/plugins/apm/public/components/app/ErrorGroupDetails/DetailView/index.test.tsx @@ -60,6 +60,7 @@ describe('DetailView', () => { const errorGroup = { occurrencesCount: 10, error: { + error: {}, timestamp: { us: 0 } @@ -85,6 +86,7 @@ describe('DetailView', () => { timestamp: { us: 0 }, + error: {}, service: {}, user: {} } as any @@ -109,6 +111,7 @@ describe('DetailView', () => { timestamp: { us: 0 }, + error: {}, context: {} } as any }; diff --git a/x-pack/legacy/plugins/apm/public/components/app/ErrorGroupDetails/DetailView/index.tsx b/x-pack/legacy/plugins/apm/public/components/app/ErrorGroupDetails/DetailView/index.tsx index 5c7b2b7d0070e..de7f0e133ba49 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/ErrorGroupDetails/DetailView/index.tsx +++ b/x-pack/legacy/plugins/apm/public/components/app/ErrorGroupDetails/DetailView/index.tsx @@ -19,7 +19,6 @@ import { Location } from 'history'; import React from 'react'; import styled from 'styled-components'; import { first } from 'lodash'; -import { idx } from '@kbn/elastic-idx'; import { ErrorGroupAPIResponse } from '../../../../../server/lib/errors/get_error_group'; import { APMError } from '../../../../../typings/es_schemas/ui/APMError'; import { IUrlParams } from '../../../../context/UrlParamsContext/types'; @@ -80,11 +79,12 @@ export function DetailView({ errorGroup, urlParams, location }: Props) { const tabs = getTabs(error); const currentTab = getCurrentTab(tabs, urlParams.detailTab); - const errorUrl = - idx(error, _ => _.error.page.url) || idx(error, _ => _.url.full); + const errorUrl = error.error.page?.url || error.url?.full; - const method = idx(error, _ => _.http.request.method); - const status = idx(error, _ => _.http.response.status_code); + const method = error.http?.request.method; + // TODO(TS-3.7-ESLINT) + // eslint-disable-next-line @typescript-eslint/camelcase + const status = error.http?.response?.status_code; return ( @@ -188,9 +188,9 @@ function TabContent({ error: APMError; currentTab: ErrorTab; }) { - const codeLanguage = idx(error, _ => _.service.language.name); - const exceptions = idx(error, _ => _.error.exception) || []; - const logStackframes = idx(error, _ => _.error.log.stacktrace); + const codeLanguage = error.service.language?.name; + const exceptions = error.error.exception || []; + const logStackframes = error.error.log?.stacktrace; switch (currentTab.key) { case logStacktraceTab.key: diff --git a/x-pack/legacy/plugins/apm/public/components/app/ErrorGroupDetails/index.tsx b/x-pack/legacy/plugins/apm/public/components/app/ErrorGroupDetails/index.tsx index df16c082404d5..a247390704e72 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/ErrorGroupDetails/index.tsx +++ b/x-pack/legacy/plugins/apm/public/components/app/ErrorGroupDetails/index.tsx @@ -17,7 +17,6 @@ import theme from '@elastic/eui/dist/eui_theme_light.json'; import { i18n } from '@kbn/i18n'; import React, { Fragment } from 'react'; import styled from 'styled-components'; -import { idx } from '@kbn/elastic-idx'; import { NOT_AVAILABLE_LABEL } from '../../../../common/i18n'; import { useFetcher } from '../../../hooks/useFetcher'; import { fontFamilyCode, fontSizes, px, units } from '../../../style/variables'; @@ -115,14 +114,11 @@ export function ErrorGroupDetails() { // If there are 0 occurrences, show only distribution chart w. empty message const showDetails = errorGroupData.occurrencesCount !== 0; - const logMessage = idx(errorGroupData, _ => _.error.error.log.message); - const excMessage = idx( - errorGroupData, - _ => _.error.error.exception[0].message - ); - const culprit = idx(errorGroupData, _ => _.error.error.culprit); + const logMessage = errorGroupData.error?.error.log?.message; + const excMessage = errorGroupData.error?.error.exception?.[0].message; + const culprit = errorGroupData.error?.error.culprit; const isUnhandled = - idx(errorGroupData, _ => _.error.error.exception[0].handled) === false; + errorGroupData.error?.error.exception?.[0].handled === false; return (
diff --git a/x-pack/legacy/plugins/apm/public/components/app/ServiceDetails/ServiceIntegrations/index.tsx b/x-pack/legacy/plugins/apm/public/components/app/ServiceDetails/ServiceIntegrations/index.tsx index 8a5d7ad10f22b..c4cc7dbfd5d1f 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/ServiceDetails/ServiceIntegrations/index.tsx +++ b/x-pack/legacy/plugins/apm/public/components/app/ServiceDetails/ServiceIntegrations/index.tsx @@ -13,7 +13,6 @@ import { import { i18n } from '@kbn/i18n'; import { memoize } from 'lodash'; import React, { Fragment } from 'react'; -import { idx } from '@kbn/elastic-idx'; import { KibanaCoreContext } from '../../../../../../observability/public'; import { IUrlParams } from '../../../../context/UrlParamsContext/types'; import { LicenseContext } from '../../../../context/LicenseContext'; @@ -149,9 +148,9 @@ export class ServiceIntegrations extends React.Component { panels={[ { id: 0, - items: this.getPanelItems( - idx(license, _ => _.features.ml.is_available) - ) + // TODO(TS-3.7-ESLINT) + // eslint-disable-next-line @typescript-eslint/camelcase + items: this.getPanelItems(license.features.ml?.is_available) } ]} /> diff --git a/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AddEditFlyout/index.tsx b/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AddEditFlyout/index.tsx index 8e7a6e3b50f67..46d6f80bf4834 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AddEditFlyout/index.tsx +++ b/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AddEditFlyout/index.tsx @@ -19,7 +19,6 @@ import { EuiText, EuiSpacer } from '@elastic/eui'; -import { idx } from '@kbn/elastic-idx'; import React, { useState } from 'react'; import { i18n } from '@kbn/i18n'; import { isRight } from 'fp-ts/lib/Either'; @@ -89,18 +88,21 @@ export function AddEditFlyout({ // config settings const [sampleRate, setSampleRate] = useState( + // TODO(TS-3.7-ESLINT) ( - idx(selectedConfig, _ => _.settings.transaction_sample_rate) || + selectedConfig?.settings.transaction_sample_rate || // eslint-disable-line @typescript-eslint/camelcase defaultSettings.TRANSACTION_SAMPLE_RATE ).toString() ); const [captureBody, setCaptureBody] = useState( - idx(selectedConfig, _ => _.settings.capture_body) || - defaultSettings.CAPTURE_BODY + // TODO(TS-3.7-ESLINT) + // eslint-disable-next-line @typescript-eslint/camelcase + selectedConfig?.settings.capture_body || defaultSettings.CAPTURE_BODY ); const [transactionMaxSpans, setTransactionMaxSpans] = useState( + // TODO(TS-3.7-ESLINT) ( - idx(selectedConfig, _ => _.settings.transaction_max_spans) || + selectedConfig?.settings.transaction_max_spans || // eslint-disable-line @typescript-eslint/camelcase defaultSettings.TRANSACTION_MAX_SPANS ).toString() ); diff --git a/x-pack/legacy/plugins/apm/public/components/app/TransactionDetails/WaterfallWithSummmary/WaterfallContainer/Waterfall/SpanFlyout/HttpContext.tsx b/x-pack/legacy/plugins/apm/public/components/app/TransactionDetails/WaterfallWithSummmary/WaterfallContainer/Waterfall/SpanFlyout/HttpContext.tsx index 167940b357616..f767ce2e9f0d8 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/TransactionDetails/WaterfallWithSummmary/WaterfallContainer/Waterfall/SpanFlyout/HttpContext.tsx +++ b/x-pack/legacy/plugins/apm/public/components/app/TransactionDetails/WaterfallWithSummmary/WaterfallContainer/Waterfall/SpanFlyout/HttpContext.tsx @@ -9,7 +9,6 @@ import styled from 'styled-components'; import { EuiSpacer, EuiTitle } from '@elastic/eui'; import theme from '@elastic/eui/dist/eui_theme_light.json'; -import { idx } from '@kbn/elastic-idx'; import { borderRadius, fontFamilyCode, @@ -34,7 +33,7 @@ interface Props { } export function HttpContext({ httpContext }: Props) { - const url = idx(httpContext, _ => _.url.original); + const url = httpContext?.url?.original; if (!url) { return null; diff --git a/x-pack/legacy/plugins/apm/public/components/app/TransactionDetails/WaterfallWithSummmary/WaterfallContainer/Waterfall/SpanFlyout/index.tsx b/x-pack/legacy/plugins/apm/public/components/app/TransactionDetails/WaterfallWithSummmary/WaterfallContainer/Waterfall/SpanFlyout/index.tsx index 0f5893772fec8..bb7c03c63f8ab 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/TransactionDetails/WaterfallWithSummmary/WaterfallContainer/Waterfall/SpanFlyout/index.tsx +++ b/x-pack/legacy/plugins/apm/public/components/app/TransactionDetails/WaterfallWithSummmary/WaterfallContainer/Waterfall/SpanFlyout/index.tsx @@ -21,7 +21,6 @@ import { import { i18n } from '@kbn/i18n'; import React, { Fragment } from 'react'; import styled from 'styled-components'; -import { idx } from '@kbn/elastic-idx'; import { px, units } from '../../../../../../../style/variables'; import { Summary } from '../../../../../../shared/Summary'; import { TimestampTooltip } from '../../../../../../shared/TimestampTooltip'; @@ -98,13 +97,15 @@ export function SpanFlyout({ } const stackframes = span.span.stacktrace; - const codeLanguage = idx(parentTransaction, _ => _.service.language.name); - const dbContext = idx(span, _ => _.span.db); - const httpContext = idx(span, _ => _.span.http); + const codeLanguage = parentTransaction?.service.language?.name; + const dbContext = span.span.db; + const httpContext = span.span.http; const spanTypes = getSpanTypes(span); - const spanHttpStatusCode = idx(httpContext, _ => _.response.status_code); - const spanHttpUrl = idx(httpContext, _ => _.url.original); - const spanHttpMethod = idx(httpContext, _ => _.method); + // TODO(TS-3.7-ESLINT) + // eslint-disable-next-line @typescript-eslint/camelcase + const spanHttpStatusCode = httpContext?.response.status_code; + const spanHttpUrl = httpContext?.url?.original; + const spanHttpMethod = httpContext?.method; return ( diff --git a/x-pack/legacy/plugins/apm/public/components/app/TransactionDetails/WaterfallWithSummmary/WaterfallContainer/Waterfall/TransactionFlyout/DroppedSpansWarning.tsx b/x-pack/legacy/plugins/apm/public/components/app/TransactionDetails/WaterfallWithSummmary/WaterfallContainer/Waterfall/TransactionFlyout/DroppedSpansWarning.tsx index 5b22c902f6a36..f3e29d7c75717 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/TransactionDetails/WaterfallWithSummmary/WaterfallContainer/Waterfall/TransactionFlyout/DroppedSpansWarning.tsx +++ b/x-pack/legacy/plugins/apm/public/components/app/TransactionDetails/WaterfallWithSummmary/WaterfallContainer/Waterfall/TransactionFlyout/DroppedSpansWarning.tsx @@ -7,7 +7,6 @@ import { EuiCallOut, EuiHorizontalRule } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import React from 'react'; -import { idx } from '@kbn/elastic-idx'; import { Transaction } from '../../../../../../../../typings/es_schemas/ui/Transaction'; import { ElasticDocsLink } from '../../../../../../shared/Links/ElasticDocsLink'; @@ -16,7 +15,7 @@ export function DroppedSpansWarning({ }: { transactionDoc: Transaction; }) { - const dropped = idx(transactionDoc, _ => _.transaction.span_count.dropped); + const dropped = transactionDoc.transaction.span_count?.dropped; if (!dropped) { return null; } diff --git a/x-pack/legacy/plugins/apm/public/components/app/TransactionDetails/WaterfallWithSummmary/WaterfallContainer/Waterfall/waterfall_helpers/waterfall_helpers.ts b/x-pack/legacy/plugins/apm/public/components/app/TransactionDetails/WaterfallWithSummmary/WaterfallContainer/Waterfall/waterfall_helpers/waterfall_helpers.ts index 10f59e237ba7f..2a69c5f51173d 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/TransactionDetails/WaterfallWithSummmary/WaterfallContainer/Waterfall/waterfall_helpers/waterfall_helpers.ts +++ b/x-pack/legacy/plugins/apm/public/components/app/TransactionDetails/WaterfallWithSummmary/WaterfallContainer/Waterfall/waterfall_helpers/waterfall_helpers.ts @@ -15,7 +15,6 @@ import { isEmpty, first } from 'lodash'; -import { idx } from '@kbn/elastic-idx'; import { TraceAPIResponse } from '../../../../../../../../server/lib/traces/get_trace'; import { Span } from '../../../../../../../../typings/es_schemas/ui/Span'; import { Transaction } from '../../../../../../../../typings/es_schemas/ui/Transaction'; @@ -224,7 +223,7 @@ function createGetTransactionById(itemsById: IWaterfallIndex) { } const item = itemsById[id]; - const isTransaction = idx(item, _ => _.docType) === 'transaction'; + const isTransaction = item?.docType === 'transaction'; if (isTransaction) { return (item as IWaterfallItemTransaction).transaction; } diff --git a/x-pack/legacy/plugins/apm/public/components/shared/ManagedTable/index.tsx b/x-pack/legacy/plugins/apm/public/components/shared/ManagedTable/index.tsx index 29a8528295dd7..7f2632dc3d81f 100644 --- a/x-pack/legacy/plugins/apm/public/components/shared/ManagedTable/index.tsx +++ b/x-pack/legacy/plugins/apm/public/components/shared/ManagedTable/index.tsx @@ -7,7 +7,6 @@ import { EuiBasicTable } from '@elastic/eui'; import { sortByOrder } from 'lodash'; import React, { useMemo, useCallback, ReactNode } from 'react'; -import { idx } from '@kbn/elastic-idx'; import { useUrlParams } from '../../../hooks/useUrlParams'; import { history } from '../../../utils/history'; import { fromQuery, toQuery } from '../Links/url_helpers'; @@ -42,7 +41,7 @@ function UnoptimizedManagedTable(props: Props) { columns, initialPageIndex = 0, initialPageSize = 10, - initialSortField = idx(props, _ => _.columns[0].field) || '', + initialSortField = props.columns[0]?.field || '', initialSortDirection = 'asc', hidePerPageOptions = true, noItemsMessage, diff --git a/x-pack/legacy/plugins/apm/public/components/shared/Stacktrace/Context.tsx b/x-pack/legacy/plugins/apm/public/components/shared/Stacktrace/Context.tsx index 9685ba920a73c..4320156fad003 100644 --- a/x-pack/legacy/plugins/apm/public/components/shared/Stacktrace/Context.tsx +++ b/x-pack/legacy/plugins/apm/public/components/shared/Stacktrace/Context.tsx @@ -22,7 +22,6 @@ import { registerLanguage } from 'react-syntax-highlighter/dist/light'; // @ts-ignore import { xcode } from 'react-syntax-highlighter/dist/styles'; import styled from 'styled-components'; -import { idx } from '@kbn/elastic-idx'; import { IStackframeWithLineContext } from '../../../../typings/es_schemas/raw/fields/Stackframe'; import { borderRadius, px, unit, units } from '../../../style/variables'; @@ -106,13 +105,13 @@ const Code = styled.code` function getStackframeLines(stackframe: IStackframeWithLineContext) { const line = stackframe.line.context; - const preLines = idx(stackframe, _ => _.context.pre) || []; - const postLines = idx(stackframe, _ => _.context.post) || []; + const preLines = stackframe.context?.pre || []; + const postLines = stackframe.context?.post || []; return [...preLines, line, ...postLines]; } function getStartLineNumber(stackframe: IStackframeWithLineContext) { - const preLines = size(idx(stackframe, _ => _.context.pre) || []); + const preLines = size(stackframe.context?.pre || []); return stackframe.line.number - preLines; } @@ -125,7 +124,7 @@ interface Props { export function Context({ stackframe, codeLanguage, isLibraryFrame }: Props) { const lines = getStackframeLines(stackframe); const startLineNumber = getStartLineNumber(stackframe); - const highlightedLineIndex = size(idx(stackframe, _ => _.context.pre) || []); + const highlightedLineIndex = size(stackframe.context?.pre || []); const language = codeLanguage || 'javascript'; // TODO: Add support for more languages return ( diff --git a/x-pack/legacy/plugins/apm/public/components/shared/Stacktrace/FrameHeading.tsx b/x-pack/legacy/plugins/apm/public/components/shared/Stacktrace/FrameHeading.tsx index c9f7057d2fb86..5ec6a2289f9c9 100644 --- a/x-pack/legacy/plugins/apm/public/components/shared/Stacktrace/FrameHeading.tsx +++ b/x-pack/legacy/plugins/apm/public/components/shared/Stacktrace/FrameHeading.tsx @@ -7,7 +7,6 @@ import theme from '@elastic/eui/dist/eui_theme_light.json'; import React, { Fragment } from 'react'; import styled from 'styled-components'; -import { idx } from '@kbn/elastic-idx'; import { IStackframe } from '../../../../typings/es_schemas/raw/fields/Stackframe'; import { fontFamilyCode, fontSize, px, units } from '../../../style/variables'; @@ -35,7 +34,7 @@ const FrameHeading: React.SFC = ({ stackframe, isLibraryFrame }) => { const FileDetail = isLibraryFrame ? LibraryFrameFileDetail : AppFrameFileDetail; - const lineNumber = idx(stackframe, _ => _.line.number) || 0; + const lineNumber = stackframe.line.number; return ( {stackframe.filename} in{' '} diff --git a/x-pack/legacy/plugins/apm/public/components/shared/Summary/TransactionSummary.tsx b/x-pack/legacy/plugins/apm/public/components/shared/Summary/TransactionSummary.tsx index b6e783a00b5d6..4de70895ff32b 100644 --- a/x-pack/legacy/plugins/apm/public/components/shared/Summary/TransactionSummary.tsx +++ b/x-pack/legacy/plugins/apm/public/components/shared/Summary/TransactionSummary.tsx @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ import React from 'react'; -import { idx } from '@kbn/elastic-idx'; import { Transaction } from '../../../../typings/es_schemas/ui/Transaction'; import { Summary } from './'; import { TimestampTooltip } from '../TimestampTooltip'; @@ -22,15 +21,17 @@ interface Props { } const getTransactionResultSummaryItem = (transaction: Transaction) => { - const result = idx(transaction, _ => _.transaction.result); + const result = transaction.transaction.result; const isRumAgent = isRumAgentName(transaction.agent.name); const url = isRumAgent - ? idx(transaction, _ => _.transaction.page.url) - : idx(transaction, _ => _.url.full); + ? transaction.transaction.page?.url + : transaction.url?.full; if (url) { - const method = idx(transaction, _ => _.http.request.method); - const status = idx(transaction, _ => _.http.response.status_code); + const method = transaction.http?.request.method; + // TODO(TS-3.7-ESLINT) + // eslint-disable-next-line @typescript-eslint/camelcase + const status = transaction.http?.response?.status_code; return ; } diff --git a/x-pack/legacy/plugins/apm/public/components/shared/TransactionActionMenu/TransactionActionMenu.tsx b/x-pack/legacy/plugins/apm/public/components/shared/TransactionActionMenu/TransactionActionMenu.tsx index 533bc845f14f9..4a3b77b699c5f 100644 --- a/x-pack/legacy/plugins/apm/public/components/shared/TransactionActionMenu/TransactionActionMenu.tsx +++ b/x-pack/legacy/plugins/apm/public/components/shared/TransactionActionMenu/TransactionActionMenu.tsx @@ -17,7 +17,6 @@ import { import url from 'url'; import { i18n } from '@kbn/i18n'; import React, { useState, FunctionComponent } from 'react'; -import { idx } from '@kbn/elastic-idx'; import { pick } from 'lodash'; import { Transaction } from '../../../../typings/es_schemas/ui/Transaction'; import { DiscoverTransactionLink } from '../Links/DiscoverLinks/DiscoverTransactionLink'; @@ -72,9 +71,9 @@ export const TransactionActionMenu: FunctionComponent = ( const { urlParams } = useUrlParams(); - const hostName = idx(transaction, _ => _.host.hostname); - const podId = idx(transaction, _ => _.kubernetes.pod.uid); - const containerId = idx(transaction, _ => _.container.id); + const hostName = transaction.host?.hostname; + const podId = transaction.kubernetes?.pod.uid; + const containerId = transaction.container?.id; const time = Math.round(transaction.timestamp.us / 1000); const infraMetricsQuery = getInfraMetricsQuery(transaction); @@ -175,7 +174,7 @@ export const TransactionActionMenu: FunctionComponent = ( { dateRangeStart: urlParams.rangeFrom, dateRangeEnd: urlParams.rangeTo, - search: `url.domain:"${idx(transaction, t => t.url.domain)}"` + search: `url.domain:"${transaction.url?.domain}"` }, (val: string) => !!val ) @@ -209,7 +208,7 @@ export const TransactionActionMenu: FunctionComponent = ( })} ), - condition: idx(transaction, _ => _.url.domain) + condition: transaction.url?.domain } ] .filter(({ condition }) => condition) diff --git a/x-pack/legacy/plugins/apm/public/components/shared/charts/TransactionCharts/index.tsx b/x-pack/legacy/plugins/apm/public/components/shared/charts/TransactionCharts/index.tsx index b5894a9d91e4a..bb4d9fa264980 100644 --- a/x-pack/legacy/plugins/apm/public/components/shared/charts/TransactionCharts/index.tsx +++ b/x-pack/legacy/plugins/apm/public/components/shared/charts/TransactionCharts/index.tsx @@ -19,7 +19,6 @@ import { Location } from 'history'; import React, { Component } from 'react'; import { isEmpty, flatten } from 'lodash'; import styled from 'styled-components'; -import { idx } from '@kbn/elastic-idx'; import { NOT_AVAILABLE_LABEL } from '../../../../../common/i18n'; import { Coordinate, TimeSeries } from '../../../../../typings/timeseries'; import { ITransactionChartData } from '../../../../selectors/chartSelectors'; @@ -172,9 +171,9 @@ export class TransactionCharts extends Component { {license => - this.renderMLHeader( - idx(license, _ => _.features.ml.is_available) - ) + // TODO(TS-3.7-ESLINT) + // eslint-disable-next-line @typescript-eslint/camelcase + this.renderMLHeader(license.features.ml?.is_available) } diff --git a/x-pack/legacy/plugins/apm/public/hooks/useFetcher.tsx b/x-pack/legacy/plugins/apm/public/hooks/useFetcher.tsx index bc6382841be3f..2d60273c1896a 100644 --- a/x-pack/legacy/plugins/apm/public/hooks/useFetcher.tsx +++ b/x-pack/legacy/plugins/apm/public/hooks/useFetcher.tsx @@ -5,7 +5,6 @@ */ import React, { useContext, useEffect, useState, useMemo } from 'react'; -import { idx } from '@kbn/elastic-idx'; import { i18n } from '@kbn/i18n'; import { IHttpFetchError } from 'src/core/public'; import { toMountPoint } from '../../../../../../src/plugins/kibana_react/public'; @@ -100,14 +99,13 @@ export function useFetcher( defaultMessage: `Error` })} - {idx(err.response, r => r.statusText)} ( - {idx(err.response, r => r.status)}) + {err.response?.statusText} ({err.response?.status})
{i18n.translate('xpack.apm.fetcher.error.url', { defaultMessage: `URL` })}
- {idx(err.response, r => r.url)} + {err.response?.url}
) }); diff --git a/x-pack/legacy/plugins/apm/server/lib/errors/distribution/get_buckets.ts b/x-pack/legacy/plugins/apm/server/lib/errors/distribution/get_buckets.ts index afb8237178a20..37889e69ad8f2 100644 --- a/x-pack/legacy/plugins/apm/server/lib/errors/distribution/get_buckets.ts +++ b/x-pack/legacy/plugins/apm/server/lib/errors/distribution/get_buckets.ts @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import { idx } from '@kbn/elastic-idx'; import { ESFilter } from '../../../../typings/elasticsearch'; import { ERROR_GROUP_ID, @@ -64,12 +63,12 @@ export async function getBuckets({ const resp = await client.search(params); - const buckets = ( - idx(resp.aggregations, _ => _.distribution.buckets) || [] - ).map(bucket => ({ - key: bucket.key, - count: bucket.doc_count - })); + const buckets = (resp.aggregations?.distribution.buckets || []).map( + bucket => ({ + key: bucket.key, + count: bucket.doc_count + }) + ); return { noHits: resp.hits.total.value === 0, diff --git a/x-pack/legacy/plugins/apm/server/lib/errors/get_error_group.ts b/x-pack/legacy/plugins/apm/server/lib/errors/get_error_group.ts index caadbfef32698..fd1199d07b95f 100644 --- a/x-pack/legacy/plugins/apm/server/lib/errors/get_error_group.ts +++ b/x-pack/legacy/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 { idx } from '@kbn/elastic-idx'; import { ERROR_GROUP_ID, PROCESSOR_EVENT, @@ -55,9 +54,9 @@ export async function getErrorGroup({ }; const resp = await client.search(params); - const error = idx(resp, _ => _.hits.hits[0]._source); - const transactionId = idx(error, _ => _.transaction.id); - const traceId = idx(error, _ => _.trace.id); + const error = resp.hits.hits[0]?._source; + const transactionId = error?.transaction?.id; + const traceId = error?.trace?.id; let transaction; if (transactionId && traceId) { diff --git a/x-pack/legacy/plugins/apm/server/lib/errors/get_error_groups.ts b/x-pack/legacy/plugins/apm/server/lib/errors/get_error_groups.ts index 193ee4c2bbd1c..baaa2d97752e3 100644 --- a/x-pack/legacy/plugins/apm/server/lib/errors/get_error_groups.ts +++ b/x-pack/legacy/plugins/apm/server/lib/errors/get_error_groups.ts @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import { idx } from '@kbn/elastic-idx'; import { ERROR_CULPRIT, ERROR_EXC_HANDLED, @@ -106,23 +105,22 @@ export async function getErrorGroups({ // aggregations can be undefined when no matching indices are found. // this is an exception rather than the rule so the ES type does not account for this. - const hits = (idx(resp, _ => _.aggregations.error_groups.buckets) || []).map( - bucket => { - const source = bucket.sample.hits.hits[0]._source; - const message = - idx(source, _ => _.error.log.message) || - idx(source, _ => _.error.exception[0].message); + // TODO(TS-3.7-ESLINT) + // eslint-disable-next-line @typescript-eslint/camelcase + const hits = (resp.aggregations?.error_groups.buckets || []).map(bucket => { + const source = bucket.sample.hits.hits[0]._source; + const message = + source.error.log?.message || source.error.exception?.[0]?.message; - return { - message, - occurrenceCount: bucket.doc_count, - culprit: source.error.culprit, - groupId: source.error.grouping_key, - latestOccurrenceAt: source['@timestamp'], - handled: idx(source, _ => _.error.exception[0].handled) - }; - } - ); + return { + message, + occurrenceCount: bucket.doc_count, + culprit: source.error.culprit, + groupId: source.error.grouping_key, + latestOccurrenceAt: source['@timestamp'], + handled: source.error.exception?.[0].handled + }; + }); return hits; } diff --git a/x-pack/legacy/plugins/apm/server/lib/errors/get_trace_errors_per_transaction.ts b/x-pack/legacy/plugins/apm/server/lib/errors/get_trace_errors_per_transaction.ts index 9a6aed02e2a84..5074f9315d8ae 100644 --- a/x-pack/legacy/plugins/apm/server/lib/errors/get_trace_errors_per_transaction.ts +++ b/x-pack/legacy/plugins/apm/server/lib/errors/get_trace_errors_per_transaction.ts @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import { idx } from '@kbn/elastic-idx'; import { ERROR_LOG_LEVEL, PROCESSOR_EVENT, @@ -55,7 +54,7 @@ export async function getTraceErrorsPerTransaction( const resp = await client.search(params); - return (idx(resp.aggregations, _ => _.transactions.buckets) || []).reduce( + return (resp.aggregations?.transactions.buckets || []).reduce( (acc, bucket) => ({ ...acc, [bucket.key]: bucket.doc_count diff --git a/x-pack/legacy/plugins/apm/server/lib/helpers/convert_ui_filters/get_kuery_ui_filter_es.ts b/x-pack/legacy/plugins/apm/server/lib/helpers/convert_ui_filters/get_kuery_ui_filter_es.ts index 2543c2b9a8a61..9e5f8bb266054 100644 --- a/x-pack/legacy/plugins/apm/server/lib/helpers/convert_ui_filters/get_kuery_ui_filter_es.ts +++ b/x-pack/legacy/plugins/apm/server/lib/helpers/convert_ui_filters/get_kuery_ui_filter_es.ts @@ -5,7 +5,6 @@ */ import { Server } from 'hapi'; -import { idx } from '@kbn/elastic-idx'; import { toElasticsearchQuery, fromKueryExpression } from '@kbn/es-query'; import { ESFilter } from '../../../../typings/elasticsearch'; import { ISavedObject } from '../../../../public/services/rest/savedObjects'; @@ -31,8 +30,8 @@ export async function getKueryUiFilterES( } // lifted from src/legacy/ui/public/index_patterns/static_utils/index.js -export function getFromSavedObject(apmIndexPattern: ISavedObject) { - if (idx(apmIndexPattern, _ => _.attributes.fields) === undefined) { +export function getFromSavedObject(apmIndexPattern: ISavedObject | undefined) { + if (apmIndexPattern?.attributes.fields === undefined) { return; } diff --git a/x-pack/legacy/plugins/apm/server/lib/metrics/by_agent/java/gc/fetchAndTransformGcMetrics.ts b/x-pack/legacy/plugins/apm/server/lib/metrics/by_agent/java/gc/fetchAndTransformGcMetrics.ts index f785e45062807..180537d68a2a2 100644 --- a/x-pack/legacy/plugins/apm/server/lib/metrics/by_agent/java/gc/fetchAndTransformGcMetrics.ts +++ b/x-pack/legacy/plugins/apm/server/lib/metrics/by_agent/java/gc/fetchAndTransformGcMetrics.ts @@ -9,7 +9,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import { idx } from '@kbn/elastic-idx'; import { sum, round } from 'lodash'; import theme from '@elastic/eui/dist/eui_theme_light.json'; import { Setup } from '../../../../helpers/setup_request'; @@ -113,7 +112,7 @@ export async function fetchAndTransformGcMetrics({ const response = await client.search(params); - const aggregations = idx(response, _ => _.aggregations); + const { aggregations } = response; if (!aggregations) { return { @@ -127,11 +126,12 @@ export async function fetchAndTransformGcMetrics({ const label = poolBucket.key as string; const timeseriesData = poolBucket.over_time; - const data = (idx(timeseriesData, _ => _.buckets) || []).map(bucket => { + const data = timeseriesData.buckets.map(bucket => { // derivative/value will be undefined for the first hit and if the `max` value is null + const bucketValue = bucket.value?.value; const y = - 'value' in bucket && bucket.value.value !== null - ? round(bucket.value.value * (60 / bucketSize), 1) + bucketValue !== null && bucketValue !== undefined && bucket.value + ? round(bucketValue * (60 / bucketSize), 1) : null; return { diff --git a/x-pack/legacy/plugins/apm/server/lib/metrics/transform_metrics_chart.ts b/x-pack/legacy/plugins/apm/server/lib/metrics/transform_metrics_chart.ts index 3764f18a6d692..1e7f197435a67 100644 --- a/x-pack/legacy/plugins/apm/server/lib/metrics/transform_metrics_chart.ts +++ b/x-pack/legacy/plugins/apm/server/lib/metrics/transform_metrics_chart.ts @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ import theme from '@elastic/eui/dist/eui_theme_light.json'; -import { idx } from '@kbn/elastic-idx'; import { Unionize, Overwrite } from 'utility-types'; import { ChartBase } from './types'; import { @@ -53,7 +52,7 @@ export function transformDataToMetricsChart( chartBase: ChartBase ) { const { aggregations, hits } = result; - const timeseriesData = idx(aggregations, _ => _.timeseriesData); + const timeseriesData = aggregations?.timeseriesData; return { title: chartBase.title, @@ -61,7 +60,7 @@ export function transformDataToMetricsChart( yUnit: chartBase.yUnit, noHits: hits.total.value === 0, series: Object.keys(chartBase.series).map((seriesKey, i) => { - const overallValue = idx(aggregations, _ => _[seriesKey].value); + const overallValue = aggregations?.[seriesKey].value; return { title: chartBase.series[seriesKey].title, @@ -69,14 +68,15 @@ export function transformDataToMetricsChart( type: chartBase.type, color: chartBase.series[seriesKey].color || colors[i], overallValue, - data: (idx(timeseriesData, _ => _.buckets) || []).map(bucket => { - const { value } = bucket[seriesKey] as { value: number | null }; - const y = value === null || isNaN(value) ? null : value; - return { - x: bucket.key, - y - }; - }) + data: + timeseriesData?.buckets.map(bucket => { + const { value } = bucket[seriesKey] as { value: number | null }; + const y = value === null || isNaN(value) ? null : value; + return { + x: bucket.key, + y + }; + }) || [] }; }) }; diff --git a/x-pack/legacy/plugins/apm/server/lib/services/get_service_agent_name.ts b/x-pack/legacy/plugins/apm/server/lib/services/get_service_agent_name.ts index bbb18eae7eb09..9e070f936a25f 100644 --- a/x-pack/legacy/plugins/apm/server/lib/services/get_service_agent_name.ts +++ b/x-pack/legacy/plugins/apm/server/lib/services/get_service_agent_name.ts @@ -3,7 +3,6 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import { idx } from '@kbn/elastic-idx'; import { PROCESSOR_EVENT, SERVICE_AGENT_NAME, @@ -44,8 +43,6 @@ export async function getServiceAgentName(serviceName: string, setup: Setup) { }; const { aggregations } = await client.search(params); - const agentName = idx(aggregations, _ => _.agents.buckets[0].key) as - | string - | undefined; + const agentName = aggregations?.agents.buckets[0]?.key as string | undefined; return { agentName }; } diff --git a/x-pack/legacy/plugins/apm/server/lib/services/get_service_node_metadata.ts b/x-pack/legacy/plugins/apm/server/lib/services/get_service_node_metadata.ts index 88e9670f4b444..e93f6b4a1c17c 100644 --- a/x-pack/legacy/plugins/apm/server/lib/services/get_service_node_metadata.ts +++ b/x-pack/legacy/plugins/apm/server/lib/services/get_service_node_metadata.ts @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import { idx } from '@kbn/elastic-idx'; import { Setup } from '../helpers/setup_request'; import { HOST_NAME, @@ -55,11 +54,8 @@ export async function getServiceNodeMetadata({ const response = await client.search(query); return { - host: - idx(response, _ => _.aggregations.host.buckets[0].key) || - NOT_AVAILABLE_LABEL, + host: response.aggregations?.host.buckets[0].key || NOT_AVAILABLE_LABEL, containerId: - idx(response, _ => _.aggregations.containerId.buckets[0].key) || - NOT_AVAILABLE_LABEL + response.aggregations?.containerId.buckets[0].key || NOT_AVAILABLE_LABEL }; } diff --git a/x-pack/legacy/plugins/apm/server/lib/services/get_service_transaction_types.ts b/x-pack/legacy/plugins/apm/server/lib/services/get_service_transaction_types.ts index 00ffa7484bb48..098342bf0221d 100644 --- a/x-pack/legacy/plugins/apm/server/lib/services/get_service_transaction_types.ts +++ b/x-pack/legacy/plugins/apm/server/lib/services/get_service_transaction_types.ts @@ -3,7 +3,6 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import { idx } from '@kbn/elastic-idx'; import { PROCESSOR_EVENT, SERVICE_NAME, @@ -40,7 +39,7 @@ export async function getServiceTransactionTypes( }; const { aggregations } = await client.search(params); - const buckets = idx(aggregations, _ => _.types.buckets) || []; - const transactionTypes = buckets.map(bucket => bucket.key as string); + const transactionTypes = + aggregations?.types.buckets.map(bucket => bucket.key as string) || []; return { transactionTypes }; } diff --git a/x-pack/legacy/plugins/apm/server/lib/services/get_services/get_services_items.ts b/x-pack/legacy/plugins/apm/server/lib/services/get_services/get_services_items.ts index 60f3091567059..240a3bd35cbea 100644 --- a/x-pack/legacy/plugins/apm/server/lib/services/get_services/get_services_items.ts +++ b/x-pack/legacy/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 { idx } from '@kbn/elastic-idx'; import { mergeProjection } from '../../../../common/projections/util/merge_projection'; import { PROCESSOR_EVENT, @@ -53,16 +52,20 @@ export async function getServicesItems(setup: Setup) { const resp = await client.search(params); const aggs = resp.aggregations; - const serviceBuckets = idx(aggs, _ => _.services.buckets) || []; + const serviceBuckets = aggs?.services.buckets || []; const items = serviceBuckets.map(bucket => { const eventTypes = bucket.events.buckets; const transactions = eventTypes.find(e => e.key === 'transaction'); - const totalTransactions = idx(transactions, _ => _.doc_count) || 0; + // TODO(TS-3.7-ESLINT) + // eslint-disable-next-line @typescript-eslint/camelcase + const totalTransactions = transactions?.doc_count || 0; const errors = eventTypes.find(e => e.key === 'error'); - const totalErrors = idx(errors, _ => _.doc_count) || 0; + // TODO(TS-3.7-ESLINT) + // eslint-disable-next-line @typescript-eslint/camelcase + const totalErrors = errors?.doc_count || 0; const deltaAsMinutes = (end - start) / 1000 / 60; const transactionsPerMinute = totalTransactions / deltaAsMinutes; @@ -75,9 +78,7 @@ export async function getServicesItems(setup: Setup) { return { serviceName: bucket.key as string, - agentName: idx(bucket, _ => _.agents.buckets[0].key) as - | string - | undefined, + agentName: bucket.agents.buckets[0]?.key as string | undefined, transactionsPerMinute, errorsPerMinute, avgResponseTime: bucket.avg.value, diff --git a/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/get_agent_name_by_service.ts b/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/get_agent_name_by_service.ts index 21663b813f01f..83df9153e557b 100644 --- a/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/get_agent_name_by_service.ts +++ b/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/get_agent_name_by_service.ts @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import { idx } from '@kbn/elastic-idx'; import { Setup } from '../../helpers/setup_request'; import { PROCESSOR_EVENT, @@ -49,7 +48,9 @@ export async function getAgentNameByService({ }; const { aggregations } = await client.search(params); - const agentName = idx(aggregations, _ => _.agent_names.buckets[0].key) as + // TODO(TS-3.7-ESLINT) + // eslint-disable-next-line @typescript-eslint/camelcase + const agentName = aggregations?.agent_names.buckets[0].key as | string | undefined; return { agentName }; diff --git a/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/get_environments/get_all_environments.ts b/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/get_environments/get_all_environments.ts index 8215e2b9fd668..52a3422f8e6b7 100644 --- a/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/get_environments/get_all_environments.ts +++ b/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/get_environments/get_all_environments.ts @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import { idx } from '@kbn/elastic-idx'; import { Setup } from '../../../helpers/setup_request'; import { PROCESSOR_EVENT, @@ -57,7 +56,9 @@ export async function getAllEnvironments({ }; const resp = await client.search(params); - const buckets = idx(resp.aggregations, _ => _.environments.buckets) || []; - const environments = buckets.map(bucket => bucket.key as string); + const environments = + resp.aggregations?.environments.buckets.map( + bucket => bucket.key as string + ) || []; return [ALL_OPTION_VALUE, ...environments]; } diff --git a/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/get_environments/get_existing_environments_for_service.ts b/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/get_environments/get_existing_environments_for_service.ts index 52efc2b50305b..fc3b62738f8fe 100644 --- a/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/get_environments/get_existing_environments_for_service.ts +++ b/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/get_environments/get_existing_environments_for_service.ts @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import { idx } from '@kbn/elastic-idx'; import { Setup } from '../../../helpers/setup_request'; import { SERVICE_NAME, @@ -43,6 +42,9 @@ export async function getExistingEnvironmentsForService({ }; const resp = await internalClient.search(params); - const buckets = idx(resp.aggregations, _ => _.environments.buckets) || []; - return buckets.map(bucket => bucket.key as string); + const existingEnvironments = + resp.aggregations?.environments.buckets.map( + bucket => bucket.key as string + ) || []; + return existingEnvironments; } diff --git a/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/get_service_names.ts b/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/get_service_names.ts index 51a4564f53576..9b9acbb1e0ad5 100644 --- a/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/get_service_names.ts +++ b/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/get_service_names.ts @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import { idx } from '@kbn/elastic-idx'; import { Setup } from '../../helpers/setup_request'; import { PromiseReturnType } from '../../../../typings/common'; import { @@ -46,7 +45,9 @@ export async function getServiceNames({ setup }: { setup: Setup }) { }; const resp = await client.search(params); - const buckets = idx(resp.aggregations, _ => _.services.buckets) || []; - const serviceNames = buckets.map(bucket => bucket.key as string).sort(); + const serviceNames = + resp.aggregations?.services.buckets + .map(bucket => bucket.key as string) + .sort() || []; return [ALL_OPTION_VALUE, ...serviceNames]; } diff --git a/x-pack/legacy/plugins/apm/server/lib/transaction_groups/transform.ts b/x-pack/legacy/plugins/apm/server/lib/transaction_groups/transform.ts index 3ec64be08d117..58a952baa8233 100644 --- a/x-pack/legacy/plugins/apm/server/lib/transaction_groups/transform.ts +++ b/x-pack/legacy/plugins/apm/server/lib/transaction_groups/transform.ts @@ -5,7 +5,6 @@ */ import moment from 'moment'; -import { idx } from '@kbn/elastic-idx'; import { ESResponse } from './fetcher'; function calculateRelativeImpacts(transactionGroups: ITransactionGroup[]) { @@ -54,7 +53,7 @@ export function transactionGroupsTransformer({ start: number; end: number; }): ITransactionGroup[] { - const buckets = idx(response, _ => _.aggregations.transactions.buckets) || []; + const buckets = response.aggregations?.transactions.buckets || []; const duration = moment.duration(end - start); const minutes = duration.asMinutes(); const transactionGroups = buckets.map(bucket => diff --git a/x-pack/legacy/plugins/apm/server/lib/transactions/breakdown/index.ts b/x-pack/legacy/plugins/apm/server/lib/transactions/breakdown/index.ts index 3d425415de832..1c84c68fd8c47 100644 --- a/x-pack/legacy/plugins/apm/server/lib/transactions/breakdown/index.ts +++ b/x-pack/legacy/plugins/apm/server/lib/transactions/breakdown/index.ts @@ -5,7 +5,6 @@ */ import { flatten, sortByOrder, last } from 'lodash'; -import { idx } from '@kbn/elastic-idx'; import { SERVICE_NAME, SPAN_SUBTYPE, @@ -149,7 +148,9 @@ export async function getTransactionBreakdown({ const kpiNames = kpis.map(kpi => kpi.name); - const bucketsByDate = idx(resp.aggregations, _ => _.by_date.buckets) || []; + // TODO(TS-3.7-ESLINT) + // eslint-disable-next-line @typescript-eslint/camelcase + const bucketsByDate = resp.aggregations?.by_date.buckets || []; const timeseriesPerSubtype = bucketsByDate.reduce((prev, bucket) => { const formattedValues = formatBucket(bucket); diff --git a/x-pack/legacy/plugins/apm/server/lib/transactions/charts/get_anomaly_data/get_ml_bucket_size.ts b/x-pack/legacy/plugins/apm/server/lib/transactions/charts/get_anomaly_data/get_ml_bucket_size.ts index 27cff20b7ff37..dfa9e9b70abdb 100644 --- a/x-pack/legacy/plugins/apm/server/lib/transactions/charts/get_anomaly_data/get_ml_bucket_size.ts +++ b/x-pack/legacy/plugins/apm/server/lib/transactions/charts/get_anomaly_data/get_ml_bucket_size.ts @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import { idx } from '@kbn/elastic-idx'; import { getMlIndex } from '../../../../../common/ml_job_constants'; import { Setup } from '../../../helpers/setup_request'; @@ -50,7 +49,9 @@ export async function getMlBucketSize({ try { const resp = await client.search(params); - return idx(resp, _ => _.hits.hits[0]._source.bucket_span) || 0; + // TODO(TS-3.7-ESLINT) + // eslint-disable-next-line @typescript-eslint/camelcase + return resp.hits.hits[0]?._source.bucket_span || 0; } catch (err) { const isHttpError = 'statusCode' in err; if (isHttpError) { diff --git a/x-pack/legacy/plugins/apm/server/lib/transactions/charts/get_anomaly_data/transform.test.ts b/x-pack/legacy/plugins/apm/server/lib/transactions/charts/get_anomaly_data/transform.test.ts index eab68a2bda974..83a7ffe1f2412 100644 --- a/x-pack/legacy/plugins/apm/server/lib/transactions/charts/get_anomaly_data/transform.test.ts +++ b/x-pack/legacy/plugins/apm/server/lib/transactions/charts/get_anomaly_data/transform.test.ts @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import { idx } from '@kbn/elastic-idx'; import { ESResponse } from './fetcher'; import { mlAnomalyResponse } from './mock-responses/mlAnomalyResponse'; import { anomalySeriesTransform, replaceFirstAndLastBucket } from './transform'; @@ -291,10 +290,12 @@ function getESResponse(buckets: any): ESResponse { buckets: buckets.map((bucket: any) => { return { ...bucket, - lower: { value: idx(bucket, _ => _.lower.value) || null }, - upper: { value: idx(bucket, _ => _.upper.value) || null }, + lower: { value: bucket?.lower?.value || null }, + upper: { value: bucket?.upper?.value || null }, anomaly_score: { - value: idx(bucket, _ => _.anomaly_score.value) || null + // TODO(TS-3.7-ESLINT) + // eslint-disable-next-line @typescript-eslint/camelcase + value: bucket?.anomaly_score?.value || null } }; }) diff --git a/x-pack/legacy/plugins/apm/server/lib/transactions/charts/get_anomaly_data/transform.ts b/x-pack/legacy/plugins/apm/server/lib/transactions/charts/get_anomaly_data/transform.ts index 0cc283fb51d91..2994990067d00 100644 --- a/x-pack/legacy/plugins/apm/server/lib/transactions/charts/get_anomaly_data/transform.ts +++ b/x-pack/legacy/plugins/apm/server/lib/transactions/charts/get_anomaly_data/transform.ts @@ -5,7 +5,6 @@ */ import { first, last } from 'lodash'; -import { idx } from '@kbn/elastic-idx'; import { Coordinate, RectCoordinate } from '../../../../../typings/timeseries'; import { ESResponse } from './fetcher'; @@ -32,9 +31,10 @@ export function anomalySeriesTransform( bucketSize: number, timeSeriesDates: number[] ) { - const buckets = ( - idx(response, _ => _.aggregations.ml_avg_response_times.buckets) || [] - ).map(getBucket); + const buckets = + // TODO(TS-3.7-ESLINT) + // eslint-disable-next-line @typescript-eslint/camelcase + response.aggregations?.ml_avg_response_times.buckets.map(getBucket) || []; const bucketSizeInMillis = Math.max(bucketSize, mlBucketSize) * 1000; diff --git a/x-pack/legacy/plugins/apm/server/lib/transactions/charts/get_timeseries_data/transform.ts b/x-pack/legacy/plugins/apm/server/lib/transactions/charts/get_timeseries_data/transform.ts index 42828367f7941..1752258078add 100644 --- a/x-pack/legacy/plugins/apm/server/lib/transactions/charts/get_timeseries_data/transform.ts +++ b/x-pack/legacy/plugins/apm/server/lib/transactions/charts/get_timeseries_data/transform.ts @@ -5,7 +5,6 @@ */ import { isNumber, round, sortBy } from 'lodash'; -import { idx } from '@kbn/elastic-idx'; import { NOT_AVAILABLE_LABEL } from '../../../../../common/i18n'; import { Coordinate } from '../../../../../typings/timeseries'; import { ESResponse } from './fetcher'; @@ -20,14 +19,16 @@ export function timeseriesTransformer({ bucketSize: number; }) { const aggs = timeseriesResponse.aggregations; - const overallAvgDuration = - idx(aggs, _ => _.overall_avg_duration.value) || null; - const responseTimeBuckets = idx(aggs, _ => _.response_times.buckets); + // TODO(TS-3.7-ESLINT) + // eslint-disable-next-line @typescript-eslint/camelcase + const overallAvgDuration = aggs?.overall_avg_duration.value || null; + // TODO(TS-3.7-ESLINT) + // eslint-disable-next-line @typescript-eslint/camelcase + const responseTimeBuckets = aggs?.response_times.buckets || []; const { avg, p95, p99 } = getResponseTime(responseTimeBuckets); - const transactionResultBuckets = idx( - aggs, - _ => _.transaction_results.buckets - ); + // TODO(TS-3.7-ESLINT) + // eslint-disable-next-line @typescript-eslint/camelcase + const transactionResultBuckets = aggs?.transaction_results.buckets || []; const tpmBuckets = getTpmBuckets(transactionResultBuckets, bucketSize); return { diff --git a/x-pack/legacy/plugins/apm/server/lib/transactions/distribution/get_buckets/transform.ts b/x-pack/legacy/plugins/apm/server/lib/transactions/distribution/get_buckets/transform.ts index 827194edd6aa3..a16e08138b87f 100644 --- a/x-pack/legacy/plugins/apm/server/lib/transactions/distribution/get_buckets/transform.ts +++ b/x-pack/legacy/plugins/apm/server/lib/transactions/distribution/get_buckets/transform.ts @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import { idx } from '@kbn/elastic-idx'; import { PromiseReturnType } from '../../../../../typings/common'; import { Transaction } from '../../../../../typings/es_schemas/ui/Transaction'; import { bucketFetcher } from './fetcher'; @@ -17,13 +16,14 @@ function getBucket( DistributionBucketResponse >['aggregations']['distribution']['buckets'][0] ) { - const sampleSource = idx(bucket, _ => _.sample.hits.hits[0]._source) as + const sampleSource = bucket.sample.hits.hits[0]?._source as | Transaction | undefined; - const isSampled = idx(sampleSource, _ => _.transaction.sampled); + + const isSampled = sampleSource?.transaction.sampled; const sample = { - traceId: idx(sampleSource, _ => _.trace.id), - transactionId: idx(sampleSource, _ => _.transaction.id) + traceId: sampleSource?.trace.id, + transactionId: sampleSource?.transaction.id }; return { @@ -34,9 +34,8 @@ function getBucket( } export function bucketTransformer(response: DistributionBucketResponse) { - const buckets = ( - idx(response.aggregations, _ => _.distribution.buckets) || [] - ).map(getBucket); + const buckets = + response.aggregations?.distribution.buckets.map(getBucket) || []; return { noHits: response.hits.total.value === 0, diff --git a/x-pack/legacy/plugins/apm/server/lib/transactions/get_transaction/index.ts b/x-pack/legacy/plugins/apm/server/lib/transactions/get_transaction/index.ts index 20152ecf06480..652acf773e2e5 100644 --- a/x-pack/legacy/plugins/apm/server/lib/transactions/get_transaction/index.ts +++ b/x-pack/legacy/plugins/apm/server/lib/transactions/get_transaction/index.ts @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import { idx } from '@kbn/elastic-idx'; import { PROCESSOR_EVENT, TRACE_ID, @@ -40,5 +39,5 @@ export async function getTransaction( }; const resp = await client.search(params); - return idx(resp, _ => _.hits.hits[0]._source); + return resp.hits.hits[0]?._source; } diff --git a/x-pack/legacy/plugins/apm/server/lib/ui_filters/get_environments.ts b/x-pack/legacy/plugins/apm/server/lib/ui_filters/get_environments.ts index ade491be32fc7..1b9e2ebd2e757 100644 --- a/x-pack/legacy/plugins/apm/server/lib/ui_filters/get_environments.ts +++ b/x-pack/legacy/plugins/apm/server/lib/ui_filters/get_environments.ts @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import { idx } from '@kbn/elastic-idx'; import { PROCESSOR_EVENT, SERVICE_ENVIRONMENT, @@ -55,7 +54,7 @@ export async function getEnvironments(setup: Setup, serviceName?: string) { const resp = await client.search(params); const aggs = resp.aggregations; - const environmentsBuckets = idx(aggs, _ => _.environments.buckets) || []; + const environmentsBuckets = aggs?.environments.buckets || []; const environments = environmentsBuckets.map( environmentBucket => environmentBucket.key as string