Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.11] [Profiling] Fix Diff TopN bug (#169549) #169648

Merged
merged 2 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions x-pack/plugins/observability/server/ui_settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ export const uiSettings: Record<string, UiSettings> = {
defaultMessage: `The average amortized per-core power consumption (based on 100% CPU utilization).`,
}),
schema: schema.number({ min: 0 }),
requiresPageReload: false,
requiresPageReload: true,
},
[profilingDatacenterPUE]: {
category: [observabilityFeatureId],
Expand Down Expand Up @@ -425,7 +425,7 @@ export const uiSettings: Record<string, UiSettings> = {
},
}),
schema: schema.number({ min: 0 }),
requiresPageReload: false,
requiresPageReload: true,
},
[profilingCo2PerKWH]: {
category: [observabilityFeatureId],
Expand All @@ -448,7 +448,7 @@ export const uiSettings: Record<string, UiSettings> = {
},
}),
schema: schema.number({ min: 0 }),
requiresPageReload: false,
requiresPageReload: true,
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ describe('Functions page', () => {
.clear()
.type('20');
cy.contains('Save changes').click();
cy.getByTestSubj('kbnLoadingMessage').should('exist');
cy.getByTestSubj('kbnLoadingMessage').should('not.exist', {
timeout: 50000,
});
cy.go('back');
cy.wait('@getTopNFunctions');
cy.get(firstRowSelector).eq(5).contains('24.22k lbs / 10.99k');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import {
useEuiTheme,
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import React from 'react';
import { TopNFunctionSortField } from '@kbn/profiling-utils';
import React, { useEffect } from 'react';
import { asCost } from '../../utils/formatters/as_cost';
import { asWeight } from '../../utils/formatters/as_weight';
import { StackFrameSummary } from '../stack_frame_summary';
Expand All @@ -39,38 +39,8 @@ export function FunctionRow({
onFrameClick,
setCellProps,
}: Props) {
const theme = useEuiTheme();
const successColor = useEuiBackgroundColor('success');
const dangerColor = useEuiBackgroundColor('danger');

if (columnId === TopNFunctionSortField.Diff) {
if (!functionRow.diff) {
return (
<EuiText size="xs" color={theme.euiTheme.colors.primaryText}>
{i18n.translate('xpack.profiling.functionsView.newLabel', {
defaultMessage: 'New',
})}
</EuiText>
);
}

if (functionRow.diff.rank === 0) {
return null;
}

const color = functionRow.diff.rank > 0 ? 'success' : 'danger';
setCellProps({ style: { backgroundColor: color === 'success' ? successColor : dangerColor } });

return (
<EuiFlexGroup direction="row" gutterSize="xs">
<EuiFlexItem grow={false}>
<EuiIcon type={functionRow.diff.rank > 0 ? 'sortUp' : 'sortDown'} color={color} />
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiText size="s">{Math.abs(functionRow.diff.rank)}</EuiText>
</EuiFlexItem>
</EuiFlexGroup>
);
return <DiffColumn diff={functionRow.diff} setCellProps={setCellProps} />;
}

if (columnId === TopNFunctionSortField.Rank) {
Expand All @@ -82,12 +52,12 @@ export function FunctionRow({
}

if (columnId === TopNFunctionSortField.Samples) {
setCellProps({ css: { textAlign: 'right' } });
return (
<SampleStat
<SamplesColumn
samples={functionRow.samples}
diffSamples={functionRow.diff?.samples}
totalSamples={totalCount}
setCellProps={setCellProps}
/>
);
}
Expand Down Expand Up @@ -116,3 +86,65 @@ export function FunctionRow({

return null;
}

interface SamplesColumnProps {
samples: number;
diffSamples?: number;
totalSamples: number;
setCellProps: EuiDataGridCellValueElementProps['setCellProps'];
}

function SamplesColumn({ samples, totalSamples, diffSamples, setCellProps }: SamplesColumnProps) {
useEffect(() => {
setCellProps({ css: { textAlign: 'right' } });
}, [setCellProps]);
return <SampleStat samples={samples} diffSamples={diffSamples} totalSamples={totalSamples} />;
}

interface DiffColumnProps {
diff: IFunctionRow['diff'];
setCellProps: EuiDataGridCellValueElementProps['setCellProps'];
}

function DiffColumn({ diff, setCellProps }: DiffColumnProps) {
const theme = useEuiTheme();
const successColor = useEuiBackgroundColor('success');
const dangerColor = useEuiBackgroundColor('danger');

useEffect(() => {
if (diff && diff.rank > 0) {
const color = diff.rank > 0 ? 'success' : 'danger';
setCellProps({
style: { backgroundColor: color === 'success' ? successColor : dangerColor },
});
}
}, [dangerColor, diff, setCellProps, successColor]);

if (!diff) {
return (
<EuiText size="xs" color={theme.euiTheme.colors.primaryText}>
{i18n.translate('xpack.profiling.functionsView.newLabel', {
defaultMessage: 'New',
})}
</EuiText>
);
}

if (diff.rank === 0) {
return null;
}

return (
<EuiFlexGroup direction="row" gutterSize="xs">
<EuiFlexItem grow={false}>
<EuiIcon
type={diff.rank > 0 ? 'sortUp' : 'sortDown'}
color={diff.rank > 0 ? 'success' : 'danger'}
/>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiText size="s">{Math.abs(diff.rank)}</EuiText>
</EuiFlexItem>
</EuiFlexGroup>
);
}
Loading