[Data Streams] Fix displayed index mode (#215683)

Fixes https://github.com/elastic/kibana/issues/208671

## Summary

Before this PR, the displayed index mode of the data streams was
determined based on the index mode of the associated index template.
However, the index mode can also be set through the component template,
so that logic is not reliable and can cause incorrectly displayed index
mode like described in https://github.com/elastic/kibana/issues/208671.

In this PR, we replace this logic with the recently added `index_mode`
field to the Es Get Data Streams API (see
https://github.com/elastic/elasticsearch/pull/122486).

**How to test:**
1. Create a component template with a LogsDB index mode (you can also
test with other index modes):
```
PUT _component_template/my-component-template
{
  "template": {
    "settings": {
      "index": {
        "mode": "logsdb"
      }
    }
  }
}
```
2. Create an index template that is composed of the component template
above:
```
PUT _index_template/my-index-template
{
  "index_patterns": [
    "my-ds-*"
  ],
  "data_stream": {},
  "composed_of": [
    "my-component-template"
  ]
}
```
3. Create a data stream that matched the index pattern from the index
template above:
```
PUT _data_stream/my-ds-1
```
4. Go to the data streams table and verify that the index mode is
displayed correctly in the table.

<img width="1165" alt="Screenshot 2025-03-24 at 18 12 04"
src="https://github.com/user-attachments/assets/ea211c14-3d03-49c7-ace7-88b15e294d1f"
/>


5. Click on the created data stream and verify that the displayed index
mode in the details panel is correct:

<img width="1165" alt="Screenshot 2025-03-06 at 14 36 12"
src="https://github.com/user-attachments/assets/954864e2-ae2a-4cb8-9eef-2c5f8b417f52"
/>

---------

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
Elena Stoeva 2025-04-16 14:09:33 +01:00 committed by GitHub
parent 937dbba41e
commit dec6a17ec0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 18 additions and 34 deletions

View file

@ -11,7 +11,6 @@ import { IScopedClusterClient } from '@kbn/core/server';
import {
IndicesDataStream,
IndicesDataStreamsStatsDataStreamsStatsItem,
IndicesGetIndexTemplateIndexTemplateItem,
SecurityHasPrivilegesResponse,
} from '@elastic/elasticsearch/lib/api/types';
import type { MeteringStats } from '../../../lib/types';
@ -32,14 +31,12 @@ const enhanceDataStreams = ({
meteringStats,
dataStreamsPrivileges,
globalMaxRetention,
indexTemplates,
}: {
dataStreams: IndicesDataStream[];
dataStreamsStats?: IndicesDataStreamsStatsDataStreamsStatsItem[];
meteringStats?: MeteringStats[];
dataStreamsPrivileges?: SecurityHasPrivilegesResponse;
globalMaxRetention?: string;
indexTemplates?: IndicesGetIndexTemplateIndexTemplateItem[];
}): EnhancedDataStreamFromEs[] => {
return dataStreams.map((dataStream) => {
const enhancedDataStream: EnhancedDataStreamFromEs = {
@ -74,16 +71,6 @@ const enhanceDataStreams = ({
}
}
if (indexTemplates) {
const indexTemplate = indexTemplates.find(
(template) => template.name === dataStream.template
);
if (indexTemplate) {
enhancedDataStream.index_mode =
indexTemplate.index_template?.template?.settings?.index?.mode;
}
}
return enhancedDataStream;
});
};
@ -172,9 +159,6 @@ export function registerGetAllRoute({ router, lib: { handleEsError }, config }:
);
}
const { index_templates: indexTemplates } =
await client.asCurrentUser.indices.getIndexTemplate();
const { persistent, defaults } = await client.asInternalUser.cluster.getSettings({
include_defaults: true,
});
@ -192,7 +176,6 @@ export function registerGetAllRoute({ router, lib: { handleEsError }, config }:
meteringStats,
dataStreamsPrivileges,
globalMaxRetention,
indexTemplates,
});
return response.ok({
@ -243,30 +226,17 @@ export function registerGetOneRoute({ router, lib: { handleEsError }, config }:
if (dataStreams[0]) {
let dataStreamsPrivileges;
let indexTemplates;
if (config.isSecurityEnabled()) {
dataStreamsPrivileges = await getDataStreamsPrivileges(client, [dataStreams[0].name]);
}
if (dataStreams[0].template) {
const { index_templates: templates } =
await client.asCurrentUser.indices.getIndexTemplate({
name: dataStreams[0].template,
});
if (templates) {
indexTemplates = templates;
}
}
const enhancedDataStreams = enhanceDataStreams({
dataStreams,
dataStreamsStats,
meteringStats,
dataStreamsPrivileges,
globalMaxRetention,
indexTemplates,
});
const { persistent, defaults } = await client.asInternalUser.cluster.getSettings({

View file

@ -287,6 +287,11 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
expect(await testSubjects.getVisibleText('indexModeValue')).to.be(indexModeName);
await testSubjects.click('closeDetailsButton');
// Perform rollover so that index mode of data stream is updated
await es.indices.rollover({
alias: TEST_DS_NAME,
});
// Navigate to the data streams tab
await pageObjects.indexManagement.changeTabs('data_streamsTab');
await pageObjects.header.waitUntilLoadingHasFinished();
@ -342,7 +347,8 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
await verifyModeHasBeenChanged(INDEX_MODE.STANDARD);
});
it('allows to upgrade data stream from time series to logsdb index mode', async () => {
// Fails because of https://github.com/elastic/elasticsearch/issues/126473
it.skip('allows to upgrade data stream from time series to logsdb index mode', async () => {
await setIndexModeTemplate({
mode: 'time_series',
routing_path: 'test',
@ -364,7 +370,8 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
await verifyModeHasBeenChanged(INDEX_MODE.LOGSDB);
});
it('allows to downgrade data stream from logsdb to time series index mode', async () => {
// Fails because of https://github.com/elastic/elasticsearch/issues/126473
it.skip('allows to downgrade data stream from logsdb to time series index mode', async () => {
await setIndexModeTemplate({
mode: 'logsdb',
});

View file

@ -205,6 +205,11 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
expect(await testSubjects.getVisibleText('indexModeValue')).to.be(indexModeName);
await testSubjects.click('closeDetailsButton');
// Perform rollover so that index mode of data stream is updated
await es.indices.rollover({
alias: TEST_DS_NAME_INDEX_MODE,
});
// Navigate to the data streams tab
await pageObjects.indexManagement.changeTabs('data_streamsTab');
await pageObjects.header.waitUntilLoadingHasFinished();
@ -267,7 +272,8 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
await verifyModeHasBeenChanged(INDEX_MODE.STANDARD);
});
it('allows to upgrade data stream from time series to logsdb index mode', async () => {
// Fails because of https://github.com/elastic/elasticsearch/issues/126473
it.skip('allows to upgrade data stream from time series to logsdb index mode', async () => {
await setIndexModeTemplate({
mode: 'time_series',
routing_path: 'test',
@ -288,7 +294,8 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
await verifyModeHasBeenChanged(INDEX_MODE.LOGSDB);
});
it('allows to downgrade data stream from logsdb to time series index mode', async () => {
// Fails because of https://github.com/elastic/elasticsearch/issues/126473
it.skip('allows to downgrade data stream from logsdb to time series index mode', async () => {
await setIndexModeTemplate({
mode: 'logsdb',
});