Skip to content

Commit

Permalink
[ML] Switching to new es client (#74965)
Browse files Browse the repository at this point in the history
* [ML] Switching to new es client

* further conversions

* fixing tests

* updating responses

* test commit

* refactoring shared services to removed context parameter

* removing last scoped clients

* removing ml js client

* udating file data viz errors

* fixing jest tests

* fixing types after merge with master

* error response changes

* adding default sizes to some requests

* adding custom error types for license checks

* tidying up shared function checks

* removing test data

* removing need for DummyKibanaRequest

* updating comment

* fixing functional api tests

* removing comments

* fixing types after master merge

* throw error rather than return it

* removing placeholder error

* changes based on review comments

* fixing types after merge with master

* fixing missing return

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
jgowdyelastic and elasticmachine authored Sep 2, 2020
1 parent 946e9f0 commit 4762cf5
Show file tree
Hide file tree
Showing 106 changed files with 1,573 additions and 2,568 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,9 @@ export function registerTransactionDurationAnomalyAlertType({
return;
}
const alertParams = params as TypeOf<typeof paramsSchema>;
const mlClient = services.getLegacyScopedClusterClient(ml.mlClient);
const request = { params: 'DummyKibanaRequest' } as KibanaRequest;
const { mlAnomalySearch } = ml.mlSystemProvider(mlClient, request);
const anomalyDetectors = ml.anomalyDetectorsProvider(mlClient, request);
const request = {} as KibanaRequest;
const { mlAnomalySearch } = ml.mlSystemProvider(request);
const anomalyDetectors = ml.anomalyDetectorsProvider(request);

const mlJobIds = await getMLJobIds(
anomalyDetectors,
Expand Down
11 changes: 4 additions & 7 deletions x-pack/plugins/apm/server/lib/helpers/setup_request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,10 @@ function getMlSetup(
if (!ml) {
return;
}
const mlClient = ml.mlClient.asScoped(request);
const mlSystem = ml.mlSystemProvider(mlClient, request);

return {
mlClient,
mlSystem,
modules: ml.modulesProvider(mlClient, request, savedObjectsClient),
anomalyDetectors: ml.anomalyDetectorsProvider(mlClient, request),
mlAnomalySearch: mlSystem.mlAnomalySearch,
mlSystem: ml.mlSystemProvider(request),
anomalyDetectors: ml.anomalyDetectorsProvider(request),
modules: ml.modulesProvider(request, savedObjectsClient),
};
}
5 changes: 2 additions & 3 deletions x-pack/plugins/infra/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,8 @@ export class InfraServerPlugin {
core.http.registerRouteHandlerContext(
'infra',
(context, request): InfraRequestHandlerContext => {
const mlSystem = context.ml && plugins.ml?.mlSystemProvider(context.ml?.mlClient, request);
const mlAnomalyDetectors =
context.ml && plugins.ml?.anomalyDetectorsProvider(context.ml?.mlClient, request);
const mlSystem = plugins.ml?.mlSystemProvider(request);
const mlAnomalyDetectors = plugins.ml?.anomalyDetectorsProvider(request);
const spaceId = plugins.spaces?.spacesService.getSpaceId(request) || 'default';

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ function title(statuses: Statuses) {
}
}

function ImportError(error: any, key: number) {
const ImportError: FC<{ error: any }> = ({ error }) => {
const errorObj = toString(error);
return (
<React.Fragment>
<p key={key}>{errorObj.msg}</p>
<>
<p>{errorObj.msg}</p>

{errorObj.more !== undefined && (
<EuiAccordion
Expand All @@ -113,9 +113,9 @@ function ImportError(error: any, key: number) {
{errorObj.more}
</EuiAccordion>
)}
</React.Fragment>
</>
);
}
};

function toString(error: any): ImportError {
if (typeof error === 'string') {
Expand All @@ -127,11 +127,11 @@ function toString(error: any): ImportError {
return { msg: error.msg };
} else if (error.error !== undefined) {
if (typeof error.error === 'object') {
if (error.error.msg !== undefined) {
if (error.error.reason !== undefined) {
// this will catch a bulk ingest failure
const errorObj: ImportError = { msg: error.error.msg };
if (error.error.body !== undefined) {
errorObj.more = error.error.response;
const errorObj: ImportError = { msg: error.error.reason };
if (error.error.root_cause !== undefined) {
errorObj.more = JSON.stringify(error.error.root_cause);
}
return errorObj;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ export class ChartLoader {
splitFieldName,
splitFieldValue
);
if (resp.error !== undefined) {
throw resp.error;
}

return resp.results;
}
return {};
Expand Down Expand Up @@ -105,9 +103,7 @@ export class ChartLoader {
aggFieldPairNames,
splitFieldName
);
if (resp.error !== undefined) {
throw resp.error;
}

return resp.results;
}
return {};
Expand Down
60 changes: 0 additions & 60 deletions x-pack/plugins/ml/server/client/elasticsearch_ml.test.ts

This file was deleted.

Loading

0 comments on commit 4762cf5

Please sign in to comment.