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

feat(global-writes): setup feature support COMPASS-8273 #6271

Merged
merged 2 commits into from
Sep 23, 2024
Merged
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
185 changes: 123 additions & 62 deletions packages/compass-connections/src/hooks/use-connection-supports.spec.ts
Original file line number Diff line number Diff line change
@@ -23,6 +23,8 @@ const mockConnections: ConnectionInfo[] = [
metricsId: 'metricsId',
metricsType: 'host',
instanceSize: 'M10',
clusterType: 'REPLICASET',
clusterUniqueId: 'clusterUniqueId',
},
},
{
@@ -38,6 +40,8 @@ const mockConnections: ConnectionInfo[] = [
metricsId: 'metricsId',
metricsType: 'replicaSet',
instanceSize: 'M0',
clusterType: 'REPLICASET',
clusterUniqueId: 'clusterUniqueId',
},
},
{
@@ -53,6 +57,8 @@ const mockConnections: ConnectionInfo[] = [
metricsId: 'metricsId',
metricsType: 'serverless',
instanceSize: 'SERVERLESS_V2',
clusterType: 'REPLICASET',
clusterUniqueId: 'clusterUniqueId',
},
},
{
@@ -68,6 +74,8 @@ const mockConnections: ConnectionInfo[] = [
metricsId: 'metricsId',
metricsType: 'replicaSet',
instanceSize: 'M10',
clusterType: 'REPLICASET',
clusterUniqueId: 'clusterUniqueId',
},
},
{
@@ -83,79 +91,132 @@ const mockConnections: ConnectionInfo[] = [
metricsId: 'metricsId',
metricsType: 'cluster',
instanceSize: 'M10',
clusterType: 'SHARDED',
clusterUniqueId: 'clusterUniqueId',
},
},
{
id: 'dedicated-geo-sharded',
connectionOptions: {
connectionString: 'mongodb://foo',
},
atlasMetadata: {
orgId: 'orgId',
projectId: 'projectId',
clusterName: 'clusterName',
regionalBaseUrl: 'https://example.com',
metricsId: 'metricsId',
metricsType: 'cluster',
instanceSize: 'M30',
clusterType: 'GEOSHARDED',
clusterUniqueId: 'clusterUniqueId',
},
},
];

describe('useConnectionSupports', function () {
it('should return false if the connection does not exist', function () {
const { result } = renderHookWithConnections(
() => useConnectionSupports('does-not-exist', 'rollingIndexCreation'),
{
connections: mockConnections,
}
);
expect(result.current).to.equal(false);
});
context('rollingIndexCreation', function () {
it('should return false if the connection does not exist', function () {
const { result } = renderHookWithConnections(
() => useConnectionSupports('does-not-exist', 'rollingIndexCreation'),
{
connections: mockConnections,
}
);
expect(result.current).to.equal(false);
});

it('should return false if the connection has no atlasMetadata', function () {
const { result } = renderHookWithConnections(
() => useConnectionSupports('no-atlasMetadata', 'rollingIndexCreation'),
{
connections: mockConnections,
}
);
expect(result.current).to.equal(false);
});
it('should return false if the connection has no atlasMetadata', function () {
const { result } = renderHookWithConnections(
() => useConnectionSupports('no-atlasMetadata', 'rollingIndexCreation'),
{
connections: mockConnections,
}
);
expect(result.current).to.equal(false);
});

it('should return false for host cluster type', function () {
const { result } = renderHookWithConnections(
() => useConnectionSupports('host-cluster', 'rollingIndexCreation'),
{
connections: mockConnections,
}
);
expect(result.current).to.equal(false);
});
it('should return false for host cluster type', function () {
const { result } = renderHookWithConnections(
() => useConnectionSupports('host-cluster', 'rollingIndexCreation'),
{
connections: mockConnections,
}
);
expect(result.current).to.equal(false);
});

it('should return false for serverless cluster type', function () {
const { result } = renderHookWithConnections(
() => useConnectionSupports('serverless-cluster', 'rollingIndexCreation'),
{
connections: mockConnections,
}
);
expect(result.current).to.equal(false);
});
it('should return false for serverless cluster type', function () {
const { result } = renderHookWithConnections(
() =>
useConnectionSupports('serverless-cluster', 'rollingIndexCreation'),
{
connections: mockConnections,
}
);
expect(result.current).to.equal(false);
});

it('should return false for free/shared tier clusters', function () {
const { result } = renderHookWithConnections(
() => useConnectionSupports('free-cluster', 'rollingIndexCreation'),
{
connections: mockConnections,
}
);
expect(result.current).to.equal(false);
});
it('should return false for free/shared tier clusters', function () {
const { result } = renderHookWithConnections(
() => useConnectionSupports('free-cluster', 'rollingIndexCreation'),
{
connections: mockConnections,
}
);
expect(result.current).to.equal(false);
});

it('should return true for dedicated replicaSet clusters', function () {
const { result } = renderHookWithConnections(
() =>
useConnectionSupports('dedicated-replicaSet', 'rollingIndexCreation'),
{
connections: mockConnections,
}
);
expect(result.current).to.equal(true);
});

it('should return true for dedicated replicaSet clusters', function () {
const { result } = renderHookWithConnections(
() =>
useConnectionSupports('dedicated-replicaSet', 'rollingIndexCreation'),
{
connections: mockConnections,
}
);
expect(result.current).to.equal(true);
it('should return true for dedicated sharded clusters', function () {
const { result } = renderHookWithConnections(
() =>
useConnectionSupports('dedicated-sharded', 'rollingIndexCreation'),
{
connections: mockConnections,
}
);
expect(result.current).to.equal(true);
});
});
context('globalWrites', function () {
it('should return false if the connection does not exist', function () {
const { result } = renderHookWithConnections(
() => useConnectionSupports('does-not-exist', 'globalWrites'),
{
connections: mockConnections,
}
);
expect(result.current).to.equal(false);
});
it('should return false if the connection has no atlasMetadata', function () {
const { result } = renderHookWithConnections(
() => useConnectionSupports('no-atlasMetadata', 'globalWrites'),
{
connections: mockConnections,
}
);
expect(result.current).to.equal(false);
});

it('should return true for dedicated sharded clusters', function () {
const { result } = renderHookWithConnections(
() => useConnectionSupports('dedicated-sharded', 'rollingIndexCreation'),
{
connections: mockConnections,
}
);
expect(result.current).to.equal(true);
it('should return true if the cluster type is geosharded', function () {
const { result } = renderHookWithConnections(
() => useConnectionSupports('dedicated-geo-sharded', 'globalWrites'),
{
connections: mockConnections,
}
);
expect(result.current).to.equal(true);
});
});
});
18 changes: 16 additions & 2 deletions packages/compass-connections/src/hooks/use-connection-supports.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { useSelector } from '../stores/store-context';
import type { ConnectionState } from '../stores/connections-store-redux';

// only one for now
type ConnectionFeature = 'rollingIndexCreation';
type ConnectionFeature = 'rollingIndexCreation' | 'globalWrites';

function isFreeOrSharedTierCluster(instanceSize: string | undefined): boolean {
if (!instanceSize) {
@@ -25,6 +24,17 @@ function supportsRollingIndexCreation(connection: ConnectionState) {
(metricsType === 'cluster' || metricsType === 'replicaSet')
);
}

function supportsGlobalWrites(connection: ConnectionState) {
const atlasMetadata = connection.info?.atlasMetadata;

if (!atlasMetadata) {
return false;
}

return atlasMetadata.clusterType === 'GEOSHARDED';
}

export function useConnectionSupports(
connectionId: string,
connectionFeature: ConnectionFeature
@@ -40,6 +50,10 @@ export function useConnectionSupports(
return supportsRollingIndexCreation(connection);
}

if (connectionFeature === 'globalWrites') {
return supportsGlobalWrites(connection);
}

return false;
});
}
10 changes: 10 additions & 0 deletions packages/compass-preferences-model/src/preferences-schema.ts
Original file line number Diff line number Diff line change
@@ -87,6 +87,7 @@ export type InternalUserPreferences = {
telemetryAnonymousId?: string;
telemetryAtlasUserId?: string;
userCreatedAt: number;
enableGlobalWrites: boolean;
};

// UserPreferences contains all preferences stored to disk.
@@ -852,6 +853,15 @@ export const storedUserPreferencesProps: Required<{
type: 'boolean',
},

enableGlobalWrites: {
ui: false,
cli: false,
global: false,
description: null,
validator: z.boolean().default(false),
type: 'boolean',
},

...allFeatureFlagsProps,
};

1 change: 1 addition & 0 deletions packages/compass-web/sandbox/index.tsx
Original file line number Diff line number Diff line change
@@ -50,6 +50,7 @@ const App = () => {
maximumNumberOfActiveConnections: isAtlas ? 10 : undefined,
atlasServiceBackendPreset: atlasServiceSandboxBackendVariant,
enableCreatingNewConnections: !isAtlas,
enableGlobalWrites: isAtlas,
}}
onTrack={sandboxTelemetry.track}
onDebug={sandboxLogger.debug}
1 change: 1 addition & 0 deletions packages/compass-web/src/connection-storage.spec.ts
Original file line number Diff line number Diff line change
@@ -161,6 +161,7 @@ describe('buildConnectionInfoFromClusterDescription', function () {
metricsType: type === 'sharded' ? 'cluster' : type,
instanceSize: expectedInstanceSize,
regionalBaseUrl: 'https://example.com',
clusterType: clusterDescription.clusterType,
});
});
}
5 changes: 4 additions & 1 deletion packages/compass-web/src/connection-storage.tsx
Original file line number Diff line number Diff line change
@@ -25,12 +25,14 @@ type ReplicationSpec = {
regionConfigs: RegionConfig[];
};

type ClusterType = 'REPLICASET' | 'SHARDED' | 'GEOSHARDED';

type ClusterDescription = {
'@provider': string;
uniqueId: string;
groupId: string;
name: string;
clusterType: string;
clusterType: ClusterType;
srvAddress: string;
state: string;
deploymentItemName: string;
@@ -196,6 +198,7 @@ export function buildConnectionInfoFromClusterDescription(
regionalBaseUrl: description.dataProcessingRegion.regionalUrl,
...getMetricsIdAndType(description, deploymentItem),
instanceSize: getInstanceSize(description),
clusterType: description.clusterType,
},
};
}
1 change: 1 addition & 0 deletions packages/compass-web/src/entrypoint.tsx
Original file line number Diff line number Diff line change
@@ -274,6 +274,7 @@ const CompassWeb = ({
trackUsageStatistics: true,
enableShell: false,
enableCreatingNewConnections: false,
enableGlobalWrites: false,
...initialPreferences,
})
);
7 changes: 7 additions & 0 deletions packages/connection-info/src/connection-info.ts
Original file line number Diff line number Diff line change
@@ -49,6 +49,13 @@ export interface AtlasClusterMetadata {
* https://github.com/10gen/mms/blob/9e6bf2d81d4d85b5ac68a15bf471dcddc5922323/client/packages/types/nds/provider.ts#L60-L107
*/
instanceSize?: string;

/**
* Possible types of Atlas clusters.
* Copied from:
* https://github.com/10gen/mms/blob/9e6bf2d81d4d85b5ac68a15bf471dcddc5922323/client/packages/types/nds/clusterDescription.ts#L12-L16
*/
clusterType: 'REPLICASET' | 'SHARDED' | 'GEOSHARDED';
}

export interface ConnectionInfo {