Skip to content

Commit 36f5622

Browse files
committed
fix(connections, web): handle flex clusters without deployment
1 parent 16724bf commit 36f5622

File tree

8 files changed

+46
-31
lines changed

8 files changed

+46
-31
lines changed

packages/atlas-service/src/atlas-service.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,21 @@ function shouldAddCSRFHeaders(method = 'get') {
3636
return !/^(get|head|options|trace)$/.test(method.toLowerCase());
3737
}
3838

39+
function getAutomationAgentClusterId(
40+
atlasMetadata: Pick<
41+
AtlasClusterMetadata,
42+
'clusterUniqueId' | 'metricsId' | 'metricsType'
43+
>
44+
): { clusterId: string } | { serverlessId: string } | { flexId: string } {
45+
if (atlasMetadata.metricsType === 'flex') {
46+
return { flexId: atlasMetadata.clusterUniqueId };
47+
}
48+
if (atlasMetadata.metricsType === 'serverless') {
49+
return { serverlessId: atlasMetadata.clusterUniqueId };
50+
}
51+
return { clusterId: atlasMetadata.metricsId };
52+
}
53+
3954
export class AtlasService {
4055
private config: AtlasServiceConfig;
4156
constructor(
@@ -121,10 +136,7 @@ export class AtlasService {
121136
opType: string,
122137
opBody: Record<string, unknown>
123138
): Promise<{ _id: string; requestType: string } | undefined> {
124-
const opBodyClusterId =
125-
atlasMetadata.metricsType === 'serverless'
126-
? { serverlessId: atlasMetadata.clusterUniqueId }
127-
: { clusterId: atlasMetadata.metricsId };
139+
const opBodyClusterId = getAutomationAgentClusterId(atlasMetadata);
128140
const requestUrl = this.regionalizedCloudEndpoint(
129141
atlasMetadata,
130142
`/explorer/v1/groups/${atlasMetadata.projectId}/requests/${opType}`

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ const mockConnections = [
145145
clusterName: 'clusterName',
146146
regionalBaseUrl: 'https://example.com',
147147
metricsId: 'metricsId',
148-
metricsType: 'replicaSet',
148+
metricsType: 'flex',
149149
instanceSize: 'FLEX',
150150
clusterType: 'REPLICASET',
151151
clusterUniqueId: 'clusterUniqueId',

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,6 @@ function isFreeOrSharedTierCluster(instanceSize: string | undefined): boolean {
99
return ['M0', 'M2', 'M5'].includes(instanceSize);
1010
}
1111

12-
function isFlexTier(instanceSize: string | undefined): boolean {
13-
if (!instanceSize) {
14-
return false;
15-
}
16-
17-
return instanceSize === 'FLEX';
18-
}
19-
2012
function supportsRollingIndexCreation(connectionInfo: ConnectionInfo) {
2113
const atlasMetadata = connectionInfo.atlasMetadata;
2214

@@ -26,9 +18,8 @@ function supportsRollingIndexCreation(connectionInfo: ConnectionInfo) {
2618

2719
const { metricsType, instanceSize } = atlasMetadata;
2820
return (
29-
!isFreeOrSharedTierCluster(instanceSize) &&
30-
!isFlexTier(instanceSize) &&
31-
(metricsType === 'cluster' || metricsType === 'replicaSet')
21+
(metricsType === 'cluster' || metricsType === 'replicaSet') &&
22+
!isFreeOrSharedTierCluster(instanceSize)
3223
);
3324
}
3425

packages/compass-indexes/src/modules/rolling-indexes-service.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,12 @@ export class RollingIndexesService {
6767

6868
// Not possible to do through UI, doing a pre-check here to avoid dealing
6969
// with payload variations based on metricsType later
70-
if (atlasMetadata.metricsType === 'serverless') {
70+
if (
71+
atlasMetadata.metricsType === 'serverless' ||
72+
atlasMetadata.metricsType === 'flex'
73+
) {
7174
throw new Error(
72-
"Serverless clusters don't support rolling index build creation"
75+
'Flex clusters don not support rolling index build creation'
7376
);
7477
}
7578

packages/compass-schema/src/utils.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ export function getAtlasPerformanceAdvisorLink({
1313
metricsType,
1414
clusterName,
1515
}: Pick<AtlasClusterMetadata, 'metricsId' | 'metricsType' | 'clusterName'>) {
16-
if (metricsType === 'serverless') {
17-
return `#/serverless/advisor/${encodeURIComponent(
18-
clusterName
19-
)}/createIndexes`;
16+
const name = encodeURIComponent(clusterName);
17+
const type = encodeURIComponent(metricsType);
18+
const id = encodeURIComponent(metricsId);
19+
20+
if (metricsType === 'serverless' || metricsType === 'flex') {
21+
return `#/${type}/advisor/${name}/createIndexes`;
2022
}
21-
return `#/metrics/${encodeURIComponent(metricsType)}/${encodeURIComponent(
22-
metricsId
23-
)}/advisor`;
23+
24+
return `#/metrics/${type}/${id}/advisor`;
2425
}

packages/compass-web/src/connection-storage.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useContext, useRef } from 'react';
22
import type {
33
ConnectionStorage,
44
ConnectionInfo,
5+
AtlasClusterMetadata,
56
} from '@mongodb-js/connection-storage/provider';
67
import {
78
ConnectionStorageProvider,
@@ -90,6 +91,10 @@ function isServerless(clusterDescription: ClusterDescription) {
9091
return clusterDescription['@provider'] === 'SERVERLESS';
9192
}
9293

94+
function isFlex(clusterDescription: ClusterDescription) {
95+
return clusterDescription['@provider'] === 'FLEX';
96+
}
97+
9398
function isSharded(clusterDescription: ClusterDescription) {
9499
return (
95100
clusterDescription.clusterType === 'SHARDED' ||
@@ -100,14 +105,15 @@ function isSharded(clusterDescription: ClusterDescription) {
100105
function getMetricsIdAndType(
101106
clusterDescription: ClusterDescription,
102107
deploymentItem?: ReplicaSetDeploymentItem | ShardingDeploymentItem
103-
): {
104-
metricsId: string;
105-
metricsType: 'serverless' | 'replicaSet' | 'cluster';
106-
} {
108+
): Pick<AtlasClusterMetadata, 'metricsId' | 'metricsType'> {
107109
if (isServerless(clusterDescription)) {
108110
return { metricsId: clusterDescription.name, metricsType: 'serverless' };
109111
}
110112

113+
if (isFlex(clusterDescription)) {
114+
return { metricsId: clusterDescription.name, metricsType: 'flex' };
115+
}
116+
111117
if (!deploymentItem) {
112118
throw new Error(
113119
"Can't build metrics info when deployment item is not found"

packages/compass-web/webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ module.exports = (env, args) => {
148148
}),
149149
],
150150
performance: {
151-
hints: serve ? 'warning' : 'error',
151+
hints: serve || args.watch ? 'warning' : 'error',
152152
maxEntrypointSize: MAX_COMPRESSION_FILE_SIZE,
153153
maxAssetSize: MAX_COMPRESSION_FILE_SIZE,
154154
},

packages/connection-info/src/connection-info.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ export interface AtlasClusterMetadata {
3636
* - `replicaSet`: anything that is not sharded (both dedicated or "free
3737
* tier" / MTM)
3838
* - `serverless`: specifically for serverless clusters
39+
* - `flex`: new type that replaces serverless and some shared
40+
* clusters
3941
*/
40-
metricsType: 'host' | 'replicaSet' | 'cluster' | 'serverless';
42+
metricsType: 'host' | 'replicaSet' | 'cluster' | 'serverless' | 'flex';
4143
/**
4244
* Atlas API base url to be used when making control plane requests for a
4345
* regionalized cluster

0 commit comments

Comments
 (0)