Skip to content
Merged
Show file tree
Hide file tree
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
20 changes: 16 additions & 4 deletions packages/atlas-service/src/atlas-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -121,10 +136,7 @@ export class AtlasService {
opType: string,
opBody: Record<string, unknown>
): 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}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ const mockConnections = [
clusterName: 'clusterName',
regionalBaseUrl: 'https://example.com',
metricsId: 'metricsId',
metricsType: 'replicaSet',
metricsType: 'flex',
instanceSize: 'FLEX',
clusterType: 'REPLICASET',
clusterUniqueId: 'clusterUniqueId',
Expand Down
13 changes: 2 additions & 11 deletions packages/compass-connections/src/utils/connection-supports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
}

Expand Down
15 changes: 8 additions & 7 deletions packages/compass-schema/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ export function getAtlasPerformanceAdvisorLink({
metricsType,
clusterName,
}: Pick<AtlasClusterMetadata, 'metricsId' | 'metricsType' | 'clusterName'>) {
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`;
}
34 changes: 33 additions & 1 deletion packages/compass-web/src/connection-storage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 10 additions & 4 deletions packages/compass-web/src/connection-storage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useContext, useRef } from 'react';
import type {
ConnectionStorage,
ConnectionInfo,
AtlasClusterMetadata,
} from '@mongodb-js/connection-storage/provider';
import {
ConnectionStorageProvider,
Expand Down Expand Up @@ -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' ||
Expand All @@ -100,14 +105,15 @@ function isSharded(clusterDescription: ClusterDescription) {
function getMetricsIdAndType(
clusterDescription: ClusterDescription,
deploymentItem?: ReplicaSetDeploymentItem | ShardingDeploymentItem
): {
metricsId: string;
metricsType: 'serverless' | 'replicaSet' | 'cluster';
} {
): Pick<AtlasClusterMetadata, 'metricsId' | 'metricsType'> {
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"
Expand Down
2 changes: 1 addition & 1 deletion packages/compass-web/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
4 changes: 3 additions & 1 deletion packages/connection-info/src/connection-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading