-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Enterprise Search] [Search application] List indices fetch indices s…
…tats from ES directly (#153696) ## Summary This PR adds a lib file to fetch indices stats of an search application from Elasticsearch directly ### Screenshot #### List page indices <img width="1728" alt="List page indices" src="https://user-images.githubusercontent.com/55930906/227617672-bfcdd3e4-85c2-4432-bcee-2aa3f5be07a4.png"> #### Overview page indices <img width="1728" alt="Overview page indices " src="https://user-images.githubusercontent.com/55930906/227617828-afa01bf6-5f23-4f3f-9ff6-75f6c5dbcff2.png"> ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios --------- Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
b002cdc
commit 327dd49
Showing
6 changed files
with
180 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
x-pack/plugins/enterprise_search/server/lib/engines/fetch_indices_stats.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import { IScopedClusterClient } from '@kbn/core/server'; | ||
|
||
import { fetchIndicesStats } from './fetch_indices_stats'; | ||
|
||
describe('fetchIndicesStats lib function', () => { | ||
const mockClient = { | ||
asCurrentUser: { | ||
indices: { | ||
stats: jest.fn(), | ||
}, | ||
}, | ||
asInternalUser: {}, | ||
}; | ||
const indices = ['test-index-name-1', 'test-index-name-2', 'test-index-name-3']; | ||
const indicesStats = { | ||
indices: { | ||
'test-index-name-1': { | ||
health: 'GREEN', | ||
primaries: { docs: [{}] }, | ||
status: 'open', | ||
total: { | ||
docs: { | ||
count: 200, | ||
deleted: 0, | ||
}, | ||
}, | ||
uuid: 'YOLLiZ_mSRiDYDk0DJ-p8B', | ||
}, | ||
'test-index-name-2': { | ||
health: 'YELLOW', | ||
primaries: { docs: [{}] }, | ||
status: 'closed', | ||
total: { | ||
docs: { | ||
count: 0, | ||
deleted: 0, | ||
}, | ||
}, | ||
uuid: 'QOLLiZ_mGRiDYD30D2-p8B', | ||
}, | ||
'test-index-name-3': { | ||
health: 'RED', | ||
primaries: { docs: [{}] }, | ||
status: 'open', | ||
total: { | ||
docs: { | ||
count: 150, | ||
deleted: 0, | ||
}, | ||
}, | ||
uuid: 'QYLLiZ_fGRiDYD3082-e7', | ||
}, | ||
}, | ||
}; | ||
const fetchIndicesStatsResponse = [ | ||
{ | ||
count: 200, | ||
health: 'GREEN', | ||
name: 'test-index-name-1', | ||
}, | ||
{ | ||
count: 0, | ||
health: 'YELLOW', | ||
name: 'test-index-name-2', | ||
}, | ||
{ | ||
count: 150, | ||
health: 'RED', | ||
name: 'test-index-name-3', | ||
}, | ||
]; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should return hydrated indices', async () => { | ||
mockClient.asCurrentUser.indices.stats.mockImplementationOnce(() => indicesStats); | ||
|
||
await expect( | ||
fetchIndicesStats(mockClient as unknown as IScopedClusterClient, indices) | ||
).resolves.toEqual(fetchIndicesStatsResponse); | ||
|
||
expect(mockClient.asCurrentUser.indices.stats).toHaveBeenCalledWith({ | ||
index: indices, | ||
metric: ['docs'], | ||
}); | ||
}); | ||
}); |
29 changes: 29 additions & 0 deletions
29
x-pack/plugins/enterprise_search/server/lib/engines/fetch_indices_stats.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { IScopedClusterClient } from '@kbn/core-elasticsearch-server/src/client/scoped_cluster_client'; | ||
|
||
import { EnterpriseSearchEngineIndex } from '../../../common/types/engines'; | ||
|
||
export const fetchIndicesStats = async (client: IScopedClusterClient, indices: string[]) => { | ||
const { indices: indicesStats = {} } = await client.asCurrentUser.indices.stats({ | ||
index: indices, | ||
metric: ['docs'], | ||
}); | ||
|
||
const indicesWithStats = indices.map((indexName: string) => { | ||
const indexStats = indicesStats[indexName]; | ||
const hydratedIndex: EnterpriseSearchEngineIndex = { | ||
count: indexStats?.total?.docs?.count ?? 0, | ||
health: indexStats?.health ?? 'unknown', | ||
name: indexName, | ||
}; | ||
return hydratedIndex; | ||
}); | ||
|
||
return indicesWithStats; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters