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

[Reporting] adjust esquery refreshes settings #157323

Merged
merged 5 commits into from
May 17, 2023
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
4 changes: 0 additions & 4 deletions x-pack/plugins/reporting/public/management/report_listing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,6 @@ class ReportListingUi extends Component<Props, State> {
throw error;
}
}

// Since the contents of the table have changed, we must reset the pagination
// and re-fetch. Otherwise, the Nth page we are on could be empty of jobs.
this.setState(() => ({ page: 0 }), this.fetchJobs);
Copy link
Member Author

Choose a reason for hiding this comment

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

Without refresh after delete, this fetchJobs tends to predicable stale report artifacts for recently deleted reoprts in the list.

};

return (
Expand Down
24 changes: 12 additions & 12 deletions x-pack/plugins/reporting/server/lib/store/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,24 @@
* 2.0.
*/

import moment from 'moment';
import { IndexResponse, UpdateResponse } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { estypes } from '@elastic/elasticsearch';
import type { ElasticsearchClient, Logger } from '@kbn/core/server';
import moment from 'moment';
import type { IReport, Report, ReportDocument } from '.';
import { SavedReport } from '.';
import { statuses } from '..';
import type { ReportingCore } from '../..';
import { ILM_POLICY_NAME, REPORTING_SYSTEM_INDEX } from '../../../common/constants';
import type { JobStatus, ReportOutput, ReportSource } from '../../../common/types';
import type { ReportTaskParams } from '../tasks';
import type { IReport, Report, ReportDocument } from '.';
import { SavedReport } from '.';
import { IlmPolicyManager } from './ilm_policy_manager';
import { indexTimestamp } from './index_timestamp';
import { mapping } from './mapping';
import { MIGRATION_VERSION } from './report';

type UpdateResponse<T> = estypes.UpdateResponse<T>;
type IndexResponse = estypes.IndexResponse;

/*
* When an instance of Kibana claims a report job, this information tells us about that instance
*/
Expand Down Expand Up @@ -150,14 +153,11 @@ export class ReportingStore {
}
}

/*
* Called from addReport, which handles any errors
*/
private async indexReport(report: Report): Promise<IndexResponse> {
const doc = {
index: report._index!,
id: report._id,
refresh: true,
refresh: false,
body: {
...report.toReportSource(),
...sourceDoc({
Expand Down Expand Up @@ -289,7 +289,7 @@ export class ReportingStore {
index: report._index,
if_seq_no: report._seq_no,
if_primary_term: report._primary_term,
refresh: true,
refresh: false,
body: { doc },
});
} catch (err) {
Expand Down Expand Up @@ -328,7 +328,7 @@ export class ReportingStore {
index: report._index,
if_seq_no: report._seq_no,
if_primary_term: report._primary_term,
refresh: true,
refresh: false,
body: { doc },
});
} catch (err) {
Expand Down Expand Up @@ -363,7 +363,7 @@ export class ReportingStore {
index: report._index,
if_seq_no: report._seq_no,
if_primary_term: report._primary_term,
refresh: true,
refresh: false,
body: { doc },
});
} catch (err) {
Expand All @@ -390,7 +390,7 @@ export class ReportingStore {
index: report._index,
if_seq_no: report._seq_no,
if_primary_term: report._primary_term,
refresh: true,
refresh: false,
body: { doc },
});
} catch (err) {
Expand Down
13 changes: 7 additions & 6 deletions x-pack/plugins/reporting/server/routes/lib/jobs_query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
* 2.0.
*/

import type { TransportResult } from '@elastic/elasticsearch';
import { errors } from '@elastic/elasticsearch';
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { estypes, errors, TransportResult } from '@elastic/elasticsearch';
import type { ElasticsearchClient } from '@kbn/core/server';
import { i18n } from '@kbn/i18n';
import type { ReportingCore } from '../..';
Expand All @@ -23,7 +21,7 @@ import { getDocumentPayloadFactory } from './get_document_payload';
const defaultSize = 10;
const getUsername = (user: ReportingUser) => (user ? user.username : false);

function getSearchBody(body: estypes.SearchRequest['body']): estypes.SearchRequest['body'] {
function getSearchBody(body: estypes.SearchRequest): estypes.SearchRequest {
return {
_source: {
excludes: ['output.content', 'payload.headers'],
Expand Down Expand Up @@ -172,7 +170,7 @@ export function jobsQueryFactory(reportingCore: ReportingCore): JobsQueryFactory
},

async getError(id) {
const body: estypes.SearchRequest['body'] = {
const body: estypes.SearchRequest = {
_source: {
includes: ['output.content', 'status'],
},
Expand Down Expand Up @@ -209,7 +207,10 @@ export function jobsQueryFactory(reportingCore: ReportingCore): JobsQueryFactory
async delete(deleteIndex, id) {
try {
const { asInternalUser: elasticsearchClient } = await reportingCore.getEsClient();
const query = { id, index: deleteIndex, refresh: true };

// Using `wait_for` helps avoid users seeing recently-deleted reports temporarily flashing back in the
// job listing.
const query = { id, index: deleteIndex, refresh: 'wait_for' as const };

return await elasticsearchClient.delete(query, { meta: true });
} catch (error) {
Expand Down