Skip to content

Commit

Permalink
[uiSettings] use refresh: false instead of default `refresh: 'wait_…
Browse files Browse the repository at this point in the history
…for'` in create and update (elastic#160278)

## Summary

Close elastic#159662

See explanation [here](elastic#159662)
  • Loading branch information
Dosant authored Jul 25, 2023
1 parent 95702ac commit c76b185
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,28 @@ describe('ui settings', () => {
await uiSettings.setMany({ one: 'value' });

expect(savedObjectsClient.update).toHaveBeenCalledTimes(1);
expect(savedObjectsClient.update).toHaveBeenCalledWith(TYPE, ID, { one: 'value' });
expect(savedObjectsClient.update).toHaveBeenCalledWith(
TYPE,
ID,
{ one: 'value' },
{ refresh: false }
);
});

it('updates several values in one operation', async () => {
const { uiSettings, savedObjectsClient } = setup();
await uiSettings.setMany({ one: 'value', another: 'val' });

expect(savedObjectsClient.update).toHaveBeenCalledTimes(1);
expect(savedObjectsClient.update).toHaveBeenCalledWith(TYPE, ID, {
one: 'value',
another: 'val',
});
expect(savedObjectsClient.update).toHaveBeenCalledWith(
TYPE,
ID,
{
one: 'value',
another: 'val',
},
{ refresh: false }
);
});

it('automatically creates the savedConfig if it is missing', async () => {
Expand Down Expand Up @@ -159,9 +169,14 @@ describe('ui settings', () => {
await uiSettings.set('one', 'value');

expect(savedObjectsClient.update).toHaveBeenCalledTimes(1);
expect(savedObjectsClient.update).toHaveBeenCalledWith(TYPE, ID, {
one: 'value',
});
expect(savedObjectsClient.update).toHaveBeenCalledWith(
TYPE,
ID,
{
one: 'value',
},
{ refresh: false }
);
});

it('validates value if a schema presents', async () => {
Expand Down Expand Up @@ -202,7 +217,12 @@ describe('ui settings', () => {
await uiSettings.remove('one');

expect(savedObjectsClient.update).toHaveBeenCalledTimes(1);
expect(savedObjectsClient.update).toHaveBeenCalledWith(TYPE, ID, { one: null });
expect(savedObjectsClient.update).toHaveBeenCalledWith(
TYPE,
ID,
{ one: null },
{ refresh: false }
);
});

it('does not fail validation', async () => {
Expand Down Expand Up @@ -246,19 +266,29 @@ describe('ui settings', () => {
await uiSettings.removeMany(['one']);

expect(savedObjectsClient.update).toHaveBeenCalledTimes(1);
expect(savedObjectsClient.update).toHaveBeenCalledWith(TYPE, ID, { one: null });
expect(savedObjectsClient.update).toHaveBeenCalledWith(
TYPE,
ID,
{ one: null },
{ refresh: false }
);
});

it('updates several values in one operation', async () => {
const { uiSettings, savedObjectsClient } = setup();
await uiSettings.removeMany(['one', 'two', 'three']);

expect(savedObjectsClient.update).toHaveBeenCalledTimes(1);
expect(savedObjectsClient.update).toHaveBeenCalledWith(TYPE, ID, {
one: null,
two: null,
three: null,
});
expect(savedObjectsClient.update).toHaveBeenCalledWith(
TYPE,
ID,
{
one: null,
two: null,
three: null,
},
{ refresh: false }
);
});

it('does not fail validation', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export abstract class UiSettingsClientCommon extends BaseUiSettingsClient {
autoCreateOrUpgradeIfMissing?: boolean;
}) {
try {
await this.savedObjectsClient.update(this.type, this.id, changes);
await this.savedObjectsClient.update(this.type, this.id, changes, { refresh: false });
} catch (error) {
if (!SavedObjectsErrorHelpers.isNotFoundError(error) || !autoCreateOrUpgradeIfMissing) {
throw error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,14 @@ describe('ui settings global client', () => {
const { uiSettingsClient, savedObjectsClient } = setup();
await uiSettingsClient.set('settingA', 'cde');
expect(savedObjectsClient.update).toHaveBeenCalledTimes(1);
expect(savedObjectsClient.update).toHaveBeenCalledWith(TYPE, ID, {
settingA: 'cde',
});
expect(savedObjectsClient.update).toHaveBeenCalledWith(
TYPE,
ID,
{
settingA: 'cde',
},
{ refresh: false }
);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ describe('uiSettings/createOrUpgradeSavedConfig', function () {
},
{
id: version,
refresh: false,
}
);
});
Expand Down Expand Up @@ -110,6 +111,7 @@ describe('uiSettings/createOrUpgradeSavedConfig', function () {
},
{
id: version,
refresh: false,
}
);
});
Expand Down Expand Up @@ -140,7 +142,7 @@ describe('uiSettings/createOrUpgradeSavedConfig', function () {
defaultIndex: 'another-index',
isDefaultIndexMigrated: true,
},
{ id: version }
{ id: version, refresh: false }
);
});

Expand Down Expand Up @@ -282,6 +284,7 @@ describe('uiSettings/createOrUpgradeSavedConfig', function () {
},
{
id: version,
refresh: false,
}
);
});
Expand Down Expand Up @@ -313,6 +316,7 @@ describe('uiSettings/createOrUpgradeSavedConfig', function () {
},
{
id: version,
refresh: false,
}
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export async function createOrUpgradeSavedConfig(

try {
// create the new SavedConfig
await savedObjectsClient.create(type, attributes, { id: version });
await savedObjectsClient.create(type, attributes, { id: version, refresh: false });
} catch (error) {
if (handleWriteErrors) {
if (SavedObjectsErrorHelpers.isConflictError(error)) {
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-es-archiver/src/actions/empty_kibana_index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export async function emptyKibanaIndexAction({

await cleanSavedObjectIndices({ client, stats, log });
await migrateSavedObjectIndices(kbnClient);
await client.indices.refresh({ index: ALL_SAVED_OBJECT_INDICES });
ALL_SAVED_OBJECT_INDICES.forEach((indexPattern) => stats.createdIndex(indexPattern));
return stats.toJSON();
}
2 changes: 2 additions & 0 deletions src/core/server/integration_tests/ui_settings/doc_missing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export const docMissingSuite = (savedObjectsIndex: string) => () => {
beforeEach(async () => {
const { esClient } = getServices();

await esClient.indices.refresh({ index: savedObjectsIndex });

// delete all docs from kibana index to ensure savedConfig is not found
await esClient.deleteByQuery({
index: savedObjectsIndex,
Expand Down

0 comments on commit c76b185

Please sign in to comment.