Skip to content

Commit

Permalink
[SLO] Alternative split to remote indices (#152463)
Browse files Browse the repository at this point in the history
## Summary

This updates the utility to process a string of one or more indices. It
assumed when one part of the string passed contained `remote:`, all
remaining indices would also have to contain `remote`, but this isn't
necessary.
  • Loading branch information
CoenWarmer authored Mar 1, 2023
1 parent 5e397c4 commit 06c70d9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ describe('common', () => {
['foo-*', 'foo-*'],
['foo-*,bar-*', ['foo-*', 'bar-*']],
['remote:foo-*', 'remote:foo-*'],
['remote:foo*,bar-*', ['remote:foo*', 'remote:bar-*']],
['remote:foo*,bar-*', ['remote:foo*', 'bar-*']],
['remote:foo*,remote:bar-*', ['remote:foo*', 'remote:bar-*']],
['remote:foo*,bar-*,remote:baz-*', ['remote:foo*', 'bar-*', 'remote:baz-*']],
])("parses the index '%s' correctly", (index, expected) => {
expect(parseIndex(index)).toEqual(expected);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,9 @@ export function getElastichsearchQueryOrThrow(kuery: string) {
}

export function parseIndex(index: string): string | string[] {
if (index.indexOf(',') > -1) {
if (index.indexOf(':') > -1) {
const indexParts = index.split(':'); // "remote_name:foo-*,bar*"
const remoteName = indexParts[0];
return indexParts[1].split(',').map((idx) => `${remoteName}:${idx}`); // [ "remote_name:foo-*", "remote_name:bar-*"]
}

return index.split(',');
if (index.indexOf(',') === -1) {
return index;
}

return index;
return index.split(',');
}

0 comments on commit 06c70d9

Please sign in to comment.