feat: show which flags use each segment in the UI#5563
feat: show which flags use each segment in the UI#5563aparimeet wants to merge 2 commits intoflipt-io:mainfrom
Conversation
|
👋 Hi @aparimeet! Thanks for your contribution to this project. It looks like one or more of your commits are missing a DCO (Developer Certificate of Origin) sign-off. The DCO is a simple way for you to certify that you have the right to submit this code under the project's license. How to fix this: # For future commits, use the -s flag
git commit -s -m "Your commit message"
# To sign off on existing commits in this PR
git rebase HEAD~$(git rev-list --count origin/main..HEAD) --signoff
git push --force-with-leaseThe 📋 View the failing DCO check for more details For more information about the DCO, visit: https://developercertificate.org/ |
bebaa51 to
4d32e83
Compare
|
This change should resolve #4037 |
|
Hey @aparimeet Thank you for your work. The idea is interesting, though I’m a bit concerned about how it would behave in setups with many flags. For systems with 99+ flags, this might become slow. |
|
@erka You're right. There is potential for slowdown with scale. I wanted to see if I can make some progress with this issue and get something working with a small number of flags per segment. This can be thought of as a proof of concept for the requirement. I'll try to test and benchmark with large number of flags and see how the system responds with this implementation. |
|
I was able to import 100+ flags. Certain flags were set to use 100+ segments. Fresh load for the SegmentTable.tsx page for 100+ segments, each being used by 100+ flags Takes about 1-2 seconds to load the "Used in flags" data: Fresh load for Segment.tsx page with 100+ flags Again, takes about 1-2 seconds to load all the flags: |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5563 +/- ##
=======================================
Coverage 58.05% 58.05%
=======================================
Files 177 177
Lines 16742 16742
=======================================
Hits 9720 9720
Misses 6019 6019
Partials 1003 1003
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@aparimeet One request for flags and extra two for each flags. It could take some time for people. Could we make this configurable with a UI preference option? I really don't want to make new api endpoint right now but I would like to make the progress with it. |
Sure, moved this under a UI preference option. Here is an overview of the changes: SummaryAdds a browser-only preference so users can opt in to loading “which flags use this segment” data. That path uses the existing APIs ( UI
State & persistence
API usage (RTK Query
|
4f4b0e8 to
f5591c1
Compare
f5591c1 to
219eadb
Compare
Signed-off-by: aparimeet <aparimeet@gmail.com>
- Add listFlagsForSegment and getSegmentFlagCounts RTK endpoints (existing REST APIs) - Segment page: Used in flags; segments list: per-segment flag counts when enabled - Preferences: Segment flag usage toggle (default off); persist with theme/timezone/sidebar - Add Sidebar enum to types; fix accidental conflict markers in store listener Signed-off-by: aparimeet <aparimeet@gmail.com>
bd95141 to
9cfa560
Compare
Problem
In the UI it was hard to see which segments are used by which flags; that information only appeared on each flag’s view/edit screen. With many flags and segments it was easy to have unused segments and hard to see the impact of changing a segment’s constraints.
Solution
Segment list: Show a “Used in N flags” count per segment so usage is visible at a glance.
Segment view: Show a “Used in flags” section with the list of flags that reference the segment (via rules or rollouts) and links to each flag’s view/edit page.
Changes
ui/src/app/segments/segmentsApi.ts
Added listFlagsForSegment query: loads all flags, then each flag’s rules and rollouts, and returns flags that reference the given segment (used on segment detail).
Added getSegmentFlagCounts query: same data source, returns a map segmentKey → number of flags (used on segment list).
Added helpers ruleReferencesSegment and rolloutReferencesSegment and exported IFlagReference and the new hooks.
ui/src/app/segments/Segment.tsx
Always show a “Used in flags” section: loading state, “This segment is not used by any flags,” or a list of flags with links to /namespaces/{ns}/flags/{flagKey}.
Use refetchOnMountOrArgChange: true for the “used in flags” query so data is fresh when opening the segment page.
ui/src/components/segments/SegmentTable.tsx
For each segment card, show “Used in N flags” (with icon) once flag counts have loaded, including “Used in 0 flags.”
Use refetchOnMountOrArgChange: true for the flag-counts query so the list shows up-to-date counts when visiting the segments page.
Notes
No new backend APIs: everything uses existing endpoints (list flags, list rules per flag, list rollouts per flag); the UI aggregates to “which flags use this segment” and “how many flags per segment.”
For namespaces with many flags, the segment list and segment detail each trigger 1 + 2×F requests (F = number of flags) when those views load; consider a dedicated backend endpoint later if this becomes a performance concern.
Screenshots