Skip to content

Commit

Permalink
[Search] [Onboarding] Add metering stats API information to indices G…
Browse files Browse the repository at this point in the history
…ET (#191631)

## Summary

Adds index size and doc count to indices management indices API. This
API is available only on ES3, relying on the _metering/stats API to
provide this information. The use of the API is scoped only for
serverless projects, via a config.

AppEx will roll out the UI changes for the other ES3 project solutions.

### Checklist

Delete any items that are not applicable to this PR.

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [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
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [ ] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- [ ] Any UI touched in this PR does not create any new axe failures
(run axe in browser:
[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),
[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This renders correctly on smaller devices using a responsive
layout. (You can test this [in your
browser](https://www.browserstack.com/guide/responsive-testing-on-local-server))
- [ ] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)


### Risk Matrix

Delete this section if it is not applicable to this PR.

Before closing this PR, invite QA, stakeholders, and other developers to
identify risks that should be tested prior to the change/feature
release.

When forming the risk matrix, consider some of the following examples
and how they may potentially impact the change:

| Risk | Probability | Severity | Mitigation/Notes |

|---------------------------|-------------|----------|-------------------------|
| Multiple Spaces—unexpected behavior in non-default Kibana Space.
| Low | High | Integration tests will verify that all features are still
supported in non-default Kibana Space and when user switches between
spaces. |
| Multiple nodes—Elasticsearch polling might have race conditions
when multiple Kibana nodes are polling for the same tasks. | High | Low
| Tasks are idempotent, so executing them multiple times will not result
in logical error, but will degrade performance. To test for this case we
add plenty of unit tests around this logic and document manual testing
procedure. |
| Code should gracefully handle cases when feature X or plugin Y are
disabled. | Medium | High | Unit tests will verify that any feature flag
or plugin combination still results in our service operational. |
| [See more potential risk
examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) |


### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

---------

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
joemcelroy and elasticmachine authored Sep 2, 2024
1 parent a487010 commit c5fe618
Show file tree
Hide file tree
Showing 14 changed files with 292 additions and 152 deletions.
2 changes: 2 additions & 0 deletions config/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ xpack.index_management.enableIndexActions: false
xpack.index_management.enableLegacyTemplates: false
# Disable index stats information from Index Management UI
xpack.index_management.enableIndexStats: false
# Enable size and doc count information via metering API from Index Management UI
xpack.index_management.enableSizeAndDocCount: true
# Disable data stream stats information from Index Management UI
xpack.index_management.enableDataStreamStats: false
# Only limited index settings can be edited
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export interface AppDependencies {
enableIndexActions: boolean;
enableLegacyTemplates: boolean;
enableIndexStats: boolean;
enableSizeAndDocCount: boolean;
enableDataStreamStats: boolean;
editableIndexSettings: 'all' | 'limited';
enableMappingsSourceFieldSection: boolean;
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/index_management/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class IndexMgmtUIPlugin
enableIndexActions: boolean;
enableLegacyTemplates: boolean;
enableIndexStats: boolean;
enableSizeAndDocCount: boolean;
enableDataStreamStats: boolean;
editableIndexSettings: 'all' | 'limited';
isIndexManagementUiEnabled: boolean;
Expand All @@ -59,6 +60,7 @@ export class IndexMgmtUIPlugin
enableIndexActions,
enableLegacyTemplates,
enableIndexStats,
enableSizeAndDocCount,
enableDataStreamStats,
editableIndexSettings,
enableMappingsSourceFieldSection,
Expand All @@ -70,6 +72,7 @@ export class IndexMgmtUIPlugin
enableIndexActions: enableIndexActions ?? true,
enableLegacyTemplates: enableLegacyTemplates ?? true,
enableIndexStats: enableIndexStats ?? true,
enableSizeAndDocCount: enableSizeAndDocCount ?? true,
enableDataStreamStats: enableDataStreamStats ?? true,
editableIndexSettings: editableIndexSettings ?? 'all',
enableMappingsSourceFieldSection: enableMappingsSourceFieldSection ?? true,
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/index_management/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export interface ClientConfigType {
enableIndexActions?: boolean;
enableLegacyTemplates?: boolean;
enableIndexStats?: boolean;
enableSizeAndDocCount?: boolean;
enableDataStreamStats?: boolean;
editableIndexSettings?: 'all' | 'limited';
enableMappingsSourceFieldSection?: boolean;
Expand Down
5 changes: 5 additions & 0 deletions x-pack/plugins/index_management/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ const schemaLatest = schema.object(
// deprecate as unused after semantic text is enabled everywhere
enableSemanticText: schema.boolean({ defaultValue: true }),
}),
enableSizeAndDocCount: offeringBasedSchema({
// Size and document count information is enabled in serverless; refer to the serverless.yml file as the source of truth
// We take this approach in order to have a central place (serverless.yml) for serverless config across Kibana
serverless: schema.boolean({ defaultValue: true }),
}),
enableIndexStats: offeringBasedSchema({
// Index stats information is disabled in serverless; refer to the serverless.yml file as the source of truth
// We take this approach in order to have a central place (serverless.yml) for serverless config across Kibana
Expand Down
281 changes: 163 additions & 118 deletions x-pack/plugins/index_management/server/lib/fetch_indices.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,143 +19,188 @@ describe('[Index management API Routes] fetch indices lib function', () => {

const getIndices = router.getMockESApiFn('indices.get');
const getIndicesStats = router.getMockESApiFn('indices.stats');
const getMeteringStats = router.getMockESApiFnAsSecondaryAuthUser('transport.request');
const mockRequest: RequestMock = {
method: 'get',
path: addBasePath('/indices'),
};

beforeAll(() => {
registerIndicesRoutes({
...routeDependencies,
router,
describe('stateful', () => {
beforeAll(() => {
registerIndicesRoutes({
...routeDependencies,
config: {
...routeDependencies.config,
isSizeAndDocCountEnabled: false,
isIndexStatsEnabled: true,
},
router,
});
});
});

test('regular index', async () => {
getIndices.mockResolvedValue({
regular_index: createTestIndexState(),
});
getIndicesStats.mockResolvedValue({
indices: {
regular_index: createTestIndexStats({ uuid: 'regular_index' }),
},
});
test('regular index', async () => {
getIndices.mockResolvedValue({
regular_index: createTestIndexState(),
});
getIndicesStats.mockResolvedValue({
indices: {
regular_index: createTestIndexStats({ uuid: 'regular_index' }),
},
});

await expect(router.runRequest(mockRequest)).resolves.toEqual({
body: [createTestIndexResponse({ name: 'regular_index', uuid: 'regular_index' })],
});
});
test('index with aliases', async () => {
getIndices.mockResolvedValue({
index_with_aliases: createTestIndexState({
aliases: { test_alias: {}, another_alias: {} },
}),
});
getIndicesStats.mockResolvedValue({
indices: {
index_with_aliases: createTestIndexStats({ uuid: 'index_with_aliases' }),
},
});

await expect(router.runRequest(mockRequest)).resolves.toEqual({
body: [
createTestIndexResponse({
aliases: ['test_alias', 'another_alias'],
name: 'index_with_aliases',
uuid: 'index_with_aliases',
await expect(router.runRequest(mockRequest)).resolves.toEqual({
body: [createTestIndexResponse({ name: 'regular_index', uuid: 'regular_index' })],
});
});
test('index with aliases', async () => {
getIndices.mockResolvedValue({
index_with_aliases: createTestIndexState({
aliases: { test_alias: {}, another_alias: {} },
}),
],
});
});
test('frozen index', async () => {
getIndices.mockResolvedValue({
frozen_index: createTestIndexState({
settings: { index: { number_of_shards: 1, number_of_replicas: 1, frozen: 'true' } },
}),
});
getIndicesStats.mockResolvedValue({
indices: {
frozen_index: createTestIndexStats({ uuid: 'frozen_index' }),
},
});
});
getIndicesStats.mockResolvedValue({
indices: {
index_with_aliases: createTestIndexStats({ uuid: 'index_with_aliases' }),
},
});

await expect(router.runRequest(mockRequest)).resolves.toEqual({
body: [
createTestIndexResponse({
name: 'frozen_index',
uuid: 'frozen_index',
isFrozen: true,
await expect(router.runRequest(mockRequest)).resolves.toEqual({
body: [
createTestIndexResponse({
aliases: ['test_alias', 'another_alias'],
name: 'index_with_aliases',
uuid: 'index_with_aliases',
}),
],
});
});
test('frozen index', async () => {
getIndices.mockResolvedValue({
frozen_index: createTestIndexState({
settings: { index: { number_of_shards: 1, number_of_replicas: 1, frozen: 'true' } },
}),
],
});
});
test('hidden index', async () => {
getIndices.mockResolvedValue({
hidden_index: createTestIndexState({
settings: { index: { number_of_shards: 1, number_of_replicas: 1, hidden: 'true' } },
}),
});
getIndicesStats.mockResolvedValue({
indices: {
hidden_index: createTestIndexStats({ uuid: 'hidden_index' }),
},
});
});
getIndicesStats.mockResolvedValue({
indices: {
frozen_index: createTestIndexStats({ uuid: 'frozen_index' }),
},
});

await expect(router.runRequest(mockRequest)).resolves.toEqual({
body: [
createTestIndexResponse({
name: 'hidden_index',
uuid: 'hidden_index',
hidden: true,
await expect(router.runRequest(mockRequest)).resolves.toEqual({
body: [
createTestIndexResponse({
name: 'frozen_index',
uuid: 'frozen_index',
isFrozen: true,
}),
],
});
});
test('hidden index', async () => {
getIndices.mockResolvedValue({
hidden_index: createTestIndexState({
settings: { index: { number_of_shards: 1, number_of_replicas: 1, hidden: 'true' } },
}),
],
});
});
test('data stream index', async () => {
getIndices.mockResolvedValue({
data_stream_index: createTestIndexState({
data_stream: 'test_data_stream',
}),
});
getIndicesStats.mockResolvedValue({
indices: {
data_stream_index: createTestIndexStats({ uuid: 'data_stream_index' }),
},
});
});
getIndicesStats.mockResolvedValue({
indices: {
hidden_index: createTestIndexStats({ uuid: 'hidden_index' }),
},
});

await expect(router.runRequest(mockRequest)).resolves.toEqual({
body: [
createTestIndexResponse({
name: 'data_stream_index',
uuid: 'data_stream_index',
await expect(router.runRequest(mockRequest)).resolves.toEqual({
body: [
createTestIndexResponse({
name: 'hidden_index',
uuid: 'hidden_index',
hidden: true,
}),
],
});
});
test('data stream index', async () => {
getIndices.mockResolvedValue({
data_stream_index: createTestIndexState({
data_stream: 'test_data_stream',
}),
],
});
getIndicesStats.mockResolvedValue({
indices: {
data_stream_index: createTestIndexStats({ uuid: 'data_stream_index' }),
},
});

await expect(router.runRequest(mockRequest)).resolves.toEqual({
body: [
createTestIndexResponse({
name: 'data_stream_index',
uuid: 'data_stream_index',
data_stream: 'test_data_stream',
}),
],
});
});
test('index missing in stats call', async () => {
getIndices.mockResolvedValue({
index_missing_stats: createTestIndexState(),
});
// simulates when an index has been deleted after get indices call
// deleted index won't be present in the indices stats call response
getIndicesStats.mockResolvedValue({
indices: {
some_other_index: createTestIndexStats({ uuid: 'some_other_index' }),
},
});
await expect(router.runRequest(mockRequest)).resolves.toEqual({
body: [
createTestIndexResponse({
name: 'index_missing_stats',
uuid: undefined,
health: undefined,
status: undefined,
documents: 0,
size: '0b',
primary_size: '0b',
}),
],
});
});
});
test('index missing in stats call', async () => {
getIndices.mockResolvedValue({
index_missing_stats: createTestIndexState(),
});
// simulates when an index has been deleted after get indices call
// deleted index won't be present in the indices stats call response
getIndicesStats.mockResolvedValue({
indices: {
some_other_index: createTestIndexStats({ uuid: 'some_other_index' }),
},

describe('stateless', () => {
beforeAll(() => {
registerIndicesRoutes({
...routeDependencies,
config: {
...routeDependencies.config,
isSizeAndDocCountEnabled: true,
isIndexStatsEnabled: false,
},
router,
});
});
await expect(router.runRequest(mockRequest)).resolves.toEqual({
body: [
createTestIndexResponse({
name: 'index_missing_stats',
uuid: undefined,
health: undefined,
status: undefined,
documents: 0,
size: '0b',
primary_size: '0b',
}),
],

test('regular index', async () => {
getIndices.mockResolvedValue({
regular_index: createTestIndexState(),
});
getMeteringStats.mockResolvedValue({
indices: [{ name: 'regular_index', num_docs: 100, size_in_bytes: 1000 }],
});

await expect(router.runRequest(mockRequest)).resolves.toEqual({
body: [
{
name: 'regular_index',
isFrozen: false,
aliases: 'none',
hidden: false,
data_stream: undefined,
documents: 100,
size: '1000b',
},
],
});
});
});
});
Loading

0 comments on commit c5fe618

Please sign in to comment.