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

remove elasticsearch package imports from reporting #107126

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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { i18n } from '@kbn/i18n';
import { SearchResponse } from 'elasticsearch';
import type { estypes } from '@elastic/elasticsearch';
import { IScopedClusterClient, IUiSettingsClient } from 'src/core/server';
import { IScopedSearchClient } from 'src/plugins/data/server';
import { Datatable } from 'src/plugins/expressions/server';
Expand Down Expand Up @@ -93,7 +93,7 @@ export class CsvGenerator {
};
const results = (
await this.clients.data.search(searchParams, { strategy: ES_SEARCH_STRATEGY }).toPromise()
).rawResponse as SearchResponse<unknown>;
).rawResponse as estypes.SearchResponse<unknown>;

return results;
}
Expand All @@ -107,7 +107,7 @@ export class CsvGenerator {
scroll_id: scrollId,
},
})
).body as SearchResponse<unknown>;
).body;
return results;
}

Expand Down Expand Up @@ -321,13 +321,13 @@ export class CsvGenerator {
if (this.cancellationToken.isCancelled()) {
break;
}
let results: SearchResponse<unknown> | undefined;
let results: estypes.SearchResponse<unknown> | undefined;
if (scrollId == null) {
// open a scroll cursor in Elasticsearch
results = await this.scan(index, searchSource, scrollSettings);
scrollId = results?._scroll_id;
if (results.hits?.total != null) {
totalRecords = results.hits.total;
totalRecords = results.hits.total as number;
this.logger.debug(`Total search results: ${totalRecords}`);
}
} else {
Expand Down
21 changes: 0 additions & 21 deletions x-pack/plugins/reporting/server/routes/generation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import Boom from '@hapi/boom';
import { errors as elasticsearchErrors } from 'elasticsearch';
import { kibanaResponseFactory } from 'src/core/server';
import { ReportingCore } from '../';
import { API_BASE_URL } from '../../common/constants';
Expand All @@ -16,8 +15,6 @@ import { registerGenerateFromJobParams } from './generate_from_jobparams';
import { registerGenerateCsvFromSavedObjectImmediate } from './csv_searchsource_immediate';
import { HandlerFunction } from './types';

const esErrors = elasticsearchErrors as Record<string, any>;

const getDownloadBaseUrl = (reporting: ReportingCore) => {
const config = reporting.getConfig();
return config.kbnConfig.get('server', 'basePath') + `${API_BASE_URL}/jobs/download`;
Expand Down Expand Up @@ -77,24 +74,6 @@ export function registerJobGenerationRoutes(reporting: ReportingCore, logger: Lo
});
}

if (err instanceof esErrors['401']) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reporting doesn't have access to the legacy client errors, so this code is dead and I removed it. If you considered this logic is necessary, please update it in a follow-up.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this code was not doing anything special but adding a custom message on top of an error code. These error codes seem appropriate: I'm not seeing unexpected transformation of these codes to a custom message. I don't think this logic was necessary.

return res.unauthorized({
body: `Sorry, you aren't authenticated`,
});
}

if (err instanceof esErrors['403']) {
return res.forbidden({
body: `Sorry, you are not authorized`,
});
}

if (err instanceof esErrors['404']) {
return res.notFound({
body: err.message,
});
}

// unknown error, can't convert to 4xx
throw err;
}
Expand Down