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

feat: add per-connection proxy settings COMPASS-8142 #6133

Merged
merged 18 commits into from
Aug 27, 2024
Merged

feat: add per-connection proxy settings COMPASS-8142 #6133

merged 18 commits into from
Aug 27, 2024

Conversation

addaleax
Copy link
Collaborator

  • Remove the ssh-tunnel package from Compass and its usage from data-service
  • Add relevant fields to the connection form and integrate them into data-service

Description

Checklist

Motivation and Context

  • Bugfix
  • New feature
  • Dependency update
  • Misc

Open Questions

Dependents

Types of changes

  • Backport Needed
  • Patch (non-breaking change which fixes an issue)
  • Minor (non-breaking change which adds functionality)
  • Major (fix or feature that would cause existing functionality to change)

- Remove the `ssh-tunnel` package from Compass and its usage from
  data-service
- Add relevant fields to the connection form and integrate them
  into data-service
@addaleax addaleax marked this pull request as ready for review August 26, 2024 18:06
Copy link
Collaborator

@gribnoysup gribnoysup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks pretty good! I would suggest to move away from using compass preferences (even through their provider, yeah...) and globalAppRegistry directly in connection-form if my reasoning makes sense to you

@@ -16,6 +17,8 @@ import { errorMessageByFieldName } from '../../../utils/validation';
import { getConnectionStringUsername } from '../../../utils/connection-string-helpers';
import type { OIDCOptions } from '../../../utils/oidc-handler';
import { useConnectionFormPreference } from '../../../hooks/use-connect-form-preferences';
import { usePreference } from 'compass-preferences-model/provider';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, we did a poor job documenting this well, but connection-form, being used by vscode too, uses this use-connect-form-preferences as a way to have a access to preferences inside the form so that we don't need to pull anything compass specific into runtime and depend on any compass logic for default preferences at all. There are a few places where preferences got used directly, and we already have ticket to clean those up, so let's add this as a new value to the connection form preferences to avoid adding more work for this planned cleanup

Copy link
Collaborator Author

@addaleax addaleax Aug 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So – I've stuck to this pattern because I've been using it for a feature flag only, similar to what we do for enableMultipleConnectionSystem (where we also call usePreference() in connection-form). The feature flag gets removed in the next PR anyway, so I'd be tempted to just leave it like this? (Will address the other comments below tho)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, I get this reasoning, at the same time the multiple connection feature flag directly used from the preferences was one of the things that broke connection form for vscode based on Alenas update attempt investigation, so this case feels similar and it might be a bit inconvenient if periodically vscode couldn't update while feature flags are used in the form. The place where we map compass preferences to connection form ones is in this file, so I wonder that maybe the logic you have here where it derives the value for enableProxySettings from the form preference value and a feature flag can be combined there? Would that make sense to you?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any chance you linked the wrong file here? Anyway, I moved this out of connection-form in 03fe506, I hope that looks like what you had in mind (and, again, this is very temporary 🙂)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, unless github is glitching out somehow, I'm linking to the same file where you moved the logic to though so it definitely looks good to me 😄 Sorry for being a nuisance with this, I'm planning to extend the eslint rules in this package shortly to cover more packages that we should avoid using directly here, so just trying to find some relatively easy ways for this PR to avoid these imports in advance

@@ -16,6 +17,8 @@ import { errorMessageByFieldName } from '../../../utils/validation';
import { getConnectionStringUsername } from '../../../utils/connection-string-helpers';
import type { OIDCOptions } from '../../../utils/oidc-handler';
import { useConnectionFormPreference } from '../../../hooks/use-connect-form-preferences';
import { usePreference } from 'compass-preferences-model/provider';
import { useGlobalAppRegistry } from 'hadron-app-registry';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is less of a problem than using preferences directly, but just from the perspective of the connection-form being a component that is not exactly aware of compass, we might want to have just a normal callback prop like onOpenProxySettingsClick passed down from the connection form root instead of emitting on global app registry directly in the form code. Would changing this up make sense to you?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, done in 42c22a6 👍

import React, { useCallback } from 'react';

export function AppProxy(): React.ReactElement {
const globalAppRegistry = useGlobalAppRegistry();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above for direct usage of appRegistry in the connection-form

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also done in 42c22a6 👍

}: {
errors: ConnectionFormError[];
connectionStringUrl: ConnectionStringUrl;
updateConnectionFormField: UpdateConnectionFormField;
connectionOptions?: ConnectionOptions;
_showProxySettingsForTesting?: boolean;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, I'd suggest to fallback to using special testing only props on components as a total last resort: should be possible to just pre-configure the preferences in test to match the logic we're expecting here, unless I'm missing something 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handled as a side-effect of the cleanup in 03fe506 👍

const [tunnel, socks5Options] = await openSshTunnel(
connectionOptions.sshTunnel,
logger
// (?. because this can be false-y in compass-web)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concerns me a bit that this requires some knowledge about how compass-web build is configured and is not enforced by anything else, but this knowledge. I wonder if we can make sure that somehow every time anything from this library is used in compas monorepo 🤔 Is there a way for us to maybe extend this package types with a shared d.ts file in some way that would make every export optional and apply it everywhere through our shared tsconfig? Not a blocker, but maybe if it's low effort to try something like this, it might be worth it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, fair enough. I think it's a bit cleaner to use the localPolyfill() variant in this case, it's not quite as "automatic" like making the types for a given package all-optional, but I don't think the latter can be implemented all that easily either

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(done in fa14cef)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, makes sense, even better probably, very obvious what the expectation is there now 👍

@@ -110,6 +111,11 @@ const sharedResolveOptions = (
};
};

const providePlugin = new ProvidePlugin({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It worked! 😄

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It did! 🙂

@addaleax addaleax requested a review from gribnoysup August 27, 2024 13:30
Copy link
Collaborator

@gribnoysup gribnoysup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks neat! TY for addressing the feedback!

@addaleax addaleax merged commit 86a9451 into main Aug 27, 2024
27 checks passed
@addaleax addaleax deleted the 8142-dev branch August 27, 2024 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants