Skip to content
Merged
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
11 changes: 9 additions & 2 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -1732,8 +1732,15 @@ x-pack/solutions/observability/plugins/observability/server/lib/esql_extensions
## Streams parts owned by Logs UX
/x-pack/platform/plugins/shared/streams_app/public/components/stream_management/data_management @elastic/obs-onboarding-team

# Streams parts owned by Kibana Management
x-pack/platform/plugins/shared/streams_app/public/components/stream_management/data_management/stream_detail_lifecycle/downsampling @elastic/kibana-management
# Streams - Data retention overrides (owned by Kibana Management)
x-pack/platform/plugins/shared/streams_app/public/components/stream_management/data_management/stream_detail_lifecycle @elastic/kibana-management
x-pack/platform/plugins/shared/streams/server/lib/streams/failure_store @elastic/kibana-management
x-pack/platform/plugins/shared/streams/server/routes/internal/streams/failure_store @elastic/kibana-management
x-pack/platform/plugins/shared/streams/server/routes/internal/streams/lifecycle @elastic/kibana-management
x-pack/platform/plugins/shared/streams/server/lib/streams/lifecycle/ilm_policies.ts @elastic/kibana-management
x-pack/platform/plugins/shared/streams/server/lib/streams/lifecycle/ilm_policies.test.ts @elastic/kibana-management
x-pack/platform/plugins/shared/streams/server/lib/streams/lifecycle/ilm_phases.ts @elastic/kibana-management
x-pack/platform/plugins/shared/streams/server/lib/streams/lifecycle/ilm_phases.test.ts @elastic/kibana-management

# Streams — sig events overrides (obs-sig-events-team owns these subtrees)
x-pack/platform/plugins/shared/streams_app/public/components/sig_events @elastic/obs-sig-events-team
Expand Down
1 change: 1 addition & 0 deletions .review/worktrees/283dd855
Submodule 283dd855 added at 283dd8
2 changes: 1 addition & 1 deletion packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ pageLoadAssetSize:
spaces: 28871
stackAlerts: 31499
stackConnectors: 85421
streams: 14000
streams: 15434
streamsApp: 25375
synthetics: 31571
telemetry: 25755
Expand Down
1 change: 1 addition & 0 deletions x-pack/platform/plugins/shared/streams/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export {
ATTACHMENT_SUGGESTIONS_LIMIT,
DEFAULT_EXTRACTION_INTERVAL_HOURS,
MIN_EXTRACTION_INTERVAL_HOURS,
FAILURE_STORE_SELECTOR,
} from './constants';

export type { StreamDocsStat } from './doc_counts';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
* 2.0.
*/

export const FAILURE_STORE_SELECTOR = '::failures';
export { getClusterDefaultFailureStoreRetentionValue, getFailureStoreStats } from './route_helpers';
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/*
* 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 type { DocStats, EpochTime, UnitMillis } from '@elastic/elasticsearch/lib/api/types';
import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import type { FailureStoreStatsResponse } from '@kbn/streams-schema/src/models/ingest/failure_store';

import { FAILURE_STORE_SELECTOR } from '../../../../common/constants';
import { parseError } from '../errors/parse_error';

export async function getClusterDefaultFailureStoreRetentionValue({
esClient,
isServerless,
}: {
esClient: ElasticsearchClient;
isServerless: boolean;
}): Promise<string | undefined> {
let defaultRetention: string | undefined;
try {
if (!isServerless) {
const { persistent, defaults } = await esClient.cluster.getSettings({
include_defaults: true,
});
const persistentDSRetention =
persistent?.data_streams?.lifecycle?.retention?.failures_default;
const defaultsDSRetention = defaults?.data_streams?.lifecycle?.retention?.failures_default;
defaultRetention = persistentDSRetention ?? defaultsDSRetention;
}
} catch (e) {
const { statusCode } = parseError(e);
if (statusCode === 403) {
// if user doesn't have permissions to read cluster settings, we just return undefined
} else {
throw e;
}
}
return defaultRetention;
}

export async function getFailureStoreStats({
name,
esClient,
esClientAsSecondaryAuthUser,
isServerless,
}: {
name: string;
esClient: ElasticsearchClient;
esClientAsSecondaryAuthUser?: ElasticsearchClient;
isServerless: boolean;
}): Promise<FailureStoreStatsResponse> {
const failureStoreDocs =
isServerless && esClientAsSecondaryAuthUser
? await getFailureStoreMeteringSize({ name, esClientAsSecondaryAuthUser })
: await getFailureStoreSize({ name, esClient });
const creationDate = await getFailureStoreCreationDate({ name, esClient });

return {
size: failureStoreDocs?.total_size_in_bytes,
count: failureStoreDocs?.count,
creationDate,
};
}

async function getFailureStoreSize({
name,
esClient,
}: {
name: string;
esClient: ElasticsearchClient;
}): Promise<DocStats | undefined> {
try {
const response = await esClient.indices.stats({
index: `${name}${FAILURE_STORE_SELECTOR}`,
metric: ['docs'],
forbid_closed_indices: false,
});
const docsStats = response?._all?.total?.docs;
return {
count: docsStats?.count || 0,
total_size_in_bytes: docsStats?.total_size_in_bytes || 0,
};
} catch (e) {
const { statusCode } = parseError(e);
if (statusCode === 404) {
return undefined;
} else {
throw e;
}
}
}

async function getFailureStoreMeteringSize({
name,
esClientAsSecondaryAuthUser,
}: {
name: string;
esClientAsSecondaryAuthUser: ElasticsearchClient;
}): Promise<DocStats | undefined> {
try {
const response = await esClientAsSecondaryAuthUser.transport.request<{
_total: { num_docs: number; size_in_bytes: number };
}>({
method: 'GET',
path: `/_metering/stats/${name}${FAILURE_STORE_SELECTOR}`,
});

return {
count: response._total?.num_docs || 0,
total_size_in_bytes: response._total?.size_in_bytes || 0,
};
} catch (e) {
const { statusCode } = parseError(e);
if (statusCode === 404) {
return undefined;
} else {
throw e;
}
}
}

async function getFailureStoreCreationDate({
name,
esClient,
}: {
name: string;
esClient: ElasticsearchClient;
}): Promise<number | undefined> {
let age: number | undefined;
try {
const response = await esClient.indices.explainDataLifecycle({
index: `${name}${FAILURE_STORE_SELECTOR}`,
});
const indices = response.indices;
if (indices && typeof indices === 'object') {
const firstIndex = Object.values(indices)[0] as {
index_creation_date_millis?: EpochTime<UnitMillis>;
};
age = firstIndex?.index_creation_date_millis;
}
return age || undefined;
} catch (e) {
const { statusCode } = parseError(e);
if (statusCode === 404) {
return undefined;
} else {
throw e;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,14 @@

import type {
ClusterComponentTemplate,
DocStats,
EpochTime,
IndicesDataStream,
IndicesGetDataStreamSettingsDataStreamSettings,
IndicesGetIndexTemplateIndexTemplateItem,
IngestPipeline,
UnitMillis,
} from '@elastic/elasticsearch/lib/api/types';
import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import type {
EffectiveFailureStore,
FailureStoreStatsResponse,
DataStreamWithFailureStore,
} from '@kbn/streams-schema/src/models/ingest/failure_store';
import type {
Expand All @@ -27,7 +23,6 @@ import type {
} from '@kbn/streams-schema';
import type { DownsampleStep } from '@kbn/streams-schema/src/models/ingest/lifecycle';

import { FAILURE_STORE_SELECTOR } from '../../../common/constants';
import { DefinitionNotFoundError } from './errors/definition_not_found_error';
import { parseError } from './errors/parse_error';

Expand Down Expand Up @@ -313,35 +308,6 @@ export async function getDataStream({
return dataStream;
}

export async function getClusterDefaultFailureStoreRetentionValue({
esClient,
isServerless,
}: {
esClient: ElasticsearchClient;
isServerless: boolean;
}): Promise<string | undefined> {
let defaultRetention: string | undefined;
try {
if (!isServerless) {
const { persistent, defaults } = await esClient.cluster.getSettings({
include_defaults: true,
});
const persistentDSRetention =
persistent?.data_streams?.lifecycle?.retention?.failures_default;
const defaultsDSRetention = defaults?.data_streams?.lifecycle?.retention?.failures_default;
defaultRetention = persistentDSRetention ?? defaultsDSRetention;
}
} catch (e) {
const { statusCode } = parseError(e);
if (statusCode === 403) {
// if user doesn't have permissions to read cluster settings, we just return undefined
} else {
throw e;
}
}
return defaultRetention;
}

export function getFailureStore({
dataStream,
}: {
Expand Down Expand Up @@ -377,114 +343,3 @@ export function getFailureStore({

return { disabled: {} };
}

export async function getFailureStoreStats({
name,
esClient,
esClientAsSecondaryAuthUser,
isServerless,
}: {
name: string;
esClient: ElasticsearchClient;
esClientAsSecondaryAuthUser?: ElasticsearchClient;
isServerless: boolean;
}): Promise<FailureStoreStatsResponse> {
const failureStoreDocs =
isServerless && esClientAsSecondaryAuthUser
? await getFailureStoreMeteringSize({ name, esClientAsSecondaryAuthUser })
: await getFailureStoreSize({ name, esClient });
const creationDate = await getFailureStoreCreationDate({ name, esClient });

return {
size: failureStoreDocs?.total_size_in_bytes,
count: failureStoreDocs?.count,
creationDate,
};
}

export async function getFailureStoreSize({
name,
esClient,
}: {
name: string;
esClient: ElasticsearchClient;
}): Promise<DocStats | undefined> {
try {
const response = await esClient.indices.stats({
index: `${name}${FAILURE_STORE_SELECTOR}`,
metric: ['docs'],
forbid_closed_indices: false,
});
const docsStats = response?._all?.total?.docs;
return {
count: docsStats?.count || 0,
total_size_in_bytes: docsStats?.total_size_in_bytes || 0,
};
} catch (e) {
const { statusCode } = parseError(e);
if (statusCode === 404) {
return undefined;
} else {
throw e;
}
}
}

export async function getFailureStoreMeteringSize({
name,
esClientAsSecondaryAuthUser,
}: {
name: string;
esClientAsSecondaryAuthUser: ElasticsearchClient;
}): Promise<DocStats | undefined> {
try {
const response = await esClientAsSecondaryAuthUser.transport.request<{
_total: { num_docs: number; size_in_bytes: number };
}>({
method: 'GET',
path: `/_metering/stats/${name}${FAILURE_STORE_SELECTOR}`,
});

return {
count: response._total?.num_docs || 0,
total_size_in_bytes: response._total?.size_in_bytes || 0,
};
} catch (e) {
const { statusCode } = parseError(e);
if (statusCode === 404) {
return undefined;
} else {
throw e;
}
}
}

export async function getFailureStoreCreationDate({
name,
esClient,
}: {
name: string;
esClient: ElasticsearchClient;
}): Promise<number | undefined> {
let age: number | undefined;
try {
const response = await esClient.indices.explainDataLifecycle({
index: `${name}${FAILURE_STORE_SELECTOR}`,
});
const indices = response.indices;
if (indices && typeof indices === 'object') {
const firstIndex = Object.values(indices)[0] as {
index_creation_date_millis?: EpochTime<UnitMillis>;
};
age = firstIndex?.index_creation_date_millis;
}
return age || undefined;
} catch (e) {
const { statusCode } = parseError(e);
if (statusCode === 404) {
return undefined;
} else {
throw e;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { z } from '@kbn/zod/v4';
import {
getClusterDefaultFailureStoreRetentionValue,
getFailureStoreStats,
} from '../../../../lib/streams/stream_crud';
} from '../../../../lib/streams/failure_store';
import { STREAMS_API_PRIVILEGES } from '../../../../../common/constants';
import { createServerRoute } from '../../../create_server_route';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { FAILURE_STORE_SELECTOR } from '../../../../../util/constants';
import { FAILURE_STORE_SELECTOR } from '@kbn/streams-plugin/common';

export const getFailureStoreIndexName = (streamName: string) => {
return streamName + FAILURE_STORE_SELECTOR;
Expand Down
Loading