Skip to content

Commit

Permalink
[Reporting/storage] set refresh=wait_for in indexing and update calls (
Browse files Browse the repository at this point in the history
…elastic#178783)

## Summary

Addresses
elastic#176022 (comment)

This is done in a standalone PR to minimize changes needed to convert
Reporting storage to use a Data Stream. Useful for
elastic#176022.
  • Loading branch information
tsullivan authored and saikatsarkar056 committed Mar 20, 2024
1 parent 0960656 commit 3608e4d
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions x-pack/plugins/reporting/server/lib/store/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const sourceDoc = (doc: Partial<ReportSource>): Partial<ReportSource> => {
};
};

const esDoc = (
const esDocForUpdate = (
report: SavedReport,
doc: Partial<ReportSource>
): Parameters<ElasticsearchClient['update']>[0] => {
Expand All @@ -82,7 +82,7 @@ const esDoc = (
index: report._index,
if_seq_no: report._seq_no,
if_primary_term: report._primary_term,
refresh: false,
refresh: 'wait_for' as estypes.Refresh,
body: { doc },
};
};
Expand Down Expand Up @@ -178,7 +178,7 @@ export class ReportingStore {
const doc = {
index: report._index!,
id: report._id,
refresh: false,
refresh: 'wait_for' as estypes.Refresh,
body: {
...report.toReportSource(),
...sourceDoc({
Expand Down Expand Up @@ -309,7 +309,7 @@ export class ReportingStore {
let body: UpdateResponse<ReportDocument>;
try {
const client = await this.getClient();
body = await client.update<unknown, unknown, ReportDocument>(esDoc(report, doc));
body = await client.update<unknown, unknown, ReportDocument>(esDocForUpdate(report, doc));
} catch (err) {
this.logError(`Error in updating status to processing! Report: ${jobDebugMessage(report)}`, err, report); // prettier-ignore
throw err;
Expand Down Expand Up @@ -341,7 +341,7 @@ export class ReportingStore {
let body: UpdateResponse<ReportDocument>;
try {
const client = await this.getClient();
body = await client.update<unknown, unknown, ReportDocument>(esDoc(report, doc));
body = await client.update<unknown, unknown, ReportDocument>(esDocForUpdate(report, doc));
} catch (err) {
this.logError(`Error in updating status to failed! Report: ${jobDebugMessage(report)}`, err, report); // prettier-ignore
throw err;
Expand All @@ -363,7 +363,7 @@ export class ReportingStore {
let body: UpdateResponse<ReportDocument>;
try {
const client = await this.getClient();
body = await client.update<unknown, unknown, ReportDocument>(esDoc(report, doc));
body = await client.update<unknown, unknown, ReportDocument>(esDocForUpdate(report, doc));
} catch (err) {
this.logError(`Error in updating status to failed! Report: ${jobDebugMessage(report)}`, err, report); // prettier-ignore
throw err;
Expand Down Expand Up @@ -391,7 +391,7 @@ export class ReportingStore {
let body: UpdateResponse<ReportDocument>;
try {
const client = await this.getClient();
body = await client.update<unknown, unknown, ReportDocument>(esDoc(report, doc));
body = await client.update<unknown, unknown, ReportDocument>(esDocForUpdate(report, doc));
} catch (err) {
this.logError(`Error in updating status to complete! Report: ${jobDebugMessage(report)}`, err, report); // prettier-ignore
throw err;
Expand Down

0 comments on commit 3608e4d

Please sign in to comment.