Skip to content

Commit

Permalink
[ML] Improve column type safety.
Browse files Browse the repository at this point in the history
  • Loading branch information
walterra committed Sep 7, 2021
1 parent 6af23f3 commit 787d9d7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import {
import { asPercent } from '../../../../common/utils/formatters';
import { FailedTransactionsCorrelation } from '../../../../common/search_strategies/failed_transactions_correlations/types';
import { APM_SEARCH_STRATEGIES } from '../../../../common/search_strategies/constants';
import { FieldValuePair } from '../../../../common/search_strategies/types';

import { useApmPluginContext } from '../../../context/apm_plugin/use_apm_plugin_context';
import { FETCH_STATUS } from '../../../hooks/use_fetcher';
Expand Down Expand Up @@ -120,7 +119,7 @@ export function FailedTransactionsCorrelations({
</>
</EuiToolTip>
),
render: (failurePercentage: number) =>
render: (_, { failurePercentage }) =>
asPercent(failurePercentage, 1),
sortable: true,
},
Expand Down Expand Up @@ -154,7 +153,7 @@ export function FailedTransactionsCorrelations({
</EuiToolTip>
),

render: (successPercentage: number) =>
render: (_, { successPercentage }) =>
asPercent(successPercentage, 1),
sortable: true,
},
Expand All @@ -174,7 +173,7 @@ export function FailedTransactionsCorrelations({
)}
</>
),
render: (normalizedScore: number) => {
render: (_, { normalizedScore }) => {
return (
<>
<ImpactBar size="m" value={normalizedScore * 100} />
Expand All @@ -196,7 +195,7 @@ export function FailedTransactionsCorrelations({
)}
</>
),
render: (pValue: number) => {
render: (_, { pValue }) => {
const label = getFailedTransactionsCorrelationImpactLabel(pValue);
return label ? (
<EuiBadge color={label.color}>{label.impact}</EuiBadge>
Expand All @@ -218,8 +217,7 @@ export function FailedTransactionsCorrelations({
'xpack.apm.correlations.failedTransactions.correlationsTable.fieldValueLabel',
{ defaultMessage: 'Field value' }
),
render: (fieldValue: FieldValuePair['fieldValue']) =>
String(fieldValue).slice(0, 50),
render: (_, { fieldValue }) => String(fieldValue).slice(0, 50),
sortable: true,
},
...percentageColumns,
Expand Down Expand Up @@ -273,13 +271,13 @@ export function FailedTransactionsCorrelations({
'xpack.apm.correlations.correlationsTable.actionsLabel',
{ defaultMessage: 'Filter' }
),
render: (_: unknown, term: FailedTransactionsCorrelation) => {
render: (_, { fieldName, fieldValue }) => {
return (
<>
<EuiLink
href={createHref(history, {
query: {
kuery: `${term.fieldName}:"${term.fieldValue}"`,
kuery: `${fieldName}:"${fieldValue}"`,
},
})}
>
Expand All @@ -289,7 +287,7 @@ export function FailedTransactionsCorrelations({
<EuiLink
href={createHref(history, {
query: {
kuery: `not ${term.fieldName}:"${term.fieldValue}"`,
kuery: `not ${fieldName}:"${fieldValue}"`,
},
})}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import {
APM_SEARCH_STRATEGIES,
DEFAULT_PERCENTILE_THRESHOLD,
} from '../../../../common/search_strategies/constants';
import { FieldValuePair } from '../../../../common/search_strategies/types';
import { LatencyCorrelation } from '../../../../common/search_strategies/latency_correlations/types';

import { useApmPluginContext } from '../../../context/apm_plugin/use_apm_plugin_context';
Expand Down Expand Up @@ -137,7 +136,7 @@ export function LatencyCorrelations({ onFilter }: { onFilter: () => void }) {
</>
</EuiToolTip>
),
render: (correlation: number) => {
render: (_, { correlation }) => {
return <div>{asPreciseDecimal(correlation, 2)}</div>;
},
sortable: true,
Expand All @@ -156,8 +155,7 @@ export function LatencyCorrelations({ onFilter }: { onFilter: () => void }) {
'xpack.apm.correlations.latencyCorrelations.correlationsTable.fieldValueLabel',
{ defaultMessage: 'Field value' }
),
render: (fieldValue: FieldValuePair['fieldValue']) =>
String(fieldValue).slice(0, 50),
render: (_, { fieldValue }) => String(fieldValue).slice(0, 50),
sortable: true,
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,22 @@
* 2.0.
*/

import { FailedTransactionsCorrelationsImpactThreshold } from '../../../../../common/search_strategies/failed_transactions_correlations/types';
import {
FailedTransactionsCorrelation,
FailedTransactionsCorrelationsImpactThreshold,
} from '../../../../../common/search_strategies/failed_transactions_correlations/types';
import { FAILED_TRANSACTIONS_IMPACT_THRESHOLD } from '../../../../../common/search_strategies/failed_transactions_correlations/constants';

export function getFailedTransactionsCorrelationImpactLabel(
pValue: number
pValue: FailedTransactionsCorrelation['pValue']
): {
impact: FailedTransactionsCorrelationsImpactThreshold;
color: string;
} | null {
if (pValue === null) {
return null;
}

// The lower the p value, the higher the impact
if (pValue >= 0 && pValue < 1e-6)
return {
Expand Down

0 comments on commit 787d9d7

Please sign in to comment.