-
-
Notifications
You must be signed in to change notification settings - Fork 158
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: Cmd evaluation #2609
feat: Cmd evaluation #2609
Conversation
✅ Deploy Preview for go-feature-flag-doc-preview ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
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.
Hey @mexes20 thanks for your contribution, I am looking forward for this new cli.
I have made a first pass and found some things to fix before being able to have a working command line.
Can you try to fix it and ensure that the code compiles before re-requesting a review?
Thanks again for your contribution 🙏
cmd/cli/evaluate.go
Outdated
|
||
"github.com/thomaspoignant/go-feature-flag/ffuser" | ||
"github.com/thomaspoignant/go-feature-flag/retriever" | ||
"github.com/thomaspoignant/go-feature-flag/variation" |
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.
issue: This package does not exist in go-feature-flag I am not sure why you are importing it? I see that you are trying to use it in your code too. Did you miss committing something or is this an error?
cmd/cli/evaluate.go
Outdated
"io/ioutil" | ||
|
||
"github.com/thomaspoignant/go-feature-flag/ffuser" | ||
"github.com/thomaspoignant/go-feature-flag/retriever" |
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.
issue: This import is not used. We should remove it.
"github.com/thomaspoignant/go-feature-flag/retriever" |
cmd/cli/evaluate.go
Outdated
} | ||
|
||
type FlagConfig struct { | ||
Flags map[string]*variation.Flag `yaml:"flags"` |
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.
suggestion: As mention in a previous comment, the package variation
does not exists, what you are looking at here is flag.Flag
Flags map[string]*variation.Flag `yaml:"flags"` | |
Flags map[string]*flag.Flag `yaml:"flags"` |
cmd/cli/evaluate.go
Outdated
evaluateCmd.Flags().StringVarP(&flagName, "flag", "f", "", "Name of the flag to evaluate") | ||
evaluateCmd.Flags().StringVarP(&evaluationContext, "evaluation-context", "e", "{}", "Evaluation context in JSON format") | ||
|
||
evaluateCmd.MarkFlagRequired("config") |
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.
suggestion: We should handle the error return by MarkFlagRequired
to be sure that we are not letting the user pass without the required parameters.
cmd/cli/main.go
Outdated
fmt.Fprintf(os.Stderr, "Error executing command: %v\n", err) | ||
os.Exit(1) |
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.
suggestion: Since we want to exit in error and write an error I would suggest to use log.Fatalf
instead.
fmt.Fprintf(os.Stderr, "Error executing command: %v\n", err) | |
os.Exit(1) | |
log.Fatalf("Error executing command: %v\n", err) |
cmd/cli/evaluate.go
Outdated
user := ffuser.NewUser(targetingKey) | ||
for k, v := range context { | ||
if k != "targetingKey" { | ||
user.Custom[k] = v |
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.
issue: Custom
is not a public attribute so you can't add things in the context like this.
suggestion: Use the function AddCustomAttribute(k, v)
instead
user.Custom[k] = v | |
evalCtx.AddCustomAttribute(k, v) |
cmd/cli/evaluate.go
Outdated
return &config, nil | ||
} | ||
|
||
func parseContext(contextJSON string) (*ffuser.User, error) { |
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.
suggestion: ffuser.User
is deprecated, please use ffcontext.EvaluationContext
instead.
cmd/cli/evaluate.go
Outdated
type EvaluationResult struct { | ||
TrackEvents bool `json:"trackEvents"` | ||
VariationType string `json:"variationType"` | ||
Failed bool `json:"failed"` | ||
Version string `json:"version"` | ||
Reason string `json:"reason"` | ||
ErrorCode string `json:"errorCode"` | ||
Value interface{} `json:"value"` | ||
Cacheable bool `json:"cacheable"` | ||
} |
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.
question: Why do you need to create a new response struct here? You can probably use model.VariationResult
instead that has the exact same signature (except that it is a generic type).
This struct is available here.
cmd/cli/evaluate.go
Outdated
return nil | ||
} | ||
|
||
func evaluateSingleFlag(flag *variation.Flag, user *ffuser.User) (*EvaluationResult, error) { |
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.
func evaluateSingleFlag(flag *variation.Flag, user *ffuser.User) (*EvaluationResult, error) { | |
func evaluateSingleFlag(flag *variation.Flag, user *ffcontext.EvaluationContext) (*EvaluationResult, error) { |
cmd/cli/evaluate.go
Outdated
func evaluateAllFlags(config *FlagConfig, user *ffuser.User) error { | ||
results := make(map[string]*EvaluationResult) | ||
|
||
for flagName, flag := range config.Flags { |
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.
issue: Here config.Flags
will always be empty since you've passed nothing for the flag name here.
suggestion: You can directly use the function AllFlagsState
that perform the evaluation for all the flags.
Okay ser, I'm working on it now. |
@thomaspoignant I'm still working on this ser, just having a hard time with some parts but I'll fix it soon |
Signed-off-by: Thomas Poignant <[email protected]>
1242877
to
97c976b
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2609 +/- ##
==========================================
+ Coverage 84.50% 84.73% +0.22%
==========================================
Files 106 111 +5
Lines 5021 5162 +141
==========================================
+ Hits 4243 4374 +131
- Misses 616 624 +8
- Partials 162 164 +2 ☔ View full report in Codecov by Sentry. 🚨 Try these New Features:
|
Signed-off-by: Thomas Poignant <[email protected]>
49ac3f9
to
862ab55
Compare
Signed-off-by: Thomas Poignant <[email protected]>
Signed-off-by: Thomas Poignant <[email protected]>
Signed-off-by: Thomas Poignant <[email protected]>
|
Description
evaluation command line for local testing
Closes issue #2560
Resolve #2560
Checklist
README.md
and/website/docs
)