Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/10816.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fix:
- [BUG] Fix careating index-patterns with ccs causes search threadPool to be exhausted ([#10816](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/10816))
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { getIndices, responseToItemArray, dedupeMatchedItems } from './get_indices';
import { getIndices, responseToItemArray } from './get_indices';
import { httpServiceMock } from '../../../../../../core/public/mocks';
import { ResolveIndexResponseItemIndexAttrs, MatchedItem } from '../types';
import { Observable } from 'rxjs';
Expand Down Expand Up @@ -105,11 +105,10 @@ describe('getIndices', () => {
});

expect(http.get).toHaveBeenCalled();
expect(result.length).toBe(4);
expect(result.length).toBe(3);
expect(result[0].name).toBe('f-alias');
expect(result[1].name).toBe('foo');
expect(result[2].name).toBe('opensearch_dashboards_sample_data_ecommerce');
expect(result[3].name).toBe('remoteCluster1:bar-01');
expect(result[2].name).toBe('remoteCluster1:bar-01');
});

it('should ignore ccs query-all', async () => {
Expand Down Expand Up @@ -160,12 +159,6 @@ describe('getIndices', () => {
expect(responseToItemArray({}, getIndexTags)).toEqual([]);
});

it('matched items are deduped', () => {
const setA = [{ name: 'a' }, { name: 'b' }] as MatchedItem[];
const setB = [{ name: 'b' }, { name: 'c' }] as MatchedItem[];
expect(dedupeMatchedItems(setA, setB)).toHaveLength(3);
});

describe('errors', () => {
it('should handle errors gracefully', async () => {
http.get.mockImplementationOnce(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,32 +105,6 @@ export const getIndicesViaResolve = async ({
});
};

/**
* Takes two MatchedItem[]s and returns a merged set, with the second set prrioritized over the first based on name
*
* @param matchedA
* @param matchedB
*/

export const dedupeMatchedItems = (matchedA: MatchedItem[], matchedB: MatchedItem[]) => {
const mergedMatchedItems = matchedA.reduce((col, item) => {
col[item.name] = item;
return col;
}, {} as Record<string, MatchedItem>);

matchedB.reduce((col, item) => {
col[item.name] = item;
return col;
}, mergedMatchedItems);

return Object.values(mergedMatchedItems).sort((a, b) => {
if (a.name > b.name) return 1;
if (b.name > a.name) return -1;

return 0;
});
};

export async function getIndices({
http,
getIndexTags = () => [],
Expand All @@ -147,7 +121,6 @@ export async function getIndices({
dataSourceId?: string;
}): Promise<MatchedItem[]> {
const pattern = rawPattern.trim();
const isCCS = pattern.indexOf(':') !== -1;
const requests: Array<Promise<MatchedItem[]>> = [];

// Searching for `*:` fails for CCS environments. The search request
Expand Down Expand Up @@ -184,26 +157,8 @@ export async function getIndices({
});
requests.push(promiseResolve);

if (isCCS) {
// CCS supports ±1 major version. We won't be able to expect resolve endpoint to exist until v9
const promiseSearch = getIndicesViaSearch({
getIndexTags,
pattern,
searchClient,
showAllIndices,
dataSourceId,
}).catch(() => []);
requests.push(promiseSearch);
}

const responses = await Promise.all(requests);

if (responses.length === 2) {
const [resolveResponse, searchResponse] = responses;
return dedupeMatchedItems(searchResponse, resolveResponse);
} else {
return responses[0];
}
return responses[0];
}

export const responseToItemArray = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,18 +209,6 @@ export async function getIndices({
});
requests.push(promiseResolve);

if (isCCS) {
// CCS supports ±1 major version. We won't be able to expect resolve endpoint to exist until v9
const promiseSearch = getIndicesViaSearch({
getIndexTags,
pattern,
searchClient,
showAllIndices,
dataSourceId,
}).catch(() => []);
requests.push(promiseSearch);
}

const responses = await Promise.all(requests);

if (responses.length === 2) {
Expand Down
Loading