Skip to content

Commit

Permalink
[Fleet] Make datastream rollover lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet committed Jan 12, 2024
1 parent 7b69611 commit 09beceb
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1611,7 +1611,14 @@ describe('EPM template', () => {
},
]);

expect(esClient.indices.rollover).toHaveBeenCalled();
expect(esClient.transport.request).toHaveBeenCalledWith(
expect.objectContaining({
path: '/test.prefix1-default/_rollover',
querystring: {
lazy: true,
},
})
);
});
it('should skip rollover on expected error when flag is on', async () => {
const esClient = elasticsearchServiceMock.createElasticsearchClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -933,8 +933,12 @@ const getDataStreams = async (
const rolloverDataStream = (dataStreamName: string, esClient: ElasticsearchClient) => {
try {
// Do no wrap rollovers in retryTransientEsErrors since it is not idempotent
return esClient.indices.rollover({
alias: dataStreamName,
return esClient.transport.request({
method: 'POST',
path: `/${dataStreamName}/_rollover`,
querystring: {
lazy: true,
},
});
} catch (error) {
throw new PackageESError(
Expand Down
70 changes: 37 additions & 33 deletions x-pack/test/fleet_api_integration/apis/epm/data_stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,43 +41,46 @@ export default function (providerContext: FtrProviderContext) {
skipIfNoDockerRegistry(providerContext);
setupFleetAndAgents(providerContext);

const writeMetricsDoc = (namespace: string) =>
es.transport.request(
{
method: 'POST',
path: `/${metricsTemplateName}-${namespace}/_doc?refresh=true`,
body: {
'@timestamp': '2015-01-01',
logs_test_name: 'test',
data_stream: {
dataset: `${pkgName}.test_metrics`,
namespace,
type: 'metrics',
},
},
},
{ meta: true }
);

const writeLogsDoc = (namespace: string) =>
es.transport.request(
{
method: 'POST',
path: `/${logsTemplateName}-${namespace}/_doc?refresh=true`,
body: {
'@timestamp': '2015-01-01',
logs_test_name: 'test',
data_stream: {
dataset: `${pkgName}.test_logs`,
namespace,
type: 'logs',
},
},
},
{ meta: true }
);
beforeEach(async () => {
await installPackage(pkgName, pkgVersion);
await Promise.all(
namespaces.map(async (namespace) => {
const createLogsRequest = es.transport.request(
{
method: 'POST',
path: `/${logsTemplateName}-${namespace}/_doc`,
body: {
'@timestamp': '2015-01-01',
logs_test_name: 'test',
data_stream: {
dataset: `${pkgName}.test_logs`,
namespace,
type: 'logs',
},
},
},
{ meta: true }
);
const createMetricsRequest = es.transport.request(
{
method: 'POST',
path: `/${metricsTemplateName}-${namespace}/_doc`,
body: {
'@timestamp': '2015-01-01',
logs_test_name: 'test',
data_stream: {
dataset: `${pkgName}.test_metrics`,
namespace,
type: 'metrics',
},
},
},
{ meta: true }
);
return Promise.all([createLogsRequest, createMetricsRequest]);
return Promise.all([writeLogsDoc(namespace), writeMetricsDoc(namespace)]);
})
);
});
Expand Down Expand Up @@ -267,6 +270,7 @@ export default function (providerContext: FtrProviderContext) {
.expect(200);

// Datastream should have been rolled over
await writeLogsDoc('default');
expect(await getLogsDefaultBackingIndicesLength()).to.be(2);
});

Expand Down

0 comments on commit 09beceb

Please sign in to comment.