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

Update dependency @elastic/elasticsearch to ^8.16.0 (main) #200275

Merged
merged 10 commits into from
Dec 13, 2024
Merged
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
"@elastic/datemath": "5.0.3",
"@elastic/ebt": "^1.1.1",
"@elastic/ecs": "^8.11.1",
"@elastic/elasticsearch": "^8.15.2",
"@elastic/elasticsearch": "^8.16.0",
"@elastic/ems-client": "8.5.3",
"@elastic/eui": "98.1.0-borealis.0",
"@elastic/eui-theme-borealis": "0.0.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
createGenericNotFoundErrorPayload,
} from '../../test_helpers/repository.test.common';
import { PointInTimeFinder } from '../point_in_time_finder';
import { OpenPointInTimeResponse } from '@elastic/elasticsearch/lib/api/types';

describe('SavedObjectsRepository', () => {
let client: ReturnType<typeof elasticsearchClientMock.createElasticsearchClient>;
Expand Down Expand Up @@ -81,7 +82,7 @@ describe('SavedObjectsRepository', () => {
describe('#openPointInTimeForType', () => {
const type = 'index-pattern';

const generateResults = (id?: string) => ({ id: id || 'id' });
const generateResults = (id?: string) => ({ id: id || 'id' } as OpenPointInTimeResponse);
const successResponse = async (type: string, options?: SavedObjectsOpenPointInTimeOptions) => {
client.openPointInTime.mockResponseOnce(generateResults());
const result = await repository.openPointInTimeForType(type, options);
Expand Down Expand Up @@ -136,7 +137,7 @@ describe('SavedObjectsRepository', () => {
it(`throws when ES is unable to find the index`, async () => {
client.openPointInTime.mockResolvedValueOnce(
elasticsearchClientMock.createSuccessTransportRequestPromise(
{ id: 'error' },
{ id: 'error' } as OpenPointInTimeResponse,
{ statusCode: 404 }
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import {
import { savedObjectsExtensionsMock } from '../mocks/saved_objects_extensions.mock';
import { arrayMapsAreEqual } from '@kbn/core-saved-objects-utils-server';
import { mockAuthenticatedUser } from '@kbn/core-security-common/mocks';
import { OpenPointInTimeResponse } from '@elastic/elasticsearch/lib/api/types';

describe('SavedObjectsRepository Security Extension', () => {
let client: ReturnType<typeof elasticsearchClientMock.createElasticsearchClient>;
Expand Down Expand Up @@ -676,7 +677,7 @@ describe('SavedObjectsRepository Security Extension', () => {
test(`returns result when partially authorized`, async () => {
setupAuthorizeFunc(mockSecurityExt.authorizeOpenPointInTime, 'partially_authorized');

client.openPointInTime.mockResponseOnce({ id });
client.openPointInTime.mockResponseOnce({ id } as OpenPointInTimeResponse);
const result = await repository.openPointInTimeForType(type);

expect(mockSecurityExt.authorizeOpenPointInTime).toHaveBeenCalledTimes(1);
Expand All @@ -687,7 +688,7 @@ describe('SavedObjectsRepository Security Extension', () => {
test(`returns result when fully authorized`, async () => {
setupAuthorizeFunc(mockSecurityExt.authorizeOpenPointInTime, 'fully_authorized');

client.openPointInTime.mockResponseOnce({ id });
client.openPointInTime.mockResponseOnce({ id } as OpenPointInTimeResponse);
const result = await repository.openPointInTimeForType(type);

expect(mockSecurityExt.authorizeOpenPointInTime).toHaveBeenCalledTimes(1);
Expand All @@ -702,7 +703,7 @@ describe('SavedObjectsRepository Security Extension', () => {

test(`calls authorizeOpenPointInTime with correct parameters`, async () => {
setupAuthorizeFunc(mockSecurityExt.authorizeOpenPointInTime, 'fully_authorized');
client.openPointInTime.mockResponseOnce({ id });
client.openPointInTime.mockResponseOnce({ id } as OpenPointInTimeResponse);
const namespaces = [namespace, 'x', 'y', 'z'];
await repository.openPointInTimeForType(type, { namespaces });
expect(mockSecurityExt.authorizeOpenPointInTime).toHaveBeenCalledTimes(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { createSearchSourceMock } from '@kbn/data-plugin/common/search/search_so
import { createSearchRequestHandlerContext } from '@kbn/data-plugin/server/search/mocks';
import type { SearchCursorSettings } from './search_cursor';
import { SearchCursorPit } from './search_cursor_pit';
import { OpenPointInTimeResponse } from '@elastic/elasticsearch/lib/api/types';

class TestSearchCursorPit extends SearchCursorPit {
constructor(...args: ConstructorParameters<typeof SearchCursorPit>) {
Expand Down Expand Up @@ -69,7 +70,7 @@ describe('CSV Export Search Cursor', () => {

openPointInTimeSpy = jest
.spyOn(es.asCurrentUser, 'openPointInTime')
.mockResolvedValue({ id: 'somewhat-pit-id' });
.mockResolvedValue({ id: 'somewhat-pit-id' } as OpenPointInTimeResponse);

logger = loggingSystemMock.createLogger();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { createSearchSourceMock } from '@kbn/data-plugin/common/search/search_so
import { createSearchRequestHandlerContext } from '@kbn/data-plugin/server/search/mocks';
import type { SearchCursorSettings } from './search_cursor';
import { SearchCursorScroll } from './search_cursor_scroll';
import type { OpenPointInTimeResponse } from '@elastic/elasticsearch/lib/api/types';

class TestSearchCursorScroll extends SearchCursorScroll {
constructor(...args: ConstructorParameters<typeof SearchCursorScroll>) {
Expand Down Expand Up @@ -47,7 +48,9 @@ describe('CSV Export Search Cursor', () => {

es = elasticsearchServiceMock.createScopedClusterClient();
data = createSearchRequestHandlerContext();
jest.spyOn(es.asCurrentUser, 'openPointInTime').mockResolvedValue({ id: 'simply-scroll-id' });
jest
.spyOn(es.asCurrentUser, 'openPointInTime')
.mockResolvedValue({ id: 'simply-scroll-id' } as OpenPointInTimeResponse);

logger = loggingSystemMock.createLogger();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { IncomingHttpHeaders } from 'http';
import type { IScopedClusterClient, Logger } from '@kbn/core/server';
import { catchError, tap } from 'rxjs';
import type { DiagnosticResult } from '@elastic/transport';
import { SqlQueryResponse } from '@elastic/elasticsearch/lib/api/types';
import { SqlQueryResponse, type SqlQuerySqlFormat } from '@elastic/elasticsearch/lib/api/types';
import { getKbnServerError } from '@kbn/kibana-utils-plugin/server';
import { getKbnSearchError } from '../../report_search_error';
import type { ISearchStrategy, SearchStrategyDependencies } from '../../types';
Expand Down Expand Up @@ -61,9 +61,9 @@ export const sqlSearchStrategyProvider = (
} else {
({ headers, body, meta } = await client.sql.query(
{
format: params.format ?? 'json',
...getDefaultAsyncSubmitParams(searchConfig, options),
...params,
format: (params.format ?? 'json') as SqlQuerySqlFormat,
},
{ ...options.transport, signal: options.abortSignal, meta: true }
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,8 @@ export const registerFieldPreviewRoute = ({ router }: RouteDependencies): void =
};

try {
// client types need to be update to support this request format
// client types need to be updated to support this request format
// when it does, supply response types
// @ts-expect-error
const { result } = await client.asCurrentUser.scriptsPainlessExecute(body);

return res.ok({ body: { values: result } });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ export async function getClusterStats(esClient: ElasticsearchClient) {
return await esClient.cluster.stats(
{
timeout: CLUSTER_STAT_TIMEOUT,

// @ts-expect-error
include_remotes: true,
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface AnalyticsManagementItems {
export interface TrainedModelsManagementItems {
id: string;
description: string;
state: estypes.MlDeploymentState | '';
state: estypes.MlDeploymentAssignmentState | '';
type: Array<string | undefined>;
spaces: string[];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,10 @@ export abstract class InferenceBase<TInferResponse> {
};
}

// @ts-expect-error error does not exist in type
protected getDocFromResponse({ doc, error }: estypes.IngestSimulatePipelineSimulation) {
if (doc === undefined) {
if (error) {
// @ts-expect-error Error is now typed in estypes. However, I doubt that it doesn't get the HTTP wrapper expected.
this.setFinishedWithErrors(error);
throw Error(error.reason);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import * as t from 'io-ts';
import {
InferenceInferenceEndpointInfo,
MlDeploymentAllocationState,
MlDeploymentState,
MlDeploymentAssignmentState,
} from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import moment from 'moment';
import { createObservabilityAIAssistantServerRoute } from '../create_observability_ai_assistant_server_route';
Expand All @@ -34,7 +34,7 @@ const getKnowledgeBaseStatus = createObservabilityAIAssistantServerRoute({
enabled: boolean;
endpoint?: Partial<InferenceInferenceEndpointInfo>;
model_stats?: {
deployment_state: MlDeploymentState | undefined;
deployment_state: MlDeploymentAssignmentState | undefined;
allocation_state: MlDeploymentAllocationState | undefined;
};
}> => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ const GetDataStreamResponse: IndicesGetDataStreamResponse = {
template: 'ignored',
next_generation_managed_by: 'Index Lifecycle Management',
prefer_ilm: false,
rollover_on_write: false,
},
],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const GetDataStreamResponse: IndicesGetDataStreamResponse = {
template: 'ignored',
next_generation_managed_by: 'Data stream lifecycle',
prefer_ilm: false,
rollover_on_write: false,
},
],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ export const GetDataStreamsResponse: estypes.IndicesGetDataStreamResponse = {
template: '',
hidden: true,
prefer_ilm: false,
rollover_on_write: true,
next_generation_managed_by: 'Index Lifecycle Management',
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export interface DataStreamIndex {
name: string;
uuid: string;
preferILM: boolean;
managedBy: string;
managedBy?: string;
}

export interface DataRetention {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,28 +87,30 @@ export const isDataStreamFullyManagedByILM = (dataStream?: DataStream | null) =>
return (
dataStream?.nextGenerationManagedBy?.toLowerCase() === 'index lifecycle management' &&
dataStream?.indices?.every(
(index) => index.managedBy.toLowerCase() === 'index lifecycle management'
(index) => index.managedBy?.toLowerCase() === 'index lifecycle management'
)
);
};

export const isDataStreamFullyManagedByDSL = (dataStream?: DataStream | null) => {
return (
dataStream?.nextGenerationManagedBy?.toLowerCase() === 'data stream lifecycle' &&
dataStream?.indices?.every((index) => index.managedBy.toLowerCase() === 'data stream lifecycle')
dataStream?.indices?.every(
(index) => index.managedBy?.toLowerCase() === 'data stream lifecycle'
)
);
};

export const isDSLWithILMIndices = (dataStream?: DataStream | null) => {
if (dataStream?.nextGenerationManagedBy?.toLowerCase() === 'data stream lifecycle') {
const ilmIndices = dataStream?.indices?.filter(
(index) => index.managedBy.toLowerCase() === 'index lifecycle management'
(index) => index.managedBy?.toLowerCase() === 'index lifecycle management'
);
const dslIndices = dataStream?.indices?.filter(
(index) => index.managedBy.toLowerCase() === 'data stream lifecycle'
(index) => index.managedBy?.toLowerCase() === 'data stream lifecycle'
);

// When there arent any ILM indices, there's no need to show anything.
// When there aren't any ILM indices, there's no need to show anything.
if (!ilmIndices?.length) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ export function deserializeDataStream(dataStreamFromEs: EnhancedDataStreamFromEs
({
index_name: indexName,
index_uuid: indexUuid,
prefer_ilm: preferILM,
prefer_ilm: preferILM = false,
managed_by: managedBy,
}: {
index_name: string;
index_uuid: string;
prefer_ilm: boolean;
managed_by: string;
prefer_ilm?: boolean;
managed_by?: string;
}) => ({
name: indexName,
uuid: indexUuid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class DataStreamService {
try {
const { data_streams: dataStreamsInfo } = await esClient.indices.getDataStream({
name: datasetName,
// @ts-expect-error
verbose: true,
});

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

import type { ElasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import type { SearchResponse } from '@elastic/elasticsearch/lib/api/types';
import type { OpenPointInTimeResponse, SearchResponse } from '@elastic/elasticsearch/lib/api/types';
import { v4 as uuidV4 } from 'uuid';
import { BaseDataGenerator } from '../../../common/endpoint/data_generators/base_data_generator';

Expand Down Expand Up @@ -45,14 +45,14 @@ export const applyEsClientSearchMock = <TDocument = unknown>({
const pitResponse = { id: `mock:pit:${index}:${uuidV4()}` };
openedPitIds.add(pitResponse.id);

return pitResponse;
return pitResponse as OpenPointInTimeResponse;
}

if (priorOpenPointInTimeImplementation) {
return priorOpenPointInTimeImplementation(...args);
}

return { id: 'mock' };
return { id: 'mock' } as OpenPointInTimeResponse;
});

esClientMock.closePointInTime.mockImplementation(async (...args) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export const applyIngestProcessorToDoc = async (

const firstDoc = res.docs?.[0];

// @ts-expect-error error is not in the types
const error = firstDoc?.error;
if (error) {
log.error('Full painless error below: ');
Expand Down
Loading
Loading