Skip to content
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

Dont error on disabled flag #382

Merged
merged 2 commits into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
This format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Changed

* Don't error on evaluating flags that are disabled, return no match instead [https://github.com/markphelps/flipt/pull/382](https://github.com/markphelps/flipt/pull/382)

## [v1.1.0](https://github.com/markphelps/flipt/releases/tag/v1.1.0) - 2021-01-15

### Changed
Expand Down
12 changes: 0 additions & 12 deletions errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,6 @@ func (e ErrInvalid) Error() string {
return string(e)
}

// ErrDisabled represents a disabled flag
type ErrDisabled string

// ErrDisabledf creates an ErrDisabled using a custom format
func ErrDisabledf(format string, args ...interface{}) error {
return ErrDisabled(fmt.Sprintf(format, args...))
}

func (e ErrDisabled) Error() string {
return string(e)
}

// ErrValidation is a validation error for a specific field and reason
type ErrValidation struct {
field string
Expand Down
5 changes: 3 additions & 2 deletions rpc/flipt.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rpc/flipt_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions server/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package server

import (
"context"
"errors"
"fmt"
"hash/crc32"
"sort"
Expand Down Expand Up @@ -70,10 +69,9 @@ func (s *Server) batchEvaluate(ctx context.Context, r *flipt.BatchEvaluationRequ
Responses: make([]*flipt.EvaluationResponse, 0, len(r.GetRequests())),
}

var errd errs.ErrDisabled
for _, flag := range r.GetRequests() {
f, err := s.evaluate(ctx, flag)
if err != nil && !errors.As(err, &errd) {
if err != nil {
return &res, err
}
f.RequestId = ""
Expand Down Expand Up @@ -102,7 +100,8 @@ func (s *Server) evaluate(ctx context.Context, r *flipt.EvaluationRequest) (*fli
}

if !flag.Enabled {
return resp, errs.ErrDisabledf("flag %q is disabled", r.FlagKey)
resp.Match = false
return resp, nil
}

rules, err := s.store.GetEvaluationRules(ctx, r.FlagKey)
Expand Down
3 changes: 1 addition & 2 deletions server/evaluator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ func TestEvaluate_FlagDisabled(t *testing.T) {
},
})

require.Error(t, err)
assert.EqualError(t, err, "flag \"foo\" is disabled")
require.NoError(t, err)
assert.False(t, resp.Match)
}

Expand Down