-
Notifications
You must be signed in to change notification settings - Fork 213
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(segments): Segment AND'ing #1915
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.
couple quick thoughts
585c63b
to
dd803a9
Compare
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.
theres a few lint failures around err checking that need 👀 I think, also wondering how performance is impacted with this change
e2f936a
to
8c1d4bc
Compare
* feat(update): UI for Rule updates * feat(rollouts/rules): Updating UI for rollouts and rules * feat(update): UI for Rule updates * feat: Add readonly attributes to edit forms * chore: address comments * chore: fix logic for updating
* chore: fix reset of rules/rollouts * chore: fix null error with segment
…nd UX around adding segments (#1975) * feat(rules/rollouts): hide or and and based on segment keys length, and change UX for adding segments * chore: fix UI integration tests
* feat(rules): Make segment be one of two types * chore: force segment operator to be OR for one segment
* chore: print statements chore: revise query chore: remove unnecessary lines * chore: defer close ruleMetaRows * chore: remove orderBy since we are sorting at the end of the function * chore: fix double quotes for rank for MySQL support
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.
one minor json comment for struct tags, thank you for all the hard work on this!!
SegmentOperator flipt.SegmentOperator `json:"segmentOperator,omitempty"` | ||
} | ||
|
||
type EvaluationSegment struct { |
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.
we should probably put the JSON struct tags on this just to be safe since this will also be cached
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.
@markphelps Thank you for this. I could have just committed directly to this now that I think about it. Here is the PR: #1984
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.
lets do it to it!
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.
Epic work 💪 Couple optimization which are take it or leave it. Either way merge away when ready 👍
From(tableRolloutSegments). | ||
Where(sq.And{sq.Eq{"rollout_id": rollout.Id}, sq.Eq{"namespace_key": rollout.NamespaceKey}}). | ||
Where(sq.And{sq.Eq{"rollout_id": rollout.Id}}). |
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.
Where(sq.And{sq.Eq{"rollout_id": rollout.Id}}). | |
Where(sq.Eq{"rollout_id": rollout.Id}). |
|
||
rows, err := builder.Select("segment_key"). | ||
From(tableRolloutSegmentReferences). | ||
Where(sq.And{sq.Eq{"rollout_segment_id": rolloutSegmentId}, sq.Eq{"namespace_key": rollout.NamespaceKey}}). |
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.
Where(sq.And{sq.Eq{"rollout_segment_id": rolloutSegmentId}, sq.Eq{"namespace_key": rollout.NamespaceKey}}). | |
Where(sq.Eq{"rollout_segment_id": rolloutSegmentId, "namespace_key": rollout.NamespaceKey}). |
internal/storage/sql/common/util.go
Outdated
result := make([]string, 0) | ||
|
||
if len(segmentKeys) > 0 { | ||
result = append(result, segmentKeys...) | ||
} else if segmentKey != "" { | ||
result = append(result, segmentKey) | ||
} | ||
|
||
return removeDuplicates(result) |
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.
Take it or leave it optimization:
result := make([]string, 0) | |
if len(segmentKeys) > 0 { | |
result = append(result, segmentKeys...) | |
} else if segmentKey != "" { | |
result = append(result, segmentKey) | |
} | |
return removeDuplicates(result) | |
if len(segmentKeys) > 0 { | |
return removeDuplicates(segmentKeys) | |
} else if segmentKey != "" { | |
return []string{segmentKey} | |
} | |
return nil |
internal/storage/sql/common/rule.go
Outdated
RunWith(tx). | ||
Set("segment_operator", segmentOperator). | ||
Set("updated_at", &fliptsql.Timestamp{Timestamp: timestamppb.Now()}). | ||
Where(sq.And{sq.Eq{"id": r.Id}, sq.Eq{"namespace_key": r.NamespaceKey}, sq.Eq{"flag_key": r.FlagKey}}). |
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.
Another small optimization. sq.And
and sq.Eq
are maps. So each time they're stated we're allocating a map. Squirell with implicity AND all the k/v equalities in a single sq.Eq
map.
Where(sq.And{sq.Eq{"id": r.Id}, sq.Eq{"namespace_key": r.NamespaceKey}, sq.Eq{"flag_key": r.FlagKey}}). | |
Where(sq.Eq{"id": r.Id, "namespace_key": r.NamespaceKey, "flag_key": r.FlagKey}). |
Segment AND'ing project.
Supporting the ability for users to add multiple segments to their rules/rollouts for evaluations.