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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
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: string;
}

export interface DataStreamIndex {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,17 @@ export const StepReview: React.FunctionComponent<Props> = React.memo(
{getDescriptionText(serializedSettings)}
</EuiDescriptionListDescription>

{/* Index settings */}
<EuiDescriptionListTitle>
<FormattedMessage
id="xpack.idxMgmt.templateForm.stepReview.summaryTab.indexModeLabel"
defaultMessage="Index mode"
/>
</EuiDescriptionListTitle>
<EuiDescriptionListDescription>
{serializedSettings?.index?.mode ?? 'standard'}
</EuiDescriptionListDescription>

{/* Mappings */}
<EuiDescriptionListTitle>
<FormattedMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ export const DataStreamDetailPanel: React.FunctionComponent<Props> = ({
meteringStorageSize,
meteringDocsCount,
lifecycle,
indexMode,
} = dataStream;

const getManagementDetails = () => {
Expand Down Expand Up @@ -345,6 +346,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.',
}),
content: indexMode ?? 'standard',
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 @@ -84,6 +84,8 @@ export const DataStreamList: React.FunctionComponent<RouteComponentProps<MatchPa
includeStats: isIncludeStatsChecked,
});

console.log(dataStreams);

const [projectLevelRetentionCallout, setprojectLevelRetentionCallout] =
useStateWithLocalStorage<boolean>(SHOW_PROJECT_LEVEL_RETENTION, true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,15 @@ 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,
});

columns.push({
field: 'lifecycle',
name: (
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