Skip to content

Commit 6efc335

Browse files
authored
chore(web): integrate connection storage with new connection info endpoint CLOUDP-302132 (#6847)
* chore(web): integrate connection storage with new connection info endpoint * chore(web): PAUSED is not connectable * chore(web): async instead of then
1 parent cfd21fe commit 6efc335

File tree

11 files changed

+260
-74
lines changed

11 files changed

+260
-74
lines changed

packages/compass-connections/src/hooks/use-connection-supports.spec.ts

+37-7
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,17 @@ const mockConnections: ConnectionInfo[] = [
1919
orgId: 'orgId',
2020
projectId: 'projectId',
2121
clusterName: 'clusterName',
22-
regionalBaseUrl: 'https://example.com',
22+
regionalBaseUrl: null,
2323
metricsId: 'metricsId',
24-
metricsType: 'host',
24+
metricsType: 'replicaSet',
2525
instanceSize: 'M10',
2626
clusterType: 'REPLICASET',
2727
clusterUniqueId: 'clusterUniqueId',
28+
clusterState: 'IDLE',
29+
supports: {
30+
globalWrites: false,
31+
rollingIndexes: false,
32+
},
2833
},
2934
},
3035
{
@@ -36,12 +41,17 @@ const mockConnections: ConnectionInfo[] = [
3641
orgId: 'orgId',
3742
projectId: 'projectId',
3843
clusterName: 'clusterName',
39-
regionalBaseUrl: 'https://example.com',
44+
regionalBaseUrl: null,
4045
metricsId: 'metricsId',
4146
metricsType: 'replicaSet',
4247
instanceSize: 'M0',
4348
clusterType: 'REPLICASET',
4449
clusterUniqueId: 'clusterUniqueId',
50+
clusterState: 'IDLE',
51+
supports: {
52+
globalWrites: false,
53+
rollingIndexes: false,
54+
},
4555
},
4656
},
4757
{
@@ -53,12 +63,17 @@ const mockConnections: ConnectionInfo[] = [
5363
orgId: 'orgId',
5464
projectId: 'projectId',
5565
clusterName: 'clusterName',
56-
regionalBaseUrl: 'https://example.com',
66+
regionalBaseUrl: null,
5767
metricsId: 'metricsId',
5868
metricsType: 'serverless',
5969
instanceSize: 'SERVERLESS_V2',
6070
clusterType: 'REPLICASET',
6171
clusterUniqueId: 'clusterUniqueId',
72+
clusterState: 'IDLE',
73+
supports: {
74+
globalWrites: false,
75+
rollingIndexes: false,
76+
},
6277
},
6378
},
6479
{
@@ -70,12 +85,17 @@ const mockConnections: ConnectionInfo[] = [
7085
orgId: 'orgId',
7186
projectId: 'projectId',
7287
clusterName: 'clusterName',
73-
regionalBaseUrl: 'https://example.com',
88+
regionalBaseUrl: null,
7489
metricsId: 'metricsId',
7590
metricsType: 'replicaSet',
7691
instanceSize: 'M10',
7792
clusterType: 'REPLICASET',
7893
clusterUniqueId: 'clusterUniqueId',
94+
clusterState: 'IDLE',
95+
supports: {
96+
globalWrites: false,
97+
rollingIndexes: true,
98+
},
7999
},
80100
},
81101
{
@@ -87,12 +107,17 @@ const mockConnections: ConnectionInfo[] = [
87107
orgId: 'orgId',
88108
projectId: 'projectId',
89109
clusterName: 'clusterName',
90-
regionalBaseUrl: 'https://example.com',
110+
regionalBaseUrl: null,
91111
metricsId: 'metricsId',
92112
metricsType: 'cluster',
93113
instanceSize: 'M10',
94114
clusterType: 'SHARDED',
95115
clusterUniqueId: 'clusterUniqueId',
116+
clusterState: 'IDLE',
117+
supports: {
118+
globalWrites: false,
119+
rollingIndexes: true,
120+
},
96121
},
97122
},
98123
{
@@ -104,12 +129,17 @@ const mockConnections: ConnectionInfo[] = [
104129
orgId: 'orgId',
105130
projectId: 'projectId',
106131
clusterName: 'clusterName',
107-
regionalBaseUrl: 'https://example.com',
132+
regionalBaseUrl: null,
108133
metricsId: 'metricsId',
109134
metricsType: 'cluster',
110135
instanceSize: 'M30',
111136
clusterType: 'GEOSHARDED',
112137
clusterUniqueId: 'clusterUniqueId',
138+
clusterState: 'IDLE',
139+
supports: {
140+
globalWrites: true,
141+
rollingIndexes: true,
142+
},
113143
},
114144
},
115145
];

packages/compass-connections/src/utils/connection-supports.spec.ts

+47-13
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,17 @@ const mockConnections = [
1818
orgId: 'orgId',
1919
projectId: 'projectId',
2020
clusterName: 'clusterName',
21-
regionalBaseUrl: 'https://example.com',
21+
regionalBaseUrl: null,
2222
metricsId: 'metricsId',
23-
metricsType: 'host',
23+
metricsType: 'replicaSet',
2424
instanceSize: 'M10',
2525
clusterType: 'REPLICASET',
2626
clusterUniqueId: 'clusterUniqueId',
27+
clusterState: 'IDLE',
28+
supports: {
29+
globalWrites: false,
30+
rollingIndexes: false,
31+
},
2732
},
2833
},
2934
{
@@ -35,12 +40,17 @@ const mockConnections = [
3540
orgId: 'orgId',
3641
projectId: 'projectId',
3742
clusterName: 'clusterName',
38-
regionalBaseUrl: 'https://example.com',
43+
regionalBaseUrl: null,
3944
metricsId: 'metricsId',
4045
metricsType: 'replicaSet',
4146
instanceSize: 'M0',
4247
clusterType: 'REPLICASET',
4348
clusterUniqueId: 'clusterUniqueId',
49+
clusterState: 'IDLE',
50+
supports: {
51+
globalWrites: false,
52+
rollingIndexes: false,
53+
},
4454
},
4555
},
4656
{
@@ -52,12 +62,17 @@ const mockConnections = [
5262
orgId: 'orgId',
5363
projectId: 'projectId',
5464
clusterName: 'clusterName',
55-
regionalBaseUrl: 'https://example.com',
65+
regionalBaseUrl: null,
5666
metricsId: 'metricsId',
5767
metricsType: 'serverless',
5868
instanceSize: 'SERVERLESS_V2',
5969
clusterType: 'REPLICASET',
6070
clusterUniqueId: 'clusterUniqueId',
71+
clusterState: 'IDLE',
72+
supports: {
73+
globalWrites: false,
74+
rollingIndexes: false,
75+
},
6176
},
6277
},
6378
{
@@ -69,12 +84,17 @@ const mockConnections = [
6984
orgId: 'orgId',
7085
projectId: 'projectId',
7186
clusterName: 'clusterName',
72-
regionalBaseUrl: 'https://example.com',
87+
regionalBaseUrl: null,
7388
metricsId: 'metricsId',
7489
metricsType: 'replicaSet',
7590
instanceSize: 'M10',
7691
clusterType: 'REPLICASET',
7792
clusterUniqueId: 'clusterUniqueId',
93+
clusterState: 'IDLE',
94+
supports: {
95+
globalWrites: false,
96+
rollingIndexes: true,
97+
},
7898
},
7999
},
80100
{
@@ -86,14 +106,16 @@ const mockConnections = [
86106
orgId: 'orgId',
87107
projectId: 'projectId',
88108
clusterName: 'clusterName',
89-
regionalBaseUrl: 'https://example.com',
109+
regionalBaseUrl: null,
90110
metricsId: 'metricsId',
91111
metricsType: 'cluster',
92112
instanceSize: 'M10',
93113
clusterType: 'SHARDED',
94114
clusterUniqueId: 'clusterUniqueId',
95-
geoSharding: {
96-
selfManagedSharding: false,
115+
clusterState: 'IDLE',
116+
supports: {
117+
globalWrites: false,
118+
rollingIndexes: true,
97119
},
98120
},
99121
},
@@ -106,12 +128,17 @@ const mockConnections = [
106128
orgId: 'orgId',
107129
projectId: 'projectId',
108130
clusterName: 'clusterName',
109-
regionalBaseUrl: 'https://example.com',
131+
regionalBaseUrl: null,
110132
metricsId: 'metricsId',
111133
metricsType: 'cluster',
112134
instanceSize: 'M30',
113135
clusterType: 'GEOSHARDED',
114136
clusterUniqueId: 'clusterUniqueId',
137+
clusterState: 'IDLE',
138+
supports: {
139+
globalWrites: true,
140+
rollingIndexes: true,
141+
},
115142
},
116143
},
117144
{
@@ -123,14 +150,16 @@ const mockConnections = [
123150
orgId: 'orgId',
124151
projectId: 'projectId',
125152
clusterName: 'clusterName',
126-
regionalBaseUrl: 'https://example.com',
153+
regionalBaseUrl: null,
127154
metricsId: 'metricsId',
128155
metricsType: 'cluster',
129156
instanceSize: 'M30',
130157
clusterType: 'GEOSHARDED',
131158
clusterUniqueId: 'clusterUniqueId',
132-
geoSharding: {
133-
selfManagedSharding: true,
159+
clusterState: 'IDLE',
160+
supports: {
161+
globalWrites: false,
162+
rollingIndexes: true,
134163
},
135164
},
136165
},
@@ -143,12 +172,17 @@ const mockConnections = [
143172
orgId: 'orgId',
144173
projectId: 'projectId',
145174
clusterName: 'clusterName',
146-
regionalBaseUrl: 'https://example.com',
175+
regionalBaseUrl: null,
147176
metricsId: 'metricsId',
148177
metricsType: 'flex',
149178
instanceSize: 'FLEX',
150179
clusterType: 'REPLICASET',
151180
clusterUniqueId: 'clusterUniqueId',
181+
clusterState: 'IDLE',
182+
supports: {
183+
globalWrites: false,
184+
rollingIndexes: false,
185+
},
152186
},
153187
},
154188
] as const;

packages/compass-connections/src/utils/connection-supports.ts

+2-17
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,14 @@
11
import type { ConnectionInfo } from '@mongodb-js/connection-info';
22
export type ConnectionFeature = 'rollingIndexCreation' | 'globalWrites';
33

4-
function isFreeOrSharedTierCluster(instanceSize: string | undefined): boolean {
5-
if (!instanceSize) {
6-
return false;
7-
}
8-
9-
return ['M0', 'M2', 'M5'].includes(instanceSize);
10-
}
11-
124
function supportsRollingIndexCreation(connectionInfo: ConnectionInfo) {
135
const atlasMetadata = connectionInfo.atlasMetadata;
146

157
if (!atlasMetadata) {
168
return false;
179
}
1810

19-
const { metricsType, instanceSize } = atlasMetadata;
20-
return (
21-
(metricsType === 'cluster' || metricsType === 'replicaSet') &&
22-
!isFreeOrSharedTierCluster(instanceSize)
23-
);
11+
return atlasMetadata.supports.rollingIndexes;
2412
}
2513

2614
function supportsGlobalWrites(connectionInfo: ConnectionInfo) {
@@ -30,10 +18,7 @@ function supportsGlobalWrites(connectionInfo: ConnectionInfo) {
3018
return false;
3119
}
3220

33-
return (
34-
atlasMetadata.clusterType === 'GEOSHARDED' &&
35-
!atlasMetadata.geoSharding?.selfManagedSharding
36-
);
21+
return atlasMetadata.supports.globalWrites;
3722
}
3823

3924
export function connectionSupports(

packages/compass-generative-ai/src/atlas-ai-service.spec.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,17 @@ const mockConnectionInfo: ConnectionInfo = {
2626
orgId: 'testOrg',
2727
projectId: 'testProject',
2828
clusterName: 'pineapple',
29-
regionalBaseUrl: 'https://example.com',
29+
regionalBaseUrl: null,
3030
metricsId: 'metricsId',
3131
metricsType: 'replicaSet',
3232
instanceSize: 'M10',
3333
clusterType: 'REPLICASET',
3434
clusterUniqueId: 'clusterUniqueId',
35+
clusterState: 'IDLE',
36+
supports: {
37+
globalWrites: false,
38+
rollingIndexes: false,
39+
},
3540
},
3641
};
3742

packages/compass-indexes/src/index.spec.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ describe('CompassIndexesPlugin', function () {
5959
atlasMetadata: {
6060
instanceSize: 'VERY BIG',
6161
metricsType: 'replicaSet',
62+
supports: {
63+
rollingIndexes: true,
64+
},
6265
} as any,
6366
},
6467
{

packages/compass-indexes/src/modules/regular-indexes.spec.ts

+3
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ describe('regular-indexes module', function () {
6868
atlasMetadata: {
6969
metricsType: 'cluster',
7070
instanceSize: 'M10',
71+
supports: {
72+
rollingIndexes: true,
73+
},
7174
},
7275
},
7376
} as ConnectionInfoRef;

packages/compass-schema/src/utils.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ describe('compass-schema utils', function () {
3232
expect(
3333
getAtlasPerformanceAdvisorLink({
3434
metricsId: '123456',
35-
metricsType: 'host',
35+
metricsType: 'replicaSet',
3636
clusterName: 'Cluster0',
3737
})
38-
).to.equal('#/metrics/host/123456/advisor');
38+
).to.equal('#/metrics/replicaSet/123456/advisor');
3939
});
4040
it('encodes the parameters', function () {
4141
expect(

packages/compass-web/src/connection-storage.spec.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@ describe('buildConnectionInfoFromClusterDescription', function () {
186186
clusterDescription.replicationSpecList?.[0].regionConfigs.slice().pop()
187187
?.electableSpecs.instanceSize;
188188

189+
// We test these separately in another test
190+
if (connectionInfo.atlasMetadata?.supports) {
191+
delete (connectionInfo.atlasMetadata as { supports?: any }).supports;
192+
}
193+
189194
expect(connectionInfo)
190195
.to.have.property('atlasMetadata')
191196
.deep.eq({
@@ -199,12 +204,9 @@ describe('buildConnectionInfoFromClusterDescription', function () {
199204
clusterUniqueId: '123abc',
200205
metricsType: type === 'sharded' ? 'cluster' : type,
201206
instanceSize: expectedInstanceSize,
202-
regionalBaseUrl: 'https://example.com',
207+
regionalBaseUrl: null,
203208
clusterType: clusterDescription.clusterType,
204-
geoSharding: {
205-
selfManagedSharding:
206-
clusterDescription.geoSharding?.selfManagedSharding,
207-
},
209+
clusterState: 'IDLE',
208210
});
209211
});
210212
}

0 commit comments

Comments
 (0)