diff --git a/packages/atlas-service/src/atlas-service.ts b/packages/atlas-service/src/atlas-service.ts index bdd401f7fdb..c7e5bbd7203 100644 --- a/packages/atlas-service/src/atlas-service.ts +++ b/packages/atlas-service/src/atlas-service.ts @@ -36,6 +36,21 @@ function shouldAddCSRFHeaders(method = 'get') { return !/^(get|head|options|trace)$/.test(method.toLowerCase()); } +function getAutomationAgentClusterId( + atlasMetadata: Pick< + AtlasClusterMetadata, + 'clusterUniqueId' | 'metricsId' | 'metricsType' + > +): { clusterId: string } | { serverlessId: string } | { flexId: string } { + if (atlasMetadata.metricsType === 'flex') { + return { flexId: atlasMetadata.clusterUniqueId }; + } + if (atlasMetadata.metricsType === 'serverless') { + return { serverlessId: atlasMetadata.clusterUniqueId }; + } + return { clusterId: atlasMetadata.metricsId }; +} + export class AtlasService { private config: AtlasServiceConfig; constructor( @@ -121,10 +136,7 @@ export class AtlasService { opType: string, opBody: Record ): Promise<{ _id: string; requestType: string } | undefined> { - const opBodyClusterId = - atlasMetadata.metricsType === 'serverless' - ? { serverlessId: atlasMetadata.clusterUniqueId } - : { clusterId: atlasMetadata.metricsId }; + const opBodyClusterId = getAutomationAgentClusterId(atlasMetadata); const requestUrl = this.regionalizedCloudEndpoint( atlasMetadata, `/explorer/v1/groups/${atlasMetadata.projectId}/requests/${opType}` diff --git a/packages/compass-connections/src/utils/connection-supports.spec.ts b/packages/compass-connections/src/utils/connection-supports.spec.ts index ff0054429b3..c568a5ef3e6 100644 --- a/packages/compass-connections/src/utils/connection-supports.spec.ts +++ b/packages/compass-connections/src/utils/connection-supports.spec.ts @@ -145,7 +145,7 @@ const mockConnections = [ clusterName: 'clusterName', regionalBaseUrl: 'https://example.com', metricsId: 'metricsId', - metricsType: 'replicaSet', + metricsType: 'flex', instanceSize: 'FLEX', clusterType: 'REPLICASET', clusterUniqueId: 'clusterUniqueId', diff --git a/packages/compass-connections/src/utils/connection-supports.ts b/packages/compass-connections/src/utils/connection-supports.ts index 900cd91e3e9..d5b22d518f0 100644 --- a/packages/compass-connections/src/utils/connection-supports.ts +++ b/packages/compass-connections/src/utils/connection-supports.ts @@ -9,14 +9,6 @@ function isFreeOrSharedTierCluster(instanceSize: string | undefined): boolean { return ['M0', 'M2', 'M5'].includes(instanceSize); } -function isFlexTier(instanceSize: string | undefined): boolean { - if (!instanceSize) { - return false; - } - - return instanceSize === 'FLEX'; -} - function supportsRollingIndexCreation(connectionInfo: ConnectionInfo) { const atlasMetadata = connectionInfo.atlasMetadata; @@ -26,9 +18,8 @@ function supportsRollingIndexCreation(connectionInfo: ConnectionInfo) { const { metricsType, instanceSize } = atlasMetadata; return ( - !isFreeOrSharedTierCluster(instanceSize) && - !isFlexTier(instanceSize) && - (metricsType === 'cluster' || metricsType === 'replicaSet') + (metricsType === 'cluster' || metricsType === 'replicaSet') && + !isFreeOrSharedTierCluster(instanceSize) ); } diff --git a/packages/compass-indexes/src/modules/rolling-indexes-service.ts b/packages/compass-indexes/src/modules/rolling-indexes-service.ts index 736c7da3d89..7c1b04042e9 100644 --- a/packages/compass-indexes/src/modules/rolling-indexes-service.ts +++ b/packages/compass-indexes/src/modules/rolling-indexes-service.ts @@ -67,9 +67,12 @@ export class RollingIndexesService { // Not possible to do through UI, doing a pre-check here to avoid dealing // with payload variations based on metricsType later - if (atlasMetadata.metricsType === 'serverless') { + if ( + atlasMetadata.metricsType === 'serverless' || + atlasMetadata.metricsType === 'flex' + ) { throw new Error( - "Serverless clusters don't support rolling index build creation" + 'Flex clusters do not support rolling index build creation' ); } diff --git a/packages/compass-schema/src/utils.ts b/packages/compass-schema/src/utils.ts index c77e45d6307..a8fe86de5cb 100644 --- a/packages/compass-schema/src/utils.ts +++ b/packages/compass-schema/src/utils.ts @@ -13,12 +13,13 @@ export function getAtlasPerformanceAdvisorLink({ metricsType, clusterName, }: Pick) { - if (metricsType === 'serverless') { - return `#/serverless/advisor/${encodeURIComponent( - clusterName - )}/createIndexes`; + const name = encodeURIComponent(clusterName); + const type = encodeURIComponent(metricsType); + const id = encodeURIComponent(metricsId); + + if (metricsType === 'serverless' || metricsType === 'flex') { + return `#/${type}/advisor/${name}/createIndexes`; } - return `#/metrics/${encodeURIComponent(metricsType)}/${encodeURIComponent( - metricsId - )}/advisor`; + + return `#/metrics/${type}/${id}/advisor`; } diff --git a/packages/compass-web/src/connection-storage.spec.ts b/packages/compass-web/src/connection-storage.spec.ts index 7d2df316020..577691e114b 100644 --- a/packages/compass-web/src/connection-storage.spec.ts +++ b/packages/compass-web/src/connection-storage.spec.ts @@ -125,6 +125,35 @@ describe('buildConnectionInfoFromClusterDescription', function () { }, 'mongodb+srv://serverless.mongodb.com/?tls=true&authMechanism=MONGODB-X509&authSource=%24external&serverMonitoringMode=poll&maxIdleTimeMS=30000&minPoolSize=0&maxPoolSize=5', ], + [ + 'flex', + { + '@provider': 'FLEX', + uniqueId: '123abc', + groupId: 'abc', + name: 'Cluster0-flex', + clusterType: 'REPLICASET', + srvAddress: 'flex.mongodb.com', + state: 'IDLE', + deploymentItemName: 'flex-xxx', + dataProcessingRegion: { + regionalUrl: 'https://example.com', + }, + replicationSpecList: [ + { + regionConfigs: [ + { + priority: 1, + electableSpecs: { + instanceSize: 'FLEX', + }, + }, + ], + }, + ], + }, + 'mongodb+srv://flex.mongodb.com/?tls=true&authMechanism=MONGODB-X509&authSource=%24external&serverMonitoringMode=poll&maxIdleTimeMS=30000&minPoolSize=0&maxPoolSize=5', + ], ]; for (const [type, clusterDescription, connectionString] of tests) { @@ -162,7 +191,10 @@ describe('buildConnectionInfoFromClusterDescription', function () { .deep.eq({ orgId: '123', projectId: 'abc', - metricsId: type === 'serverless' ? `Cluster0-serverless` : '123abc', + metricsId: + type === 'serverless' || type === 'flex' + ? `Cluster0-${type}` + : '123abc', clusterName: `Cluster0-${type}`, clusterUniqueId: '123abc', metricsType: type === 'sharded' ? 'cluster' : type, diff --git a/packages/compass-web/src/connection-storage.tsx b/packages/compass-web/src/connection-storage.tsx index 6a69149a48d..acaf36e4820 100644 --- a/packages/compass-web/src/connection-storage.tsx +++ b/packages/compass-web/src/connection-storage.tsx @@ -2,6 +2,7 @@ import React, { useContext, useRef } from 'react'; import type { ConnectionStorage, ConnectionInfo, + AtlasClusterMetadata, } from '@mongodb-js/connection-storage/provider'; import { ConnectionStorageProvider, @@ -90,6 +91,10 @@ function isServerless(clusterDescription: ClusterDescription) { return clusterDescription['@provider'] === 'SERVERLESS'; } +function isFlex(clusterDescription: ClusterDescription) { + return clusterDescription['@provider'] === 'FLEX'; +} + function isSharded(clusterDescription: ClusterDescription) { return ( clusterDescription.clusterType === 'SHARDED' || @@ -100,14 +105,15 @@ function isSharded(clusterDescription: ClusterDescription) { function getMetricsIdAndType( clusterDescription: ClusterDescription, deploymentItem?: ReplicaSetDeploymentItem | ShardingDeploymentItem -): { - metricsId: string; - metricsType: 'serverless' | 'replicaSet' | 'cluster'; -} { +): Pick { if (isServerless(clusterDescription)) { return { metricsId: clusterDescription.name, metricsType: 'serverless' }; } + if (isFlex(clusterDescription)) { + return { metricsId: clusterDescription.name, metricsType: 'flex' }; + } + if (!deploymentItem) { throw new Error( "Can't build metrics info when deployment item is not found" diff --git a/packages/compass-web/webpack.config.js b/packages/compass-web/webpack.config.js index 6a0ec622284..8aa97cb25a2 100644 --- a/packages/compass-web/webpack.config.js +++ b/packages/compass-web/webpack.config.js @@ -148,7 +148,7 @@ module.exports = (env, args) => { }), ], performance: { - hints: serve ? 'warning' : 'error', + hints: serve || args.watch ? 'warning' : 'error', maxEntrypointSize: MAX_COMPRESSION_FILE_SIZE, maxAssetSize: MAX_COMPRESSION_FILE_SIZE, }, diff --git a/packages/connection-info/src/connection-info.ts b/packages/connection-info/src/connection-info.ts index 73b46494342..f8b92b88576 100644 --- a/packages/connection-info/src/connection-info.ts +++ b/packages/connection-info/src/connection-info.ts @@ -36,8 +36,10 @@ export interface AtlasClusterMetadata { * - `replicaSet`: anything that is not sharded (both dedicated or "free * tier" / MTM) * - `serverless`: specifically for serverless clusters + * - `flex`: new type that replaces serverless and some shared + * clusters */ - metricsType: 'host' | 'replicaSet' | 'cluster' | 'serverless'; + metricsType: 'host' | 'replicaSet' | 'cluster' | 'serverless' | 'flex'; /** * Atlas API base url to be used when making control plane requests for a * regionalized cluster