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

[7.x] remove elasticsearch package imports from reporting (#107126) #107297

Merged
merged 2 commits into from
Jul 31, 2021
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 @@ -17,8 +16,6 @@ import { registerLegacy } from './legacy';
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 @@ -78,24 +75,6 @@ export function registerJobGenerationRoutes(reporting: ReportingCore, logger: Lo
});
}

if (err instanceof esErrors['401']) {
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