Skip to content

Commit

Permalink
feat(rollouts): Additional functionality working with multiple segmen…
Browse files Browse the repository at this point in the history
…ts for rollouts
  • Loading branch information
yquansah committed Jul 28, 2023
1 parent 4868a4b commit 777f817
Show file tree
Hide file tree
Showing 6 changed files with 435 additions and 420 deletions.
1 change: 1 addition & 0 deletions internal/server/evaluation/evaluation.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ func (s *Server) boolean(ctx context.Context, flag *flipt.Flag, r *rpcevaluation
// If we have exhausted all rollouts and we still don't have a match, return flag enabled value.
resp.Reason = rpcevaluation.EvaluationReason_DEFAULT_EVALUATION_REASON
resp.Enabled = flag.Enabled

s.logger.Debug("default rollout matched", zap.Bool("enabled", flag.Enabled))
return resp, nil
}
Expand Down
10 changes: 8 additions & 2 deletions internal/storage/sql/common/evaluation.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ func (s *Store) GetEvaluationRollouts(ctx context.Context, namespaceKey, flagKey
rt.value,
rss.segment_key,
rss.rollout_segment_value,
rss.segment_operator,
rss.match_type,
rss.constraint_type,
rss.constraint_property,
Expand All @@ -240,6 +241,7 @@ func (s *Store) GetEvaluationRollouts(ctx context.Context, namespaceKey, flagKey
rsr.segment_key,
s.match_type,
rs.value AS rollout_segment_value,
rs.segment_operator AS segment_operator,
c."type" AS constraint_type,
c.property AS constraint_property,
c.operator AS constraint_operator,
Expand Down Expand Up @@ -276,6 +278,7 @@ func (s *Store) GetEvaluationRollouts(ctx context.Context, namespaceKey, flagKey
rtPercentageValue sql.NullBool
rsSegmentKey sql.NullString
rsSegmentValue sql.NullBool
rsSegmentOperator sql.NullInt32
rsMatchType sql.NullInt32
rsConstraintType sql.NullInt32
rsConstraintProperty sql.NullString
Expand All @@ -292,6 +295,7 @@ func (s *Store) GetEvaluationRollouts(ctx context.Context, namespaceKey, flagKey
&rtPercentageValue,
&rsSegmentKey,
&rsSegmentValue,
&rsSegmentOperator,
&rsMatchType,
&rsConstraintType,
&rsConstraintProperty,
Expand All @@ -310,6 +314,7 @@ func (s *Store) GetEvaluationRollouts(ctx context.Context, namespaceKey, flagKey
evaluationRollout.Threshold = storageThreshold
} else if rsSegmentKey.Valid &&
rsSegmentValue.Valid &&
rsSegmentOperator.Valid &&
rsMatchType.Valid &&
rsConstraintType.Valid &&
rsConstraintProperty.Valid &&
Expand Down Expand Up @@ -338,8 +343,9 @@ func (s *Store) GetEvaluationRollouts(ctx context.Context, namespaceKey, flagKey
}

storageSegment := &storage.RolloutSegment{
Value: rsSegmentValue.Bool,
Segments: make(map[string]*storage.EvaluationSegment),
Value: rsSegmentValue.Bool,
SegmentOperator: flipt.SegmentOperator(rsSegmentOperator.Int32),
Segments: make(map[string]*storage.EvaluationSegment),
}

storageSegment.Segments[rsSegmentKey.String] = &storage.EvaluationSegment{
Expand Down
2 changes: 2 additions & 0 deletions internal/storage/sql/common/rollout.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func getRollout(ctx context.Context, builder sq.StatementBuilderType, namespaceK
}

segmentRule.Segment.Value = value
segmentRule.Segment.SegmentOperator = segmentOperator

rows, err := builder.Select("segment_key").
From("rollout_segment_references").
Expand Down Expand Up @@ -298,6 +299,7 @@ func (s *Store) ListRollouts(ctx context.Context, namespaceKey, flagKey string,
}

rs.Value = v.value
rs.SegmentOperator = v.segmentOperator

rollout.Rule = &flipt.Rollout_Segment{Segment: rs}
}
Expand Down
Loading

0 comments on commit 777f817

Please sign in to comment.