Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(compass-web): use ccs for atlas sandbox instead of local proxy COMPASS-8693 #6570

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
28 changes: 25 additions & 3 deletions packages/atlas-service/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,11 @@ export type AtlasServiceConfig = {
* Atlas service backend configurations.
* - atlas-local: local mms backend (localhost)
* - atlas-dev: dev mms backend (cloud-dev.mongodb.com)
* - atlas-qa: qa mms backend (cloud-qa.mongodb.com)
* - atlas: mms backend (cloud.mongodb.com)
* - web-sandbox-atlas-local: local mms backend + proxy (localhost / proxy prefix)
* - web-sandbox-atlas-dev: dev mms backend + proxy (cloud-dev.mongodb.com / proxy prefix)
* - web-sandbox-atlas-qa: qa mms backend + proxy (cloud-qa.mongodb.com / proxy prefix)
* - web-sandbox-atlas: mms backend + proxy (cloud.mongodb.com / proxy prefix)
*/
const config = {
Expand All @@ -148,6 +150,16 @@ const config = {
},
authPortalUrl: 'https://account-dev.mongodb.com/account/login',
},
'atlas-qa': {
wsBaseUrl: '',
cloudBaseUrl: '',
atlasApiBaseUrl: 'https://cloud-qa.mongodb.com/api/private',
atlasLogin: {
clientId: '0oaq1le5jlzxCuTbu357',
issuer: 'https://auth-qa.mongodb.com/oauth2/default',
},
authPortalUrl: 'https://account-qa.mongodb.com/account/login',
},
atlas: {
wsBaseUrl: '',
cloudBaseUrl: '',
Expand All @@ -159,7 +171,7 @@ const config = {
authPortalUrl: 'https://account.mongodb.com/account/login',
},
'web-sandbox-atlas-local': {
wsBaseUrl: 'ws://localhost:1337',
wsBaseUrl: '/ccs',
cloudBaseUrl: '/cloud-mongodb-com',
atlasApiBaseUrl: 'http://localhost:8080/api/private',
atlasLogin: {
Expand All @@ -169,7 +181,17 @@ const config = {
authPortalUrl: 'https://account-dev.mongodb.com/account/login',
},
'web-sandbox-atlas-dev': {
wsBaseUrl: 'ws://localhost:1337',
wsBaseUrl: '/ccs',
cloudBaseUrl: '/cloud-mongodb-com',
atlasApiBaseUrl: 'https://cloud-dev.mongodb.com/api/private',
atlasLogin: {
clientId: '0oaq1le5jlzxCuTbu357',
issuer: 'https://auth-qa.mongodb.com/oauth2/default',
},
authPortalUrl: 'https://account-dev.mongodb.com/account/login',
},
'web-sandbox-atlas-qa': {
wsBaseUrl: '/ccs',
cloudBaseUrl: '/cloud-mongodb-com',
atlasApiBaseUrl: 'https://cloud-dev.mongodb.com/api/private',
atlasLogin: {
Expand All @@ -179,7 +201,7 @@ const config = {
authPortalUrl: 'https://account-dev.mongodb.com/account/login',
},
'web-sandbox-atlas': {
wsBaseUrl: 'ws://localhost:1337',
wsBaseUrl: '/ccs',
cloudBaseUrl: '/cloud-mongodb-com',
atlasApiBaseUrl: 'https://cloud.mongodb.com/api/private',
atlasLogin: {
Expand Down
4 changes: 0 additions & 4 deletions packages/compass-e2e-tests/helpers/compass-web-sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,6 @@ export async function spawnCompassWebSandboxAndSignInToAtlas(
return electronProxyRemote;
}

debug('Waiting for x509 cert to propagate to Atlas clusters ...');

await fetch(`${sandboxUrl}/x509`);

return electronProxyRemote;
}

Expand Down
9 changes: 7 additions & 2 deletions packages/compass-preferences-model/src/preferences-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ export type UserConfigurablePreferences = PermanentFeatureFlags &
atlasServiceBackendPreset:
| 'atlas-local'
| 'atlas-dev'
| 'atlas-qa'
| 'atlas'
| 'web-sandbox-atlas-local'
| 'web-sandbox-atlas-dev'
| 'web-sandbox-atlas-qa'
| 'web-sandbox-atlas';
optInDataExplorerGenAIFeatures: boolean;
// Features that are enabled by default in Compass, but are disabled in Data
Expand Down Expand Up @@ -672,6 +674,7 @@ export const storedUserPreferencesProps: Required<{
* Chooses atlas service backend configuration from preset
* - atlas-local: local mms backend (http://localhost:8080)
* - atlas-dev: dev mms backend (cloud-dev.mongodb.com)
* - atlas-qa: qa mms backend (cloud-qa.mongodb.com)
* - atlas: mms backend (cloud.mongodb.com)
*/
atlasServiceBackendPreset: {
Expand All @@ -683,11 +686,13 @@ export const storedUserPreferencesProps: Required<{
},
validator: z
.enum([
'atlas-dev',
'atlas-local',
'atlas-dev',
'atlas-qa',
'atlas',
'web-sandbox-atlas-dev',
'web-sandbox-atlas-local',
'web-sandbox-atlas-dev',
'web-sandbox-atlas-qa',
'web-sandbox-atlas',
])
.default('atlas'),
Expand Down
36 changes: 16 additions & 20 deletions packages/compass-web/polyfills/net/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@ import { ipVersion } from 'is-ip';
import type { ConnectionOptions } from 'mongodb-data-service';
import { Duplex } from 'stream';

const WS_PROXY_PORT = process.env.COMPASS_WEB_WS_PROXY_PORT
? Number(process.env.COMPASS_WEB_WS_PROXY_PORT)
: 1337;

/**
* net.Socket interface that works over the WebSocket connection. For now, only
* used when running compass-web in a local sandbox, mms has their own
* implementation
*/
class Socket extends Duplex {
private _tls = false;
private _ws: WebSocket | null = null;
private _setOptions: {
setKeepAlive?: { enabled?: boolean; initialDelay?: number };
Expand All @@ -30,17 +27,20 @@ class Socket extends Duplex {
lookup?: ConnectionOptions['lookup'];
tls?: boolean;
}) {
const { wsURL, ...atlasOptions } = lookup?.() ?? {};
this._ws = new WebSocket(wsURL ?? `ws://localhost:${WS_PROXY_PORT}`);
this._tls = !!options.tls;
const { wsURL, ...atlasOptions } =
lookup?.() ?? ({} as { wsURL?: string; clusterName?: string });
this._ws = new WebSocket(wsURL ?? '/ws-proxy');
this._ws.binaryType = 'arraybuffer';
this._ws.addEventListener(
'open',
() => {
const connectMsg = JSON.stringify({
connectOptions: options,
atlasOptions:
Object.keys(atlasOptions).length > 0 ? atlasOptions : undefined,
setOptions: this._setOptions,
port: options.port,
host: options.host,
tls: options.tls ?? false,
clusterName: atlasOptions.clusterName,
ok: 1,
});
setTimeout(() => {
this._ws?.send(connectMsg);
Expand All @@ -59,16 +59,12 @@ class Socket extends Duplex {
({ data }: MessageEvent<string | ArrayBuffer>) => {
if (typeof data === 'string') {
try {
const { evt, error } = JSON.parse(data) as {
evt: string;
error?: Error;
};
setTimeout(() => {
this.emit(
evt,
evt === 'error' ? Object.assign(new Error(), error) : undefined
);
});
const res = JSON.parse(data) as { preMessageOk: 1 };
if (res.preMessageOk) {
setTimeout(() => {
this.emit(this._tls ? 'secureConnect' : 'connect');
});
}
} catch (err) {
// eslint-disable-next-line no-console
console.error('error parsing proxy message "%s":', data, err);
Expand Down
5 changes: 3 additions & 2 deletions packages/compass-web/sandbox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ const App = () => {
const atlasServiceSandboxBackendVariant =
process.env.COMPASS_WEB_HTTP_PROXY_CLOUD_CONFIG === 'local'
? 'web-sandbox-atlas-local'
: process.env.COMPASS_WEB_HTTP_PROXY_CLOUD_CONFIG === 'dev' ||
process.env.COMPASS_WEB_HTTP_PROXY_CLOUD_CONFIG === 'qa'
: process.env.COMPASS_WEB_HTTP_PROXY_CLOUD_CONFIG === 'dev'
? 'web-sandbox-atlas-dev'
: process.env.COMPASS_WEB_HTTP_PROXY_CLOUD_CONFIG === 'qa'
? 'web-sandbox-atlas-qa'
: 'web-sandbox-atlas';

const overrideGenAIEnablement =
Expand Down
Loading
Loading