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

Only checkUpdates if AllowUpdateConnectors enabled #21138

Conversation

ambirdsall
Copy link
Contributor

@ambirdsall ambirdsall commented Jan 6, 2023

What

Changes the conditional guarding whether we actually query the webBackendCheckUpdates endpoint. The current version checks whether the app is using a cloud build; this updates it to check whether the AllowUpdateConnector feature is enabled, which is the actual source of truth (i.e. if we ever start supporting this endpoint for cloud, that's what would change). Closes https://github.com/airbytehq/airbyte-cloud/issues/3972

on the implementation

The only API we expose for querying FeatureService is a react hook, which can't be directly used outside of other react hooks or components--i.e., not in the ConnectorService class. Conveniently (in the short term, anyway), the only API we expose for using ConnectorService is... a react hook defined in the same file. So the job was reduced to writing an explicit constructor which can be passed the app's feature context via an additional argument. There's a few lines of diff that are just porting the right type definitions for the superclass's constructor args.

I used the FeatureService in a slightly roundabout way, though: for aesthetic reasons, I wanted an object which mapped FeatureItem member keys to boolean values, and useFeatureService doesn't expose anything like that. Maybe I should move the local EnabledFeatures into FeatureService instead, so it's reusable?

@octavia-squidington-iv octavia-squidington-iv added area/platform issues related to the platform area/frontend Related to the Airbyte webapp labels Jan 6, 2023
@ambirdsall ambirdsall force-pushed the alex/guard-checkUpdates-on-AllowUpdateConnector-instead-of-isCloud branch 2 times, most recently from fe44799 to 68df877 Compare January 9, 2023 23:05
@octavia-squidington-iv octavia-squidington-iv removed the area/platform issues related to the platform label Jan 9, 2023
@ambirdsall ambirdsall marked this pull request as ready for review January 9, 2023 23:05
Copy link
Contributor

@josephkmh josephkmh left a comment

Choose a reason for hiding this comment

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

This is a clever (and very concise) solution!

The approach I was thinking of was to refactor the components that call useGetConnectorsOutOfDate() to avoid calling this hook in the first place. The only way to do this with hooks is to do conditional components. This would require a bit of a larger refactor because of the way useGetConnectorsOutOfDate() is being used currently.

My thoughts for why this is maybe a better approach:

  1. We keep our AirbyteRequestService classes very lean, only concerned with data fetching and not other logic (e.g. feature toggling)
  2. It's kind of a "lie" to mock out the API response in this way - I can imagine following this pattern could lead to confusion about what's a real API response and what's "intercepted" in the AirbyteRequestService
  3. In places where we use useGetConnectorsOutOfDate(), its result is usually being fed to another component that uses a conditional rendering based on useFeature(FeatureItem.AllowUpdateConnectors) (see here). So why not just avoid calling this API endpoint in the first place, if we're avoiding rendering its result later anyway, based on the same feature flag?

Comment on lines +36 to +38
const enabledFeatures = {
[FeatureItem.AllowUpdateConnectors]: useFeature(FeatureItem.AllowUpdateConnectors),
};
Copy link
Contributor

Choose a reason for hiding this comment

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

An alternative to get a list of all enabled features would be:

const { features: enabledFeatures }  = useFeatureService();

Where enabledFeatures: FeatureItem[]. That would avoid needing to manually update this object map here, giving you access to all features as they are added/removed from the provider.

@krishnaglick
Copy link
Contributor

This is a clever (and very concise) solution!

The approach I was thinking of was to refactor the components that call useGetConnectorsOutOfDate() to avoid calling this hook in the first place. The only way to do this with hooks is to do conditional components. This would require a bit of a larger refactor because of the way useGetConnectorsOutOfDate() is being used currently.

My thoughts for why this is maybe a better approach:

1. We keep our `AirbyteRequestService` classes very lean, only concerned with data fetching and not other logic (e.g. feature toggling)

2. It's kind of a "lie" to mock out the API response in this way - I can imagine following this pattern could lead to confusion about what's a real API response and what's "intercepted" in the `AirbyteRequestService`

3. In places where we use `useGetConnectorsOutOfDate()`, its result is usually being fed to another component that uses a conditional rendering based on `useFeature(FeatureItem.AllowUpdateConnectors)` (see [here](https://github.com/airbytehq/airbyte/blob/master/airbyte-webapp/src/pages/SettingsPage/pages/ConnectorsPage/components/ConnectorsView.tsx#L49)). So why not just avoid calling this API endpoint in the first place, if we're avoiding rendering its result later anyway, based on the same feature flag?

While I do agree with some of your points here, I'm not sure it's worth the extra effort for most of it. Primarily because Cloud has a hard-coded response of 0 out of date connectors. The whole permissions issue is separate, but Cloud won't ever have something actionable for the user (in its current state at least).
As long as our feature flagging correctly identifies Cloud vs OSS this solution works fine.

I'm not saying we shouldn't do additional work here, just that I'm not sure it's worth it.

@ambirdsall
Copy link
Contributor Author

I'm not sure it's the best solution (I'm not sure it isn't either, at least given the current conventions in the codebase; it's at least simple and defensive code), but I think this as-is is better than what we have. I reckon it makes sense to merge this now and then we can figure out if we want to restructure how we do the feature-gating at our leisure.

Copy link
Contributor

@krishnaglick krishnaglick left a comment

Choose a reason for hiding this comment

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

I'm going to approve this since I feel this is good enough, but as this is in Cloud's Compose's bucket I'll leave it up to y'all if you want to spend more time on this!

@ambirdsall ambirdsall force-pushed the alex/guard-checkUpdates-on-AllowUpdateConnector-instead-of-isCloud branch from 68df877 to e0d0418 Compare February 1, 2023 01:15
@ambirdsall ambirdsall merged commit 79b4c7a into master Feb 1, 2023
@ambirdsall ambirdsall deleted the alex/guard-checkUpdates-on-AllowUpdateConnector-instead-of-isCloud branch February 1, 2023 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/frontend Related to the Airbyte webapp
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants