Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Index Management] Add support for index mode #197874

Merged
merged 19 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
4 changes: 4 additions & 0 deletions x-pack/plugins/index_management/common/types/data_streams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export type DataStreamIndexFromEs = IndicesDataStreamIndex;

export type Health = 'green' | 'yellow' | 'red';

export type IndexMode = 'standard' | 'logsdb' | 'time_series';

export interface EnhancedDataStreamFromEs extends IndicesDataStream {
global_max_retention?: string;
store_size?: IndicesDataStreamsStatsDataStreamsStatsItem['store_size'];
Expand All @@ -45,6 +47,7 @@ export interface EnhancedDataStreamFromEs extends IndicesDataStream {
delete_index: boolean;
manage_data_stream_lifecycle: boolean;
};
index_mode?: string | null;
}

export interface DataStream {
Expand All @@ -71,6 +74,7 @@ export interface DataStream {
retention_determined_by?: string;
globalMaxRetention?: string;
};
indexMode: IndexMode;
}

export interface DataStreamIndex {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
EuiCodeBlock,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import { getIndexModeLabel } from '../../../lib/index_mode_labels';
import { allowAutoCreateRadioIds } from '../../../../../common/constants';
import { serializers } from '../../../../shared_imports';

Expand Down Expand Up @@ -268,6 +269,19 @@ export const StepReview: React.FunctionComponent<Props> = React.memo(
{getDescriptionText(serializedSettings)}
</EuiDescriptionListDescription>

{/* Index mode */}
<EuiDescriptionListTitle data-test-subj="indexModeTitle">
<FormattedMessage
id="xpack.idxMgmt.templateForm.stepReview.summaryTab.indexModeLabel"
defaultMessage="Index mode"
/>
</EuiDescriptionListTitle>
<EuiDescriptionListDescription data-test-subj="indexModeValue">
{getIndexModeLabel(
serializedSettings?.['index.mode'] ?? serializedSettings?.index?.mode
mattkime marked this conversation as resolved.
Show resolved Hide resolved
)}
</EuiDescriptionListDescription>

{/* Mappings */}
<EuiDescriptionListTitle>
<FormattedMessage
Expand Down
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 { i18n } from '@kbn/i18n';

export const getIndexModeLabel = (mode?: string | null) => {
switch (mode) {
case 'standard':
case null:
mattkime marked this conversation as resolved.
Show resolved Hide resolved
case undefined:
return i18n.translate('xpack.idxMgmt.indexModeLabels.standardModeLabel', {
defaultMessage: 'Standard',
});
case 'logsdb':
return i18n.translate('xpack.idxMgmt.indexModeLabels.logsdbModeLabel', {
defaultMessage: 'LogsDB',
});
case 'time_series':
return i18n.translate('xpack.idxMgmt.indexModeLabels.tsdbModeLabel', {
defaultMessage: 'Time series',
});
default:
return mode;
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
EuiSpacer,
} from '@elastic/eui';

import { getIndexModeLabel } from '../../../../lib/index_mode_labels';
import { DiscoverLink } from '../../../../lib/discover_link';
import { getLifecycleValue } from '../../../../lib/data_streams';
import { SectionLoading, reactRouterNavigate } from '../../../../../shared_imports';
Expand Down Expand Up @@ -166,6 +167,7 @@ export const DataStreamDetailPanel: React.FunctionComponent<Props> = ({
meteringStorageSize,
meteringDocsCount,
lifecycle,
indexMode,
} = dataStream;

const getManagementDetails = () => {
Expand Down Expand Up @@ -345,6 +347,17 @@ export const DataStreamDetailPanel: React.FunctionComponent<Props> = ({
),
dataTestSubj: 'indexTemplateDetail',
},
{
name: i18n.translate('xpack.idxMgmt.dataStreamDetailPanel.indexModeTitle', {
defaultMessage: 'Index mode',
}),
toolTip: i18n.translate('xpack.idxMgmt.dataStreamDetailPanel.indexModeToolTip', {
defaultMessage:
'The index mode setting of the index template that configured this data stream.',
ElenaStoeva marked this conversation as resolved.
Show resolved Hide resolved
}),
content: getIndexModeLabel(indexMode),
dataTestSubj: 'indexModeDetail',
},
{
name: i18n.translate('xpack.idxMgmt.dataStreamDetailPanel.dataRetentionTitle', {
defaultMessage: 'Effective data retention',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { humanizeTimeStamp } from '../humanize_time_stamp';
import { DataStreamsBadges } from '../data_stream_badges';
import { ConditionalWrap } from '../data_stream_detail_panel';
import { isDataStreamFullyManagedByILM } from '../../../../lib/data_streams';
import { getIndexModeLabel } from '../../../../lib/index_mode_labels';
import { FilterListButton, Filters } from '../../components';
import { type DataStreamFilterName } from '../data_stream_list';

Expand Down Expand Up @@ -184,6 +185,16 @@ export const DataStreamTable: React.FunctionComponent<Props> = ({
),
});

columns.push({
field: 'indexMode',
name: i18n.translate('xpack.idxMgmt.dataStreamList.table.indexModeColumnTitle', {
defaultMessage: 'Index mode',
}),
truncateText: true,
sortable: true,
render: (indexMode: DataStream['indexMode']) => getIndexModeLabel(indexMode),
});

columns.push({
field: 'lifecycle',
name: (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { TemplateDeserialized } from '../../../../../../../common';
import { ILM_PAGES_POLICY_EDIT } from '../../../../../constants';
import { useIlmLocator } from '../../../../../services/use_ilm_locator';
import { allowAutoCreateRadioIds } from '../../../../../../../common/constants';
import { getIndexModeLabel } from '../../../../../lib/index_mode_labels';

interface Props {
templateDetails: TemplateDeserialized;
Expand Down Expand Up @@ -57,6 +58,9 @@ export const TabSummary: React.FunctionComponent<Props> = ({ templateDetails })
_meta,
_kbnMeta: { isLegacy, hasDatastream },
allowAutoCreate,
template: {
settings: { index: indexSettings },
},
} = templateDetails;

const numIndexPatterns = indexPatterns.length;
Expand Down Expand Up @@ -221,6 +225,17 @@ export const TabSummary: React.FunctionComponent<Props> = ({ templateDetails })
</>
)}

{/* Index mode */}
<EuiDescriptionListTitle>
<FormattedMessage
id="xpack.idxMgmt.templateDetails.stepReview.summaryTab.indexModeLabel"
defaultMessage="Index mode"
/>
</EuiDescriptionListTitle>
<EuiDescriptionListDescription>
{getIndexModeLabel(indexSettings?.mode)}
</EuiDescriptionListDescription>

{/* Allow auto create */}
{isLegacy !== true &&
allowAutoCreate !== allowAutoCreateRadioIds.NO_OVERWRITE_RADIO_OPTION && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import { ByteSizeValue } from '@kbn/config-schema';
import type { DataStream, EnhancedDataStreamFromEs, Health } from '../../common';
import { IndexMode } from "@kbn/index-management-plugin/common/types/data_streams";

export function deserializeDataStream(dataStreamFromEs: EnhancedDataStreamFromEs): DataStream {
const {
Expand All @@ -28,6 +29,7 @@ export function deserializeDataStream(dataStreamFromEs: EnhancedDataStreamFromEs
lifecycle,
global_max_retention: globalMaxRetention,
next_generation_managed_by: nextGenerationManagedBy,
index_mode: indexMode,
} = dataStreamFromEs;
const meteringStorageSize =
meteringStorageSizeBytes !== undefined
Expand Down Expand Up @@ -73,6 +75,7 @@ export function deserializeDataStream(dataStreamFromEs: EnhancedDataStreamFromEs
globalMaxRetention,
},
nextGenerationManagedBy,
indexMode: (indexMode ?? 'standard') as IndexMode,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
deserializeDataStream,
deserializeDataStreamList,
} from '../../../lib/data_stream_serialization';
import { EnhancedDataStreamFromEs } from '../../../../common/types';
import { EnhancedDataStreamFromEs, TemplateSerialized } from '../../../../common/types';
import { RouteDependencies } from '../../../types';
import { addBasePath } from '..';

Expand All @@ -31,12 +31,14 @@ const enhanceDataStreams = ({
meteringStats,
dataStreamsPrivileges,
globalMaxRetention,
indexTemplates,
}: {
dataStreams: IndicesDataStream[];
dataStreamsStats?: IndicesDataStreamsStatsDataStreamsStatsItem[];
meteringStats?: MeteringStats[];
dataStreamsPrivileges?: SecurityHasPrivilegesResponse;
globalMaxRetention?: string;
indexTemplates?: Array<{ name: string; index_template: TemplateSerialized }>;
}): EnhancedDataStreamFromEs[] => {
return dataStreams.map((dataStream) => {
const enhancedDataStream: EnhancedDataStreamFromEs = {
Expand Down Expand Up @@ -71,6 +73,11 @@ const enhanceDataStreams = ({
}
}

const indexTemplate = indexTemplates.find((template) => template.name === dataStream.template);
if (indexTemplate) {
enhancedDataStream.index_mode = indexTemplate.index_template?.template?.settings?.index?.mode;
}

return enhancedDataStream;
});
};
Expand Down Expand Up @@ -152,11 +159,15 @@ export function registerGetAllRoute({ router, lib: { handleEsError }, config }:
);
}

const { index_templates: indexTemplates } =
await client.asCurrentUser.indices.getIndexTemplate();

const enhancedDataStreams = enhanceDataStreams({
dataStreams,
dataStreamsStats,
meteringStats,
dataStreamsPrivileges,
indexTemplates,
});

return response.ok({ body: deserializeDataStreamList(enhancedDataStreams) });
Expand Down Expand Up @@ -199,17 +210,30 @@ 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 body = deserializeDataStream(enhancedDataStreams[0]);
return response.ok({ body });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export default function ({ getService }: FtrProviderContext) {
health: 'yellow',
indexTemplateName: testDataStreamName,
hidden: false,
indexMode: 'standard',
});
});

Expand Down Expand Up @@ -120,6 +121,7 @@ export default function ({ getService }: FtrProviderContext) {
lifecycle: {
enabled: true,
},
indexMode: 'standard',
});
});

Expand Down Expand Up @@ -158,8 +160,25 @@ export default function ({ getService }: FtrProviderContext) {
lifecycle: {
enabled: true,
},
indexMode: 'standard',
});
});

it('correctly returns index mode property', async () => {
const logsdbDataStreamName = 'logsdb-test-data-stream';
const indexMode = 'logsdb';

await createDataStream(logsdbDataStreamName, indexMode);

const { body: dataStream } = await supertest
.get(`${API_BASE_PATH}/data_streams/${logsdbDataStreamName}`)
.set('kbn-xsrf', 'xxx')
.expect(200);

expect(dataStream.indexMode).to.eql(indexMode);

await deleteDataStream(logsdbDataStreamName);
});
});

describe('Update', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { FtrProviderContext } from '../../../../ftr_provider_context';
export function datastreamsHelpers(getService: FtrProviderContext['getService']) {
const es = getService('es');

const createDataStream = async (name: string) => {
const createDataStream = async (name: string, indexMode?: string) => {
// A data stream requires an index template before it can be created.
await es.indices.putIndexTemplate({
name,
Expand All @@ -26,6 +26,11 @@ export function datastreamsHelpers(getService: FtrProviderContext['getService'])
},
},
},
settings: {
index: {
mode: indexMode,
},
},
lifecycle: {
// @ts-expect-error @elastic/elasticsearch enabled prop is not typed yet
enabled: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
await testSubjects.click('closeDetailsButton');
});

it('shows the correct index mode in the details flyout', async () => {
// Open details flyout
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to have tests that also check for logsdb

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added with 2590ba4.

await pageObjects.indexManagement.clickDataStreamNameLink(TEST_DS_NAME);
// Check that index mode detail exists and its label is "Standard"
expect(await testSubjects.exists('indexModeDetail')).to.be(true);
expect(await testSubjects.getVisibleText('indexModeDetail')).to.be('Standard');
// Close flyout
await testSubjects.click('closeDetailsButton');
});

it('allows to update data retention', async () => {
// Open details flyout
await pageObjects.indexManagement.clickDataStreamNameLink(TEST_DS_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
const summaryTabContent = await testSubjects.exists('summaryTabContent');
expect(summaryTabContent).to.be(true);

// Verify that index mode is set to "Standard"
expect(await testSubjects.exists('indexModeTitle')).to.be(true);
expect(await testSubjects.getVisibleText('indexModeValue')).to.be('Standard');

// Click Create template
await pageObjects.indexManagement.clickNextButton();
});
Expand Down