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

[ML] Functional Tests: Extend canvas assertion options. #91473

Merged
merged 41 commits into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
fd0f68a
[ML] Extend canvas assertion options.
walterra Feb 16, 2021
67c6237
Merge branch 'master' into ml-fix-canvas-element
walterra Feb 16, 2021
d18cd4d
[ML] Fix color stats sorting for asserting data grid mini charts.
walterra Feb 16, 2021
2f2a25d
[ML] Fix assertions.
walterra Feb 16, 2021
532f0aa
Merge branch 'master' into ml-fix-canvas-element
walterra Feb 16, 2021
a3332e5
[ML] Add retry to canvas element assertion.
walterra Feb 17, 2021
cec2731
Merge branch 'master' into ml-fix-canvas-element
walterra Feb 17, 2021
ec980a7
[ML] Reenable test suite.
walterra Feb 17, 2021
d7ea8d4
Merge branch 'master' into ml-fix-canvas-element
walterra Feb 18, 2021
f954317
[ML] Assert loading state of scatterplot matrices.
walterra Feb 18, 2021
f83656e
Merge branch 'master' into ml-fix-canvas-element
walterra Feb 22, 2021
4f16ee6
[ML] In functional tests, scroll to scatterplot before asserting it.
walterra Feb 22, 2021
117552a
Merge branch 'master' into ml-fix-canvas-element
walterra Feb 23, 2021
95438b0
[ML] Disable anti aliasing for asserting canvas elements.
walterra Feb 24, 2021
7fea2b7
Merge branch 'master' into ml-fix-canvas-element
walterra Mar 8, 2021
bc6723e
[ML] assertColorInCanvasElement().
walterra Mar 8, 2021
aa83a08
Merge branch 'master' into ml-fix-canvas-element
walterra Mar 8, 2021
8c32ed4
[ML] Expose isColorWithinTolerance() to make it available for single …
walterra Mar 8, 2021
cb8a9a3
Merge branch 'master' into ml-fix-canvas-element
walterra Mar 9, 2021
351df8f
[ML] Output full color stats if assertion of canvas element fails.
walterra Mar 9, 2021
36f3b16
Merge branch 'master' into ml-fix-canvas-element
walterra Mar 10, 2021
a763515
[ML] Tweak how props for the scatterplot matrix are composed.
walterra Mar 10, 2021
cfcf32f
[ML] Increase assertion timeouts.
walterra Mar 10, 2021
08e0d6d
Merge branch 'master' into ml-fix-canvas-element
walterra Mar 10, 2021
b8a1694
Merge branch 'master' into ml-fix-canvas-element
walterra Mar 11, 2021
636d8ca
[ML] Color assertion tweaks.
walterra Mar 11, 2021
de2d687
[ML] Fix asserting colors in canvas elements.
walterra Mar 11, 2021
718f95d
Merge branch 'master' into ml-fix-canvas-element
walterra Mar 15, 2021
1d9e36f
[ML] Tweak assertion colors.
walterra Mar 15, 2021
3b6ce45
[ML] Tweak assertion value.
walterra Mar 15, 2021
98b8d82
[ML] Tweak assertion value.
walterra Mar 15, 2021
e19308c
[ML] Tweak assertion value.
walterra Mar 15, 2021
5eab756
Merge branch 'master' into ml-fix-canvas-element
walterra Mar 16, 2021
2730771
Merge branch 'master' into ml-fix-canvas-element
kibanamachine Mar 17, 2021
b6559ae
Merge branch 'master' into ml-fix-canvas-element
walterra Mar 17, 2021
8d6bee6
Merge branch 'ml-fix-canvas-element' of github.com:walterra/kibana in…
walterra Mar 17, 2021
65170ec
[ML] Update callout assertion.
walterra Mar 17, 2021
b70f3f9
[ML] Value tweaks to pass tests on Windows.
walterra Mar 17, 2021
d568b2b
Merge branch 'master' into ml-fix-canvas-element
walterra Mar 18, 2021
e24fbf1
[ML] Tweak assertion value tolerance.
walterra Mar 18, 2021
5c7ef8d
[ML] Unskip test.
walterra Mar 18, 2021
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
11 changes: 10 additions & 1 deletion x-pack/plugins/ml/public/application/_hacks.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.tab-datavisualizer_index_select,
.tab-timeseriesexplorer,
.tab-explorer, {
.tab-explorer {
// Make all page background white until More of the pages use EuiPage to wrap in panel-like components
background-color: $euiColorEmptyShade;
}
Expand All @@ -22,3 +22,12 @@
.clear, .clearfix {
clear: both;
}

// Helper class for functional tests to disable anti-aliasing for canvas elements
.mlDisableAntiAliasing {
-webkit-font-smoothing : none;

* canvas {
image-rendering: pixelated;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export const ScatterplotMatrix: FC<ScatterplotMatrixProps> = ({
{splom === undefined || vegaSpec === undefined ? (
<VegaChartLoading />
) : (
<div data-test-subj="mlScatterplotMatrix">
<div data-test-subj={`mlScatterplotMatrix ${isLoading ? 'loading' : 'loaded'}`}>
<EuiFlexGroup>
<EuiFlexItem>
<EuiFormRow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,6 @@ export const ConfigurationStepForm: FC<CreateAnalyticsStepProps> = ({
language: SEARCH_QUERY_LANGUAGE.KUERY,
});

const scatterplotFieldOptions = useMemo(
() =>
includesTableItems
.filter((d) => d.feature_type === 'numerical' && d.is_included)
.map((d) => d.name),
[includesTableItems]
);

const toastNotifications = getToastNotifications();

const setJobConfigQuery: ExplorationQueryBarProps['setSearchQuery'] = (update) => {
Expand Down Expand Up @@ -341,16 +333,37 @@ export const ConfigurationStepForm: FC<CreateAnalyticsStepProps> = ({
[currentIndexPattern.fields]
);

const scatterplotMatrixProps = useMemo(
() => ({
color: isJobTypeWithDepVar ? dependentVariable : undefined,
fields: includesTableItems
.filter((d) => d.feature_type === 'numerical' && d.is_included)
.map((d) => d.name),
index: currentIndexPattern.title,
legendType: getScatterplotMatrixLegendType(jobType),
searchQuery: jobConfigQuery,
}),
[
currentIndexPattern.title,
dependentVariable,
includesTableItems,
isJobTypeWithDepVar,
jobConfigQuery,
jobType,
]
);

// Show the Scatterplot Matrix only if
// - There's more than one suitable field available
// - The job type is outlier detection, or
// - The job type is regression or classification and the dependent variable has been set
const showScatterplotMatrix =
(jobType === ANALYSIS_CONFIG_TYPE.OUTLIER_DETECTION ||
((jobType === ANALYSIS_CONFIG_TYPE.REGRESSION ||
jobType === ANALYSIS_CONFIG_TYPE.CLASSIFICATION) &&
!dependentVariableEmpty)) &&
scatterplotFieldOptions.length > 1;
const showScatterplotMatrix = useMemo(
() =>
(jobType === ANALYSIS_CONFIG_TYPE.OUTLIER_DETECTION ||
(isJobTypeWithDepVar && !dependentVariableEmpty)) &&
scatterplotMatrixProps.fields.length > 1,
[dependentVariableEmpty, jobType, scatterplotMatrixProps.fields.length]
);

// Don't render until `savedSearchQuery` has been initialized.
// `undefined` means uninitialized, `null` means initialized but not used.
Expand Down Expand Up @@ -550,18 +563,7 @@ export const ConfigurationStepForm: FC<CreateAnalyticsStepProps> = ({
paddingSize="m"
data-test-subj="mlAnalyticsCreateJobWizardScatterplotMatrixPanel"
>
<ScatterplotMatrix
fields={scatterplotFieldOptions}
index={currentIndexPattern.title}
color={
jobType === ANALYSIS_CONFIG_TYPE.REGRESSION ||
jobType === ANALYSIS_CONFIG_TYPE.CLASSIFICATION
? dependentVariable
: undefined
}
legendType={getScatterplotMatrixLegendType(jobType)}
searchQuery={jobConfigQuery}
/>
<ScatterplotMatrix {...scatterplotMatrixProps} />
</EuiPanel>
<EuiSpacer />
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const getRocCurveChartVegaLiteSpec = (

return {
$schema: 'https://vega.github.io/schema/vega-lite/v4.8.1.json',
background: 'transparent',
// Left padding of 45px to align the left axis of the chart with the confusion matrix above.
padding: { left: 45, top: 0, right: 0, bottom: 0 },
config: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ export default function ({ getService }: FtrProviderContext) {
const ml = getService('ml');
const editedDescription = 'Edited description';

// Failing: See https://github.com/elastic/kibana/issues/91450
describe.skip('classification creation', function () {
describe('classification creation', function () {
before(async () => {
await esArchiver.loadIfNeeded('ml/bm_classification');
await ml.testResources.createIndexPatternIfNeeded('ft_bank_marketing', '@timestamp');
Expand Down Expand Up @@ -43,24 +42,21 @@ export default function ({ getService }: FtrProviderContext) {
createIndexPattern: true,
expected: {
rocCurveColorState: [
// background
{ key: '#FFFFFF', value: 93 },
// tick/grid/axis
{ key: '#98A2B3', value: 1 },
{ key: '#DDDDDD', value: 3 },
// line
{ key: '#6092C0', value: 1 },
{ key: '#DDDDDD', value: 48 },
Copy link
Contributor

@peteharverson peteharverson Mar 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running locally on Windows, I had to edit these values to the following to get it to pass:

            // tick/grid/axis
            { key: '#DDDDDD', value: 50 },
            // lines
            { key: '#98A2B3', value: 30 },
            { key: '#6092C0', value: 10 },
            { key: '#5F92C0', value: 6 },

Before that, this single test was failing with the error

      retry.tryForTime timeout: Error: Color stats for 'mlDFAnalyticsClassificationExplorationRocCurveChart' should be w
ithin tolerance. Expected: '[{"key":"#DDDDDD","value":48},{"key":"#98A2B3","value":32},{"key":"#6092C0","value":10},{"ke
y":"#5F92C0","value":6}]' (got '[{"key":"#DDDDDD","value":54.5920820644334,"withinTolerance":false},{"key":"#98A2B3","va
lue":26.106747876262215,"withinTolerance":false},{"key":"#6092C0","value":9.145696425709247,"withinTolerance":true},{"ke
y":"#5F92C0","value":9.145696425709247,"withinTolerance":true}]')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, updated in b70f3f9, let's see if it's within the tolerance to still pass CI :)

// lines
{ key: '#98A2B3', value: 32 },
{ key: '#6092C0', value: 10 },
{ key: '#5F92C0', value: 6 },
],
scatterplotMatrixColorStats: [
// background
{ key: '#000000', value: 94 },
// marker colors
{ key: '#7FC6B3', value: 1 },
{ key: '#88ADD0', value: 0.03 },
// tick/grid/axis
{ key: '#DDDDDD', value: 1 },
{ key: '#D3DAE6', value: 1 },
{ key: '#F5F7FA', value: 1 },
// scatterplot circles
{ key: '#6A717D', value: 1 },
{ key: '#54B39A', value: 1 },
{ key: '#DDDDDD', value: 8 },
{ key: '#D3DAE6', value: 8 },
{ key: '#F5F7FA', value: 20 },
],
row: {
type: 'classification',
Expand Down Expand Up @@ -112,8 +108,7 @@ export default function ({ getService }: FtrProviderContext) {
await ml.dataFrameAnalyticsCreation.assertIncludeFieldsSelectionExists();

await ml.testExecution.logTestStep('displays the scatterplot matrix');
await ml.dataFrameAnalyticsCanvasElement.assertCanvasElement(
'mlAnalyticsCreateJobWizardScatterplotMatrixFormRow',
await ml.dataFrameAnalyticsCreation.assertScatterplotMatrix(
testData.expected.scatterplotMatrixColorStats
);

Expand Down Expand Up @@ -157,7 +152,12 @@ export default function ({ getService }: FtrProviderContext) {

await ml.testExecution.logTestStep('checks validation callouts exist');
await ml.dataFrameAnalyticsCreation.assertValidationCalloutsExists();
await ml.dataFrameAnalyticsCreation.assertAllValidationCalloutsPresent(3);
// Expect the follow callouts:
// - ✓ Dependent variable
// - ✓ Training percent
// - ✓ Top classes
// - ⚠ Analysis fields
await ml.dataFrameAnalyticsCreation.assertAllValidationCalloutsPresent(4);

await ml.testExecution.logTestStep('continues to the create step');
await ml.dataFrameAnalyticsCreation.continueToCreateStep();
Expand Down Expand Up @@ -238,16 +238,16 @@ export default function ({ getService }: FtrProviderContext) {
await ml.testExecution.logTestStep('displays the results view for created job');
await ml.dataFrameAnalyticsTable.openResultsView(testData.jobId);
await ml.dataFrameAnalyticsResults.assertClassificationEvaluatePanelElementsExists();
await ml.dataFrameAnalyticsCanvasElement.assertCanvasElement(
await ml.commonUI.assertColorsInCanvasElement(
'mlDFAnalyticsClassificationExplorationRocCurveChart',
testData.expected.rocCurveColorState
testData.expected.rocCurveColorState,
['#000000']
);
await ml.dataFrameAnalyticsResults.assertClassificationTablePanelExists();
await ml.dataFrameAnalyticsResults.assertResultsTableExists();
await ml.dataFrameAnalyticsResults.assertResultsTableTrainingFiltersExist();
await ml.dataFrameAnalyticsResults.assertResultsTableNotEmpty();
await ml.dataFrameAnalyticsCanvasElement.assertCanvasElement(
'mlDFExpandableSection-splom',
await ml.dataFrameAnalyticsResults.assertScatterplotMatrix(
testData.expected.scatterplotMatrixColorStats
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,19 @@ export default function ({ getService }: FtrProviderContext) {
{ chartAvailable: true, id: 'Exterior2nd', legend: '3 categories' },
{ chartAvailable: true, id: 'Fireplaces', legend: '0 - 3' },
],
scatterplotMatrixColorStatsWizard: [
// background
{ key: '#000000', value: 91 },
// tick/grid/axis
{ key: '#6A717D', value: 2 },
{ key: '#F5F7FA', value: 2 },
{ key: '#D3DAE6', value: 1 },
// scatterplot circles
{ key: '#54B399', value: 1 },
{ key: '#54B39A', value: 1 },
scatterplotMatrixColorsWizard: [
{ key: '#6A717D', value: 30 },
{ key: '#52B398', value: 25 },
],
scatterplotMatrixColorStatsResults: [
// background
{ key: '#000000', value: 91 },
// red markers
{ key: '#D98071', value: 1 },
// tick/grid/axis, grey markers
// the red outlier color is not above the 1% threshold.
{ key: '#6A717D', value: 2 },
{ key: '#98A2B3', value: 1 },
{ key: '#F5F7FA', value: 2 },
{ key: '#D3DAE6', value: 1 },
{ key: '#6A717D', value: 30 },
{ key: '#D3DAE6', value: 8 },
{ key: '#98A1B3', value: 25 },
// anti-aliasing
{ key: '#F5F7FA', value: 27 },
],
row: {
type: 'outlier_detection',
Expand All @@ -93,6 +86,10 @@ export default function ({ getService }: FtrProviderContext) {
await ml.navigation.navigateToDataFrameAnalytics();

await ml.testExecution.logTestStep('loads the source selection modal');

// Disable anti-aliasing to stabilize canvas image rendering assertions
await ml.commonUI.disableAntiAliasing();

await ml.dataFrameAnalytics.startAnalyticsCreation();

await ml.testExecution.logTestStep(
Expand Down Expand Up @@ -128,9 +125,8 @@ export default function ({ getService }: FtrProviderContext) {
await ml.dataFrameAnalyticsCreation.assertIncludeFieldsSelectionExists();

await ml.testExecution.logTestStep('displays the scatterplot matrix');
await ml.dataFrameAnalyticsCanvasElement.assertCanvasElement(
'mlAnalyticsCreateJobWizardScatterplotMatrixFormRow',
testData.expected.scatterplotMatrixColorStatsWizard
await ml.dataFrameAnalyticsCreation.assertScatterplotMatrix(
testData.expected.scatterplotMatrixColorsWizard
);

await ml.testExecution.logTestStep('continues to the additional options step');
Expand Down Expand Up @@ -257,8 +253,7 @@ export default function ({ getService }: FtrProviderContext) {
await ml.dataFrameAnalyticsResults.assertResultsTableExists();
await ml.dataFrameAnalyticsResults.assertResultsTableNotEmpty();
await ml.dataFrameAnalyticsResults.assertFeatureInfluenceCellNotEmpty();
await ml.dataFrameAnalyticsCanvasElement.assertCanvasElement(
'mlDFExpandableSection-splom',
await ml.dataFrameAnalyticsResults.assertScatterplotMatrix(
testData.expected.scatterplotMatrixColorStatsResults
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,13 @@ export default function ({ getService }: FtrProviderContext) {
createIndexPattern: true,
expected: {
scatterplotMatrixColorStats: [
// background
{ key: '#000000', value: 80 },
// some marker colors of the continuous color scale
{ key: '#61AFA3', value: 2 },
{ key: '#D1E5E0', value: 2 },
// tick/grid/axis
{ key: '#6A717D', value: 1 },
{ key: '#F5F7FA', value: 2 },
{ key: '#D3DAE6', value: 1 },
// because a continuous color scale is used for the scatterplot circles,
// none of the generated colors is above the 1% threshold.
{ key: '#6A717D', value: 10 },
{ key: '#F5F7FA', value: 12 },
{ key: '#D3DAE6', value: 3 },
],
row: {
type: 'regression',
Expand Down Expand Up @@ -101,8 +100,7 @@ export default function ({ getService }: FtrProviderContext) {
await ml.dataFrameAnalyticsCreation.assertIncludeFieldsSelectionExists();

await ml.testExecution.logTestStep('displays the scatterplot matrix');
await ml.dataFrameAnalyticsCanvasElement.assertCanvasElement(
'mlAnalyticsCreateJobWizardScatterplotMatrixFormRow',
await ml.dataFrameAnalyticsCreation.assertScatterplotMatrix(
testData.expected.scatterplotMatrixColorStats
);

Expand Down Expand Up @@ -231,8 +229,7 @@ export default function ({ getService }: FtrProviderContext) {
await ml.dataFrameAnalyticsResults.assertResultsTableExists();
await ml.dataFrameAnalyticsResults.assertResultsTableTrainingFiltersExist();
await ml.dataFrameAnalyticsResults.assertResultsTableNotEmpty();
await ml.dataFrameAnalyticsCanvasElement.assertCanvasElement(
'mlDFExpandableSection-splom',
await ml.dataFrameAnalyticsResults.assertScatterplotMatrix(
testData.expected.scatterplotMatrixColorStats
);
});
Expand Down
Loading