Properly filter out system indices in CCS env (#16536)

This commit is contained in:
Chris Roberson 2018-02-08 10:13:51 -05:00 committed by GitHub
parent bf14b4e3e0
commit 75c05459c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 50 additions and 1 deletions

View file

@ -93,4 +93,41 @@ describe('getMatchedIndices', () => {
]);
});
});
describe('systemIndices', () => {
it('should return all visible ccs indices', () => {
const query = 'cluster_one:*';
const indices = [
{ name: 'cluster_one:kibana' },
{ name: 'cluster_one:es' },
{ name: 'cluster_two:kibana' },
{ name: 'kibana' },
{ name: 'cluster_one:.kibana' },
];
const { visibleIndices } = getMatchedIndices(indices, indices, query, true);
expect(visibleIndices).toEqual([
{ name: 'cluster_one:kibana' },
{ name: 'cluster_one:es' },
{ name: 'cluster_one:.kibana' },
]);
});
it('should return all visible ccs indices except for system indices', () => {
const query = 'cluster_one:*';
const indices = [
{ name: 'cluster_one:kibana' },
{ name: 'cluster_one:es' },
{ name: 'cluster_two:kibana' },
{ name: 'kibana' },
{ name: 'cluster_one:.kibana' },
];
const { visibleIndices } = getMatchedIndices(indices, indices, query, false);
expect(visibleIndices).toEqual([
{ name: 'cluster_one:kibana' },
{ name: 'cluster_one:es' },
]);
});
});
});

View file

@ -1,6 +1,18 @@
import { MAX_NUMBER_OF_MATCHING_INDICES } from '../constants';
import { isQueryAMatch } from './is_query_a_match';
function isSystemIndex(index) {
if (index.startsWith('.')) {
return true;
}
if (index.includes(':')) {
return index.split(':').reduce((isSystem, index) => isSystem || isSystemIndex(index), false);
}
return false;
}
function filterSystemIndices(indices, isIncludingSystemIndices) {
if (!indices) {
return indices;
@ -9,7 +21,7 @@ function filterSystemIndices(indices, isIncludingSystemIndices) {
const acceptableIndices = isIncludingSystemIndices
? indices
// All system indices begin with a period.
: indices.filter(index => !index.name.startsWith('.'));
: indices.filter(index => !isSystemIndex(index.name));
return acceptableIndices.slice(0, MAX_NUMBER_OF_MATCHING_INDICES);
}