From f69df810b5b0ca1d82ada407a8b7629acd755153 Mon Sep 17 00:00:00 2001 From: Sonia Sanz Vivas Date: Mon, 21 Oct 2024 13:27:35 +0200 Subject: [PATCH] Remove dataStreamsStats API and use Data Streams verbose in serverless and stateful --- config/serverless.yml | 2 - .../test_suites/core_plugins/rendering.ts | 1 - .../helpers/setup_environment.tsx | 1 - .../home/data_streams_tab.test.ts | 52 ++++++++------- .../public/application/app_context.tsx | 1 - .../data_stream_detail_panel.tsx | 63 +++++++++---------- .../data_stream_table/data_stream_table.tsx | 50 +++++++-------- .../plugins/index_management/public/plugin.ts | 3 - .../plugins/index_management/public/types.ts | 1 - .../plugins/index_management/server/config.ts | 6 -- .../plugins/index_management/server/plugin.ts | 1 - .../register_privileges_route.test.ts | 2 - .../api/data_streams/register_get_route.ts | 28 +++------ .../register_privileges_route.test.ts | 2 - .../server/test/helpers/route_dependencies.ts | 1 - .../plugins/index_management/server/types.ts | 1 - .../common/index_management/datastreams.ts | 2 + 17 files changed, 95 insertions(+), 122 deletions(-) diff --git a/config/serverless.yml b/config/serverless.yml index 75be6151e3bb2..1155a25c043dc 100644 --- a/config/serverless.yml +++ b/config/serverless.yml @@ -102,8 +102,6 @@ xpack.index_management.enableLegacyTemplates: false 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 xpack.index_management.editableIndexSettings: limited # Disable _source field in the Mappings editor's advanced options form from Index Management UI diff --git a/test/plugin_functional/test_suites/core_plugins/rendering.ts b/test/plugin_functional/test_suites/core_plugins/rendering.ts index 83ef8629a6efc..85fee686e2b30 100644 --- a/test/plugin_functional/test_suites/core_plugins/rendering.ts +++ b/test/plugin_functional/test_suites/core_plugins/rendering.ts @@ -291,7 +291,6 @@ export default function ({ getService }: PluginFunctionalProviderContext) { 'xpack.index_management.enableIndexActions (boolean?|never)', 'xpack.index_management.enableLegacyTemplates (boolean?|never)', 'xpack.index_management.enableIndexStats (boolean?|never)', - 'xpack.index_management.enableDataStreamStats (boolean?|never)', 'xpack.index_management.enableSizeAndDocCount (boolean?|never)', 'xpack.index_management.editableIndexSettings (all?|limited?|never)', 'xpack.index_management.enableMappingsSourceFieldSection (boolean?|never)', diff --git a/x-pack/plugins/index_management/__jest__/client_integration/helpers/setup_environment.tsx b/x-pack/plugins/index_management/__jest__/client_integration/helpers/setup_environment.tsx index 633ed96ec8225..7d7c25edd4bd3 100644 --- a/x-pack/plugins/index_management/__jest__/client_integration/helpers/setup_environment.tsx +++ b/x-pack/plugins/index_management/__jest__/client_integration/helpers/setup_environment.tsx @@ -82,7 +82,6 @@ const appDependencies = { enableLegacyTemplates: true, enableIndexActions: true, enableIndexStats: true, - enableDataStreamStats: true, editableIndexSettings: 'all', enableMappingsSourceFieldSection: true, enableTogglingDataRetention: true, diff --git a/x-pack/plugins/index_management/__jest__/client_integration/home/data_streams_tab.test.ts b/x-pack/plugins/index_management/__jest__/client_integration/home/data_streams_tab.test.ts index 1d7ee65790cfd..ee00fc4c07ebc 100644 --- a/x-pack/plugins/index_management/__jest__/client_integration/home/data_streams_tab.test.ts +++ b/x-pack/plugins/index_management/__jest__/client_integration/home/data_streams_tab.test.ts @@ -312,29 +312,10 @@ describe('Data Streams tab', () => { actions.sortTableOnName(); }); - test(`doesn't hide stats toggle if enableDataStreamStats===false`, async () => { - testBed = await setup(httpSetup, { - config: { - enableDataStreamStats: false, - }, - }); - - const { actions, component, exists } = testBed; - - await act(async () => { - actions.goToDataStreamsList(); - }); - - component.update(); - - expect(exists('includeStatsSwitch')).toBeTruthy(); - }); - - test('shows storage size and documents count if enableSizeAndDocCount===true, enableDataStreamStats==false', async () => { + test('shows storage size, documents count, last updated and storage size if enableSizeAndDocCount===true', async () => { testBed = await setup(httpSetup, { config: { enableSizeAndDocCount: true, - enableDataStreamStats: false, }, }); @@ -350,15 +331,38 @@ describe('Data Streams tab', () => { const { tableCellsValues } = table.getMetaData('dataStreamTable'); expect(tableCellsValues).toEqual([ - ['', 'dataStream1', 'green', '156kb', '10000', '1', 'Standard', '7 days', 'Delete'], - ['', 'dataStream2', 'green', '156kb', '10000', '1', 'Standard', '5 days ', 'Delete'], + [ + '', + 'dataStream1', + 'green', + '156kb', + '10000', + 'December 31st, 1969 7:00:00 PM', + '5b', + '1', + 'Standard', + '7 days', + 'Delete', + ], + [ + '', + 'dataStream2', + 'green', + '156kb', + '10000', + 'December 31st, 1969 7:00:00 PM', + '1kb', + '1', + 'Standard', + '5 days ', + 'Delete', + ], ]); }); - test('shows last updated and storage size if enableDataStreamStats===true, enableSizeAndDocCount===false', async () => { + test('shows last updated and storage size if enableSizeAndDocCount===false', async () => { testBed = await setup(httpSetup, { config: { - enableDataStreamStats: true, enableSizeAndDocCount: false, }, }); diff --git a/x-pack/plugins/index_management/public/application/app_context.tsx b/x-pack/plugins/index_management/public/application/app_context.tsx index 1a8276d76b7fc..ffd6916a32ed1 100644 --- a/x-pack/plugins/index_management/public/application/app_context.tsx +++ b/x-pack/plugins/index_management/public/application/app_context.tsx @@ -64,7 +64,6 @@ export interface AppDependencies { enableLegacyTemplates: boolean; enableIndexStats: boolean; enableSizeAndDocCount: boolean; - enableDataStreamStats: boolean; editableIndexSettings: 'all' | 'limited'; enableMappingsSourceFieldSection: boolean; enableTogglingDataRetention: boolean; diff --git a/x-pack/plugins/index_management/public/application/sections/home/data_stream_list/data_stream_detail_panel/data_stream_detail_panel.tsx b/x-pack/plugins/index_management/public/application/sections/home/data_stream_list/data_stream_detail_panel/data_stream_detail_panel.tsx index 5b3bf0920c3b7..4e23b59a32edc 100644 --- a/x-pack/plugins/index_management/public/application/sections/home/data_stream_list/data_stream_detail_panel/data_stream_detail_panel.tsx +++ b/x-pack/plugins/index_management/public/application/sections/home/data_stream_list/data_stream_detail_panel/data_stream_detail_panel.tsx @@ -265,38 +265,37 @@ export const DataStreamDetailPanel: React.FunctionComponent = ({ } ); } - if (config.enableDataStreamStats) { - defaultDetails.push( - { - name: i18n.translate('xpack.idxMgmt.dataStreamDetailPanel.maxTimeStampTitle', { - defaultMessage: 'Last updated', - }), - toolTip: i18n.translate('xpack.idxMgmt.dataStreamDetailPanel.maxTimeStampToolTip', { - defaultMessage: 'The most recent document to be added to the data stream.', - }), - content: maxTimeStamp ? ( - humanizeTimeStamp(maxTimeStamp) - ) : ( - - {i18n.translate('xpack.idxMgmt.dataStreamDetailPanel.maxTimeStampNoneMessage', { - defaultMessage: `Never`, - })} - - ), - dataTestSubj: 'lastUpdatedDetail', - }, - { - name: i18n.translate('xpack.idxMgmt.dataStreamDetailPanel.storageSizeTitle', { - defaultMessage: 'Storage size', - }), - toolTip: i18n.translate('xpack.idxMgmt.dataStreamDetailPanel.storageSizeToolTip', { - defaultMessage: `The total size of all shards in the data stream’s backing indices.`, - }), - content: storageSize, - dataTestSubj: 'storageSizeDetail', - } - ); - } + + defaultDetails.push( + { + name: i18n.translate('xpack.idxMgmt.dataStreamDetailPanel.maxTimeStampTitle', { + defaultMessage: 'Last updated', + }), + toolTip: i18n.translate('xpack.idxMgmt.dataStreamDetailPanel.maxTimeStampToolTip', { + defaultMessage: 'The most recent document to be added to the data stream.', + }), + content: maxTimeStamp ? ( + humanizeTimeStamp(maxTimeStamp) + ) : ( + + {i18n.translate('xpack.idxMgmt.dataStreamDetailPanel.maxTimeStampNoneMessage', { + defaultMessage: `Never`, + })} + + ), + dataTestSubj: 'lastUpdatedDetail', + }, + { + name: i18n.translate('xpack.idxMgmt.dataStreamDetailPanel.storageSizeTitle', { + defaultMessage: 'Storage size', + }), + toolTip: i18n.translate('xpack.idxMgmt.dataStreamDetailPanel.storageSizeToolTip', { + defaultMessage: `The total size of all shards in the data stream’s backing indices.`, + }), + content: storageSize, + dataTestSubj: 'storageSizeDetail', + } + ); defaultDetails.push( { diff --git a/x-pack/plugins/index_management/public/application/sections/home/data_stream_list/data_stream_table/data_stream_table.tsx b/x-pack/plugins/index_management/public/application/sections/home/data_stream_list/data_stream_table/data_stream_table.tsx index e91fd644f795c..4aea201f79f1a 100644 --- a/x-pack/plugins/index_management/public/application/sections/home/data_stream_list/data_stream_table/data_stream_table.tsx +++ b/x-pack/plugins/index_management/public/application/sections/home/data_stream_list/data_stream_table/data_stream_table.tsx @@ -140,32 +140,30 @@ export const DataStreamTable: React.FunctionComponent = ({ sortable: true, }); } - if (config.enableDataStreamStats) { - columns.push({ - field: 'maxTimeStamp', - name: i18n.translate('xpack.idxMgmt.dataStreamList.table.maxTimeStampColumnTitle', { - defaultMessage: 'Last updated', - }), - truncateText: true, - sortable: true, - render: (maxTimeStamp: DataStream['maxTimeStamp']) => - maxTimeStamp - ? humanizeTimeStamp(maxTimeStamp) - : i18n.translate('xpack.idxMgmt.dataStreamList.table.maxTimeStampColumnNoneMessage', { - defaultMessage: 'Never', - }), - }); - columns.push({ - field: 'storageSizeBytes', - name: i18n.translate('xpack.idxMgmt.dataStreamList.table.storageSizeColumnTitle', { - defaultMessage: 'Storage size', - }), - truncateText: true, - sortable: true, - render: (storageSizeBytes: DataStream['storageSizeBytes'], dataStream: DataStream) => - dataStream.storageSize, - }); - } + columns.push({ + field: 'maxTimeStamp', + name: i18n.translate('xpack.idxMgmt.dataStreamList.table.maxTimeStampColumnTitle', { + defaultMessage: 'Last updated', + }), + truncateText: true, + sortable: true, + render: (maxTimeStamp: DataStream['maxTimeStamp']) => + maxTimeStamp + ? humanizeTimeStamp(maxTimeStamp) + : i18n.translate('xpack.idxMgmt.dataStreamList.table.maxTimeStampColumnNoneMessage', { + defaultMessage: 'Never', + }), + }); + columns.push({ + field: 'storageSizeBytes', + name: i18n.translate('xpack.idxMgmt.dataStreamList.table.storageSizeColumnTitle', { + defaultMessage: 'Storage size', + }), + truncateText: true, + sortable: true, + render: (storageSizeBytes: DataStream['storageSizeBytes'], dataStream: DataStream) => + dataStream.storageSize, + }); } columns.push({ diff --git a/x-pack/plugins/index_management/public/plugin.ts b/x-pack/plugins/index_management/public/plugin.ts index 5d857d8d8ac9c..78e5c8c65c618 100644 --- a/x-pack/plugins/index_management/public/plugin.ts +++ b/x-pack/plugins/index_management/public/plugin.ts @@ -48,7 +48,6 @@ export class IndexMgmtUIPlugin enableIndexActions: boolean; enableLegacyTemplates: boolean; enableIndexStats: boolean; - enableDataStreamStats: boolean; enableSizeAndDocCount: boolean; editableIndexSettings: 'all' | 'limited'; isIndexManagementUiEnabled: boolean; @@ -68,7 +67,6 @@ export class IndexMgmtUIPlugin enableIndexActions, enableLegacyTemplates, enableIndexStats, - enableDataStreamStats, enableSizeAndDocCount, editableIndexSettings, enableMappingsSourceFieldSection, @@ -81,7 +79,6 @@ export class IndexMgmtUIPlugin enableIndexActions: enableIndexActions ?? true, enableLegacyTemplates: enableLegacyTemplates ?? true, enableIndexStats: enableIndexStats ?? true, - enableDataStreamStats: enableDataStreamStats ?? true, enableSizeAndDocCount: enableSizeAndDocCount ?? false, editableIndexSettings: editableIndexSettings ?? 'all', enableMappingsSourceFieldSection: enableMappingsSourceFieldSection ?? true, diff --git a/x-pack/plugins/index_management/public/types.ts b/x-pack/plugins/index_management/public/types.ts index c470398c31957..e69c3f25651e0 100644 --- a/x-pack/plugins/index_management/public/types.ts +++ b/x-pack/plugins/index_management/public/types.ts @@ -53,7 +53,6 @@ export interface ClientConfigType { enableLegacyTemplates?: boolean; enableIndexStats?: boolean; enableSizeAndDocCount?: boolean; - enableDataStreamStats?: boolean; editableIndexSettings?: 'all' | 'limited'; enableMappingsSourceFieldSection?: boolean; enableTogglingDataRetention?: boolean; diff --git a/x-pack/plugins/index_management/server/config.ts b/x-pack/plugins/index_management/server/config.ts index f93d7a7d515e7..c48c467c72deb 100644 --- a/x-pack/plugins/index_management/server/config.ts +++ b/x-pack/plugins/index_management/server/config.ts @@ -48,11 +48,6 @@ const schemaLatest = schema.object( // We take this approach in order to have a central place (serverless.yml) for serverless config across Kibana serverless: schema.boolean({ defaultValue: true }), }), - enableDataStreamStats: offeringBasedSchema({ - // Data stream 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 - serverless: schema.boolean({ defaultValue: true }), - }), editableIndexSettings: offeringBasedSchema({ // on serverless only a limited set of index settings can be edited serverless: schema.oneOf([schema.literal('all'), schema.literal('limited')], { @@ -87,7 +82,6 @@ const configLatest: PluginConfigDescriptor = { enableIndexActions: true, enableLegacyTemplates: true, enableIndexStats: true, - enableDataStreamStats: true, enableSizeAndDocCount: true, editableIndexSettings: true, enableMappingsSourceFieldSection: true, diff --git a/x-pack/plugins/index_management/server/plugin.ts b/x-pack/plugins/index_management/server/plugin.ts index 0ba15c463d4ec..77a522feb0af9 100644 --- a/x-pack/plugins/index_management/server/plugin.ts +++ b/x-pack/plugins/index_management/server/plugin.ts @@ -58,7 +58,6 @@ export class IndexMgmtServerPlugin implements Plugin { isLegacyTemplatesEnabled: true, isIndexStatsEnabled: true, isSizeAndDocCountEnabled: false, - isDataStreamStatsEnabled: true, enableMappingsSourceFieldSection: true, enableTogglingDataRetention: true, enableProjectLevelRetentionChecks: false, @@ -122,7 +121,6 @@ describe('GET privileges', () => { isLegacyTemplatesEnabled: true, isIndexStatsEnabled: true, isSizeAndDocCountEnabled: false, - isDataStreamStatsEnabled: true, enableMappingsSourceFieldSection: true, enableTogglingDataRetention: true, enableProjectLevelRetentionChecks: false, diff --git a/x-pack/plugins/index_management/server/routes/api/data_streams/register_get_route.ts b/x-pack/plugins/index_management/server/routes/api/data_streams/register_get_route.ts index cd47b8cc9e0bb..8e3c5a2cc7578 100644 --- a/x-pack/plugins/index_management/server/routes/api/data_streams/register_get_route.ts +++ b/x-pack/plugins/index_management/server/routes/api/data_streams/register_get_route.ts @@ -89,10 +89,17 @@ const enhanceDataStreams = ({ }; const getDataStreams = (client: IScopedClusterClient, name = '*') => { - return client.asCurrentUser.indices.getDataStream({ - name, - expand_wildcards: 'all', + // TODO: Replace this request with the one below when the JS client is updated to 8.16 + return client.asCurrentUser.transport.request({ + method: 'GET', + path: `/_data_stream/${name}?expand_wildcards=all&verbose=true`, }); + + // return client.asCurrentUser.indices.getDataStream({ + // name, + // expand_wildcards: 'all', + // verbose: true, + // }); }; const getDataStreamLifecycle = (client: IScopedClusterClient, name: string) => { @@ -101,14 +108,6 @@ const getDataStreamLifecycle = (client: IScopedClusterClient, name: string) => { }); }; -const getDataStreamsStats = (client: IScopedClusterClient, name = '*') => { - return client.asCurrentUser.indices.dataStreamsStats({ - name, - expand_wildcards: 'all', - human: true, - }); -}; - const getMeteringStats = (client: IScopedClusterClient, name?: string) => { let path = `/_metering/stats`; if (name) { @@ -151,9 +150,6 @@ export function registerGetAllRoute({ router, lib: { handleEsError }, config }: let dataStreamsPrivileges; let meteringStats; - if (includeStats && config.isDataStreamStatsEnabled !== false) { - ({ data_streams: dataStreamsStats } = await getDataStreamsStats(client)); - } if (includeStats && config.isSizeAndDocCountEnabled !== false) { ({ datastreams: meteringStats } = await getMeteringStats(client)); } @@ -206,10 +202,6 @@ export function registerGetOneRoute({ router, lib: { handleEsError }, config }: // @ts-ignore - TS doesn't know about the `global_retention` property yet const globalMaxRetention = lifecycle?.global_retention?.max_retention; - if (config.isDataStreamStatsEnabled !== false) { - ({ data_streams: dataStreamsStats } = await getDataStreamsStats(client, name)); - } - if (config.isSizeAndDocCountEnabled !== false) { ({ datastreams: meteringStats } = await getMeteringStats(client, name)); } diff --git a/x-pack/plugins/index_management/server/routes/api/enrich_policies/register_privileges_route.test.ts b/x-pack/plugins/index_management/server/routes/api/enrich_policies/register_privileges_route.test.ts index 82d1c3cb36ecf..932c28fde7c0d 100644 --- a/x-pack/plugins/index_management/server/routes/api/enrich_policies/register_privileges_route.test.ts +++ b/x-pack/plugins/index_management/server/routes/api/enrich_policies/register_privileges_route.test.ts @@ -49,7 +49,6 @@ describe('GET privileges', () => { isLegacyTemplatesEnabled: true, isIndexStatsEnabled: true, isSizeAndDocCountEnabled: false, - isDataStreamStatsEnabled: true, enableMappingsSourceFieldSection: true, enableTogglingDataRetention: true, enableProjectLevelRetentionChecks: false, @@ -122,7 +121,6 @@ describe('GET privileges', () => { isLegacyTemplatesEnabled: true, isIndexStatsEnabled: true, isSizeAndDocCountEnabled: false, - isDataStreamStatsEnabled: true, enableMappingsSourceFieldSection: true, enableTogglingDataRetention: true, enableProjectLevelRetentionChecks: false, diff --git a/x-pack/plugins/index_management/server/test/helpers/route_dependencies.ts b/x-pack/plugins/index_management/server/test/helpers/route_dependencies.ts index 8d6f37d5128ae..0565f18f362d3 100644 --- a/x-pack/plugins/index_management/server/test/helpers/route_dependencies.ts +++ b/x-pack/plugins/index_management/server/test/helpers/route_dependencies.ts @@ -15,7 +15,6 @@ export const routeDependencies: Omit = { isLegacyTemplatesEnabled: true, isIndexStatsEnabled: true, isSizeAndDocCountEnabled: false, - isDataStreamStatsEnabled: true, enableMappingsSourceFieldSection: true, enableTogglingDataRetention: true, enableProjectLevelRetentionChecks: false, diff --git a/x-pack/plugins/index_management/server/types.ts b/x-pack/plugins/index_management/server/types.ts index ac10983657cec..a44d21059d5a0 100644 --- a/x-pack/plugins/index_management/server/types.ts +++ b/x-pack/plugins/index_management/server/types.ts @@ -26,7 +26,6 @@ export interface RouteDependencies { isLegacyTemplatesEnabled: boolean; isIndexStatsEnabled: boolean; isSizeAndDocCountEnabled: boolean; - isDataStreamStatsEnabled: boolean; enableMappingsSourceFieldSection: boolean; enableTogglingDataRetention: boolean; enableProjectLevelRetentionChecks: boolean; diff --git a/x-pack/test_serverless/api_integration/test_suites/common/index_management/datastreams.ts b/x-pack/test_serverless/api_integration/test_suites/common/index_management/datastreams.ts index 12151f1b169db..7b486870729fe 100644 --- a/x-pack/test_serverless/api_integration/test_suites/common/index_management/datastreams.ts +++ b/x-pack/test_serverless/api_integration/test_suites/common/index_management/datastreams.ts @@ -81,6 +81,7 @@ export default function ({ getService }: FtrProviderContext) { indexTemplateName: testDataStreamName, hidden: false, indexMode: 'standard', + maxTimeStamp: 0, }); }); @@ -123,6 +124,7 @@ export default function ({ getService }: FtrProviderContext) { meteringStorageSize: '0b', meteringStorageSizeBytes: 0, indexMode: 'standard', + maxTimeStamp: 0, }); }); });