[Dataset Quality] Fix brittle test which was failing in the midnight job (#216260)

This PR fixes a bug where the test would run at midnight and due to the
odd timing, the index which gets created is asserted for a different
date than expected.

With this fix, we don't check the complete index name now by replacing
the date assertion part with startWith and endsWith assertions.
This commit is contained in:
Achyut Jhunjhunwala 2025-03-28 16:13:05 +01:00 committed by GitHub
parent 69bd83e69e
commit 0f0ee3a0b8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 8 additions and 73 deletions

View file

@ -11,7 +11,7 @@ import expect from '@kbn/expect';
import { DegradedField } from '@kbn/dataset-quality-plugin/common/api_types';
import { DeploymentAgnosticFtrProviderContext } from '../../../ftr_provider_context';
import { SupertestWithRoleScopeType } from '../../../services';
import { rolloverDataStream, createBackingIndexNameWithoutVersion } from './utils';
import { rolloverDataStream } from './utils';
const MORE_THAN_1024_CHARS =
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?';
@ -178,20 +178,15 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
(dFields: DegradedField) => dFields.name === 'trace.id'
)?.indexFieldWasLastPresentIn;
expect(logLevelLastBackingIndex).to.be(
`${createBackingIndexNameWithoutVersion({
type,
dataset: degradedFieldDataset,
namespace,
})}-000002`
const logLevelRegex = new RegExp(
`^\\.ds-${type}-${degradedFieldDataset}-${namespace}.*-000002$`
);
expect(traceIdLastBackingIndex).to.be(
`${createBackingIndexNameWithoutVersion({
type,
dataset: degradedFieldDataset,
namespace,
})}-000001`
expect(logLevelLastBackingIndex?.match(logLevelRegex)).to.not.be(null);
const traceIdRegex = new RegExp(
`^\\.ds-${type}-${degradedFieldDataset}-${namespace}.*-000001$`
);
expect(traceIdLastBackingIndex?.match(traceIdRegex)).to.not.be(null);
});
});
});

View file

@ -1,59 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { Client } from '@elastic/elasticsearch';
import { IndicesIndexSettings } from '@elastic/elasticsearch/lib/api/types';
export async function rolloverDataStream(es: Client, name: string) {
return es.indices.rollover({ alias: name });
}
export async function getDataStreamSettingsOfEarliestIndex(es: Client, name: string) {
const matchingIndexesObj = await es.indices.getSettings({ index: name });
const matchingIndexes = Object.keys(matchingIndexesObj ?? {});
matchingIndexes.sort((a, b) => {
return (
Number(matchingIndexesObj[a].settings?.index?.creation_date) -
Number(matchingIndexesObj[b].settings?.index?.creation_date)
);
});
return matchingIndexesObj[matchingIndexes[0]].settings;
}
function getCurrentDateFormatted() {
const date = new Date();
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
return `${year}.${month}.${day}`;
}
export function createBackingIndexNameWithoutVersion({
type,
dataset,
namespace = 'default',
}: {
type: string;
dataset: string;
namespace: string;
}) {
return `.ds-${type}-${dataset}-${namespace}-${getCurrentDateFormatted()}`;
}
export async function setDataStreamSettings(
esClient: Client,
name: string,
settings: IndicesIndexSettings
) {
return esClient.indices.putSettings({
index: name,
settings,
});
}

View file

@ -6,4 +6,3 @@
*/
export { expectToReject } from './expect_to_reject';
export * from './data_stream';