Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Add Remote Feature Flag Params to Dashboard Cards endpoint - #674

Merged
salimbraksa merged 15 commits into
trunkfrom
task/22315-backend-driven-dynamic-cards-filtering
Jan 5, 2024
Merged

Add Remote Feature Flag Params to Dashboard Cards endpoint#674
salimbraksa merged 15 commits into
trunkfrom
task/22315-backend-driven-dynamic-cards-filtering

Conversation

@salimbraksa

@salimbraksa salimbraksa commented Jan 3, 2024

Copy link
Copy Markdown
Contributor

Description

Part of wordpress-mobile/WordPress-iOS#22315

This PR passes the following params to the dashboard cards endpoint:

  • device_id
  • platform
  • build_number
  • marketing_version
  • identifier

Testing Details

See wordpress-mobile/WordPress-iOS#22320

Note

Please remove the [Status] DO NOT MERGE label and merge after:

  • the backend change is deployed D133371-code
  • the WPiOS PR is approved so that the two PRs are merged together and no breakages is introduced in trunk

  • Please check here if your pull request includes additional test coverage.
  • I have considered if this change warrants release notes and have added them to the appropriate section in the CHANGELOG.md if necessary.

@salimbraksa
salimbraksa force-pushed the task/22315-backend-driven-dynamic-cards-filtering branch from 7239eef to 1f7ab13 Compare January 3, 2024 18:12
@salimbraksa salimbraksa self-assigned this Jan 3, 2024
@salimbraksa salimbraksa added the enhancement New feature or request label Jan 3, 2024
@salimbraksa
salimbraksa marked this pull request as ready for review January 3, 2024 23:20
@salimbraksa
salimbraksa force-pushed the task/22315-backend-driven-dynamic-cards-filtering branch 7 times, most recently from 34cdcad to 91b6e05 Compare January 5, 2024 02:24
@salimbraksa
salimbraksa force-pushed the task/22315-backend-driven-dynamic-cards-filtering branch from 91b6e05 to accfc22 Compare January 5, 2024 02:30

@hassaanelgarem hassaanelgarem left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me! 🚀
Kudos on adding tests!
Only left a few code improvement suggestions.

"cards": cards.joined(separator: ",") as NSString
]
let featureFlagParams = try {
let params = FeatureFlagRemote.RemoteFeatureFlagsEndpointParams(deviceId: deviceId)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wonder if this struct should still live inside FeatureFlagRemote now that it's shared with an unrelated class.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That was the plan initially, but couldn't figure out a name for that type. 😅

Comment thread WordPressKit/FeatureFlagRemote.swift Outdated
Comment thread WordPressKit/FeatureFlagRemote.swift
Comment thread WordPressKit/FeatureFlagRemote.swift Outdated
}

public struct RemoteFeatureFlagsEndpointParams {
public struct FetchAllEndpointParams {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@salimbraksa FetchAllEndpointParams feels a bit confusing. How about SessionDetails?

Also, can we move it outside of the FeatureFlagRemote scope? Referencing it by FeatureFlagRemote.FetchAllEndpointParams hurts the readability as it implies it is tighly coupled with feature flags while it's not. This is what I meant here #674 (comment)

@salimbraksa salimbraksa Jan 5, 2024

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

My concern with global scope is the following:

  1. Let's say another developer added a valid "session" attribute in SessionDetails.
  2. The new attribute is encoded and returned in the dictionary representation.
  3. Now that attribute will be sent in all other endpoints, and I'm not sure how endpoints handle extra attributes that don't need.

This is why I kept that type tightly related to Feature Flags, and if you think about it, the new params added in Dashboard Cards are for the Feature Flags mechanism.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Now that attribute will be sent in all other endpoints, and I'm not sure how endpoints handle extra attribute that don't need.

We can assume that developers will seek to understand what this type is used for before changing it.
However, extra params won't cause an issue either way.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We can assume that developers will seek to understand what this type is used for before changing it.

I agree, but my concern is that if we expand the SessionDetails with new 'session' attributes in the future, we need to ensure they are not inadvertently included in the Feature Flags and Dashboard Cards endpoint query params.

If we rename that type to SessionDetails, I think the Feature Flag Remote and Dashboard Cards service should select only the params they need.

Also, while I'm sure developers double check API usage before making changes, I think it's also important to write resilient code that mitigates the risks associated with human error.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll rename the type to SessionsDetails and update the Unit Tests to ensure only the the params required by the endpoint are sent.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

However, extra params won't cause an issue either way.

Given this, I think we would be over-engineering to avoid something that's not critical.

@salimbraksa salimbraksa Jan 5, 2024

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Resolved in 28cc006

However, extra params won't cause an issue either way.

Passing extra params to endpoints is a code smell in my opinion. Moreover, some backend APIs may reject the request if it includes additional parameters as a security measure.

I agree that we shouldn't spend time on imaginary problems. For now, it's enough to have Unit Tests to check for this. I looked at the tests we already have, and they'll fail if extra params are sent to Feature Flags and Dashboard Cards endpoints.

@salimbraksa
salimbraksa merged commit 87eba25 into trunk Jan 5, 2024
@salimbraksa
salimbraksa deleted the task/22315-backend-driven-dynamic-cards-filtering branch January 5, 2024 17:18
@mokagio

mokagio commented Jan 8, 2024

Copy link
Copy Markdown
Contributor

Thank you for working on this @salimbraksa and for adding tests. I also appreciate the helper functions, which enable writing othre tests in the future 🎉

I landed here while preparing the library for Jetpack and WordPress iOS 24.0. I noticed this PR introduce a breaking change, which is something we should be careful with because of the downstream implication in https://github.com/wordpress-mobile/WordPressAuthenticator-iOS which depends on WordPressKit.

Given the app PR that uses this logic, wordpress-mobile/WordPress-iOS#22320, has not been merged at this time and won't be part of 24.0, I will not ship a new release with this breaking change just yet.

Ideally, we'd want to provide a non-breaking API. If that's not possible, given we'll need to go through the effort of shipping the breaking change, we might as well look for other breaking low hanging fruits to slot in.

Cheers (and Happy New Year!)

@mokagio mokagio mentioned this pull request Jan 8, 2024
@salimbraksa

Copy link
Copy Markdown
Contributor Author

Hey @mokagio, the other PR was supposed to be merged on Friday, but I just realized it didn't because of a flaky unit test unrelated to my PR.

The PR was already been reviewed and approved, so I’ll work on fixing the failing test and aim to merge it into release/24.0.

crazytonyli added a commit that referenced this pull request Jan 11, 2024
The parameter was [initially designed to be non-optional][PR-1]. Later
it's later [changed to be optional][PR-2], under [this proposal][comment-1].

This commit simply reverts the parameter to be non-optional, to ship it
along with other breaking changes.

[PR-1]: #674
[PR-2]: #676
[comment-1]: wordpress-mobile/WordPress-iOS#22320 (comment)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants