Skip to content

Commit

Permalink
chore(indexes): add feature flag for rolling indexes COMPASS-8507 (#6509
Browse files Browse the repository at this point in the history
)

* chore(indexes): add feature flag for rolling indexes

* chore: remove custom docker registry
  • Loading branch information
gribnoysup authored Nov 19, 2024
1 parent 8512aa7 commit 732eff0
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 7 deletions.
7 changes: 4 additions & 3 deletions .evergreen/start-atlas-cloud-cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

RUN_ID="$(date +"%s")-$(git rev-parse --short HEAD)"
DELETE_AFTER="$(date -u -Iseconds -d '+2 hours' 2>/dev/null || date -u -Iseconds -v '+2H')"
DOCKER_REGISTRY="${DOCKER_REGISTRY:-docker.io}"

# This script helps to automatically provision Atlas cluster for running the e2e
# tests against. In CI this will always create a new cluster and delete it when
Expand Down Expand Up @@ -39,8 +40,8 @@ DELETE_AFTER="$(date -u -Iseconds -d '+2 hours' 2>/dev/null || date -u -Iseconds
# MCLI_ORG_ID Org ID
# MCLI_PROJECT_ID Project ID
#
# COMPASS_E2E_ATLAS_CLOUD_SANDBOX_USERNAME Cloud user you created
# COMPASS_E2E_ATLAS_CLOUD_SANDBOX_PASSWORD Cloud user password
# COMPASS_E2E_ATLAS_CLOUD_SANDBOX_USERNAME Cloud user you created
# COMPASS_E2E_ATLAS_CLOUD_SANDBOX_PASSWORD Cloud user password
#
# - Source the script followed by running the tests to make sure that some
# variables exported from this script are available for the test env:
Expand Down Expand Up @@ -68,7 +69,7 @@ function atlascli() {
-e MCLI_ORG_ID \
-e MCLI_PROJECT_ID \
-e MCLI_OPS_MANAGER_URL \
mongodb/atlas atlas $@
"$DOCKER_REGISTRY/mongodb/atlas" atlas $@
}

cleanup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
useConnectionInfo,
useConnectionSupports,
} from '@mongodb-js/compass-connections/provider';
import { usePreference } from 'compass-preferences-model/provider';

const createIndexModalFieldsStyles = css({
margin: `${spacing[4]}px 0 ${spacing[5]}px 0`,
Expand Down Expand Up @@ -43,10 +44,13 @@ function CreateIndexForm({
onRemoveFieldClick,
}: CreateIndexFormProps) {
const { id: connectionId } = useConnectionInfo();
const rollingIndexesFeatureEnabled = !!usePreference('enableRollingIndexes');
const supportsRollingIndexes = useConnectionSupports(
connectionId,
'rollingIndexCreation'
);
const showRollingIndexOption =
rollingIndexesFeatureEnabled && supportsRollingIndexes;
const schemaFields = useAutocompleteFields(namespace);
const schemaFieldNames = useMemo(() => {
return schemaFields
Expand Down Expand Up @@ -95,7 +99,7 @@ function CreateIndexForm({
<CollapsibleInput name="columnstoreProjection"></CollapsibleInput>
)}
<CheckboxInput name="sparse"></CheckboxInput>
{supportsRollingIndexes && (
{showRollingIndexOption && (
<CheckboxInput name="buildInRollingProcess"></CheckboxInput>
)}
</div>
Expand Down
5 changes: 5 additions & 0 deletions packages/compass-indexes/src/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ describe('CompassIndexesPlugin', function () {
instanceSize: 'VERY BIG',
metricsType: 'replicaSet',
} as any,
},
{
preferences: {
enableRollingIndexes: true,
},
}
);
}
Expand Down
2 changes: 2 additions & 0 deletions packages/compass-indexes/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { createLoggerLocator } from '@mongodb-js/compass-logging/provider';
import { telemetryLocator } from '@mongodb-js/compass-telemetry/provider';
import { IndexesTabTitle } from './plugin-title';
import { atlasServiceLocator } from '@mongodb-js/atlas-service/provider';
import { preferencesLocator } from 'compass-preferences-model/provider';

export const CompassIndexesHadronPlugin = registerHadronPlugin(
{
Expand All @@ -36,6 +37,7 @@ export const CompassIndexesHadronPlugin = registerHadronPlugin(
track: telemetryLocator,
collection: collectionModelLocator,
atlasService: atlasServiceLocator,
preferences: preferencesLocator,
}
);

Expand Down
2 changes: 2 additions & 0 deletions packages/compass-indexes/src/modules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import type { ConnectionInfoRef } from '@mongodb-js/compass-connections/provider
import type { IndexesDataServiceProps } from '../stores/store';
import type { Collection } from '@mongodb-js/compass-app-stores/provider';
import type { RollingIndexesService } from './rolling-indexes-service';
import type { PreferencesAccess } from 'compass-preferences-model';
const reducer = combineReducers({
// From instance.isWritable. Used to know if the create button should be
// enabled.
Expand Down Expand Up @@ -76,6 +77,7 @@ export type IndexesExtraArgs = {
regularIndexes: ReturnType<typeof setInterval> | null;
searchIndexes: ReturnType<typeof setInterval> | null;
};
preferences: PreferencesAccess;
};
export type IndexesThunkDispatch<A extends Action = AnyAction> = ThunkDispatch<
RootState,
Expand Down
17 changes: 14 additions & 3 deletions packages/compass-indexes/src/modules/regular-indexes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,13 @@ const fetchIndexes = (
return async (
dispatch,
getState,
{ dataService, collection, connectionInfoRef, rollingIndexesService }
{
dataService,
collection,
connectionInfoRef,
rollingIndexesService,
preferences,
}
) => {
const {
isReadonlyView,
Expand All @@ -387,16 +393,21 @@ const fetchIndexes = (
return;
}

const isRollingIndexesSupported = connectionSupports(
const clusterSupportsRollingIndexes = connectionSupports(
connectionInfoRef.current,
'rollingIndexCreation'
);
const rollingIndexesEnabled =
!!preferences.getPreferences().enableRollingIndexes;

const shouldFetchRollingIndexes =
clusterSupportsRollingIndexes && rollingIndexesEnabled;

try {
dispatch(fetchIndexesStarted(reason));
const promises = [
dataService.indexes(namespace),
isRollingIndexesSupported
shouldFetchRollingIndexes
? rollingIndexesService.listRollingIndexes(namespace)
: undefined,
] as [Promise<IndexDefinition[]>, Promise<AtlasIndexStats[]> | undefined];
Expand Down
4 changes: 4 additions & 0 deletions packages/compass-indexes/src/stores/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
} from '../modules/collection-stats';
import type { AtlasService } from '@mongodb-js/atlas-service/provider';
import { RollingIndexesService } from '../modules/rolling-indexes-service';
import type { PreferencesAccess } from 'compass-preferences-model';

export type IndexesDataServiceProps =
| 'indexes'
Expand Down Expand Up @@ -60,6 +61,7 @@ export type IndexesPluginServices = {
collection: Collection;
track: TrackFunction;
atlasService: AtlasService;
preferences: PreferencesAccess;
};

export type IndexesPluginOptions = {
Expand All @@ -85,6 +87,7 @@ export function activateIndexesPlugin(
dataService,
collection: collectionModel,
atlasService,
preferences,
}: IndexesPluginServices,
{ on, cleanup, addCleanup }: ActivateHelpers
) {
Expand Down Expand Up @@ -119,6 +122,7 @@ export function activateIndexesPlugin(
connectionInfoRef
),
pollingIntervalRef,
preferences,
})
)
);
Expand Down
7 changes: 7 additions & 0 deletions packages/compass-indexes/test/setup-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ export const setupStore = (
collection: createMockCollection(),
connectionInfoRef,
atlasService,
preferences: {
getPreferences() {
return {
enableRollingIndexes: true,
};
},
} as any,
...services,
},
createActivateHelpers()
Expand Down
8 changes: 8 additions & 0 deletions packages/compass-preferences-model/src/feature-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export type FeatureFlags = {
enableRenameCollectionModal: boolean;
enableQueryHistoryAutocomplete: boolean;
enableProxySupport: boolean;
enableRollingIndexes: boolean;
};

export const featureFlags: Required<{
Expand Down Expand Up @@ -84,4 +85,11 @@ export const featureFlags: Required<{
long: 'Allows users to specify proxy configuration for the entire Compass application.',
},
},

enableRollingIndexes: {
stage: 'development',
description: {
short: 'Enable creating indexes with the rolling build in Atlas Cloud',
},
},
};
1 change: 1 addition & 0 deletions packages/compass-web/sandbox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const App = () => {
atlasServiceBackendPreset: atlasServiceSandboxBackendVariant,
enableCreatingNewConnections: !isAtlas,
enableGlobalWrites: isAtlas,
enableRollingIndexes: isAtlas,
}}
onTrack={sandboxTelemetry.track}
onDebug={sandboxLogger.debug}
Expand Down

0 comments on commit 732eff0

Please sign in to comment.