-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add sample feature flagging system to next.js template #259
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, looks great! Left a high level comment on the architectural pattern
… into aligg/ff # Conflicts: # app/src/pages/index.tsx
Co-authored-by: Sawyer Hollenshead <git@sawyerh.com>
Co-authored-by: Sawyer Hollenshead <git@sawyerh.com>
Co-authored-by: Sawyer Hollenshead <git@sawyerh.com>
Co-authored-by: Sawyer Hollenshead <git@sawyerh.com>
Co-authored-by: Sawyer Hollenshead <git@sawyerh.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good, thanks for iterating and debugging things! I was able to test this successfully locally using the Platform IAM credentials (left a comment with relevant instructions).
app/tests/pages/index.test.tsx
Outdated
@@ -2,11 +2,13 @@ import { axe } from "jest-axe"; | |||
import Index from "src/pages/index"; | |||
import { render, screen } from "tests/react-utils"; | |||
|
|||
jest.mock("src/services/feature-flags/setup"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can get rid of this line as well as the __mocks__
file now since the moduleNameMapper
change fixed the original issue.
isFeatureEnabled(feature: string, userId?: string): Promise<boolean>; | ||
} | ||
|
||
export const manager: FlagManager = process.env.FEATURE_FLAGS_PROJECT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we may still want to add the NODE_ENV !== "test"
check here, since we are getting rid of the Jest mock. It's not causing issues at the moment since there's no test for getServerSideProps
so the feature flag check is never executed in a test, but the NODE_ENV
check would be useful for when a project adds test coverage for code that calls isFeatureEnabled
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer not to do environment checks in our source code since that breaks 12 factor app principles. A couple of reasons: (1) if the logic in the code has branches based on environment variables, it means that we have less confidence that the code branch that's covered in one environment (e.g. automated test suite) would work the same as the code branch that's covered when deployed to production and. Relatedly, in terms of test coverage tools, one entire branch of code will not be covered. (2) it makes it harder to implement automated integration tests if the test suite is forced to not use the AWS flag manager.
If we want to be more explicit about when we're using one flag manager type over the other without having to comment out or remove the FEATURE_FLAGS_PROJECT env var, we could always add an extra env var like FEATURE_FLAG_MANAGER_TYPE that is either "aws" or "local" e.g.
manager = process.env.FEATURE_FLAG_MANAGER_TYPE === "aws" ? new AWSFeatureFlagManager(process.env.FEATURE_FLAGS_PROJECT) : new LocalFeatureFlagManager();
would that address the issue you mentioned without a NODE_ENV check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cross-posting from Slack:
Sorry, I caused confusion with an inaccurate statement — Next.js only loads env vars into the test environment from the .env file, but it doesn’t load the vars in files like .env.development or .env.local so I think ultimately Ali your existing condition that just checks the FF project var would be enough.
docs/feature-flagging.md
Outdated
# Feature flagging | ||
|
||
- [AWS Evidently](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Evidently.html) is used for feature flagging | ||
- For more information about the decision-making behind using Evidently, [this infra ADR is available](https://github.com/navapbc/template-infra/blob/main/docs/decisions/infra/0010-feature-flags-system-design.md) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR is merged, so you can probably reference the ADR directly on the main branch
docs/feature-flagging.md
Outdated
## Local development | ||
|
||
Out-of-the-box, local calls to Evidently will fail with feature flag values defaulting to false. If you want to test Evidently locally, use your AWS IAM credentials. Once you set AWS environment variables locally for the environment you wish to connect to, calls to Evidently will succeed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think we should provide a local feature flag implementation that doesn't rely on evidently. config files and environment variables are the approaches that jump to mind, but if there's an approach that leverages Next.js's local hot reloading that'd be nice to have.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isFeatureEnabled(feature: string, userId?: string): Promise<boolean>; | ||
} | ||
|
||
export const manager: FlagManager = process.env.FEATURE_FLAGS_PROJECT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer not to do environment checks in our source code since that breaks 12 factor app principles. A couple of reasons: (1) if the logic in the code has branches based on environment variables, it means that we have less confidence that the code branch that's covered in one environment (e.g. automated test suite) would work the same as the code branch that's covered when deployed to production and. Relatedly, in terms of test coverage tools, one entire branch of code will not be covered. (2) it makes it harder to implement automated integration tests if the test suite is forced to not use the AWS flag manager.
If we want to be more explicit about when we're using one flag manager type over the other without having to comment out or remove the FEATURE_FLAGS_PROJECT env var, we could always add an extra env var like FEATURE_FLAG_MANAGER_TYPE that is either "aws" or "local" e.g.
manager = process.env.FEATURE_FLAG_MANAGER_TYPE === "aws" ? new AWSFeatureFlagManager(process.env.FEATURE_FLAGS_PROJECT) : new LocalFeatureFlagManager();
would that address the issue you mentioned without a NODE_ENV check?
I meant to just add one inline comment in response to a thread, not sure why it posted an entire review with what seems to be outdated comments. Sorry! edit: oh it looks like i had review comments pending that i just never remembered to submit. maybe worth looking at the comments but apologies in advance if any of them are no longer relevant. |
Co-authored-by: Sawyer Hollenshead <git@sawyerh.com>
Changes
Context for reviewers
Testing