From 99aaf6085d5be6176ff4273885097b0eaa918a21 Mon Sep 17 00:00:00 2001 From: Daniel Echlin Date: Fri, 25 Oct 2024 16:06:10 -0400 Subject: [PATCH 1/6] changes --- .../src/store/reducer.ts | 52 ++++++++++++++++--- 1 file changed, 45 insertions(+), 7 deletions(-) diff --git a/packages/compass-global-writes/src/store/reducer.ts b/packages/compass-global-writes/src/store/reducer.ts index 4255bb49072..0b51d971175 100644 --- a/packages/compass-global-writes/src/store/reducer.ts +++ b/packages/compass-global-writes/src/store/reducer.ts @@ -5,6 +5,7 @@ import { showConfirmation as showConfirmationModal, } from '@mongodb-js/compass-components'; import type { ManagedNamespace } from '../services/atlas-global-writes-service'; +import { GlobalWrites } from '../components'; export const POLLING_INTERVAL = 5000; @@ -30,6 +31,7 @@ enum GlobalWritesActionTypes { NamespaceShardKeyFetched = 'global-writes/NamespaceShardKeyFetched', ShardZonesFetched = 'global-writes/ShardZonesFetched', + ShardZonesFetchedError = 'global-writes/ShardZonesFetchedError', SubmittingForShardingStarted = 'global-writes/SubmittingForShardingStarted', SubmittingForShardingFinished = 'global-writes/SubmittingForShardingFinished', @@ -67,6 +69,10 @@ type ShardZonesFetchedAction = { shardZones: ShardZoneData[]; }; +type ShardZonesFetchedErrorAction = { + type: GlobalWritesActionTypes.ShardZonesFetchedError; +}; + type SubmittingForShardingStartedAction = { type: GlobalWritesActionTypes.SubmittingForShardingStarted; }; @@ -317,6 +323,18 @@ const reducer: Reducer = (state = initialState, action) => { }; } + if ( + isAction( + action, + GlobalWritesActionTypes.ShardZonesFetchedError + ) + ) { + return { + ...state, + shardZones: [], + }; + } + if ( isAction( action, @@ -742,18 +760,38 @@ export const fetchNamespaceShardKey = (): GlobalWritesThunkAction< export const fetchShardingZones = (): GlobalWritesThunkAction< Promise, - ShardZonesFetchedAction + ShardZonesFetchedAction | ShardZonesFetchedErrorAction > => { - return async (dispatch, getState, { atlasGlobalWritesService }) => { + return async ( + dispatch, + getState, + { atlasGlobalWritesService, connectionInfoRef } + ) => { const { shardZones } = getState(); if (shardZones.length > 0) { return; } - const shardingZones = await atlasGlobalWritesService.getShardingZones(); - dispatch({ - type: GlobalWritesActionTypes.ShardZonesFetched, - shardZones: shardingZones, - }); + try { + throw new Error('dan echlin fake error'); + const shardingZones = await atlasGlobalWritesService.getShardingZones(); + dispatch({ + type: GlobalWritesActionTypes.ShardZonesFetched, + shardZones: shardingZones, + }); + } catch (error) { + dispatch({ + type: GlobalWritesActionTypes.ShardZonesFetchedError, + }); + openToast( + `global-writes-fetch-sharding-zones-error-${connectionInfoRef.current.id}`, + { + title: `Failed to fetch sharding zones: ${(error as Error).message}`, + dismissible: true, + timeout: 5000, + variant: 'important', + } + ); + } }; }; From 67dfc1175774703b6de8cc70eaeded7793881903 Mon Sep 17 00:00:00 2001 From: Daniel Echlin Date: Tue, 29 Oct 2024 15:14:57 -0400 Subject: [PATCH 2/6] remove throw error --- packages/compass-global-writes/src/store/reducer.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/compass-global-writes/src/store/reducer.ts b/packages/compass-global-writes/src/store/reducer.ts index a0d2e39835b..5caccd842e7 100644 --- a/packages/compass-global-writes/src/store/reducer.ts +++ b/packages/compass-global-writes/src/store/reducer.ts @@ -811,7 +811,6 @@ export const fetchShardingZones = (): GlobalWritesThunkAction< return; } try { - throw new Error('dan echlin fake error'); const shardingZones = await atlasGlobalWritesService.getShardingZones(); dispatch({ type: GlobalWritesActionTypes.ShardZonesFetched, From 4236798b83478b5f351706489d9826fc6b8e94e0 Mon Sep 17 00:00:00 2001 From: Daniel Echlin Date: Wed, 30 Oct 2024 22:55:51 -0400 Subject: [PATCH 3/6] start tests --- .../compass-global-writes/src/store/index.spec.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/compass-global-writes/src/store/index.spec.ts b/packages/compass-global-writes/src/store/index.spec.ts index a32c7d032ff..b3d34fb3247 100644 --- a/packages/compass-global-writes/src/store/index.spec.ts +++ b/packages/compass-global-writes/src/store/index.spec.ts @@ -71,6 +71,7 @@ function createStore({ hasShardingError = () => false, hasShardKey = () => false, failsOnShardingRequest = () => false, + failsOnShardZoneRequest = () => false, authenticatedFetchStub, }: | { @@ -78,6 +79,7 @@ function createStore({ hasShardingError?: () => boolean; hasShardKey?: () => boolean | AtlasShardKey; failsOnShardingRequest?: () => boolean; + failsOnShardZoneRequest?: () => boolean; authenticatedFetchStub?: never; } | { @@ -85,11 +87,12 @@ function createStore({ hasShardingError?: never; hasShardKey?: () => boolean | ShardKey; failsOnShardingRequest?: never; + failsOnShardZoneRequest?: () => never; authenticatedFetchStub?: () => void; } = {}): GlobalWritesStore { const atlasService = { authenticatedFetch: (uri: string) => { - if (uri.includes(`/geoSharding`) && failsOnShardingRequest()) { + if (uri.endsWith('/geoSharding') && failsOnShardingRequest()) { return Promise.reject(new Error('Failed to shard')); } @@ -111,6 +114,13 @@ function createStore({ }); } + if ( + /geoSharding.*newFormLocationMapping/.test(uri) && + failsOnShardZoneRequest() + ) { + return Promise.reject(new Error('Failed to fetch shard zones')); + } + return createAuthFetchResponse({}); }, automationAgentRequest: (_meta: unknown, type: string) => ({ @@ -262,6 +272,7 @@ describe('GlobalWritesStore Store', function () { const store = createStore({ isNamespaceManaged: () => true, hasShardKey: Sinon.fake(() => mockShardKey), + failsOnShardZoneRequest: () => true, }); await waitFor(() => { expect(store.getState().status).to.equal('SHARDING'); From 8ca405ddc82f995fee67d1b9589a3edc29ce4b35 Mon Sep 17 00:00:00 2001 From: Daniel Echlin Date: Thu, 31 Oct 2024 10:24:51 -0400 Subject: [PATCH 4/6] tests --- .../compass-global-writes/src/store/index.spec.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/compass-global-writes/src/store/index.spec.ts b/packages/compass-global-writes/src/store/index.spec.ts index b3d34fb3247..a101526c4fa 100644 --- a/packages/compass-global-writes/src/store/index.spec.ts +++ b/packages/compass-global-writes/src/store/index.spec.ts @@ -320,6 +320,18 @@ describe('GlobalWritesStore Store', function () { }); }); + it('valid shard key -> failsOnShardZoneRequest', async function () { + const store = createStore({ + isNamespaceManaged: () => true, + hasShardKey: () => true, + failsOnShardZoneRequest: () => true, + }); + await waitFor(() => { + expect(store.getState().status).to.equal('SHARD_KEY_CORRECT'); + expect(store.getState().managedNamespace).to.equal(managedNamespace); + }); + }); + it('valid shard key -> not managed', async function () { // initial state === shard key correct const store = createStore({ From 1838e19ec31f70151c17eb23c3152c25ffae3343 Mon Sep 17 00:00:00 2001 From: djechlin-mongodb <132293929+djechlin-mongodb@users.noreply.github.com> Date: Tue, 5 Nov 2024 13:34:21 -0500 Subject: [PATCH 5/6] Update packages/compass-global-writes/src/store/reducer.ts Co-authored-by: Paula Stachova --- packages/compass-global-writes/src/store/reducer.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/compass-global-writes/src/store/reducer.ts b/packages/compass-global-writes/src/store/reducer.ts index 5caccd842e7..3ce3c951c1a 100644 --- a/packages/compass-global-writes/src/store/reducer.ts +++ b/packages/compass-global-writes/src/store/reducer.ts @@ -5,7 +5,6 @@ import { showConfirmation as showConfirmationModal, } from '@mongodb-js/compass-components'; import type { ManagedNamespace } from '../services/atlas-global-writes-service'; -import { GlobalWrites } from '../components'; export const POLLING_INTERVAL = 5000; From c291dbf60653312fb7d009cb2dcd07a13c2c695c Mon Sep 17 00:00:00 2001 From: Daniel Echlin Date: Thu, 7 Nov 2024 12:46:43 -0500 Subject: [PATCH 6/6] reformat --- packages/compass-global-writes/src/store/index.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/compass-global-writes/src/store/index.spec.ts b/packages/compass-global-writes/src/store/index.spec.ts index a9222a9d9ae..74a1ac056ec 100644 --- a/packages/compass-global-writes/src/store/index.spec.ts +++ b/packages/compass-global-writes/src/store/index.spec.ts @@ -323,7 +323,7 @@ describe('GlobalWritesStore Store', function () { expect(store.getState().managedNamespace).to.equal(managedNamespace); }); }); - + it('valid shard key -> failsOnShardZoneRequest', async function () { const store = createStore({ isNamespaceManaged: () => true,