Skip to content

Commit

Permalink
[Dataset Quality] Fix loading on dataset quality summary (#201757)
Browse files Browse the repository at this point in the history
## 📓 Summary

Closes #186549 

Refreshing the page didn't give enough time for the data ingestion to
process correctly, hopefully navigating to the page, which is gated by
an assertion on loading indicators, should check that data is loaded
correctly.

Also, running the test in isolation raised a bug in the code, where the
loading of the summary details was not synced with the loaded data from
the table. This resulted in the summary always being 0 at first load,
and then immediately update once the table is ready, which broke the
test. Syncing their loading indicators fixed the issue and tests passes
in isolation too.

---------

Co-authored-by: Marco Antonio Ghiani <marcoantonio.ghiani@elastic.co>
  • Loading branch information
tonyghiani and Marco Antonio Ghiani authored Nov 27, 2024
1 parent 0735ab8 commit 8814e43
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ import { filterInactiveDatasets } from '../utils';

const useSummaryPanel = () => {
const { service } = useDatasetQualityContext();
const { filteredItems, canUserMonitorDataset, canUserMonitorAnyDataStream, loading } =
useDatasetQualityTable();
const {
filteredItems,
canUserMonitorDataset,
canUserMonitorAnyDataStream,
loading: isTableLoading,
} = useDatasetQualityTable();

const { timeRange } = useSelector(service, (state) => state.context.filters);

Expand All @@ -27,9 +31,10 @@ const useSummaryPanel = () => {
percentages: filteredItems.map((item) => item.degradedDocs.percentage),
};

const isDatasetsQualityLoading = useSelector(service, (state) =>
const isDegradedDocsLoading = useSelector(service, (state) =>
state.matches('stats.degradedDocs.fetching')
);
const isDatasetsQualityLoading = isDegradedDocsLoading || isTableLoading;

/*
User Authorization
Expand All @@ -38,7 +43,7 @@ const useSummaryPanel = () => {
(item) => item.userPrivileges?.canMonitor ?? true
);

const isUserAuthorizedForDataset = !loading
const isUserAuthorizedForDataset = !isTableLoading
? canUserMonitorDataset && canUserMonitorAnyDataStream && canUserMonitorAllFilteredDataStreams
: true;

Expand Down
30 changes: 28 additions & 2 deletions x-pack/test/functional/apps/dataset_quality/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,33 @@ import { FtrConfigProviderContext, GenericFtrProviderContext } from '@kbn/test';
import { createLogger, LogLevel, LogsSynthtraceEsClient } from '@kbn/apm-synthtrace';
import { FtrProviderContext } from '../../ftr_provider_context';

export default async function createTestConfig({ readConfigFile }: FtrConfigProviderContext) {
import { FtrProviderContext as InheritedFtrProviderContext } from '../../ftr_provider_context';

export type InheritedServices = InheritedFtrProviderContext extends GenericFtrProviderContext<
infer TServices,
{}
>
? TServices
: {};

export type InheritedPageObjects = InheritedFtrProviderContext extends GenericFtrProviderContext<
infer TServices,
infer TPageObjects
>
? TPageObjects
: {};

interface DatasetQualityConfig {
services: InheritedServices & {
logSynthtraceEsClient: (
context: InheritedFtrProviderContext
) => Promise<LogsSynthtraceEsClient>;
};
}

export default async function createTestConfig({
readConfigFile,
}: FtrConfigProviderContext): Promise<DatasetQualityConfig> {
const functionalConfig = await readConfigFile(require.resolve('../../config.base.js'));
const services = functionalConfig.get('services');
const pageObjects = functionalConfig.get('pageObjects');
Expand All @@ -34,7 +60,7 @@ export default async function createTestConfig({ readConfigFile }: FtrConfigProv
export type CreateTestConfig = Awaited<ReturnType<typeof createTestConfig>>;

export type DatasetQualityServices = CreateTestConfig['services'];
export type DatasetQualityPageObject = CreateTestConfig['pageObjects'];
export type DatasetQualityPageObject = InheritedPageObjects;

export type DatasetQualityFtrProviderContext = GenericFtrProviderContext<
DatasetQualityServices,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ export default function ({ getService, getPageObjects }: DatasetQualityFtrProvid
);
});

countColumn.sort('ascending');
await countColumn.sort('ascending');

await retry.tryForTime(5000, async () => {
const currentUrl = await browser.getCurrentUrl();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function ({ getService, getPageObjects }: DatasetQualityFtrProvid
const synthtrace = getService('logSynthtraceEsClient');
const to = '2024-01-01T12:00:00.000Z';

const ingestDataForSummary = async () => {
const ingestDataForSummary = () => {
// Ingest documents for 3 type of datasets
return synthtrace.index([
// Ingest good data to all 3 datasets
Expand Down Expand Up @@ -48,16 +48,14 @@ export default function ({ getService, getPageObjects }: DatasetQualityFtrProvid
};

describe('Dataset quality summary', () => {
before(async () => {
await synthtrace.index(getInitialTestLogs({ to, count: 4 }));
await PageObjects.datasetQuality.navigateTo();
});

afterEach(async () => {
await synthtrace.clean();
});

it('shows poor, degraded and good count as 0 and all dataset as healthy', async () => {
await synthtrace.index(getInitialTestLogs({ to, count: 4 }));
await PageObjects.datasetQuality.navigateTo();

const summary = await PageObjects.datasetQuality.parseSummaryPanel();
expect(summary).to.eql({
datasetHealthPoor: '0',
Expand All @@ -70,7 +68,7 @@ export default function ({ getService, getPageObjects }: DatasetQualityFtrProvid

it('shows updated count for poor, degraded and good datasets, estimated size and updates active datasets', async () => {
await ingestDataForSummary();
await PageObjects.datasetQuality.refreshTable();
await PageObjects.datasetQuality.navigateTo();

const summary = await PageObjects.datasetQuality.parseSummaryPanel();
const { estimatedData, ...restOfSummary } = summary;
Expand Down

0 comments on commit 8814e43

Please sign in to comment.