Skip to content

Commit

Permalink
[8.x] 🌊 Streams: Improve integration tests (#213115) (#213159)
Browse files Browse the repository at this point in the history
# Backport

This will backport the following commits from `main` to `8.x`:
- [🌊 Streams: Improve integration tests
(#213115)](#213115)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Joe
Reuter","email":"johannes.reuter@elastic.co"},"sourceCommit":{"committedDate":"2025-03-04T20:11:24Z","message":"🌊
Streams: Improve integration tests (#213115)\n\nI noticed that a couple
integration tests were not actually validating\nwhether the documents
got routed the right way (the number and string\ntests).\n\nThis PR
fixes this by introducing a helper that can easily do the same\ncheck we
had a couple of times in
there.","sha":"ef0c364f11b485c29e4c9d065a93c2a4d12fb5eb","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:version","Feature:Streams","v9.1.0","v8.19.0"],"title":"🌊
Streams: Improve integration
tests","number":213115,"url":"https://github.com/elastic/kibana/pull/213115","mergeCommit":{"message":"🌊
Streams: Improve integration tests (#213115)\n\nI noticed that a couple
integration tests were not actually validating\nwhether the documents
got routed the right way (the number and string\ntests).\n\nThis PR
fixes this by introducing a helper that can easily do the same\ncheck we
had a couple of times in
there.","sha":"ef0c364f11b485c29e4c9d065a93c2a4d12fb5eb"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/213115","number":213115,"mergeCommit":{"message":"🌊
Streams: Improve integration tests (#213115)\n\nI noticed that a couple
integration tests were not actually validating\nwhether the documents
got routed the right way (the number and string\ntests).\n\nThis PR
fixes this by introducing a helper that can easily do the same\ncheck we
had a couple of times in
there.","sha":"ef0c364f11b485c29e4c9d065a93c2a4d12fb5eb"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Joe Reuter <johannes.reuter@elastic.co>
  • Loading branch information
kibanamachine and flash1293 authored Mar 4, 2025
1 parent f921aa9 commit 03d92f8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
enableStreams,
fetchDocument,
forkStream,
indexAndAssertTargetStream,
indexDocument,
} from './helpers/requests';

Expand Down Expand Up @@ -153,10 +154,7 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
stream: 'somethingelse', // a field named stream should work as well
}),
};
const response = await indexDocument(esClient, 'logs', doc);
expect(response.result).to.eql('created');
const result = await fetchDocument(esClient, 'logs', response._id);
expect(result._index).to.match(/^\.ds\-logs-.*/);
const result = await indexAndAssertTargetStream(esClient, 'logs', doc);
expect(result._source).to.eql({
'@timestamp': '2024-01-01T00:00:00.000Z',
message: 'test',
Expand Down Expand Up @@ -191,11 +189,7 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
message: 'test',
}),
};
const response = await indexDocument(esClient, 'logs', doc);
expect(response.result).to.eql('created');

const result = await fetchDocument(esClient, 'logs.nginx', response._id);
expect(result._index).to.match(/^\.ds\-logs.nginx-.*/);
const result = await indexAndAssertTargetStream(esClient, 'logs.nginx', doc);
expect(result._source).to.eql({
'@timestamp': '2024-01-01T00:00:10.000Z',
message: 'test',
Expand Down Expand Up @@ -225,11 +219,7 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
message: 'test',
}),
};
const response = await indexDocument(esClient, 'logs', doc);
expect(response.result).to.eql('created');

const result = await fetchDocument(esClient, 'logs.nginx.access', response._id);
expect(result._index).to.match(/^\.ds\-logs.nginx.access-.*/);
const result = await indexAndAssertTargetStream(esClient, 'logs.nginx.access', doc);
expect(result._source).to.eql({
'@timestamp': '2024-01-01T00:00:20.000Z',
message: 'test',
Expand Down Expand Up @@ -259,11 +249,7 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
message: 'test',
}),
};
const response = await indexDocument(esClient, 'logs', doc);
expect(response.result).to.eql('created');

const result = await fetchDocument(esClient, 'logs.nginx', response._id);
expect(result._index).to.match(/^\.ds\-logs.nginx-.*/);
const result = await indexAndAssertTargetStream(esClient, 'logs.nginx', doc);
expect(result._source).to.eql({
'@timestamp': '2024-01-01T00:00:20.000Z',
message: 'test',
Expand Down Expand Up @@ -299,10 +285,8 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
message: 'test',
}),
};
const response1 = await indexDocument(esClient, 'logs', doc1);
expect(response1.result).to.eql('created');
const response2 = await indexDocument(esClient, 'logs', doc2);
expect(response2.result).to.eql('created');
await indexAndAssertTargetStream(esClient, 'logs.number-test', doc1);
await indexAndAssertTargetStream(esClient, 'logs.number-test', doc2);
});

it('Fork logs to logs.string-test', async () => {
Expand Down Expand Up @@ -334,11 +318,8 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
message: 'status_code: 400',
}),
};
const response1 = await indexDocument(esClient, 'logs', doc1);
expect(response1.result).to.eql('created');

const response2 = await indexDocument(esClient, 'logs', doc2);
expect(response2.result).to.eql('created');
await indexAndAssertTargetStream(esClient, 'logs.string-test', doc1);
await indexAndAssertTargetStream(esClient, 'logs.string-test', doc2);
});

it('Fork logs to logs.weird-characters', async () => {
Expand Down Expand Up @@ -369,17 +350,8 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
'weird fieldname': 'Keep where it is',
},
};
const response1 = await indexDocument(esClient, 'logs', doc1);
expect(response1.result).to.eql('created');

const result1 = await fetchDocument(esClient, 'logs.weird-characters', response1._id);
expect(result1._index).to.match(/^\.ds\-logs.weird-characters-.*/);

const response2 = await indexDocument(esClient, 'logs', doc2);
expect(response2.result).to.eql('created');

const result2 = await fetchDocument(esClient, 'logs', response2._id);
expect(result2._index).to.match(/^\.ds\-logs-.*/);
await indexAndAssertTargetStream(esClient, 'logs.weird-characters', doc1);
await indexAndAssertTargetStream(esClient, 'logs', doc2);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ export async function indexDocument(esClient: Client, index: string, document: J
return response;
}

export async function indexAndAssertTargetStream(
esClient: Client,
target: string,
document: JsonObject
) {
const response = await esClient.index({ index: 'logs', document, refresh: 'wait_for' });
const result = await fetchDocument(esClient, target, response._id);
expect(result._index).to.match(new RegExp(`^\.ds\-${target}-.*`));
return result;
}

export async function fetchDocument(esClient: Client, index: string, id: string) {
const query = {
ids: { values: [id] },
Expand Down

0 comments on commit 03d92f8

Please sign in to comment.