Skip to content

Commit

Permalink
chore(connection-info): rename clusterId and clusterType to more appr…
Browse files Browse the repository at this point in the history
…opriate metricsId and metricsType COMPASS-8248 (#6211)

chore(connection-info): rename clusterId and clusterType to more appropriate metricsId and metricsType
  • Loading branch information
gribnoysup authored Sep 10, 2024
1 parent 86f6d05 commit 7be3eae
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ const mockConnections: ConnectionInfo[] = [
projectId: 'projectId',
clusterName: 'clusterName',
regionalBaseUrl: 'https://example.com',
clusterId: 'clusterId',
clusterType: 'host',
metricsId: 'metricsId',
metricsType: 'host',
instanceSize: 'M10',
},
},
Expand All @@ -35,8 +35,8 @@ const mockConnections: ConnectionInfo[] = [
projectId: 'projectId',
clusterName: 'clusterName',
regionalBaseUrl: 'https://example.com',
clusterId: 'clusterId',
clusterType: 'replicaSet',
metricsId: 'metricsId',
metricsType: 'replicaSet',
instanceSize: 'M0',
},
},
Expand All @@ -50,8 +50,8 @@ const mockConnections: ConnectionInfo[] = [
projectId: 'projectId',
clusterName: 'clusterName',
regionalBaseUrl: 'https://example.com',
clusterId: 'clusterId',
clusterType: 'serverless',
metricsId: 'metricsId',
metricsType: 'serverless',
instanceSize: 'SERVERLESS_V2',
},
},
Expand All @@ -65,8 +65,8 @@ const mockConnections: ConnectionInfo[] = [
projectId: 'projectId',
clusterName: 'clusterName',
regionalBaseUrl: 'https://example.com',
clusterId: 'clusterId',
clusterType: 'replicaSet',
metricsId: 'metricsId',
metricsType: 'replicaSet',
instanceSize: 'M10',
},
},
Expand All @@ -80,8 +80,8 @@ const mockConnections: ConnectionInfo[] = [
projectId: 'projectId',
clusterName: 'clusterName',
regionalBaseUrl: 'https://example.com',
clusterId: 'clusterId',
clusterType: 'cluster',
metricsId: 'metricsId',
metricsType: 'cluster',
instanceSize: 'M10',
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ function supportsRollingIndexCreation(connection: ConnectionState) {
return false;
}

const { clusterType, instanceSize } = atlasMetadata;
const { metricsType, instanceSize } = atlasMetadata;
return (
!isFreeOrSharedTierCluster(instanceSize) &&
(clusterType === 'cluster' || clusterType === 'replicaSet')
(metricsType === 'cluster' || metricsType === 'replicaSet')
);
}
export function useConnectionSupports(
Expand Down
24 changes: 12 additions & 12 deletions packages/compass-schema/src/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,51 @@ describe('compass-schema utils', function () {
it('returns the correct link for a serverless cluster', function () {
expect(
getAtlasPerformanceAdvisorLink({
clusterId: '123456',
clusterType: 'serverless',
metricsId: '123456',
metricsType: 'serverless',
clusterName: 'Cluster0',
})
).to.equal('#/serverless/advisor/Cluster0/createIndexes');
});
it('returns the correct link for other clusters', function () {
expect(
getAtlasPerformanceAdvisorLink({
clusterId: '123456',
clusterType: 'replicaSet',
metricsId: '123456',
metricsType: 'replicaSet',
clusterName: 'Cluster0',
})
).to.equal('#/metrics/replicaSet/123456/advisor');

expect(
getAtlasPerformanceAdvisorLink({
clusterId: '123456',
clusterType: 'cluster',
metricsId: '123456',
metricsType: 'cluster',
clusterName: 'Cluster0',
})
).to.equal('#/metrics/cluster/123456/advisor');

expect(
getAtlasPerformanceAdvisorLink({
clusterId: '123456',
clusterType: 'host',
metricsId: '123456',
metricsType: 'host',
clusterName: 'Cluster0',
})
).to.equal('#/metrics/host/123456/advisor');
});
it('encodes the parameters', function () {
expect(
getAtlasPerformanceAdvisorLink({
clusterId: '123456',
clusterType: 'serverless',
metricsId: '123456',
metricsType: 'serverless',
clusterName: 'Cluster Something',
}),
'encodes cluster name'
).to.equal('#/serverless/advisor/Cluster%20Something/createIndexes');

expect(
getAtlasPerformanceAdvisorLink({
clusterId: '123 456',
clusterType: 'replica#Set' as any,
metricsId: '123 456',
metricsType: 'replica#Set' as any,
clusterName: 'Cluster Something',
}),
'encodes cluster id and cluster type'
Expand Down
12 changes: 6 additions & 6 deletions packages/compass-schema/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import type { AtlasClusterMetadata } from '@mongodb-js/connection-storage/renderer';

export function getAtlasPerformanceAdvisorLink({
clusterId,
clusterType,
metricsId,
metricsType,
clusterName,
}: Pick<AtlasClusterMetadata, 'clusterId' | 'clusterType' | 'clusterName'>) {
if (clusterType === 'serverless') {
}: Pick<AtlasClusterMetadata, 'metricsId' | 'metricsType' | 'clusterName'>) {
if (metricsType === 'serverless') {
return `#/serverless/advisor/${encodeURIComponent(
clusterName
)}/createIndexes`;
}
return `#/metrics/${encodeURIComponent(clusterType)}/${encodeURIComponent(
clusterId
return `#/metrics/${encodeURIComponent(metricsType)}/${encodeURIComponent(
metricsId
)}/advisor`;
}
4 changes: 2 additions & 2 deletions packages/compass-web/src/connection-storage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ describe('buildConnectionInfoFromClusterDescription', function () {
.deep.eq({
orgId: '123',
projectId: 'abc',
clusterId: type === 'serverless' ? `Cluster0-serverless` : '123abc',
metricsId: type === 'serverless' ? `Cluster0-serverless` : '123abc',
clusterName: `Cluster0-${type}`,
clusterType: type === 'sharded' ? 'cluster' : type,
metricsType: type === 'sharded' ? 'cluster' : type,
instanceSize: expectedInstanceSize,
regionalBaseUrl: 'https://example.com',
});
Expand Down
15 changes: 7 additions & 8 deletions packages/compass-web/src/connection-storage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,15 @@ function isSharded(clusterDescription: ClusterDescription) {
);
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
function getMetricsIdAndType(
clusterDescription: ClusterDescription,
deploymentItem?: ReplicaSetDeploymentItem | ShardingDeploymentItem
): {
clusterId: string;
clusterType: 'serverless' | 'replicaSet' | 'cluster';
metricsId: string;
metricsType: 'serverless' | 'replicaSet' | 'cluster';
} {
if (isServerless(clusterDescription)) {
return { clusterId: clusterDescription.name, clusterType: 'serverless' };
return { metricsId: clusterDescription.name, metricsType: 'serverless' };
}

if (!deploymentItem) {
Expand All @@ -105,8 +104,8 @@ function getMetricsIdAndType(
}

return {
clusterId: deploymentItem.state.clusterId,
clusterType: isSharded(clusterDescription) ? 'cluster' : 'replicaSet',
metricsId: deploymentItem.state.clusterId,
metricsType: isSharded(clusterDescription) ? 'cluster' : 'replicaSet',
};
}

Expand Down Expand Up @@ -246,12 +245,12 @@ class AtlasCloudConnectionStorage
.map(async (description) => {
// Even though nds/clusters will list serverless clusters, to get
// the regional description we need to change the url
const clusterType = isServerless(description)
const clusterDescriptionType = isServerless(description)
? 'serverless'
: 'clusters';
const res = await this.atlasService.authenticatedFetch(
this.atlasService.cloudEndpoint(
`nds/${clusterType}/${this.projectId}/${description.name}/regional/clusterDescription`
`nds/${clusterDescriptionType}/${this.projectId}/${description.name}/regional/clusterDescription`
)
);
return await (res.json() as Promise<ClusterDescriptionWithDataProcessingRegion>);
Expand Down
18 changes: 16 additions & 2 deletions packages/connection-info/src/connection-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,23 @@ export interface AtlasClusterMetadata {
* https://www.mongodb.com/docs/atlas/api/atlas-admin-api-ref/#project-id
*/
projectId: string;
clusterId: string;
/**
* Cluster name, unique inside same project
*/
clusterName: string;
clusterType: 'host' | 'replicaSet' | 'cluster' | 'serverless';
/**
* A special id and type that are only relevant in context of mms metrics
* features. These are deployment items props (with a special exception for
* serverless, where id is just name, and type is `serverless` that doesn't
* make sense in context of deployments), not cluster description props.
* https://github.com/10gen/mms/blob/43b0049a85196b44e465feb9b96ef942d6f2c8f4/client/js/legacy/core/models/deployment
*/
metricsId: string;
metricsType: 'host' | 'replicaSet' | 'cluster' | 'serverless';
/**
* Atlas API base url to be used when connecing to a regionalized cluster
*/
regionalBaseUrl: string;
/*
* At the time of writing these are the possible instance sizes. If we include
Expand Down

0 comments on commit 7be3eae

Please sign in to comment.