Skip to content

Commit

Permalink
[ML] Address comments, rename
Browse files Browse the repository at this point in the history
  • Loading branch information
qn895 committed Aug 16, 2021
1 parent e70878c commit 1554436
Show file tree
Hide file tree
Showing 17 changed files with 98 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

import { i18n } from '@kbn/i18n';

export const FAILURE_CORRELATION_SEARCH_STRATEGY =
'apmFailureCorrelationsSearchStrategy';
export const FAILED_TRANSACTIONS_CORRELATION_SEARCH_STRATEGY =
'apmFailedTransactionsCorrelationsSearchStrategy';

export const FAILURE_CORRELATION_IMPACT_THRESHOLD = {
HIGH: i18n.translate(
'xpack.apm.correlations.failedTransactions.highImpactText',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { FAILURE_CORRELATION_IMPACT_THRESHOLD } from './constants';

export interface FailureCorrelationValue {
export interface FailedTransactionsCorrelationValue {
key: string;
doc_count: number;
bg_count: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,31 @@ import { CorrelationsTable } from './correlations_table';
import { enableInspectEsQueries } from '../../../../../observability/public';
import { asPreciseDecimal } from '../../../../common/utils/formatters';
import { useApmServiceContext } from '../../../context/apm_service/use_apm_service_context';
import { FailureCorrelationsHelpPopover } from './ml_failure_correlations_help_popover';
import { useCorrelationsSearchStrategy } from './use_correlations_search_strategy';
import { FailedTransactionsCorrelationsHelpPopover } from './failed_transactions_correlations_help_popover';
import { useFailedTransactionsCorrelationsSearchStrategy } from './use_failed_transactions_correlations_search_strategy';
import {
BaseSearchStrategyResponse,
FailureCorrelationValue,
FailedTransactionsCorrelationValue,
} from '../../../../common/search_strategies/failure_correlations/types';
import { ImpactBar } from '../../shared/ImpactBar';
import { FAILURE_CORRELATION_SEARCH_STRATEGY } from '../../../../common/search_strategies/failure_correlations/constants';
import { FAILED_TRANSACTIONS_CORRELATION_SEARCH_STRATEGY } from '../../../../common/search_strategies/failure_correlations/constants';
import { isErrorMessage } from './utils/is_error_message';
import { Summary } from '../../shared/Summary';
import { FETCH_STATUS } from '../../../hooks/use_fetcher';
import { getFailureCorrelationImpactLabel } from './utils/get_failure_correlation_impact_label';
import { getFailedTransactionsCorrelationImpactLabel } from './utils/get_failure_correlation_impact_label';
import { createHref, push } from '../../shared/Links/url_helpers';
import { useUiTracker } from '../../../../../observability/public';

interface Props {
onClose: () => void;
}

interface ErrorCorrelationSearchStrategyResult
interface FailedTransactionsCorrelationsSearchStrategyResult
extends BaseSearchStrategyResponse {
values: FailureCorrelationValue[];
values: FailedTransactionsCorrelationValue[];
}

export function MlFailureCorrelations({ onClose }: Props) {
export function FailedTransactionsCorrelations({ onClose }: Props) {
const {
core: { notifications, uiSettings },
} = useApmPluginContext();
Expand All @@ -68,21 +68,17 @@ export function MlFailureCorrelations({ onClose }: Props) {

const displayLog = uiSettings.get<boolean>(enableInspectEsQueries);

const result = useCorrelationsSearchStrategy<ErrorCorrelationSearchStrategyResult>(
const result = useFailedTransactionsCorrelationsSearchStrategy<FailedTransactionsCorrelationsSearchStrategyResult>(
{
...{
...{
environment,
kuery,
serviceName,
transactionName,
transactionType,
start,
end,
},
},
environment,
kuery,
serviceName,
transactionName,
transactionType,
start,
end,
},
FAILURE_CORRELATION_SEARCH_STRATEGY
FAILED_TRANSACTIONS_CORRELATION_SEARCH_STRATEGY
);

const {
Expand Down Expand Up @@ -110,7 +106,7 @@ export function MlFailureCorrelations({ onClose }: Props) {
const [
selectedSignificantTerm,
setSelectedSignificantTerm,
] = useState<FailureCorrelationValue | null>(null);
] = useState<FailedTransactionsCorrelationValue | null>(null);

const selectedTerm = useMemo(() => {
if (selectedSignificantTerm) return selectedSignificantTerm;
Expand All @@ -124,8 +120,8 @@ export function MlFailureCorrelations({ onClose }: Props) {
const history = useHistory();
const handleOnFilter = onClose;

const errorCorrelationsColumns: Array<
EuiBasicTableColumn<FailureCorrelationValue>
const failedTransactionsCorrelationsColumns: Array<
EuiBasicTableColumn<FailedTransactionsCorrelationValue>
> = useMemo(
() => [
{
Expand All @@ -134,7 +130,7 @@ export function MlFailureCorrelations({ onClose }: Props) {
name: (
<>
{i18n.translate(
'xpack.apm.correlations.failure.correlationsTable.pValueLabel',
'xpack.apm.correlations.failedTransactions.correlationsTable.pValueLabel',
{
defaultMessage: 'Score',
}
Expand All @@ -155,26 +151,26 @@ export function MlFailureCorrelations({ onClose }: Props) {
name: (
<>
{i18n.translate(
'xpack.apm.correlations.failure.correlationsTable.impactLabel',
'xpack.apm.correlations.failedTransactions.correlationsTable.impactLabel',
{
defaultMessage: 'Impact',
}
)}
</>
),
render: getFailureCorrelationImpactLabel,
render: getFailedTransactionsCorrelationImpactLabel,
},
{
field: 'fieldName',
name: i18n.translate(
'xpack.apm.correlations.failure.correlationsTable.fieldNameLabel',
'xpack.apm.correlations.failedTransactions.correlationsTable.fieldNameLabel',
{ defaultMessage: 'Field name' }
),
},
{
field: 'key',
name: i18n.translate(
'xpack.apm.correlations.failure.correlationsTable.fieldValueLabel',
'xpack.apm.correlations.failedTransactions.correlationsTable.fieldValueLabel',
{ defaultMessage: 'Field value' }
),
render: (fieldValue: string) => String(fieldValue).slice(0, 50),
Expand All @@ -193,7 +189,7 @@ export function MlFailureCorrelations({ onClose }: Props) {
),
icon: 'plusInCircle',
type: 'icon',
onClick: (term: FailureCorrelationValue) => {
onClick: (term: FailedTransactionsCorrelationValue) => {
push(history, {
query: {
kuery: `${term.fieldName}:"${encodeURIComponent(
Expand All @@ -216,7 +212,7 @@ export function MlFailureCorrelations({ onClose }: Props) {
),
icon: 'minusInCircle',
type: 'icon',
onClick: (term: FailureCorrelationValue) => {
onClick: (term: FailedTransactionsCorrelationValue) => {
push(history, {
query: {
kuery: `not ${term.fieldName}:"${encodeURIComponent(
Expand All @@ -233,7 +229,7 @@ export function MlFailureCorrelations({ onClose }: Props) {
'xpack.apm.correlations.correlationsTable.actionsLabel',
{ defaultMessage: 'Filter' }
),
render: (_: any, term: FailureCorrelationValue) => {
render: (_: unknown, term: FailedTransactionsCorrelationValue) => {
return (
<>
<EuiLink
Expand Down Expand Up @@ -270,10 +266,13 @@ export function MlFailureCorrelations({ onClose }: Props) {
useEffect(() => {
if (isErrorMessage(error)) {
notifications.toasts.addDanger({
title: i18n.translate('xpack.apm.correlations.failure.errorTitle', {
defaultMessage:
'An error occurred performing correlations on failed transactions',
}),
title: i18n.translate(
'xpack.apm.correlations.failedTransactions.errorTitle',
{
defaultMessage:
'An error occurred performing correlations on failed transactions',
}
),
text: error.toString(),
});
}
Expand All @@ -285,27 +284,27 @@ export function MlFailureCorrelations({ onClose }: Props) {
{!isRunning && (
<EuiButton size="s" onClick={startFetch}>
<FormattedMessage
id="xpack.apm.correlations.failure.refreshButtonTitle"
id="xpack.apm.correlations.failedTransactions.refreshButtonTitle"
defaultMessage="Refresh"
/>
</EuiButton>
)}
{isRunning && (
<EuiButton size="s" onClick={cancelFetch}>
<FormattedMessage
id="xpack.apm.correlations.failure.cancelButtonTitle"
id="xpack.apm.correlations.failedTransactions.cancelButtonTitle"
defaultMessage="Cancel"
/>
</EuiButton>
)}
</EuiFlexItem>
<EuiFlexItem>
<EuiFlexGroup direction="column" gutterSize="none">
<EuiFlexItem data-test-subj="apmCorrelationsfailedTransactionsCorrelationsProgressTitle">
<EuiFlexItem data-test-subj="apmCorrelationsFailedTransactionsCorrelationsProgressTitle">
<EuiText size="xs" color="subdued">
<FormattedMessage
data-test-subj="apmCorrelationsfailedTransactionsCorrelationsProgressTitle"
id="xpack.apm.correlations.failure.progressTitle"
data-test-subj="apmCorrelationsFailedTransactionsCorrelationsProgressMessage"
id="xpack.apm.correlations.failedTransactions.progressTitle"
defaultMessage="Progress: {progress}%"
values={{ progress: Math.round(progress * 100) }}
/>
Expand All @@ -314,7 +313,7 @@ export function MlFailureCorrelations({ onClose }: Props) {
<EuiFlexItem>
<EuiProgress
aria-label={i18n.translate(
'xpack.apm.correlations.failure.progressAriaLabel',
'xpack.apm.correlations.failedTransactions.progressAriaLabel',
{ defaultMessage: 'Progress' }
)}
value={Math.round(progress * 100)}
Expand All @@ -325,7 +324,7 @@ export function MlFailureCorrelations({ onClose }: Props) {
</EuiFlexGroup>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<FailureCorrelationsHelpPopover />
<FailedTransactionsCorrelationsHelpPopover />
</EuiFlexItem>
</EuiFlexGroup>
{selectedTerm ? (
Expand All @@ -336,18 +335,19 @@ export function MlFailureCorrelations({ onClose }: Props) {
<EuiBadge color="hollow">
{`${selectedTerm.fieldName}: ${selectedTerm.key}`}
</EuiBadge>,
`p-value: ${
<>{`p-value: ${
// Arbitrary threshold 0.00001
selectedTerm.pValue !== null && selectedTerm.pValue < 0.00001
? '<.00001'
: asPreciseDecimal(selectedTerm.pValue, 4)
}`,
}`}</>,
]}
/>
<EuiSpacer size="m" />
</>
) : null}
<CorrelationsTable<FailureCorrelationValue>
columns={errorCorrelationsColumns}
<CorrelationsTable<FailedTransactionsCorrelationValue>
columns={failedTransactionsCorrelationsColumns}
significantTerms={result?.response?.values}
status={FETCH_STATUS.SUCCESS}
setSelectedSignificantTerm={setSelectedSignificantTerm}
Expand All @@ -360,7 +360,7 @@ export function MlFailureCorrelations({ onClose }: Props) {
<EuiSpacer size="m" />
<EuiCallOut
title={i18n.translate(
'xpack.apm.correlations.failure.ccsWarningCalloutTitle',
'xpack.apm.correlations.failedTransactions.ccsWarningCalloutTitle',
{
defaultMessage: 'Cross-cluster search compatibility',
}
Expand All @@ -369,10 +369,10 @@ export function MlFailureCorrelations({ onClose }: Props) {
>
<p>
{i18n.translate(
'xpack.apm.correlations.failure.ccsWarningCalloutBody',
'xpack.apm.correlations.failedTransactions.ccsWarningCalloutBody',
{
defaultMessage:
'Data for the correlation analysis could not be fully retrieved. This feature is supported only for 7.14 and later versions.',
'Data for the correlation analysis could not be fully retrieved. This feature is supported only for 7.15 and later versions.',
}
)}
</p>
Expand All @@ -383,9 +383,9 @@ export function MlFailureCorrelations({ onClose }: Props) {

{log.length > 0 && displayLog && (
<EuiAccordion
id="accordion1"
id="apmFailedTransactionsCorrelationsLogAccordion"
buttonContent={i18n.translate(
'xpack.apm.correlations.failure.logButtonContent',
'xpack.apm.correlations.failedTransactions.logButtonContent',
{
defaultMessage: 'Log',
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { HelpPopover, HelpPopoverButton } from '../help_popover/help_popover';

export function FailureCorrelationsHelpPopover() {
export function FailedTransactionsCorrelationsHelpPopover() {
const [isPopoverOpen, setIsPopoverOpen] = useState(false);

return (
Expand Down
12 changes: 6 additions & 6 deletions x-pack/plugins/apm/public/components/app/correlations/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ import {
} from '../../../../common/elasticsearch_fieldnames';
import { useApmServiceContext } from '../../../context/apm_service/use_apm_service_context';
import { useApmParams } from '../../../hooks/use_apm_params';
import { MlFailureCorrelations } from './ml_failure_correlations';
import { FailedTransactionsCorrelations } from './failed_transactions_correlations';

const failureCorrelationsTab = {
key: 'errorRate',
const failedTransactionsCorrelationsTab = {
key: 'failedTransactionsCorrelations',
label: i18n.translate(
'xpack.apm.correlations.tabs.failureCorrelationsLabel',
'xpack.apm.correlations.tabs.failedTransactionsCorrelationsLabel',
{
defaultMessage: 'Failure correlations',
}
),
component: MlFailureCorrelations,
component: FailedTransactionsCorrelations,
};
const latencyCorrelationsTab = {
key: 'latencyCorrelations',
Expand All @@ -66,7 +66,7 @@ const latencyCorrelationsTab = {
}),
component: MlLatencyCorrelations,
};
const tabs = [latencyCorrelationsTab, failureCorrelationsTab];
const tabs = [latencyCorrelationsTab, failedTransactionsCorrelationsTab];

export function Correlations() {
const license = useLicenseContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface SearchStrategyOptions {
end?: string;
}

export function useCorrelationsSearchStrategy<
export function useFailedTransactionsCorrelationsSearchStrategy<
T extends BaseSearchStrategyResponse
>(params: SearchStrategyOptions, strategy: string) {
const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { FailureCorrelationImpactThreshold } from '../../../../../common/search_strategies/failure_correlations/types';
import { FAILURE_CORRELATION_IMPACT_THRESHOLD } from '../../../../../common/search_strategies/failure_correlations/constants';

export function getFailureCorrelationImpactLabel(
export function getFailedTransactionsCorrelationImpactLabel(
pValue: number
): FailureCorrelationImpactThreshold | null {
if (pValue > 0 && pValue < 1e-6)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { euiStyled } from '../../../../../../../src/plugins/kibana_react/common'
import { Maybe } from '../../../../typings/common';

interface Props {
items: Array<Maybe<React.ReactElement | string>>;
items: Array<Maybe<React.ReactElement>>;
}

const Item = euiStyled(EuiFlexItem)`
Expand Down
Loading

0 comments on commit 1554436

Please sign in to comment.